Hi I am experimenting with raster interrupts. Please bear in mind I am not a very good C or assembly programmer. I don't know either very well.
In the NGDevKit - Using the NeoThunder example game (which is written in C) . I made a very simple effect (literally switching the background colour from white to black every line) before I try anything more ambitious.
I wanted to stop this interrupt happening outside of the display area - so within the vertical blank routine, I set the timer to skip 40 lines. I hope I have understood this correctly.
I used a global variable called 'liner' to count which display line is currently being displayed
The code below does seem to work - unless I just think it is working. But I would like to know - is this the 'right' way to do this? and also is there a better way than using a global variable? I also use one (cswitch) as a flag to switch background colours
Here is a summary of my code (I cut out the unimportant lines)
(I set flag to reset timer at beginning of first line of horiz blanking on first vblank line)
* Standard IRQ1 handler (timer interrupt)
cmp.l #0,_liner (Is it the first line of the display?)
move.w #0x17F,0x3C000A (this should set the timer to skip one line from now on)
move.w #0x7FFF,0x401ffe (Change background colour to white)
move.w #0x8000,0x401ffe (Change background colour to black)
* Standard IRQ2 handler (Vertical Blank)
move.w #(384*40)-1,0x3C000A (set the timer to skip 40 lines)
move.l #0, _liner
clr.l _cswitch (reset colour toggle)
EDIT I think I can see a better way of doing this by setting the mode register to not reload the timer counter with the new value straight away. But I'll still need to figure out when to change it back to a one line interval after it's been loaded with 40 lines.