278 lines
11 KiB
C
278 lines
11 KiB
C
#include "cpu.h"
|
|
|
|
#define NEW_OPCODE(op, addr, cyc, len, ill) {op, addr, cyc, len, ill, #op}
|
|
|
|
const struct Opcode OPCODE_TABLE[256] =
|
|
{
|
|
/* 00 */ NEW_OPCODE(BRK, IMP, 7, 1, 0),
|
|
/* 01 */ NEW_OPCODE(ORA, INDX, 6, 2, 0),
|
|
/* 02 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 03 */ NEW_OPCODE(SLO, INDX, 8, 2, 1),
|
|
/* 04 */ NEW_OPCODE(NOP, ZPG, 3, 2, 1),
|
|
/* 05 */ NEW_OPCODE(ORA, ZPG, 3, 2, 0),
|
|
/* 06 */ NEW_OPCODE(ASL, ZPG, 5, 2, 0),
|
|
/* 07 */ NEW_OPCODE(SLO, ZPG, 5, 2, 1),
|
|
/* 08 */ NEW_OPCODE(PHP, IMP, 3, 1, 0),
|
|
/* 09 */ NEW_OPCODE(ORA, IMM, 2, 2, 0),
|
|
/* 0A */ NEW_OPCODE(ASL, ACC, 2, 1, 0),
|
|
/* 0B */ NEW_OPCODE(ANC, IMM, 2, 2, 1),
|
|
/* 0C */ NEW_OPCODE(NOP, ABS, 4, 3, 1),
|
|
/* 0D */ NEW_OPCODE(ORA, ABS, 4, 3, 0),
|
|
/* 0E */ NEW_OPCODE(ASL, ABS, 6, 3, 0),
|
|
/* 0F */ NEW_OPCODE(SLO, ABS, 6, 3, 1),
|
|
|
|
/* 10 */ NEW_OPCODE(BPL, REL, 2, 2, 0),
|
|
/* 11 */ NEW_OPCODE(ORA, INDY, 5, 2, 0),
|
|
/* 12 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 13 */ NEW_OPCODE(SLO, INDY, 8, 2, 1),
|
|
/* 14 */ NEW_OPCODE(NOP, ZPX, 4, 2, 1),
|
|
/* 15 */ NEW_OPCODE(ORA, ZPX, 4, 2, 0),
|
|
/* 16 */ NEW_OPCODE(ASL, ZPX, 6, 2, 0),
|
|
/* 17 */ NEW_OPCODE(SLO, ZPX, 6, 2, 1),
|
|
/* 18 */ NEW_OPCODE(CLC, IMP, 2, 1, 0),
|
|
/* 19 */ NEW_OPCODE(ORA, ABY, 4, 3, 0),
|
|
/* 1A */ NEW_OPCODE(NOP, IMP, 2, 1, 1),
|
|
/* 1B */ NEW_OPCODE(SLO, ABY, 7, 3, 1),
|
|
/* 1C */ NEW_OPCODE(NOP, ABX, 4, 3, 1),
|
|
/* 1D */ NEW_OPCODE(ORA, ABX, 4, 3, 0),
|
|
/* 1E */ NEW_OPCODE(ASL, ABX, 7, 3, 0),
|
|
/* 1F */ NEW_OPCODE(SLO, ABX, 7, 3, 1),
|
|
|
|
/* 20 */ NEW_OPCODE(JSR, ABS, 6, 3, 0),
|
|
/* 21 */ NEW_OPCODE(AND, INDX, 6, 2, 0),
|
|
/* 22 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 23 */ NEW_OPCODE(RLA, INDX, 8, 2, 1),
|
|
/* 24 */ NEW_OPCODE(BIT, ZPG, 3, 2, 0),
|
|
/* 25 */ NEW_OPCODE(AND, ZPG, 3, 2, 0),
|
|
/* 26 */ NEW_OPCODE(ROL, ZPG, 5, 2, 0),
|
|
/* 27 */ NEW_OPCODE(RLA, ZPG, 5, 2, 1),
|
|
/* 28 */ NEW_OPCODE(PLP, IMP, 4, 1, 0),
|
|
/* 29 */ NEW_OPCODE(AND, IMM, 2, 2, 0),
|
|
/* 2A */ NEW_OPCODE(ROL, ACC, 2, 1, 0),
|
|
/* 2B */ NEW_OPCODE(ANC, IMM, 2, 2, 1),
|
|
/* 2C */ NEW_OPCODE(BIT, ABS, 4, 3, 0),
|
|
/* 2D */ NEW_OPCODE(AND, ABS, 4, 3, 0),
|
|
/* 2E */ NEW_OPCODE(ROL, ABS, 6, 3, 0),
|
|
/* 2F */ NEW_OPCODE(RLA, ABS, 6, 3, 1),
|
|
|
|
/* 30 */ NEW_OPCODE(BMI, REL, 2, 2, 0),
|
|
/* 31 */ NEW_OPCODE(AND, INDY, 5, 2, 0),
|
|
/* 32 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 33 */ NEW_OPCODE(RLA, INDY, 8, 2, 1),
|
|
/* 34 */ NEW_OPCODE(NOP, ZPX, 4, 2, 1),
|
|
/* 35 */ NEW_OPCODE(AND, ZPX, 4, 2, 0),
|
|
/* 36 */ NEW_OPCODE(ROL, ZPX, 6, 2, 0),
|
|
/* 37 */ NEW_OPCODE(RLA, ZPX, 6, 2, 1),
|
|
/* 38 */ NEW_OPCODE(SEC, IMP, 2, 1, 0),
|
|
/* 39 */ NEW_OPCODE(AND, ABY, 4, 3, 0),
|
|
/* 3A */ NEW_OPCODE(NOP, IMP, 2, 1, 1),
|
|
/* 3B */ NEW_OPCODE(RLA, ABY, 7, 3, 1),
|
|
/* 3C */ NEW_OPCODE(NOP, ABX, 4, 3, 1),
|
|
/* 3D */ NEW_OPCODE(AND, ABX, 4, 3, 0),
|
|
/* 3E */ NEW_OPCODE(ROL, ABX, 7, 3, 0),
|
|
/* 3F */ NEW_OPCODE(RLA, ABX, 7, 3, 0),
|
|
|
|
/* 40 */ NEW_OPCODE(RTI, IMP, 6, 1, 0),
|
|
/* 41 */ NEW_OPCODE(EOR, INDX, 6, 2, 0),
|
|
/* 42 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 43 */ NEW_OPCODE(SRE, INDX, 8, 2, 1),
|
|
/* 44 */ NEW_OPCODE(NOP, ZPG, 3, 2, 1),
|
|
/* 45 */ NEW_OPCODE(EOR, ZPG, 3, 2, 0),
|
|
/* 46 */ NEW_OPCODE(LSR, ZPG, 5, 2, 0),
|
|
/* 47 */ NEW_OPCODE(SRE, ZPG, 5, 2, 1),
|
|
/* 48 */ NEW_OPCODE(PHA, IMP, 3, 1, 0),
|
|
/* 49 */ NEW_OPCODE(EOR, IMM, 2, 2, 0),
|
|
/* 4A */ NEW_OPCODE(LSR, ACC, 2, 1, 0),
|
|
/* 4B */ NEW_OPCODE(ASR, IMM, 2, 2, 1),
|
|
/* 4C */ NEW_OPCODE(JMP, ABS, 3, 3, 0),
|
|
/* 4D */ NEW_OPCODE(EOR, ABS, 4, 3, 0),
|
|
/* 4E */ NEW_OPCODE(LSR, ABS, 6, 3, 0),
|
|
/* 4F */ NEW_OPCODE(SRE, ABS, 6, 3, 1),
|
|
|
|
/* 50 */ NEW_OPCODE(BVC, REL, 2, 2, 0),
|
|
/* 51 */ NEW_OPCODE(EOR, INDY, 5, 2, 0),
|
|
/* 52 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 53 */ NEW_OPCODE(SRE, INDY, 8, 2, 1),
|
|
/* 54 */ NEW_OPCODE(NOP, ZPX, 4, 2, 1),
|
|
/* 55 */ NEW_OPCODE(EOR, ZPX, 4, 2, 0),
|
|
/* 56 */ NEW_OPCODE(LSR, ZPX, 6, 2, 0),
|
|
/* 57 */ NEW_OPCODE(SRE, ZPX, 6, 2, 1),
|
|
/* 58 */ NEW_OPCODE(CLI, IMP, 2, 1, 0),
|
|
/* 59 */ NEW_OPCODE(EOR, ABY, 4, 3, 0),
|
|
/* 5A */ NEW_OPCODE(NOP, IMP, 2, 1, 1),
|
|
/* 5B */ NEW_OPCODE(SRE, ABY, 7, 3, 1),
|
|
/* 5C */ NEW_OPCODE(NOP, ABX, 4, 3, 1),
|
|
/* 5D */ NEW_OPCODE(EOR, ABX, 4, 3, 0),
|
|
/* 5E */ NEW_OPCODE(LSR, ABX, 7, 3, 0),
|
|
/* 5F */ NEW_OPCODE(SRE, ABX, 7, 3, 1),
|
|
|
|
/* 60 */ NEW_OPCODE(RTS, IMP, 6, 1, 0),
|
|
/* 61 */ NEW_OPCODE(ADC, INDX, 6, 2, 0),
|
|
/* 62 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 63 */ NEW_OPCODE(RRA, INDX, 8, 2, 1),
|
|
/* 64 */ NEW_OPCODE(NOP, ZPG, 3, 2, 1),
|
|
/* 65 */ NEW_OPCODE(ADC, ZPG, 3, 2, 0),
|
|
/* 66 */ NEW_OPCODE(ROR, ZPG, 5, 2, 0),
|
|
/* 67 */ NEW_OPCODE(RRA, ZPG, 5, 2, 1),
|
|
/* 68 */ NEW_OPCODE(PLA, IMP, 4, 1, 0),
|
|
/* 69 */ NEW_OPCODE(ADC, IMM, 2, 2, 0),
|
|
/* 6A */ NEW_OPCODE(ROR, ACC, 2, 1, 0),
|
|
/* 6B */ NEW_OPCODE(ARR, IMM, 2, 2, 1),
|
|
/* 6C */ NEW_OPCODE(JMP, IND, 5, 3, 0),
|
|
/* 6D */ NEW_OPCODE(ADC, ABS, 4, 3, 0),
|
|
/* 6E */ NEW_OPCODE(ROR, ABS, 6, 3, 0),
|
|
/* 6F */ NEW_OPCODE(RRA, ABS, 6, 3, 1),
|
|
|
|
/* 70 */ NEW_OPCODE(BVS, REL, 2, 2, 0),
|
|
/* 71 */ NEW_OPCODE(ADC, INDY, 5, 2, 0),
|
|
/* 72 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 73 */ NEW_OPCODE(RRA, INDY, 8, 2, 1),
|
|
/* 74 */ NEW_OPCODE(NOP, ZPX, 4, 2, 1),
|
|
/* 75 */ NEW_OPCODE(ADC, ZPX, 4, 2, 0),
|
|
/* 76 */ NEW_OPCODE(ROR, ZPX, 6, 2, 0),
|
|
/* 77 */ NEW_OPCODE(RRA, ZPX, 6, 2, 1),
|
|
/* 78 */ NEW_OPCODE(SEI, IMP, 2, 1, 0),
|
|
/* 79 */ NEW_OPCODE(ADC, ABY, 4, 3, 0),
|
|
/* 7A */ NEW_OPCODE(NOP, IMP, 2, 1, 1),
|
|
/* 7B */ NEW_OPCODE(RRA, ABY, 7, 3, 1),
|
|
/* 7C */ NEW_OPCODE(NOP, ABX, 4, 3, 1),
|
|
/* 7D */ NEW_OPCODE(ADC, ABX, 4, 3, 0),
|
|
/* 7E */ NEW_OPCODE(ROR, ABX, 7, 3, 0),
|
|
/* 7F */ NEW_OPCODE(RRA, ABX, 7, 3, 1),
|
|
|
|
/* 80 */ NEW_OPCODE(NOP, IMM, 2, 3, 1),
|
|
/* 81 */ NEW_OPCODE(STA, INDX, 6, 2, 0),
|
|
/* 82 */ NEW_OPCODE(NOP, IMM, 2, 3, 1),
|
|
/* 83 */ NEW_OPCODE(SAX, INDX, 6, 2, 1),
|
|
/* 84 */ NEW_OPCODE(STY, ZPG, 3, 2, 0),
|
|
/* 85 */ NEW_OPCODE(STA, ZPG, 3, 2, 0),
|
|
/* 86 */ NEW_OPCODE(STX, ZPG, 3, 2, 0),
|
|
/* 87 */ NEW_OPCODE(SAX, ZPG, 3, 2, 1),
|
|
/* 88 */ NEW_OPCODE(DEY, IMP, 2, 1, 0),
|
|
/* 89 */ NEW_OPCODE(NOP, IMM, 2, 3, 1),
|
|
/* 8A */ NEW_OPCODE(TXA, IMP, 2, 1, 0),
|
|
/* 8B */ NEW_OPCODE(XAA, IMM, 2, 2, 1),
|
|
/* 8C */ NEW_OPCODE(STY, ABS, 4, 3, 0),
|
|
/* 8D */ NEW_OPCODE(STA, ABS, 4, 3, 0),
|
|
/* 8E */ NEW_OPCODE(STX, ABS, 4, 3, 0),
|
|
/* 8F */ NEW_OPCODE(SAX, ABS, 4, 3, 1),
|
|
|
|
/* 90 */ NEW_OPCODE(BCC, REL, 2, 2, 0),
|
|
/* 91 */ NEW_OPCODE(STA, INDY, 6, 2, 0),
|
|
/* 92 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* 93 */ NEW_OPCODE(SHA, INDY, 6, 2, 1),
|
|
/* 94 */ NEW_OPCODE(STY, ZPX, 4, 2, 0),
|
|
/* 95 */ NEW_OPCODE(STA, ZPX, 4, 2, 0),
|
|
/* 96 */ NEW_OPCODE(STX, ZPY, 4, 2, 0),
|
|
/* 97 */ NEW_OPCODE(SAX, ZPY, 4, 2, 1),
|
|
/* 98 */ NEW_OPCODE(TYA, IMP, 2, 1, 0),
|
|
/* 99 */ NEW_OPCODE(STA, ABY, 5, 3, 0),
|
|
/* 9A */ NEW_OPCODE(TXS, IMP, 2, 1, 0),
|
|
/* 9B */ NEW_OPCODE(SHS, ABY, 5, 3, 1),
|
|
/* 9C */ NEW_OPCODE(SHY, ABX, 5, 3, 1),
|
|
/* 9D */ NEW_OPCODE(STA, ABX, 5, 3, 0),
|
|
/* 9E */ NEW_OPCODE(SHX, ABY, 5, 3, 1),
|
|
/* 9F */ NEW_OPCODE(SHA, ABY, 5, 3, 1),
|
|
|
|
/* A0 */ NEW_OPCODE(LDY, IMM, 2, 2, 0),
|
|
/* A1 */ NEW_OPCODE(LDA, INDX, 6, 2, 0),
|
|
/* A2 */ NEW_OPCODE(LDX, IMM, 2, 2, 0),
|
|
/* A3 */ NEW_OPCODE(LAX, INDX, 6, 2, 1),
|
|
/* A4 */ NEW_OPCODE(LDY, ZPG, 3, 2, 0),
|
|
/* A5 */ NEW_OPCODE(LDA, ZPG, 3, 2, 0),
|
|
/* A6 */ NEW_OPCODE(LDX, ZPG, 3, 2, 0),
|
|
/* A7 */ NEW_OPCODE(LAX, ZPG, 3, 2, 1),
|
|
/* A8 */ NEW_OPCODE(TAY, IMP, 2, 1, 0),
|
|
/* A9 */ NEW_OPCODE(LDA, IMM, 2, 2, 0),
|
|
/* AA */ NEW_OPCODE(TAX, IMP, 2, 1, 0),
|
|
/* AB */ NEW_OPCODE(LAX, IMM, 2, 2, 1),
|
|
/* AC */ NEW_OPCODE(LDY, ABS, 4, 3, 0),
|
|
/* AD */ NEW_OPCODE(LDA, ABS, 4, 3, 0),
|
|
/* AE */ NEW_OPCODE(LDX, ABS, 4, 3, 0),
|
|
/* AF */ NEW_OPCODE(LAX, ABS, 4, 3, 1),
|
|
|
|
/* B0 */ NEW_OPCODE(BCS, REL, 2, 2, 0),
|
|
/* B1 */ NEW_OPCODE(LDA, INDY, 5, 2, 0),
|
|
/* B2 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* B3 */ NEW_OPCODE(LAX, INDY, 5, 2, 1),
|
|
/* B4 */ NEW_OPCODE(LDY, ZPX, 4, 2, 0),
|
|
/* B5 */ NEW_OPCODE(LDA, ZPX, 4, 2, 0),
|
|
/* B6 */ NEW_OPCODE(LDX, ZPY, 4, 2, 0),
|
|
/* B7 */ NEW_OPCODE(LAX, ZPY, 4, 2, 1),
|
|
/* B8 */ NEW_OPCODE(CLV, IMP, 2, 1, 0),
|
|
/* B9 */ NEW_OPCODE(LDA, ABY, 4, 3, 0),
|
|
/* BA */ NEW_OPCODE(TSX, IMP, 2, 1, 0),
|
|
/* BB */ NEW_OPCODE(LAS, ABY, 4, 3, 1),
|
|
/* BC */ NEW_OPCODE(LDY, ABX, 4, 3, 0),
|
|
/* BD */ NEW_OPCODE(LDA, ABX, 4, 3, 0),
|
|
/* BE */ NEW_OPCODE(LDX, ABY, 4, 3, 0),
|
|
/* BF */ NEW_OPCODE(LAX, ABY, 4, 3, 1),
|
|
|
|
/* C0 */ NEW_OPCODE(CPY, IMM, 2, 2, 0),
|
|
/* C1 */ NEW_OPCODE(CMP, INDX, 6, 2, 0),
|
|
/* C2 */ NEW_OPCODE(NOP, IMM, 2, 2, 1),
|
|
/* C3 */ NEW_OPCODE(DCP, INDX, 8, 2, 1),
|
|
/* C4 */ NEW_OPCODE(CPY, ZPG, 3, 2, 0),
|
|
/* C5 */ NEW_OPCODE(CMP, ZPG, 3, 2, 0),
|
|
/* C6 */ NEW_OPCODE(DEC, ZPG, 5, 2, 0),
|
|
/* C7 */ NEW_OPCODE(DCP, ZPG, 5, 2, 1),
|
|
/* C8 */ NEW_OPCODE(INY, IMP, 2, 1, 0),
|
|
/* C9 */ NEW_OPCODE(CMP, IMM, 2, 2, 0),
|
|
/* CA */ NEW_OPCODE(DEX, IMP, 2, 1, 0),
|
|
/* CB */ NEW_OPCODE(SBX, IMM, 2, 2, 1),
|
|
/* CC */ NEW_OPCODE(CPY, ABS, 4, 3, 0),
|
|
/* CD */ NEW_OPCODE(CMP, ABS, 4, 3, 0),
|
|
/* CE */ NEW_OPCODE(DEC, ABS, 6, 3, 0),
|
|
/* CF */ NEW_OPCODE(DCP, ABS, 6, 3, 1),
|
|
|
|
/* D0 */ NEW_OPCODE(BNE, REL, 2, 2, 0),
|
|
/* D1 */ NEW_OPCODE(CMP, INDY, 5, 2, 0),
|
|
/* D2 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* D3 */ NEW_OPCODE(DCP, INDY, 8, 2, 1),
|
|
/* D4 */ NEW_OPCODE(NOP, ZPX, 4, 2, 1),
|
|
/* D5 */ NEW_OPCODE(CMP, ZPX, 4, 2, 0),
|
|
/* D6 */ NEW_OPCODE(DEC, ZPX, 6, 2, 0),
|
|
/* D7 */ NEW_OPCODE(DCP, ZPX, 6, 2, 1),
|
|
/* D8 */ NEW_OPCODE(CLD, IMP, 2, 1, 0),
|
|
/* D9 */ NEW_OPCODE(CMP, ABY, 4, 3, 0),
|
|
/* DA */ NEW_OPCODE(NOP, IMP, 2, 1, 1),
|
|
/* DB */ NEW_OPCODE(DCP, ABY, 7, 3, 1),
|
|
/* DC */ NEW_OPCODE(NOP, ABX, 4, 3, 1),
|
|
/* DD */ NEW_OPCODE(CMP, ABX, 4, 3, 0),
|
|
/* DE */ NEW_OPCODE(DEC, ABX, 7, 3, 0),
|
|
/* DF */ NEW_OPCODE(DCP, ABX, 7, 3, 1),
|
|
|
|
/* E0 */ NEW_OPCODE(CPX, IMM, 2, 2, 0),
|
|
/* E1 */ NEW_OPCODE(SBC, INDX, 6, 2, 0),
|
|
/* E2 */ NEW_OPCODE(NOP, IMM, 2, 2, 1),
|
|
/* E3 */ NEW_OPCODE(ISC, INDX, 8, 2, 1),
|
|
/* E4 */ NEW_OPCODE(CPX, ZPG, 3, 2, 0),
|
|
/* E5 */ NEW_OPCODE(SBC, ZPG, 3, 2, 0),
|
|
/* E6 */ NEW_OPCODE(INC, ZPG, 5, 2, 0),
|
|
/* E7 */ NEW_OPCODE(ISC, ZPG, 5, 2, 1),
|
|
/* E8 */ NEW_OPCODE(INX, IMP, 2, 1, 0),
|
|
/* E9 */ NEW_OPCODE(SBC, IMM, 2, 2, 0),
|
|
/* EA */ NEW_OPCODE(NOP, IMP, 2, 1, 0),
|
|
/* EB */ NEW_OPCODE(SBC, IMM, 2, 2, 1),
|
|
/* EC */ NEW_OPCODE(CPX, ABS, 4, 3, 0),
|
|
/* ED */ NEW_OPCODE(SBC, ABS, 4, 3, 0),
|
|
/* EE */ NEW_OPCODE(INC, ABS, 6, 3, 0),
|
|
/* EF */ NEW_OPCODE(ISC, ABS, 6, 3, 1),
|
|
|
|
/* F0 */ NEW_OPCODE(BEQ, REL, 2, 2, 0),
|
|
/* F1 */ NEW_OPCODE(SBC, INDY, 5, 2, 0),
|
|
/* F2 */ NEW_OPCODE(JAM, IMP, -1, 1, 1),
|
|
/* F3 */ NEW_OPCODE(ISC, INDY, 8, 2, 1),
|
|
/* F4 */ NEW_OPCODE(NOP, ZPX, 4, 2, 1),
|
|
/* F5 */ NEW_OPCODE(SBC, ZPX, 4, 2, 0),
|
|
/* F6 */ NEW_OPCODE(INC, ZPX, 6, 2, 0),
|
|
/* F7 */ NEW_OPCODE(ISC, ZPX, 6, 2, 1),
|
|
/* F8 */ NEW_OPCODE(SED, IMP, 2, 1, 0),
|
|
/* F9 */ NEW_OPCODE(SBC, ABY, 4, 3, 0),
|
|
/* FA */ NEW_OPCODE(NOP, IMP, 2, 1, 1),
|
|
/* FC */ NEW_OPCODE(ISC, ABY, 7, 3, 1),
|
|
/* FB */ NEW_OPCODE(NOP, ABX, 4, 3, 1),
|
|
/* FD */ NEW_OPCODE(SBC, ABX, 4, 3, 0),
|
|
/* FE */ NEW_OPCODE(INC, ABX, 7, 3, 0),
|
|
/* FF */ NEW_OPCODE(ISC, ABX, 7, 3, 1)
|
|
}; |