Page 1 of 3
6502 Klaus Test Program
Posted: Sun Nov 30, 2014 5:17 am
by BobLoblaw0101
I'm trying to test my emulator against the Klaus Test Program and would like to throw it into another emulator just so I can walk through it and see what to expect. Whats a good/easy 6502 emulator I can use that will work out of the box with the Klaus test program I assembled?
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 4:04 pm
by 8BIT
Give the Kowalski Simulator a try. It supports 6502 and 65C02.
http://exifpro.com/utils.html
Daryl
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 4:54 pm
by BobLoblaw0101
Okay great!
I ran the 6502 Kowalski simulator program you linked in and it's getting stuck in the same loop that my emulator is stuck in. This suggests that I'm not building the test code correctly.
I downloaded Klaus' program from:
https://github.com/Klaus2m5/6502_65C02_ ... l_test.a65
Then I assembled it with AS65 from
http://www.kingswood-consulting.co.uk/assemblers/ using the following options:
as65.exe -l -m -s2 -w -h0 6502_functional_test.a65
This produced an Intel HEX format file. I ran this against my emulator and Kowalski's 6502 simulator program (starting at address 0x400). We both infinitely loop in the "dex" code ("relative address target field with branch under test in the middle") which is one of the first tests.
Does anyone have an idea of what I'm doing wrong? Ideally, I'd like to get this code working in any emulator so I can start debugging my own. Thanks in advance.
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 5:06 pm
by Klaus2m5
Bob,
could you please post the listing as an attachment or link?
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 5:12 pm
by BigEd
Hi Bob
See results from a previous thread, such as
viewtopic.php?p=26265#p26265
which indicates that lib6502 passes everything except decimal tests, py65 passes. Those are the two emulators I run most often.
You might also like to try Michael Steil's perfect6502:
https://github.com/mist64/perfect6502
which is a port to C of the visual6502 netlist simulator.
Oh, and easy6502 also passes, apparently, according to my note at
viewtopic.php?p=24177#p24177
Cheers
Ed
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 5:29 pm
by BobLoblaw0101
Bob,
could you please post the listing as an attachment or link?
Thanks, I've attached the generated list file.
Both simulators get stuck in the dex loop between 0x429 and 0x4a7. I'm guessing it's user error, something I forgot to change on the asm file before I built it.
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 6:08 pm
by Klaus2m5
Strange, there is nothing wrong with the generated listing. I ran my own hex file in Kowalski and it traps the break at $982, well beyond the branch range test (DEX loop). Changing the simulator option "Finish running program" from BRK to 0xBB continues to loop on the trap at $36E5, a known compatibilty problem in Kowalski (The stacked status from a BRK has the unused bit = 0).
Maybe you could attach your hex file too please.
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 6:56 pm
by BobLoblaw0101
Strange, there is nothing wrong with the generated listing. I ran my own hex file in Kowalski and it traps the break at $982, well beyond the branch range test (DEX loop). Changing the simulator option "Finish running program" from BRK to 0xBB continues to loop on the trap at $36E5, a known compatibilty problem in Kowalski (The stacked status from a BRK has the unused bit = 0).
Maybe you could attach your hex file too please.
Okay, that's really weird. I thought maybe there was something that needed to get changed in the asm file before I assembled. I've attached the hex file thats being generated, although I expect it to be the same as what you have.
To reproduce the issue:
Open Kowalski 6502 simulator. Click File->Load Code. Then select the attached hex file. Once opened click Simulator->Step Into, and continue stepping until stuck in the infinite loop.
Does it loop when you do that? Or did I miss additional steps in between? Thanks.
Re: 6502 Klaus Test Program
Posted: Sun Nov 30, 2014 9:14 pm
by Klaus2m5
To reproduce the issue:
Open Kowalski 6502 simulator. Click File->Load Code. Then select the attached hex file. Once opened click Simulator->Step Into, and continue stepping until stuck in the infinite loop.
Does it loop when you do that? Or did I miss additional steps in between? Thanks.

