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

All times are UTC




Post new topic Reply to topic  [ 49 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: Wed Sep 16, 2015 2:32 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Since I've been running into a bunch of nitpicking questions about the 65816 during my attempt to emulate the chip, I thought I might keep them in one thread for future intrepid coders instead of spreading them out all over the forum like I did with the TXS/SP question (viewtopic.php?f=4&t=3446). I'm assuming that the same problems will come up again.

Here's my latest one: Is there anything to prevent me from manipulating the Direct Register (D) in emulation mode, and what effect would that have? The Programming Manual just says that it gets set to 0 when we switch, but there doesn't seem to be anything that keeps me from doing a TCD in emulation mode, and the entry for Direct Page Addressing (p. 298) doesn't say anything about "65816/65802 only". I've checked BDD's 65C816 Programming Tips entry for DP (viewtopic.php?f=2&t=3198&p=36677e#p36677), but nothing there either, it all seems to be about native mode.

So if I switch to emulated mode, change D to, say, $1000, and then do some ZP access at $10, will the processor just ignore D or actually give me $1010?

Obviously, this would be a weird thing to do, but you never know.


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 16, 2015 4:25 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8504
Location: Midwestern USA
scotws wrote:
Here's my latest one: Is there anything to prevent me from manipulating the Direct Register (D) in emulation mode, and what effect would that have?

The general rule is that all instructions work in both modes, although the results may differ between the two modes. In emulation mode, a sequence such as:

Code:
         lda #$c8
         xba
         lda #$40
         tcd

will set DP to $C840. On the other hand:

Code:
         lda #$c8
         xba
         lda #$40
         tcs

will not set SP to $C840, as the MSB of the stack pointer is hard-wired to $01 in emulation mode. Instead, SP will be $0140.

As a reminder, direct page and stack accesses always occur in bank $00, and the JMP (<addr>) instruction is effectively JMP ($00<addr>).

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 16, 2015 4:36 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
So with XBA, TCD and TDC, emulation mode has access to a further two bytes of register?


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 16, 2015 5:13 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8504
Location: Midwestern USA
BigEd wrote:
So with XBA, TCD and TDC, emulation mode has access to a further two bytes of register?

Correct.

XBA is particularly useful in emulation mode, as you effectively have two accumulators at your disposal. It's just a matter of keeping track of which accumulator is holding what, and remembering that a PHA only pushes the A-accumulator.

Even in native mode, XBA is very useful. Consider, for example, a SCSI driver that is setting up a command descriptor block (CDB). Data transfer sizes in CDBs are written in big-endian format, but the 65C816 processes in little-endian. So if a data transfer size has been computed and is presently loaded in the 16-bit accumulator, it will be in little-endian format. Prior to writing the size value into the CDB, an XBA would reverse endianess.

Interesting aside: XBA counter-intuitively affects the N and Z flags in SR according to the value transferred into the A-accumulator, regardless of the current m bit setting in SR. Hence the following code would set N and clear Z:

Code:
         rep #%00100000        ;16 bit accumulator
         lda #$8000            ;.C = $8000
         xba                   ;.C = $0080
         brk

On the other hand:

Code:
         rep #%00100000        ;16 bit accumulator
         lda #$8000            ;.C = $8000
         and #$ff00            ;.C = $8000
         brk

would also set N and clear Z, as all arithmetic and Boolean operations on the 16 bit accumulator condition N according to the value of bit 15, not bit 7.

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 16, 2015 6:43 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
BigDumbDinosaur wrote:
In emulation mode, a sequence such as (...) will set DP to $C840.
So if I'm willing to force the issue by manipulating D in emulation mode, I can put the Direct Page anywhere in the first 64k in that mode as well? That of course simplifies the code for the direct page addressing mode, but sounds like an accident waiting to happen in emulation mode ... thanks!


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 16, 2015 10:20 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
BigDumbDinosaur wrote:
scotws wrote:
Is there anything to prevent me from manipulating the Direct Register (D) in emulation mode

The general rule is that all instructions work in both modes
The general rule is just that, so I'd be cautious about reading too much detail beween the lines. This is an esoteric question, and the answer is probably worth confirming.

Sometimes an actual experiment is required. (BDD? Garth? Anyone?) Thanks. I think Scot would prefer a definite answer if one is available. The question is,
Quote:
if I switch to emulated mode, change D to, say, $1000, and then do some ZP access at $10, will the processor just ignore D or actually give me $1010?

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 4:24 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8504
Location: Midwestern USA
scotws wrote:
So if I'm willing to force the issue by manipulating D in emulation mode, I can put the Direct Page anywhere in the first 64k in that mode as well?

That's what both the data sheet and the Lichty and Eyes programming manual say. I've not tried it.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 8:00 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
It's when you guys use words like "esoteric" and "experimental" that I start to wonder if I'm in over my head :D . Thanks - for the moment, I'll go with what we think happens and put a note in the TODO and MANUALs with the background until somebody can test this.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 8:09 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
It would be interesting to have a list of forum members who have a working '816 system to experiment with, and which of them is willing to help out.

I believe Bruce has a IIGS. I've had the beeb816 but nothing I can run with at present. BDD has the POC series.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 12:55 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
BigEd wrote:
It would be interesting to have a list of forum members who have a working '816 system to experiment with, and which of them is willing to help out.

I believe Bruce has a IIGS. I've had the beeb816 but nothing I can run with at present. BDD has the POC series.

I could try some tests on my SXB - Its one of the reasons I bought it as some of the instruction descriptions weren't clear enough for me to write the PIC24 emulation code for them.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 1:07 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
That'd be great, Andrew!

BigDumbDinosaur wrote:
That's what both the data sheet and the Lichty and Eyes programming manual say. I've not tried it.
To be clear, neither outcome will surprise me. I posted simply to point out that doc has limitations. As with test equipment, it's constantly necessary to question the reliability of the info you're collecting because the info gets more and more questionable as the limitations are approached.

Re: the answer to Scot's question, I haven't yet seen a reference that's specific rather than merely suggestive. To me that says we've reached the limit -- the doc simply doesn't answer the question satisfactorily.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 1:30 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
BigDumbDinosaur wrote:
scotws wrote:
So if I'm willing to force the issue by manipulating D in emulation mode, I can put the Direct Page anywhere in the first 64k in that mode as well?

That's what both the data sheet and the Lichty and Eyes programming manual say. I've not tried it.

My guess is that you can write to D in emulation mode, but the value won't affect any zero page addressing. Edit: did a little reading, and it seems my guess is wrong!


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 5:30 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8504
Location: Midwestern USA
BigEd wrote:
It would be interesting to have a list of forum members who have a working '816 system to experiment with, and which of them is willing to help out.

I believe Bruce has a IIGS. I've had the beeb816 but nothing I can run with at present. BDD has the POC series.

I'd have to burn a special ROM to make the POC unit boot into emulation mode or write some code to temporarily run it in emulation mode. One more thing on the bucket list. :lol:

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


Last edited by BigDumbDinosaur on Thu Sep 17, 2015 6:36 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 6:09 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
The designers of the '816 thoughtfully provided an XCE instruction to help you.
Code:
    org  $0300
    phd             ; save DPR
    rep  #$40       ; select 16-bit accumulator and memory
    lda  #$0000
    tcd             ; DPR = 0
    lda  #$abcd
    sta  $00        ; absolute location $0000: $cd, $0001: $ab
    lda  #$0001
    sec
    xce             ; switch to emulation mode
    tcd             ; DPR = 1 (?)
    lda  $00        ; grab a byte from mystery location
    sta  $1000      ; store it in $1000
    clc
    xce             ; switch to native mode
    pld             ; restore DPR
    rts             ; return to monitor

If I didn't make any coding errors, executing this small test will cause location $1000 to contain $cd if DPR is ignored in emulation mode, and $ab if it is not.

Mike B.

[Edit: Fixed obvious and heinous coding error.]


Last edited by barrym95838 on Thu Sep 17, 2015 6:28 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 6:24 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Quote:
Fixed obvious and heinous coding error.
Sorry I missed that, Mike! :D But I won't tease you for being too quick to hit the Submit button -- I'm often guilty of that myself. :oops: Thanks for posting.

_________________
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 Thu Sep 17, 2015 6:46 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 49 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC


Who is online

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