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

Thank you smile

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)
move.w #240,0x3C0006

move.w #0,0x3C0008
move.w #0x17F,0x3C000A

* Standard IRQ1 handler (timer interrupt)
cmp.l #0,_liner (Is it the first line of the display?)
jne 2f
move.w #0x17F,0x3C000A (this should set the timer to skip one line from now on)
not.l _cswitch
cmp.l #0,_cswitch
jeq 3f

move.w #0x7FFF,0x401ffe (Change background colour to white)
jra 4f
move.w #0x8000,0x401ffe (Change background colour to black)
add.l #1,_liner

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


To have IRQ1 repeat after an initial value, during VBlank:

- set 3c0006 bits 4 & 5
- write your initial timing value
- set 3c0006 bits 4 & 7
- write your repeat timing value

Now only have to handle color in IRQ handler, it will repeat each line.


Thanks HPMan. It worked great. I had it in my head that I had to synchronise my raster using D6. Now I see I could have used the VBlank only.

I made the longer interval slightly less than the full 40 lines so the counter reaches zero at the end of the previous line just before the HBlank. It seemed sensible to give a little more time to the raster effect (for the future when I hopefully make something better!)


Yeah with this method you need to do a few cycle counting to aim your initial value just right.