void init_backgrounds() { int main_bg2 = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0); bgSetPriority(main_bg2, BG_PRIORITY(1)); int main_bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 6, 0); bgSetPriority(main_bg3, BG_PRIORITY(0)); consoleInit(&top_screen, 0, BgType_Text4bpp, BgSize_T_256x256, 31, 0, 0, 1); consoleSelect(&top_screen); consoleClear(); puts("Made by Lennart Kroes, s1062295"); }
void advMultipleLayers(void) { videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG); //initialize the backgrounds int bg1 = bgInit(0, BgType_Text8bpp, BgSize_ER_256x256, 0,1); int bg2 = bgInit(1, BgType_Text8bpp, BgSize_ER_256x256, 1,1); int bg3 = bgInit(2, BgType_ExRotation, BgSize_ER_256x256, 2,1); //make sure the floor is on the bottom (by default hardware layer 0 will be rendered last) bgSetPriority(bg1, 3); bgSetPriority(bg2, 2); bgSetPriority(bg3, 1); //they all share tiles and a palette dmaCopy(MultilayerTiles, bgGetGfxPtr(bg1), sizeof(MultilayerTiles)); dmaCopy(MultilayerPal, BG_PALETTE, sizeof(MultilayerPal)); //all we need to do is copy in the maps dmaCopy(Layer_1Map, bgGetMapPtr(bg1), Layer_1MapLen); dmaCopy(Layer_2Map, bgGetMapPtr(bg2), Layer_2MapLen); dmaCopy(Layer_3Map, bgGetMapPtr(bg3), Layer_3MapLen); int keys = 0; bool bg1_hidden = false; bool bg2_hidden = false; bool bg3_hidden = false; while(!(keys & KEY_B)) { scanKeys(); keys = keysDown(); if(keys & KEY_UP) bg1_hidden = !bg1_hidden; if(keys & KEY_DOWN) bg2_hidden = !bg2_hidden; if(keys & KEY_LEFT) bg3_hidden = !bg3_hidden; swiWaitForVBlank(); bg1_hidden ? bgHide(bg1) : bgShow(bg1); bg2_hidden ? bgHide(bg2) : bgShow(bg2); bg3_hidden ? bgHide(bg3) : bgShow(bg3); consoleClear(); iprintf("Press UP DOWN LEFT to toggle the layers\n\n"); iprintf("Floor (UP): %s\n", bg1_hidden ? "hidden" : "displayed"); iprintf("Walls (DOWN): %s\n", bg2_hidden ? "hidden" : "displayed"); iprintf("Decorations (LEFT): %s\n", bg3_hidden ? "hidden" : "displayed"); } }
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 videoInit() { videoSetModeSub(MODE_0_2D); oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false); int bgId = bgInitSub(3, BgType_Text8bpp, BgSize_T_256x256, 0, 1); bgSetPriority(bgId, 3); dmaCopy(background.gfxData, bgGetGfxPtr(bgId), MemChunk_GetSize(background.gfxData)); dmaCopy(background.mapData, bgGetMapPtr(bgId), MemChunk_GetSize(background.mapData)); dmaCopy(background.palData, BG_PALETTE_SUB, MemChunk_GetSize(background.palData)); videoSetMode(MODE_3_2D); int bgBmp = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 2, 0); bmpBuf = bgGetGfxPtr(bgBmp); clearBitmap(); int bgTop = bgInit(2, BgType_Text8bpp, BgSize_T_256x256, 0, 1); bgSetPriority(bgTop, 3); dmaCopy(topscr.gfxData, bgGetGfxPtr(bgTop), MemChunk_GetSize(topscr.gfxData)); dmaCopy(topscr.mapData, bgGetMapPtr(bgTop), MemChunk_GetSize(topscr.mapData)); dmaCopy(topscr.palData, BG_PALETTE, MemChunk_GetSize(topscr.palData)); u16* gfx = SPRITE_GFX_SUB; for (int i = 0; i < 6; i ++) { int xPos = 16 + (i % 3) * (64+16); int yPos = 48 + (i / 3) * (64+8); oamSet(&oamSub, i, xPos, yPos, 1, 15, SpriteSize_64x64, SpriteColorFormat_Bmp, gfx, -1, 0, false, false, false, false); gfx += 64*64; } { dmaCopy(selection.gfxData, gfx, MemChunk_GetSize(selection.gfxData)); oamSet(&oamSub, 6, 0, 0, 0, 15, SpriteSize_16x16, SpriteColorFormat_Bmp, gfx, -1, 0, false, false, false, false); gfx += 16*16; } for (int i = 0; i < MAX_RUNNING_APP_COUNT; i ++) { oamSet(&oamSub, 7+i, 64+(i*(16+8)), 16, 1, 15, SpriteSize_16x16, SpriteColorFormat_Bmp, gfx, -1, 0, false, false, false, false); oamSub_mem[7+i].isHidden = true; gfx += 16*16; } g_appListChanged = true; bump.init(BG_PALETTE_SUB); bump.SelectBump(page); updCursor(); loadPageIcons(); updAppList(); forceTopScrRefresh = true; }
void onInit() { setBrightness(3, -16); videoSetMode(MODE_5_2D); videoSetModeSub(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_BG); vramSetBankC(VRAM_C_SUB_BG); int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0); dmaCopy(splashBitmap, bgGetGfxPtr(bg3), 256*256); dmaCopy(splashPal, BG_PALETTE, 256*2); for(int i = 0; i < 128; i++) { setBrightness(3, -16+(i/8)); swiWaitForVBlank(); } for(int i = 0; i < 128; i++) { setBrightness(3, -(i/8)); swiWaitForVBlank(); } }
void initBackgrounds() { // bgInit(int layer, BgType type, BgSize size, int mapBase, int tileBase) int bg2 = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0,0); int bg2sub = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 2,0); decompress(MainBgBitmap, bgGetGfxPtr(bg2), LZ77Vram); decompress(MainBgBitmap, bgGetGfxPtr(bg2sub), LZ77Vram); }
Console::Console(int bg, bool main, int mapBase, int tileBase) { pal = 0; if(main) this->bg = bgInit(bg, BgType_Text4bpp, BgSize_T_256x256, mapBase, tileBase); else this->bg = bgInitSub(bg, BgType_Text4bpp, BgSize_T_256x256, mapBase, tileBase); }
int main(void) { // set the mode for 2 text layers and two extended background layers videoSetMode(MODE_5_2D); // set the sub background up for text display (we could just print to one // of the main display text backgrounds just as easily videoSetModeSub(MODE_0_2D); //sub bg 0 will be used to print text vramSetBankA(VRAM_A_MAIN_BG); consoleDemoInit(); iprintf("\n\n\tHello DS devers\n"); iprintf("\twww.drunkencoders.com\n"); iprintf("\t16 bit bitmap demo"); // set up our bitmap background bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0); decompress(drunkenlogoBitmap, BG_GFX, LZ77Vram); while(1) { swiWaitForVBlank(); } return 0; }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- //set the mode for 2 text layers and two extended background layers videoSetMode(MODE_5_2D); //set the first two banks as background memory and the third as sub background memory //D is not used..if you need a bigger background then you will need to map //more vram banks consecutivly (VRAM A-D are all 0x20000 bytes in size) vramSetPrimaryBanks( VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG , VRAM_D_LCD); consoleDemoInit(); iprintf("\n\n\tHello DS devers\n"); iprintf("\twww.drunkencoders.com\n"); iprintf("\tdouble buffer demo"); int bg = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0); u16 colorMask = 0x1F; u16* backBuffer = (u16*)bgGetGfxPtr(bg) + 256*256; while(1) { //draw a box (60,60,196,136) for(int iy = 60; iy < 196 - 60; iy++) for(int ix = 60; ix < 256 - 60; ix++) backBuffer[iy * 256 + ix] = (rand() & colorMask) | BIT(15); swiWaitForVBlank(); scanKeys(); if (keysDown()&KEY_START) break; //swap the back buffer to the current buffer backBuffer = (u16*)bgGetGfxPtr(bg); //swap the current buffer by changing the base. Each base //represents 16KB of offset and each screen is 256x256x2 (128KB) //this requires a map base seperation of 8 (could get away with smaller //as the screen is really only showing 256x192 (96KB or map base 6) if(bgGetMapBase(bg) == 8) { bgSetMapBase(bg, 0); } else { bgSetMapBase(bg, 8); } colorMask ^= 0x3FF; } }
void advRotating(void) { videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG); int bg = bgInit(3, BgType_ExRotation, BgSize_ER_256x256, 0,1); dmaCopy(TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles)); dmaCopy(TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal)); dmaCopy(Layer256x256Map, bgGetMapPtr(bg), Layer256x256MapLen); bgMosaicEnable(bg); int keys = 0; int angle = 0; int center_x = 0; int center_y = 0; while(!(keys & KEY_B)) { scanKeys(); keys = keysHeld(); if(keys & KEY_UP) center_y--; if(keys & KEY_DOWN) center_y++; if(keys & KEY_LEFT) center_x--; if(keys & KEY_RIGHT) center_x++; if(keys & KEY_L) angle-=40; if(keys & KEY_R) angle+=40; if(center_x > 256) center_x = 256; if(center_x < 0) center_x = 0; if(center_y > 192) center_y = 192; if(center_y < 0) center_y = 0; swiWaitForVBlank(); bgSetRotate(bg, angle); bgSetScroll(bg, center_x, center_y); bgSetCenter(bg, center_x, center_y); bgUpdate(); consoleClear(); iprintf("Press B to exit.n"); iprintf("Angle: %d \ncenter X: %d center Y: %d", angleToDegrees(angle), center_x, center_y); } }
/* Screen_Init Mode 5 gives us 2 text backgrounds 0-1 (tiled mode) and 2 extended rotation backgrounds 2-3. (linear fb) Also we need to map 2 banks of vram so we have enough space for our 512x512 surface. */ LOCALFUNC blnr Screen_Init(void) { videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_BG_0x06020000); Display_bg2_Main = bgInit(2, BgType_Bmp8, BgSize_B8_512x512, 0, 0); BG_PALETTE[0] = RGB15(31, 31, 31); BG_PALETTE[1] = RGB15(0, 0, 0); return trueblnr; }
void Hardware::init() { #ifndef USING_SDL powerOn(POWER_ALL_2D); videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_BG_0x06020000); vramSetBankC(VRAM_C_SUB_BG); // Initialise backgrounds bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); _topBuffer = new FrameBuffer((u16*)BG_BMP_RAM(0), SCREEN_WIDTH, SCREEN_HEIGHT); _bottomBuffer = new FrameBuffer((u16*)BG_BMP_RAM_SUB(0), SCREEN_WIDTH, SCREEN_HEIGHT); #else Uint32 initflags = SDL_INIT_VIDEO; // Initialize the SDL library if (SDL_Init(initflags) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } // Set video mode _window = SDL_CreateWindow("EarthShaker", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT * 2, 0); _renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 255); SDL_RenderClear(_renderer); SDL_RenderPresent(_renderer); _texture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_ABGR1555, SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH, SCREEN_HEIGHT * 2); _topBitmap = new u16[SCREEN_WIDTH * SCREEN_HEIGHT]; _bottomBitmap = new u16[SCREEN_WIDTH * SCREEN_HEIGHT]; _topBuffer = new FrameBuffer(_topBitmap, SCREEN_WIDTH, SCREEN_HEIGHT); _bottomBuffer = new FrameBuffer(_bottomBitmap, SCREEN_WIDTH, SCREEN_HEIGHT); #endif _topGfx = _topBuffer->newGraphics(); _bottomGfx = _bottomBuffer->newGraphics(); }
//--------------------------------------------------------------------------------- PrintConsole* consoleInit(PrintConsole* console, int layer, BgType type, BgSize size, int mapBase, int tileBase, bool mainDisplay, bool loadGraphics){ //--------------------------------------------------------------------------------- static bool firstConsoleInit = true; if(firstConsoleInit) { devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; setvbuf(stdout, NULL , _IONBF, 0); setvbuf(stderr, NULL , _IONBF, 0); firstConsoleInit = false; } if(console) { currentConsole = console; } else { console = currentConsole; } *currentConsole = defaultConsole; if(mainDisplay) { console->bgId = bgInit(layer, type, size, mapBase, tileBase); } else { console->bgId = bgInitSub(layer, type, size, mapBase, tileBase); } console->fontBgGfx = (u16*)bgGetGfxPtr(console->bgId); console->fontBgMap = (u16*)bgGetMapPtr(console->bgId); console->consoleInitialised = 1; consoleCls('2'); if(loadGraphics) consoleLoadFont(console); return currentConsole; }
void advMosaic(void) { videoSetMode(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_BG); int bg = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0,1); dmaCopy(TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles)); dmaCopy(Layer256x256Map, bgGetMapPtr(bg), Layer256x256MapLen); dmaCopy(TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal)); bgMosaicEnable(bg); int keys = 0; int mosaic_x = 0; int mosaic_y = 0; while(!(keys & KEY_B)) { scanKeys(); keys = keysDown(); if(keys & KEY_UP) mosaic_y--; if(keys & KEY_DOWN) mosaic_y++; if(keys & KEY_LEFT) mosaic_x--; if(keys & KEY_RIGHT) mosaic_x++; if(mosaic_x > 15) mosaic_x = 15; if(mosaic_x < 0) mosaic_x = 0; if(mosaic_y > 15) mosaic_y = 15; if(mosaic_y < 0) mosaic_y = 0; swiWaitForVBlank(); bgSetMosaic(mosaic_x, mosaic_y); consoleClear(); iprintf("Press B to exit\n"); iprintf("DX: %d DY: %d", mosaic_x, mosaic_y); } }
BG_INF* initBg(s16* tiles, int tileSz, s16* pal, int width, int height, int layer, u16* map) { BG_INF* tmp; if((tmp = malloc(sizeof(BG_INF)))) { tmp->bgId = bgInit(layer, BgType_Text8bpp, BgSize_T_512x256, 0,1); dmaCopy(tiles, bgGetGfxPtr(tmp->bgId), tileSz); dmaCopy(pal, BG_PALETTE, 256*2); tmp->vram_map = bgGetMapPtr(tmp->bgId); tmp->map = map; tmp->mapwidth = width; tmp->mapHeight = height; tmp->x = 0; tmp->y = 0; fillScreen(tmp, 0, 0); return tmp; } return NULL; }
void splashScreen::initiate() { lcdMainOnTop(); videoSetMode(MODE_5_2D); videoSetModeSub(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankC(VRAM_C_SUB_BG_0x06200000); //sets up our backgrounds bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256,0,0); dmaCopy(splashBitmap, bgGetGfxPtr(bg3), splashBitmapLen); dmaCopy(splashPal, BG_PALETTE, splashPalLen); bg2 = bgInitSub(2, BgType_Bmp8, BgSize_B8_256x256, 0,0); dmaCopy(splashBitmap, bgGetGfxPtr(bg2), splashBitmapLen); dmaCopy(splashPal, BG_PALETTE_SUB, splashPalLen); initiated = true; }
void advScaling(void) { videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG); int bg = bgInit(3, BgType_ExRotation, BgSize_ER_256x256, 0,1); dmaCopy(TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles)); dmaCopy(TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal)); dmaCopy(Layer256x256Map, bgGetMapPtr(bg), Layer256x256MapLen); bgMosaicEnable(bg); int keys = 0; int scale_x = 1 << 8; int scale_y = 1 << 8; while(!(keys & KEY_B)) { scanKeys(); keys = keysHeld(); if(keys & KEY_UP) scale_y++; if(keys & KEY_DOWN) scale_y--; if(keys & KEY_LEFT) scale_x++; if(keys & KEY_RIGHT) scale_x--; swiWaitForVBlank(); bgSetScale(bg, scale_x , scale_y ); bgUpdate(); consoleClear(); iprintf("Press B to exit.n"); iprintf("scale X: %d scale Y: %d", scale_x, scale_y); } }
int main(void) { // 상단 화면 설정 InitDebug(); videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG); bgInit(3,BgType_Bmp16, BgSize_B16_256x256, 0, 0); decompress(upBitmap, BG_GFX, LZ77Vram); // 하단 화면 설정 videoSetModeSub(MODE_5_2D); vramSetBankC(VRAM_C_SUB_BG); bgInitSub(3,BgType_Bmp16, BgSize_B16_256x256, 0, 0); decompress(downBitmap, BG_GFX_SUB, LZ77Vram); xTaskCreate(Key_Task, (const signed char * const)"Key_Task", 2048, (void *)NULL, tskIDLE_PRIORITY + 10, NULL); xTaskCreate(Main_Task, (const signed char * const)"Main_Task", 2048, (void *)NULL, tskIDLE_PRIORITY + 1, NULL); KeyQueue = xQueueCreate(MAX_KEY_LOG, sizeof(u8)); vTaskStartScheduler(); // Never returns while(1) ; return 0; }
int main(int argc, char *argv[]) { tlmmProgram *prog; int down; unsigned int selection = 0; prog = tlmmInitProgram(); consoleDemoInit(); videoSetMode(MODE_5_2D); vramSetPrimaryBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE); bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); iprintf("\x1b[2J================================\n"); iprintf("Program: %s\n", progs[selection]); tlmmParseProgram(prog, progs[selection]); evaluate(prog); do { swiWaitForVBlank(); scanKeys(); down = keysDown(); if(down & KEY_LEFT) selection = (selection + NUM_PROGS - 1) % NUM_PROGS; if(down & KEY_RIGHT) selection = (selection + 1) % NUM_PROGS; if(down & (KEY_LEFT|KEY_RIGHT)) { iprintf("\x1b[2J================================\n"); iprintf("Program: %s\n", progs[selection]); tlmmParseProgram(prog, progs[selection]); evaluate(prog); } } while(!(down & KEY_B)); 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; }
int main(void) { consoleDemoInit(); //videoSetMode(MODE_FB0); videoSetMode( MODE_5_2D ); vramSetBankA(VRAM_A_MAIN_BG); vramSetBankB(VRAM_B_MAIN_BG); // vramSetBankC(VRAM_C_MAIN_BG); // vramSetBankD(VRAM_D_MAIN_BG_0x06040000); int bg = bgInit(3, BgType_Bmp8, BgSize_B8_512x512, 0,0); //vramSetBankA(VRAM_A_LCD); lcdMainOnBottom(); // lcdMainOnTop(); printf("Video modes configured\n"); printf("BG ID %d\n", bg); if (fatInitDefault()) printf("FAT initialized\n"); else printf("FAT initialization failed\n"); AppState state; uiOpenNotebook(state); // Keyboard *kbd = keyboardDemoInit(); Segment * currentSegment = NULL; touchPosition touch; while (1) { scanKeys(); if(keysHeld() & KEY_TOUCH) { // write the touchscreen coordinates in the touch variable touchRead(&touch); Point screenPoint = Point(touch.px, touch.py); Point imagePoint = state.convertScreenToImage(screenPoint); if (currentSegment == NULL) { state.currentPage->segments.push_back(Segment()); currentSegment = &(state.currentPage->segments[state.currentPage->segments.size()-1]); currentSegment->points.push_back(imagePoint); continue; } Point lastImagePoint = currentSegment->points[currentSegment->points.size()-1]; currentSegment->points.push_back(imagePoint); Point bufferPoint = state.convertScreenToBuffer(screenPoint); Point lastBufferPoint = state.convertImageToBuffer(lastImagePoint); drawLine(lastBufferPoint.x, lastBufferPoint.y, bufferPoint.x, bufferPoint.y, RGB15(31,0,0) | BIT(15)); } else { currentSegment = NULL; } if (keysDown() & KEY_X) { int page = state.lastPage+1; while (state.notebook.pages.size() < page+1) { state.notebook.pages.push_back(Page()); printf("New Page created\n"); } state.currentPage = &(state.notebook.pages[page]); currentSegment = NULL; printf("Display page %d\n", page); fillDisplay(RGB15(0,0,0) | BIT(15), page, state); drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state); } if (keysDown() & KEY_Y) { int page = 0; if (state.lastPage > 0) { page = state.lastPage-1; } state.currentPage = &(state.notebook.pages[page]); currentSegment = NULL; printf("Display page %d\n", page); fillDisplay(RGB15(0,0,0) | BIT(15), page, state); drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state); } if (keysDown() & KEY_A) { int page = 0; std::string fileName = state.notebookName + "/notes.txt"; state.notebook = loadFile(fileName.c_str()); state.currentPage = &(state.notebook.pages[page]); currentSegment = NULL; printf("Display page %d\n", page); fillDisplay(RGB15(0,0,0) | BIT(15), page, state); drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state); } if (keysDown() & KEY_B) { std::string fileName = state.notebookName + "/notes.txt"; saveFile(fileName.c_str(), state.notebook); } if (keysDown() & KEY_LEFT) { state.scroll_x-=50; updateCenter(state); } if (keysDown() & KEY_RIGHT) { state.scroll_x+=50; updateCenter(state); } if (keysDown() & KEY_UP) { state.scroll_y-=50; updateCenter(state); } if (keysDown() & KEY_DOWN) { state.scroll_y+=50; updateCenter(state); } if (keysDown() & KEY_START) { uiOpenNotebook(state); } swiWaitForVBlank(); } }
static int NDS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch) { struct NDS_WindowData *wdata; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; const SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); const SDL_DisplayMode *mode = display->driverdata; const Uint32 fmt = mode->format; if (fmt != SDL_PIXELFORMAT_ABGR1555) { SDL_SetError("Unsupported pixel format (%x)", fmt); return -1; } if (!SDL_PixelFormatEnumToMasks (fmt, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { SDL_SetError("Unknown texture format"); return -1; } wdata = SDL_calloc(1, sizeof(struct NDS_WindowData)); if (!wdata) { SDL_OutOfMemory(); return -1; } if (bpp == 8) { wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH; } else { wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH*2; } wdata->pixels = SDL_calloc(1, wdata->pixels_length); if (!wdata->pixels) { SDL_free(wdata); SDL_SetError("Not enough memory"); return -1; } if (bpp == 8) { wdata->main.bg_id = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0); wdata->sub.bg_id = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0); wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH; wdata->main.pixels = wdata->pixels; wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH; wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ } else { wdata->main.bg_id = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0); wdata->sub.bg_id = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; wdata->main.pixels = wdata->pixels; wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ } wdata->pitch = (window->w) * ((bpp+1) / 8); wdata->bpp = bpp; wdata->rotate = 0; wdata->scale.x = 0x100; wdata->scale.y = 0x100; wdata->scroll.x = 0; wdata->scroll.y = 0; wdata->main.vram_pixels = bgGetGfxPtr(wdata->main.bg_id); wdata->sub.vram_pixels = bgGetGfxPtr(wdata->sub.bg_id); #if 0 bgSetCenter(wdata->main.bg_id, 0, 0); bgSetRotateScale(wdata->main.bg_id, wdata->rotate, wdata->scale.x, wdata->scale.y); bgSetScroll(wdata->main.bg_id, wdata->scroll.x, wdata->scroll.y); #endif #if 0 bgSetCenter(wdata->sub.bg_id, 0, 0); bgSetRotateScale(wdata->sub.bg_id, wdata->rotate, wdata->scale.x, wdata->scale.y); bgSetScroll(wdata->sub.bg_id, wdata->scroll.x, wdata->scroll.y); #endif bgUpdate(); *format = fmt; *pixels = wdata->pixels; *pitch = wdata->pitch; window->driverdata = wdata; return 0; }
int main(void) { aplist *head = NULL; aplist *cur; bool attached = true; // change this to false if you are only testing servos bool wifi_scan = true; // change this for emulator bool emulate = false; float pain = 0.9f; time_t update = 0; uint8 num; uint8 servo_pos = 0; uint8 current_servo = 1; unsigned char SERVO_PINS[3] = { SERVO_PIN1 ,SERVO_PIN2 ,SERVO_PIN3 } ; uint16 val[3] = { 0 }; uint8 i; touchPosition touch; videoSetMode(MODE_4_2D); vramSetBankA(VRAM_A_MAIN_BG); // set up our bitmap background bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0); decompress(cclogoBitmap, BG_GFX, LZ77Vram); // initialise lower screen for textoutput consoleDemoInit(); if (emulate == false) { iprintf("Initializing WiFi.. "); Wifi_InitDefault(false); while (Wifi_CheckInit() != 1) { } Wifi_ScanMode(); iprintf("done\n"); iprintf("Initializing DS brut.. "); uart_init(); uart_set_spi_rate(1000); iprintf("done\n\n\n"); iprintf("Using servo pins: %u %u %u\n\n", SERVO_PIN1, SERVO_PIN2, SERVO_PIN3); iprintf("Default pain multiplier: %.2f\n\n", pain); swiDelay(60000000); while (1) { scanKeys(); touchRead(&touch); if (keysDown() & KEY_X) { if (attached) { servo_detach(SERVO_PIN1); servo_detach(SERVO_PIN2); servo_detach(SERVO_PIN3); attached = false; } else { attached = true; } } if (keysDown() & KEY_A) { if (attached) { uint8 i = 0; for (i=0;i<3;i++) { servo_set(SERVO_PINS[i],0); } } //servo_set(SERVO_PIN1, 180-((rand() % 100)+(rand() % 50)+(rand() % 25))); //servo_set(SERVO_PIN2, 180-((rand() % 100)+(rand() % 50)+(rand() % 25))); //servo_set(SERVO_PIN3, 180-((rand() % 100)+(rand() % 50)+(rand() % 25))); } if (keysDown() & KEY_B) { if (wifi_scan == true) { wifi_scan = false; } else { wifi_scan = true; } } if (keysDown() & KEY_DOWN) { pain -= 0.1f; if (pain < 0.0f) { pain = 0.0f; } update = time(NULL); } if (keysDown() & KEY_UP) { pain += 0.1f; if (2.0f < pain) { pain = 2.0f; } update = time(NULL); } if (keysDown() & KEY_L) { current_servo += 1; if (current_servo > 3) { current_servo = 1; } } consoleClear(); if (wifi_scan == true) { num = 0; cur = head; iprintf("\n"); while (cur && num < 15) { // display if (!(cur->flags & 0x2)) { cur = cur->next; continue; } iprintf("%2u ", num); if (cur->ssid[0] == '\0') { iprintf("%02x%02x%02x%02x%02x%02x", cur->mac[0], cur->mac[1], cur->mac[2], cur->mac[3], cur->mac[4], cur->mac[5]); } else { iprintf("%s", cur->ssid); } iprintf(" @ %u", cur->rssi); if ((cur->flags & 0x06) == 0x06) { iprintf(" WPA"); } else if (cur->flags & 0x02) { iprintf(" WEP"); } // calculate servo commands if (attached && num < 3) { val[num] = (uint16)(cur->rssi*pain); if (180 < val[num]) { val[num] = 180; } iprintf(" %u", val[num]); } iprintf("\n"); if (num == 2) { iprintf ("\n"); } num++; cur = cur->next; } iprintf("\n"); if (time(NULL) < update+3) { printf("\npain multiplier: %.2f\n", pain); } // set the servo to zero if we don't have enough wifi nodes for (i=num; i<3; i++) { val[i] = 0; } if (attached) { servo_set(SERVO_PIN1, (uint8)val[0]); servo_set(SERVO_PIN2, 180-(uint8)val[1]); servo_set(SERVO_PIN3, (uint8)val[2]); } updateApList(&head, 0x00, NULL, NULL); sortApList(&head, false); } if (KEY_TOUCH && attached && !wifi_scan) { servo_pos = (touch.rawx / 3850.) * 180; iprintf ("servo pos x: %d;", servo_pos); iprintf ("\n"); servo_set(SERVO_PINS[current_servo-1],servo_pos); iprintf ("current servo: %d", current_servo); iprintf ("\n\n"); } swiWaitForVBlank(); } } while (1) { swiWaitForVBlank(); } return 0; }
int main(void) { lcdMainOnBottom(); // Register vblank IRQ irqEnable(IRQ_VBLANK); // Set banks vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000 , VRAM_D_LCD); // Set modes videoSetMode(MODE_5_2D); videoSetModeSub(MODE_5_2D); // sub display int sub_bg3 = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 2, 0); bgSetPriority(sub_bg3, 1); #ifdef DEBUG // Text bg on sub PrintConsole *pc = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false); bgSetPriority(pc->bgId, 0); BG_PALETTE_SUB[255] = RGB15(31,0,31); #endif // The main display is for graphics. // Set up an extended rotation background for background gfx int main_bg2 = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0); bgSetPriority(main_bg2, 1); // Set up tile mode for the keyboard int main_bg0 = bgInit(0, BgType_Text4bpp, BgSize_T_256x256, 8, 0); bgSetPriority(main_bg0, 0); // Clear tile mem u16 *tile_ram = (u16*)bgGetGfxPtr(main_bg0); u32 i; for(i=0; i<(32*1024); ++i) { tile_ram[i] = 0; } // Copy tiles and palettes dmaCopy((uint16*)keyboard_Palette, (uint16*)BG_PALETTE, 32); dmaCopy((uint16*)keyboard_fullnotehighlight_Palette, (uint16*)BG_PALETTE+16, 32); dmaCopy((uint16*)keyboard_halfnotehighlight_Palette, (uint16*)BG_PALETTE+32, 32); dmaCopy((uint16*)keyboard_Tiles, (uint16*)CHAR_BASE_BLOCK(0), 736); // Fill screen with empty tiles u16 *map = (u16*)bgGetMapPtr(main_bg0); for(i=0;i<768;++i) { map[i] = 28; } // Draw the backgrounds main_vram = (u16*)bgGetGfxPtr(main_bg2); for(i=0; i<192*256; ++i) { main_vram[i] = ((uint16*)bg_main)[i]; } u16 *sub_vram = (u16*)bgGetGfxPtr(sub_bg3); for(i=0; i<192*256; ++i) { sub_vram[i] = ((uint16*)bg_sub)[i]; } displayChannel(channel); displayOctave(baseOctave); drawString("connecting ...", 89, 96); iprintf("Connecting\n"); int res = dsmi_connect(); if(res == 1) { iprintf("OK\n"); } else { iprintf("Oh no! Could not connect\n"); drawString("failed!", 180, 96); while(1); } iprintf("Ready.\n"); // Copy the keyboard to the screen kb_map = (u16*)bgGetMapPtr(main_bg0); u8 x, y; for(y=0; y<5; ++y) { for(x=0; x<28; ++x) { kb_map[32*(y+keyb_ypos)+(x+keyb_xpos)] = keyboard_Map[29*y+x+1]; } } while(1) { VblankHandler(); swiWaitForVBlank(); } return 0; }
void initGame(void) { lcdMainOnTop(); int oldv=getMemFree(); NOGBA("mem free : %dko (%do)",getMemFree()/1024,getMemFree()); NOGBA("initializing..."); videoSetMode(MODE_5_3D | DISPLAY_BG3_ACTIVE); videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE); glInit(); vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_LCD,VRAM_D_MAIN_BG_0x06000000); vramSetBankH(VRAM_H_SUB_BG); vramSetBankI(VRAM_I_SUB_BG_0x06208000); glEnable(GL_TEXTURE_2D); // glEnable(GL_ANTIALIAS); glDisable(GL_ANTIALIAS); glEnable(GL_BLEND); glEnable(GL_OUTLINE); glSetOutlineColor(0,RGB15(0,0,0)); //TEMP? glSetOutlineColor(1,RGB15(0,0,0)); //TEMP? glSetOutlineColor(7,RGB15(31,0,0)); //TEMP? glSetToonTableRange(0, 15, RGB15(8,8,8)); //TEMP? glSetToonTableRange(16, 31, RGB15(24,24,24)); //TEMP? glClearColor(31,31,0,31); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0,0,255,191); // initVramBanks(1); initVramBanks(2); initTextures(); initSound(); initCamera(NULL); initPlayer(NULL); initLights(); initParticles(); initMaterials(); loadMaterialSlices("slices.ini"); loadMaterials("materials.ini"); loadControlConfiguration("config.ini"); initElevators(); initWallDoors(); initTurrets(); initBigButtons(); initTimedButtons(); initEnergyBalls(); initPlatforms(); initCubes(); initEmancipation(); initDoors(); initSludge(); initPause(); initText(); NOGBA("lalala"); getPlayer()->currentRoom=&gameRoom; currentBuffer=false; getVramStatus(); fadeIn(); mainBG=bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); bgSetPriority(mainBG, 0); REG_BG0CNT=BG_PRIORITY(3); #ifdef DEBUG_GAME consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 16, 0, false, true); consoleSelect(&bottomScreen); #endif // glSetToonTableRange(0, 14, RGB15(16,16,16)); // glSetToonTableRange(15, 31, RGB15(26,26,26)); initPortals(); //PHYSICS initPI9(); strcpy(&mapFilePath[strlen(mapFilePath)-3], "map"); newReadMap(mapFilePath, NULL, 255); transferRectangles(&gameRoom); makeGrid(); generateRoomGrid(&gameRoom); gameRoom.displayList=generateRoomDisplayList(&gameRoom, vect(0,0,0), vect(0,0,0), false); getVramStatus(); startPI(); NOGBA("START mem free : %dko (%do)",getMemFree()/1024,getMemFree()); NOGBA("vs mem free : %dko (%do)",oldv/1024,oldv); levelInfoCounter=60; }
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(); }
Display::Display(){ // INIT //------------------------------------------------------------------------- frame = 0; srand((int)NULL); // Main Init videoSetMode(MODE_5_2D | DISPLAY_BG_EXT_PALETTE); oamInit(&oamMain, SpriteMapping_1D_128, true); // Sub Init videoSetModeSub(MODE_5_2D | DISPLAY_BG_EXT_PALETTE); oamInit(&oamSub, SpriteMapping_1D_128, true); //------------------------------------------------------------------------- // FONT LOADING //------------------------------------------------------------------------- ConsoleFont font; font.gfx = (u16*)fontTiles; font.pal = (u16*)fontPal; font.numChars = 95; font.numColors = 16; font.bpp = 4; font.asciiOffset = 32; font.convertSingleColor = true; //------------------------------------------------------------------------- // MAIN BACKGROUNDS //------------------------------------------------------------------------- //BG Palettes vramSetBankE(VRAM_E_LCD); dmaCopy(fontPal, VRAM_E_EXT_PALETTE[0], 512); dmaCopy(bgMainPal, VRAM_E_EXT_PALETTE[2], 512); dmaCopy(padsBgMainPal, VRAM_E_EXT_PALETTE[3], 512); vramSetBankE(VRAM_E_BG_EXT_PALETTE); //BG0 : Text mainbg0 = bgInit(0, BgType_Text4bpp, BgSize_T_256x256, 1, 0); consoleInit(&this->mainConsole, 0, BgType_Text4bpp, BgSize_T_256x256, 1, 0, true, false); consoleSetFont(&this->mainConsole, &font); bgSetPriority(this->mainbg0, 0); //BG2 mainbg2 = bgInit(2, BgType_Rotation, BgSize_R_256x256, 7, 1); dmaCopy(bgMainTiles, bgGetGfxPtr(mainbg2), bgMainTilesLen); dmaCopy(bgMainMap, bgGetMapPtr(mainbg2), bgMainMapLen); bgSetPriority(this->mainbg2, 3); bgHide(mainbg2); //BG3 mainbg3 = bgInit(3, BgType_Rotation, BgSize_R_256x256, 12, 2); dmaCopy(padsBgMainTiles, bgGetGfxPtr(mainbg3), padsBgMainTilesLen); dmaCopy(padsBgMainMap, bgGetMapPtr(mainbg3), padsBgMainMapLen); bgSetPriority(this->mainbg3, 2); bgHide(mainbg3); //------------------------------------------------------------------------- // MAIN SPRITES //------------------------------------------------------------------------- //Palettes vramSetBankF(VRAM_F_LCD); dmaCopy(dotSpritePal, VRAM_F_EXT_SPR_PALETTE[0], 512); dmaCopy(ledSpritePal, VRAM_F_EXT_SPR_PALETTE[1], 512); dmaCopy(banksSpritePal, VRAM_F_EXT_SPR_PALETTE[2], 512); dmaCopy(octaveSelectSpritePal, VRAM_F_EXT_SPR_PALETTE[3], 512); vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE); //Sprites loading dotSprite = new Sprite(1, dotSpriteTiles, 0, SpriteSize_64x32, 3); ledSprite = new Sprite(1, ledSpriteTiles, 1, SpriteSize_16x16, 4); banksSprite = new Sprite(1, banksSpriteTiles, 2, SpriteSize_16x16, 8); octaveSelectSprite = new Sprite(1, octaveSelectSpriteTiles, 3, SpriteSize_32x16, 1); //------------------------------------------------------------------------- // SUB BACKGROUNDS //------------------------------------------------------------------------- //BG Palettes vramSetBankH(VRAM_H_LCD); dmaCopy(fontPal, VRAM_H_EXT_PALETTE[0], 512); dmaCopy(slidersBg2SubPal, VRAM_H_EXT_PALETTE[2], 512); dmaCopy(slidersBg3SubPal, VRAM_H_EXT_PALETTE[3], 512); vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); //BG0 : Text subbg0 = bgInitSub(0, BgType_Text4bpp, BgSize_T_256x256, 4, 0); consoleInit(&subConsole, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, false, true); consoleSetFont(&subConsole, &font); bgSetPriority(subbg0, 1); //BG2 subbg2 = bgInitSub(2, BgType_Rotation, BgSize_R_256x256, 5,1); bgSetPriority(subbg2, 3); //BG3 subbg3 = bgInitSub(3, BgType_Rotation, BgSize_R_256x256, 6,2); bgSetPriority(subbg3, 2); bgHide(subbg3); //------------------------------------------------------------------------- // SUB SPRITES //------------------------------------------------------------------------- //Palettes vramSetBankI(VRAM_I_LCD); dmaCopy(kaossBrickSpritePal, VRAM_I_EXT_SPR_PALETTE[0], 512); dmaCopy(padSpritePal, VRAM_I_EXT_SPR_PALETTE[1], 512); dmaCopy(modeSpritePal, VRAM_I_EXT_SPR_PALETTE[2], 512); dmaCopy(sliderCursorSpritePal, VRAM_I_EXT_SPR_PALETTE[3], 512); dmaCopy(muteSpritePal, VRAM_I_EXT_SPR_PALETTE[4], 512); dmaCopy(editParamsSpritePal, VRAM_I_EXT_SPR_PALETTE[5], 512); vramSetBankI(VRAM_I_SUB_SPRITE_EXT_PALETTE); //Sprites loading kaossBrickSprite = new Sprite(0, kaossBrickSpriteTiles, 0, SpriteSize_32x32, 16); padSprite = new Sprite(0, padSpriteTiles, 1, SpriteSize_64x64, 2); modesSprite = new Sprite(0, modeSpriteTiles, 2, SpriteSize_64x64, 4); sliderCursorSprite = new Sprite(0, sliderCursorSpriteTiles, 3, SpriteSize_32x16, 6); muteSprite = new Sprite(0, muteSpriteTiles, 4, SpriteSize_32x32, 2); paramsEditSprite = new Sprite(0, editParamsSpriteTiles, 5, SpriteSize_16x16, 8); //------------------------------------------------------------------------- // STRUCTURES INITIALISATION //------------------------------------------------------------------------- kaossBricksState = new u8**[4]; for (u8 b = 0; b < 4; ++b){ kaossBricksState[b] = new u8*[8]; for (u8 i = 0; i < 8; ++i){ kaossBricksState[b][i] = new u8[8]; for (u8 j = 0; j < 8; ++j) kaossBricksState[b][i][j] = 0; } } slidersBg2Map = new unsigned short[768]; slidersBg3Map = new unsigned short[768]; //------------------------------------------------------------------------- consoleSelect(&mainConsole); consoleClear(); dmaCopy(bgSplashTiles, bgGetGfxPtr(subbg2), bgSplashTilesLen); dmaCopy(bgSplashMap, bgGetMapPtr(subbg2), bgSplashMapLen); echo(0, GREY, 12, 10, "Connecting..."); echo(0, WHITE, 23, 6, "midicontrolds.blogspot.com"); }
void Outro_Run() { Outro_ConfigureHardware(); /* Enable background blending */ REG_BLDCNT = BLEND_SRC_BG0 | BLEND_SRC_BG3 | BLEND_FADE_BLACK; REG_BLDCNT_SUB = BLEND_SRC_BG0 | BLEND_SRC_BG3 | BLEND_FADE_BLACK; /* Configure background engines */ int bg0_main = bgInit(0, BgType_Text4bpp, BgSize_T_256x256, 1, 0); int bg0_sub = bgInitSub(0, BgType_Text4bpp, BgSize_T_256x256, 1, 0); /* Set background 0 to display below background 1 */ bgSetPriority(bg0_main, 1); bgSetPriority(bg0_sub, 1); Outro_LoadResources(bg0_main, bg0_sub); /* Set up distortion effects */ Distorter *distorter_main = malloc(sizeof(Distorter)); Distorter_Init(distorter_main, 0, DistorterEngineMain, -(20 << 8), 96, 4 << 8); Distorter *distorter_sub = malloc(sizeof(Distorter)); Distorter_Init(distorter_sub, 3, DistorterEngineSub, -(16 << 8), 96, 4 << 8); /* Create a console for the main display and print the message to it */ PrintConsole display_console_main; TitleConsole_Init(&display_console_main, 3, true, 2, 1); consoleSelect(&display_console_main); iprintf("THE\nEND"); /* Create a console for the sub display and print the message to it */ PrintConsole display_console_sub; TitleConsole_Init(&display_console_sub, 3, false, 2, 1); consoleSelect(&display_console_sub); iprintf("MORE\nSOON"); /* Offset each console so they are vertically centered */ bgSetScroll(display_console_main.bgId, 0, -16); bgSetScroll(display_console_sub.bgId, 0, -16); bgUpdate(); /* Fade in */ for (int blend_factor = 0xf; blend_factor >= 0x0; blend_factor--) { Outro_Draw(distorter_main, distorter_sub); REG_BLDY = blend_factor; REG_BLDY_SUB = blend_factor; } /* Main stage loop. Exit when a key is pressed */ while (!(keysDown() & KEY_START)) { Outro_Draw(distorter_main, distorter_sub); scanKeys(); } Distorter_Free(distorter_main); free(distorter_main); Distorter_Free(distorter_sub); free(distorter_sub); }
static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; NDS_TextureData *txdat = NULL; int i; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; if (!SDL_PixelFormatEnumToMasks (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { SDL_SetError("Unknown texture format"); return -1; } /* conditional statements on w/h to place it as bg/sprite depending on which one it fits. */ if (texture->w <= 64 && texture->h <= 64) { int whichspr = -1; printf("NDS_CreateTexture: Tried to make a sprite.\n"); txdat->type = NDSTX_SPR; #if 0 for (i = 0; i < SPRITE_COUNT; ++i) { if (data->oam_copy.spriteBuffer[i].attribute[0] & ATTR0_DISABLED) { whichspr = i; break; } } if (whichspr >= 0) { SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]); int maxside = texture->w > texture->h ? texture->w : texture->h; int pitch; texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); txdat = (NDS_TextureData *) texture->driverdata; if (!txdat) { SDL_OutOfMemory(); return -1; } sprent->objMode = OBJMODE_BITMAP; sprent->posX = 0; sprent->posY = 0; sprent->colMode = OBJCOLOR_16; /* OBJCOLOR_256 for INDEX8 */ /* the first 32 sprites get transformation matrices. first come, first served */ if (whichspr < MATRIX_COUNT) { sprent->isRotoscale = 1; sprent->rsMatrixIdx = whichspr; } /* containing shape (square or 2:1 rectangles) */ sprent->objShape = OBJSHAPE_SQUARE; if (texture->w / 2 >= texture->h) { sprent->objShape = OBJSHAPE_WIDE; } else if (texture->h / 2 >= texture->w) { sprent->objShape = OBJSHAPE_TALL; } /* size in pixels */ /* FIXME: "pitch" is hardcoded for 2bytes per pixel. */ sprent->objSize = OBJSIZE_64; pitch = 128; if (maxside <= 8) { sprent->objSize = OBJSIZE_8; pitch = 16; } else if (maxside <= 16) { sprent->objSize = OBJSIZE_16; pitch = 32; } else if (maxside <= 32) { sprent->objSize = OBJSIZE_32; pitch = 64; } /* FIXME: this is hard-coded and will obviously only work for one sprite-texture. tells it to look at the beginning of SPRITE_GFX for its pixels. */ sprent->tileIdx = 0; /* now for the texture data */ txdat->type = NDSTX_SPR; txdat->hw_index = whichspr; txdat->dim.hdx = 0x100; txdat->dim.hdy = 0; txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; txdat->dim.pitch = pitch; txdat->dim.bpp = bpp; txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX); /* FIXME: use tileIdx*boundary to point to proper location */ } else { SDL_SetError("Out of NDS sprites."); } #endif } else if (texture->w <= 256 && texture->h <= 256) { int whichbg = -1, base = 0; if (!data->bg_taken[2]) { whichbg = 2; } else if (!data->bg_taken[3]) { whichbg = 3; base = 4; } if (whichbg >= 0) { texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); txdat = (NDS_TextureData *) texture->driverdata; if (!txdat) { SDL_OutOfMemory(); return -1; } // hard-coded for 256x256 for now... // TODO: a series of if-elseif-else's to find the closest but larger size. if (!data->sub) { if (bpp == 8) { txdat->hw_index = bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0); } else { txdat->hw_index = bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0); } } else { if (bpp == 8) { txdat->hw_index = bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0); } else { txdat->hw_index = bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0); } } /* useful functions bgGetGfxPtr(bg3); bgSetCenter(bg3, rcX, rcY); bgSetRotateScale(bg3, angle, scaleX, scaleY); bgSetScroll(bg3, scrollX, scrollY); bgUpdate(bg3); */ txdat->type = NDSTX_BG; txdat->pitch = (texture->w) * (bpp / 8); txdat->bpp = bpp; txdat->rotate = 0; txdat->scale.x = 0x100; txdat->scale.y = 0x100; txdat->scroll.x = 0; txdat->scroll.y = 0; txdat->vram_pixels = (u16 *) bgGetGfxPtr(txdat->hw_index); bgSetCenter(txdat->hw_index, 0, 0); bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x, txdat->scale.y); bgSetScroll(txdat->hw_index, txdat->scroll.x, txdat->scroll.y); bgUpdate(txdat->hw_index); data->bg_taken[whichbg] = 1; /*txdat->size = txdat->dim.pitch * texture->h; */ } else { SDL_SetError("Out of NDS backgrounds."); } } else { SDL_SetError("Texture too big for NDS hardware."); } if (!texture->driverdata) { return -1; } return 0; }