From: Lukas Krickl Date: Sat, 17 Feb 2024 17:50:18 +0000 (+0100) Subject: Moved registers to own arch file X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=15fd59b809a332aed2d47293ed07e28ef3e0377e;p=ulas%2F.git Moved registers to own arch file --- diff --git a/src/archs.h b/src/archs.h new file mode 100644 index 0000000..bf2d71f --- /dev/null +++ b/src/archs.h @@ -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 diff --git a/src/ulas.c b/src/ulas.c index ac3ebf0..c26cd8d 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -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 */ diff --git a/src/ulas.h b/src/ulas.h index 01e8ea2..0d6291b 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -4,6 +4,7 @@ #include #include #include +#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