void updateCenter(AppState & state) { Point bottomLeft = state.convertBufferToScreen(Point(0,0)); Point topRight = state.convertBufferToScreen(Point(MY_BG_W,MY_BG_H)); Point newCenter = state.convertScreenToImage(Point(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)); // printf("--------------\n"); // printf("%d %d\n", bottomLeft.x, bottomLeft.y); // printf("%d %d\n", topRight.x, topRight.y); // printf("%d %d\n", newCenter.x, newCenter.y); if (bottomLeft.x > 0 || bottomLeft.y > 0 || topRight.x < SCREEN_WIDTH || topRight.y < SCREEN_HEIGHT) { //Point newCenter = state.convertScreenToImage(Point(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)); state.scroll_x = MY_BG_W/2-SCREEN_WIDTH/2; state.scroll_y = MY_BG_H/2-SCREEN_HEIGHT/2; state.center_x = newCenter.x; state.center_y = newCenter.y; // printf("%d %d\n", state.center_x, state.center_y); bgHide(3); fillDisplay(RGB15(0,0,0) | BIT(15), state.lastPage, state); drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state); } bgSetScroll(3, state.scroll_x, state.scroll_y); bgUpdate(); bgShow(3); }
/* DS_VBlank_IRQ Vertical blank interrupt callback. */ LOCALPROC DS_VBlank_IRQ(void) { scanKeys(); KeysHeld = keysHeld(); if (++VBlankCounter == 60) { VBlankCounter = 0; } /* TODO: Rewrite this at some point, I'm not sure I like it. */ if (0 != (KeysHeld & KEY_LEFT)) { --CursorX; } else if (0 != (KeysHeld & KEY_RIGHT)) { ++CursorX; } if (0 != (KeysHeld & KEY_UP)) { --CursorY; } else if (0 != (KeysHeld & KEY_DOWN)) { ++CursorY; } CursorX = CursorX < 0 ? 0 : CursorX; CursorX = CursorX > vMacScreenWidth ? vMacScreenWidth : CursorX; CursorY = CursorY < 0 ? 0 : CursorY; CursorY = CursorY > vMacScreenHeight ? vMacScreenHeight : CursorY; DS_ScrollBackground(); bgUpdate(); }
void updateScroll(BG_INF* inf, int dx, int dy) { scroll(inf->x, inf->y, dx, dy, inf); inf->x+= dx; inf->y+= dy; bgSetScroll (inf->bgId, inf->x, inf->y); bgUpdate(); }
boxUI::boxUI( ) { IO::swapScreens( ); IO::vramSetup( ); videoSetMode( MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_EXT_PALETTE ); dmaFillWords( 0, bgGetGfxPtr( IO::bg2 ), 256 * 192 ); dmaFillWords( 0, bgGetGfxPtr( IO::bg2sub ), 256 * 192 ); bgUpdate( ); swiWaitForVBlank( ); IO::NAV->draw( ); drawAllBoxStatus( ); IO::initOAMTable( false ); u16 tileCnt = 0; tileCnt = IO::loadSprite( BACK_ID, BACK_ID, 0, tileCnt, SCREEN_WIDTH - 28, SCREEN_HEIGHT - 28, 32, 32, BackPal, BackTiles, BackTilesLen, false, false, false, OBJPRIORITY_1, false ); tileCnt = IO::loadSprite( ARROW_ID, 0, 1, tileCnt, 0, 0, 16, 16, box_arrowPal, box_arrowTiles, box_arrowTilesLen, false, false, true, OBJPRIORITY_0, false ); tileCnt += 64; tileCnt = IO::loadSprite( PAGE_ICON_START + ( 0 ), 0, PAGE_ICON_START + ( 0 ), tileCnt, 20, 0, 32, 32, time_iconPal, time_iconTiles, time_iconTilesLen, false, false, true, OBJPRIORITY_0, false ); tileCnt = IO::loadSprite( PAGE_ICON_START + ( 1 ), 0, PAGE_ICON_START + ( 1 ), tileCnt, 40, 0, 32, 32, memoPal, memoTiles, memoTilesLen, false, false, true, OBJPRIORITY_0, false ); tileCnt = IO::loadSprite( PAGE_ICON_START + ( 2 ), 0, PAGE_ICON_START + ( 2 ), tileCnt, 0, 0, 32, 32, PKMNPal, PKMNTiles, PKMNTilesLen, false, false, true, OBJPRIORITY_0, false ); tileCnt = IO::loadSprite( PAGE_ICON_START + ( 3 ), 0, PAGE_ICON_START + ( 3 ), tileCnt, 50, 0, 32, 32, atksPal, atksTiles, atksTilesLen, false, false, true, OBJPRIORITY_0, false ); tileCnt = IO::loadSprite( PAGE_ICON_START + ( 4 ), 0, PAGE_ICON_START + ( 4 ), tileCnt, 60, 0, 32, 32, ContestPal, ContestTiles, ContestTilesLen, false, false, true, OBJPRIORITY_0, false ); for( u8 i = 0; i < 5; ++i ) { IO::OamTop->oamBuffer[ PAGE_ICON_START + i ].x = 48 + 32 * i; IO::OamTop->oamBuffer[ PAGE_ICON_START + i ].y = 256 - 10; } IO::updateOAM( false ); IO::initOAMTable( true ); BG_PALETTE[ COLOR_IDX ] = GREEN; BG_PALETTE[ WHITE_IDX ] = WHITE; BG_PALETTE[ GRAY_IDX ] = GRAY; BG_PALETTE[ BLACK_IDX ] = BLACK; BG_PALETTE[ RED_IDX ] = RED; BG_PALETTE_SUB[ COLOR_IDX ] = GREEN; BG_PALETTE_SUB[ WHITE_IDX ] = WHITE; BG_PALETTE_SUB[ GRAY_IDX ] = GRAY; BG_PALETTE_SUB[ BLACK_IDX ] = BLACK; BG_PALETTE_SUB[ RED_IDX ] = RED; }
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 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); } }
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); } }
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); }
void updateVideo(void) { oamUpdate(states(SUB_SCREEN)); bgUpdate(); }
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; }
static int play(void *userData) { srand(time(NULL)); int scroll = 0; int quit = 0; int down; int redraw = 0; int mapNum = 0; touchPosition touch; gui = new Gui(); console = new Console(); try { anagram = new Anagram(); } catch (const char* err) { delete console; delete gui; return EXIT_FAILURE; } //copy bg tiles decompress(map[mapNum], bgGetMapPtr(1)); reset(); scroll = printList(scroll); console->flush(); keysSetRepeat(30, 6); while(!quit) { swiWaitForVBlank(); bgScrollf(1, -48, 48); bgUpdate(); scanKeys(); if(redraw) { scroll = printList(scroll); console->flush(); } redraw = 0; down = keysDown() | (keysDownRepeat() & (KEY_UP|KEY_DOWN)); if(down & KEY_UP) redraw = 1, scroll--; else if(down & KEY_DOWN) redraw = 1, scroll++; else if(down & KEY_B) redraw = 1, quit = 1; else if(down & KEY_START) redraw = 1, scroll = reset(); else if(down & KEY_X) { redraw = 1; strfry(choices); if(strlen(choices) == strlen(solution)) strcpy(solution, choices); } else if(down & KEY_Y) { mapNum = (mapNum+1)%NUM_MAPS; decompress(map[mapNum], bgGetMapPtr(1)); } if(down & KEY_TOUCH) touchRead(&touch); else memset(&touch, 0, sizeof(touch)); if(gui->update(choices, guess, touch) == GuiRC_Submit) { if(strlen(guess) > 2) { anagram->attempt(guess); addHistory(guess); } memset(guess, 0, sizeof(guess)); memset(choices, 0, sizeof(choices)); strcpy(choices, solution); redraw = 1; } } delete gui; delete console; delete anagram; return EXIT_SUCCESS; }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- const int tile_base = 0; const int map_base = 20; videoSetMode(0); videoSetModeSub(MODE_5_2D); vramSetBankC(VRAM_C_SUB_BG); PrintConsole *console = consoleInit(0, 3, BgType_ExRotation, BgSize_ER_256x256, map_base, tile_base, false, false); ConsoleFont font; font.gfx = (u16*)fontTiles; font.pal = (u16*)fontPal; font.numChars = 95; font.numColors = fontPalLen / 2; font.bpp = 8; font.asciiOffset = 32; font.convertSingleColor = false; consoleSetFont(console, &font); int bg3 = console->bgId; iprintf("Custom Font Demo\n"); iprintf(" by Poffy\n"); iprintf("modified by WinterMute and dovoto\n"); iprintf("for libnds examples\n"); unsigned int angle = 0; int scrollX = 0; int scrollY = 0; int scaleX = intToFixed(1,8); int scaleY = intToFixed(1,8); while(1) { scanKeys(); u32 keys = keysHeld(); if ( keys & KEY_L ) angle+=64; if ( keys & KEY_R ) angle-=64; if ( keys & KEY_LEFT ) scrollX++; if ( keys & KEY_RIGHT ) scrollX--; if ( keys & KEY_UP ) scrollY++; if ( keys & KEY_DOWN ) scrollY--; if ( keys & KEY_A ) scaleX++; if ( keys & KEY_B ) scaleX--; if( keys & KEY_X ) scaleY++; if( keys & KEY_Y ) scaleY--; swiWaitForVBlank(); bgSetRotateScale(bg3, angle, scaleX, scaleY); bgSetScroll(bg3, scrollX, scrollY); bgUpdate(); } }
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; }
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; }