Yet another crazy project of mine. Actually the project aims to create an emulator for the Super Nintendo console. “Why?” you say? And then “there are tons of emulators already!”. You are right, but let’s not forget that doing this kind of stuff is fun! There is a lot you can learn by writing an emulator, by the time you are done you will know every single detail about the system. The goal of this project is not to create the next best SNES emulator. I just want to see how far I can get and challenge myself a bit. That’s all.
So far I reached the first milestone, which is emulating the CPU. Super Nintendo was based on the 65816 CPU, which is a 16 bit extension of the super popular 6502 CPU (NES, Commodore, Atari, Terminator, Bender, …).
After reaching the first milestone I decided to stabilize it in case I later give up on the SNES emulator, and I made a C++ library out of it.
The library provides all the bits needed to build a basic system based on 65816. The idea is to write more about how to use it, for now I’ll just add one small example. There is a sample application using the library on my GitHub. All it does is wiring up a very basic system with the CPU and some RAM, load a bunch of instructions, set up the debugger and run the instructions. It’s all very basic but it works.
You can find the library on GitHub. Following is the output from running a very basic program.
$ ./Lib65816_Sample MAIN: +++ Lib65816 Sample Programs +++ Stack: Initialized at default location $01ff Stack: Initialized at default location $01ff Cpu65816Debugger: Cpu is ready to run Cpu65816Debugger: Emulation mode RST vector at $0000 Cpu65816Debugger: Native mode BRK vector at $0000 Cpu65816Debugger: Native mode VSYNC vector at $0000 Cpu65816Debugger: $00:$0000 | $18 CLC Cpu65816Debugger: $00:$0001 | $fb XCE Stack: Initialized at default location $01ff Cpu65816Debugger: $00:$0002 | $a9 LDA #$1265 Cpu65816Debugger: BREAKPOINT $00$0005 Cpu65816Debugger: ====== CPU status start ====== Cpu65816Debugger: A: $1265 X: $0000 Y: $0000 Cpu65816Debugger: PB: $00 PC: $0005 Cpu65816Debugger: DB: $00 D: $0000 Cpu65816Debugger: S (Stack pointer): $01ff Cpu65816Debugger: P (Status): $01 Cpu65816Debugger: ====== CPU status end ====== MAIN: +++ Program completed +++
The library is still in development and might still contain bugs, so be careful if you decide to use it. If you do and find some issue please let me know!