Moved registers to own arch file
authorLukas Krickl <lukas@krickl.dev>
Sat, 17 Feb 2024 17:50:18 +0000 (18:50 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 17 Feb 2024 17:50:18 +0000 (18:50 +0100)
src/archs.h [new file with mode: 0644]
src/ulas.c
src/ulas.h

diff --git a/src/archs.h b/src/archs.h
new file mode 100644 (file)
index 0000000..bf2d71f
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef ARCHS_H_
+#define ARCHS_H_
+
+enum ulas_asmregs_sm83 {
+  // r8
+  ULAS_REG_B = 1,
+  ULAS_REG_C = 2,
+  ULAS_REG_D = 3,
+  ULAS_REG_E = 4,
+  ULAS_REG_H = 5,
+  ULAS_REG_L = 6,
+  ULAS_REG_A = 7,
+
+  // r16
+  ULAS_REG_BC = 8,
+  ULAS_REG_DE = 9,
+  ULAS_REG_HL = 10,
+  ULAS_REG_AF = 16,
+
+  // flags
+  ULAS_REG_NOT_ZERO = 11,
+  ULAS_REG_ZERO = 12,
+  ULAS_REG_NOT_CARRY = 13,
+  ULAS_REG_CARRY = 14,
+
+  // misc
+  ULAS_REG_SP = 15,
+  ULAS_VEC00 = 17,
+  ULAS_VEC08 = 18,
+  ULAS_VEC10 = 19,
+  ULAS_VEC18 = 20,
+  ULAS_VEC20 = 21,
+  ULAS_VEC28 = 22,
+  ULAS_VEC30 = 23,
+  ULAS_VEC38 = 24
+};
+
+#endif
index ac3ebf092fba32ef25345e734ed0fd93c4fb1a74..c26cd8df1e08e6f609fa263d7d647353246e9b98 100644 (file)
@@ -1764,11 +1764,11 @@ char *ulas_strexpr(const char **line, unsigned long n, int *rc) {
   return NULL;
 }
 
-// TODO: instead of hard-coding the 
+// TODO: instead of hard-coding the
 // registers
-// we should use a register table 
-// that is used to look up register tokens 
-const char *ulas_asmregstr(enum ulas_asmregs reg) {
+// we should use a register table
+// that is used to look up register tokens
+const char *ulas_asmregstr(unsigned int reg) {
   switch (reg) {
   case ULAS_REG_A:
     return "a";
@@ -1818,12 +1818,14 @@ const char *ulas_asmregstr(enum ulas_asmregs reg) {
     return "0x30";
   case ULAS_VEC38:
     return "0x38";
+  default:
+    return NULL;
   }
 
   return NULL;
 }
 
-enum ulas_asmregs ulas_asmstrreg(const char *s, unsigned long n) {
+unsigned int ulas_asmstrreg(const char *s, unsigned long n) {
   for (int i = 0; i < 10; i++) {
     const char *rs = ulas_asmregstr(i);
     if (rs && strncmp(rs, s, n) == 0) {
@@ -1834,10 +1836,6 @@ enum ulas_asmregs ulas_asmstrreg(const char *s, unsigned long n) {
   return -1;
 }
 
-int ulas_asmregisr8(enum ulas_asmregs reg) {
-  return reg != ULAS_REG_BC && reg != ULAS_REG_DE && reg != ULAS_REG_HL;
-}
-
 /**
  * Instruction table
  */
index 01e8ea2db6cdb0de1e1a75d987deeeb29a9754a8..0d6291b4576bd7076cbeae3e305abd5e41b58d8a 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include "archs.h"
 
 // if this is used as a path use stdin or stdout instead
 #define ULAS_STDFILEPATH "-"
@@ -151,7 +152,7 @@ struct ulas_str {
 // any token before 256 is just the literal char value
 // primitive data types
 // FIXME: split up types and operators
-// TODO:add float expressions 
+// TODO:add float expressions
 enum ulas_type {
   ULAS_SYMBOL = 256,
   ULAS_INT,
@@ -417,43 +418,6 @@ enum ulas_asmdir {
   ULAS_ASMDIR_REP,
 };
 
-// amount of registers
-#define ULAS_NR8 7
-#define ULAS_NR16 3
-
-enum ulas_asmregs {
-  // r8
-  ULAS_REG_B = 1,
-  ULAS_REG_C = 2,
-  ULAS_REG_D = 3,
-  ULAS_REG_E = 4,
-  ULAS_REG_H = 5,
-  ULAS_REG_L = 6,
-  ULAS_REG_A = 7,
-
-  // r16
-  ULAS_REG_BC = 8,
-  ULAS_REG_DE = 9,
-  ULAS_REG_HL = 10,
-  ULAS_REG_AF = 16,
-
-  // flags
-  ULAS_REG_NOT_ZERO = 11,
-  ULAS_REG_ZERO = 12,
-  ULAS_REG_NOT_CARRY = 13,
-  ULAS_REG_CARRY = 14,
-
-  // misc
-  ULAS_REG_SP = 15,
-  ULAS_VEC00 = 17,
-  ULAS_VEC08 = 18,
-  ULAS_VEC10 = 19,
-  ULAS_VEC18 = 20,
-  ULAS_VEC20 = 21,
-  ULAS_VEC28 = 22,
-  ULAS_VEC30 = 23,
-  ULAS_VEC38 = 24
-};
 
 // special asm tokens for instr enum
 // TODO: add more expressions types such as e8, e16, e24, e32, e64