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.

Beginners > Interupts

#69861 - QuantumDoja - Thu Feb 02, 2006 2:13 pm

Hi, I have read people talking about Interupts, What do they do, what can they be used for, why should I use them?

Regards

Chris
_________________
Chris Davis

#70193 - deltree - Sat Feb 04, 2006 10:45 pm

from what I've understood, interrupts are some kind of events that are triggered automatiquely by the system:
for exemple, the screen is updated 60 times per seconds on the GBA. every time a frame is draw, and interrupt is triggered.
You can easily associate a function with this trigger.
One purpose for that "frame" trigger would be to have a regular timer for example.

#70204 - Cearn - Sun Feb 05, 2006 12:46 am

What deltree said.

And to add a few things:
Interrupts make the CPU stop whatever it's doing and does the associated interrupt service routine (ISR). No matter where you are in the code, it'll go to the ISR. For example, if you want things to be updated at HBlank (which is necessary for mode7 and a slew of other effects), you won't have to pepper your code with ifs to see when you're inside the HBlank, just catch it with an interrupt. The same is true with playing music, which has to be updated at very regular intervals. This is often done with timing or DMA interrupts.

Aside from functional items like these, it is recommended to use the WaitForVBlank() BIOS call when you have to wait for the VBlank, rather than test manually using REG_DISPSTAT, because it'll actually stop the CPU until you need it again, thus saving battery power. But for this to work, you have to have interrupts.

More on using interrupts here.