#include "opcode.h" #include #include #define MAX_TOK 0x1000 #define TXS_MNE_ID 78 /* Used for a special case in the assembler. */ typedef struct tok token ; typedef struct ln line ; typedef struct sym symbol; typedef struct fix fixup ; struct tok { token *next; /* Pointer to the next token. */ uint8_t id; /* Token ID. */ uint8_t type; /* Token type ID. */ /* Token value(s). */ union { symbol *sym; char *str; uint8_t byte ; uint16_t word ; uint32_t dword; uint64_t qword; }; }; struct ln { line *next; /* Pointer to the next line. */ token *tok; /* The token(s) for this line. */ uint16_t count; /* Total tokens for this line. */ uint32_t linenum; /* Line number. */ uint64_t addr; /* The address of this line. */ uint8_t stab; /* Number of starting tabs. */ uint8_t sspace; /* Number of starting spaces. */ uint8_t etab; /* Number of ending tabs. */ uint8_t espace; /* Number of ending spaces. */ }; struct fix { fixup *next; symbol *s; token *t; uint64_t adr; }; struct sym { symbol *next; symbol *local; uint16_t count; uint64_t val; uint8_t def; char *name; uint16_t id; }; extern char lexeme[]; extern char *string[]; extern char *comment[]; extern uint16_t incl[]; extern line *lines; extern line *last_line; extern token *tokens; extern token *last_tok; extern symbol *symbols; extern symbol *locals; extern fixup *fixups; extern uint8_t lex_type; enum dir { DIR_ORG, DIR_BYTE, DIR_WORD, DIR_DWORD, DIR_QWORD, DIR_INCLUDE }; enum token { TOK_DIR, TOK_LOCAL, TOK_LABEL, TOK_SYM, TOK_EXPR, TOK_CSV, TOK_STRING, TOK_CHAR, TOK_IND, TOK_IMM, TOK_OPCODE, TOK_RS, TOK_OF, TOK_COMMENT, TOK_HEX, TOK_DEC, TOK_BIN, TOK_INCLUDE }; enum pre_token { PTOK_DOT, PTOK_AT, PTOK_COLON, PTOK_EQU, PTOK_PLUS, PTOK_MINUS, PTOK_GT, PTOK_LT, PTOK_LBRACK, PTOK_RBRACK, PTOK_COMMA, PTOK_X, PTOK_Y, PTOK_S, PTOK_P, PTOK_DQUOTE, PTOK_SQUOTE, PTOK_HASH, PTOK_SCOLON, PTOK_DOLLAR, PTOK_PERCENT, PTOK_NUMBER, PTOK_ALPHA, PTOK_OTHER }; enum expr { EXPR_PLUS, EXPR_MINUS, EXPR_LOW, EXPR_HIGH, EXPR_NONE }; static const uint8_t opcodes[OPNUM][10] = { /* IMM ZM ZMX ZMY IND INDX INDY ABS REL IMPL*/ [AAB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02}, /* AAB */ [ABA] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x22}, /* ABA */ [ADC] = {0x01, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x04, 0xFF, 0xFF}, /* ADC */ [AND] = {0x21, 0x26, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x24, 0xFF, 0xFF}, /* AND */ [ARB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF2}, /* ARB */ [ASR] = {0xF1, 0xF6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF4, 0xFF, 0xFF}, /* ASR */ [BCC] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0xFF}, /* BCC */ [BCS] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x70, 0xFF}, /* BCS */ [BEQ] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x90, 0xFF}, /* BEQ */ [BNE] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xA0, 0xFF}, /* BNE */ [BNG] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x60, 0xFF}, /* BNG */ [BPO] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x50, 0xFF}, /* BPO */ [BRA] = {0xFF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{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC2}, /* DEB */ [DEC] = {0xFF, 0x0D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0xFF, 0x0A}, /* DEC */ [DEX] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x09}, /* DEX */ [DEY] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x29}, /* DEY */ [DIV] = {0xA1, 0xA6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xA4, 0xFF, 0xFF}, /* DIV */ [INB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xD2}, /* INB */ [INC] = {0xFF, 0x1D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1C, 0xFF, 0x1A}, /* INC */ [INX] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x19}, /* INX */ [INY] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x39}, /* INY */ [JMP] = {0xFF, 0x30, 0xFF, 0xFF, 0xB5, 0xFF, 0xFF, 0x10, 0xFF, 0xFF}, /* JMP */ [JSR] = {0xFF, 0x40, 0xFF, 0xFF, 0xA5, 0xFF, 0xFF, 0x20, 0xFF, 0xFF}, /* JSR */ [LDA] = {0xC1, 0xC6, 0xB8, 0x78, 0x05, 0x5D, 0x5C, 0xC4, 0xFF, 0xFF}, /* LDA */ [LDB] = {0xD1, 0xD6, 0xD8, 0x98, 0x35, 0x8D, 0x8C, 0xD4, 0xFF, 0xFF}, /* LDB */ [LDX] = {0xB9, 0xBD, 0xFF, 0xFF, 0x85, 0xFF, 0xFF, 0xBC, 0xFF, 0xFF}, /* LDX */ [LDY] = {0xE1, 0xE6, 0xFF, 0xFF, 0x65, 0xFF, 0xFF, 0xE4, 0xFF, 0xFF}, /* LDY */ [LLB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x52}, /* LLB */ [LRB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x62}, /* LRB */ [LSL] = {0x51, 0x56, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0xFF, 0xFF}, /* LSL */ [LSR] = {0x61, 0x66, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x64, 0xFF, 0xFF}, /* LSR */ [MAB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x92}, /* MAB */ [MUL] = {0x91, 0x96, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x94, 0xFF, 0xFF}, /* MUL */ [NOP] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEA}, /* NOP */ [OAB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x32}, /* OAB */ [ORA] = {0x31, 0x36, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x34, 0xFF, 0xFF}, /* ORA */ [PHA] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x79}, /* PHA */ [PHB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x99}, /* PHB */ [PHP] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x59}, /* PHP */ [PHX] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE9}, /* PHX */ [PHY] = {0xFF, 0xFF, 0xFF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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x8A}, /* TYA */ [TYX] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBA}, /* TYX */ [WAI] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x58}, /* WAI */ [XAB] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x42}, /* XAB */ [XOR] = {0x41, 0x46, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x44, 0xFF, 0xFF} /* XOR */ }; static const char *dir_t[6] = { [0] = "org", [1] = "byte", [2] = "word", [3] = "dword", [4] = "qword", [5] = "include" }; static const char *rs_t[4] = { [0] = "", [1] = ".w", [2] = ".d", [3] = ".q" }; static const char *lex_tok[18] = { [TOK_DIR ] = "TOK_DIR", [TOK_LOCAL ] = "TOK_LOCAL", [TOK_LABEL ] = "TOK_LABEL", [TOK_SYM ] = "TOK_SYM", [TOK_EXPR ] = "TOK_EXPR", [TOK_CSV ] = "TOK_CSV", [TOK_STRING ] = "TOK_STRING", [TOK_CHAR ] = "TOK_CHAR", [TOK_IND ] = "TOK_IND", [TOK_IMM ] = "TOK_IMM", [TOK_OPCODE ] = "TOK_OPCODE", [TOK_RS ] = "TOK_RS", [TOK_OF ] = "TOK_OF", [TOK_COMMENT] = "TOK_COMMENT", [TOK_HEX ] = "TOK_HEX", [TOK_DEC ] = "TOK_DEC", [TOK_BIN ] = "TOK_BIN", [TOK_INCLUDE] = "TOK_INCLUDE" }; static const char *adrmode[10] = { [IMM ] = "IMM", [ZM ] = "ZM", [ZMX ] = "ZMX", [ZMY ] = "ZMY", [IND ] = "IND", [INDX] = "INDX", [INDY] = "INDY", [ABS ] = "ABS", [REL ] = "REL", [IMPL] = "IMPL" }; static const char *mne[OPNUM] = { [AAB] = "AAB", [ABA] = "ABA", [ADC] = "ADC", [AND] = "AND", [ARB] = "ARB", [ASR] = "ASR", [BCC] = "BCC", [BCS] = "BCS", [BEQ] = "BEQ", [BNE] = "BNE", [BNG] = "BNG", [BPO] = "BPO", [BRA] = "BRA", [BRK] = "BRK", [BVC] = "BVC", [BVS] = "BVS", [CAB] = "CAB", [CLC] = "CLC", [CLI] = "CLI", [CLV] = "CLV", [CMP] = "CMP", [CPB] = "CPB", [CPS] = "CPS", [CPX] = "CPX", [CPY] = "CPY", [DAB] = "DAB", [DEB] = "DEB", [DEC] = "DEC", [DEX] = "DEX", [DEY] = "DEY", [DIV] = "DIV", [INB] = "INB", [INC] = "INC", [INX] = "INX", [INY] = "INY", [JMP] = "JMP", [JSR] = "JSR", [LDA] = "LDA", [LDB] = "LDB", [LDX] = "LDX", [LDY] = "LDY", [LLB] = "LLB", [LRB] = "LRB", [LSL] = "LSL", [LSR] = "LSR", [MAB] = "MAB", [MUL] = "MUL", [NOP] = "NOP", [OAB] = "OAB", [ORA] = "ORA", [PHA] = "PHA", [PHB] = "PHB", [PHP] = "PHP", [PHX] = "PHX", [PHY] = "PHY", [PLA] = "PLA", [PLB] = "PLB", [PLP] = "PLP", [PLX] = "PLX", [PLY] = "PLY", [RLB] = "RLB", [ROL] = "ROL", [ROR] = "ROR", [RRB] = "RRB", [RTI] = "RTI", [RTS] = "RTS", [SAB] = "SAB", [SBC] = "SBC", [SEC] = "SEC", [SEI] = "SEI", [STA] = "STA", [STB] = "STB", [STX] = "STX", [STY] = "STY", [TAB] = "TAB", [TAX] = "TAX", [TAY] = "TAY", [TBA] = "TBA", [TSX] = "TSX", [TXA] = "TXA", [TXS] = "TXS", [TXY] = "TXY", [TYA] = "TYA", [TYX] = "TYX", [WAI] = "WAI", [XAB] = "XAB", [XOR] = "XOR" }; static const char *instdesc[OPNUM] = { [AAB] = "Add Accumulator, with B, carry if needed.", [ABA] = "Bitwise AND Accumulator, with B.", [ADC] = "ADd accumulator, with operand, Carry if needed.", [AND] = "Bitwise AND accumulator, with operand.", [ARB] = "Arithmetic shift Right accumulator, with B.", [ASR] = "Arithmetic Shift Right accumulator, with operand.", [BCC] = "Branch if the Carry flag has been Cleared.", [BCS] = "Branch if the Carry flag is Set.", [BEQ] = "Branch if EQual (the zero flag has been set).", [BNE] = "Branch if Not Equal (the zero flag has been cleared)", [BNG] = "Branch if NeGative.", [BPO] = "Branch if POsitive.", [BRA] = "BRanch Always.", [BRK] = "BReaKpoint", [BVC] = "Branch if the oVerflow flag has been Cleared.", [BVS] = "Branch if the oVerflow flag is Set.", [CAB] = "Compare Accumulator, with B.", [CLC] = "CLear the Carry flag.", [CLI] = "CLear the Interrupt flag.", [CLV] = "CLear the oVerflow flag.", [CMP] = "CoMPare acumulator, with operand.", [CPB] = "ComPare the B register, with operand.", [CPS] = "Clears the Processor Status register.", [CPX] = "ComPare the X register, with operand.", [CPY] = "ComPare the Y register, with operand.", [DAB] = "Divide Accumulator, with B, and put the remainder into the X register.", [DEB] = "DEcrement the B register.", [DEC] = "DECrement accumulator, or memory.", [DEX] = "DEcrement the X register.", [DEY] = "DEcrement the Y register.", [DIV] = "DIVide accumulator, with operand, and put the remainder into the B register.", [INB] = "INcrement the B register.", [INC] = "INCrement accumulator, or memory.", [INX] = "INcrement the X register.", [INY] = "INcrement the Y register.", [JMP] = "JuMP to the address specified.", [JSR] = "Jump to a SubRoutine.", [LDA] = "LoaD the value from the operand, to the Accumulator.", [LDB] = "LoaD the value from the operand, to the B register.", [LDX] = "LoaD the value from the operand, to the X register.", [LDY] = "LoaD the value from the operand, to the Y register.", [LLB] = "Logical Shift Left accumulator, with B.", [LRB] = "Logical Shift Right accumulator, with B.", [LSL] = "Logical Shift Left accumulator, with operand.", [LSR] = "Logical Shift Right accumulator, with operand.", [MAB] = "Multiply Accumulator, with B.", [MUL] = "MULtiply accumulator, with operand.", [NOP] = "NO oPeration", [OAB] = "Bitwise OR Accumulator, with B.", [ORA] = "Bitwise OR Accumulator, with operand.", [PHA] = "PusH the number of bytes specified, from the Accumulator to the stack.", [PHB] = "PusH the number of bytes specified, from the B register to the stack.", [PHP] = "PusH the number of bytes specified, from the Processor status register to the stack.", [PHX] = "PusH the number of bytes specified, from the X register to the stack.", [PHY] = "PusH the number of bytes specified, from the Y register to the stack.", [PLA] = "PuLl the number of bytes specified, from the stack, to the Accumulator.", [PLB] = "PuLl the number of bytes specified, from the stack, to the B register.", [PLP] = "PuLl the number of bytes specified, from the stack, to the Processor status register.", [PLX] = "PuLl the number of bytes specified, from the stack, to the X register.", [PLY] = "PuLl the number of bytes specified, from the stack, to the Y register.", [RLB] = "Rotate Left accumulator, with B.", [ROL] = "ROtate Left accumulator, with operand.", [ROR] = "ROtate Right accumulator, with operand.", [RRB] = "Rotate Right accumulator, with B.", [RTI] = "ReTurn from an Interrupt.", [RTS] = "ReTurn from a Subroutine.", [SAB] = "Subtract Accumulator, with B, carry if needed.", [SBC] = "SuBtract accumulator, with operand, Carry if needed", [SEC] = "SEt the Carry flag.", [SEI] = "SEt the Interrupt flag.", [STA] = "STore the value from the Accumulator, in memory.", [STB] = "STore the value from the B register, in memory.", [STX] = "STore the value from the X register, in memory.", [STY] = "STore the value from the Y register, in memory.", [TAB] = "Transfer the value from the Accumulator, to the B register.", [TAX] = "Transfer the value from the Accumulator, to the X register.", [TAY] = "Transfer the value from the Accumulator, to the Y register.", [TBA] = "Transfer the value from the Y register, to the Accumulator.", [TSX] = "Transfer the value from the Stack pointer, to the X register.", [TXA] = "Transfer the value from the X register, to the Accumulator.", [TXS] = "Transfer the value from the X register, to the Stack pointer.", [TXY] = "Transfer the value from the X register, to the Y register.", [TYA] = "Transfer the value from the Y register, to the Accumulator.", [TYX] = "Transfer the value from the Y register, to the X register.", [WAI] = "WAIt for an interrupt", [XAB] = "Bitwise XOR Accumulator, with B.", [XOR] = "Bitwise XOR Accumulator, with operand." }; static const uint8_t bitsize[4] = { [0] = 0x07, [1] = 0x0F, [2] = 0x1F, [3] = 0x3F }; static const uint8_t amp[8] = { [0] = 0x00, [1] = 0x00, [2] = 0x07, [4] = 0x07, [5] = 0x0B, [6] = 0x0B, [3] = 0x0F, [7] = 0x0F }; extern uint16_t linenum; extern uint16_t lineidx; extern uint16_t stridx; extern uint16_t comidx; extern uint16_t inc_file; /* Number of included files. */ extern uint16_t inc_count; struct bc { uint64_t progsize; uint64_t datasize; }; typedef struct bc bytecount; extern uint8_t defined; extern uint8_t isfixup; extern line *find_line(uint32_t ln, uint8_t dbg); extern uint64_t lex(char *str, uint64_t address, uint8_t dbg); extern uint64_t parse_tokens(token *tm, bytecount *bc, uint8_t isasm, uint64_t address, uint8_t dbg); extern token *make_token(uint8_t id, uint8_t type, uint64_t value, char *str, symbol *sym); extern void assemble(line *ln, bytecount *bc, uint8_t dbg); extern void cleanup();