A simple 6502 emulator, with I/O via a 6850 UART.
Go to file
Rob McMullen ff67a94658 Added tests from https://github.com/kingcons/cl-6502 2017-12-19 17:45:43 -08:00
examples Initial commit 2017-01-03 19:39:48 +00:00
test Added tests from https://github.com/kingcons/cl-6502 2017-12-19 17:45:43 -08:00
.gitignore Improve/simplify Makefile. main.c also renamed. 2017-01-03 20:01:18 +00:00
6502-emu.c Added -f flag to step through emulation at max possible speed (i.e. without the delay loop) 2017-12-19 14:59:28 -08:00
6502.c Added decimal mode for ADC and SBC 2017-12-19 17:25:35 -08:00
6502.h Added -l command line argument to specify load address 2017-12-19 11:44:17 -08:00
6850.c Fixed backspace, mostly 2017-02-08 15:37:31 +00:00
6850.h Make status bits bools 2017-01-07 21:25:34 +00:00
LICENSE Initial commit 2017-01-03 19:29:36 +00:00
Makefile Reverted changes to Makefile to compile debug by default 2017-12-19 09:20:27 -08:00
README.md Adjust wording 2017-01-03 21:30:18 +00:00
compare.py Added tests from https://github.com/kingcons/cl-6502 2017-12-19 17:45:43 -08:00
run-tests.sh Added tests from https://github.com/kingcons/cl-6502 2017-12-19 17:45:43 -08:00

README.md

6502-emu

A relatively bug-free and simple 6502 emulator. It is capable of running ehBasic.

Many 6502 emulators make extensive use of macros, which I personally think makes code harder to understand. At the other extreme, some emulators implement each addressing mode of each instruction separately, which is a big waste of time and makes the code harder to maintain.

I chose a middle-ground, and used lookup tables for instruction decoding and address decoding. This also gets rid of the common "giant opcode switch statement" (which can be seen in my CHIP8 emulator project).

Usage Example:

[david@D-ARCH 6502-emu]$ ./6502-emu examples/ehbasic.rom 

Enhanced 6502 BASIC 2.22 (c) Lee Davison
[C]old/[W]arm ?

Memory size ? 

40191 Bytes free

Enhanced BASIC 2.22

Ready
10 X1=59
15 Y1=21
20 I1=-1.0
23 I2=1.0
26 R1=-2.0
28 R2=1.0
30 S1=(R2-R1)/X1
35 S2=(I2-I1)/Y1
40 FOR Y=0 TO Y1
50 I3=I1+S2*Y
60 FOR X=0 TO X1
70 R3=R1+S1*X
73 Z1=R3
76 Z2=I3
80 FOR N=0 TO 30
90 A=Z1*Z1
95 B=Z2*Z2
100 IF A+B>4.0 GOTO 130
110 Z2=2*Z1*Z2+I3
115 Z1=A-B+R3
120 NEXT N
130 PRINT CHR$(63-N);
140 NEXT X
150 PRINT
160 NEXT Y
170 END

RUN
??????>>>>>===============<<<<<<;;;:7143;<<<<====>>>>>>>>>>>
?????>>>================<<<<<<<;;;984+18:;;<<<<=====>>>>>>>>
????>>>===============<<<<<<<;;::85    )/:;;;;<<=====>>>>>>>
???>>===============<<<<<<;:9999875     689::::;<<=====>>>>>
??>>=============<<<<;;;;::7/ '3           56446;<======>>>>
??>===========<<<;;;;;;:::863                 +8:;<======>>>
?>========<<<;6::::::::997!                   &89;<<======>>
?====<<<<<;;;:83567.678874                      ,:<<=======>
?=<<<<<<;;;;:986'      /4                       +:<<<======>
?<<<<<<;;::8675(        (                       9;<<<======>
?;;:999:88460                                 '9:;<<<======>
?;;:999:88460                                 '9:;<<<======>
?<<<<<<;;::8675(        (                       9;<<<======>
?=<<<<<<;;;;:986'      /4                       +:<<<======>
?====<<<<<;;;:83567.678874                      ,:<<=======>
?>========<<<;6::::::::997!                   &89;<<======>>
??>===========<<<;;;;;;:::863                 +8:;<======>>>
??>>=============<<<<;;;;::7/ '3           56446;<======>>>>
???>>===============<<<<<<;:9999875     689::::;<<=====>>>>>
????>>>===============<<<<<<<;;::85    )/:;;;;<<=====>>>>>>>
?????>>>================<<<<<<<;;;984+18:;;<<<<=====>>>>>>>>
??????>>>>>===============<<<<<<;;;:7143;<<<<====>>>>>>>>>>>

Ready

TODO:

  • Decimal mode.
  • Cycle-accurate timing.
  • GDB interface for easy debugging of 6502 programs (and the emulator itself).
  • Implement more hardware devices (mainly a 6522, also some character/graphics LCDs).
  • Turn it into a NES emulator.