6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 4:13 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sun Jan 16, 2022 10:45 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
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


Attachments:
BreaksDebug_17.zip [712.42 KiB]
Downloaded 55 times
149550095-053e9276-df3b-4868-b8d4-b5987c47209a.png
149550095-053e9276-df3b-4868-b8d4-b5987c47209a.png [ 235.25 KiB | Viewed 4620 times ]
148691773-e7dbd64a-8067-41f2-82c5-94662ee20311.png
148691773-e7dbd64a-8067-41f2-82c5-94662ee20311.png [ 398.52 KiB | Viewed 4620 times ]

_________________
6502 addict


Last edited by org on Fri Jan 21, 2022 5:26 pm, edited 3 times in total.
Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 18, 2022 12:02 am 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
Fixed the emulation of the tricky S register.

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

_________________
6502 addict


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 18, 2022 11:09 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
It was a great joy to see how the 6502 uses S as a temporary during JSR!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 19, 2022 4:29 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
https://github.com/emu-russia/breaks/re ... s-debug-16

All 6502 instructions are now executed correctly.

_________________
6502 addict


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 19, 2022 4:49 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
UnitTest Mode

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

Code:
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:
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).

_________________
6502 addict


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 21, 2022 5:16 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
The M6502Core is tested in the Nintendulator:

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

_________________
6502 addict


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 21, 2022 6:19 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Oh, do I take it you found a couple of bugs not spotted by Klaus Dormann's test?


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 25, 2022 11:43 am 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
Thanks for the tip, I'll check them out too!

_________________
6502 addict


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 07, 2022 2:50 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
All functional tests of the 6502 by Klaus Dormann are successful.

I ran the unit test with these parameters:

Code:
{
   "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:
{"A":"0xF0","X":"0x0E","Y":"0xFF","S":"0xFF","PC":"0x3469","C":1,"Z":0,"I":0,"D":0,"V":1,"N":1,"CLK":96241361}


Attachments:
reset_patch.jpg
reset_patch.jpg [ 335.08 KiB | Viewed 4189 times ]
page_2.jpg
page_2.jpg [ 278.67 KiB | Viewed 4189 times ]
page_0.jpg
page_0.jpg [ 276.96 KiB | Viewed 4189 times ]

_________________
6502 addict
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: