| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
The mistery of $00/$01 ram bytes and the ghost value.
As asked by Groepaz, here is the splitted thread about this story.
What's the point?
The question is that this code:
.> c000 a9 7f lda #$7f
.> c002 cd 12 d0 cmp $d012
.> c005 d0 fb bne $c002
.> c007 ad 11 d0 lda $d011
.> c00a 10 fb bpl $c007
.> c00c a5 01 lda $01
.> c00e a0 e0 ldy #$e0
.> c010 8c ff 3f sty $3fff
.> c013 85 01 sta $01
.> c015 a5 01 lda $01
.> c017 ad 00 de ldx $de00
.> c01a 60 rts
write and then read value "$e0" from RAM lication $01 (not from internal cpu "register"!) reading it from an "unconnected" ram location (as $de00 is), just after a "regular" access to $01 by the cpu.
The first big part of the mistery is that i supposed that value coming from $01 ram was "parked" on the bus, since cpu when access "internal" $01 setup anyway the bus to read from ram, but without really access it.
As pointed out in the other thread, before a LDX $DE00 can access the bus to read the value contained into ram $01, at least 3 bytes go throught the bus: the opcode LDX, a 00 and a DE.
But at the end of execution, we have the value "$E0", as supposed to be, in .X.
So... where this value come from?
And again.
If we try to write into $01, "directly" without use the "idle vic access"/$01 write trick, no value is stored into ram $01.
Why we need vic to do that?
For eg:
SEI
LDA $01
LDX #$E0
STA $01
STX $DE00
CLI
RTS
don't store anything in ram $01.
Groepaz says that into an issue of C=hacking on codebase the question is explained as well... but i looked for infos without success.
Someone of you can explain me what kind of magic is this? |
|
| |
lft
Registered: Jul 2007 Posts: 369 |
The $e0 is still at $3fff, so VIC fetches this byte at every half cycle. Including the half cycles between operand fetches and the read from $de00. You are not reading from $01, you are reading the idle byte (which happens to hold the same value as $0001 does).
Hope this clears things up. |
| |
Oswald
Registered: Apr 2002 Posts: 5086 |
that makes sense. the C= Hacking article suggests using sprite collision for reading, for writing the method is the same there, however I have my doubts its working, as VICII always performs read accesses, why would it let both the bus address and R/W line alone, even in an idle read ? an idle read must set bus to read and address to 3fff. |
| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
YES!
Now make sense.
Now i have to understand why value in $3FFF is written to $01. |
| |
Oswald
Registered: Apr 2002 Posts: 5086 |
Quote: YES!
Now make sense.
Now i have to understand why value in $3FFF is written to $01.
you should check atleast visually $01 to make sure the write happens. not sure maybe you did that already. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11354 |
didnt i post the test program that does all that before? it works, really :) |
| |
Fresh
Registered: Jan 2005 Posts: 101 |
When the cpu writes to addresses 0/1, it sets R/W to low (write), it correctly sets the address lines ($0000/$0001) BUT it sets the data register to tri-state (font: vic article - it clearly makes sense, because it needs to route the data register bus to its internal I/O ports).
But also the VIC lines are in tri-state, because the video chip is in idle, so the data bus is just floating or, as it often happens in c64 world, it's somehow keeping the last levels. Those levels depend on the last half cycle, during which the VIC has read its own stuff.
Now, as mentioned before, R/W line and address bus are correctly set, so the stuff on the floating data bus - VIC latest read - happily goes to the memory chip. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11354 |
Quote:it's somehow keeping the last levels.
well, not "somehow" of course, there is no magic involved - it is parasitic capacitance of the bus and the i/o driver stages. the same phenomena that also eg lets you read back the value from readonly SID registers. |
| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
Quoting Groepazreadonly SID registers.
Writeonly...
gotcha!
Rotfl... just kiddin' eh... =)
Now my mind goes around thinking how can happen if i write to, for eg, $DE00 in the middle of some Vic-half-cycles...
...shame that i have never coded a FLI routine...
=P |
| |
chatGPZ
Registered: Dec 2001 Posts: 11354 |
Quote:
Writeonly...
gotcha!
oooops =D
as for open i/o... again in c=hacking you can find an article by marko m. where he runs a "program" located at $de00, that one gives some more answers on the behaviour of this stuff. |