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 > Stable Raster routine
2014-10-22 18:40
xIII

Registered: Nov 2008
Posts: 210
Stable Raster routine

A long time ago I coded a small routine which shows some rasterbars moving on the screen (Transparent Rasterbars). I got some help from my mates in WOW with this stable raster routine.
I know that the NOPs are there for cycle timing but I don't understand how it works :(
Can someone explain me how this works?

;--------------------------------------------------
; stable raster routine ?
;--------------------------------------------------

irq INC $D019 ; 6 cycles
LDY #$19 ; 2 cycles
INY ; 2 cycles
INY ; 2 cycles
STY $D011 ; 4 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles

LDY #$00 ; 2 cycles
jump01 LDX #$F8 ; 2 cycles
LDA rastertable,Y ; 4+ cycles
jump03 STA $D020 ; 4 cycles
STA $D021 ; 4 cycles
INY ; 2 cycles
INX ; 2 cycles
BEQ jump01 ; 2++ cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
NOP ; 2 cycles
LDA rastertable,Y ; 4+ cycles
CPY #$80 ; 2 cycles
BCS clearrastertbl ; 2++ cycles
NOP ; 2 cycles
NOP ; 2 cycles
CLC ; 2 cycles
BCC jump03 ; 2++ cycles

; ---------------
; 94-102 cycles
2014-10-22 18:52
chatGPZ

Registered: Dec 2001
Posts: 11123
the "trick" is in the first few lines of code.... you set the raster irq to trigger in a non badline between lines $30 and $f8, and then change $d011 to match the badline condition. that will then result in a badline and after that the code is stabilized (the infamous "auto stabilizing" of FLI).

i strongly recommend to have a look at the "double irq" method though :)
2014-10-22 19:45
Oswald

Registered: Apr 2002
Posts: 5020
the effect (FLI) used there might fuck up your gfx.

I'd recommend using this instead (clean & short):

http://codebase64.org/doku.php?id=base:using_a_timer_as_an_inve..


This method uses a CIA timer to know where the CPU is within a certain rasterline, and use this to take a tricky branch which wastes enough cycles according to the timer so the routine becomes stable.
2014-10-22 20:03
xIII

Registered: Nov 2008
Posts: 210
Thx for the reply ... but I still don't get it :(

Would it be possible to have a detailed explanation of the code in fucntion of timing and cycles ?

Much appreciate it !

And I will look into the double irq method, allthough at first sight it looks even more complicated :)
2014-10-22 20:08
xIII

Registered: Nov 2008
Posts: 210
@Oswald: I read the article earlier today and also the discussion on CSDB forum :) But reading and understanding is not the same :(
I will dig into it again and try to understand :)
2014-10-22 20:29
TWW

Registered: Jul 2009
Posts: 541
http://codebase64.org/doku.php?id=base:stable_raster_routine
2014-10-23 07:27
xIII

Registered: Nov 2008
Posts: 210
TWW: thanks, I will study that too :)

But in my routine, where does the cyclecount start ?
If i need 64/65 cycles, I need to know where/when I should start counting.
2014-10-23 07:51
lft

Registered: Jul 2007
Posts: 369


http://linusakesson.net/programming/vic-timing/victiming.pdf

Study this chart. Starting anywhere on cycle 15-54 (corresponding to the large red box), you go from non-badline to badline by writing to $d011. This jumps sideways into the red box. As signified by the red colour in the chart, this stalls the CPU, and it will resume execution again at cycle 55. Thus, you stabilise the raster by going from an unknown cycle (within a range) to a known cycle.

Hope this helps!
2014-10-23 07:52
Oswald

Registered: Apr 2002
Posts: 5020
your routine relies on a special "auto" stabilizing effect but it also has a graphical glitch as a sideeffect on the line executed.

the one by TWW starts a raster interrupt, then starts a 2nd raster irq while the first is executing nops, this is done so that an irq interrupting nops will only have 1 cycle jitter. finally the "critical" instruction removes the final jitter. (if the raster counter is on the same line adds 1 more cycle, if its on the next line it doest, because the final jitter is exactly between two raster lines)
2014-10-23 09:57
Flavioweb

Registered: Nov 2011
Posts: 447
It's also possible to mix up both things:
Use the dma stabilization trick to setup a cia timer, then use the "inverted timer" trick to stabilize your irq code.
Imho is the simplest way to have a stable raster code without side effects (like fli bug).
2014-10-23 09:59
chatGPZ

Registered: Dec 2001
Posts: 11123
the double irq thing is much simpler IMHO. but you should be able to do both, of course =)
2014-10-23 13:10
Dr.j

Registered: Feb 2003
Posts: 276
@xIII/WOW: for simple rasterbars effect you don't need stable rasters. you can use delay table or better
a compact raster routine which take 63 cycles for
normal line/21 cycles for bad line. good luck
2014-10-24 08:29
xIII

Registered: Nov 2008
Posts: 210
Dr J.: I usually use a delay table, at least I understand how that works ;)

Thanks everyone for the replies and especially for the links and the PDF !
2014-10-27 00:25
HCL

Registered: Feb 2003
Posts: 716
Checkout Uncensored for a stable raster routine.. even rotating :) Haha, i just couldn't resist :P.
2014-10-27 15:37
Pantaloon

Registered: Aug 2003
Posts: 124
hcl, haha
2014-10-27 21:52
Smasher

Registered: Feb 2003
Posts: 512
that part with rotating rasters caused the biggest "WOOOOOW!" in the whole democompo! :) (ok, offtopic & I dont care)
2014-10-27 21:54
chatGPZ

Registered: Dec 2001
Posts: 11123
despite that i wouldnt call this drunken mess exactly stable at all! =P
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
MaD ][/Starship
Krill/Plush
Guests online: 127
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 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (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 Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 MWS  (9.6)

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