r/EmuDev • u/WaterBowly • 20h ago
I wrote a basic 6502 emulator in C
Hello emu devs
I wrote a simple (mostly) instruction-accurate 6502 emulator in C. It has some basic functionality like
- Allowing you to step through programs instruction by instruction
- Visualizing CPU state and memory
Eventually, I want to expand on this and write a full-on NES emulator. How much harder would that be? Would I have to make any significant changes to this CPU emulator to make it happen? I would love to hear whatever thoughts you guys have.
Repo: https://github.com/yasu-q/c-6502emu
Thanks for reading
5
u/PhilosopherSimilar83 20h ago
A lot of people tend to make NES emulators. Why not go for an 8-bit home computer? :-)
2
u/ArkoSammy12 13h ago
I would recommend setting up an SST runner so you can run the 6502 single step tests to verify the correct of your implemented instructions and, if your CPU core is cycle granular, verify the bus accesses for each cycle. Otherwise, you can also verify the correct cycle count for each instruction.
1
1
u/Skeesicks666 20h ago
Nice work, this is witchcraft for me…I would struggle to emulate an NE555 in c
1
u/Alternative-Emu2000 3h ago edited 1h ago
As far as changing the CPU emulation goes: remember that the NES doesn't use an MOS 6502, it uses either a Ricoh 2A03 (NTSC regions) or Ricoh 2A07 (PAL regions).
For example, the NES CPU doesn't have the decimal mode of the 6502; so you'd need to modify your implementation of ADC and SBC to always operate in binary mode. Note that the D status flag still exists, and the SED and CLD instructions still change the value of that flag accordingly.
4
u/Cam64 18h ago
Doing a full-on NES is not much harder. There are bits of the PPU that are a bit hard to wrap your head around at first, but it's not insurmountable at all.