void Display::slidersUpdate(){ bool change = false; if (Cfg::sliders.bank != Cfg::sliders.previousBank){ sliders(); Cfg::sliders.previousBank = Cfg::sliders.bank; change = true; } CCParam* sliderCC; for (u8 s = 0; s < 16; ++s){ sliderCC = &Cfg::sliders.ccs[Cfg::sliders.bank][s]; if (Cfg::ccChangedVblank[(*sliderCC).channel][(*sliderCC).cc]){ updateSliderUpMap(s); change = true; } } DC_FlushAll(); dmaCopy(this->slidersBg2Map, bgGetMapPtr(subbg2), 1536); if (change){ DC_FlushAll(); dmaCopy(this->slidersBg3Map, bgGetMapPtr(subbg3), 1536); } showBank(Cfg::sliders.bank, 3); }
void Display::modeSelektor(){ //Displaying bg3, and mode sprites bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(subbg3); s8 i; for (i = 0; i < 4; ++i){ modesSprite->display(64 + i, 32 + 128 * (i % 2), 16 + 96 * (i / 2), OBJPRIORITY_0, i); } oamUpdate(&oamSub); input->paused = true; while(!(Cfg::modeSelector && input->pad->select() == DOWN) && input->modeSelektor() != 1){ swiWaitForVBlank(); } Cfg::modeSelector = false; oamClear(&oamSub, 64, 4); if (Cfg::mode == SLIDERS){ dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(this->subbg3), slidersBg3SubTilesLen); dmaCopy(this->slidersBg3Map, bgGetMapPtr(this->subbg3), 1536); } else { bgSetPriority(this->subbg3, 2); bgHide(this->subbg3); } }
void Console::print(int x, int y, const char *format, ...) { #define MAX_BUFFER 32*32 static char msg[MAX_BUFFER]; va_list arg_ptr; u8 *buf = (u8*)msg; u16 *map = bgGetMapPtr(bg) + (x+y*32); u16 *end = bgGetMapPtr(bg) + 32*32; va_start(arg_ptr, format); vsnprintf(msg, MAX_BUFFER, format, arg_ptr); va_end(arg_ptr); for(; map < end && *buf; buf++) { switch(*buf) { case '\n': map = (u16*)(((int)(map+32))%32); break; case ' ' ... '~': *map++ = ((*buf)-' ') | (pal<<12); break; default: *map++ = 0; } } }
void Outro_LoadResources(int grid_bg_main_id, int grid_bg_sub_id) { /* Copy tile, map and palette data into VRAM */ dmaCopy(gridTiles, bgGetGfxPtr(grid_bg_main_id), gridTilesLen); dmaCopy(gridMap, bgGetMapPtr(grid_bg_main_id), gridMapLen); dmaCopy(gridPal, BG_PALETTE + 0x2, gridPalLen); dmaCopy(gridTiles, bgGetGfxPtr(grid_bg_sub_id), gridTilesLen); dmaCopy(gridMap, bgGetMapPtr(grid_bg_sub_id), gridMapLen); dmaCopy(gridPal, BG_PALETTE_SUB + 0x2, gridPalLen); }
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 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 Display::editKaossParams(){ CCParam* ccParam = NULL; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<3; ++i){ if (i == 0){ echo(0, RED, 5, 7 + 8*(i%8), "X"); ccParam = &Cfg::kaoss.x[Cfg::kaoss.bank]; } if (i == 1){ echo(0, RED, 5, 7 + 8*(i%8), "Y"); ccParam = &Cfg::kaoss.y[Cfg::kaoss.bank]; } if (i == 2){ echo(0, RED, 5, 7 + 8*(i%8), "Z"); ccParam = &Cfg::kaoss.z[Cfg::kaoss.bank]; } echo(0, WHITE, 8, 7 + 8*(i%8), "CC"); paramsEditSprite->display(16+i, 56 + 64*(i%8), 72, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 10, 6 + 8*(i%8), (*ccParam).cc); paramsEditSprite->display(32+i, 56 + 64*(i%8), 88, OBJPRIORITY_0, 1); echo(0, WHITE, 13, 7 + 8*(i%8), "CH"); paramsEditSprite->display(48+i, 56 + 64*(i%8), 112, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 15, 6 + 8*(i%8), 1 + (*ccParam).channel); paramsEditSprite->display(64+i, 56 + 64*(i%8), 128, OBJPRIORITY_0, 1); } oamUpdate(&oamSub); input->editKaossParams(); Cfg::editParams = true; swiWaitForVBlank(); } Cfg::editParams = false; save->write(); oamClear(&oamSub, 16, 80); consoleClear(); if (Cfg::mode == SLIDERS){ dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(this->subbg3), slidersBg3SubTilesLen); dmaCopy(slidersBg3Map, bgGetMapPtr(this->subbg3), 1536); } else { bgSetPriority(this->subbg3, 2); bgHide(this->subbg3); } }
void Target::drawUpdate() { volatile u16* mapPtr = (volatile u16*)bgGetMapPtr(bgHandle); if(state < 5) { mapPtr[pos2idx(xPos*2, yPos*2)] = ((paletteIndex << 12) | (tileBase+state*4)); mapPtr[pos2idx(xPos*2+1, yPos*2)] = ((paletteIndex << 12) | (tileBase+1+state*4)); mapPtr[pos2idx(xPos*2, yPos*2+1)] = ((paletteIndex << 12) | (tileBase+2+state*4)); mapPtr[pos2idx(xPos*2+1, yPos*2+1)] = ((paletteIndex << 12) | (tileBase+3+state*4)); if(state > 0) { if(frameCounter > 4) { state++; frameCounter = 0; } else { ++frameCounter; } } } else if(state == 5) { mapPtr[pos2idx(xPos*2, yPos*2)] = 0; mapPtr[pos2idx(xPos*2+1, yPos*2)] = 0; mapPtr[pos2idx(xPos*2, yPos*2+1)] = 0; mapPtr[pos2idx(xPos*2+1, yPos*2+1)] = 0; state++; //Notify the level that a target was destroyed level->targetDestroyed(this); } }
Mirror::~Mirror() { volatile u16* mirrorMapPtr = (volatile u16*)bgGetMapPtr(mirrorBgHandle); //clear the 4 base tiles on the map mirrorMapPtr[pos2idx(xPos*2, yPos*2)] = 0; mirrorMapPtr[pos2idx(xPos*2+1, yPos*2)] = 0; mirrorMapPtr[pos2idx(xPos*2, yPos*2+1)] = 0; mirrorMapPtr[pos2idx(xPos*2+1, yPos*2+1)] = 0; }
void copyMap(void) { int mapOffset = (gpu.control & GPU_CONTROL_TILEMAP) ? 0x1c00 : 0x1800; mapOffset += ((gpu.scrollY & 255) >> 3) << 5; int x, y; for(y = 0; y < 144 / 8; y++) { for(x = 0; x < 160 / 8; x++) { bgGetMapPtr(layer)[((256 - 160) / 2) / 8 + x + (y + ((192 - 144) / 2) / 8) * 256 / 8] = vram[mapOffset + x + y * 256 / 8]; } } }
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 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 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); } }
// MIXER Functions //------------------------------------------------------------------------- void Display::mixer(){ clearGfx(); DC_FlushAll(); dmaCopy(mixerBgSubTiles, bgGetGfxPtr(subbg2), mixerBgSubTilesLen); dmaCopy(mixerBgSubMap, bgGetMapPtr(subbg2), mixerBgSubMapLen); for (u8 i = 0; i < 8; ++i) muteSprite->display(i, i*32 , 163, 1, 1); bgHide(mainbg3); save->writeCcs(); }
void Mirror::drawUpdate() { if(needsUpdate) { volatile u16* mapPtr = (volatile u16*)bgGetMapPtr(bgHandle); volatile u16* mirrorMapPtr = (volatile u16*)bgGetMapPtr(mirrorBgHandle); //fill in the 4 base tiles on the map mirrorMapPtr[pos2idx(xPos*2, yPos*2)] = ((paletteIndex << 12) | mirrorTileBase); mirrorMapPtr[pos2idx(xPos*2+1, yPos*2)] = ((paletteIndex << 12) | (mirrorTileBase+1)); mirrorMapPtr[pos2idx(xPos*2, yPos*2+1)] = ((paletteIndex << 12) | (mirrorTileBase+2)); mirrorMapPtr[pos2idx(xPos*2+1, yPos*2+1)] = ((paletteIndex << 12) | (mirrorTileBase+3)); //fill in the 4 mirror-position tiles int angleTileIdx = 4+(4*angle); mapPtr[pos2idx(xPos*2,yPos*2)] = ((paletteIndex << 12) | (mirrorTileBase+angleTileIdx)); mapPtr[pos2idx(xPos*2+1,yPos*2)] = ((paletteIndex << 12) | (mirrorTileBase+angleTileIdx+1)); mapPtr[pos2idx(xPos*2,yPos*2+1)] = ((paletteIndex << 12) | (mirrorTileBase+angleTileIdx+2)); mapPtr[pos2idx(xPos*2+1,yPos*2+1)] = ((paletteIndex << 12) | (mirrorTileBase+angleTileIdx+3)); needsUpdate = false; } }
// SLIDERS Functions //------------------------------------------------------------------------- void Display::sliders(){ clearGfx(); for(u8 i = 0; i<16; ++i){ this->updateSliderMap(i); this->updateSliderUpMap(i); } DC_FlushAll(); dmaCopy(slidersBg2SubTiles, bgGetGfxPtr(subbg2), slidersBg2SubTilesLen); dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(subbg3), slidersBg3SubTilesLen); DC_FlushAll(); dmaCopy(slidersBg2Map, bgGetMapPtr(subbg2), 1536); dmaCopy(slidersBg3Map, bgGetMapPtr(subbg3), 1536); echo(1, LIGHT_GREY, 1, 2, "BANK:"); echo(1, WHITE, 6, 3, "BANK-"); echo(1, WHITE, 6, 19, "BANK;"); bgHide(mainbg3); save->writeCcs(); }
static inline void writecharRS (int row, int col, u16 car) { // get map pointer u16 *gfx = bgGetMapPtr(bg2); // get old pair of values from VRAM u16 oldval = gfx[row*(512/8/2)+(col/2)]; // clear the half we will update oldval &= (col%2) ? 0x00FF : 0xFF00; // apply the updated half oldval |= (col%2) ? (car<<8) : car; // write back to VRAM gfx[row*(512/8/2)+col/2] = oldval; }
// KAOSS Functions //------------------------------------------------------------------------- void Display::kaoss(){ u16 i; clearGfx(); dmaCopy(kaossBgSubTiles, bgGetGfxPtr(subbg2), kaossBgSubTilesLen); dmaCopy(kaossBgSubMap, bgGetMapPtr(subbg2), kaossBgSubMapLen); for (i = 0; i < 64; ++i) setKaossSpriteFrame(i, 0); bgHide(mainbg3); echo(1, LIGHT_GREY, 1, 2, "BANK:"); save->writeCcs(); }
void Display::editMixerParams(){ CCParam ccParam; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); echo(0, RED, 0, 13, "MIXER"); echo(0, RED, 12, 13, "MUTES"); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<8; ++i){ ccParam = Cfg::mixer.ccs[i]; echo(0, WHITE, 2, 1 + 4*(i%8), "CC"); paramsEditSprite->display(16+i, 8 + 32*(i%8), 24, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 4, 4*(i%8), ccParam.cc); paramsEditSprite->display(32+i, 8 + 32*(i%8), 40, OBJPRIORITY_0, 1); echo(0, WHITE, 6, 1 + 4*(i%8), "CH"); paramsEditSprite->display(48+i, 8 + 32*(i%8), 56, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 8, 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(64+i, 8 + 32*(i%8), 72, OBJPRIORITY_0, 1); ccParam = Cfg::mixer.mutes[i]; echo(0, WHITE, 14, 1 + 4*(i%8), "CC"); paramsEditSprite->display(24+i, 8 + 32*(i%8), 120, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 16, 4*(i%8), ccParam.cc); paramsEditSprite->display(40+i, 8 + 32*(i%8), 136, OBJPRIORITY_0, 1); echo(0, WHITE, 18, 1 + 4*(i%8), "CH"); paramsEditSprite->display(56+i, 8 + 32*(i%8), 152, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 20, 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(72+i, 8 + 32*(i%8), 168, OBJPRIORITY_0, 1); } oamUpdate(&oamSub); input->editMixerParams(); Cfg::editParams = true; swiWaitForVBlank(); } save->write(); Cfg::editParams = false; oamClear(&oamSub, 16, 80); consoleClear(); }
//--------------------------------------------------------------------------------- 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 SpinBlocker::drawUpdate() { volatile u16* mapPtr = (volatile u16*)bgGetMapPtr(bgHandle); mapPtr[pos2idx(xPos*2, yPos*2)] = ((paletteIndex << 12) | (tileBase+angle*4)); mapPtr[pos2idx(xPos*2+1, yPos*2)] = ((paletteIndex << 12) | (tileBase+1+angle*4)); mapPtr[pos2idx(xPos*2, yPos*2+1)] = ((paletteIndex << 12) | (tileBase+2+angle*4)); mapPtr[pos2idx(xPos*2+1, yPos*2+1)] = ((paletteIndex << 12) | (tileBase+3+angle*4)); if(frameCounter > ANIMATION_DELAY) { angle++; if(angle & 8) angle = 0; frameCounter = 0; } else { ++frameCounter; } }
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 Display::editSliderParams(){ CCParam ccParam; u8 color; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<16; ++i){ ccParam = Cfg::sliders.ccs[Cfg::sliders.bank][i]; color = Cfg::sliders.colors[Cfg::sliders.bank][i]; echo(0, WHITE, 12*(i/8) , 1 + 4*(i%8), "CC"); paramsEditSprite->display(16+i, 8 + 32*(i%8), 8 + 96*(i/8), OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 2 + 12*(i/8) , 4*(i%8), ccParam.cc); paramsEditSprite->display(32+i, 8 + 32*(i%8), 24 + 96*(i/8), OBJPRIORITY_0, 1); echo(0, WHITE, 4+12*(i/8) , 1 + 4*(i%8), "CH"); paramsEditSprite->display(48+i, 8 + 32*(i%8), 40 + 96*(i/8), OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 6 + 12*(i/8) , 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(64+i, 8 + 32*(i%8), 56 + 96*(i/8), OBJPRIORITY_0, 1); paramsEditSprite->display(80+i, 8 + 32*(i%8), 72 + 96*(i/8), OBJPRIORITY_0, color + 2); } oamUpdate(&oamSub); input->editSliderParams(); Cfg::editParams = true; swiWaitForVBlank(); } save->write(); Cfg::editParams = false; oamClear(&oamSub, 16, 80); consoleClear(); sliders(); }
void Laser::drawUpdate() { volatile u16* mapPtr = (volatile u16*)bgGetMapPtr(bgHandle); switch (dir) { case UP: //facing up mapPtr[pos2idx(xPos*2, yPos*2)] = ((paletteIndex << 12) | laserTileBase); mapPtr[pos2idx(xPos*2+1, yPos*2)] = ((paletteIndex << 12) | (laserTileBase+1)); mapPtr[pos2idx(xPos*2, yPos*2+1)] = ((paletteIndex << 12) | (laserTileBase+2)); mapPtr[pos2idx(xPos*2+1, yPos*2+1)] = ((paletteIndex << 12) | (laserTileBase+3)); break; case RIGHT: //facing right mapPtr[pos2idx(xPos*2, yPos*2)] = ((paletteIndex << 12) | (laserTileBase+4)); mapPtr[pos2idx(xPos*2+1, yPos*2)] = ((paletteIndex << 12) | (laserTileBase+5)); mapPtr[pos2idx(xPos*2, yPos*2+1)] = ((paletteIndex << 12) | (laserTileBase+6)); mapPtr[pos2idx(xPos*2+1, yPos*2+1)] = ((paletteIndex << 12) | (laserTileBase+7)); break; case DOWN: //facing down - facing up mirrored mapPtr[pos2idx(xPos*2, yPos*2)] = ((paletteIndex << 12) | (laserTileBase+2) | BIT(11)); mapPtr[pos2idx(xPos*2+1, yPos*2)] = ((paletteIndex << 12) | (laserTileBase+3) | BIT(11)); mapPtr[pos2idx(xPos*2, yPos*2+1)] = ((paletteIndex << 12) | laserTileBase | BIT(11)); mapPtr[pos2idx(xPos*2+1, yPos*2+1)] = ((paletteIndex << 12) | (laserTileBase+1) | BIT(11)); break; case LEFT: //facing left - facing right mirrored mapPtr[pos2idx(xPos*2, yPos*2)] = ((paletteIndex << 12) | (laserTileBase+5) | BIT(10)); mapPtr[pos2idx(xPos*2+1, yPos*2)] = ((paletteIndex << 12) | (laserTileBase+4) | BIT(10)); mapPtr[pos2idx(xPos*2, yPos*2+1)] = ((paletteIndex << 12) | (laserTileBase+7) | BIT(10)); mapPtr[pos2idx(xPos*2+1, yPos*2+1)] = ((paletteIndex << 12) | (laserTileBase+6) | BIT(10)); break; default: break; } }
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; }
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; }
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"); }
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; }