6502 Klaus Test Program Question

Topics pertaining to the emulation or simulation of the 65xx microprocessors and their peripheral chips.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: 6502 Klaus Test Program Question

Post by BigEd »

Cheers - fixed the link.
aaronmell
Posts: 13
Joined: 28 Mar 2013

Re: 6502 Klaus Test Program Question

Post by aaronmell »

I hope resurrecting an old thread isn't too frowned upon, I just figured it would be be better to continue here where I left off then to start a new one. Got busy with life, but now I want to finally finish the project I started earlier this year.

My simulator is making it to the first test, where it fails. I am running
load_data_direct = 0

This is the listing of the test that is failing

Code: Select all

                        ;testing relative addressing with BEQ
0435 : a0fe                     ldy #$fe        ;testing maximum range, not -1/-2 (invalid/self adr)
0437 :                  range_loop
0437 : 88                       dey             ;next relative address
0438 : 98                       tya
0439 : aa                       tax             ;precharge count to end of loop
043a : 1003                     bpl range_fw    ;calculate relative address
043c : 18                       clc             ;avoid branch self or to relative address of branch
043d : 6902                     adc #2
043f :                  range_fw
043f : 497f                     eor #$7f        ;complement except sign
0441 : 8dc804                   sta range_adr   ;load into test target
0444 : a900                     lda #0          ;should set zero flag in status register
0446 : 4cc704                   jmp range_op
0449 : ca                       dex             ;-128 - max backward
044a : ca                       dex
044b : ca                       dex
044c : ca                       dex
044d : ca                       dex
044e : ca                       dex
044f : ca                       dex
0450 : ca                       dex
0451 : ca                       dex             ;-120
0452 : ca                       dex
0453 : ca                       dex
0454 : ca                       dex
0455 : ca                       dex
0456 : ca                       dex
0457 : ca                       dex
0458 : ca                       dex
0459 : ca                       dex
045a : ca                       dex
045b : ca                       dex             ;-110
045c : ca                       dex
045d : ca                       dex
045e : ca                       dex
045f : ca                       dex
0460 : ca                       dex
0461 : ca                       dex
0462 : ca                       dex
0463 : ca                       dex
0464 : ca                       dex
0465 : ca                       dex             ;-100
0466 : ca                       dex
0467 : ca                       dex
0468 : ca                       dex
0469 : ca                       dex
046a : ca                       dex
046b : ca                       dex
046c : ca                       dex
046d : ca                       dex
046e : ca                       dex
046f : ca                       dex             ;-90
0470 : ca                       dex
0471 : ca                       dex
0472 : ca                       dex
0473 : ca                       dex
0474 : ca                       dex
0475 : ca                       dex
0476 : ca                       dex
0477 : ca                       dex
0478 : ca                       dex
0479 : ca                       dex             ;-80
047a : ca                       dex
047b : ca                       dex
047c : ca                       dex
047d : ca                       dex
047e : ca                       dex
047f : ca                       dex
0480 : ca                       dex
0481 : ca                       dex
0482 : ca                       dex
0483 : ca                       dex             ;-70
0484 : ca                       dex
0485 : ca                       dex
0486 : ca                       dex
0487 : ca                       dex
0488 : ca                       dex
0489 : ca                       dex
048a : ca                       dex
048b : ca                       dex
048c : ca                       dex
048d : ca                       dex             ;-60
048e : ca                       dex
048f : ca                       dex
0490 : ca                       dex
0491 : ca                       dex
0492 : ca                       dex
0493 : ca                       dex
0494 : ca                       dex
0495 : ca                       dex
0496 : ca                       dex
0497 : ca                       dex             ;-50
0498 : ca                       dex
0499 : ca                       dex
049a : ca                       dex
049b : ca                       dex
049c : ca                       dex
049d : ca                       dex
049e : ca                       dex
049f : ca                       dex
04a0 : ca                       dex
04a1 : ca                       dex             ;-40
04a2 : ca                       dex
04a3 : ca                       dex
04a4 : ca                       dex
04a5 : ca                       dex
04a6 : ca                       dex
04a7 : ca                       dex
04a8 : ca                       dex
04a9 : ca                       dex
04aa : ca                       dex
04ab : ca                       dex             ;-30
04ac : ca                       dex
04ad : ca                       dex
04ae : ca                       dex
04af : ca                       dex
04b0 : ca                       dex
04b1 : ca                       dex
04b2 : ca                       dex
04b3 : ca                       dex
04b4 : ca                       dex
04b5 : ca                       dex             ;-20
04b6 : ca                       dex
04b7 : ca                       dex
04b8 : ca                       dex
04b9 : ca                       dex
04ba : ca                       dex
04bb : ca                       dex
04bc : ca                       dex
04bd : ca                       dex
04be : ca                       dex
04bf : ca                       dex             ;-10
04c0 : ca                       dex
04c1 : ca                       dex
04c2 : ca                       dex
04c3 : ca                       dex
04c4 : ca                       dex
04c5 : ca                       dex
04c6 : ca                       dex             ;-3
04c7 :                  range_op                ;test target with zero flag=0, z=1 if previous dex
04c8 =                  range_adr   = *+1       ;modifiable relative address
04c7 : f03e                     beq *+64        ;if called without modification
04c9 : ca                       dex             ;+0
04ca : ca                       dex
04cb : ca                       dex
04cc : ca                       dex
04cd : ca                       dex
04ce : ca                       dex
04cf : ca                       dex
04d0 : ca                       dex
04d1 : ca                       dex
04d2 : ca                       dex
04d3 : ca                       dex             ;+10
04d4 : ca                       dex
04d5 : ca                       dex
04d6 : ca                       dex
04d7 : ca                       dex
04d8 : ca                       dex
04d9 : ca                       dex
04da : ca                       dex
04db : ca                       dex
04dc : ca                       dex
04dd : ca                       dex             ;+20
04de : ca                       dex
04df : ca                       dex
04e0 : ca                       dex
04e1 : ca                       dex
04e2 : ca                       dex
04e3 : ca                       dex
04e4 : ca                       dex
04e5 : ca                       dex
04e6 : ca                       dex
04e7 : ca                       dex             ;+30
04e8 : ca                       dex
04e9 : ca                       dex
04ea : ca                       dex
04eb : ca                       dex
04ec : ca                       dex
04ed : ca                       dex
04ee : ca                       dex
04ef : ca                       dex
04f0 : ca                       dex
04f1 : ca                       dex             ;+40
04f2 : ca                       dex
04f3 : ca                       dex
04f4 : ca                       dex
04f5 : ca                       dex
04f6 : ca                       dex
04f7 : ca                       dex
04f8 : ca                       dex
04f9 : ca                       dex
04fa : ca                       dex
04fb : ca                       dex             ;+50
04fc : ca                       dex
04fd : ca                       dex
04fe : ca                       dex
04ff : ca                       dex
0500 : ca                       dex
0501 : ca                       dex
0502 : ca                       dex
0503 : ca                       dex
0504 : ca                       dex
0505 : ca                       dex             ;+60
0506 : ca                       dex
0507 : ca                       dex
0508 : ca                       dex
0509 : ca                       dex
050a : ca                       dex
050b : ca                       dex
050c : ca                       dex
050d : ca                       dex
050e : ca                       dex
050f : ca                       dex             ;+70
0510 : ca                       dex
0511 : ca                       dex
0512 : ca                       dex
0513 : ca                       dex
0514 : ca                       dex
0515 : ca                       dex
0516 : ca                       dex
0517 : ca                       dex
0518 : ca                       dex
0519 : ca                       dex             ;+80
051a : ca                       dex
051b : ca                       dex
051c : ca                       dex
051d : ca                       dex
051e : ca                       dex
051f : ca                       dex
0520 : ca                       dex
0521 : ca                       dex
0522 : ca                       dex
0523 : ca                       dex             ;+90
0524 : ca                       dex
0525 : ca                       dex
0526 : ca                       dex
0527 : ca                       dex
0528 : ca                       dex
0529 : ca                       dex
052a : ca                       dex
052b : ca                       dex
052c : ca                       dex
052d : ca                       dex             ;+100
052e : ca                       dex
052f : ca                       dex
0530 : ca                       dex
0531 : ca                       dex
0532 : ca                       dex
0533 : ca                       dex
0534 : ca                       dex
0535 : ca                       dex
0536 : ca                       dex
0537 : ca                       dex             ;+110
0538 : ca                       dex
0539 : ca                       dex
053a : ca                       dex
053b : ca                       dex
053c : ca                       dex
053d : ca                       dex
053e : ca                       dex
053f : ca                       dex
0540 : ca                       dex
0541 : ca                       dex             ;+120
0542 : ca                       dex
0543 : ca                       dex
0544 : ca                       dex
0545 : ca                       dex
0546 : ca                       dex
0547 : ca                       dex
0548 : f003                     beq range_ok    ;+127 - max forward
                                trap            ; bad range
054a : 4c4a05          >        jmp *           ;failed anyway
                        
054d :                  range_ok
054d : c000                     cpy #0
054f : f003                     beq range_end   
0551 : 4c3704                   jmp range_loop
0554 :                  range_end               ;range test successful
This is my simulator's executed steps

Code: Select all

LDY #$00FE     O: 160  L: FE H: 88 PC: 1035 A: 001 X: 255 Y: 000 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 1 
DEY            O: 136  L:  H:  PC: 1037 A: 001 X: 255 Y: 254 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 1 
TYA            O: 152  L:  H:  PC: 1038 A: 001 X: 255 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 1 
TAX            O: 170  L:  H:  PC: 1039 A: 253 X: 255 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 1 
BPL $103A      O: 16  L: 03 H:  PC: 103A A: 253 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 1 
CLC            O: 24  L:  H:  PC: 103C A: 253 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 1 
ADC #$0002     O: 105  L: 02 H: 49 PC: 103D A: 253 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
EOR #$007F     O: 73  L: 7F H: 8D PC: 103F A: 255 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
STA $04C8      O: 141  L: C8 H: 04 PC: 1041 A: 128 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
LDA #$0000     O: 169  L: 00 H: 4C PC: 1044 A: 128 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
JMP $04C7      O: 76  L: C7 H: 04 PC: 1046 A: 000 X: 253 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0 
BRK            O: 0  L:  H:  PC: 4C7  A: 000 X: 253 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0
The instruction at 04C7 is empty, which puts me into an invalid state.
I've walked the code in the test a few times manually, and everything looks correct to my untrained eye.
Last edited by aaronmell on Sun Oct 27, 2013 11:27 pm, edited 1 time in total.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: 6502 Klaus Test Program Question

Post by GARTHWILSON »

Quote:
I hope resurrecting an old thread isn't too frowned upon
Never.
Quote:
I just figured it would be be better to continue here where I left off then to start a new one.
Absolutely. If you were to start a new one, then we would have to find the old one to figure out where we were on this thing. Keep it together. I don't understand forums that don't want anything old continued. They just make it harder to make progress and build knowledge on knowledge. Projects here sometimes take years, and it doesn't make sense to chop one up into unconnected segments.

To keep the white space in your code, put [code] and [/code] around it, and make sure your "Disable BBCoce" box is not checked. If you're logged in, you can click "edit" at the bottom of your post above to fix it.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
aaronmell
Posts: 13
Joined: 28 Mar 2013

Re: 6502 Klaus Test Program Question

Post by aaronmell »

It's amazing what a fresh look at a problem will do for you.

My issue turned out to be that I was loading my program into the wrong place, and starting the program from the wrong place.

I was loading it into memory starting at 1000 and starting execution at 1000. I changed this to loading and running from 400 and that seemed to fix the previous issue at least, Of course it didn't take long for a new issue to come up. My code looks correct, it matches the listing. But the BEQ instruction seems to fall one short here.

Code: Select all

0541 : ca                       dex             ;+120
0542 : ca                       dex
0543 : ca                       dex
0544 : ca                       dex
0545 : ca                       dex
0546 : ca                       dex
0547 : ca                       dex
0548 : f003                     beq range_ok    ;+127 - max forward
                                trap            ; bad range
