- Notifications
You must be signed in to change notification settings - Fork17
6502/65C02 emulator library (C99)
License
NotificationsYou must be signed in to change notification settings
visrealm/vrEmu6502
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
6502/65C02 emulator written in standard C99 with no external dependencies.
Initially created for myHBC-56 (6502 on a backplane) Emulator
Includes:
- Support for standard 6502/6510, 65C02, WDC65C02 and R65C02.
- Supports all unofficial ("illegal") 6502/6510 opcodes (Use model value
CPU_6502U
). - Correct handling of Decimal mode.
- Accurate instruction timing.
- All WDC and Rockwell-specific 65C02 instructions.
- User-supplied I/O callbacks.
- IRQ and NMI signals.
- Multiple CPU instances.
- Instruction disassembler.
- Test runner.
Includes a test program which was designed to runKlaus Dormann's 6502 tests.
Passes all tests:
- 6502_functional_test (all models)
- 6502_decimal_test (with valid and invalid bcd) (6502)
- 65C02_decimal_test (with valid and invalid bcd) (all 65C02 models)
- 65C02_extended_opcodes_test (Standard 65C02)
- W65C02_extended_opcodes_test (WDC65C02)
- R65C02_extended_opcodes_test (R65C02)
See thetest directory or more details.
vrEmu6502 uses the CMake build system
git clone https://github.com/visrealm/vrEmu6502.gitcd vrEmu6502
mkdir buildcd buildcmake ..
cmake --build .
Windows: Optionally, open the generated solution file
ctest
Windows: Optionally, build the ALL_TESTS project in the generated solution file
#include"vrEmu6502.h"uint8_tram[0x8000];uint8_trom[0x8000];uint8_tMy6502MemoryReadFunction(uint16_taddr,boolisDbg){if (addr<0x8000) {returnram[addr]; }returnrom[addr&0x7fff];}voidMy6502MemoryWriteFunction(uint16_taddr,uint8_tval){if (addr<0x8000) {ram[addr]=val; }}/* fill rom with something that makes sense here *//* create a new WDC 65C02. */VrEmu6502*my6502=vrEmu6502New(CPU_W65C02,My6502MemoryReadFunction,My6502MemoryWriteFunction);if (my6502){/* if you want to interrupt the CPU, get a handle to its IRQ "pin" */vrEmu6502Interrupt*irq=vrEmu6502Int(my6502);/* reset the cpu (technically don't need to do this as vrEmu6502New does reset it) */vrEmu6502Reset(my6502);while (1) {/* call me once for each clock cycle (eg. 1,000,000 times per second for a 1MHz clock) */vrEmu6502Tick(my6502);/* interrupt it? */if (myHardwareWantsAttention) {*irq=IntRequested;/* at some point, the hardware will be happy and it will need to release the interrupt */ } }vrEmu6502Destroy(my6502);my6502=NULL;}
SeeHBC-56 for real-life example usage.
This code is licensed under theMIT license
About
6502/65C02 emulator library (C99)