6502 emulator for Commodore 64 ROMs, serial terminal edition for MBED. Recommend terminal echo on, line edit on, caps lock, 115200bps, implicit carriage return on newline, currently non-buffered so don't paste lots of stuff
More details at:
[https://github.com/davervw] [https://techwithdave.davevw.com/2020/03/simple-emu-c64.html]
Diff: emu6502.cpp
- Revision:
- 8:519febdce8db
- Parent:
- 7:f49fa56672d8
--- a/emu6502.cpp Mon Apr 13 05:13:26 2020 +0000 +++ b/emu6502.cpp Wed Apr 15 05:15:07 2020 +0000 @@ -58,7 +58,7 @@ extern void ResetRun(bool (*ExecutePatch)(void)) { - ushort addr = (ushort)((GetMemory(0xFFFC) | (GetMemory(0xFFFD) << 8))); // RESET vector + ushort addr = (ushort)((GetMemory(0xFFFC) | (GetMemory(0xFFFD) << 8))); // JMP(RESET) Execute(addr, ExecutePatch); } @@ -96,17 +96,6 @@ return (byte)(value >> 8); } -static void BRK(byte *p_bytes) -{ - ++PC; - Push(HI(PC)); - Push(LO(PC)); - PHP(); - B = true; - PC = (ushort)(GetMemory(0xFFFE) + (GetMemory(0xFFFF) << 8)); - *p_bytes = 0; -} - static byte Subtract(byte reg, byte value, bool *p_overflow) { bool old_reg_neg = (reg & 0x80) != 0; @@ -498,6 +487,17 @@ *p_addr = (ushort)((hi << 8) | lo); } +static void BRK(byte *p_bytes) +{ + ++PC; + Push(HI(PC)); + Push(LO(PC)); + PHP(); + B = true; + PC = (ushort)(GetMemory(0xFFFE) + (GetMemory(0xFFFF) << 8)); // JMP(IRQ) + *p_bytes = 0; +} + static void JMP(ushort *p_addr, byte *p_bytes) { *p_bytes = 0; // caller should not advance address