| 1 |
The original fake6502.c has been split up into subcomponents, rather than being one long file - |
| 2 |
support functions, 6502 instructions, address modes, data tables and 65c02 extensions. |
| 3 |
|
| 4 |
The file tables.h is now created from 6502.opcodes and 65c02.opcodes which are lists of instructions, |
| 5 |
cycle times, address modes and opcodes. |
| 6 |
|
| 7 |
The python script buildtables.py creates this. |
| 8 |
|
| 9 |
Minor changes have been made to modes.h and instructions.h to correct for 65C02 behaviour. These |
| 10 |
are documented in the files. |
| 11 |
|
| 12 |
Breaking Changes |
| 13 |
================ |
| 14 |
|
| 15 |
Note: these breaking changes are *only in the emulator*. The behaviour is correct for a 65C02, which is |
| 16 |
almost but not the same as a 6502. |
| 17 |
|
| 18 |
(1) BRK clears D after pushing on the stack. Probably unimportant as most routines in 6502 |
| 19 |
code CLD to get round this issue anyway. |
| 20 |
|
| 21 |
(2) ADC/SBC In Decimal Mode, these now set N and Z flags. They did not previously. It is |
| 22 |
possible that code may rely on this to preserve flag status through an ALU |
| 23 |
operation but unlikely. |
| 24 |
|
| 25 |
(3) JMP The absolute indirect mode JMP (xxxx) had a bug where JMP ($12FF) got its |
| 26 |
target address from $12FF and $1200. This bug is corrected. |
| 27 |
This could break code with oddly positioned jump tables. Even align any vector |
| 28 |
tables or memory vectors. |
| 29 |
|
| 30 |
(4) (Misc) Undocumented instructions now do not work. They don't work on a 65C02. |
| 31 |
|
| 32 |
Also note that read-modify-write instructions all now do not do the double write. ASL xx would do |
| 33 |
read xx ; write xx ; write shifted xx on a 6502. On a 65C02 it does not. However, the emulator did |
| 34 |
not emulate this behaviour anyway, so it doesn't actually matter. |
| 35 |
|
| 36 |
Paul Robson 4/Sep/19 |
| 37 |
|
| 38 |
Testing |
| 39 |
======= |
| 40 |
Fixed stz bug .... writing a ... duh ! |
| 41 |
|
| 42 |
Conformance fixes |
| 43 |
================= |
| 44 |
|
| 45 |
Found by tests/test_processor_tests.c, which runs SingleStepTests against the |
| 46 |
core. Each changes emulated behaviour, so code that depended on the old |
| 47 |
behaviour will see a difference. |
| 48 |
|
| 49 |
(1) P bit 4 Was forced set on every instruction for the 65C02, which |
| 50 |
applies the 65C816's emulation-mode rule to the wrong CPU. |
| 51 |
Bit 4 has no register bit behind it on a 65C02 and is now |
| 52 |
preserved. PLP and RTI no longer load it from the stack. |
| 53 |
|
| 54 |
(2) $5C $DC $FC Were one-byte implied NOPs, so their operand bytes were |
| 55 |
executed. Now three bytes, as on a real 65C02. $5C is 8 |
| 56 |
cycles per the WDC datasheet and the 6502.org opcode list; |
| 57 |
SingleStepTests says 4, and that divergence is recorded in |
| 58 |
the baseline rather than matched. |
| 59 |
|
| 60 |
(3) SBC Decimal mode used the NMOS per-nibble correction. The |
| 61 |
65C02 subtracts in binary and corrects afterwards. The two |
| 62 |
differ only when a digit is $A-$F. Overflow was also |
| 63 |
computed from the carry the instruction had just written |
| 64 |
rather than the one it started with. |
| 65 |
|
| 66 |
(4) BRK Cost 14 cycles: interrupt6502() charges seven for the |
| 67 |
interrupt sequence, which BRK also pays through the opcode |
| 68 |
table. IRQ and NMI still need it, as neither goes through |
| 69 |
the table. |
| 70 |
|
| 71 |
(5) Timing JMP (abs) is 6 cycles, not the NMOS 5. ASL, ROL, LSR and |
| 72 |
ROR abs,X are 6 plus one only when indexing crosses a page, |
| 73 |
where the NMOS always paid it. BIT abs,X gains the same |
| 74 |
conditional cycle. The variant opcode files may now override |
| 75 |
6502.opcodes rather than only adding to it. |
| 76 |
|
| 77 |
(6) 65C816 A 16-bit operand costs an extra cycle, which only LDA |
| 78 |
charged. PHX, PHY, PLX and PLY charged the accumulator |
| 79 |
width instead of the index width, and TSB charged nothing. |
| 80 |
|
| 81 |
(7) 65C816 (dp), (dp,X), (dp),Y and (sr),Y ignored the data bank and |
| 82 |
used bank 0. Indexing now carries past $FFFF into the next |
| 83 |
bank. |
| 84 |
|
| 85 |
The read-modify-write double write noted above is still not emulated, and shows |
| 86 |
up as a bus-trace divergence in the same tests. |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|