I've written a delay function that simply counts the times the screen raster line reaches a particular value.
// zero page addresses .const delayFrames = $00fa .const delayCounter = $00fb // ============================================== // Delay n frames // [A,delayFrames,delayCounter] // ============================================== Delay: lda #0 sta delayCounter !: // check if delay done lda delayCounter cmp delayFrames beq !++ // -> done // inc delayCounter inc delayCounter // loop until raster line reached (1 frame) !: lda #200 cmp Screen.RasterLine bne !- jmp !-- // done !: rts
But it doesn't behave the way I expect. Could anyone help me understand the following behaviour...
With delayFrames set to 50 (1 second) and checking for raster line 0 : I get about 200ms delay
With delayFrames set to 50 (1 second) and checking for raster line 200 : I get about 500ms delay.
So, I don't understand why checking for a different raster line should change anything. Every raster line will be reached once in 1/50th second. Is there something wrong in my code, or is there an issue with reading the raster line?
The way I understand the raster line system variable (RasterLine = $d012) is that it contains the current y position of the electron gun as driven by the C64. And if I read it continuously, I would get something like this:
i.e. some readout of the current raster line.
Presumably it's going pretty fast, but I don't really know how fast, and I might get a few readings for each line. Or one reading, or just one reading every few lines. But I just don't know what the situation is.
How reliable is the raster line value?