diff --git a/include/asm/asm.h b/include/asm/asm.h deleted file mode 100644 index 66cf60a0..00000000 --- a/include/asm/asm.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of RGBDS. - * - * Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors. - * - * SPDX-License-Identifier: MIT - */ - -/* - * Contains some assembler-wide defines and externs - */ - -#ifndef RGBDS_ASM_ASM_H -#define RGBDS_ASM_ASM_H - -#include -#include -#include -#include - -#include "asm/localasm.h" -#include "asm/symbol.h" - -#define MAXMACROARGS 99999 -#define MAXINCPATHS 128 - -extern struct Section *pCurrentSection; - -#endif /* RGBDS_ASM_ASM_H */ diff --git a/include/asm/fstack.h b/include/asm/fstack.h index ace82372..f3577272 100644 --- a/include/asm/fstack.h +++ b/include/asm/fstack.h @@ -13,10 +13,10 @@ #ifndef RGBDS_ASM_FSTACK_H #define RGBDS_ASM_FSTACK_H +#include #include #include -#include "asm/asm.h" #include "asm/lexer.h" #include "types.h" diff --git a/include/asm/lexer.h b/include/asm/lexer.h index ba95acc4..9146094f 100644 --- a/include/asm/lexer.h +++ b/include/asm/lexer.h @@ -9,6 +9,8 @@ #ifndef RGBDS_ASM_LEXER_H #define RGBDS_ASM_LEXER_H +#include + #define MAXSTRLEN 255 struct LexerState; diff --git a/include/asm/localasm.h b/include/asm/localasm.h deleted file mode 100644 index 1326d85d..00000000 --- a/include/asm/localasm.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * This file is part of RGBDS. - * - * Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors. - * - * SPDX-License-Identifier: MIT - */ - -#ifndef RGBDS_ASM_LOCALASM_H -#define RGBDS_ASM_LOCALASM_H - -/* - * GB Z80 instruction groups - * - * n3 = 3-bit - * n = 8-bit - * nn = 16-bit - * - * ADC A,n : 0xCE - * ADC A,r : 0x88|r - * ADD A,n : 0xC6 - * ADD A,r : 0x80|r - * ADD HL,ss : 0x09|(ss<<4) - * ADD SP,n : 0xE8 - * AND A,n : 0xE6 - * AND A,r : 0xA0|r - * BIT n3,r : 0xCB 0x40|(n3<<3)|r - * CALL cc,nn : 0xC4|(cc<<3) - * CALL nn : 0xCD - * CCF : 0x3F - * CP A,n : 0xFE - * CP A,r : 0xB8|r - * CPL : 0x2F - * DAA : 0x27 - * DEC r : 0x05|(r<<3) - * DEC ss : 0x0B|(ss<<4) - * DI : 0xF3 - * EI : 0xFB - * HALT : 0x76 - * INC r : 0x04|(r<<3) - * INC ss : 0x03|(ss<<4) - * JP HL : 0xE9 - * JP cc,nn : 0xC2|(cc<<3) - * JP nn : 0xC3|(cc<<3) - * JR n : 0x18 - * JR cc,n : 0x20|(cc<<3) - * LD (nn),SP : 0x08 - * LD ($FF00+C),A : 0xE2 - * LD ($FF00+n),A : 0xE0 - * LD (nn),A : 0xEA - * LD (rr),A : 0x02|(rr<<4) // HL+ and HL- included - * LD A,($FF00+C) : 0xF2 - * LD A,($FF00+n) : 0xF0 - * LD A,(nn) : 0xFA - * LD A,(rr) : 0x0A|(rr<<4) // HL+ and HL- included - * LD HL,SP+n : 0xF8 - * LD SP,HL : 0xF9 - * LD r,n : 0x06|(r<<3) - * LD r,r' : 0x40|(r<<3)|r' // NOTE: LD (HL),(HL) not allowed - * LD ss,nn : 0x01|(ss<<4) - * NOP : 0x00 - * OR A,n : 0xF6 - * OR A,r : 0xB0|r - * POP tt : 0xC1|(tt<<4) - * PUSH tt : 0xC5|(tt<<4) - * RES n3,r : 0xCB 0x80|(n3<<3)|r - * RET : 0xC9 - * RET cc : 0xC0|(cc<<3) - * RETI : 0xD9 - * RL r : 0xCB 0x10|r - * RLA : 0x17 - * RLC r : 0xCB 0x00|r - * RLCA : 0x07 - * RR r : 0xCB 0x18|r - * RRA : 0x1F - * RRC r : 0xCB 0x08|r - * RRCA : 0x0F - * RST n : 0xC7|n - * SBC A,n : 0xDE - * SBC A,r : 0x98|r - * SCF : 0x37 - * SET n3,r : 0xCB 0xC0|(n8<<3)|r - * SLA r : 0xCB 0x20|r - * SRA r : 0xCB 0x28|r - * SRL r : 0xCB 0x38|r - * STOP : 0x10 0x00 - * SUB A,n : 0xD6 - * SUB A,r : 0x90|r - * SWAP r : 0xCB 0x30|r - * XOR A,n : 0xEE - * XOR A,r : 0xA8|r - */ - -/* "r" defs */ -enum { - REG_B = 0, - REG_C, - REG_D, - REG_E, - REG_H, - REG_L, - REG_HL_IND, - REG_A -}; - -/* "rr" defs */ -enum { - REG_BC_IND = 0, - REG_DE_IND, - REG_HL_INDINC, - REG_HL_INDDEC, -}; - -/* "ss" defs (SP) and "tt" defs (AF) */ -enum { - REG_BC = 0, - REG_DE = 1, - REG_HL = 2, - REG_SP = 3, - REG_AF = 3 -}; - -/* "cc" defs */ -enum { - CC_NZ = 0, - CC_Z, - CC_NC, - CC_C -}; - -#endif /* RGBDS_ASM_LOCALASM_H */ diff --git a/include/asm/output.h b/include/asm/output.h index 6f8895b6..bad90203 100644 --- a/include/asm/output.h +++ b/include/asm/output.h @@ -14,6 +14,7 @@ #include "linkdefs.h" struct Expression; +struct FileStackNode; extern char *tzObjectname; extern struct Section *pSectionList, *pCurrentSection; diff --git a/src/asm/charmap.c b/src/asm/charmap.c index aa3c584c..62f2da4a 100644 --- a/src/asm/charmap.c +++ b/src/asm/charmap.c @@ -13,7 +13,6 @@ #include #include -#include "asm/asm.h" #include "asm/charmap.h" #include "asm/main.h" #include "asm/output.h" diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 802d377f..175843d4 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -21,6 +21,8 @@ #include "asm/warning.h" #include "platform.h" /* S_ISDIR (stat macro) */ +#define MAXINCPATHS 128 + #ifdef LEXER_DEBUG #define dbgPrint(...) fprintf(stderr, "[lexer] " __VA_ARGS__) #else diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 6ab49053..a92dbe01 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -27,7 +27,6 @@ #include "extern/utf8decoder.h" #include "platform.h" /* For `ssize_t` */ -#include "asm/asm.h" #include "asm/lexer.h" #include "asm/format.h" #include "asm/fstack.h" diff --git a/src/asm/macro.c b/src/asm/macro.c index ff9c723f..e478d06e 100644 --- a/src/asm/macro.c +++ b/src/asm/macro.c @@ -6,10 +6,11 @@ #include #include -#include "asm/asm.h" #include "asm/macro.h" #include "asm/warning.h" +#define MAXMACROARGS 99999 + /* * Your average macro invocation does not go past the tens, but some go further * This ensures that sane and slightly insane invocations suffer no penalties, diff --git a/src/asm/output.c b/src/asm/output.c index 30f2b7ff..0481bba5 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -18,7 +18,6 @@ #include #include -#include "asm/asm.h" #include "asm/charmap.h" #include "asm/fstack.h" #include "asm/main.h" diff --git a/src/asm/parser.y b/src/asm/parser.y index 612530dc..c3feda54 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -16,7 +16,6 @@ #include #include -#include "asm/asm.h" #include "asm/charmap.h" #include "asm/format.h" #include "asm/fstack.h" @@ -354,6 +353,41 @@ void yyerror(char const *str) free(buf); } +// The CPU encodes instructions in a logical way, so most instructions actually follow patterns. +// These enums thus help with bit twiddling to compute opcodes +enum { + REG_B = 0, + REG_C, + REG_D, + REG_E, + REG_H, + REG_L, + REG_HL_IND, + REG_A +}; + +enum { + REG_BC_IND = 0, + REG_DE_IND, + REG_HL_INDINC, + REG_HL_INDDEC, +}; + +enum { + REG_BC = 0, + REG_DE = 1, + REG_HL = 2, + REG_SP = 3, + REG_AF = 3 +}; + +enum { + CC_NZ = 0, + CC_Z, + CC_NC, + CC_C +}; + %} %union diff --git a/src/asm/rpn.c b/src/asm/rpn.c index 4268edc6..21bbc6c9 100644 --- a/src/asm/rpn.c +++ b/src/asm/rpn.c @@ -15,10 +15,11 @@ #include #include #include +#include #include -#include "asm/asm.h" #include "asm/main.h" +#include "asm/output.h" #include "asm/rpn.h" #include "asm/section.h" #include "asm/symbol.h" diff --git a/src/asm/section.c b/src/asm/section.c index a8d0746f..f96de32a 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -11,6 +11,7 @@ #include "asm/output.h" #include "asm/rpn.h" #include "asm/section.h" +#include "asm/symbol.h" #include "asm/warning.h" #include "extern/err.h" diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 70bafff9..d59b266d 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -18,7 +18,6 @@ #include #include -#include "asm/asm.h" #include "asm/fstack.h" #include "asm/macro.h" #include "asm/main.h" diff --git a/src/asm/warning.c b/src/asm/warning.c index dcc166be..69b973b0 100644 --- a/src/asm/warning.c +++ b/src/asm/warning.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "asm/fstack.h"