6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Sep 25, 2024 4:19 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Oct 12, 2010 6:08 am 
Offline
User avatar

Joined: Fri Dec 12, 2003 7:22 am
Posts: 259
Location: Heerlen, NL
Hallo allemaal,


Please have a look at this code:
Code:
      lda   #0
      pha      
      plp
      php
      pla

What value should A contain? I expected $20 but it appears to be $30. Running the ML in VICE shows that A contains $30 but the P register $20. Not sure if the monitor is too blame, I created this ML:
Code:
      lda   #1
      sta   $0400
      sta   $0401
      sta   $0402

      sei

      lda   #0
      pha      
      plp
      php
      pla
      sta   $0401

      cli
      rts

Running the ML the second 'A' turns into a Zero, confirming A contains $30.

The big question: WHY ???

Many thanks for an explanation!

_________________
Code:
    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       URL: www.baltissen.org



Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 12, 2010 6:43 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8517
Location: Southern California
The PHP always pushes a '1' BRK bit (bit 4, value $10). The only way to see if and ISR was entered by a BRK instruction is to pull the stacked record of P that was put there by the interrupt itself. This was covered in this topic.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 12, 2010 11:01 am 
Offline
User avatar

Joined: Fri Dec 12, 2003 7:22 am
Posts: 259
Location: Heerlen, NL
GARTHWILSON wrote:
The PHP always pushes a '1' BRK bit (bit 4, value $10). The only way to see if and ISR was entered by a BRK instruction is to pull the stacked record of P that was put there by the interrupt itself. This was covered in this topic.

Thank you!

_________________
Code:
    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       URL: www.baltissen.org



Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 12, 2010 5:44 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Just for the record: you have to pull the saved P into A using PLA (or load it into a register by other means) - you can't use PLP because P as a register only has 6 useful bits. (The value saved by an interrupt has 7 useful bits, but the transistors just aren't there in the P register itself.)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 13, 2010 5:02 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8395
Location: Midwestern USA
Also note that the W65C816S has a different behavior when operation in native mode. In this case, the value pushed to the stack by PHP and subsequently retrieved by PLA (PLX, or PLY) does not change. Hence:
Code:
SEP #%00110000
LDA #0
PHA
PLP
PHP
PLA

returns $00 in .A.

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 30, 2010 9:11 am 
Offline

Joined: Wed Oct 27, 2010 1:28 pm
Posts: 25
Location: Valladolid (Spain)
I think a clear way to understand this is to realize that the B flag is not a flag at all but only the logical OR of the I flag and the /IRQ pin. The bit pulled from the stack into the P register is just discarded.
I was suspecting this, and after digging in the 6502 schematic from http://impulzus.sch.bme.hu/6502/letolt.php3, I found it is true. I also found that this signal can clear the Instruction Register: In fact, fetching a BRK op-code instead of the byte present on the data bus when an interrupt is accepted. This can also explain why the BRK instruction is ignored if an interrupt is accepted at the same time (a well known bug of the NMOS 6502)


GARTHWILSON wrote:
The PHP always pushes a '1' BRK bit (bit 4, value $10). The only way to see if and ISR was entered by a BRK instruction is to pull the stacked record of P that was put there by the interrupt itself. This was covered in this topic.
[/url]


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

All times are UTC


Who is online

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