Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Erik_Bam ! (Registered 2024-05-26) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > (Ab)use of dummy accesses
2020-03-09 17:04
chatGPZ

Registered: Dec 2001
Posts: 11148
(Ab)use of dummy accesses

For the next release of my "No more Secrets" doc i am preparing a chapter related to the dummy access which happen when the CPU performs an internal operation. Once again i am looking for some examples on how to (ab)use it :) I guess everyone knows "inc $d019" - but i am sure there is more than this. And not only with RMW instructions. So if you have anything in your mind - just drop it here!

here are some related notes which i pasted together. feel free to proofread and point out mistakes :)
 
... 55 posts hidden. Click here to view all posts....
 
2020-04-03 16:24
chatGPZ

Registered: Dec 2001
Posts: 11148
Quote: Lovely stuff!!!

” Most 1-Byte instructions will fetch PC+1 after the opcode fetch”

All 1-byte right?


btw, its not all of them .... the various JAM opcodes will stall before that happens. not that it matters :)
2020-04-03 17:13
JackAsser

Registered: Jun 2002
Posts: 1994
Quote: btw, its not all of them .... the various JAM opcodes will stall before that happens. not that it matters :)

Haha wtf! That doesn’t count!! :D
2020-04-05 21:10
CyberBrain
Administrator

Posts: 392
Ok, let me take a stab at abusing the dummy write-cycle of RMW instructions:


$3FFF (ghostbyte) under ROM

As we know, when reading a byte from ROM, the CPU reads from the ROM, but when writing to a byte in the ROM, the write falls through to the RAM beneath it.
So with an RMW instruction you can actually write 2 values to a byte in RAM, 1 cycle apart, where none of the two written values are the value that was already present.
Usually not a useful thing to do, but together with the VIC we could exploit this:

Put the VIC in bank 2 or 3 and enable the KERNAL/BASIC ROM. Then an INC (for example) can write to the ghostbyte twice, 1 cycle apart - and the first write doesn't necessarily have to write what was already there!

Unfortunately what you can write at the first dummy cycle is limited to what is in the ROM at the chosen ghostbyte address (4 possibilities).
What you can write at the 2nd write cycle also depends on that value as well as which RMW-instruction you use (so we have 6 possibilities per ghostbyte address for the second write-cycle).

Let's look at which possibilities of pixels we have:

                               First wcycle    Second wcycle:
                                   |           INC         DEC         ASL         ROL (C=1)   LSR         ROR (C=1)
 - $B7FF in ROM contains $B0 = %10110000.      %10110001   %10101111   %01100000   %01100001   %01011000   %11011000
 - $BFFF in ROM contains $E0 = %11100000.      %11100001   %11011111   %11000000   %11000001   %01110000   %11110000
 - $F7FF in ROM contains $D1 = %11010001.      %11010010   %11010000   %10100010   %10100011   %01101000   %11101000
 - $FFFF in ROM contains $FF = %11111111.      %00000000   %11111110   %11111110   %11111111   %01111111   %11111111
                                                  |
                                                  +----> (*)


The choice marked with (*) ($FFFF and INC) might be useful in practice to create a *single cycle* wide $FF pattern! ($00 -> $FF -> $00)

Just do an INC $FFFF somewhere the ghostbyte is visible. (And init the ghostbyte to $00 in advance)

(This can of course be repeated all the way throughout the border, the x-pos can be changed, can be done multiple times per rasterline, etc etc)

Perhaps one can even be creative and use the other patterns for something too...



Charset/Bitmap

Instead of the ghostbyte, the same could be done for charset/bitmaps (but not sprites or the screen) - maybe there is an application there too.

For example (using precise timing) a charset-byte could could be set to $FF at the exact time it is read by the VIC, using the dummy-write of an INC, and then to $00 immediately after, at the second write-cycle, so that it is $00 next time it is rendered by the VIC (instead of LDA #$FF, STA $xxxx, LDA #$00; STA $xxxx).
When repeating the 7th pixel-line of a text-line using linecrunch, for example, this could make the charset-byte $FF on one raster line and $00 on the next with only one INC $xxxx instruction.

That could of course be repeated again and again, every 2nd line, so that the charset-byte alternates between $00 and $FF every rasterline...
(Of course, this requires that there is a $FF or $00 byte in the ROM at that location - but other values might be nice too)

But I haven't really found a totally perfect use-case for this yet, so not sure if it's useful in practice. Ideas?
2020-04-05 22:16
tlr

Registered: Sep 2003
Posts: 1727
_Very_ cool! We approves.
2020-04-05 22:54
chatGPZ

Registered: Dec 2001
Posts: 11148
YES! keep it coming! :)
2020-04-06 17:48
Compyx

Registered: Jan 2005
Posts: 631
Perhaps I'm missing something, but aren't the 'alternate' ghostbytes at $B9FF and $F9FF (when using ECM)?
2020-04-06 18:04
CyberBrain
Administrator

Posts: 392
Yes, you're absolutely right of course. Their values unfortunately doesn't become much nicer:

$B9FF = $A0
$F9FF = $D2
2020-04-06 19:22
Compyx

Registered: Jan 2005
Posts: 631
Nope. But the 'trick' is very interesting though, never would have thought of it :)
2020-04-06 20:15
Oswald

Registered: Apr 2002
Posts: 5028
nice trick, but 3fff can be set to any byte in a 8 pixel wide area with another trick.
2020-04-06 20:56
Compyx

Registered: Jan 2005
Posts: 631
Pray tell.
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 - 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
Didi/Laxity
Gregfeel/Lepsi De, S..
bugjam
Nith/TRIÉ…D
MCM/ONSLAUGHT
jmin
Guests online: 66
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Aliens in Wonderland  (9.7)
5 Coma Light 13  (9.7)
6 Edge of Disgrace  (9.6)
7 No Bounds  (9.6)
8 Comaland 100%  (9.6)
9 Uncensored  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Covert Bitops  (9.4)
2 Nostalgia  (9.4)
3 Oxyron  (9.3)
4 Booze Design  (9.3)
5 Crest  (9.3)
Top Fullscreen Graphicians
1 Sulevi  (9.9)
2 Carrion  (9.8)
3 Joe  (9.8)
4 Duce  (9.8)
5 Mirage  (9.7)

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