6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 4:40 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Jun 15, 2014 2:18 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
I came across this yesterday, at http://nesdev.com/6502bugs.txt
*If an interrupt occurs on a BRK instruction, the breakpoint is ignored.

I'm using BRK as a one-byte JSR to get to 6502. The PET ROM also pushes all the machine registers to the stack for me, and there's a corresponding ROM routine at $E600 that restores things before RTI

It's allegedly fixed in the 65C02 and beyond, but I have never heard of it before in my life. Does this mean that every time the jiffy clock IRQ fires off in my PET, it's like a bullet zinging by my code, and if I happen to hit a BRK instruction exactly then, it will process the interrupt instead of the BRK, and then crash into my Sweet16 code pretending it's 6502? Should I be doing SEI BRK all over the place instead of just BRK?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 15, 2014 3:51 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
To my knowledge this is only true for an NMI interrupt. You can compensate by also checking the B flag in the NMI vector and if set process BRK after NMI was handled. I know, that contradicts that NMI handling should be as fast as possible.

For IRQ it is the other way round. The IRQ gets handled as BRK but since you haven't cleared the interrupt source IRQ fires again after RTI from the BRK handler. So the IRQ is only delayed.

more: http://visual6502.org/wiki/index.php?ti ... _and_B_bit

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 15, 2014 6:09 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8390
Location: Midwestern USA
chitselb wrote:
I came across this yesterday, at http://nesdev.com/6502bugs.txt
*If an interrupt occurs on a BRK instruction, the breakpoint is ignored.

I'm using BRK as a one-byte JSR to get to 6502. The PET ROM also pushes all the machine registers to the stack for me, and there's a corresponding ROM routine at $E600 that restores things before RTI

It's allegedly fixed in the 65C02 and beyond, but I have never heard of it before in my life. Does this mean that every time the jiffy clock IRQ fires off in my PET, it's like a bullet zinging by my code, and if I happen to hit a BRK instruction exactly then, it will process the interrupt instead of the BRK, and then crash into my Sweet16 code pretending it's 6502? Should I be doing SEI BRK all over the place instead of just BRK?

This problem is unique to the NMOS 6502. If any hardware interrupt hits during the execution of BRK, BRK will be forgotten and the hardware interrupt will take control—this applies to both /IRQ and /NMI. Page 30 of the 65C02 data sheet also notes this anomaly. Regarding the NMOS behavior:

    Interrupt vector is loaded; BRK vector is ignored.

In the 65C02, this behavior has been corrected. Again, from page 30 of the data sheet:

    BRK is executed, and then interrupt is executed.

The 65C02 behavior also applies to the 65C816 in either mode. Note that the 65C816's COP instruction is a software interrupt like BRK.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


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

All times are UTC


Who is online

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