6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 7:38 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Nov 05, 2019 11:32 pm 
Offline

Joined: Tue Nov 05, 2019 11:11 pm
Posts: 2
Hi all, I'm trying to work out the bugs in a 6502 emulator I'm writing so I'm going through Dormann's testing suite and I'm stuck on this test. It zeroes out all the flags, goes through a bunch of tests to make sure that branch instructions work properly, and then checks the flags. For some reason, it's expecting the break and reserve flags to be set, but I can't see what would set them? Any help here would be greatly appreciated, I must be missing something.

Code:
                                set_stat 0      ;all off
                       >            load_flag 0     
0644 : a900            >            lda #0                   ;allow test to change I-flag (no mask)
                       >
0646 : 48              >            pha         ;use stack to load status
0647 : 28              >            plp

                                           //Skipped a bunch of branch tests here, only branch instructions, none of which affect flags

0670 : 08               br14    php
0671 : 68                       pla
                                cmp_flag 0      ;flags off except break (pushed by sw) + reserved?
0672 : c930            >            cmp #(0      |fao)&m8    ;expected flags + always on bits
                       
                                trap_ne
0674 : d0fe            >        bne *           ;failed not equal (non zero)


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 06, 2019 12:40 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Hello, Rhad, and welcome!

Until now I've never looked at any of the code in Klaus's suite, but based on this snippet there does seem to be a puzzle here.

Is it possible the following lines are confusing your assembler? (I know they're confusing me! :wink: ) Anyway, maybe the result is something other than what Klaus's assembler would give. For me that's the first thing that comes to mind -- an assembler issue (with the expression for the CMP instruction).
Code:
                                cmp_flag 0      ;flags off except break (pushed by sw) + reserved?
0672 : c930            >            cmp #(0      |fao)&m8    ;expected flags + always on bits

But the comment does say, ""except break (pushed by sw) + reserved"... followed by a question mark. Maybe someone will pipe up who can explain that.

Edit: I've gotten too distracted by "sw" and the odd expression, and have overlooked the actual issue :oops: -- which Chromatix identifies below.

cheers
Jeff

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


Last edited by Dr Jefyll on Wed Nov 06, 2019 2:14 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 06, 2019 1:28 am 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
In the 6502, only six of the bits in the status register actually exist in hardware - N, Z, C, V, I, and D (not in that order). The other two always read as set bits when pushed with PHP.

The B bit is purposefully manipulated when the status register is pushed on the stack by an interrupt, to indicate to the interrupt handler routine whether it was a hardware interrupt or the BRK instruction that triggered it. The "reserved" bit remains set even in this case.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 06, 2019 3:39 am 
Offline

Joined: Tue Nov 05, 2019 11:11 pm
Posts: 2
Wow. After poring back through the programming manual trying to find the documentation for this behavior I found out I somehow chose to start skimming at the very paragraph where they talk about this in the interrupt chapter. Thanks, probably never would've figured that out on my own.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 06, 2019 9:13 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
(Welcome, Rhad! Hope to hear more about your emulator in due course. The behaviour of B often trips up emulators. I think there are very few emulators indeed which pass Klaus' test suite first time they encounter it.)


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

All times are UTC


Who is online

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