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 > (Ab)use of dummy accesses
2020-03-09 17:04
chatGPZ

Registered: Dec 2001
Posts: 11130
(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-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: 1717
_Very_ cool! We approves.
2020-04-05 22:54
chatGPZ

Registered: Dec 2001
Posts: 11130
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: 5022
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.
2020-04-07 08:32
tlr

Registered: Sep 2003
Posts: 1717
Quote: nice trick, but 3fff can be set to any byte in a 8 pixel wide area with another trick.

I assume you are refering to exploiting the difference in pipeline delay between changing the videomode and changing the fetched graphics data to be fetched?

That is a neat trick, but it is dependant on the type of VIC-II (old/new) and it takes more cycles per instance.

The inc $ffff trick is only 6 cycles per instance.
2020-04-07 08:41
Hoogo

Registered: Jun 2002
Posts: 102
Dec $dc0d after a Timer A IRQ occurred would acknowledge that IRQ and stop further ones. But I don't see a good reason to do that.
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
DanPhillips
Mason/Unicess
mutetus/Ald ^ Ons
Guests online: 91
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Webmasters
1 Slaygon  (9.7)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

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