Fixed warning for ldh instructions
authorLukas Krickl <lukas@krickl.dev>
Sat, 16 Dec 2023 11:21:52 +0000 (12:21 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 16 Dec 2023 11:21:52 +0000 (12:21 +0100)
include/ulas.h
src/ulas.c

index 0419c3df3c8817c1b00b1013e6bd92d282ebb54d..d286d0ad61f4dd55fe2481fbe12d6f4f5a293d12 100644 (file)
@@ -71,7 +71,7 @@
     fprintf(ulaserr, __VA_ARGS__);                                             \
     exit(-1);                                                                  \
   }
-#define ULASWARNLEVEL(level) ulascfg.warn_level & (level)
+#define ULASWARNLEVEL(level) ulascfg.warn_level &(level)
 
 // format macros
 #define ULAS_FMT(f, fmt)                                                       \
@@ -430,7 +430,12 @@ enum ulas_asmregs {
 };
 
 // special asm tokens for instr enum
-enum ulas_asmspetok { ULAS_E8 = -1, ULAS_E16 = -2, ULAS_DATZERO = 0xFF00 };
+enum ulas_asmspetok {
+  ULAS_E8 = -1,
+  ULAS_E16 = -2,
+  ULAS_A8 = -3,
+  ULAS_DATZERO = 0xFF00
+};
 
 #define ULAS_INSTRTOKMAX 16
 #define ULAS_INSTRDATMAX 16
index 17114a46195029a4ec308dc6b4c1d700f981482c..e38e47ef940502bac1a6052305b8d74c92f07b31 100644 (file)
@@ -1938,8 +1938,8 @@ const struct ulas_instr ULASINSTRS[] = {
     {"ldh", {'[', ULAS_REG_C, ']', ',', ULAS_REG_A, 0}, {0xE2, 0}},
     {"ldh", {ULAS_REG_A, ',', '[', ULAS_REG_C, ']', 0}, {0xF2, 0}},
 
-    {"ldh", {'[', ULAS_E8, ']', ',', ULAS_REG_A, 0}, {0xE0, ULAS_E8, 0}},
-    {"ldh", {ULAS_REG_A, ',', '[', ULAS_E8, ']', 0}, {0xF0, ULAS_E8, 0}},
+    {"ldh", {'[', ULAS_A8, ']', ',', ULAS_REG_A, 0}, {0xE0, ULAS_A8, 0}},
+    {"ldh", {ULAS_REG_A, ',', '[', ULAS_A8, ']', 0}, {0xF0, ULAS_A8, 0}},
 
     // ld r8, e8
     ULAS_INSTR_R8_EXPR8("ld", 0x06, ULAS_REG_B),
@@ -2149,7 +2149,7 @@ int ulas_asminstr(char *dst, unsigned long max, const char **line,
         if (strncmp(regstr, ulas.tok.buf, ulas.tok.maxlen) != 0) {
           goto skip;
         }
-      } else if (tok[i] == ULAS_E8 || tok[i] == ULAS_E16) {
+      } else if (tok[i] == ULAS_E8 || tok[i] == ULAS_E16 || tok[i] == ULAS_A8) {
         assert(expridx < ULAS_INSTRDATMAX);
         int rc = 0;
         int res = ulas_intexpr(line, n, &rc);
@@ -2158,12 +2158,16 @@ int ulas_asminstr(char *dst, unsigned long max, const char **line,
           return -1;
         }
 
-        if (ULASWARNLEVEL(ULAS_WARN_OVERFLOW) &&
-            (unsigned int)res > 0xFF && tok[i] == ULAS_E8) {
-          ULASWARN("Warning: 0x%X overflows the maximum allowed value of 0xFF\n", res);
+        if (ULASWARNLEVEL(ULAS_WARN_OVERFLOW) && (unsigned int)res > 0xFF &&
+            tok[i] == ULAS_E8) {
+          ULASWARN(
+              "Warning: 0x%X overflows the maximum allowed value of 0xFF\n",
+              res);
         } else if (ULASWARNLEVEL(ULAS_WARN_OVERFLOW) &&
                    (unsigned int)res > 0xFFFF && tok[i] == ULAS_E16) {
-          ULASWARN("Warning: 0x%X overflows the maximum allowed value of 0xFFFF\n", res);
+          ULASWARN(
+              "Warning: 0x%X overflows the maximum allowed value of 0xFFFF\n",
+              res);
         }
       } else {
         if (ulas_tok(&ulas.tok, line, n) == -1) {
@@ -2187,7 +2191,7 @@ int ulas_asminstr(char *dst, unsigned long max, const char **line,
       assert(datread < ULAS_INSTRDATMAX);
       assert(expridx < ULAS_INSTRDATMAX);
 
-      if (dat[datread] == ULAS_E8) {
+      if (dat[datread] == ULAS_E8 || dat[datread] == ULAS_A8) {
         dst[written] = (char)exprres[expridx++];
       } else if (dat[datread] == ULAS_E16) {
         // write 16-bit le values