A Simple 6502 / 65C02 implementation for Digital
This implementation aims simplicity for educational purposes. For a more complete documentation (work in progress) refer to the docu.md file.
It is fully 6502 and 65C02 compatible and passes all functional and extended opcode tests from Klaus Dormann's test suite, but it is NOT cycle accurate with the original CPU versions. (The actual cycles for each opcode can be seen in the microcode ROM files).
The microcode is generated by a C program and can generate the 6502 or 65C02 microcode. (Use any C compiler, but it has been only tested with GCC.)
The interrupts are handled by injecting the BRK opcode just like in the original CPU.
To start open the 6502.dig file in Digital.
The test suite will be loaded into the RAM and the simulation can be started.
(The test suite runs quite a long time but when it finishes it loads ASCII 'E'($45), 'N'($4E), 'D'($44) into the registers A X and Y and the PC loops around $34DE.)
This is a simplified version of the circuit (simpler ALU and interrupt logic) which only supports the 6502 microcode.
There is also a generic version of the CPU with isolated data bus which can be included as a sub-circuit and configured as either 6502 or 65C02. For examples see 6502_test.dig and 65c02_test.dig.
In theese versions the test suit output to the memory mapped data terminal at address $0000.
Unfortunately Digital does not allow to "dive" into a sub-circuit during the simulation, but if you right click on the RAM you can view it's contents updating during the simulation.
The circuit 6502_basic.dig shows a tipical configuration to run MS-BASIC including a telnet terminal as I/O.
Memory configuration:
| Start | End | Peripheral |
|---|---|---|
| $0000 | $7FFF | 32 KB RAM |
| $8000 | $BFFF | Telnet I/O |
| $C000 | $FFFF | 16 KB Basic ROM |
The MS-BASIC source has been modified to work with the above configuration and includes the compiled binary ROM image which the circuit loads on start. You will need a decent terminal program (putty) to connect to port 23. The basic interpretter understands only capitals so use caps lock.
*** MS-BASIC ***
Detecting RAM size...
U
32255 BYTES FREE
COPYRIGHT 1977 BY MICROSOFT CO.
OK
5 A$(0)="/":A$(1)="\"
10 PRINT A$(0.5+RND(1));:GOTO 10
RUN
//\//\/\\\\/\/\\//\\/\\\/\\\\\\\\////\\\\\\//\/\\\\\///\\/\/\\//\\/\///\/\\\/\//
//\\\\/\/\\/\\\\\\//\\/\//\\\/\/\\/\/\//\/\\\/\\\\\//\\/\/\//\//\\\\\\\\\//\\/\/
//\\\\///\\/\\\\\//\/\/\//\/\\\/\\\/\//\\/\/\//////\//\///////\\/\\\/\\//\/\\\\/
/\//\//\\//\\\/\/\\/\\\////\\/\///\\////\\\/\/\/\/\/\\\/\\\\\/\\\///\\/\\/\\\\//
///\//\/////\///////\\/\/\//\/\/\/\\\/\\////\/\//\///\\\/\//\/\\\/\////\\\//\\\/
///\\/\\//\/\//\\\/\////\\\///////\\\//\/\\\//\\\\\///\\//\//\///\/\\/\\\//\/\/\
\/////\\//\/\/\////\//\\\/\//\/\\\\\/\////\\\//\\\/\\////\/\/\/\\\/\\\///\\\\/\/
\//\\//\//\\\\/\\////\///\////\/\/\///\//\\\\\///\/\///\/\//\/\\///////\\\/\//\\
\//\\//\///\/\//\\\\\\\/\/\//\\\/\/\\/\\\\/\\/\/\/\/\\/\\\\\\\\\\/\\///\/\/\\\//
\\\\/\/\\//\\\/////\/\//\//\\\\\/\////\\\/\/\\\\/\\//\///////\////\\///\\\\\/\\\
\//////\\/\/\\\///\\/\\\/\/\\\\\\///\//\/\/\//\/\\\\/\/\//\\\\/\\///\/\\\\\\///\
/\//\/\//\/////\//\/\///\\////\//\\//\///\//\/\//\\////\\/\\\/\\/\\\/\//\\/\/\\/
\\/\///\//\/\\/\\/\//////\///\\\//\\\///\\\////\\//\\\\\/\/\\\\////\\\\\/\\\/\\/
\/\//\\/\////\/\//\///\/\\\/\//\/\/\//\//\/\/\\///\//\\\///\/\/\\\
BREAK IN 10
OK
Note: The U below Detecting RAM size... is the RAM size test routine from BASIC writing it's test pattern directly after the RAM area but it hits the telnet I/O space.
In general you will need:
- Helmut Neemann's Digital simulator to run the circuit
- A C compiler if you want to change the microcode easily
- A 6502 assembler if you want to run your own 6502 code or make changes to the test suits or the MS-BASIC sources
- A telnet client or terminal program if you want to play with MS-BASIC
Inspirations and informations are taken from: