#2109 - Wanderer - Wed Jan 29, 2003 4:21 pm
Hi Folks,
I'm just starting to play arround with interrupts and want to get them working from as low down and dirty as possible in C (to fully understand how they work)
I've knocked out the following code which should display a striped background on Bkg0 and then on the first HBlank turn off the display (not the most exciting use of interrupts ever but it should show if they're working for me).
Can someone please tell me what I'm doing wrong?
cheers,
Wanderer.
I'm just starting to play arround with interrupts and want to get them working from as low down and dirty as possible in C (to fully understand how they work)
I've knocked out the following code which should display a striped background on Bkg0 and then on the first HBlank turn off the display (not the most exciting use of interrupts ever but it should show if they're working for me).
Can someone please tell me what I'm doing wrong?
Code: |
typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; u16 offset = 1; void interruptCode() { offset = 0; } int main() { u16 pal, x, y; // Blank the screen while we set it up. *(u16*)0x04000000 = 0x0080; // Fill in the first 8 entries in the palette for(pal=0; pal<8; pal++) { *(u16*)(0x05000000 + 2*pal) = pal * 0x0842; } // Create a single tile. for(y=0; y<8; y++) { for(x=0; x<4; x++) { *(u16*)(0x06000000 + x*2 + y*8) = (x*2) + (((x*2)+1)<<8); } } // Clear the tile map to all 0s for(y=0; y<32; y++) { for(x=0; x<32; x++) { *(u16*)(0x06000800 + x + y*32) = 0; } } // Set up Bkg 0 with a 256 colour palette, and the correct tile map offset. *(u16*)0x04000008 = 0x0180; // Enable Bkg 0. *(u16*)0x04000000 = 0x0100; // Set the code to be run on an interrupt. *(u32*)0x03007FFC = (u32) &interruptCode; // Set interrupts for HBlank in DISPSTAT. *(u16*)0x04000004 = 0x0010; // Set the HBlank interrupt to be enabled in REG_IE. *(u16*)0x04000200 = 0x0010; // Enable Interrupts in REG_IME. *(u8*)0x4000208 = (u8) 1; while(offset); // Blank the screen once the interrupt has been hit. *(u16*)0x04000000 = 0x0080; while(1); return 0; } |
cheers,
Wanderer.