6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 6:04 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun May 01, 2016 8:45 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
I'm not certain if I found an anomaly or if I'm doing something wrong. In some recent testing, I've noticed that the BRK bit is being set in the processor status register on a PLP, but the byte it pulls is a $00. Code is simple enough, I invoke code via a CNTRL key (to limit any other code interfering) to run a small routine. Note: CPU is W65C02S.

Code:
;Break test - invoked by CNTRL-Y
BRKTEST   ;Test theory on BRK flag being set on PHY/PLP with zero pushed on the stack
               LDY   $04FE   ;Load Y reg with value from RAM
               PHY   ;Push it to the stack
               PLP   ;Pull it to the Processor status reg
               PHP   ;Push it back to the stack
               PLX   ;Pull it to X reg
               STX   $04FF   ;Store it in memory for viewing
               RTS   ;Return to caller


Regardless of how I load $04FE, the result in $04FF always shows the BRK bit being set. I searched around and haven't found this documented anywhere. Also, I have a routine in my BIOS which handles a software break (send a null character to the board). This is handled correctly and the BRK bit is not set. Executing code which does execute a BRK instruction does set the BRK flag. The unused status bit (emulation bit for the 65C816) always shows as set when testing the processor status which is normal. I also have a full ISR that handles both HW interrupts and the BRK instruction and this works correctly. Has anyone else noticed this odd behavior?

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Sun May 01, 2016 9:27 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
This is a common question! Nothing is wrong. The confusion arises because there is no B bit in the status register, and that's not obvious and often not described correctly. See 6502 'B' flag & BRK opcode by Brad Taylor and for more details and references this page on the visual6502 wiki.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 01, 2016 3:40 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
See also the BRK section of the 6502 interrupts primer.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon May 02, 2016 9:39 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Thanks Ed, I hadn't seen that before... I did do some digging in my old (hardcopy) manuals but nothing around that was covered.

Garth, thanks... I should visit your site more often ;-)

I have concluded that my current C02 BIOS/Monitor is working as designed! At some point I should post the updated source code, but then again... I think most are beyond needing yet another BIOS and Monitor.

_________________
Regards, KM
https://github.com/floobydust


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

All times are UTC


Who is online

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