054a : 4c4a05          >        jmp *           ;failed anyway
                        
054d :                  range_ok
054d : c000                     cpy #0
054f : f003                     beq range_end   
0551 : 4c3704                   jmp range_loop
0554 :                  range_end               ;range test successful

Code: Select all

BEQ $0548      O: 240  L: 03 H:  PC: 548  A: 000 X: 000 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0 
0547 : CA DEX            A: 000 X: 001 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
0548 : F003 BEQ $0548      A: 000 X: 000 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0 
054C : 05C0 ORA $C0        A: 000 X: 000 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0 
So it jumps to 054C instead of 054D. my output matches the compiler output.
Attachments
BEQ Test.txt
Entire output from BEQ Test
(23.58 KiB) Downloaded 139 times
Klaus2m5
Posts: 442
Joined: 28 Jul 2012
Location: Wiesbaden, Germany

Re: 6502 Klaus Test Program Question

Post by Klaus2m5 »

Your conclusion is correct.
Quote:
So it jumps to 054C instead of 054D.
So you need to fix relative addressing of your emulator (again).

The backward branch @ $04C7 worked correctly.

Code: Select all

...
0441 : 8DC804 STA $04C8      A: 128 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0
                  ^----         ^-- self modify BEQ under test / backward max (-128)  
0444 : A900 LDA #$0000     A: 128 X: 253 Y: 253 SP 255 N: 1 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
                                     ^--    ^-- number of dex to be executed
                              ^-- max 128 backward
0446 : 4CC704 JMP $04C7      A: 000 X: 253 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0
                                                                     previous lda #0 -
04C7 : F080 BEQ $04C7      A: 000 X: 253 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0 
                ^---- was replaced by self modifying code to $0449 (-128)
0449 : CA DEX            A: 000 X: 253 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0
...        a lot of DEX until 
04C7 : F080 BEQ $04C7      A: 000 X: 127 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
                                     this time the branch is not taken because Z=0 ^
04C9 : CA DEX            A: 000 X: 127 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0 
...        more DEX to be executed
0547 : CA DEX            A: 000 X: 001 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 0 C: 0
                                   ^-- last DEX, so the expected number of DEX was counted
0548 : F003 BEQ $0548      A: 000 X: 000 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0 
                                     ^--   last DEX set Z=1, branch will be taken  ^
                ^---- should read $054D (+3)                                     
054C : 05C0 ORA $C0        A: 000 X: 000 Y: 253 SP 255 N: 0 V: 0 B: 0 D: 0 I: 1 Z: 1 C: 0 
^--- but ends at $054C (+2)
...
So it is not the BEQ -128 under test that fails, but it is the BEQ +3 that is part of the test harness that fails.

This is why there is a warning in the header of the test:

Code: Select all

; Please note that in early tests some instructions will have to be used before
; they are actually tested!
6502 sources on GitHub: https://github.com/Klaus2m5
aaronmell
Posts: 13
Joined: 28 Mar 2013

Re: 6502 Klaus Test Program Question

Post by aaronmell »

Klaus2m5 wrote:
Your conclusion is correct.
Quote:
So it jumps to 054C instead of 054D.
So you need to fix relative addressing of your emulator (again).
Not sure why I would only be off by one on forward jumps, it may be where I am starting my count from. That got me to the end of the that particular test.

Need to make some additional improvements to my simulator, Need to add the ability to load and save state, so I can start at the point where things go bad, and not have to run through the entire test to get back to the point where I fail. Been putting off adding breakpoints to my simulator, but it looks like I need to do that as well.
aaronmell
Posts: 13
Joined: 28 Mar 2013

Re: 6502 Klaus Test Program Question

Post by aaronmell »

My simulator finally passed all of the functional tests!

