6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon May 06, 2024 2:40 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Wed Mar 01, 2017 8:04 pm 
Offline

Joined: Sun Jan 08, 2017 12:07 am
Posts: 11
Referring to this manual, I'm currently studying the timing of absolute, X addressing for read-modify-write instructions (section A. 4.4.). In cycles 3 and 4, the address bus has the exact same values, but data is only fetched in cycle 4. The address bus is marked with "(discarded)" in T3. Why is this? I would think that the extra cycle, T4, would only be needed if a carry was generated out of adding BAL and X, in order to increment ADH, similar to how other types of instructions in this mode handle page crossing.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 01, 2017 8:12 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10798
Location: England
I vaguely recall there are some anomalies in this area: some instructions always use the extra cycle. As you say, it's not strictly necessary. You could think of it as a performance bug.

This might help:
Quote:
Unfortunately, this is not always documented correctly, as some 65C02 documentation mistakenly assumes that DEC and INC have the same timing as ASL, LSR, ROL, and ROR; namely that INC abs,X and DEC abs,X take 6 cycles when a page boundary is not crossed, which is, once again, incorrect. DEC abs,X and INC abs,X always take 7 cycles.

From Bruce Clark's "65C02 Opcodes"


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 01, 2017 8:31 pm 
Offline

Joined: Sun Jan 08, 2017 12:07 am
Posts: 11
Very interesting. Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 01, 2017 10:01 pm 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 672
I would think that a descriptive solution to why this cycle is always there merits a trip through visual6502. See how the paths starting from the micro-operation dispatch table differ between extra-cycle-when-page-crossed and the always-take-an-extra-cycle instructions like these. The 6502 is very compact and clever, and if some things just didn't fall into the optimization model they chose, it's either tear it apart and lose simplicity and reusable optimizations, or live with a sometimes-extra cycle on your RMW abs,X instructions.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 01, 2017 10:07 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10798
Location: England
Fair point: not so much a bug, as a wrinkle, which couldn't be ironed out within the constraints of the implementation (they had a hard limit on how big the chip could be, and did cut things out, and also had a tight timescale.) [I speak of the NMOS 6502 - the CMOS 6502s had different constraints and could perhaps have got everything "right" if they'd noticed every detail of what they'd designed.]


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2017 12:16 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3353
Location: Ontario, Canada
BigEd wrote:
I vaguely recall there are some anomalies in this area:
Yes. And the 'C02 fixed the problem... but, curiously, for some but not all of the RMW instructions. :!: Moreover, the documentation fails to accurately describe this! See dclxvi's thread, A 65C02 bug?

Attachment:
Table 7-1 excerpt (original).gif
Table 7-1 excerpt (original).gif [ 6.04 KiB | Viewed 5932 times ]
I wrote:
indexed addressing raises the possibility of a page crossing, which means an extra cycle may be required prior to the memory access. But for some indexed Read-Modify-Write instructions an NMOS chip will always include an extra cycle, even when no page crossing occurs. [...]

Table 7-1 of the WDC datasheet claims this issue has been corrected for the CMOS version, but in fact that's only true regarding ROL ROR ASL and LSR. INC and DEC are also Read-Modify-Write instructions, but the fix does not apply. Table 7-1 should read as shown below.


Attachments:
Table 7-1 excerpt (corrected).gif
Table 7-1 excerpt (corrected).gif [ 8.17 KiB | Viewed 5932 times ]

_________________
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: Mon Aug 20, 2018 12:33 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10798
Location: England
Dr Jefyll wrote:
BigEd wrote:
I vaguely recall there are some anomalies in this area:
Yes. And the 'C02 fixed the problem... but, curiously, for some but not all of the RMW instructions. :!: Moreover, the documentation fails to accurately describe this! See dclxvi's thread, A 65C02 bug?


Aha - I just had a lightbulb moment of my own. I noticed Jens' "true cycle" core is intended for use in an Apple II disk application - where cycle-accurate timing is everything. I wonder if the unimproved instructions, the ones which apparently have some unoptimised logic and take one more cycle than they need to, were used by Apple's 8 bit code, and for compatibility purposes had to be left as-is?


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 20, 2018 1:03 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3353
Location: Ontario, Canada
BigEd wrote:
I wonder if the unimproved instructions [...] for compatibility purposes had to be left as-is?

Interesting idea, Ed! :shock: The context is 65C02, but I'm reminded of another thread which mentions the 65816 getting its evolution reversed because that's what Apple wanted. :|

Quote:
If WDC wanted Apple to use the '816, WDC would have to redesign the chip. They did.
Detailed summary here.

-- Jeff

_________________
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: Mon Aug 20, 2018 1:13 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10798
Location: England
Aha - we'd already solved the puzzle, more or less!


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 20, 2018 2:52 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3353
Location: Ontario, Canada
It was you, Ed, who suggested Apple's (possible) influence. Which is just a theory, but a plausible one, IMO. I can't think of a better explanation for why the 'C02 fix is so puzzlingly incomplete.

I'd be interested to know whether it can be confirmed that Apple's disk controller relies on the NMOS timing for INC and DEC with Absolute, X mode.

_________________
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: Mon Aug 20, 2018 3:05 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10798
Location: England
I'd be interested too!


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 20, 2018 7:24 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8175
Location: Midwestern USA
Dr Jefyll wrote:
It was you, Ed, who suggested Apple's (possible) influence. Which is just a theory, but a plausible one, IMO. I can't think of a better explanation for why the 'C02 fix is so puzzlingly incomplete.

I'd be interested to know whether it can be confirmed that Apple's disk controller relies on the NMOS timing for INC and DEC with Absolute, X mode.

...and then there's the undocumented double-read with <addr>,X that the 65C02 does, much to the chagrin of anyone trying to configure an NXP UART using that addressing mode. :twisted:

_________________
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  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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: