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 > Quick Interrupt Handling Questions

#58072 - AkumaATR - Thu Oct 20, 2005 5:12 pm

1. Is it very often that people need to switch to user mode stack when dealing with nested interrupts via Jeff F.'s approach? I was going to use the interrupt dispatcher from his crt0.o until I started worrying about blowing the IRQ mode stack.

2. I decided to at this point use Wintermute's interrupt dispatcher, as I don't think I have any interrupt processing that is important enough that it can't wait for a current interrupt handler to finish. However, I have REG_IE set so that only interrupts occur on timer 1 overflow, yet it seems that I have to have my handler at index [0] in IntrTable. I read that the function pointers for each associated interrupt should be in the same order as the bits in REG_IF. Wouldn't that mean I should be able to have all entries in IntrTable as NULL except for IntrTable[4]? Like I said, at this point in time it only seems to work for me if I have my handler at IntrTable[0].

Any tips/ideas as to what's going on?

Thanks so much.

#58097 - wintermute - Thu Oct 20, 2005 8:37 pm

The libgba interrupt dispatcher in libgba is a slightly more complex beast than the old method seen in Jeff's crt0. It's designed to allow a basic priority system so that the user can effectively specify the order in which interrupt flags are checked. Instead of a table of function pointers it uses a table which contains both a mask to check for and a function to use for servicing. There are functions in libgba for setting the table entries, you should not attempt to access them directly.

http://devkitpro.sourceforge.net/onlinedocs/libgba/a00031.html

Handlers are placed in the table in the order they are set by the user. No particular entry corresponds to any particular interrupt.

The dispatcher itself is designed to allow nested interrupts when the user requires them rather than making all interrupts nested by default. Setting the interrupt master flag (REG_IME) in your handler allows it to be interrupted, leaving it alone operates as a standard single interrupt without nesting.