who knows a full test code for 6502?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
amin2312
Posts: 4
Joined: 30 Jul 2009

who knows a full test code for 6502?

Post by amin2312 »

i had written a emulator for 6502,but i can't know it is right,so who can give me a full test code to test every instruction for it?thank u very much.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Post by BigEd »

If you can use (or convert) python, you might get some mileage out of the testsuite in Mike's py65 emulator. A typical test looks like this [I've cut a few lines]

Code: Select all

  def test_adc_bcd_off_absolute_carry_clear_in_accumulator_zeroes(self):
    mpu.a = 0
    self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000
    mpu.memory[0xC000] = 0x00
    mpu.step()
    self.assertEquals(0x0003, mpu.pc)
    self.assertEquals(0x00, mpu.a)
    self.assertEquals(0, mpu.flags & mpu.CARRY)
    self.assertEquals(0, mpu.flags & mpu.NEGATIVE)
    self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO)
At the end of this 2006 thread "stable, tested 6502 core" (also found here) MikeJ says
Quote:
Quote:
It might be a fun project to run two cores in lock step running the same program and see how far they get before they get a different result.
I maintain the cores on fpgaarcade. That trick is how I found most of the problems in the T80 core, and is the reason it is more accurate than the T65 core which I have never got around to doing the same thing
after a discussion that indicates there is no good verification suite to be found. (Emulators are usually tested by running game code.)
User avatar
Mike Naberezny
Site Admin
Posts: 295
Joined: 30 Aug 2002
Location: Northern California
Contact:

Post by Mike Naberezny »

BigEd wrote:
If you can use (or convert) python, you might get some mileage out of the testsuite in Mike's py65 emulator.
Having good test coverage is one of the goals of the Py65 simulator. I wrote the majority of the tests before attempting to run any non-trivial 6502 code. After the tests were all passing, Py65 was able to run Lee's EhBASIC without any issues.

That's not to say that Py65 or its tests are perfect; it's still early and I am sure this is far from the case. However, I do feel that having a good test harness is important for reaching good compatibility and minimizing bugs or regressions.

I started working on Py65 mainly because I am interested in a replacement for Michal Kowalski's 6502 Macroassembler and Simulator. While I think this is an excellent program, it only works on Windows and is not extensible without modifying its C++ source. I am gradually building up the components in Py65 so that a similar type of program can be written on top of it without these limitations.

Regards,
Mike
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Post by BigEd »

Quote:
I wrote the majority of the tests before attempting to run any non-trivial 6502 code
Excellent!

I had an idea that one could write code - perhaps automatically, derived from the py65 testsuite - which was self-checking, hitting a BRK if it found a flag or a value in a different state from that expected.

I see now that Rob Finch has already written such a self-checking program! His bc6502 includes test6502.a65 which starts by checking branch and compare and then going on to more interesting instructions. He's got 40+ tests in 1000 lines of assembly.

(The license may be problematic: revocable, only for education and evaluation, only distributable unmodified and in full. So no snippets from me.)

(Oddly though, py65 fails several of the tests. At least one looks like a real bug - filed!)
Post Reply