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
./run.sh
Note: the run script will run make then if the exit code is not an error will run bin/emulator.out
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: everything ncurses related
- keyboard handler: listener for key presses
After quitting, the program dumps its memory to a .bin file.
The example program source code is stored in 6502-src/. Compile with the VASM compiler.
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
0x0000and0xFFFFwe 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
- convert argument processing to getopt / getoptlong
- add the possibility to load custom programs
- add the possibility to load custom programs at specific memory locations
- abstract all memory access through a read and write function
- add highlighting of the last memory read or write
- add the ability to set the third memory display to follow the PC page
- add ability to set the address for the fourth memory display