6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 9:12 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Wed Jun 04, 2014 9:56 pm 
Offline

Joined: Wed Jun 04, 2014 9:07 pm
Posts: 8
Hi, I'm writing a 6502 emulator, I'm testing it with a ROM I'm doing myself too, but would like to have some other emulator to compare to, as a reference.
As when I see my emu doing something different than the other emu, it will point most likely to a bug in mine.

For that, I need an emulator that can output a runtime disassembly in some parseable format that I can compare programmatically to my emu's disassembly.
( Because running each emu side by side and step by step would do for the first 100 instructions, but I have to use some automated method to test it further )

If said emulator has binaries for Mac OSX or has portable C/C++ sources I can build from, that would be great.

Thanks in advance.

PS: If someone wants to talk me out of making yet another 6502 emu, I think that's good advice, but we could leave that to a different thread.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 05, 2014 1:08 am 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
Two suggestions for you, then:

First, there are 6502 test suites out there, grab a few and use them.

Second, if you really want to work in terms of execution traces from an existing simulator, find a simulator that you can modify in order to add the tracing output that you want.

Writing your own CPU simulator is, in many ways, a rite of passage. I've written several, with varying degrees of success... and varying levels of documentation. The 6502 was one of the easier ones, for all that it was my first. Best of luck.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 05, 2014 4:27 am 
Offline

Joined: Wed Jun 04, 2014 9:07 pm
Posts: 8
1) I've seen some but they I didn't find any with a clear documentation of how to run it and how to know the test results. Anyway, I could run tests, or games or whatever piece of machine code. The important thing is comparing if the outputs are different or the same.
2) Good advice, I'll try that. The problem is that I've already seen many emulators' source, at least for NES emulators, and most are really poorly documented and highly optimization-wise obfuscated as to take the time to read and understand their source code to be able to modify it.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 05, 2014 5:09 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
Petruza wrote:
1) I've seen some but they I didn't find any with a clear documentation of how to run it and how to know the test results. Anyway, I could run tests, or games or whatever piece of machine code. The important thing is comparing if the outputs are different or the same.
2) Good advice, I'll try that. The problem is that I've already seen many emulators' source, at least for NES emulators, and most are really poorly documented and highly optimization-wise obfuscated as to take the time to read and understand their source code to be able to modify it.

You could have a look at the Kowalski simulator (pedantic note: what you are talking about is a simulator, not an emulator—the latter term generally refers to hardware) to see if that will do it for you.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 05, 2014 6:22 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Welcome, Petruza :)

My knowledge of these matters is superficial, but I have a hunch the test suite by Klaus2m5 here on 6502.org may be just what you need. It seems to be the subject of extensive discussion and improvement, and is probably worth checking out: Functional Test for the NMOS 6502 - request for verification

Cheers,
Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 05, 2014 9:41 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Seconded, to use Klaus' suite - it is self-checking, and can either report when it fails or go into a loop.

For a modifiable emulator, I'd go with Ian Piumarta's run6502, because it's C and command-line. It is quite compact and quite clever C, so it may be a learning experience.
http://www.piumarta.com/software/lib6502/

I attach a patch file which might help. But probably you're better off with a dump of the machine state, not a disassembly.
Code:
ed$ ./run6502 -B -t 10 -l 0 bbc.img
D9CD A940    @  lda #40
D9CF 8D000D     sta 0D00
D9D2 78     x   sei
D9D3 D8         cld
D9D4 A2FF       ldx #FF
D9D6 9A         txs
D9D7 AD4EFE  N  lda FE4E
D9DA 0A         asla
D9DB 48     H   pha
D9DC F009       beq D9E7
D9E7 A204       ldx #04
D9E9 8601       stx 01
D9EB 8500       sta 00
D9ED A8         tay
D9EE 9100       sta (00),Y
tracing limit reached

BBC Computer 32K

BASIC

>


Note that getting the decimal mode arithmetic to work is a special challenge - Klaus' test will check it, and unfortunately lib6502 fails. I'd recommend you use Bruce's test for decimal mode:
http://www.6502.org/tutorials/decimal_mode.html

Cheers
Ed


Attachments:
File comment: patch file for lib6502 to add tracing
lib6502-tracing.patch.txt [10.45 KiB]
Downloaded 98 times
Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 06, 2014 12:43 am 
Offline

Joined: Wed Jun 04, 2014 9:07 pm
Posts: 8
BigDumbDinosaur wrote:
(pedantic note: what you are talking about is a simulator, not an emulator

Not pedantic at all, it's good to learn the right terminology. I come from a more software-oriented view of emulation were we call them emulators as in MAME, but reading this site and forum I see here that simulator makes more sense in this context.

Thanks to all, I'll try your suggestions and let you know.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 06, 2014 5:40 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Petruza wrote:
BigDumbDinosaur wrote:
(pedantic note: what you are talking about is a simulator, not an emulator

Not pedantic at all, it's good to learn the right terminology. I come from a more software-oriented view of emulation were we call them emulators as in MAME, but reading this site and forum I see here that simulator makes more sense in this context.

Beware - this is not at all a settled point! [...deleted details...]

Say "emulator" and no-one will be confused. A very few people will be mildly perturbed. Say "simulator" and you will be in a small minority, and will be communicating less clearly.

In an effort not to derail this thread I've started another one about this terminological point, which keeps coming up, to no-one's delight.

Cheers
Ed


Last edited by BigEd on Fri Jun 06, 2014 6:36 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 07, 2014 8:40 pm 
Offline

Joined: Wed Jun 04, 2014 9:07 pm
Posts: 8
BigEd wrote:
I'd go with Ian Piumarta's run6502, because it's C and command-line. It is quite compact and quite clever C, so it may be a learning experience.
http://www.piumarta.com/software/lib6502/

Thanks Ed for the suggestion, I'm debugging it to try and understand how to call a single instruction so I run its emulation and mine step by step and side by side and compare the cpu state in each step.
Unfortunately it's a macro hell, hard to debug and understand, isn't there any other C emulator nicer to the eye?
I'll keep trying with this one in the meantime.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 07, 2014 11:56 pm 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
I hate to suggest trying to dig up a copy of DarcNES, especially since I don't remember offhand if it does decimal mode even remotely correctly, but the 6502 simulator should (based on looking at my local copy of the 6280 simulator) be very easy to hack to output a trace on a per-instruction (not per-cycle) basis. It won't cover undocumented opcodes, and I don't recall if it works for decimal mode or not, but should be close to cycle-exact for an NMOS system (again, on a per-instruction, not per-cycle, basis), and is capable of playing at least some Apple ][ games (not to mention NES games), though IIRC some part of the input system needs to be updated for the newer C specification.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 08, 2014 5:39 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Petruza wrote:
... isn't there any other C emulator nicer to the eye?

You could try lib65816/run65816, which is more conventional (but therefore more bulky) - it emulates a 65816 but just like the real thing it boots into a 65C02 mode which is entirely compatible.
viewtopic.php?f=8&t=1176&p=23983&hilit=run65816#p23983

Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 09, 2014 7:51 pm 
Offline

Joined: Wed Jun 04, 2014 9:07 pm
Posts: 8
nyef wrote:
... DarcNES, especially since I don't remember offhand if it does decimal mode ...

It's OK since the NES has no decimal mode and my first goal for the 6502 emu is to be used in a NES emu so I'm OK with no decimal
will try it, thanks


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 12 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: