Skip to main content
4 of 4
Clarifications. Split up solid block of text into paragraphs for clarity.
TonyM
  • 5.3k
  • 1
  • 24
  • 37

Assembly delay function for C64

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...

  1. With delayFrames set to 50 (1 second) and checking for raster line 0 : I get about 200ms delay

  2. 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:

0,0,0,1,1,2,2,2,3,3,3,3,4,4,4,5,5,6,6,6

or...

0,1,2,3,4,5,6

or...

1,4,9,12,16,18

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?

Links: Get exact position of raster beam on C64/C128