#69642 - deltree - Tue Jan 31, 2006 10:22 pm
hi,
I've been wondering about a problem:
most people advise me to use the vsync interrupt as a timer.
of course, this is a very regular event, it happens 60 times per second, so, it's a good timer.
but what if I use a function that is too much big, and doesn't complete in time before the next interrupt happends, and call that function again?
what if my variables are not updated in time?
#69650 - DekuTree64 - Tue Jan 31, 2006 11:02 pm
That's what interrupt handlers are for :)
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#71066 - SeanMon - Fri Feb 10, 2006 4:38 am
What happens if the VBlank handler doesn't complete before the next VBlank? Does it call the VBlank handler again while inside of the current one (I don't think so), or does it ignore the new interupt to finish the current one?
#71072 - wintermute - Fri Feb 10, 2006 5:36 am
SeanMon wrote: |
What happens if the VBlank handler doesn't complete before the next VBlank? Does it call the VBlank handler again while inside of the current one (I don't think so), or does it ignore the new interupt to finish the current one? |
depends how the interrupts are set up.
If you allow nesting then the next vbl irq will interrupt the current handler and end up trashing the irq stack. If nesting isn't allowed then the interrupt will be serviced immediately on return from the current handler.
With the libgba interrupt dispatcher the irq will be ignored and the vblank handler will no longer be called 60 times a second. It disables the interrupt being serviced and re-enables when the handler has completed.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#71078 - DekuTree64 - Fri Feb 10, 2006 6:47 am
Generally you'll want to keep the VBlank interrupt handler small enough that it finishes before the next frame starts drawing, so it's not an issue.
Do as much game logic as possible outside VBlank, and queue up any display updates (OAM, BG regs, maybe some VRAM transfers). Once you've finished processing for the frame, set a flag to tell your interrupt handler to do all the display updates next time it fires.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku