How To

Raster Interrupt Volatility

1

nathanielbabiak 2020-10-25 01:28

Is there any way to know the scan line that's being drawn from within a main game loop (not within the raster interrupt)? Or, is there any way to have volatile variables that are changed by the raster interrupt?

The manual shows this:
=RASTER
RASTER
Returns the current screen line (y position). Use this in a raster subprogram.
Does this mean the RASTER value can only be useful within a raster interrupt?

I've tried many things. (I've tried a loop that just stores RASTER to an array, then a separate loop to print the array values. I've tried a raster interrupt that loads RASTER value into a global variable, and reads it back in the main game loop. I've tried a raster interrupt that pokes the RASTER value into working memory, then reading *that* in the main game loop. I repeated most of these attempts using PEEK($FF26) also. All these attempts made I think it might have to do with the raster interrupt and volatility. So, I tried just incrementing a global variable within a raster interrupt. Finally, I tried PEEK'ing a value from working memory within the raster interrupt, incrementing it, and POKE'ing it back, then checking on that memory address from within the main game loop.)


nathanielbabiak 2020-10-25 01:31

And, now that it's public I realized my code had a typo. :-/ This code works just fine...

ON RASTER CALL TESTR
WAIT VBL
DO
R = PEEKW( $A000 )
TEXT 0, 0, STR$( R )
LOOP
SUB TESTR
R = PEEKW( $A000 )
INC R
POKEW $A000, R
END SUB


Timo 2020-10-25 06:58

The main program is always executed between the screen refreshes, so RASTER has no useful value there (it's always the same).


Log in to reply.