#10452 - Lupin - Fri Sep 05, 2003 2:35 pm
what exactly is your problem about interrupts?
you could use interrupts by using the crt0.s file and creating an array of function pointers or specify the interrupt handler yourself using the interrrupt vector (that's how I do it).
that's my code:
//Interrupts
#define INT_VBLANK 0x0001
#define INT_HBLANK 0x0002
#define INT_VCOUNT 0x0004
#define INT_TIMMER0 0x0008
#define INT_TIMMER1 0x0010
#define INT_TIMMER2 0x0020
#define INT_TIMMER3 0x0040
#define INT_COMUNICATION 0x0080 //serial communication interupt
#define INT_DMA0 0x0100
#define INT_DMA1 0x0200
#define INT_DMA2 0x0400
#define INT_DMA3 0x0800
#define INT_KEYBOARD 0x1000
#define INT_CART 0x2000 //the cart can actually generate an interupt
#define INT_ALL 0x4000 //this is just a flag we can set to allow the function to enable or disable all interrupts. Doesn't actually correspond to a bit in REG_IE
typedef void (*interrupt_handler_t)();
typedef interrupt_handler_t *interrupt_handler_ptr_t;
#define REG_IME (*(vu16*)0x4000208) //Interrupt Master Enable
#define REG_IE (*(vu16*)0x4000200) //Interrupt Enable (Welche Interrupts sollen verarbeitet werden?)
#define REG_IF (*(vu16*)0x4000202) //Interrupt Flags (welcher Interrupt ausgel??t wurde, wichtig zur Auswertung)
#define REG_INTERUPT (*((interrupt_handler_ptr_t)0x03007FFC))
//Interruptfunktionen
void VBLANK(void);
void KEYBOARD(void);
//Das ist der Interrupt-Handler, vielleicht ist es besser ihn
//im Rom zu haben, da spart man sich immerhin einen long call
void HandleInterrupt() {
if (REG_IF & INT_VBLANK) {
VBLANK();
}
if (REG_IF & INT_KEYBOARD) {
KEYBOARD();
}
}
/*-------enable/disable interupt rutien---------------*/
void EnableInterrupt(u16 interrupt) {
REG_IME = 0; //probably not necessary but not a good idea to change interupt registers when an interupt is ocuring
if(interrupt == INT_VBLANK)
REG_DISP_STAT |= 0x8;
else if(interrupt == INT_HBLANK)
REG_DISP_STAT |= 0x10;
else if(interrupt == INT_KEYBOARD) //Alle Tasten aktivieren
REG_P1CNT |= BIT14 | BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5 | BIT6 | BIT7 | BIT8 | BIT9;
REG_IE |= interrupt;
REG_IME = 1;
}
void DissableInterrupts(u16 interrupts) {
REG_IE &= ~interrupts;
if(interrupts == INT_ALL) //this is were that ALL comes in
REG_IME = 0; //disable all interupts;
}
......in main()
REG_INTERUPT = HandleInterrupt;
EnableInterrupt(INT_VBLANK);
EnableInterrupt(INT_KEYBOARD);