void init_game() { //Initialization //Field_0 memcpy(pal_bg_mem, bd_forestPal, bd_forestPalLen); memcpy(&tile_mem[0][0], bd_forestTiles, bd_forestTilesLen); memcpy(&se_mem[30][0], bd_forestMap, bd_forestMapLen); REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_4BPP | BG_REG_32x32 | BG_PRIO(1); //Bg_Forest memcpy(&pal_bg_bank[1], bg_forestPal, bg_forestPalLen); memcpy(&tile_mem[0][16], bg_forestTiles, bg_forestTilesLen); memcpy(&se_mem[28][0], bg_forestMap, bg_forestMapLen); REG_BG1CNT = BG_CBB(0) | BG_SBB(28) | BG_4BPP | BG_REG_64x32 | BG_PRIO(0); memcpy(&tile8_mem[4][0], pikmin_sheetTiles, pikmin_sheetTilesLen); memcpy(pal_obj_mem, pikmin_sheetPal, pikmin_sheetPalLen); REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_OBJ| DCNT_OBJ_1D; oam_init(obj_buffer, 128); u32 tid=0, pb=0; OBJ_ATTR *pkm = &obj_buffer[0]; obj_set_attr(pkm, ATTR0_TALL, ATTR1_SIZE_16x32, ATTR2_PALBANK(pb) | tid); pkm->attr0 |= ATTR0_8BPP; oam_copy(oam_mem, obj_buffer, 1); }
/** \brief Displays the list of all known species. Calls ShowDexEntry when the user wants to. */ void openPokeDex() { int cX = 0; int cY = 0; int cursor = (cX * 5) + cY; int scroll = 0; int species = 0; char daah[32]; Redraw: vwBlackTransparentLUT(); CleanUpCrap(); ClearOamBak(); DmaArrayCopy(dexlist_gsPal, MEM_PAL_BG + 0x0000); DmaArrayCopy(dexlist_gsTiles, MEM_VRAM + 0x0000); DmaArrayCopy(dexlist_gsMap, MEM_VRAM + 0xE000); REG_BG0CNT = BG_4BPP | BG_SIZE0 | BG_PRIO(0) | 31 << BG_SBB_SHIFT | 2 << BG_CBB_SHIFT; REG_BG1CNT = BG_4BPP | BG_SIZE0 | BG_PRIO(1) | 28 << BG_SBB_SHIFT | 0 << BG_CBB_SHIFT; REG_BG2CNT = BG_4BPP | BG_SIZE2 | BG_PRIO(2) | 29 << BG_SBB_SHIFT | 0 << BG_CBB_SHIFT; REG_DISPCNT = DCNT_MODE0 | DCNT_OBJ | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ_1D; pal_bg_mem[0] = 0x7FFF; REG_BG2VOFS = 23; REG_BG2HOFS = 21; vwWhiteTransparentLUT(); vw_SetSmall(); vwWrite(4,129,"¥PICK ¢OK £CANCEL °±²OPTIONS"); vwSetLine(0,20,0, 608, 15); vw_SetBig(); vwSetLine(8,20,17, 96, 15); vwSetLine(8,20,18,128, 15); vwBlackTransparentLUT(); PokeDex_WriteList(scroll, cursor, 1); FadeIn(); REG_BLDCNT = BLD_BUILD(BLD_OBJ, BLD_BG2 | BLD_BD, 0); REG_BLDALPHA = BLDA_BUILD(8, 8); while(1) { species = DexList[cursor + scroll + 1]; DoVBlank(); KeyRead(); if(Trg & A_BUTTON) { if(GETBIT(MyDex.seen, DexList[cursor+scroll]) == 0) { //error buzz? } else { FadeOut(); ShowDexEntry(DexList[cursor+scroll]); goto Redraw; } } if(Trg & B_BUTTON) { break; } if(Trg & U_KEY) { if (cX == 0) { if(scroll > 0) { scroll--; } } else cX--; cursor = (cX * 5) + cY; PokeDex_WriteList(scroll, cursor, 0); } else if(Trg & D_KEY) { if (cX == 2) { if(scroll < 42) { scroll++; } } else cX++; cursor = (cX * 5) + cY; PokeDex_WriteList(scroll, cursor, 0); } else if(Trg & L_KEY) { cY--; if(cY == -1) { cY = 4; cX--; if(cX == -1) { scroll--; cX = 0; if(scroll == -1) { scroll = 0; cY = 0; } } } cursor = (cX * 5) + cY; PokeDex_WriteList(scroll, cursor, 0); } else if(Trg & R_KEY) { cY++; if(cY == 5) { cY = 0; cX++; if (cX == 3) { scroll++; cX = 2; } } cursor = (cX * 5) + cY; PokeDex_WriteList(scroll, cursor, 0); } else if(Trg & KEY_SELECT) { PokeSearch(); goto Redraw; } } FadeOut(); vwNormalLUT(); ClearOamBak(); ResetBackgrounds(); }
int main() { // Set display options. // DCNT_MODE0 sets mode 0, which provides four tiled backgrounds. // DCNT_OBJ enables objects. // DCNT_OBJ_1D make object tiles mapped in 1D (which makes life easier). REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ; REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_8BPP | BG_REG_32x32 | BG_PRIO(0); REG_BG1CNT = BG_CBB(0) | BG_SBB(29) | BG_8BPP | BG_REG_32x32 | BG_PRIO(1); REG_BG2CNT = BG_CBB(0) | BG_SBB(25) | BG_8BPP | BG_REG_64x64 | BG_PRIO(2); REG_BG2HOFS = 0; REG_BG2VOFS = 0; ClearObjects(); SetPaletteBG(1, RGB(31, 31, 31)); // white //Load each tile in font_bold into it's corresponding position in charblock 0 for (int i = 0; i < 128; i++) { LoadTile8(0, i, font_bold[i]); } DrawText(5, (SCREEN_HEIGHT / 16) - 2, "DECEPTIVE DIMENSIONS"); DrawText(5, (SCREEN_HEIGHT / 16), "Press start to begin"); Buttons buttons; int framecounter = 0; //Title screen (under construction) while (true) { buttons.Update(); if (buttons.StartJustPressed()) { break; } WaitVSync(); } while (true) { //Load Custom spritesheet LoadPaletteObjData(0, spritesheet4Pal, sizeof spritesheet4Pal); LoadPaletteBGData(0, backgroundnewnewPal, sizeof backgroundnewnewPal); LoadTileData(4, 0, spritesheet4Tiles, sizeof spritesheet4Tiles); LoadTileData(0, 0, backgroundnewnewTiles, sizeof backgroundnewnewTiles); int levelnumber = 1; Level level(levelnumber); for (int screenblock = 21; screenblock < 31; screenblock++) { level.FillScreenblock(screenblock, 0); } level.DrawBackground(level.curdimension); bool gamerunning = true; //Main game loop while (gamerunning) { buttons.Update(); gamerunning = level.CheckIfLevelComplete(); level.TakeInput(buttons); level.MoveObjects(); level.Draw(); level.UpdateLevelObjects(framecounter); framecounter++; WaitVSync(); FlipBuffers(); } //Reload each tile in font_bold into it's corresponding position in charblock 0 for (int i = 0; i < 128; i++) { LoadTile8(0, i, font_bold[i]); } SetPaletteBG(0, RGB(0, 0, 0)); // black SetPaletteBG(1, RGB(31, 31, 31)); // white for (int screenblock = 25; screenblock < 31; screenblock++) { for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { SetTile(screenblock, x, y, 0); } } } level.player.drawx = SCREEN_WIDTH; SetObject(level.player.GetObjNum(), ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_HIDE, ATTR1_SIZE(2) | ATTR1_X(level.player.drawx), ATTR2_ID8(0) | ATTR2_PRIO(2)); UpdateObjects(); DrawText(6, (SCREEN_HEIGHT / 16) - 2, "That's all folks!!"); DrawText(3, (SCREEN_HEIGHT / 16), "Press start to try again"); while (true) { buttons.Update(); if (buttons.StartJustPressed()) { break; } WaitVSync(); } } }
void scene_BuildBattleScreen() { REG_BG0CNT = BG_4BPP | BG_SIZE2 | BG_PRIO(0) | 24 << BG_SBB_SHIFT | 0 << BG_CBB_SHIFT; REG_BG3CNT = BG_4BPP | BG_SIZE1 | BG_PRIO(3) | 26 << BG_SBB_SHIFT | 2 << BG_CBB_SHIFT; REG_BLDCNT = 0; DmaClear(0, MEM_VRAM, 0xFFFF); //DmaClear(0, MEM_VRAM, 0xF000); ClearOamBak(); REG_DISPCNT |= DCNT_WIN0; REG_WIN0H = 240; REG_WIN0V = 112; REG_WININ = WIN_BG3 | WIN_BG2 | WIN_BG1 | WIN_BG0 | WIN_OBJ | WIN_BLD; REG_WINOUT = 0; vwf_init(0, BG_CBB(0) | BG_SBB(24), fontWesternTiles, fontWesternWidths); vwDestination = (u32*)VWDEST_BATTLE; vwClear(1); CpuFastArrayCopy(battleinterfaceTiles,MEM_VRAM); CpuFastCopy(battleinterfacePal, MEM_PAL_BG + 0x1C0, 16); CpuFastCopy(framePal, MEM_PAL_BG + 0x1E0, 16); CpuFastCopy(frameTiles + (0x90 * MyPlayer.Options.frame),MEM_VRAM+0x240,0x120); u16* meh = (u16*)(MEM_VRAM + 0xC000); int i; for(i=0; i < 640*3; i++) meh[i] = battleinterfaceMap[i] + 0xE000; // meh[i] = grassMap[i] + 0x1000; //scene_DrawFrame(0,30,14,6); scene_SetLine(1,28,15,96,14); scene_SetLine(1,28,17,160,14); //scene_DrawFrame(0,15,34,6); scene_SetLine(1,13,35,224,14); scene_SetLine(1,13,37,288,14); //scene_DrawFrame(15,15,34,6); vwClearLine(1,9); vwClearLine(1,13); vwWriteG(16,4,strBattleFight); //vwf_set_color(TEXT_INK, 3); vwWriteG(24,4,strBattleBag); //vwNormalLUT(); vwWriteG(16,6,strBattlePokemon); vwWriteG(24,6,strBattleRun); scene_SetLine(17,6,35,240,15); scene_SetLine(24,5,35,248,15); scene_SetLine(17,6,37,304,15); if(!ThisBattle.trainer) scene_SetLine(24,5,37,312,15); //scene_DrawFrame(0,20,54,6); scene_SetLine(2,8,55,352,15); scene_SetLine(11,8,55,416,15); scene_SetLine(2,8,57,480,15); scene_SetLine(11,8,57,544,15); //scene_DrawFrame(20,10,54,6); scene_SetLine(21,8,55,368,15); scene_SetLine(21,8,57,376,15); vwWriteG(31,4,strArrow); //ThisBattle.background AGBPrintf("Supposed to copy battle background from 0x%x.\n",battlebacks[ThisBattle.background*4]); DmaCopy(battlebacks[ThisBattle.background*4], MEM_VRAM + 0x8000, 0x1000); DmaCopy(battlebacks[(ThisBattle.background*4)+1], MEM_VRAM + 0xD000, 0x1000); if(currentLevel->tileseta->flags && 1) DmaCopy(battlebacks[(ThisBattle.background*4)+2], MEM_PAL_BG, 32); else LoadTimeAdjustedColors((u16*)MEM_PAL_BG, (u16*)battlebacks[(ThisBattle.background*4)+2], 16); ThisBattle.environment = battlebacks[(ThisBattle.background*4)+3]; //DmaArrayCopy(battlegrassTiles, MEM_VRAM + 0x8000); //DmaArrayCopy(battlegrassMap, MEM_VRAM + 0xD000); //LoadTimeAdjustedColors((u16*)MEM_PAL_BG, (u16*)battlegrassPal, 16); REG_BG3HOFS = 0; REG_BG3VOFS = 0; OamBak[0].Shape = 0; OamBak[0].Size = 3; OamBak[1].Shape = 0; OamBak[1].Size = 3; // DmaArrayCopy(playerwindowPal, MEM_PAL_OBJ + 0x10a0); // DmaArrayCopy(hpbarPal, MEM_PAL_OBJ + 0x10c0); DmaArrayCopy(btlstatusTiles, MEM_VRAM_OBJ + 0x3580); DmaArrayCopy(btlstatusPal, MEM_PAL_OBJ + 0xE0); }
void videoInit() { // Blank screen for faster loading REG_DISPCNT = DCNT_BLANK; // Completely clear VRAM memset16(vid_mem, 0x0000, 49152); // BACKGROUND SETUP // // Set background 0 control register // -Render this BG on bottom // -Tile indexing starts in charblock 0 // -Screen-entry indexing starts in charblock 3 / screenblock 24 // -4 bits per pixel // -512 x 512 pixels - 32 x 32 tiles - 1 x 1 screenblocks REG_BG0CNT = BG_PRIO(3) | BG_CBB(0) | BG_SBB(24) | BG_4BPP | BG_REG_32x32; // Set background 2 control register - Bottom text screen // -Render this BG on top // -Tile indexing starts in charblock 0 // -Screen-entry indexing starts in charblock 3 / screenblock 29 // -4 bits per pixel // -256 x 256 pixels - 32 x 32 tiles - 1 x 1 screenblocks REG_BG2CNT = BG_PRIO(1) | BG_CBB(0) | BG_SBB(29) | BG_4BPP | BG_REG_32x32; // Set background 3 control register - Top Text Screen // -Render this BG on top // -Tile indexing starts in charblock 0 // -Screen-entry indexing starts in charblock 3 / screenblock 28 // -4 bits per pixel // -256 x 256 pixels - 32 x 32 tiles - 1 x 1 screenblocks REG_BG3CNT = BG_PRIO(0) | BG_CBB(0) | BG_SBB(28) | BG_4BPP | BG_REG_32x32; // Load background palette memcpy16(&pal_bg_mem[0], g_bgPal, g_bgPalLen >> 1); // Load background tiles // Load Font tiles memcpy16(&tile_mem[0][g_galaxulonFont_TilesPos], g_galaxulonFont_Tiles, g_galaxulonFont_TilesLen >> 1); // Load other BG tiles memcpy16(&tile_mem[0][g_blankBG_TilesPos], g_blankBG_Tiles, g_blankBG_TilesLen >> 1); memcpy16(&tile_mem[0][g_assertTile_TilesPos], g_assertTile_Tiles, g_assertTile_TilesLen >> 1); memcpy16(&tile_mem[0][g_demo_starsTilesPos], g_demo_starsTiles, g_demo_starsTilesLen >> 1); // Clear Background screenmaps - set the four background screenblocks memset32(&se_mem[24], 0x00000000, (SBB_SIZE/4)); // OAM SETUP // // Load OAM palette memcpy16(pal_obj_mem, g_spritePal, g_spritePalLen >> 1); // Load OAM tiles // Init Player sprite memcpy16(&tile_mem_obj[0][g_playerSpriteTilesPos], g_playerSpriteTiles, g_playerSpriteTilesLen >> 1); // Init bullet sprites memcpy16(&tile_mem_obj[0][g_bulletSpriteTilesPos], g_bulletSpriteTiles, g_bulletSpriteTilesLen >> 1); memcpy16(&tile_mem_obj[0][g_missileSpriteTilesPos], g_missileSpriteTiles, g_missileSpriteTilesLen >> 1); // Init display sprites memcpy16(&tile_mem_obj[0][g_bullet_selection1TilesPos], g_bullet_selection1Tiles, g_bullet_selection1TilesLen >> 1); memcpy16(&tile_mem_obj[0][g_bullet_selection2TilesPos], g_bullet_selection2Tiles, g_bullet_selection2TilesLen >> 1); // Init enemy sprites memcpy16(&tile_mem_obj[0][g_jellyfishTilesPos], g_jellyfishTiles, g_jellyfishTilesLen >> 1); memcpy16(&tile_mem_obj[0][g_mineTilesPos], g_mineTiles, g_mineTilesLen >> 1); memcpy16(&tile_mem_obj[0][g_sharkTilesPos], g_sharkTiles, g_sharkTilesLen >> 1); memcpy16(&tile_mem_obj[0][g_squidTilesPos], g_squidTiles, g_squidTilesLen >> 1); memcpy16(&tile_mem_obj[0][g_crabTilesPos], g_crabTiles, g_crabTilesLen >> 1); // Init upgrade sprites memcpy16(&tile_mem_obj[0][g_extraLife_TilesPos], g_extraLife_Tiles, g_extraLife_TilesLen >> 1); memcpy16(&tile_mem_obj[0][g_extraBomb_TilesPos], g_extraBomb_Tiles, g_extraBomb_TilesLen >> 1); memcpy16(&tile_mem_obj[0][g_primaryFireUp_TilesPos], g_primaryFireUp_Tiles, g_primaryFireUp_TilesLen >> 1); memcpy16(&tile_mem_obj[0][g_secondFireUp_TilesPos], g_secondFireUp_Tiles, g_secondFireUp_TilesLen >> 1); memcpy16(&tile_mem_obj[0][g_shield_TilesPos], g_shield_Tiles, g_shield_TilesLen >> 1); // Load Title screen logo memcpy16(&tile_mem_obj[0][g_galaxulon_titleTilesPos1], g_galaxulon_titleTiles, g_galaxulon_titleTilesLen >> 1); // Clear OAM oam_init(oam_mem, 128); // Setup Display Control Register // -Video mode 0 - tiled // -BG 0, BG 2, and BG 3 enabled // -Enable sprites // -1D sprite-mapping mode REG_DISPCNT = DCNT_MODE0 | DCNT_OBJ_1D | DCNT_BG0 | DCNT_BG2 | DCNT_BG3 | DCNT_OBJ; }
void BlackCredits() { int timmy; REG_DISPCNT = 0; REG_BG1CNT = BG_4BPP | BG_SIZE1 | BG_PRIO(1) | 29 << BG_SBB_SHIFT | 0 << BG_CBB_SHIFT | BG_MOSAIC; DmaArrayCopy(blackcredsTiles, MEM_VRAM + 0x0000); DmaArrayCopy(blackcredsPal, MEM_PAL_BG + 0x0000); DmaArrayCopy(blackcredsMap, MEM_VRAM + 0xE800); REG_BG1HOFS = 8; REG_BLDCNT = BLD_BLACK | BLD_BG1; REG_BLDY = 16; REG_DISPCNT = DCNT_MODE0 | DCNT_BG1; for(timmy = 16; timmy > 0; timmy--) { DoVBlank(); DoVBlank(); DoVBlank(); REG_BLDY = timmy; } //just turn it off to ensure full viz REG_BLDCNT = 0; //simple wait loop while(1) { DoVBlank(); timmy++; if(timmy == 250) break; } for(timmy=8; timmy < 256; timmy+=2) { DoVBlank(); REG_BG1HOFS=timmy; } timmy=0; while(1) { DoVBlank(); timmy++; if(timmy == 250) break; } REG_BLDCNT = BLD_BLACK | BLD_BG1; for(timmy = 0; timmy < 15; timmy++) { DoVBlank(); DoVBlank(); DoVBlank(); REG_BLDY = timmy; } REG_BG1HOFS = 0; REG_BLDCNT = 0; REG_DISPCNT = DCNT_MODE0 | DCNT_OBJ | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_BG3 | DCNT_OBJ_1D; REG_BG1CNT = BG_4BPP | BG_SIZE0 | BG_PRIO(1) | 29 << BG_SBB_SHIFT | 0 << BG_CBB_SHIFT | BG_MOSAIC; DmaClear(0, MEM_VRAM, VRAM_SIZE); //clean up crap }