A minimal, single-stepped and beginner friendly 6502 emulator written in C using ncurses for graphics.
This main goal of this project is to understand how CPUs works by directly emulating one and to debug it by single stepping instructions. The code is meant to be readable and understandable, a lot of things could be done better, especially the graphics.
The emulator only shows you what's going on under the hood of a 6502 CPU, without displaying stuff graphically (you will only see hex digits). The example program simply caluclates 10*3
and it's not optimized.
You must have ncurses
installed on your machine. This project was developed in a Linux environment.
make
./bin/emulator.out
Or you can run the shortcut script
bash run.sh
By default, the emulator loads example.bin
. If you want to load a custom binary file, just provide the path as the second argument while launching the emulator:
./bin/emulator.out your_binary_here
The paradigm I've chosen is modular programming
, especially because this is C. System components aren't defined in a OOP way.
Everything is very verbose with a lot of comments.
The project is divided in multiple components:
- cpu: here you will find the CPU itself, including main methods to interact with the memory
- instructions handler: here we handle OP codes
- mem: pretty simple memory implementation, each page has a dedicated array
- peripherals
- interface: everyhting ncurses related
- keyboard handler: listener for key presses
After quitting, the program dumps its memory to a .bin
file.
The loaded program multiplies 10 by 3, in order to try it you must single step instructions until you see 1E
(30) in the third memory cell in the zero page. You can continue to single step it but nothing will happen.
Do you want to contribute? Here are some things that are still a WIP.
- check for errors on cpu_fetch() calls
- due to uint16_t always being between
0x0000
and0xFFFF
we don't have to perform extra checking while fetching memory.
- due to uint16_t always being between
- add remaining comments to
instructions.c
- create a better interface
- add the possibility to load custom programs