I just need to get the interrupt tests working now
Nonax
Posts: 2
Joined: 26 Mar 2014

Re: 6502 Klaus Test Program Question

Post by Nonax »

Hi all!

So I'm working on yet another 6510 emulation and am using the incredible test programs from Klaus. Now I'm stuck on a problem and hope someone can help me.

What I've done is compile the 6502_functional_test with the settings as described in the test itself. Only difference I made was to generate a binary file instead of an Intel hex-dump:

Code: Select all

AS65.EXE -l -m -w -h0 6502_functional_test.a65
I made no changes to the settings in the a65 script itself. The bin file is then loaded into the memory of the emulator starting at $0A. Then I start emulating from $0400. It runs fine until the 'break test' on $0982.

The BRK instruction reads the address stored in $FFFE - which is $00CB - and stores it in the PC. But there is no valid code on that location. I assumed that $FFFE would be the IRQ vector (which is true for the C64), is this correct or is it on another address?
Or is the binary file created the wrong way or corrupt?
Or did I implement the BRK instruction the wrong way?
Or should I implement a interrupt handler? If so, would an RTS do the job?

Any help would be great!
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: 6502 Klaus Test Program Question

Post by BigEd »

according to the listing, the vector at FFFE should contain cb36, which means control passes to 36cb, where we find the routine "irq_trap"

https://github.com/Klaus2m5/6502_65C02_ ... lst#L13990

https://github.com/Klaus2m5/6502_65C02_ ... lst#L13828

(This assumes you assembled with ROM_vectors = 1)

Hope this helps
Ed
Nonax
Posts: 2
Joined: 26 Mar 2014

Re: 6502 Klaus Test Program Question

Post by Nonax »

Thanks for the quick answer Ed!
Turns out I loaded the bin file one byte short :(
It now runs like a charm, thanks again.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: 6502 Klaus Test Program Question

Post by BigEd »

Great!
JimDrew
Posts: 107
Joined: 14 Oct 2012

Re: 6502 Klaus Test Program Question

Post by JimDrew »

I finally got around to looking at Klaus' test programs. Is there a way to convert this so that it is ROM based instead of requiring ~16K of RAM? My emulation only has 2K of RAM available, but up to 32K of ROM space. There is apparently self-modifying code in the test, which won't work ROM based. Any suggestions?
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: 6502 Klaus Test Program Question

Post by barrym95838 »

JimDrew wrote:
... Any suggestions?
Could you temporarily modify your emulator for more RAM, or just replace some of your ROM with RAM, just for Klaus' test?

Mike
Klaus2m5
Posts: 442
Joined: 28 Jul 2012
Location: Wiesbaden, Germany

Re: 6502 Klaus Test Program Question

Post by Klaus2m5 »

Self modifying code is used in two areas. Whenever an immediate instruction is to be tested in a loop with different operands and in the branch range test. The RAM integrity check resets all self modified addresses. You can do a find "self" in the code as I have commented almost every self modifying portion of the code. The only other place is at ";testing relative addressing with BEQ". The self modified labels are:

Code: Select all

range_adr
tandi1
tandi2
teori1
teori2
torai1
torai2
chkdadi
chkdsbi
chkadi
chksbi
RAM integrity can be left disabled, so you don't have to worry about that. You can chop all portions of the code using self modifying tests leaving these instructions untested in immediate mode and to not test for correct branch range. This will eliminate the tests for logical and arithmetic immediate instructions. All immediate loads and compares will still be tested if I remember correctly. They are not tested in a loop.

In a second step you could try and squeeze the chopped test portions into a smaller image to be executed from RAM separately.
6502 sources on GitHub: https://github.com/Klaus2m5
JimDrew
Posts: 107
Joined: 14 Oct 2012

Re: 6502 Klaus Test Program Question

Post by JimDrew »

Thanks, Klaus. I would like to be able to test everything.

Barry - I have a state machine that handles the memory map for opcodes that deal with memory, so I guess the best way would be to make a new state machine just for running the instruction test suite. More work, but that would allow me to test everything.
Post Reply