int main(void) { // Initialize Bottom Screen for printf() PrintConsole topScreen; videoSetMode(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_BG); consoleInit(&topScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleSelect(&topScreen); videoSetModeSub(MODE_5_2D); vramSetBankC(VRAM_C_SUB_BG); bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0,0); decompress(drunkenlogoBitmap, BG_GFX_SUB, LZ77Vram); xTaskCreate(Key_Press, (const signed char * const)"Key_Press", 2048, (void *)NULL, tskIDLE_PRIORITY + 2, NULL); xTaskCreate(Touch_Press, (const signed char * const)"Touch_Press", 2048, (void *)NULL, tskIDLE_PRIORITY + 1, NULL); vTaskStartScheduler(); // Never returns while(1) ; return 0; }
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); }
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); }
void init() { initMemory(); //Init backgrounds // Main 3D init3DSettings(); // Main Map: mapEngine = new MapEngine(1, 4, 1); // Main Console: consoleInit(&main_console,3,BgType_ExRotation, BgSize_ER_256x256, 31, 0, true, false); bg3 = main_console.bgId; bgSetCenter(bg3, 254, 0); bgSetRotate(bg3, -8192); // Sub Console: consoleInit(&sub_console,3,BgType_ExRotation, BgSize_ER_256x256, 31, 1, false, false); bg3Sub = sub_console.bgId; bgSetCenter(bg3Sub, 254, 0); bgSetRotate(bg3Sub, -8192); // Sub Image: bg2Sub = bgInitSub(2, BgType_Bmp8, BgSize_B8_256x256, 4,0); dmaCopy(leftmenuBitmap, bgGetGfxPtr(bg2Sub), 256*192); dmaCopy(leftmenuPal, BG_PALETTE_SUB, leftmenuPalLen); // Init Sprites oamInit(&oamMain, SpriteMapping_1D_128, false); // Set the priorities bgSetPriority(0,1); bgSetPriority(1,2); bgSetPriority(2,3); bgSetPriority(3,0); bgSetPriority(bg3Sub, 2); bgSetPriority(bg2Sub, 3); //Init 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(&main_console, &font); consoleSetFont(&sub_console, &font); consoleSelect(&main_console); iprintf("\x1b[2J"); iprintf("Arkham Tower v0.01"); consoleSelect(&sub_console); iprintf("\x1b[2J"); }
void initConsole(void) { int sz = 0; u16* consoleGfx = bufferFile("font.img.bin", &sz); if(consoleGfx) { consoleId = bgInitSub(0, BgType_Text4bpp, BgSize_T_256x256, 2,0); dmaCopy(consoleGfx, bgGetGfxPtr(consoleId), sz); col = row = 0; consoleMap = bgGetMapPtr(consoleId); free(consoleGfx); } }
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 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(); }
int main(void) { // Video setup lcdMainOnBottom(); irqEnable(IRQ_VBLANK); vramSetBankC(VRAM_C_SUB_BG); // Text console videoSetModeSub(MODE_5_2D); PrintConsole *pc = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false, true); BG_PALETTE_SUB[255] = RGB15(31,15,0); bgSetPriority(pc->bgId, 0); // DSMI Logo int bg2 = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0); bgSetPriority(bg2, 1); u16 *bg2vram = bgGetGfxPtr(bg2); dmaCopy(dsmi_logo_dsBitmap, bg2vram, 256*192); iprintf("\x1b[12;12HPulse DS\n"); // Connect int res = dsmi_connect(); while(res == 0) { iprintf("\x1b[15;0H\x1b[KCould not connect. We apologize for the inconvecience.\n"); while(1); } iprintf("\x1b[15;0H\x1b[KRunning.\n"); u8 message, data1, data2; while(1) { // We query every 60th of a second (notice the swiWaitForVBlank). // For lower latency you should query more frequently. // Query and play until there are no more new messages while(dsmi_read(&message, &data1, &data2)) { printf("0x%x 0x%x 0x%x\n", message, data1, data2); midiToArm7(message, data1, data2); } swiWaitForVBlank(); } return 0; }
static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { display->driverdata = mode->driverdata; #ifdef USE_HW_RENDERER videoSetMode(MODE_5_3D); videoSetModeSub(MODE_5_2D); /* initialize gl2d */ glScreen2D(); vramSetBankA(VRAM_A_TEXTURE); vramSetBankB(VRAM_B_TEXTURE ); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankE(VRAM_E_TEX_PALETTE); powerOn(POWER_ALL_2D); irqInit(); irqEnable(IRQ_VBLANK); // sub sprites hold the bottom image when 3D directed to top initSubSprites(); // sub background holds the top image when 3D directed to bottom bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); #else /* Select mode 5 for both screens. Can do Extended Rotation * Background on both (BG 2 and 3). */ videoSetMode(MODE_5_2D); videoSetModeSub(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_TEXTURE ); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankE(VRAM_E_TEX_PALETTE); powerOn(POWER_ALL_2D); irqInit(); irqEnable(IRQ_VBLANK); #endif return 0; }
//--------------------------------------------------------------------------------- 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 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; }
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; }
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(); }
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; }
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() { //------------------------------------------------------- videoSetMode(MODE_0_3D); videoSetModeSub(MODE_5_2D); glInit(); // sub sprites hold the bottom image when 3D directed to top initSubSprites(); // sub background holds the top image when 3D directed to bottom bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); //------------------------------------------------------- // Setup gl //------------------------------------------------------- glEnable(GL_ANTIALIAS); glClearColor(0,0,0,31); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0,0,255,191); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); //------------------------------------------------------- // main loop //------------------------------------------------------- bool top = true; while (true) { // wait for capture unit to be ready while(REG_DISPCAPCNT & DCAP_ENABLE); scanKeys(); int keys = keysDown(); if (keys & KEY_START) break; //------------------------------------------------------- // Switch render targets //------------------------------------------------------- top = !top; if(top) { lcdMainOnBottom(); vramSetBankC(VRAM_C_LCD); vramSetBankD(VRAM_D_SUB_SPRITE); REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3); } else { lcdMainOnTop(); vramSetBankD(VRAM_D_LCD); vramSetBankC(VRAM_C_SUB_BG); REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3); } //------------------------------------------------------- // Render the scene //------------------------------------------------------- glMatrixMode(GL_MODELVIEW); renderScene(top); glFlush(0); } return 0; }
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); }
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; }