Page 1 of 1

Breaks Debugger + 6502 Simulator on gate level

Posted: Sun Jan 16, 2022 10:45 pm
by org
After many years of research and experiments I think it is time to present you the result - the 6502 simulator (or emulator) on the gate level - Breaks Debugger.

https://github.com/emu-russia/breaks/re ... s-debug-17

(If you're interested you can read the development history of previous versions there)

The Debugger consists of two parts - GUI in c# to display the internals of the processor and native code in c++ which contains the actual emulation of the processor. When you click on the "Step" button, the processor performs one half-cycle and the GUI shows you what's there. The debugger also includes a simple assembler that compiles a 64 Kbyte memory blob at once.

The data flow diagram for the lower part with slight modifications is taken from the dissection of 6502 by ttlworks. Thanks ttlworks! :)

It is possible to dump the internals as Markdown with pictures, for this you need to create a folder WikiMarkdown, where results will be stored.

An example of what results can be seen here: https://github.com/emu-russia/breaks/bl ... /ops/A2.md

Source code of the 6502 emulator here: https://github.com/emu-russia/breaks/tr ... /M6502Core

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Tue Jan 18, 2022 12:02 am
by org
Fixed the emulation of the tricky S register.

https://github.com/emu-russia/breaks/re ... s-debug-15

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Tue Jan 18, 2022 11:09 am
by BigEd
It was a great joy to see how the 6502 uses S as a temporary during JSR!

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Wed Jan 19, 2022 4:29 pm
by org
https://github.com/emu-russia/breaks/re ... s-debug-16

All 6502 instructions are now executed correctly.

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Wed Jan 19, 2022 4:49 pm
by org
UnitTest Mode

To run the debugger in unit test mode, you need to create a JSON like this:

Code: Select all

json
{
	"CompileFromSource": true,
	"MemDumpInput": "mem.bin",
	"AsmSource": "Test.asm",
	"RamStart": "0",
	"RamSize": "0x800",
	"RomStart": "0xc000",
	"RomSize": "0x4000",
	"RunUntilBrk": true,
	"RunCycleAmount": true,
	"CycleMax": 10000,
	"DumpMem": true,
	"JsonResult": "res.json",
	"MemDumpOutput": "mem2.bin"
}
And run with parameter:

Code: Select all

BreaksDebugger Test.json
As input code, you can use 64 Kbytes memory dump (MemDumpInput) or assembly language source (AsmSource).

Simulator will run until it encounters instruction `BRK` (RunUntilBrk) or specified number of cycles (RunCycleAmount, CycleMax) (These are cycles, not half-cycles).

The output will be a memory dump after simulation (MemDumpOutput) and JSON with simulation results (JsonResult).

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Fri Jan 21, 2022 5:16 pm
by org
The M6502Core is tested in the Nintendulator:

https://github.com/emu-russia/breaks/re ... s-debug-17

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Fri Jan 21, 2022 6:19 pm
by BigEd
Oh, do I take it you found a couple of bugs not spotted by Klaus Dormann's test?

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Tue Jan 25, 2022 11:43 am
by org
Thanks for the tip, I'll check them out too!

Re: Breaks Debugger + 6502 Simulator on gate level

Posted: Mon Feb 07, 2022 2:50 pm
by org
All functional tests of the 6502 by Klaus Dormann are successful.

I ran the unit test with these parameters:

Code: Select all

{
	"CompileFromSource": false,
	"MemDumpInput": "6502_functional_test.bin",
	"AsmSource": "Test.asm",
	"RamStart": "0",
	"RamSize": "0x8000",
	"RomStart": "0xc000",
	"RomSize": "0x4000",
	"RunUntilBrk": false,
	"RunCycleAmount": true,
	"CycleMax": 120000000,
	"RunUntilPC": true,
	"PC": "0x3469",
	"TraceMemOps": false,
	"TraceCLK": true,
	"DumpMem": true,
	"JsonResult": "res.json",
	"MemDumpOutput": "mem_out.bin"
}
The original image was slightly patched (RESET = 0x0400).

The state of the registers and the CLK on the output:

Code: Select all

{"A":"0xF0","X":"0x0E","Y":"0xFF","S":"0xFF","PC":"0x3469","C":1,"Z":0,"I":0,"D":0,"V":1,"N":1,"CLK":96241361}