Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > 6502 instruction decoding
2012-02-29 18:14
JackAsser

Registered: Jun 2002
Posts: 2014
6502 instruction decoding

Why is it that STA-opcodes always gets an implicit page-crossing penalty in comparison to their LDA counter parts?

F.e.
lda abs,x is 4/5 depending on page crossing
sta abs,x is always 5 independent of page crossing
2012-02-29 18:34
Graham
Account closed

Registered: Dec 2002
Posts: 990
LDA $1234,X

1. fetch opcode
2. fetch low byte of absolute address
3. fetch high byte of absolute address, add X to low byte
4. read byte from calculated address, increase high byte of address if X + LO overflowed
5. if X + LO overflowed, read byte again

If the same happened for STA, the 6502 would sometimes write a byte to a wrong address when doing step 4, so STA will always don't do the write at step 4 and always wait for step 5.
2012-02-29 19:15
Fresh

Registered: Jan 2005
Posts: 101
What Graham said.
The cpu is not able to check cycle hi byte decide whether to write. In lda, by the time it checks it, it has already loaded a (possibly) correct value. But then again, that's just reading.
2012-02-29 19:18
Slammer

Registered: Feb 2004
Posts: 416
Interesting. Do you have some documentation describing the internal working of the processor?
2012-02-29 19:24
Fresh

Registered: Jan 2005
Posts: 101
The good old c64doc
http://www.viceteam.org/plain/64doc.txt
Or you can try the 'real' thing:
http://www.visual6502.org
2012-02-29 20:15
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: What Graham said.
The cpu is not able to check cycle hi byte decide whether to write. In lda, by the time it checks it, it has already loaded a (possibly) correct value. But then again, that's just reading.


Stupid me, but it's quite obvious... :) So... those reads actually occur, not that it matters on the C64, but another platform with full IO-address decoding would perhaps suffer from implicit IRQ-acks f.e. due to those reads then?
2012-02-29 20:15
Copyfault

Registered: Dec 2001
Posts: 478
It always made me wonder why with STA ind,x the chip developers went for a rather consequent solution (only ONE write cycle @ calculation cycle 5) whereas it seems somewhat unpolished for the RMW-opcodes (TWO write cycles: unaltered value @ calc cycle 5, changed value @ calc cycle 6).

Most probably they had no other chance; writing the same value to a register that has just been read from it should not really cause troubles.


A good documentation should be AAY64 by Ninja. At least the internal processor states are also listed there.
2012-02-29 20:21
Graham
Account closed

Registered: Dec 2002
Posts: 990
It should be mentioned that STA $1234,X reads from the same address as LDA $1234,X in step 4.

And yes, this wrong read can acknowledge IRQs. Example:

    LDX #$FF
    LDA $DC0E,X

This would read from $DC0D in cycle 4 and $DD0D in cycle 5, acknowledging both, IRQs and NMIs :)
2012-02-29 20:28
Graham
Account closed

Registered: Dec 2002
Posts: 990
Quoting Copyfault
It always made me wonder why with STA ind,x the chip developers went for a rather consequent solution (only ONE write cycle @ calculation cycle 5) whereas it seems somewhat unpolished for the RMW-opcodes (TWO write cycles: unaltered value @ calc cycle 5, changed value @ calc cycle 6).

It needs 1 cycle to actually do the ALU action.

Quote:
Most probably they had no other chance; writing the same value to a register that has just been read from it should not really cause troubles.

It does have it's effects. Acknowledging Raster IRQs with DEC $D019 only works because RMW writes the same value back that it reads. A clean way to acknowledge VIC2 IRQs would be LDA $D019 STA $D019.
2012-02-29 21:07
JackAsser

Registered: Jun 2002
Posts: 2014
RMW has two write cycles? Wow. So, on Nintendo, with auto incrementing vram-pointer when writing to $2007, this would mean that it would increment the pointer TWO times if I do say, INC $2007. Or rather, THREE times because of the one load cycle as well?
2012-02-29 21:11
TWW

Registered: Jul 2009
Posts: 545
Quote: It should be mentioned that STA $1234,X reads from the same address as LDA $1234,X in step 4.

And yes, this wrong read can acknowledge IRQs. Example:

    LDX #$FF
    LDA $DC0E,X

This would read from $DC0D in cycle 4 and $DD0D in cycle 5, acknowledging both, IRQs and NMIs :)


That is amazing! 8-D

so no more:

    lda $dc0d
    lda $dd0d


just:

    ldx #$ff
    lda $dc0e,X


cool!
 
... 8 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
ΛΛdZ
Acidchild/Padua
Chesser/Blazon
Scrap/Genesis Project
AMB/Level 64
The Syndrom/TIA/Pret..
Guests online: 95
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.053 sec.