summaryrefslogtreecommitdiff
path: root/asmmon.h
diff options
context:
space:
mode:
Diffstat (limited to 'asmmon.h')
-rw-r--r--asmmon.h250
1 files changed, 242 insertions, 8 deletions
diff --git a/asmmon.h b/asmmon.h
index a126f16..54b2ab7 100644
--- a/asmmon.h
+++ b/asmmon.h
@@ -2,11 +2,42 @@
#include <ctype.h>
#include <string.h>
-#define debug 1
-
char lexeme[0x1000];
uint8_t lex_type;
+enum {
+ DIR_ORG,
+ DIR_BYTE,
+ DIR_WORD,
+ DIR_DWORD,
+ DIR_QWORD,
+ DIR_INCLUDE
+};
+
+enum {
+ TOK_DIR,
+ TOK_LABEL,
+ TOK_SYM,
+ TOK_PLUS,
+ TOK_MINUS,
+ TOK_STRING,
+ TOK_CHAR,
+ TOK_IMM,
+ TOK_OPCODE,
+ TOK_RS,
+ TOK_COMMENT,
+ TOK_HEX,
+ TOK_DEC,
+ TOK_BIN,
+ TOK_INCLUDE
+};
+
+enum {
+ BASE_HEX,
+ BASE_DEC,
+ BASE_BIN
+};
+
static const uint8_t opcodes[OPNUM][9] = {
/* IMM ZM ZMX ZMY IND INDX INDY ABS IMPL*/
[ 0] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
@@ -101,12 +132,13 @@ static const uint8_t opcodes[OPNUM][9] = {
[89] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE}
};
-static const char *dir_t[5] = {
+static const char *dir_t[6] = {
[0] = "org",
[1] = "byte",
[2] = "word",
[3] = "dword",
- [4] = "qword"
+ [4] = "qword",
+ [5] = "include"
};
static const char *rs_t[4] = {
@@ -116,7 +148,7 @@ static const char *rs_t[4] = {
[3] = ".q"
};
-static const char *lex_tok[14] = {
+static const char *lex_tok[15] = {
[0x0] = "TOK_DIR",
[0x1] = "TOK_LABEL",
[0x2] = "TOK_SYM",
@@ -130,7 +162,206 @@ static const char *lex_tok[14] = {
[0xA] = "TOK_COMMENT",
[0xB] = "TOK_HEX",
[0xC] = "TOK_DEC",
- [0xD] = "TOK_BIN"
+ [0xD] = "TOK_BIN",
+ [0xE] = "TOK_INCLUDE"
+};
+
+static const char *adrmode[9] = {
+ [IMM ] = "IMM",
+ [ZM ] = "ZM",
+ [ZMX ] = "ZMX",
+ [ZMY ] = "ZMY",
+ [IND ] = "IND",
+ [INDX] = "INDX",
+ [INDY] = "INDY",
+ [ABS ] = "ABS",
+ [IMPL] = "IMPL"
+};
+
+static const char *mne[OPNUM] = {
+ [ 0] = "CPS",
+ [ 1] = "ADC",
+ [ 2] = "AAB",
+ [ 3] = "PHP",
+ [ 4] = "CPB",
+ [ 5] = "PHB",
+ [ 6] = "DEC",
+ [ 7] = "JMP",
+ [ 8] = "SBC",
+ [ 9] = "SAB",
+ [10] = "ENT",
+ [11] = "CPY",
+ [12] = "PLB",
+ [13] = "INC",
+ [14] = "JSR",
+ [15] = "JSL",
+ [16] = "AND",
+ [17] = "ABA",
+ [18] = "PLP",
+ [19] = "CPX",
+ [20] = "PHY",
+ [21] = "BPO",
+ [22] = "ORA",
+ [23] = "OAB",
+ [24] = "STT",
+ [25] = "PLY",
+ [26] = "BNG",
+ [27] = "XOR",
+ [28] = "XAB",
+ [29] = "PHA",
+ [30] = "PHX",
+ [31] = "BCS",
+ [32] = "LSL",
+ [33] = "LLB",
+ [34] = "CLC",
+ [35] = "PLX",
+ [36] = "BCC",
+ [37] = "LSR",
+ [38] = "LRB",
+ [39] = "PLA",
+ [40] = "TAB",
+ [41] = "BEQ",
+ [42] = "ROL",
+ [43] = "RLB",
+ [44] = "SEC",
+ [45] = "TBA",
+ [46] = "BNE",
+ [47] = "ROR",
+ [48] = "RRB",
+ [49] = "DEY",
+ [50] = "TAY",
+ [51] = "BVS",
+ [52] = "MUL",
+ [53] = "MAB",
+ [54] = "CLI",
+ [55] = "TYA",
+ [56] = "BVC",
+ [57] = "DIV",
+ [58] = "DAB",
+ [59] = "INY",
+ [60] = "TAX",
+ [61] = "RTS",
+ [62] = "RTL",
+ [63] = "CMP",
+ [64] = "CAB",
+ [65] = "SEI",
+ [66] = "LDX",
+ [67] = "TXA",
+ [68] = "RTI",
+ [69] = "LDA",
+ [70] = "DEX",
+ [71] = "CLV",
+ [72] = "TYX",
+ [73] = "STA",
+ [74] = "TSX",
+ [75] = "LDB",
+ [76] = "INX",
+ [77] = "WAI",
+ [78] = "TXY",
+ [79] = "STB",
+ [80] = "TXS",
+ [81] = "LDY",
+ [82] = "BRK",
+ [83] = "NOP",
+ [84] = "STY",
+ [85] = "DEB",
+ [86] = "ASR",
+ [87] = "ARB",
+ [88] = "STX",
+ [89] = "INB"
+};
+
+static const char *instdesc[OPNUM] = {
+ [ 0] = "Clears the Processor Status register.",
+ [ 1] = "ADd accumulator, with operand, Carry if needed.",
+ [ 2] = "Add Accumulator, with B, carry if needed.",
+ [ 3] = "PusH the number of bytes specified, from the Processor status register to the stack.",
+ [ 4] = "ComPare the B register, with operand.",
+ [ 5] = "PusH the number of bytes specified, from the B register to the stack.",
+ [ 6] = "DECrement accumulator, or memory.",
+ [ 7] = "JuMP to the address specified.",
+ [ 8] = "SuBtract accumulator, with operand, Carry if needed",
+ [ 9] = "Subtract Accumulator, with B, carry if needed.",
+ [10] = "ENd a Thread.",
+ [11] = "ComPare the Y register, with operand.",
+ [12] = "PuLl the number of bytes specified, from the stack, to the B register.",
+ [13] = "INCrement accumulator, or memory.",
+ [14] = "Jump to a SubRoutine.",
+ [15] = "Jump to a Subroutine, Long address.",
+ [16] = "Bitwise AND accumulator, with operand.",
+ [17] = "Bitwise AND Accumulator, with B.",
+ [18] = "PuLl the number of bytes specified, from the stack, to the Processor status register.",
+ [19] = "ComPare the X register, with operand.",
+ [20] = "PusH the number of bytes specified, from the Y register to the stack.",
+ [21] = "Branch if POsitive.",
+ [22] = "Bitwise OR Accumulator, with operand.",
+ [23] = "Bitwise OR Accumulator, with B.",
+ [24] = "STart a Thread.",
+ [25] = "PuLl the number of bytes specified, from the stack, to the Y register.",
+ [26] = "Branch if NeGative.",
+ [27] = "Bitwise XOR Accumulator, with operand.",
+ [28] = "Bitwise XOR Accumulator, with B.",
+ [29] = "PusH the number of bytes specified, from the Accumulator to the stack.",
+ [30] = "PusH the number of bytes specified, from the X register to the stack.",
+ [31] = "Branch if the Carry flag is Set.",
+ [32] = "Logical Shift Left accumulator, with operand.",
+ [33] = "Logical Shift Left accumulator, with B.",
+ [34] = "CLear the Carry flag.",
+ [35] = "PuLl the number of bytes specified, from the stack, to the X register.",
+ [36] = "Branch if the Carry flag has been Cleared.",
+ [37] = "Logical Shift Right accumulator, with operand.",
+ [38] = "Logical Shift Right accumulator, with B.",
+ [39] = "PuLl the number of bytes specified, from the stack, to the Accumulator.",
+ [40] = "Transfer the value from the Accumulator, to the B register.",
+ [41] = "Branch if EQual (the zero flag has been set).",
+ [42] = "ROtate Left accumulator, with operand.",
+ [43] = "Rotate Left accumulator, with B.",
+ [44] = "SEt the Carry flag.",
+ [45] = "Transfer the value from the Y register, to the Accumulator.",
+ [46] = "Branch if Not Equal (the zero flag has been cleared)",
+ [47] = "ROtate Right accumulator, with operand.",
+ [48] = "Rotate Right accumulator, with B.",
+ [49] = "DEcrement the Y register.",
+ [50] = "Transfer the value from the Accumulator, to the Y register.",
+ [51] = "Branch if the oVerflow flag is Set.",
+ [52] = "MULtiply accumulator, with operand.",
+ [53] = "Multiply Accumulator, with B.",
+ [54] = "CLear the Interrupt flag.",
+ [55] = "Transfer the value from the Y register, to the Accumulator.",
+ [56] = "Branch if the oVerflow flag has been Cleared.",
+ [57] = "DIVide accumulator, with operand, and put the remainder into the B register.",
+ [58] = "Divide Accumulator, with B, and put the remainder into the X register.",
+ [59] = "INcrement the Y register.",
+ [60] = "Transfer the value from the Accumulator, to the X register.",
+ [61] = "ReTurn from a Subroutine.",
+ [62] = "ReTurn from subroutine, Long address.",
+ [63] = "CoMPare acumulator, with operand.",
+ [64] = "Compare Accumulator, with B.",
+ [65] = "SEt the Interrupt flag.",
+ [66] = "LoaD the value from the operand, to the X register.",
+ [67] = "Transfer the value from the X register, to the Accumulator.",
+ [68] = "ReTurn from an Interrupt.",
+ [69] = "LoaD the value from the operand, to the Accumulator.",
+ [70] = "DEcrement the X register.",
+ [71] = "CLear the oVerflow flag.",
+ [72] = "Transfer the value from the Y register, to the X register.",
+ [73] = "STore the value from the Accumulator, in memory.",
+ [74] = "Transfer the value from the Stack pointer, to the X register.",
+ [75] = "LoaD the value from the operand, to the B register.",
+ [76] = "INcrement the X register.",
+ [77] = "WAIt for an interrupt",
+ [78] = "Transfer the value from the X register, to the Y register.",
+ [79] = "STore the value from the B register, in memory.",
+ [80] = "Transfer the value from the X register, to the Stack pointer.",
+ [81] = "LoaD the value from the operand, to the Y register.",
+ [82] = "BReaKpoint",
+ [83] = "NO oPeration",
+ [84] = "STore the value from the Y register, in memory.",
+ [85] = "DEcrement the B register.",
+ [86] = "Arithmetic Shift Right accumulator, with operand.",
+ [87] = "Arithmetic shift Right accumulator, with B.",
+ [88] = "STore the value from the X register, in memory.",
+ [89] = "INcrement the B register."
};
static const uint8_t bitsize[4] = {
@@ -168,6 +399,7 @@ struct line {
uint16_t sym;
uint16_t com;
uint16_t str;
+ uint16_t incl;
uint16_t linenum;
uint64_t op;
uint64_t aop;
@@ -181,8 +413,10 @@ extern uint16_t comidx;
char *string[0x1000];
char *comment[0x1000];
+uint16_t incl[0x1000];
struct line tokline[0x1000];
+struct line tln[0x1000];
struct fixup {
struct symbol *s;
@@ -209,5 +443,5 @@ extern uint8_t set_symval(const char *name, uint16_t id, uint64_t val, uint8_t u
extern char *get_symname(uint16_t id, uint8_t dbg);
extern uint16_t get_symid(const char *name, uint64_t val, uint16_t ln, uint8_t dbg);
extern uint16_t get_comment(const char *cmnt, uint8_t dbg);
-extern uint16_t reslv_fixups(uint8_t dbg);
-extern uint64_t lex(char *str, uint64_t address, uint8_t dbg);
+extern uint16_t reslv_fixups(struct line *l, uint8_t dbg);
+extern uint64_t lex(char *str, struct line *l, uint64_t address, uint8_t dbg);