6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 10, 2024 8:31 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: PEI explanation
PostPosted: Thu Aug 15, 2024 10:24 am 
Offline

Joined: Tue Feb 07, 2023 12:27 pm
Posts: 46
I use this help when programming a 65816 simulator.
http://www.6502.org/tutorials/65c816opcodes.html
It is very helpful, but I have a problem understanding how the PEI instruction works.
Attachment:
File comment: ?
65816.jpg
65816.jpg [ 66.55 KiB | Viewed 615 times ]

The thing is that there is no clear explanation of where the HIGH byte is taken from in the case of e=1 D=$FF00 for PEI $FF?
If the low byte comes from $FFFF, then the high byte comes from $0000 or maybe $10000?

Also, the author has obscured the issue with the "!" character. Besides, if the LOW byte is $00, adding an 8-bit value will never change the HIGH byte, which is logical.

Then why include it in the description at all?

And for example, if e=1 D=$0100 PEI $FF, Low byte is taken from $01FF and where will the High Byte be taken from?
$0200 or $0100 ?


Top
 Profile  
Reply with quote  
 Post subject: Re: PEI explanation
PostPosted: Thu Aug 15, 2024 11:06 am 
Offline
User avatar

Joined: Mon Aug 30, 2021 11:52 am
Posts: 287
Location: South Africa
The first post in A (WDC) 65816 calling convention might be helpful. The WDC datasheet doesn't have any notes about e=1 so don't know why the above author has specified it with !

I must still finish the second post but there's an off by one error in my stack pictures and I've lost the context to fix it.


Top
 Profile  
Reply with quote  
 Post subject: Re: PEI explanation
PostPosted: Thu Aug 15, 2024 11:20 am 
Offline
User avatar

Joined: Mon Aug 30, 2021 11:52 am
Posts: 287
Location: South Africa
Actually the WDC datasheet does specify:
Attachment:
Direct Addressing.png
Direct Addressing.png [ 108.36 KiB | Viewed 607 times ]
but - and I could be misreading - it just seems like a complicated way of saying the '816 in emulation mode executing PEI will behave the same as the '816 in native mode.


Top
 Profile  
Reply with quote  
 Post subject: Re: PEI explanation
PostPosted: Thu Aug 15, 2024 11:43 am 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Bruce's document has a Notation section which explains the ! in the diagrams: it indicates that what happens to the right cannot affect what happens on the left.

So, PEI is a bank-wrapping instruction. (For old instructions in emulation mode and a page-aligned direct page, the direct mode is page-wrapping.)


Top
 Profile  
Reply with quote  
 Post subject: Re: PEI explanation
PostPosted: Thu Aug 15, 2024 12:00 pm 
Offline
User avatar

Joined: Mon Aug 30, 2021 11:52 am
Posts: 287
Location: South Africa
BigEd wrote:
So, PEI is a bank-wrapping instruction. (For old instructions in emulation mode and a page-aligned direct page, the direct mode is page-wrapping.)
Right! I was misreading Bruce's doc. Old instructions are page wrapping but the page wrapping ! does not apply to new instructions so the 'Otherwise' block always applies to the new instruction PEI.


Top
 Profile  
Reply with quote  
 Post subject: Re: PEI explanation
PostPosted: Thu Aug 15, 2024 1:36 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
Not to muddy the water, but there's another side effect with PEI worth noting:

In emulation mode, if the stack pointer is $0100, then PEI will push the high value to $0100 and the low value to $00FF, not $01FF. The stack pointer will reflect $01FE after the instruction is executed.

Bruce's tutorial mentions this for the PEA opcode but it also is true for PEI. This was confirmed when I validated the 65816 Test Suite.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
 Post subject: Re: PEI explanation
PostPosted: Thu Aug 15, 2024 2:37 pm 
Offline
User avatar

Joined: Mon Aug 30, 2021 11:52 am
Posts: 287
Location: South Africa
8BIT wrote:
In emulation mode, if the stack pointer is $0100, then PEI will push the high value to $0100 and the low value to $00FF, not $01FF. The stack pointer will reflect $01FE after the instruction is executed.

Bruce's tutorial mentions this for the PEA opcode but it also is true for PEI
Thanks for pointing that out, turns out that's a bug in my simulator.


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

All times are UTC


Who is online

Users browsing this forum: BigEd 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: