void Display::modeSelektor(){ //Displaying bg3, and mode sprites bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(subbg3); s8 i; for (i = 0; i < 4; ++i){ modesSprite->display(64 + i, 32 + 128 * (i % 2), 16 + 96 * (i / 2), OBJPRIORITY_0, i); } oamUpdate(&oamSub); input->paused = true; while(!(Cfg::modeSelector && input->pad->select() == DOWN) && input->modeSelektor() != 1){ swiWaitForVBlank(); } Cfg::modeSelector = false; oamClear(&oamSub, 64, 4); if (Cfg::mode == SLIDERS){ dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(this->subbg3), slidersBg3SubTilesLen); dmaCopy(this->slidersBg3Map, bgGetMapPtr(this->subbg3), 1536); } else { bgSetPriority(this->subbg3, 2); bgHide(this->subbg3); } }
//------------------------------------------------------- // set up a 2D layer construced of bitmap sprites // this holds the image when rendering to the top screen //------------------------------------------------------- void initSubSprites(void){ //------------------------------------------------------- oamInit(&oamSub, SpriteMapping_Bmp_2D_256, false); int x = 0; int y = 0; int id = 0; //set up a 4x3 grid of 64x64 sprites to cover the screen for(y = 0; y < 3; y++) for(x = 0; x < 4; x++) { /* u16 *offset = &SPRITE_GFX_SUB[(x * 64) + (y * 64 * 256)]; oamSet(&oamSub, x + y * 4, x * 64, y * 64, 0, 15, SpriteSize_64x64, SpriteColorFormat_Bmp, offset, -1, false,false,false,false,false); */ oamSub.oamMemory[id].attribute[0] = ATTR0_BMP | ATTR0_SQUARE | (64 * y); oamSub.oamMemory[id].attribute[1] = ATTR1_SIZE_64 | (64 * x); oamSub.oamMemory[id].attribute[2] = ATTR2_ALPHA(1) | (8 * 32 * y) | (8 * x); id++; } swiWaitForVBlank(); oamUpdate(&oamSub); }
// DISPLAY UPDATE FUNCTION //------------------------------------------------------------------------- void Display::update(){ consoleSelect(&mainConsole); iprintf("\e[37m\x1b[1;20H%4d.%1d.%1d", midi->bars, midi->beats, midi->quarters); consoleSelect(&subConsole); tempoLeds(); switch (Cfg::mode){ case KAOSS: if (Cfg::previousMode != KAOSS){ Cfg::previousMode = KAOSS; kaoss(); } if (!input->paused) kaossUpdate(); break; case PADS: if (Cfg::previousMode != PADS){ Cfg::previousMode = PADS; pads(); } padsUpdate(); break; case MIXER: if (Cfg::previousMode != MIXER){ Cfg::previousMode = MIXER; mixer(); } mixerUpdate(); break; case SLIDERS: if (Cfg::previousMode != SLIDERS){ Cfg::previousMode = SLIDERS; sliders(); } slidersUpdate(); break; } for (u8 c = 0; c < 16; ++c){ for (u8 v = 0; v < 128; ++v) Cfg::ccChangedVblank[c][v] = false; } oamUpdate(&oamSub); oamUpdate(&oamMain); ++frame; }
void iconTitleInit (void) { // initialize video mode videoSetMode(MODE_4_2D); // initialize VRAM banks vramSetPrimaryBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_LCD, VRAM_D_LCD); // initialize bg2 as a rotation background and bg3 as a bmp background // http://mtheall.com/vram.html#T2=3&RNT2=96&MB2=3&TB2=0&S2=2&T3=6&MB3=1&S3=1 bg2 = bgInit(2, BgType_Rotation, BgSize_R_512x512, 3, 0); bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 1, 0); // initialize rotate, scale, and scroll bgSetRotateScale(bg3, 0, 1<<8, 1<<8); bgSetScroll(bg3, 0, 0); bgSetRotateScale(bg2, 0, 8*(1<<8)/6, 1<<8); bgSetScroll(bg2, -TITLE_POS_X, -TITLE_POS_Y); // clear bg2's map: 512x512 pixels is 64x64 tiles is 4KB dmaFillHalfWords(0, bgGetMapPtr(bg2), 4096); // load compressed font into bg2's tile data decompress(font6x8Tiles, bgGetGfxPtr(bg2), LZ77Vram); // load compressed bitmap into bg3 decompress(hbmenu_bannerBitmap, bgGetGfxPtr(bg3), LZ77Vram); // load font palette dmaCopy(font6x8Pal, BG_PALETTE, font6x8PalLen); // apply the bg changes bgUpdate(); // initialize OAM oamInit(&oamMain, SpriteMapping_1D_128, false); sprite = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_16Color); dmaFillHalfWords(0, sprite, sizeof(banner.icon)); oamSet(&oamMain, 0, ICON_POS_X, ICON_POS_Y, 0, 0, SpriteSize_32x32, SpriteColorFormat_16Color, sprite, -1, 0, 0, 0, 0, 0); // oam can only be updated during vblank swiWaitForVBlank(); oamUpdate(&oamMain); // everything's ready :) writeRow (0,"...initializing..."); writeRow (1,"===>>> HBMenu+ <<<==="); writeRow (2,"(this text should disappear..."); writeRow (3,"...otherwise, trouble!)"); }
void Display::editKaossParams(){ CCParam* ccParam = NULL; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<3; ++i){ if (i == 0){ echo(0, RED, 5, 7 + 8*(i%8), "X"); ccParam = &Cfg::kaoss.x[Cfg::kaoss.bank]; } if (i == 1){ echo(0, RED, 5, 7 + 8*(i%8), "Y"); ccParam = &Cfg::kaoss.y[Cfg::kaoss.bank]; } if (i == 2){ echo(0, RED, 5, 7 + 8*(i%8), "Z"); ccParam = &Cfg::kaoss.z[Cfg::kaoss.bank]; } echo(0, WHITE, 8, 7 + 8*(i%8), "CC"); paramsEditSprite->display(16+i, 56 + 64*(i%8), 72, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 10, 6 + 8*(i%8), (*ccParam).cc); paramsEditSprite->display(32+i, 56 + 64*(i%8), 88, OBJPRIORITY_0, 1); echo(0, WHITE, 13, 7 + 8*(i%8), "CH"); paramsEditSprite->display(48+i, 56 + 64*(i%8), 112, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 15, 6 + 8*(i%8), 1 + (*ccParam).channel); paramsEditSprite->display(64+i, 56 + 64*(i%8), 128, OBJPRIORITY_0, 1); } oamUpdate(&oamSub); input->editKaossParams(); Cfg::editParams = true; swiWaitForVBlank(); } Cfg::editParams = false; save->write(); oamClear(&oamSub, 16, 80); consoleClear(); if (Cfg::mode == SLIDERS){ dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(this->subbg3), slidersBg3SubTilesLen); dmaCopy(slidersBg3Map, bgGetMapPtr(this->subbg3), 1536); } else { bgSetPriority(this->subbg3, 2); bgHide(this->subbg3); } }
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 Display::editMixerParams(){ CCParam ccParam; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); echo(0, RED, 0, 13, "MIXER"); echo(0, RED, 12, 13, "MUTES"); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<8; ++i){ ccParam = Cfg::mixer.ccs[i]; echo(0, WHITE, 2, 1 + 4*(i%8), "CC"); paramsEditSprite->display(16+i, 8 + 32*(i%8), 24, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 4, 4*(i%8), ccParam.cc); paramsEditSprite->display(32+i, 8 + 32*(i%8), 40, OBJPRIORITY_0, 1); echo(0, WHITE, 6, 1 + 4*(i%8), "CH"); paramsEditSprite->display(48+i, 8 + 32*(i%8), 56, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 8, 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(64+i, 8 + 32*(i%8), 72, OBJPRIORITY_0, 1); ccParam = Cfg::mixer.mutes[i]; echo(0, WHITE, 14, 1 + 4*(i%8), "CC"); paramsEditSprite->display(24+i, 8 + 32*(i%8), 120, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 16, 4*(i%8), ccParam.cc); paramsEditSprite->display(40+i, 8 + 32*(i%8), 136, OBJPRIORITY_0, 1); echo(0, WHITE, 18, 1 + 4*(i%8), "CH"); paramsEditSprite->display(56+i, 8 + 32*(i%8), 152, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 20, 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(72+i, 8 + 32*(i%8), 168, OBJPRIORITY_0, 1); } oamUpdate(&oamSub); input->editMixerParams(); Cfg::editParams = true; swiWaitForVBlank(); } save->write(); Cfg::editParams = false; oamClear(&oamSub, 16, 80); consoleClear(); }
void gamestate::battleAction() { // applies Gravity to all objects (moves them) for(u8 i = 0; i < players_count; i += 1) { players[i].applyGravity(); } bombs[0].applyGravity(); //landscape1.dropLandscape(); swiWaitForVBlank(); // Wait for a good time to put stuff in OAM // Put objects in OAM for(u8 i = 0; i < players_count; i += 1) { players[i].updateOAM(); } bombs[0].updateOAM(); oamUpdate(&oamMain); // Updates the Landscape and Background DC_FlushRange(landscape1.Bitmap, BG_BITMAP_LEN); dmaCopy(landscape1.Bitmap, bgGetGfxPtr(bg[2]), BG_BITMAP_LEN); }
void EzabatuBeltza(int indizea, int x, int y) { oamSet(&oamMain, indizea, x, y, 0, 0, SpriteSize_16x16, SpriteColorFormat_256Color, gfx_beltza, -1, false, true, false, false, false ); oamUpdate(&oamMain); }
void Display::editSliderParams(){ CCParam ccParam; u8 color; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<16; ++i){ ccParam = Cfg::sliders.ccs[Cfg::sliders.bank][i]; color = Cfg::sliders.colors[Cfg::sliders.bank][i]; echo(0, WHITE, 12*(i/8) , 1 + 4*(i%8), "CC"); paramsEditSprite->display(16+i, 8 + 32*(i%8), 8 + 96*(i/8), OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 2 + 12*(i/8) , 4*(i%8), ccParam.cc); paramsEditSprite->display(32+i, 8 + 32*(i%8), 24 + 96*(i/8), OBJPRIORITY_0, 1); echo(0, WHITE, 4+12*(i/8) , 1 + 4*(i%8), "CH"); paramsEditSprite->display(48+i, 8 + 32*(i%8), 40 + 96*(i/8), OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 6 + 12*(i/8) , 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(64+i, 8 + 32*(i%8), 56 + 96*(i/8), OBJPRIORITY_0, 1); paramsEditSprite->display(80+i, 8 + 32*(i%8), 72 + 96*(i/8), OBJPRIORITY_0, color + 2); } oamUpdate(&oamSub); input->editSliderParams(); Cfg::editParams = true; swiWaitForVBlank(); } save->write(); Cfg::editParams = false; oamClear(&oamSub, 16, 80); consoleClear(); sliders(); }
/* Set up a 2D layer construced of bitmap sprites. This holds the * image when rendering to the top screen. From libnds example. */ static void initSubSprites(void) { oamInit(&oamSub, SpriteMapping_Bmp_2D_256, false); int x = 0; int y = 0; int id = 0; //set up a 4x3 grid of 64x64 sprites to cover the screen for(y = 0; y < 3; y++) for(x = 0; x < 4; x++) { oamSub.oamMemory[id].attribute[0] = ATTR0_BMP | ATTR0_SQUARE | (64 * y); oamSub.oamMemory[id].attribute[1] = ATTR1_SIZE_64 | (64 * x); oamSub.oamMemory[id].attribute[2] = ATTR2_ALPHA(1) | (8 * 32 * y) | (8 * x); id++; } swiWaitForVBlank(); oamUpdate(&oamSub); }
int main(int argc, char **argv) { // Pantalla de espera inicializando NitroFS NF_Set2D(0, 0); NF_Set2D(1, 0); consoleDemoInit(); iprintf("\n NitroFS init. Please wait.\n\n"); iprintf(" Iniciando NitroFS,\n por favor, espere.\n\n"); swiWaitForVBlank(); // Define el ROOT e inicializa el sistema de archivos NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS // Inicializa el motor 2D NF_Set2D(0, 0); // Modo 2D_0 en la pantalla superior // Inicializa los fondos tileados NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior // Inicializa los Sprites NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior // Inicializa los buffers de mapas de colisiones NF_InitCmapBuffers(); // Carga los archivos de fondo NF_LoadTiledBg("bg/pdemo_bg", "bg3", 256, 256); // Carga el fondo para la capa 3, pantalla superior // Carga los archivos de sprites NF_LoadSpriteGfx("sprite/whiteball", 0, 16, 16); // Pelota NF_LoadSpritePal("sprite/whitepal", 0); // Carga el fondo de colisiones NF_LoadColisionBg("maps/pdemo_colmap", 0, 256, 256); // Crea los fondos de la pantalla superior NF_CreateTiledBg(0, 3, "bg3"); // Transfiere a la VRAM los sprites necesarios NF_VramSpriteGfx(0, 0, 0, true); // Puntero NF_VramSpritePal(0, 0, 0); // Variables de uso genereal u8 b = 0; u8 n = 0; // Crea el Sprite del puntero en la pantalla inferior for (b = 0; b < 3; b ++) { NF_CreateSprite(0, b, 0, 0, -16, -16); // Crea el puntero en la pantalla inferior NF_SpriteLayer(0, b, 3); // Y la capa sobre la que se dibujara } // Variables para el control de movimiento s16 x[3]; s16 y[3]; x[0] = 32; y[0] = -16; x[1] = 228; y[1] = 32; x[2] = 10; y[2] = 100; // Variables de control de colisiones, define todos los puntos de colision del sprite por debajo s16 py[16]; py[0] = 11; py[1] = 13; py[2] = 14; py[3] = 15; py[4] = 15; py[5] = 16; py[6] = 16; py[7] = 16; py[8] = 16; py[9] = 16; py[10] = 16; py[11] = 15; py[12] = 15; py[13] = 14; py[14] = 13; py[15] = 11; // Control de movimiento bool down = false; bool left = false; bool right = false; // Bucle (repite para siempre) while(1) { // Borra la pantalal de texto consoleClear(); // Bola a bola for (b = 0; b < 3; b ++) { // Control de colisiones, caida down = true; // Flag de descenso arriba // Busca pixel por pixel, si hay colisiones (pixel azul, nº4) for (n = 0; n < 16; n ++) { if (NF_GetPoint(0, (x[b] + n), (y[b] + py[n])) == 4) down = false; } // Control de colisiones, decide derecha o izquierda right = true; // Flag de movimiento lateral arriba left = true; // Caida a izquierda if (NF_GetPoint(0, (x[b] - 1), (y[b] + 16)) == 4) left = false; // Caida a derecha if (NF_GetPoint(0, (x[b] + 16), (y[b] + 16)) == 4) right = false; // Si hay caida libre, no te muevas en horizontal if (left && right) { right = false; left = false; } // Si es necesario, caida libre if (down) y[b] ++; // Muevete a la derecha if (right) x[b] ++; // Muevete a la izquierda if (left) x[b] --; // Recoloca la pelota si sale de los limites de pantalla if (y[b] > 192) { x[b] = 32; y[b] = -16; } // Posicion del Sprite NF_MoveSprite(0, b, x[b], y[b]); // Imprime la posicion de la pelota printf("x:%03d y:%03d\n", x[b], y[b]); } NF_SpriteOamSet(0); // Actualiza el Array del OAM swiWaitForVBlank(); // Espera al sincronismo vertical oamUpdate(&oamMain); // Actualiza a VRAM el OAM Secundario } return 0; }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; int angle = 0; videoSetMode(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_SPRITE); oamInit(&oamMain, SpriteMapping_1D_32, false); u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color); /* This is where we load the image. * In this case we're doing a really simple striped pattern, * but we could also load a bitmap. */ for(i = 0; i < 32 * 32 / 2; i++) { //gfx[i] = 1 | (1 << 8); gfx[i] = 0x201; // alternating red and yellow } SPRITE_PALETTE[1] = RGB15(31,0,0); // full red SPRITE_PALETTE[2] = RGB15(28,28,0); // bright yellow while(1) { scanKeys(); /* Slow down the rotate if the left trigger is pressed * I'd like to do a fixed-point here, but I don't know how */ float inc = (keysHeld() & KEY_L)? 0.05 : 0.3; if(keysHeld() & KEY_LEFT) angle += degreesToAngle(inc); if(keysHeld() & KEY_RIGHT) angle -= degreesToAngle(inc); //------------------------------------------------------------------------- // Set the first rotation/scale matrix // // There are 32 rotation/scale matricies that can store sprite rotations // Any number of sprites can share a sprite rotation matrix or each sprite // (up to 32) can utilize a seperate rotation. Because this sprite is doubled // in size we have to adjust its position by subtracting half of its height and // width (20 - 16, 20 - 16, ) //------------------------------------------------------------------------- oamRotateScale(&oamMain, 0, angle, intToFixed(1, 8), intToFixed(1, 8)); oamSet(&oamMain, //main graphics engine context 0, //oam index (0 to 127) 20 - 16, 20 - 16, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index true, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); //------------------------------------------------------------------------- // Because the sprite below has size double set to false it can never be larger than // 32x32 causing it to clip as it rotates. //------------------------------------------------------------------------- oamSet(&oamMain, //main graphics engine context 1, //oam index (0 to 127) 204, 20, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); swiWaitForVBlank(); oamUpdate(&oamMain); } return 0; }
int hwMainFunc(void* userData) { CGrf* bootSplash = new CGrf(); if (!bootSplash) return ERR_NOMEM; if (!bootSplash->Load(GUI_ASSET_DIR "/bootsplash.grf")) { delete bootSplash; return ERR_NOLOAD; } setBrightness(3, -16); videoSetMode(MODE_3_2D); int bg = bgInit(2, BgType_Text8bpp, BgSize_T_256x256, 0, 1); dmaCopy(bootSplash->gfxData, bgGetGfxPtr(bg), MemChunk_GetSize(bootSplash->gfxData)); dmaCopy(bootSplash->mapData, bgGetMapPtr(bg), MemChunk_GetSize(bootSplash->mapData)); dmaCopy(bootSplash->palData, BG_PALETTE, MemChunk_GetSize(bootSplash->palData)); delete bootSplash; LoadApps(); if (!g_appCount) return ERR_NOAPPS; LoadFileTypes(); if (!(background.Load(GUI_ASSET_DIR "/background.grf") && dummy.Load(GUI_ASSET_DIR "/dummy.grf") && selection.Load(GUI_ASSET_DIR "/selection.grf") && topscr.Load(GUI_ASSET_DIR "/topscr.grf") && defappicon.Load(GUI_ASSET_DIR "/dummyapp.grf") && fiGenericFile.Load(GUI_ASSET_DIR "/genericfile.grf") && fiConflictFile.Load(GUI_ASSET_DIR "/conflictfile.grf") && font.Load("tahoma", 10))) return ERR_NOLOAD; for (int q = 0; q < 92; q ++) { if (q < 16) setBrightness(3, q-16); if (q >= (92-16-1)) setBrightness(3, q-(92-16-1)); if (keysDown()) break; swiWaitForVBlank(); scanKeys(); } setBrightness(3, 0); swiWaitForVBlank(); DSVideoReset(); videoInit(); EnableGuiMon(); for (;;) { swiWaitForVBlank(); scanKeys(); oamUpdate(&oamMain); oamUpdate(&oamSub); bgUpdate(); if (g_curApp) RunAppVBlank(); else if (!MainVBlank()) break; RunBgProcess(); } DisableGuiMon(); return 0; }
void Display::pre_connect(){ if (Midi::msTicks%500 == 0) dotSprite->display(0, 96,80, 3, ((Midi::msTicks%1500)/500)%3); oamUpdate(&oamMain); }
void splashScreen::renderSub() { oamUpdate(&oamSub); }
//renders void splashScreen::renderMain() { oamUpdate(&oamMain); }
void updateVideo(void) { oamUpdate(states(SUB_SCREEN)); bgUpdate(); }
int main(int argc, char **argv) { // Pantalla de espera inicializando NitroFS NF_Set2D(0, 0); NF_Set2D(1, 0); consoleDemoInit(); iprintf("\n NitroFS init. Please wait.\n\n"); iprintf(" Iniciando NitroFS,\n por favor, espere.\n\n"); swiWaitForVBlank(); // Define el ROOT e inicializa el sistema de archivos NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS // Inicializa el motor 2D NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas NF_Set2D(1, 0); // Inicializa los Sprites NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior // Carga los archivos de sprites desde la FAT / NitroFS a la RAM NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); NF_LoadSpritePal("sprite/bola", 1); // Transfiere a la VRAM los sprites necesarios NF_VramSpriteGfx(0, 1, 0, true); NF_VramSpritePal(0, 1, 0); // Crea las bolas en la pantalla superior s16 bola_x = 20; s16 bola_y = 20; s8 bola_spx = 3; s8 bola_spy = 3; NF_CreateSprite(0, 0, 0, 0, bola_x, bola_y); // Bucle (repite para siempre) while(1) { // Mueve las bolas bola_x += bola_spx; if ((bola_x < 0) || (bola_x > 223)) bola_spx *= -1; bola_y += bola_spy; if ((bola_y < 0) || (bola_y > 159)) bola_spy *= -1; NF_MoveSprite(0, 0, bola_x, bola_y); // Actualiza el array de OAM NF_SpriteOamSet(0); swiWaitForVBlank(); // Espera al sincronismo vertical // Actualiza el OAM oamUpdate(&oamMain); } return 0; }
int main() { touchPosition touch; PrintConsole mainScreen; mySprite sprites[128]; lcdMainOnBottom(); initVideo(); initBackgrounds(); initConsole(&mainScreen); initSprites(sprites); //leftButtonOff oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false); //rightButtonOff oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false); int keys = keysDown(); int currentSprite = 4; int moveLeft = 0; int moveRight = 0; int MOVE_SPEED = 21; while (true) { //consoleClear(); scanKeys(); touchRead(&touch); keys = keysHeld(); if (keys) { if (keys & KEY_TOUCH) { touchRead(&touch); if (within(&touch, sprites[0])) { // leftButton clicked // leftButtonOn oamClearSprite(&oamMain, 0); oamSet(&oamMain, sprites[1].id, sprites[1].x, sprites[1].y, 0, 1, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[1].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); moveLeft = 1; } else if (within(&touch, sprites[2])) { // rightButton clicked // rightButtonOn oamClearSprite(&oamMain, 2); oamSet(&oamMain, sprites[3].id, sprites[3].x, sprites[3].y, 0, 1, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[3].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); moveRight = 1; } else if(within(&touch, sprites[currentSprite])) { mmEffectEx(&sprites[currentSprite].sfx); } } } else { //leftButtonOff oamClearSprite(&oamMain, 1); oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false); //rightButtonOff oamClearSprite(&oamMain, 3); oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false); if (moveLeft) { if ((currentSprite - 1) >= 4) { // move current sprite to the right and new one in from left int x1 = sprites[currentSprite].x; int x2 = -64; while (x1 < 280 || x2 < 96) { oamSet(&oamMain, sprites[currentSprite].id, x1, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, -1, false, false, false, false, false); oamSet(&oamMain, sprites[currentSprite-1].id, x2, sprites[currentSprite-1].y, 0, sprites[currentSprite-1].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite-1].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); x1 += MOVE_SPEED; x2 += MOVE_SPEED; } currentSprite--; } moveLeft = 0; } else if (moveRight) { if ((currentSprite + 1) - SPRITECOUNT < 0) { // move current sprite to the left and new one from right int x1 = sprites[currentSprite].x; int x2 = 256; while (x1 > -80 || x2 > 96) { oamSet(&oamMain, sprites[currentSprite].id, x1, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, -1, false, false, false, false, false); oamSet(&oamMain, sprites[currentSprite+1].id, x2, sprites[currentSprite+1].y, 0, sprites[currentSprite+1].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite+1].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); x1 -= MOVE_SPEED; x2 -= MOVE_SPEED; } currentSprite++; } moveRight = 0; } } //oamSet(oam, id, x, y, priority, palette_alpha, size, colorformat, gfxOffset, affineIndex, //sizedouble, hide, hflip, vflip, mosaic); // //gong consoleClear(); printf("\x1b[3;3H%s", sprites[currentSprite].desc); oamSet(&oamMain, sprites[currentSprite].id, sprites[currentSprite].x, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, -1, false, false, false, false, false); swiWaitForVBlank(); oamUpdate(&oamMain); } }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; videoSetMode(MODE_0_2D); videoSetModeSub(0); // not using subscreen lcdMainOnBottom(); //initialize the sprite engine with 1D mapping 128 byte boundary //and no external palette support oamInit(&oamMain, SpriteMapping_1D_32, false); vramSetBankA(VRAM_A_MAIN_SPRITE); for (i = 0; i < 5; i++) { //allocate some space for the sprite graphics sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format); //fill each sprite with a different index (2 pixels at a time) dmaFillHalfWords( ((i+1)<<8)|(i+1), sprites[i].gfx, 32*32); } //set indexes to different colours SPRITE_PALETTE[1] = RGB15(31,0,0); SPRITE_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3] = RGB15(0,0,31); SPRITE_PALETTE[4] = RGB15(31,0,31); SPRITE_PALETTE[5] = RGB15(0,31,31); // initialise maxmod using default settings, and enable interface for soundbank that is loaded into memory mmInitDefaultMem( (mm_addr)mmsolution_bin ); // setup maxmod to use the song event handler mmSetEventHandler( myEventHandler ); // load song // values for this function are in the solution header mmLoad( MOD_EXAMPLE2 ); // start song playing mmStart( MOD_EXAMPLE2, MM_PLAY_LOOP ); while(1) { for (i=0; i < 5; i++) { // constantly increase the sprite's y velocity sprites[i].dy += 1; // update the sprite's y position with its y velocity sprites[i].y += sprites[i].dy; // clamp the sprite's y position if ( sprites[i].y<72 ) sprites[i].y = 72; if ( sprites[i].y>96 ) sprites[i].y = 96; oamSet( &oamMain, //main graphics engine context i, //oam index (0 to 127) sprites[i].x, //x and y pixel location of the sprite sprites[i].y, 0, //priority, lower renders last (on top) sprites[i].paletteAlpha, //palette index sprites[i].size, sprites[i].format, sprites[i].gfx, //pointer to the loaded graphics sprites[i].rotationIndex, //sprite rotation data false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); } swiWaitForVBlank(); //send the updates to the hardware oamUpdate(&oamMain); } return 0; }
//update this function first it's the ugliest and most unwieldly //maybe add bsprite param? void blu_impl::GFX_BltSpr(bluSprite* bsp){ oamSet(&oamMain,bsp->id,bsp->x,bsp->y,bsp->priority,0,bsp->sz,bsp->sfmt,bsp->gfx,0,false,false,false,false,false); oamUpdate(&oamMain); }
void Aim::draw() { oamUpdate(&oamMain); }
void Statue::draw() { dmaCopy(statueTiles + counter*STATUE_TILE_SIZE, oamGetGfxPtr(&oamMain, STATUE_TILE), STATUE_TILE_SIZE); oamUpdate(&oamMain); }
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; }