void delete_sprite(sprite_t *s) { oam_init(s->obj, 1); s->obj = NULL; if ((active_objs / 2) < MIN_OBJS) { return; } for (int i = active_objs / 2; i < active_objs; i++) { if (OBJ_VISIBLE(obj_buffer[i])) { return; } } oam_init(&obj_buffer[active_objs / 2], active_objs - (active_objs / 2)); active_objs /= 2; }
int main(void) { memcpy(&tile_mem[4][0], blobLargeTiles, blobLargeTilesLen); memcpy(pal_obj_mem, blobLargePal, blobLargePalLen); oam_init(obj_buffer, 128); REG_DISPCNT = DCNT_OBJ | DCNT_OBJ_1D; OBJ_ATTR * blob = &obj_buffer[0]; u32 blobTileIndex = 0; u32 blobPalBank = 0; //two different ways of setting OAM values: by hand and using TONC macros blob->attr0 = (blob->attr0 & ~ATTR0_SHAPE_MASK) | ATTR0_SQUARE; blob->attr1 = (blob->attr1 & ~ATTR1_SIZE_MASK) | ATTR1_SIZE_64; blob->attr2 = (blob->attr2 & ~ATTR2_ID_MASK) | (blobTileIndex << ATTR2_ID_SHIFT); blob->attr2 = (blob->attr2 & ~ATTR2_PALBANK_MASK) | (blobPalBank << ATTR2_PALBANK_SHIFT); /* BFN_SET2(blob->attr0, ATTR0_SQUARE, ATTR0_SHAPE); BFN_SET2(blob->attr1, ATTR1_SIZE_64, ATTR1_SIZE); BFN_SET(blob->attr2, blobTileIndex, ATTR2_ID); BFN_SET(blob->attr2, blobPalBank, ATTR2_PALBANK); */ while (1) { vid_vsync(); obj_unhide(blob, 0); oam_copy(oam_mem, obj_buffer, 1); } }
void init_hare() { oam_init(); dma_memcpy(&tl_mem[TB_OBJ][0], hareData, hareLen/4); oi_set_attr(oi_face, OI_A0_AFF_FLAG | OI_A0_PAL256 | OI_A0_SIZE2X, // Square Aff-sprite OI_A1_SIZE_64 | oi_aff2oam(0), // 64x64, using obj_aff[0] 0); // pal256, tile 0 oi_set_pos(oi_face, 120-hareWidth, 80-hareHeight); oa_identity(&oa_buffer[0]); dma_memcpy(pal_obj_mem, harePal, harePalLen/4); rotate_hare(0, 0x1000); oam_update(0, 3); }
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); }
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 init_sprites() { oam_init(obj_buffer, 128); }