Page 1 of 1
I need a 6502 emulator that outputs its runtime disassembly
Posted: Wed Jun 04, 2014 9:56 pm
by Petruza
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.
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Thu Jun 05, 2014 1:08 am
by nyef
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.
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Thu Jun 05, 2014 4:27 am
by Petruza
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.
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Thu Jun 05, 2014 5:09 am
by BigDumbDinosaur
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.
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Thu Jun 05, 2014 6:22 am
by Dr Jefyll
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
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Thu Jun 05, 2014 9:41 am
by BigEd
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: Select all
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
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Fri Jun 06, 2014 12:43 am
by Petruza
(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.
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Fri Jun 06, 2014 5:40 am
by BigEd
(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
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Sat Jun 07, 2014 8:40 pm
by Petruza
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.
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Sat Jun 07, 2014 11:56 pm
by nyef
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.
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Sun Jun 08, 2014 5:39 am
by BigEd
... 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
Re: I need a 6502 emulator that outputs its runtime disassem
Posted: Mon Jun 09, 2014 7:51 pm
by Petruza
... 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