diff --git a/src/dk/camelot64/kickc/asm/AsmInstruction.java b/src/dk/camelot64/kickc/asm/AsmInstruction.java index e7f11e90b..ec0be4db0 100644 --- a/src/dk/camelot64/kickc/asm/AsmInstruction.java +++ b/src/dk/camelot64/kickc/asm/AsmInstruction.java @@ -43,11 +43,9 @@ public class AsmInstruction implements AsmLine { return getInvocationCountEstimate()*getLineCycles(); } - @Override public String getAsm() { return type.getAsm(parameter); } - } diff --git a/src/dk/camelot64/kickc/asm/AsmInstructionType.java b/src/dk/camelot64/kickc/asm/AsmInstructionType.java index cf2e93461..53eba7b97 100644 --- a/src/dk/camelot64/kickc/asm/AsmInstructionType.java +++ b/src/dk/camelot64/kickc/asm/AsmInstructionType.java @@ -1,5 +1,7 @@ package dk.camelot64.kickc.asm; +import dk.camelot64.kickc.asm.parser.AsmClobber; + /** The instructions of the 6502 assembler instruction set */ public class AsmInstructionType { @@ -13,11 +15,14 @@ public class AsmInstructionType { private boolean jump; + private AsmClobber clobber; + public AsmInstructionType(int opcode, String mnemnonic, AsmAddressingMode addressingMode, double cycles) { this.opcode = opcode; this.mnemnonic = mnemnonic; this.addressingMode = addressingMode; this.cycles = cycles; + this.clobber = new AsmClobber(); } public String getMnemnonic() { @@ -52,4 +57,7 @@ public class AsmInstructionType { this.jump = jump; } + public AsmClobber getClobber() { + return clobber; + } } diff --git a/src/dk/camelot64/kickc/asm/AsmInstuctionSet.java b/src/dk/camelot64/kickc/asm/AsmInstuctionSet.java index b1ffd34e6..26eb036d3 100644 --- a/src/dk/camelot64/kickc/asm/AsmInstuctionSet.java +++ b/src/dk/camelot64/kickc/asm/AsmInstuctionSet.java @@ -3,6 +3,7 @@ package dk.camelot64.kickc.asm; import dk.camelot64.kickc.icl.NumberParser; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -48,7 +49,7 @@ public class AsmInstuctionSet { private List instructions; private void add(int opcode, String mnemonic, AsmAddressingMode addressingmMode, double cycles) { - instructions.add(new AsmInstructionType(opcode, mnemonic.toLowerCase(), addressingmMode, cycles)); + instructions.add(new AsmInstructionType(opcode, mnemonic, addressingmMode, cycles)); } public AsmInstuctionSet() { @@ -65,275 +66,304 @@ public class AsmInstuctionSet { AsmAddressingMode izy = AsmAddressingMode.IZY; AsmAddressingMode rel = AsmAddressingMode.REL; AsmAddressingMode ind = AsmAddressingMode.IND; - add(0x00, "BRK", non, 7.0); - add(0x01, "ORA", izx, 6.0); - add(0x01, "ORA", izx, 6.0); - add(0x02, "KIL", non, 0.0); - add(0x03, "SLO", izx, 8.0); - add(0x04, "NOP", zp, 3.0); - add(0x05, "ORA", zp, 3.0); - add(0x06, "ASL", zp, 5.0); - add(0x07, "SLO", zp, 5.0); - add(0x08, "PHP", non, 3.0); - add(0x09, "ORA", imm, 2.0); - add(0x0a, "ASL", non, 2.0); - add(0x0b, "ANC", imm, 2.0); - add(0x0c, "NOP", abs, 4.0); - add(0x0d, "ORA", abs, 4.0); - add(0x0e, "ASL", abs, 6.0); - add(0x0f, "SLO", abs, 6.0); - add(0x10, "BPL", rel, 2.5); - add(0x11, "ORA", izy, 5.5); - add(0x12, "KIL", non, 0.0); - add(0x13, "SLO", izy, 8.0); - add(0x14, "NOP", zpx, 4.0); - add(0x15, "ORA", zpx, 4.0); - add(0x16, "ASL", zpx, 6.0); - add(0x17, "SLO", zpx, 6.0); - add(0x18, "CLC", non, 2.0); - add(0x19, "ORA", aby, 4.5); - add(0x1a, "NOP", non, 2.0); - add(0x1b, "SLO", aby, 7.0); - add(0x1c, "NOP", abx, 4.5); - add(0x1d, "ORA", abx, 4.5); - add(0x1e, "ASL", abx, 7.0); - add(0x1f, "SLO", abx, 7.0); - add(0x20, "JSR", abs, 6.0); - add(0x21, "AND", izx, 6.0); - add(0x22, "KIL", non, 0.0); - add(0x23, "RLA", izx, 8.0); - add(0x24, "BIT", zp, 3.0); - add(0x25, "AND", zp, 3.0); - add(0x26, "ROL", zp, 5.0); - add(0x27, "RLA", zp, 5.0); - add(0x28, "PLP", non, 4.0); - add(0x29, "AND", imm, 2.0); - add(0x2a, "ROL", non, 2.0); - add(0x2b, "ANC", imm, 2.0); - add(0x2c, "BIT", abs, 4.0); - add(0x2d, "AND", abs, 4.0); - add(0x2e, "ROL", abs, 6.0); - add(0x2f, "RLA", abs, 6.0); - add(0x30, "BMI", rel, 2.5); - add(0x31, "AND", izy, 5.5); - add(0x32, "KIL", non, 0.0); - add(0x33, "RLA", izy, 8.0); - add(0x34, "NOP", zpx, 4.0); - add(0x35, "AND", zpx, 4.0); - add(0x36, "ROL", zpx, 6.0); - add(0x37, "RLA", zpx, 6.0); - add(0x38, "SEC", non, 2.0); - add(0x39, "AND", aby, 4.5); - add(0x3a, "NOP", non, 2.0); - add(0x3b, "RLA", aby, 7.0); - add(0x3c, "NOP", abx, 4.5); - add(0x3d, "AND", abx, 4.5); - add(0x3e, "ROL", abx, 7.0); - add(0x3f, "RLA", abx, 7.0); - add(0x40, "RTI", non, 6.0); - add(0x41, "EOR", izx, 6.0); - add(0x42, "KIL", non, 0.0); - add(0x43, "SRE", izx, 8.0); - add(0x44, "NOP", zp, 3.0); - add(0x45, "EOR", zp, 3.0); - add(0x46, "LSR", zp, 5.0); - add(0x47, "SRE", zp, 5.0); - add(0x48, "PHA", non, 3.0); - add(0x49, "EOR", imm, 2.0); - add(0x4a, "LSR", non, 2.0); - add(0x4b, "ALR", imm, 2.0); - add(0x4c, "JMP", abs, 3.0); - add(0x4d, "EOR", abs, 4.0); - add(0x4e, "LSR", abs, 6.0); - add(0x4f, "SRE", abs, 6.0); - add(0x50, "BVC", rel, 2.5); - add(0x51, "EOR", izy, 5.5); - add(0x52, "KIL", non, 0.0); - add(0x53, "SRE", izy, 8.0); - add(0x54, "NOP", zpx, 4.0); - add(0x55, "EOR", zpx, 4.0); - add(0x56, "LSR", zpx, 6.0); - add(0x57, "SRE", zpx, 6.0); - add(0x58, "CLI", non, 2.0); - add(0x59, "EOR", aby, 4.5); - add(0x5a, "NOP", non, 2.0); - add(0x5b, "SRE", aby, 7.0); - add(0x5c, "NOP", abx, 4.5); - add(0x5d, "EOR", abx, 4.5); - add(0x5e, "LSR", abx, 7.0); - add(0x5f, "SRE", abx, 7.0); - add(0x60, "RTS", non, 6.0); - add(0x61, "ADC", izx, 6.0); - add(0x62, "KIL", non, 0.0); - add(0x63, "RRA", izx, 8.0); - add(0x64, "NOP", zp, 3.0); - add(0x65, "ADC", zp, 3.0); - add(0x66, "ROR", zp, 5.0); - add(0x67, "RRA", zp, 5.0); - add(0x68, "PLA", non, 4.0); - add(0x69, "ADC", imm, 2.0); - add(0x6a, "ROR", non, 2.0); - add(0x6b, "ARR", imm, 2.0); - add(0x6c, "JMP", ind, 5.0); - add(0x6d, "ADC", abs, 4.0); - add(0x6e, "ROR", abs, 6.0); - add(0x6f, "RRA", abs, 6.0); - add(0x70, "BVS", rel, 2.5); - add(0x71, "ADC", izy, 5.5); - add(0x72, "KIL", non, 0.0); - add(0x73, "RRA", izy, 8.0); - add(0x74, "NOP", zpx, 4.0); - add(0x75, "ADC", zpx, 4.0); - add(0x76, "ROR", zpx, 6.0); - add(0x77, "RRA", zpx, 6.0); - add(0x78, "SEI", non, 2.0); - add(0x79, "ADC", aby, 4.5); - add(0x7a, "NOP", non, 2.0); - add(0x7b, "RRA", aby, 7.0); - add(0x7c, "NOP", abx, 4.5); - add(0x7d, "ADC", abx, 4.5); - add(0x7e, "ROR", abx, 7.0); - add(0x7f, "RRA", abx, 7.0); - add(0x80, "NOP", imm, 2.0); - add(0x81, "STA", izx, 6.0); - add(0x82, "NOP", imm, 2.0); - add(0x83, "SAX", izx, 6.0); - add(0x84, "STY", zp, 3.0); - add(0x85, "STA", zp, 3.0); - add(0x86, "STX", zp, 3.0); - add(0x87, "SAX", zp, 3.0); - add(0x88, "DEY", non, 2.0); - add(0x89, "NOP", imm, 2.0); - add(0x8a, "TXA", non, 2.0); - add(0x8b, "XAA", imm, 2.0); - add(0x8c, "STY", abs, 4.0); - add(0x8d, "STA", abs, 4.0); - add(0x8e, "STX", abs, 4.0); - add(0x8f, "SAX", abs, 4.0); - add(0x90, "BCC", rel, 2.5); - add(0x91, "STA", izy, 6.0); - add(0x92, "KIL", non, 0.0); - add(0x93, "AHX", izy, 6.0); - add(0x94, "STY", zpx, 4.0); - add(0x95, "STA", zpx, 4.0); - add(0x96, "STX", zpy, 4.0); - add(0x97, "SAX", zpy, 4.0); - add(0x98, "TYA", non, 2.0); - add(0x99, "STA", aby, 5.0); - add(0x9a, "TXS", non, 2.0); - add(0x9b, "TAS", aby, 5.0); - add(0x9c, "SHY", abx, 5.0); - add(0x9d, "STA", abx, 5.0); - add(0x9e, "SHX", aby, 5.0); - add(0x9f, "AHX", aby, 5.0); - add(0xa0, "LDY", imm, 2.0); - add(0xa1, "LDA", izx, 6.0); - add(0xa2, "LDX", imm, 2.0); - add(0xa3, "LAX", izx, 6.0); - add(0xa4, "LDY", zp, 3.0); - add(0xa5, "LDA", zp, 3.0); - add(0xa6, "LDX", zp, 3.0); - add(0xa7, "LAX", zp, 3.0); - add(0xa8, "TAY", non, 2.0); - add(0xa9, "LDA", imm, 2.0); - add(0xaa, "TAX", non, 2.0); - add(0xab, "LAX", imm, 2.0); - add(0xac, "LDY", abs, 4.0); - add(0xad, "LDA", abs, 4.0); - add(0xae, "LDX", abs, 4.0); - add(0xaf, "LAX", abs, 4.0); - add(0xb0, "BCS", rel, 2.5); - add(0xb1, "LDA", izy, 5.5); - add(0xb2, "KIL", non, 0.0); - add(0xb3, "LAX", izy, 5.5); - add(0xb4, "LDY", zpx, 4.0); - add(0xb5, "LDA", zpx, 4.0); - add(0xb6, "LDX", zpy, 4.0); - add(0xb7, "LAX", zpy, 4.0); - add(0xb8, "CLV", non, 2.0); - add(0xb9, "LDA", aby, 4.5); - add(0xba, "TSX", non, 2.0); - add(0xbb, "LAS", aby, 4.5); - add(0xbc, "LDY", abx, 4.5); - add(0xbd, "LDA", abx, 4.5); - add(0xbe, "LDX", aby, 4.5); - add(0xbf, "LAX", aby, 4.5); - add(0xc0, "CPY", imm, 2.0); - add(0xc1, "CMP", izx, 6.0); - add(0xc2, "NOP", imm, 2.0); - add(0xc3, "DCP", izx, 8.0); - add(0xc4, "CPY", zp, 3.0); - add(0xc5, "CMP", zp, 3.0); - add(0xc6, "DEC", zp, 5.0); - add(0xc7, "DCP", zp, 5.0); - add(0xc8, "INY", non, 2.0); - add(0xc9, "CMP", imm, 2.0); - add(0xca, "DEX", non, 2.0); - add(0xcb, "AXS", imm, 2.0); - add(0xcc, "CPY", abs, 4.0); - add(0xcd, "CMP", abs, 4.0); - add(0xce, "DEC", abs, 6.0); - add(0xcf, "DCP", abs, 6.0); - add(0xd0, "BNE", rel, 2.5); - add(0xd1, "CMP", izy, 5.5); - add(0xd2, "KIL", non, 0.0); - add(0xd3, "DCP", izy, 8.0); - add(0xd4, "NOP", zpx, 4.0); - add(0xd5, "CMP", zpx, 4.0); - add(0xd6, "DEC", zpx, 6.0); - add(0xd7, "DCP", zpx, 6.0); - add(0xd8, "CLD", non, 2.0); - add(0xd9, "CMP", aby, 4.5); - add(0xda, "NOP", non, 2.0); - add(0xdb, "DCP", aby, 7.0); - add(0xdc, "NOP", abx, 4.5); - add(0xdd, "CMP", abx, 4.5); - add(0xde, "DEC", abx, 7.0); - add(0xef, "CPX", imm, 2.0); - add(0xe0, "SBC", izx, 6.0); - add(0xe1, "NOP", imm, 2.0); - add(0xe2, "ISC", izx, 8.0); - add(0xe3, "CPX", zp, 3.0); - add(0xe4, "SBC", zp, 3.0); - add(0xe5, "INC", zp, 5.0); - add(0xe6, "ISC", zp, 5.0); - add(0xe7, "INX", non, 2.0); - add(0xe8, "SBC", imm, 2.0); - add(0xe9, "NOP", non, 2.0); - add(0xea, "SBC", imm, 2.0); - add(0xeb, "CPX", abs, 4.0); - add(0xec, "SBC", abs, 4.0); - add(0xed, "INC", abs, 6.0); - add(0xee, "ISC", abs, 6.0); - add(0xef, "DCP", abx, 7.0); - add(0xf0, "BEQ", rel, 2.5); - add(0xf1, "SBC", izy, 5.5); - add(0xf2, "KIL", non, 0.0); - add(0xf3, "ISC", izy, 8.0); - add(0xf4, "NOP", zpx, 4.0); - add(0xf5, "SBC", zpx, 4.0); - add(0xf6, "INC", zpx, 6.0); - add(0xf7, "ISC", zpx, 6.0); - add(0xf8, "SED", non, 2.0); - add(0xf9, "SBC", aby, 4.5); - add(0xfa, "NOP", non, 2.0); - add(0xfb, "ISC", aby, 7.0); - add(0xfc, "NOP", abx, 4.5); - add(0xfd, "SBC", abx, 4.5); - add(0xfe, "INC", abx, 7.0); - add(0xff, "ISC", abx, 7.0); + add(0x00, "brk", non, 7.0); + add(0x01, "ora", izx, 6.0); + add(0x01, "ora", izx, 6.0); + add(0x02, "kil", non, 0.0); + add(0x03, "slo", izx, 8.0); + add(0x04, "nop", zp, 3.0); + add(0x05, "ora", zp, 3.0); + add(0x06, "asl", zp, 5.0); + add(0x07, "slo", zp, 5.0); + add(0x08, "php", non, 3.0); + add(0x09, "ora", imm, 2.0); + add(0x0a, "asl", non, 2.0); + add(0x0b, "anc", imm, 2.0); + add(0x0c, "nop", abs, 4.0); + add(0x0d, "ora", abs, 4.0); + add(0x0e, "asl", abs, 6.0); + add(0x0f, "slo", abs, 6.0); + add(0x10, "bpl", rel, 2.5); + add(0x11, "ora", izy, 5.5); + add(0x12, "kil", non, 0.0); + add(0x13, "slo", izy, 8.0); + add(0x14, "nop", zpx, 4.0); + add(0x15, "ora", zpx, 4.0); + add(0x16, "asl", zpx, 6.0); + add(0x17, "slo", zpx, 6.0); + add(0x18, "clc", non, 2.0); + add(0x19, "ora", aby, 4.5); + add(0x1a, "nop", non, 2.0); + add(0x1b, "slo", aby, 7.0); + add(0x1c, "nop", abx, 4.5); + add(0x1d, "ora", abx, 4.5); + add(0x1e, "asl", abx, 7.0); + add(0x1f, "slo", abx, 7.0); + add(0x20, "jsr", abs, 6.0); + add(0x21, "and", izx, 6.0); + add(0x22, "kil", non, 0.0); + add(0x23, "rla", izx, 8.0); + add(0x24, "bit", zp, 3.0); + add(0x25, "and", zp, 3.0); + add(0x26, "rol", zp, 5.0); + add(0x27, "rla", zp, 5.0); + add(0x28, "plp", non, 4.0); + add(0x29, "and", imm, 2.0); + add(0x2a, "rol", non, 2.0); + add(0x2b, "anc", imm, 2.0); + add(0x2c, "bit", abs, 4.0); + add(0x2d, "and", abs, 4.0); + add(0x2e, "rol", abs, 6.0); + add(0x2f, "rla", abs, 6.0); + add(0x30, "bmi", rel, 2.5); + add(0x31, "and", izy, 5.5); + add(0x32, "kil", non, 0.0); + add(0x33, "rla", izy, 8.0); + add(0x34, "nop", zpx, 4.0); + add(0x35, "and", zpx, 4.0); + add(0x36, "rol", zpx, 6.0); + add(0x37, "rla", zpx, 6.0); + add(0x38, "sec", non, 2.0); + add(0x39, "and", aby, 4.5); + add(0x3a, "nop", non, 2.0); + add(0x3b, "rla", aby, 7.0); + add(0x3c, "nop", abx, 4.5); + add(0x3d, "and", abx, 4.5); + add(0x3e, "rol", abx, 7.0); + add(0x3f, "rla", abx, 7.0); + add(0x40, "rti", non, 6.0); + add(0x41, "eor", izx, 6.0); + add(0x42, "kil", non, 0.0); + add(0x43, "sre", izx, 8.0); + add(0x44, "nop", zp, 3.0); + add(0x45, "eor", zp, 3.0); + add(0x46, "lsr", zp, 5.0); + add(0x47, "sre", zp, 5.0); + add(0x48, "pha", non, 3.0); + add(0x49, "eor", imm, 2.0); + add(0x4a, "lsr", non, 2.0); + add(0x4b, "alr", imm, 2.0); + add(0x4c, "jmp", abs, 3.0); + add(0x4d, "eor", abs, 4.0); + add(0x4e, "lsr", abs, 6.0); + add(0x4f, "sre", abs, 6.0); + add(0x50, "bvc", rel, 2.5); + add(0x51, "eor", izy, 5.5); + add(0x52, "kil", non, 0.0); + add(0x53, "sre", izy, 8.0); + add(0x54, "nop", zpx, 4.0); + add(0x55, "eor", zpx, 4.0); + add(0x56, "lsr", zpx, 6.0); + add(0x57, "sre", zpx, 6.0); + add(0x58, "cli", non, 2.0); + add(0x59, "eor", aby, 4.5); + add(0x5a, "nop", non, 2.0); + add(0x5b, "sre", aby, 7.0); + add(0x5c, "nop", abx, 4.5); + add(0x5d, "eor", abx, 4.5); + add(0x5e, "lsr", abx, 7.0); + add(0x5f, "sre", abx, 7.0); + add(0x60, "rts", non, 6.0); + add(0x61, "adc", izx, 6.0); + add(0x62, "kil", non, 0.0); + add(0x63, "rra", izx, 8.0); + add(0x64, "nop", zp, 3.0); + add(0x65, "adc", zp, 3.0); + add(0x66, "ror", zp, 5.0); + add(0x67, "rra", zp, 5.0); + add(0x68, "pla", non, 4.0); + add(0x69, "adc", imm, 2.0); + add(0x6a, "ror", non, 2.0); + add(0x6b, "arr", imm, 2.0); + add(0x6c, "jmp", ind, 5.0); + add(0x6d, "adc", abs, 4.0); + add(0x6e, "ror", abs, 6.0); + add(0x6f, "rra", abs, 6.0); + add(0x70, "bvs", rel, 2.5); + add(0x71, "adc", izy, 5.5); + add(0x72, "kil", non, 0.0); + add(0x73, "rra", izy, 8.0); + add(0x74, "nop", zpx, 4.0); + add(0x75, "adc", zpx, 4.0); + add(0x76, "ror", zpx, 6.0); + add(0x77, "rra", zpx, 6.0); + add(0x78, "sei", non, 2.0); + add(0x79, "adc", aby, 4.5); + add(0x7a, "nop", non, 2.0); + add(0x7b, "rra", aby, 7.0); + add(0x7c, "nop", abx, 4.5); + add(0x7d, "adc", abx, 4.5); + add(0x7e, "ror", abx, 7.0); + add(0x7f, "rra", abx, 7.0); + add(0x80, "nop", imm, 2.0); + add(0x81, "sta", izx, 6.0); + add(0x82, "nop", imm, 2.0); + add(0x83, "sax", izx, 6.0); + add(0x84, "sty", zp, 3.0); + add(0x85, "sta", zp, 3.0); + add(0x86, "stx", zp, 3.0); + add(0x87, "sax", zp, 3.0); + add(0x88, "dey", non, 2.0); + add(0x89, "nop", imm, 2.0); + add(0x8a, "txa", non, 2.0); + add(0x8b, "xaa", imm, 2.0); + add(0x8c, "sty", abs, 4.0); + add(0x8d, "sta", abs, 4.0); + add(0x8e, "stx", abs, 4.0); + add(0x8f, "sax", abs, 4.0); + add(0x90, "bcc", rel, 2.5); + add(0x91, "sta", izy, 6.0); + add(0x92, "kil", non, 0.0); + add(0x93, "ahx", izy, 6.0); + add(0x94, "sty", zpx, 4.0); + add(0x95, "sta", zpx, 4.0); + add(0x96, "stx", zpy, 4.0); + add(0x97, "sax", zpy, 4.0); + add(0x98, "tya", non, 2.0); + add(0x99, "sta", aby, 5.0); + add(0x9a, "txs", non, 2.0); + add(0x9b, "tas", aby, 5.0); + add(0x9c, "shy", abx, 5.0); + add(0x9d, "sta", abx, 5.0); + add(0x9e, "shx", aby, 5.0); + add(0x9f, "ahx", aby, 5.0); + add(0xa0, "ldy", imm, 2.0); + add(0xa1, "lda", izx, 6.0); + add(0xa2, "ldx", imm, 2.0); + add(0xa3, "lax", izx, 6.0); + add(0xa4, "ldy", zp, 3.0); + add(0xa5, "lda", zp, 3.0); + add(0xa6, "ldx", zp, 3.0); + add(0xa7, "lax", zp, 3.0); + add(0xa8, "tay", non, 2.0); + add(0xa9, "lda", imm, 2.0); + add(0xaa, "tax", non, 2.0); + add(0xab, "lax", imm, 2.0); + add(0xac, "ldy", abs, 4.0); + add(0xad, "lda", abs, 4.0); + add(0xae, "ldx", abs, 4.0); + add(0xaf, "lax", abs, 4.0); + add(0xb0, "bcs", rel, 2.5); + add(0xb1, "lda", izy, 5.5); + add(0xb2, "kil", non, 0.0); + add(0xb3, "lax", izy, 5.5); + add(0xb4, "ldy", zpx, 4.0); + add(0xb5, "lda", zpx, 4.0); + add(0xb6, "ldx", zpy, 4.0); + add(0xb7, "lax", zpy, 4.0); + add(0xb8, "clv", non, 2.0); + add(0xb9, "lda", aby, 4.5); + add(0xba, "tsx", non, 2.0); + add(0xbb, "las", aby, 4.5); + add(0xbc, "ldy", abx, 4.5); + add(0xbd, "lda", abx, 4.5); + add(0xbe, "ldx", aby, 4.5); + add(0xbf, "lax", aby, 4.5); + add(0xc0, "cpy", imm, 2.0); + add(0xc1, "cmp", izx, 6.0); + add(0xc2, "nop", imm, 2.0); + add(0xc3, "dcp", izx, 8.0); + add(0xc4, "cpy", zp, 3.0); + add(0xc5, "cmp", zp, 3.0); + add(0xc6, "dec", zp, 5.0); + add(0xc7, "dcp", zp, 5.0); + add(0xc8, "iny", non, 2.0); + add(0xc9, "cmp", imm, 2.0); + add(0xca, "dex", non, 2.0); + add(0xcb, "axs", imm, 2.0); + add(0xcc, "cpy", abs, 4.0); + add(0xcd, "cmp", abs, 4.0); + add(0xce, "dec", abs, 6.0); + add(0xcf, "dcp", abs, 6.0); + add(0xd0, "bne", rel, 2.5); + add(0xd1, "cmp", izy, 5.5); + add(0xd2, "kil", non, 0.0); + add(0xd3, "dcp", izy, 8.0); + add(0xd4, "nop", zpx, 4.0); + add(0xd5, "cmp", zpx, 4.0); + add(0xd6, "dec", zpx, 6.0); + add(0xd7, "dcp", zpx, 6.0); + add(0xd8, "cld", non, 2.0); + add(0xd9, "cmp", aby, 4.5); + add(0xda, "nop", non, 2.0); + add(0xdb, "dcp", aby, 7.0); + add(0xdc, "nop", abx, 4.5); + add(0xdd, "cmp", abx, 4.5); + add(0xde, "dec", abx, 7.0); + add(0xef, "cpx", imm, 2.0); + add(0xe0, "sbc", izx, 6.0); + add(0xe1, "nop", imm, 2.0); + add(0xe2, "isc", izx, 8.0); + add(0xe3, "cpx", zp, 3.0); + add(0xe4, "sbc", zp, 3.0); + add(0xe5, "inc", zp, 5.0); + add(0xe6, "isc", zp, 5.0); + add(0xe7, "inx", non, 2.0); + add(0xe8, "sbc", imm, 2.0); + add(0xe9, "nop", non, 2.0); + add(0xea, "sbc", imm, 2.0); + add(0xeb, "cpx", abs, 4.0); + add(0xec, "sbc", abs, 4.0); + add(0xed, "inc", abs, 6.0); + add(0xee, "isc", abs, 6.0); + add(0xef, "dcp", abx, 7.0); + add(0xf0, "beq", rel, 2.5); + add(0xf1, "sbc", izy, 5.5); + add(0xf2, "kil", non, 0.0); + add(0xf3, "isc", izy, 8.0); + add(0xf4, "nop", zpx, 4.0); + add(0xf5, "sbc", zpx, 4.0); + add(0xf6, "inc", zpx, 6.0); + add(0xf7, "isc", zpx, 6.0); + add(0xf8, "sed", non, 2.0); + add(0xf9, "sbc", aby, 4.5); + add(0xfa, "nop", non, 2.0); + add(0xfb, "isc", aby, 7.0); + add(0xfc, "nop", abx, 4.5); + add(0xfd, "sbc", abx, 4.5); + add(0xfe, "inc", abx, 7.0); + add(0xff, "isc", abx, 7.0); + List jumps = Arrays.asList("jmp", "beq", "bne", "bcc", "bcs", "bvs", "bvc", "bmi", "bpl"); for (AsmInstructionType instruction : instructions) { - switch(instruction.getMnemnonic()) { - case "jmp": - case "beq": - case "bne": - case "bcc": - case "bcs": - case "bvc": - case "bvs": - case "bmi": - case "bpl": - instruction.setJump(true); + if(jumps.contains(instruction.getMnemnonic())) { + instruction.setJump(true); + } + } + List cxs = Arrays.asList("dex", "inx", "ldx", "tax", "tsx", "las", "lax", "axs"); + for (AsmInstructionType instruction : instructions) { + if(cxs.contains(instruction.getMnemnonic())) { + instruction.getClobber().setClobberX(true); + } + } + List cys = Arrays.asList("dey", "iny", "ldy", "tay" ); + for (AsmInstructionType instruction : instructions) { + if(cys.contains(instruction.getMnemnonic())) { + instruction.getClobber().setClobberY(true); + } + } + List cas = Arrays.asList("ora", "and", "eor", "adc", "sbc", "lda", "txa", "tya", "pla", "slo", "rla", "sre", "rra", "isc", "anc", "alr", "arr", "xaa", "lax", "las"); + for (AsmInstructionType instruction : instructions) { + if(cas.contains(instruction.getMnemnonic())) { + instruction.getClobber().setClobberA(true); + } + } + List ccs = Arrays.asList("adc", "sbc", "cmp", "cpx", "cpy", "asl", "rol", "lsr", "ror", "plp", "rti", "clc", "sec", "slo", "rla", "sre", "rra", "dcp", "isc", "anc", "alr", "arr", "axs"); + for (AsmInstructionType instruction : instructions) { + if(ccs.contains(instruction.getMnemnonic())) { + instruction.getClobber().setClobberC(true); + } + } + List cvs = Arrays.asList("adc", "sbc", "plp", "rti", "bit", "rra", "isc", "arr"); + for (AsmInstructionType instruction : instructions) { + if(cvs.contains(instruction.getMnemnonic())) { + instruction.getClobber().setClobberV(true); + } + } + List czs = Arrays.asList("ora", "and", "eor", "adc", "sbc", "cmp", "cpx", "cpy", "dec", "dex", "dey", "inc", "inx", "iny", "asl", "rol", "lsr", "ror", "lda", "ldx", "ldy", "tax", "txa", "tay", "tya", "tsx", "txs", "pla", "plp", "rti", "bit", "slo", "rla", "sre", "rra", "lax", "dcp", "isc", "anc", "alr", "arr", "xaa", "lax", "axs", "las"); + for (AsmInstructionType instruction : instructions) { + if(czs.contains(instruction.getMnemnonic())) { + instruction.getClobber().setClobberZ(true); + instruction.getClobber().setClobberN(true); } } } diff --git a/src/dk/camelot64/kickc/asm/parser/AsmClobber.java b/src/dk/camelot64/kickc/asm/parser/AsmClobber.java new file mode 100644 index 000000000..e6a51586c --- /dev/null +++ b/src/dk/camelot64/kickc/asm/parser/AsmClobber.java @@ -0,0 +1,72 @@ +package dk.camelot64.kickc.asm.parser; + +/** Information about what parts of the CPU an ASM instruction clobbers */ +public class AsmClobber { + + boolean clobberA; + boolean clobberX; + boolean clobberY; + boolean clobberC; + boolean clobberN; + boolean clobberZ; + boolean clobberV; + + public AsmClobber() { + } + + public boolean isClobberA() { + return clobberA; + } + + public boolean isClobberX() { + return clobberX; + } + + public boolean isClobberY() { + return clobberY; + } + + public boolean isClobberC() { + return clobberC; + } + + public boolean isClobberN() { + return clobberN; + } + + public boolean isClobberZ() { + return clobberZ; + } + + public boolean isClobberV() { + return clobberV; + } + + public void setClobberA(boolean clobberA) { + this.clobberA = clobberA; + } + + public void setClobberX(boolean clobberX) { + this.clobberX = clobberX; + } + + public void setClobberY(boolean clobberY) { + this.clobberY = clobberY; + } + + public void setClobberC(boolean clobberC) { + this.clobberC = clobberC; + } + + public void setClobberN(boolean clobberN) { + this.clobberN = clobberN; + } + + public void setClobberZ(boolean clobberZ) { + this.clobberZ = clobberZ; + } + + public void setClobberV(boolean clobberV) { + this.clobberV = clobberV; + } +}