gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > About V Bank Interrupt

#6820 - tangl_99 - Tue Jun 03, 2003 3:52 am

If The V Bank Interrupt server function does much things, the V Bank interrupt sever function will still execute 60 times per a second?

I have some puzzle about the interrupt!

#6873 - philip - Wed Jun 04, 2003 1:01 am

If you mean "Will the interrupt be called again even if it hasn't finished" then yes! Or at least, I'm fairly certain, because I'm doing some work in 3D which takes longer than 1/60th of a second, and if I leave the interrupt on I get a spectacular crash in the emulator with all sorts of memory violations. These are presumably caused by running out of stack space and screwing up other memory areas as a large number of functions get put on the stack but never finish.

To avoid this, turn off the interrupt while servicing it.

#6893 - gb_feedback - Wed Jun 04, 2003 9:16 am

I would have said 'Make sure you stop processing BEFORE the next interrupt is due'. Schedule long bits of processing over several frames in chunks. Otherwise you may find adding sound support (for example) gets really hard.
_________________
http://www.bookreader.co.uk/

#6938 - philip - Wed Jun 04, 2003 7:44 pm

You can't shedule over several frames if EVERY frame takes longer than 1/60th of a second (though your suggestion works for doing AI, like when Advance Wars makes its move). What you need to do in this case is create a flag that indicates if rendering is complete yet. If you interrupt and rendering is not complete, you only deal with the sound, then return. If it is complete, you render the next frame, too.

Doing it this way also allows you to do a frame limiter, so you can restrict framerate to a lower value. You need to do this when your frames sometimes render at 60 frames a second, but sometimes at 30 etc. You can increment a counter every time you interrupt, and only render if you are READY and have WAITED a certain number of frames.

#6960 - gb_feedback - Thu Jun 05, 2003 9:24 am

I take your point that a 'frame' may be multiples of 1/60 sec. Blame my
loose use of terminology.

But I still think that doing processing in a vblank interrupt routine which is going to take longer than 1/60 sec is asking for trouble. Why not do this long term processing in (for want of the correct term) the foreground and use the interrupts for timing and looking at flags to know when the next picture frame is due, thus guaranteeing that other things needing vblank interrupt, like perhaps sound, work correctly.

Of course I'm talking theoretically, while you are actually writing something that needs this, so consider this not as an argument but as a search for new truths from my part.
_________________
http://www.bookreader.co.uk/

#6984 - philip - Thu Jun 05, 2003 7:41 pm

Actually, I was a little fuzzy on how VBlank actually works. As far as I know, you hit the bottom of the screen, which causes the interrupt, and then you get a brief period, about a quarter of the whole frame time, in which nothing gets drawn and you have to draw your back frame, swap it and do anything else like sound which needs to be done at this time.

Now, currently I'm doing all my transformations for my 3D scene, then enabling VBL interrupt, and in this interrupt I look for keypresses and do my drawing to the screen. But, it's THIS section which is taking longer than 1/60th of a second. As you suggest, this shouldn't be the case. I think I should actually be drawing in the main loop and NOT waiting for VBlank; That's what back buffers are for! That just leaves us with checking button presses, swapping the buffer and doing sound. The VBlank can easily do this in the time available. However, it may take longer than 1/60th of a second for you main loop to complete and for the interrupt to have anything to swap to, but that's okay, because you're still swapping in the blank period.

I suppose in my current program, because my VBlank interrupt is taking too long, I'm actually swapping buffers in the middle of the frame being drawn, though I haven't noticed any visual distortion.

#7008 - tangl_99 - Fri Jun 06, 2003 3:44 am

Thanks!
I have some other problems.
When the interrupts functions ends,should I set REG_IF to 0?
Will the REG_IF automatic be set to 0?