O.K., I understand the issue now!
The branch range test runs for a very long time (in excess of 70000 clocks). So running it in step mode doesn't do you any good. It repeats the loop 254 times from 254 DEX to none. You should run that test at speed and check the PC from time to time. If the PC is stuck, then checking the listing about where it is stuck (branch to self) should give you an idea of what went wrong.
Your hex file runs as expected in Kowalski up to $36E5 (simulator click run, after a few seconds click break). It would run to completion in the Kowalski simulator if you would set ROM_vectors = 0 (BRK cannot be tested without the IRQ vector) before assembly.
Re: 6502 Klaus Test Program
Posted: Mon Dec 01, 2014 3:11 am
by BobLoblaw0101
To reproduce the issue:
Open Kowalski 6502 simulator. Click File->Load Code. Then select the attached hex file. Once opened click Simulator->Step Into, and continue stepping until stuck in the infinite loop.
Does it loop when you do that? Or did I miss additional steps in between? Thanks.

O.K., I understand the issue now!
The branch range test runs for a very long time (in excess of 70000 clocks). So running it in step mode doesn't do you any good. It repeats the loop 254 times from 254 DEX to none. You should run that test at speed and check the PC from time to time. If the PC is stuck, then checking the listing about where it is stuck (branch to self) should give you an idea of what went wrong.
Your hex file runs as expected in Kowalski up to $36E5 (simulator click run, after a few seconds click break). It would run to completion in the Kowalski simulator if you would set ROM_vectors = 0 (BRK cannot be tested without the IRQ vector) before assembly.
That was it! What threw me off was that I was running Kowalski's emulator in "animate mode" which was stepping through the code fast, but not fast enough, so it made it look like I was in an infinite loop. My emulator did have a bug which was actually producing an infinite loop in that same spot.
Thanks for the help and your test program, it's very comprehensive!
Re: 6502 Klaus Test Program
Posted: Sun Dec 07, 2014 9:55 pm
by BobLoblaw0101
I'm trying to emulate a system that doesn't have support for BCD mode.
Looking at Klaus' "6502_functional_test.a65" file, does anyone know the point at which everything has been tested EXCEPT for BCD? I'm trying to figure out a place to put a breakpoint in my debugger so I don't creep into the BCD testing code. Thanks.
Re: 6502 Klaus Test Program
Posted: Sun Dec 07, 2014 10:32 pm
by MichaelM
The BCD ADC/SBC tests are numbered $2A. Look for where Klaus writes the test number to location $0200. In my listing of Klaus' functional tests, the BCD tests start around address $397B. These tests start with a bold header and an SED instruction. If you are searching a binary, look for the following hexadecimal sequence: A92A8D0002F8.
Re: 6502 Klaus Test Program
Posted: Mon Dec 08, 2014 9:48 am
by Klaus2m5
Thanks Michael. In the assembler source you can search for:
Re: 6502 Klaus Test Program
Posted: Thu Dec 11, 2014 4:41 pm
by BobLoblaw0101
Code: Select all
12979 ; decimal add/subtract test
12980 ; *** WARNING - tests documented behavior only! ***
12981 ; only valid BCD operands are tested, N V Z flags are ignored
12982 ; iterates through all valid combinations of operands and carry input
12983 ; uses increments/decrements to predict result & carry flag
12984 32f4 : f8 sed
12985 32f5 : a20e ldx #ad2 ;for indexed test
12986 32f7 : a0ff ldy #$ff ;max range
12987 32f9 : a999 lda #$99 ;start with adding 99 to 99 with carry
12988 32fb : 850d sta ad1 ;operand 1 - accumulator
12989 32fd : 850e sta ad2 ;operand 2 - memory or immediate
12990 32ff : 8d0302 sta ada2 ;non zp
12991 3302 : 850f sta adrl ;expected result bits 0-7
12992 3304 : a901 lda #1 ;set carry in & out
12993 3306 : 850c sta adfc ;carry in - for diag
12994 3308 : 8510 sta adrh ;expected result bit 8 (carry out)
12995 330a : a900 lda #0 ;complemented operand 2 for subtract
I'm able to get to $32f4 as seen above. Does this mean that I passed Klaus' test? I'm writing an NES emulator for now, so I'd like to test everything but BCD.
Re: 6502 Klaus Test Program
Posted: Thu Dec 11, 2014 4:50 pm
by Klaus2m5
Yep, everything except BCD has been tested at this point.