// // 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 // MAP buffer top address #define MAPTOP1 (u16*)0x6004800 // MAP buffer top address #define MAPTOP2 (u16*)0x6005000 // MAP buffer top address #define MAPTOP3 (u16*)0x6005800 // MAP buffer top address #define PALETTE (u16*)0x5000000 // PALETTE 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 LCD_BGMODE0 0x0000 // BG mode 0 #define LCD_BGMODE1 0x0001 // BG mode 1 #define LCD_BGMODE2 0x0002 // BG mode 2 #define LCD_BGMODE3 0x0003 // BG mode 3 #define LCD_BGMODE4 0x0004 // BG mode 4 #define LCD_BGMODE5 0x0005 // BG mode 5 // 有効な背景 #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 BG_PRIORITY_HIGHEST 0x0000 #define BG_PRIORITY_HIGH 0x0001 #define BG_PRIORITY_NORMAL 0x0002 #define BG_PRIORITY_LOW 0x0003 // 背景用 VRAM アドレス #define BG_VRAM0 0x0000 // 0x06000000- #define BG_VRAM1 0x0004 // 0x06004000- #define BG_VRAM2 0x0008 // 0x06008000- #define BG_VRAM3 0x000C // 0x0600C000- // パレット選択 #define BG_PALETTE16 0x0000 // 16 colors * 16 palettes #define BG_PALETTE1 0x0080 // 256 colors * 1 palette // 背景用 MAP アドレス #define BG_MAP00 0x0000 // 0x06000000- #define BG_MAP01 0x0100 // 0x06000800- #define BG_MAP02 0x0200 // 0x06001000- #define BG_MAP03 0x0300 // 0x06001800- #define BG_MAP04 0x0400 // 0x06002000- #define BG_MAP05 0x0500 // 0x06002800- #define BG_MAP06 0x0600 // 0x06003000- #define BG_MAP07 0x0700 // 0x06003800- #define BG_MAP08 0x0800 // 0x06004000- #define BG_MAP09 0x0900 // 0x06004800- #define BG_MAP10 0x0A00 // 0x06005000- #define BG_MAP11 0x0B00 // 0x06005800- #define BG_MAP12 0x0C00 // 0x06006000- #define BG_MAP13 0x0D00 // 0x06006800- #define BG_MAP14 0x0E00 // 0x06007000- #define BG_MAP15 0x0F00 // 0x06007800- #define BG_MAP16 0x1000 // 0x06008000- #define BG_MAP17 0x1100 // 0x06008800- #define BG_MAP18 0x1200 // 0x06009000- #define BG_MAP19 0x1300 // 0x06009800- #define BG_MAP20 0x1400 // 0x0600A000- #define BG_MAP21 0x1500 // 0x0600A800- #define BG_MAP22 0x1600 // 0x0600B000- #define BG_MAP23 0x1700 // 0x0600B800- #define BG_MAP24 0x1800 // 0x0600C000- #define BG_MAP25 0x1900 // 0x0600C800- #define BG_MAP26 0x1A00 // 0x0600D000- #define BG_MAP27 0x1B00 // 0x0600D800- #define BG_MAP28 0x1C00 // 0x0600E000- #define BG_MAP29 0x1D00 // 0x0600E800- #define BG_MAP30 0x1E00 // 0x0600F000- #define BG_MAP31 0x1F00 // 0x0600F800- // 背景サイズ #define BG_SIZE0 0x0000 // Tile 256*256 // Scale 128*128 #define BG_SIZE1 0x4000 // Tile 512*256 // Scale 256*256 #define BG_SIZE2 0x8000 // Tile 256*512 // Scale 512*512 #define BG_SIZE3 0xC000 // Tile 512*512 // Scale 1024*1024 #define RGB(r, g, b) (((b) << 10) + ((g) << 5) + (r)) // マルチブート指定 int __gba_multiboot = 0; // メインプログラム int main(void) { u16* vram = VRAMTOP; u16* map0 = MAPTOP0; u16* map1 = MAPTOP1; u16* map2 = MAPTOP2; u16* map3 = MAPTOP3; u16* palette = PALETTE; // 画面モードの初期化 register(LCD_CTRL) = LCD_BG0EN | LCD_BG1EN | LCD_BG2EN | LCD_BG3EN | LCD_BGMODE0; // 背景 0-3 の初期化 register(BG0CNT) = BG_SIZE0 | BG_MAP08 | BG_VRAM0 | BG_PRIORITY_NORMAL; register(BG1CNT) = BG_SIZE0 | BG_MAP09 | BG_VRAM0 | BG_PRIORITY_NORMAL; register(BG2CNT) = BG_SIZE0 | BG_MAP10 | BG_VRAM0 | BG_PRIORITY_NORMAL; register(BG3CNT) = BG_SIZE0 | BG_MAP11 | BG_VRAM0 | BG_PRIORITY_NORMAL; // パレットへの登録 palette[0] = RGB(31, 31, 31); palette[1] = RGB(31, 0, 0); palette[2] = RGB(0, 31, 0); palette[3] = RGB(0, 0, 31); palette[4] = RGB(31, 31, 0); // タイル 0 for(i = 0; i < 16; i++){vram[i] = 0x0000;} // タイル 1 for(i = 16; i < 32; i++){vram[i] = 0x1111;} // タイル 2 for(i = 32; i < 48; i++){vram[i] = 0x2222;} // タイル 3 for(i = 48; i < 64; i++){vram[i] = 0x3333;} // タイル 4 for(i = 64; i < 80; i++){vram[i] = 0x4444;} // マップへタイルを配置 map0[0] = 0x0001; map1[0] = 0x0002; map2[0] = 0x0003; map3[0] = 0x0004; // 背景のスクロール register(BG1_X_SCROLLING) = 0x0100 - 2; register(BG1_Y_SCROLLING) = 0x0100 - 2; register(BG2_X_SCROLLING) = 0x0100 - 4; register(BG2_Y_SCROLLING) = 0x0100 - 4; register(BG3_X_SCROLLING) = 0x0100 - 6; register(BG3_Y_SCROLLING) = 0x0100 - 6; // 無限ループ while (1){} }