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

All times are UTC




Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
PostPosted: Thu Sep 24, 2015 9:24 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Rob Finch wrote:
Because it's typically a couple of clock cycles between an IRQ event and when the status register needs to be saved on the stack. So this is state that has to be saved (in a FF) for a clock or two, before it gets written to memory.
Ideally, yes. Yet, as you say, they also could've directly muxed the IRQ line onto the databus in the break flag position. Regarding those options, it's possible the NMOS and CMOS 02's are in different camps. This bug-fix note from the 'c02 datasheet seems to imply that. But right now I haven't got my thinking cap on, and hesitate to say for certain. :) Anyway I'm guessing Emulation mode doesn't reproduce the bug.

Attachment:
'c02 BRK bug-fix1.gif
'c02 BRK bug-fix1.gif [ 9.54 KiB | Viewed 1557 times ]


Rob Finch wrote:
The long term state of the break flag still really exists only on the stack and not in the processor.
Yes, that was my main point. I may've been slightly sloppy in expressing it.

_________________
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 24, 2015 9:30 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
Rob Finch wrote:
Quote:
I'm inclined to think that the 816 also does not pull it from the stack since it's 100% 6502 compatible in emulation mode (it's the way I coded the FT816).

Actually, the 65C816's emulation mode is not 100 percent compatible with either the NMOS 6502 or the 65C02. The "caveats" section in the '816 data sheet (page 51) explains the differences.

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2015 6:57 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
So here's the next problem. The MVN and MVP instructions (p. 367/368) state that C (as I have come to think of it by now) is $FFFF after the instruction has terminated. It also says that the move instructions do not affect any flag. Shouldn't I end up with N being set, or is that test really skipped? Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2015 12:56 pm 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 460
Location: Canada
Quote:
Shouldn't I end up with N being set, or is that test really skipped? Thanks!

I believe no flags are set. It shows no flags being set on pg 36 of the datasheet, so I wouldn't count on them being set. It might be nice to have flags set based on the last byte/word moved. It likely has to do with keeping the processor pipelining simple.

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2015 6:08 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
scotws wrote:
So here's the next problem. The MVN and MVP instructions (p. 367/368) state that C (as I have come to think of it by now) is $FFFF after the instruction has terminated. It also says that the move instructions do not affect any flag. Shouldn't I end up with N being set, or is that test really skipped? Thanks!

MVN and MVP affect no flags whatsoever. However, DB is left pointing at the destination data bank. Hence I usually surround an MVx instruction with PHB and PLB.

As an aside, it should be noted that both of these instructions can be interrupted during execution.

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2015 6:24 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
BigDumbDinosaur wrote:
However, DB is left pointing at the destination data bank. Hence I usually surround an MVx instruction with PHB and PLB.
Ah, that's a good tip. Maybe it should be in the 65816 tricks thread as well?


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 08, 2015 5:33 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
scotws wrote:
BigDumbDinosaur wrote:
However, DB is left pointing at the destination data bank. Hence I usually surround an MVx instruction with PHB and PLB.
Ah, that's a good tip. Maybe it should be in the 65816 tricks thread as well?

I thought that I posted it. I'll have to check.

EDIT: I did mention it in a post about MVN and MVP.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 08, 2015 12:14 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Apols, can't believe I missed that. Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 12, 2015 10:56 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
It's time for me to be a man, quit hiding behind my desk chair, and face the horrors of bank and page wrapping. With the help of Bruce's great 65816 opcode tutorial (http://6502.org/tutorials/65c816opcodes.html) and Programming the 65816, I think I have condensed the logic of it all down to these pseudocode rules, organized by the addressing modes, since that is how I will be coding them.

First, Direct Page Addressing:
Code:
        IF (emulation mode) AND
           (DL == 0) AND   
           (instruction from 6502 or 65C02) 
        THEN wrap on page boundry

        ALWAYS: wrap bank 0
Then, Stack Addressing:
Code:
        IF (emulation mode) AND
           (instruction from 6502 or 65C02)
        THEN wrap page 01
       
        ALWAYS: wrap bank 0
That seems straightforward, thought it took me hours to understand it. We have two more cases of wrapping at bank 0:
Code:
        IF (absolute mode)   \ eg. JMP ($aaaa) / jmp.i aaaa
        THEN wrap on bank 0  \ NOT rpt not PBR

        IF (absolute indirect long)  \ eg. JMP [$aaaa] / jmp.il aaaa
        THEN wrap on bank 0  \ NOT rpt not PBR
The important part about Absolute Indrect Long is that the resulting effective address is 24 bit again, that is, we pull the Bank Byte, too.
Next, three cases of wrapping at the Program Bank Register (PBR):
Code:
        IF (absolute X indirect)  \ eg. JSR ($aaaa,X) / jsr.xi aaaa
        THEN wrap on PBR

        IF (branch instuction) THEN wrap on PBR

        Program Counter (PC) wraps at PBR  \ duh
Last, we have instructions that use the Data Bank Register (DBR) and are not Direct Page or Stack addressing. This is pretty much only:
Code:
        IF (move addressing) THEN wrap on banks
which means MVN and MVP.

The last case hides an important rule: All X and X indexed absolute and long addressing modes that deal with the DBR extend into the next bank. Even more supremely important: This is true for Emulation Mode as well, an real, hard-core difference to the real 6502/65C02. The horror, the horror.

Or at least this is how I understand it. I'd be grateful if anybody sees something I might have missed?

EDIT: Corrected error in Direct Mode, must be DL instead of DH.
EDIT: DP and S mode always wrap on bank boundry, not only if we're not wrapping on page


Last edited by scotws on Wed Oct 14, 2015 9:43 am, edited 4 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 12, 2015 11:12 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
You have emulation-mode Direct Page wrapping depending on DH rather than on DL... you might be right but Bruce says not!
(Related discussion at viewtopic.php?p=40853#p40853)


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 12, 2015 12:34 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
BigEd wrote:
You have emulation-mode Direct Page wrapping depending on DH rather than on DL... you might be right but Bruce says not!
Ahhh, I think I know what the problem is: I'm different-endian here. :D . Let's put this differently: The MSB of D is zero, so D is on "zero page", and the LSB is the one that is changed, right?


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 12, 2015 12:46 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
I'm afraid you've lost me! D is the direct page register, and on the 816 it's two bytes. Bruce calls them DH and DL for the high and the low byte respectively. DH is something that's been seen in some 6502 variations but DL is new, I think. DL allows you to have a non-page-aligned direct page.

In your pseudocode, you're assuming that it's a Direct Page mapped exactly on Zero Page which is the special case. But Bruce's document says that the special case is a page-aligned Direct Page (which includes the case of placing it exactly on zero page.) Bruce has an example of D=FF00, which is page-aligned but not on zero page. By placing a pointer's low byte at FFFF, he can demonstrate the page wrapping: the high byte is fetched at FF00.


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 12, 2015 1:09 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
BigEd wrote:
In your pseudocode, you're assuming that it's a Direct Page mapped exactly on Zero Page which is the special case. But Bruce's document says that the special case is a page-aligned Direct Page (which includes the case of placing it exactly on zero page.)
Now I've got it. Yes, you (and Bruce) are right, I let myself get confused by the paragraph on p. 283 of Programming the 65816, where methinks the paragraph could be clearer:
Quote:
The exception to this is that zero page stack wrapping is only enforced for 6502 and 65C02 instructions, and only when DP = 0 in the case of page zero wrapping.
Will correct, thank you!


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 14, 2015 9:44 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
I've changed the entries for DP and S a bit: Even if we wrap on a page, we also wrap on bank 0. Of course this is a bit silly, because if you wrap on a page, you never are in danger of wrapping the bank (if you never leave your city, you'll never leave your country). But I find this helps with the logic.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 14, 2015 10:59 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Sanity prevails! The "new" DP indexed instructions, that is, those that never ever have page wrapping because they are not found on the 65c02, all seem to have the LSB of the opcode set to 7. Of course, I only noticed this after putting together a nice arrary:
Code:
create new-dp-opcodes
   07 c, ( ora.dil)  17 c, ( ora.dily)
   27 c, ( and.dil)  37 c, ( and.dily)
   47 c, ( eor.dil)  57 c, ( eor.dily)
   67 c, ( adc.dil)  77 c, ( adc.dily)
   87 c, ( sta.dil)  97 c, ( sta.dily)
  0a7 c, ( lda.dil) 0b7 c, ( lda.dily)
  0c7 c, ( cmp.dil) 0d7 c, ( cmp.dily)
  0e7 c, ( sbc.dil) 0f7 c, ( sbc.dily)
I guess that is my useless typing exercise for today. Now we don't have to look through the table, just mask the MSB of the opcode and compare the rest to seven. Clever engineers!

EDIT: I should clarify: Obviously the .dil (direct page indirect long) instructions don't wrap, but we can include them in this word, because they will not call this routine and so are "don't cares".


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

All times are UTC


Who is online

Users browsing this forum: jds and 11 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: