// // Test program for GBA devkitadv // // 型情報 typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; typedef signed char s8; typedef signed short s16; typedef signed long s32; // 制御レジスタ情報 #define VRAMTOP (u16*)0x6000000 // VRAM frame buffer top address #define MAPTOP0 (u16*)0x6004000 // VRAM frame buffer top address #define MAPTOP1 (u16*)0x6004800 // VRAM frame buffer top address #define MAPTOP2 (u16*)0x6005000 // VRAM frame buffer top address #define MAPTOP3 (u16*)0x6005800 // VRAM frame buffer top address #define PALETTE (u16*)0x5000000 // VRAM frame buffer top address #define register(p) *((u16*) p) // I/O register handling macro #define LCD_CTRL 0x04000000 // LCD control #define BG0CNT 0x04000008 // BG0 control #define BG1CNT 0x0400000a // BG1 control #define BG2CNT 0x0400000c // BG2 control #define BG3CNT 0x0400000e // BG3 control #define BG0_X_SCROLLING 0x04000010 #define BG0_Y_SCROLLING 0x04000012 #define BG1_X_SCROLLING 0x04000014 #define BG1_Y_SCROLLING 0x04000016 #define BG2_X_SCROLLING 0x04000018 #define BG2_Y_SCROLLING 0x0400001a #define BG3_X_SCROLLING 0x0400001c #define BG3_Y_SCROLLING 0x0400001e #define KEY_INPUT 0x04000130 #define KEY_INTERRUPT 0x04000132 #define INT_IE 0x04000200 #define INT_IF 0x04000202 #define INT_IME 0x04000208 #define LCD_BG0EN 0x0100 // Enable BG0 #define LCD_BG1EN 0x0200 // Enable BG1 #define LCD_BG2EN 0x0400 // Enable BG2 #define LCD_BG3EN 0x0800 // Enable BG3 #define RGB(r, g, b) (((b) << 10) + ((g) << 5) + (r)) #define KEY_A 0x0001 #define KEY_B 0x0002 #define KEY_SELECT 0x0004 #define KEY_START 0x0008 #define KEY_RIGHT 0x0010 #define KEY_LEFT 0x0020 #define KEY_UP 0x0040 #define KEY_DOWN 0x0080 #define KEY_R 0x0100 #define KEY_L 0x0200 #define KEY_INTEN 0x4000 #define KEY_INTAND 0x8000 #define INT_VBLANK 0x0001 #define INT_HBLANK 0x0002 #define INT_VCOUNT 0x0004 #define INT_TIMER0 0x0008 #define INT_TIMER1 0x0010 #define INT_TIMER2 0x0020 #define INT_TIMER3 0x0040 #define INT_COMM 0x0080 #define INT_DMA0 0x0100 #define INT_DMA1 0x0200 #define INT_DMA2 0x0400 #define INT_DMA3 0x0800 #define INT_KEY 0x1000 #define INT_GAMEP 0x2000 // マルチブート指定 int __gba_multiboot = 0; volatile u16 x_scrolling = 0; void IRQ_Handler() { u16 Int_Flag; register(INT_IME) = 0; Int_Flag = register(INT_IF); if((Int_Flag & INT_KEY) != 0){ if((register(KEY_INPUT) & KEY_A) == 0){ x_scrolling = 0; } else if((register(KEY_INPUT) & KEY_B) == 0){ x_scrolling = 8; } } register(INT_IF) = Int_Flag; register(INT_IME) = 1; } void WaitForVsync(void) { while(*(volatile u16*)0x4000006 >= 160){}; while(*(volatile u16*)0x4000006 < 160){}; } // メインプログラム int main(void) { s32 i; u8 x, y; u16* vram = VRAMTOP; u16* map0 = MAPTOP0; u16* map1 = MAPTOP1; u16* map2 = MAPTOP2; u16* map3 = MAPTOP3; u16* palette = PALETTE; register(INT_IME) = 0; *(u32*)0x03007FFC = (u32)IRQ_Handler; register(INT_IE) |= INT_KEY; register(KEY_INTERRUPT) = KEY_INTEN | KEY_A | KEY_B; register(INT_IME) = 1; // 画面モードの初期化 register(LCD_CTRL) = (0 << 13) | (1 << 6) | LCD_BG0EN | 0x0000; // Mode0, BG0 表示 register(BG0CNT) = (8 << 8) | (0 << 7) | 0x0000; // 赤青緑のカラーパターン描画 palette[0] = RGB(31, 31, 31); palette[1] = RGB(31, 0, 0); palette[2] = RGB(0, 31, 0); palette[3] = RGB(0, 0, 31); for(i = 0; i < 16; i++){ vram[i] = 0x0000; } for(i = 16; i < 32; i++){ vram[i] = 0x1111; } for(i = 32; i < 48; i++){ vram[i] = 0x2222; } for(i = 48; i < 64; i++){ vram[i] = 0x3333; } map0[0] = 0x0000; map0[1] = 0x0001; map0[2] = 0x0002; map0[3] = 0x0003; // 無限ループ while(1){ register(BG0_X_SCROLLING) = x_scrolling; // Vブランクまで待機 WaitForVsync(); } }