static int NDS_RenderClear(SDL_Renderer *renderer) { NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; /* wait for capture unit to be ready */ while(REG_DISPCAPCNT & DCAP_ENABLE); /* 3D engine can only work on one screen at a time. */ data->is_sub = !data->is_sub; if (data->is_sub) { lcdMainOnBottom(); vramSetBankC(VRAM_C_LCD); vramSetBankD(VRAM_D_SUB_SPRITE); REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3); } else { lcdMainOnTop(); vramSetBankD(VRAM_D_LCD); vramSetBankC(VRAM_C_SUB_BG); REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3); } glBegin2D(); glClearColor(renderer->r >> 3, renderer->g >> 3, renderer->b >> 3, renderer->a >> 3); return 0; }
void updateD3D() { if (d3dScreen) { videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE); vramSetBankC(VRAM_C_SUB_BG); vramSetBankD(VRAM_D_LCD); setRegCapture(true, 0, 15, 3, 0, 3, 0, 0); d3dScreen=false; }else{ videoSetModeSub(MODE_5_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_2D_BMP_256); vramSetBankC(VRAM_C_LCD); vramSetBankD(VRAM_D_SUB_SPRITE); setRegCapture(true, 0, 15, 2, 0, 3, 0, 0); d3dScreen=true; } lcdSwap(); }
/* Finish this subScreen */ void ds_g_game_finish() { // FIRST!!! - Capture the screen on bank D (subscreen) vramSetBankD(VRAM_D_LCD); SetRegCapture(true, 0, 0, 31, 3, 1, 3, 1, 0); // Capture from C swiWaitForVBlank(); swiWaitForVBlank(); swiWaitForVBlank(); vramSetBankD(VRAM_D_MAIN_BG_0x06000000); /* Deletes certain things related to the map */ ds_map_reset(0); // Simple map reset /* Deletes the things related to the objects */ ds_objects_reset(); /* No submaps optimizations! - if they were executing */ ds_submap_endOpt(); /* Resets the state of Juni */ ds_juni_reset(); /* Dialogues are out, too */ ds_dialogue_reset(); /* Camera? No need */ /* Finally, deletes all the sprites of the screen... new screen will have new sprites */ // Remember that dialog had ONE sprite!!!! ds_3dsprite_reset(1); /* ...and the upper screen subsystem needs to be reset */ ds_gamestatus_reset(); /* Resets the music subsystem */ ds_music_reset(); // DEBUG // PA_DisableSpecialFx(1); // Reset the *HW* sprites... so the captured subscreen is shown ^_- ds_3dsprite_cleanHWSprites(); }
void Game::initVram() { videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000); videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE| DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_SUB_SPRITE); }
static void NDS_VideoQuit(_THIS) { videoSetMode(DISPLAY_SCREEN_OFF); videoSetModeSub(DISPLAY_SCREEN_OFF); vramSetBankA(VRAM_A_LCD); vramSetBankB(VRAM_B_LCD); vramSetBankC(VRAM_C_LCD); vramSetBankD(VRAM_D_LCD); vramSetBankE(VRAM_E_LCD); vramSetBankF(VRAM_F_LCD); vramSetBankG(VRAM_G_LCD); vramSetBankH(VRAM_H_LCD); vramSetBankI(VRAM_I_LCD); }
void initMemory() { // Setup video mode for Main: 3D | Text | Text | Text videoSetMode(MODE_5_3D); // Setup video mode for Sub: Text | Text | Rotation | Rotation videoSetModeSub(MODE_5_2D); //Setup Memory Banks vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_TEXTURE); // Set Main screen on bottom REG_POWERCNT &= ~POWER_SWAP_LCDS; }
int main(void) { int i; int memUsageTemp = 0xFFFFFFFF; videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_SPRITE); vramSetBankB(VRAM_B_MAIN_SPRITE); vramSetBankD(VRAM_D_SUB_SPRITE); consoleDemoInit(); // consoleDebugInit(DebugDevice_NOCASH); //send stderr to no$gba debug window //api: initialize OAM to 1D mapping with XX byte offsets and no external palette oamInit(oam, SpriteMapping_1D_128, false); //create some sprites for(i = 0; i < SPRITE_MAX; i++) randomSprite(&sprites[i]); //load a randomly colored palette for(i = 0; i < 256; i++) { SPRITE_PALETTE[i] = rand(); SPRITE_PALETTE_SUB[i] = rand(); } while(1) { moveSprites(); updateSprites(); swiWaitForVBlank(); //api: updates real oam memory oamUpdate(oam); if(oom) { memUsageTemp = memUsageTemp > spriteMemoryUsage ? spriteMemoryUsage : memUsageTemp; } consoleClear(); printf("Memory usage: %i %i%% \n", spriteMemoryUsage, 100 * spriteMemoryUsage / (spriteMemSize)); printf("Percentage fail: %i%% \n", oomCount * 100 / allocationCount); printf("Lowest Usage at fail %i %i%% \n", memUsageTemp, 100 * memUsageTemp / (spriteMemSize)); } return 0; }
void initVideo() { // initialize VRAM banks vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_SUB_SPRITE); vramSetBankE(VRAM_E_LCD); vramSetBankF(VRAM_F_LCD); vramSetBankG(VRAM_G_LCD); vramSetBankH(VRAM_H_LCD); vramSetBankI(VRAM_I_LCD); // set video modes videoSetMode(MODE_5_2D); videoSetModeSub(MODE_5_2D); }
void hasieratuBideoa() { /* Bi pantailatan irudiak erakutsi ahal izateko memoria mapeatu. */ vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000, VRAM_E_LCD); vramSetBankE(VRAM_E_MAIN_SPRITE); vramSetBankD(VRAM_D_SUB_SPRITE); /* Pantaila nagusirako bideo modua ezarri */ videoSetMode(MODE_5_2D | // 5. bideo modua ezarri DISPLAY_BG2_ACTIVE | // 2. fondoa aktibatu DISPLAY_BG3_ACTIVE); // 3. fondoa aktibatu /* 2. mailako pantaila bideo modua ezarri */ videoSetModeSub(MODE_5_2D | // 5. bideo modua ezarri DISPLAY_BG3_ACTIVE); // 3. fondoa aktibatu }
int main(void) { mmInitDefaultMem((mm_addr)soundbank_bin); //set video mode and map vram to the background videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE); //set video mode and map vram to the background videoSetModeSub(MODE_1_2D | DISPLAY_BG1_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); vramSetBankD(VRAM_D_MAIN_BG_0x06000000); vramSetBankE(VRAM_E_MAIN_SPRITE); lcdMainOnBottom(); #ifdef BBDEBUG consoleDemoInit(); #endif sound s; s.load_bank(0); sprites spr; machine m(&s); machine_view mv(&spr); #ifndef BBDEBUG thread_view tv; #endif cursor c(&m,&spr); pointer p(&spr); iprintf("%d\n",list::unit_test()); int frame=0; int x=0; int y=0; int tx=0; int ty=0; int dx=0; int dy=0; int touchedlast=0; int tempo=2; int bank=0; u8 flip=0; u8 flip_count=1; irqEnable( IRQ_VCOUNT ); while(1) { // wait until line 0 swiIntrWait( 0, IRQ_VCOUNT); u32 t=tempo; //t=t/(flip+1); //iprintf("%d\n",t); if (tempo==0 || frame%t==0) { m.run(); /* flip_count--; if (flip_count==0) { flip_count=4; if (flip) flip=0; else flip=1; }*/ } scanKeys(); frame++; touchPosition touch; touchRead(&touch); if (keysDown() & KEY_UP) m.slow_down_closest(c.get_cursor_addr()); if (keysDown() & KEY_DOWN) m.speed_up_closest(c.get_cursor_addr()); if (tempo<0) tempo=0; if (keysDown() & KEY_L) sound_check(m); if (keysDown() & KEY_LEFT) { bank--; s.load_bank(bank); } if (keysDown() & KEY_RIGHT) { bank++; s.load_bank(bank); } if(keysDown() & KEY_TOUCH) { tx=touch.px; ty=touch.py; if (!c.touch(tx,ty,&p)) { touchedlast=1; } } else if(keysHeld() & KEY_TOUCH) { if (!c.menu_shown() && !c.drag(touch.px+x,touch.py+y,(touch.px+x)/16,(touch.py+y)/16)) { if (touchedlast>0) touchedlast++; x+=tx-touch.px; y+=ty-touch.py; tx=touch.px; ty=touch.py; } } if (keysUp() & KEY_TOUCH) { if (touchedlast>0 && touchedlast<5) { int lx=(tx+x)/16; int ly=(ty+y)/16; c.set_pos(lx,ly,lx*16,ly*16); } touchedlast=0; } if (keysUp() & KEY_A) { for (u32 i=0; i<HEAP_SIZE; i++) { m.poke(i,rand()); } } c.update(x,y); if (c.menu_shown()) { dx=c.get_x()-128; dy=c.get_y()-82; if (dx!=x) x+=(dx-x)*0.1; if (dy!=y) y+=(dy-y)*0.1; } p.update(x,y,&m); REG_BG0HOFS = x; REG_BG0VOFS = y; spr.update(); mv.update(x,y,&m); s.update(); #ifndef BBDEBUG tv.update(&m); #endif BG_PALETTE_SUB[0]=13<<10; swiWaitForVBlank(); BG_PALETTE_SUB[0]=31; } return 0; }
void TunnelPartInit(void) { T_Mesh* mesh; int i; /* * Initialisation vidéo */ /* Modes video */ videoSetMode(MODE_5_3D); videoSetModeSub(MODE_5_2D); lcdMainOnBottom(); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_BG_0x06020000); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_TEXTURE_SLOT3); videoBgEnable(DISPLAY_BG0_ACTIVE | DISPLAY_BG2_ACTIVE); videoBgEnableSub(DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE); /* Le BG qui servira pour le tunnel */ TunnelBgId = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0); TunnelBgPixels = (u16*)bgGetGfxPtr(TunnelBgId); bgSetPriority(TunnelBgId, 2); /* Le tunnel en fond */ /* L'avant plan de l'éléphant */ FrontLayerId = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 8, 0); FrontLayerPixels = (u8*)bgGetGfxPtr(FrontLayerId); bgSetPriority(FrontLayerId, 0); /* En avant plan */ decompress(bouleBitmap, FrontLayerPixels, LZ77Vram); decompress(boulePal, BG_PALETTE, LZ77Vram); bgSetPriority(0, 1); /* La 3D entre les deux */ /* Initialisation de la 3D */ Init3DEngine(); TunnelFxInit(TunnelBgPixels); mesh = CreateMesh(); mesh->display_list = DiscoElephant_mesh; mesh->alpha = 31; mesh->texturing = TRUE; mesh->lighting = TRUE; DiscoElephant = CreateObj3D(mesh); Scene = CreateScene(); AddObject(Scene, DiscoElephant); Scene->lights[0] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(16, 0, 01), TRUE); Scene->lights[1] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(0, 16, 0), TRUE); Scene->lights[2] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(0, 0, 16), TRUE); Scene->lights[3] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(16, 16, 0), TRUE); glClearColor(0, 0, 0, 0); flare_tex = CreateTextureFromMemory((u8*)flareBitmap, GL_RGBA, 0, 16, 64, TRUE, LZ77Vram); for(i=0; i<4; i++) { flares[i] = malloc(sizeof(*flares[i])); } flares[0]->position[0] = 0; flares[0]->position[1] = 0; flares[0]->position[2] = floattof32(-1); flares[0]->poly_alpha = 16; flares[0]->color = RGB15(31, 0, 0); flares[0]->size = floattov16(0.15f); flares[0]->texture_id = flare_tex->id; flares[0]->poly_id = 5; flares[1]->position[0] = 0; flares[1]->position[1] = 0; flares[1]->position[2] = floattof32(-1); flares[1]->poly_alpha = 16; flares[1]->color = RGB15(0, 31, 0); flares[1]->size = floattov16(0.15f); flares[1]->texture_id = flare_tex->id; flares[1]->poly_id = 6; flares[2]->position[0] = 0; flares[2]->position[1] = 0; flares[2]->position[2] = floattof32(-1); flares[2]->poly_alpha = 16; flares[2]->color = RGB15(0, 0, 31); flares[2]->size = floattov16(0.15f); flares[2]->texture_id = flare_tex->id; flares[2]->poly_id = 6; flares[3]->position[0] = 0; flares[3]->position[1] = 0; flares[3]->position[2] = floattof32(-1); flares[3]->poly_alpha = 16; flares[3]->color = RGB15(31, 31, 0); flares[3]->size = floattov16(0.15f); flares[3]->texture_id = flare_tex->id; flares[3]->poly_id = 7; tex = CreateTextureFromMemory((u8*)DiscoElephantBitmap, GL_RGB, 0, 16, 64, TRUE, LZ77Vram); DiscoElephant->mesh->texture_id = tex->id; DiscoElephant->mesh->texturing = TRUE; /* Initialisation du fade in depuis le blanc */ REG_MASTER_BRIGHT = (1<<14); REG_MASTER_BRIGHT_SUB = REG_MASTER_BRIGHT; StartFlash(-1000); // pour éviter un flash à la première seconde glMaterialf(GL_AMBIENT, RGB15(16,16,16)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(31,31,31)); glMaterialShinyness(); }
//------------------------------------------------------- int main() { //------------------------------------------------------- videoSetMode(MODE_0_3D); videoSetModeSub(MODE_5_2D); glInit(); // sub sprites hold the bottom image when 3D directed to top initSubSprites(); // sub background holds the top image when 3D directed to bottom bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); //------------------------------------------------------- // Setup gl //------------------------------------------------------- glEnable(GL_ANTIALIAS); glClearColor(0,0,0,31); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0,0,255,191); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); //------------------------------------------------------- // main loop //------------------------------------------------------- bool top = true; while (true) { // wait for capture unit to be ready while(REG_DISPCAPCNT & DCAP_ENABLE); scanKeys(); int keys = keysDown(); if (keys & KEY_START) break; //------------------------------------------------------- // Switch render targets //------------------------------------------------------- top = !top; if(top) { lcdMainOnBottom(); vramSetBankC(VRAM_C_LCD); vramSetBankD(VRAM_D_SUB_SPRITE); REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3); } else { lcdMainOnTop(); vramSetBankD(VRAM_D_LCD); vramSetBankC(VRAM_C_SUB_BG); REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3); } //------------------------------------------------------- // Render the scene //------------------------------------------------------- glMatrixMode(GL_MODELVIEW); renderScene(top); glFlush(0); } return 0; }
int main(int argc, char** argv) { //three sprites of differing color format MySprite sprites[] = { {0, SpriteSize_32x32, SpriteColorFormat_Bmp, 0, 15, 20, 15}, {0, SpriteSize_32x32, SpriteColorFormat_256Color, -1, 0, 20, 80}, {0, SpriteSize_32x32, SpriteColorFormat_16Color, -1, 1, 20, 136} }; videoSetModeSub(MODE_0_2D); consoleDemoInit(); //initialize the sub sprite engine with 1D mapping 128 byte boundary //and no external palette support oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false); vramSetBankD(VRAM_D_SUB_SPRITE); //allocate some space for the sprite graphics for(int i = 0; i < 3; i++) sprites[i].gfx = oamAllocateGfx(&oamSub, sprites[i].size, sprites[i].format); //ugly positional printf iprintf("\x1b[1;1HDirect Bitmap:"); iprintf("\x1b[9;1H256 color:"); iprintf("\x1b[16;1H16 color:"); //fill bmp sprite with the color red dmaFillHalfWords(ARGB16(1,31,0,0), sprites[0].gfx, 32*32*2); //fill the 256 color sprite with index 1 (2 pixels at a time) dmaFillHalfWords((1<<8)|1, sprites[1].gfx, 32*32); //fill the 16 color sprite with index 1 (4 pixels at a time) dmaFillHalfWords((1<<12)|(1<<8)|(1<<4)|1, sprites[2].gfx, 32*32 / 2); //set index 1 to blue...this will be the 256 color sprite SPRITE_PALETTE_SUB[1] = RGB15(0,31,0); //set index 17 to green...this will be the 16 color sprite SPRITE_PALETTE_SUB[16 + 1] = RGB15(0,0,31); int angle = 0; while(1) { for(int i = 0; i < 3; i++) { oamSet( &oamSub, //sub display i, //oam entry to set sprites[i].x, sprites[i].y, //position 0, //priority sprites[i].paletteAlpha, //palette for 16 color sprite or alpha for bmp sprite sprites[i].size, sprites[i].format, sprites[i].gfx, sprites[i].rotationIndex, true, //double the size of rotated sprites false, //don't hide the sprite false, false, //vflip, hflip false //apply mosaic ); } oamRotateScale(&oamSub, 0, angle, (1 << 8), (1<<8)); angle += 64; swiWaitForVBlank(); //send the updates to the hardware oamUpdate(&oamSub); } return 0; }