bsnes/higan/processor/wdc65816/instruction.hpp

259 lines
7.9 KiB
C++
Raw Normal View History

Update to v102r25 release. byuu says: Changelog: - processor/arm: corrected MUL instruction timings [Jonas Quinn] - processor/wdc65816: finished phase two of the rewrite I'm really pleased with the visual results of the wdc65816 core rewrite. I was able to eliminate all of the weird `{Boolean,Natural}BitRange` templates, as well as the need to use unions/structs. Registers are now just simple `uint24` or `uint16` types (technically they're `Natural<T>` types, but then all of higan uses those), flags are now just bool types. I also eliminated all of the implicit object state inside of the core (aa, rd, dp, sp) and instead do all computations on the stack frame with local variables. Through using macros to reference the registers and individual parts of them, I was able to reduce the visual tensity of all of the instructions. And by using normal types without implicit states, I was able to eliminate about 15% of the instructions necessary, instead reusing existing ones. The final third phase of the rewrite will be to recode the disassembler. That code is probably the oldest code in all of higan right now, still using sprintf to generate the output. So it is very long overdue for a cleanup. And now for the bad news ... as with any large code cleanup, regression errors have seeped in. Currently, no games are running at all. I've left the old disassembler in for this reason: we can compare trace logs of v102r23 against trace logs of v102r25. The second there's any difference, we've spotted a buggy instruction and can correct it. With any luck, this will be the last time I ever rewrite the wdc65816 core. My style has changed wildly over the ~10 years since I wrote this core, but it's really solidifed in recent years.
2017-06-14 15:55:55 +00:00
switch(fetch()) {
opA(0x00, Interrupt, EF ? 0xfffe : 0xffe6) //emulation mode lacks BRK vector; uses IRQ vector instead
opM(0x01, IndexedIndirectRead, m(ORA))
opA(0x02, Interrupt, EF ? 0xfff4 : 0xffe4)
opM(0x03, StackRead, m(ORA))
opM(0x04, DirectModify, m(TSB))
opM(0x05, DirectRead, m(ORA))
opM(0x06, DirectModify, m(ASL))
opM(0x07, IndirectLongRead, m(ORA))
opA(0x08, Push8, P)
opM(0x09, ImmediateRead, m(ORA))
opM(0x0a, ImpliedModify, m(ASL), A)
opA(0x0b, PHD)
opM(0x0c, BankModify, m(TSB))
opM(0x0d, BankRead, m(ORA))
opM(0x0e, BankModify, m(ASL))
opM(0x0f, LongRead, m(ORA))
opA(0x10, Branch, NF == 0)
opM(0x11, IndirectIndexedRead, m(ORA))
opM(0x12, IndirectRead, m(ORA))
opM(0x13, IndirectStackRead, m(ORA))
opM(0x14, DirectModify, m(TRB))
opM(0x15, DirectRead, m(ORA), X)
opM(0x16, DirectIndexedModify, m(ASL))
opM(0x17, IndirectLongRead, m(ORA), Y)
opA(0x18, ClearFlag, CF)
opM(0x19, BankRead, m(ORA), Y)
opM(0x1a, ImpliedModify, m(INC), A)
opA(0x1b, TCS)
opM(0x1c, BankModify, m(TRB))
opM(0x1d, BankRead, m(ORA), X)
opM(0x1e, BankIndexedModify, m(ASL))
opM(0x1f, LongRead, m(ORA), X)
opA(0x20, JSRShort)
opM(0x21, IndexedIndirectRead, m(AND))
opA(0x22, JSRLong)
opM(0x23, StackRead, m(AND))
opM(0x24, DirectRead, m(BIT))
opM(0x25, DirectRead, m(AND))
opM(0x26, DirectModify, m(ROL))
opM(0x27, IndirectLongRead, m(AND))
opA(0x28, PLP)
opM(0x29, ImmediateRead, m(AND))
opM(0x2a, ImpliedModify, m(ROL), A)
opA(0x2b, PLD)
opM(0x2c, BankRead, m(BIT))
opM(0x2d, BankRead, m(AND))
opM(0x2e, BankModify, m(ROL))
opM(0x2f, LongRead, m(AND))
opA(0x30, Branch, NF == 1)
opM(0x31, IndirectIndexedRead, m(AND))
opM(0x32, IndirectRead, m(AND))
opM(0x33, IndirectStackRead, m(AND))
opM(0x34, DirectRead, m(BIT), X)
opM(0x35, DirectRead, m(AND), X)
opM(0x36, DirectIndexedModify, m(ROL))
opM(0x37, IndirectLongRead, m(AND), Y)
opA(0x38, SetFlag, CF)
opM(0x39, BankRead, m(AND), Y)
opM(0x3a, ImpliedModify, m(DEC), A)
opA(0x3b, Transfer16, S, A)
opM(0x3c, BankRead, m(BIT), X)
opM(0x3d, BankRead, m(AND), X)
opM(0x3e, BankIndexedModify, m(ROL))
opM(0x3f, LongRead, m(AND), X)
opA(0x40, RTI)
opM(0x41, IndexedIndirectRead, m(EOR))
opA(0x42, WDM)
opM(0x43, StackRead, m(EOR))
opX(0x44, BlockMove, -1)
opM(0x45, DirectRead, m(EOR))
opM(0x46, DirectModify, m(LSR))
opM(0x47, IndirectLongRead, m(EOR))
opM(0x48, Push, A)
opM(0x49, ImmediateRead, m(EOR))
opM(0x4a, ImpliedModify, m(LSR), A)
opA(0x4b, Push8, db(PC))
opA(0x4c, JMPShort)
opM(0x4d, BankRead, m(EOR))
opM(0x4e, BankModify, m(LSR))
opM(0x4f, LongRead, m(EOR))
opA(0x50, Branch, VF == 0)
opM(0x51, IndirectIndexedRead, m(EOR))
opM(0x52, IndirectRead, m(EOR))
opM(0x53, IndirectStackRead, m(EOR))
opX(0x54, BlockMove, +1)
opM(0x55, DirectRead, m(EOR), X)
opM(0x56, DirectIndexedModify, m(LSR))
opM(0x57, IndirectLongRead, m(EOR), Y)
opA(0x58, ClearFlag, IF)
opM(0x59, BankRead, m(EOR), Y)
opX(0x5a, Push, Y)
opA(0x5b, Transfer16, A, D)
opA(0x5c, JMPLong)
opM(0x5d, BankRead, m(EOR), X)
opM(0x5e, BankIndexedModify, m(LSR))
opM(0x5f, LongRead, m(EOR), X)
opA(0x60, RTS)
opM(0x61, IndexedIndirectRead, m(ADC))
opA(0x62, PER)
opM(0x63, StackRead, m(ADC))
opM(0x64, DirectWrite, Z)
opM(0x65, DirectRead, m(ADC))
opM(0x66, DirectModify, m(ROR))
opM(0x67, IndirectLongRead, m(ADC))
opM(0x68, Pull, A)
opM(0x69, ImmediateRead, m(ADC))
opM(0x6a, ImpliedModify, m(ROR), A)
opA(0x6b, RTL)
opA(0x6c, JMPIndirect)
opM(0x6d, BankRead, m(ADC))
opM(0x6e, BankModify, m(ROR))
opM(0x6f, LongRead, m(ADC))
opA(0x70, Branch, VF == 1)
opM(0x71, IndirectIndexedRead, m(ADC))
opM(0x72, IndirectRead, m(ADC))
opM(0x73, IndirectStackRead, m(ADC))
opM(0x74, DirectWrite, Z, X)
opM(0x75, DirectRead, m(ADC), X)
opM(0x76, DirectIndexedModify, m(ROR))
opM(0x77, IndirectLongRead, m(ADC), Y)
opA(0x78, SetFlag, IF)
opM(0x79, BankRead, m(ADC), Y)
opX(0x7a, Pull, Y)
opA(0x7b, Transfer16, D, A)
opA(0x7c, JMPIndexedIndirect)
opM(0x7d, BankRead, m(ADC), X)
opM(0x7e, BankIndexedModify, m(ROR))
opM(0x7f, LongRead, m(ADC), X)
opA(0x80, Branch)
opM(0x81, IndexedIndirectWrite)
opA(0x82, BRL)
opM(0x83, StackWrite)
opX(0x84, DirectWrite, Y)
opM(0x85, DirectWrite, A)
opX(0x86, DirectWrite, X)
opM(0x87, IndirectLongWrite)
opX(0x88, ImpliedModify, x(DEC), Y)
opM(0x89, BITImmediate)
opM(0x8a, Transfer, X, A)
opA(0x8b, Push8, B)
opX(0x8c, BankWrite, Y)
opM(0x8d, BankWrite, A)
opX(0x8e, BankWrite, X)
opM(0x8f, LongWrite)
opA(0x90, Branch, CF == 0)
opM(0x91, IndirectIndexedWrite)
opM(0x92, IndirectWrite)
opM(0x93, IndirectStackWrite)
opX(0x94, DirectWrite, Y, X)
opM(0x95, DirectWrite, A, X)
opX(0x96, DirectWrite, X, Y)
opM(0x97, IndirectLongWrite, Y)
opM(0x98, Transfer, Y, A)
opM(0x99, BankWrite, A, Y)
opA(0x9a, TXS)
opX(0x9b, Transfer, X, Y)
opM(0x9c, BankWrite, Z)
opM(0x9d, BankWrite, A, X)
opM(0x9e, BankWrite, Z, X)
opM(0x9f, LongWrite, X)
opX(0xa0, ImmediateRead, x(LDY))
opM(0xa1, IndexedIndirectRead, m(LDA))
opX(0xa2, ImmediateRead, x(LDX))
opM(0xa3, StackRead, m(LDA))
opX(0xa4, DirectRead, x(LDY))
opM(0xa5, DirectRead, m(LDA))
opX(0xa6, DirectRead, x(LDX))
opM(0xa7, IndirectLongRead, m(LDA))
opX(0xa8, Transfer, A, Y)
opM(0xa9, ImmediateRead, m(LDA))
opX(0xaa, Transfer, A, X)
opA(0xab, PLB)
opX(0xac, BankRead, x(LDY))
opM(0xad, BankRead, m(LDA))
opX(0xae, BankRead, x(LDX))
opM(0xaf, LongRead, m(LDA))
opA(0xb0, Branch, CF == 1)
opM(0xb1, IndirectIndexedRead, m(LDA))
opM(0xb2, IndirectRead, m(LDA))
opM(0xb3, IndirectStackRead, m(LDA))
opX(0xb4, DirectRead, x(LDY), X)
opM(0xb5, DirectRead, m(LDA), X)
opX(0xb6, DirectRead, x(LDX), Y)
opM(0xb7, IndirectLongRead, m(LDA), Y)
opA(0xb8, ClearFlag, VF)
opM(0xb9, BankRead, m(LDA), Y)
opX(0xba, TSX)
opX(0xbb, Transfer, Y, X)
opX(0xbc, BankRead, x(LDY), X)
opM(0xbd, BankRead, m(LDA), X)
opX(0xbe, BankRead, x(LDX), Y)
opM(0xbf, LongRead, m(LDA), X)
opX(0xc0, ImmediateRead, x(CPY))
opM(0xc1, IndexedIndirectRead, m(CMP))
opA(0xc2, REP)
opM(0xc3, StackRead, m(CMP))
opX(0xc4, DirectRead, x(CPY))
opM(0xc5, DirectRead, m(CMP))
opM(0xc6, DirectModify, m(DEC))
opM(0xc7, IndirectLongRead, m(CMP))
opX(0xc8, ImpliedModify, x(INC), Y)
opM(0xc9, ImmediateRead, m(CMP))
opX(0xca, ImpliedModify, x(DEC), X)
opA(0xcb, WAI)
opX(0xcc, BankRead, x(CPY))
opM(0xcd, BankRead, m(CMP))
opM(0xce, BankModify, m(DEC))
opM(0xcf, LongRead, m(CMP))
opA(0xd0, Branch, ZF == 0)
opM(0xd1, IndirectIndexedRead, m(CMP))
opM(0xd2, IndirectRead, m(CMP))
opM(0xd3, IndirectStackRead, m(CMP))
opA(0xd4, PEI)
opM(0xd5, DirectRead, m(CMP), X)
opM(0xd6, DirectIndexedModify, m(DEC))
opM(0xd7, IndirectLongRead, m(CMP), Y)
opA(0xd8, ClearFlag, DF)
opM(0xd9, BankRead, m(CMP), Y)
opX(0xda, Push, X)
opA(0xdb, STP)
opA(0xdc, JMPIndirectLong)
opM(0xdd, BankRead, m(CMP), X)
opM(0xde, BankIndexedModify, m(DEC))
opM(0xdf, LongRead, m(CMP), X)
opX(0xe0, ImmediateRead, x(CPX))
opM(0xe1, IndexedIndirectRead, m(SBC))
opA(0xe2, SEP)
opM(0xe3, StackRead, m(SBC))
opX(0xe4, DirectRead, x(CPX))
opM(0xe5, DirectRead, m(SBC))
opM(0xe6, DirectModify, m(INC))
opM(0xe7, IndirectLongRead, m(SBC))
opX(0xe8, ImpliedModify, x(INC), X)
opM(0xe9, ImmediateRead, m(SBC))
opA(0xea, NOP)
opA(0xeb, XBA)
opX(0xec, BankRead, x(CPX))
opM(0xed, BankRead, m(SBC))
opM(0xee, BankModify, m(INC))
opM(0xef, LongRead, m(SBC))
opA(0xf0, Branch, ZF == 1)
opM(0xf1, IndirectIndexedRead, m(SBC))
opM(0xf2, IndirectRead, m(SBC))
opM(0xf3, IndirectStackRead, m(SBC))
opA(0xf4, PEA)
opM(0xf5, DirectRead, m(SBC), X)
opM(0xf6, DirectIndexedModify, m(INC))
opM(0xf7, IndirectLongRead, m(SBC), Y)
opA(0xf8, SetFlag, DF)
opM(0xf9, BankRead, m(SBC), Y)
opX(0xfa, Pull, X)
opA(0xfb, XCE)
opA(0xfc, JSRIndexedIndirect)
opM(0xfd, BankRead, m(SBC), X)
opM(0xfe, BankIndexedModify, m(INC))
opM(0xff, LongRead, m(SBC), X)
}