

opcode values other than the designed 151). Since the 6502 CPU uses 8 bit to encode the opcode value it also has a lot of "illegal opcodes" (i.e. Uint16_t Addr_ABI() // ABSOLUTE INDIRECTĪll the 151 opcodes are emulated. Uint16_t Addr_INY() // INDEXED-Y INDIRECT Uint16_t Addr_INX() // INDEXED-X INDIRECT Uint16_t Addr_ABY() // INDEXED-Y ABSOLUTE Uint16_t Addr_ABX() // INDEXED-X ABSOLUTE Uint16_t Addr_ZEY() // INDEXED-Y ZERO PAGE Uint16_t Addr_ZEX() // INDEXED-X ZERO PAGE My project is a simple jump-table based emulator: the actual value of the opcode (let's say 0x80) is used to address a function pointer table, each entry of such table is a C++ function which emulates the behavior of the corresponding real instruction.Īll the 13 addressing modes are emulated:
#6502 EMULATOR CODE#
The switch-case based are the simpler ones but also the slowest: the opcode value is thrown inside a huge switch case which selects the code snippet to execute compilers can optimize switch case to reach near O(log(n)) complexity but they hardly do it when dealing with sparse integers (like most of the CPU opcode tables).

The PLA/microcode based are the best as they offer both speed and limited complexity. However, the complexity of such emulators is non-linear with the number of transistors: in other word, you don't want to emulate a modern Intel quad core using this approach!!! They emulate even the unwanted glitches, known and still unknown. The latter are the most accurate as they emulate the connections between transistors inside the die of the CPU. You can group all the CPU emulators out there in 4 main categories:
#6502 EMULATOR UPDATE#
However cycle accuracy is not yet implemented so mid-frame register update tricks cannot be reliably emulated. You can use this emulator in your machine emulator project. This CPU (and its many derivatives) powered machines such as:Īnd many other embedded devices still used today. at least on the normal behavior: as I said stuff like illegal opcodes or hardware glitches are currently not implemented. So expect nearly 100% compliance with the real deal. The emulator was extensively tested against this test suite:

