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; }
Graphics::Graphics(void) { //irqInit(); //irqSet(IRQ_VBLANK, 0); setColor(RGB15(20,31,10) | (1<<15)); videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); //videoSetModeSub(MODE_2_2D | DISPLAY_BG3_ACTIVE); vramSetBankA(VRAM_A_MAIN_BG); vramSetBankB(VRAM_B_MAIN_BG); //vramSetBankC(VRAM_C_SUB_BG); REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0); REG_BG3PA = 1 << 8; REG_BG3PB = 0; REG_BG3PC = 0; REG_BG3PD = 1 << 8; videoRam = BG_BMP_RAM(0); //REG_BG3CNT_SUB = BG_BMP16_256x256 | BG_BMP_BASE(0); //REG_BG3PA_SUB = 1<< 8; //REG_BG3PB_SUB = 0; //REG_BG3PC_SUB = 0; //REG_BG3PD_SUB = 1 << 8; //memClone = BG_BMP_RAM_SUB(2); }
void init_displays() { videoSetMode(MODE_5_2D); videoSetModeSub(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_BG); vramSetBankB(VRAM_B_MAIN_BG); lcdMainOnBottom(); }
void Game::initVram() { videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000); videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE| DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_SUB_SPRITE); }
/* 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; }
static void NDS_VideoQuit(_THIS) { videoSetMode(DISPLAY_SCREEN_OFF); videoSetModeSub(DISPLAY_SCREEN_OFF); vramSetBankA(VRAM_A_LCD); vramSetBankB(VRAM_B_LCD); vramSetBankC(VRAM_C_LCD); vramSetBankD(VRAM_D_LCD); vramSetBankE(VRAM_E_LCD); vramSetBankF(VRAM_F_LCD); vramSetBankG(VRAM_G_LCD); vramSetBankH(VRAM_H_LCD); vramSetBankI(VRAM_I_LCD); }
void initMemory() { // Setup video mode for Main: 3D | Text | Text | Text videoSetMode(MODE_5_3D); // Setup video mode for Sub: Text | Text | Rotation | Rotation videoSetModeSub(MODE_5_2D); //Setup Memory Banks vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_TEXTURE); // Set Main screen on bottom REG_POWERCNT &= ~POWER_SWAP_LCDS; }
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) { int i; int memUsageTemp = 0xFFFFFFFF; videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_SPRITE); vramSetBankB(VRAM_B_MAIN_SPRITE); vramSetBankD(VRAM_D_SUB_SPRITE); consoleDemoInit(); // consoleDebugInit(DebugDevice_NOCASH); //send stderr to no$gba debug window //api: initialize OAM to 1D mapping with XX byte offsets and no external palette oamInit(oam, SpriteMapping_1D_128, false); //create some sprites for(i = 0; i < SPRITE_MAX; i++) randomSprite(&sprites[i]); //load a randomly colored palette for(i = 0; i < 256; i++) { SPRITE_PALETTE[i] = rand(); SPRITE_PALETTE_SUB[i] = rand(); } while(1) { moveSprites(); updateSprites(); swiWaitForVBlank(); //api: updates real oam memory oamUpdate(oam); if(oom) { memUsageTemp = memUsageTemp > spriteMemoryUsage ? spriteMemoryUsage : memUsageTemp; } consoleClear(); printf("Memory usage: %i %i%% \n", spriteMemoryUsage, 100 * spriteMemoryUsage / (spriteMemSize)); printf("Percentage fail: %i%% \n", oomCount * 100 / allocationCount); printf("Lowest Usage at fail %i %i%% \n", memUsageTemp, 100 * memUsageTemp / (spriteMemSize)); } return 0; }
void initVideo() { // initialize VRAM banks vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000); vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_SUB_SPRITE); vramSetBankE(VRAM_E_LCD); vramSetBankF(VRAM_F_LCD); vramSetBankG(VRAM_G_LCD); vramSetBankH(VRAM_H_LCD); vramSetBankI(VRAM_I_LCD); // set video modes videoSetMode(MODE_5_2D); videoSetModeSub(MODE_5_2D); }
rtems_device_driver frame_buffer_open (rtems_device_major_number major, rtems_device_minor_number minor, void *arg) { printk ("[#] entering graphic mode on fb%d\n", minor); if (!minor) { videoSetMode (MODE_FB0); vramSetBankA (VRAM_A_LCD); memset ((void *)fb_fix_info.smem_start, 0, fb_fix_info.smem_len); } else { videoSetModeSub (MODE_FB0); vramSetBankB (VRAM_B_LCD); memset ((void *)fb_fix_info2.smem_start, 0, fb_fix_info2.smem_len); } return RTEMS_SUCCESSFUL; }
bool videoStart(const char* file) { vramSetBankB(VRAM_B_LCD); vramSetBankC(VRAM_C_LCD); // videoSetMode(MODE_FB1); if(videoPlaying) return false; videoFile = fopen(file, "rb"); if (videoFile == NULL) return false; timerStart(3, ClockDivider_256, TIMER_FREQ_256(20), videoTick); videoFrames = 0; videoPlaying = true; vramBank = false; return true; }
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(); }
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(); } }
int main() { struct timeval tv; powerON(POWER_ALL); //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); //Use console videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text vramSetBankC(VRAM_C_SUB_BG); SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31,31,31); //by default font will be rendered with color 255 consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); //iprintf("Starting up...\n"); // install the default exception handler defaultExceptionHandler(); //irqs are nice irqInit(); irqEnable(IRQ_VBLANK); // set the generic sound parameters setGenericSound( 11025, /* sample rate */ 127, /* volume */ 64, /* panning */ 1 ); /* sound format*/ glInit(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); //this should work the same as the normal gl call glViewPort(0,0,255,191); glClearColor(0,0,0,0); glClearDepth(0x7FFF); vramSetBankA(VRAM_A_TEXTURE); vramSetBankB(VRAM_B_TEXTURE); logo(); glGenTextures(1, &textureID); glBindTexture(0, textureID); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD , (u8*)die_bmp_bin); glGenTextures(1, &textureID2); glBindTexture(0, textureID2); glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)mario_bmp_bin); gettimeofday(&tv, NULL); //iprintf("Seeding with %d\n", tv.tv_usec); srand(tv.tv_usec); while(1){ gameLoop(); } return 0; }//end main
int main() { int textureID; int i; float rotateX = 0.0; float rotateY = 0.0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // initialize gl glInit(); //enable textures glEnable(GL_TEXTURE_2D); //this should work the same as the normal gl call glViewport(0,0,255,191); // enable antialiasing glEnable(GL_ANTIALIAS); // setup the rear plane glClearColor(0,0,0,31); // BG must be opaque for AA to work glClearPolyID(63); // BG must have a unique polygon ID for AA to work glClearDepth(0x7FFF); vramSetBankB(VRAM_B_LCD); REG_DISPCAPCNT = DCAP_MODE(DCAP_MODE_BLEND) //blend source A and source B //| DCAP_SRC_ADDR //this is not used since we are setting the display to render from VRAM | DCAP_SRC_B(DCAP_SRC_B_VRAM) | DCAP_SRC_A(DCAP_SRC_A_3DONLY) | DCAP_SIZE(DCAP_SIZE_256x192) | DCAP_OFFSET(0) //where to write the captured data within our chosen VRAM bank | DCAP_BANK(DCAP_BANK_VRAM_B) | DCAP_B(12) //blend mostly from B to make a very dramatic effect | DCAP_A(4) //and blend only a little bit from the new scene ; //but, dramatic effects tend to leave some garbage on the screen since the precision of the math is low, //and we're not putting a lot of dampening on the effect. //a more realistic value might be 8 and 8, but perhaps in a more complex 3d scene the garbage isn't such a bad thing //since the scene is changing constantly DisplayEnableMotionBlur(); bool displayBlurred = true; vramSetBankA(VRAM_A_TEXTURE); glGenTextures(1, &textureID); glBindTexture(0, textureID); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin); //any floating point gl call is being converted to fixed prior to being implemented glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 40); gluLookAt( 0.0, 0.0, 1.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up while(1) { glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0); glLight(1, RGB15(31,0,31), 0, floattov10(1) - 1, 0); glLight(2, RGB15(0,31,0) , floattov10(-1.0), 0, 0); glLight(3, RGB15(0,0,31) , floattov10(1.0) - 1, 0, 0); glPushMatrix(); //move it away from the camera glTranslatef32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glMaterialf(GL_AMBIENT, RGB15(8,8,8)); glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); glMaterialf(GL_EMISSION, RGB15(5,5,5)); //ds uses a table for shinyness..this generates a half-ass one glMaterialShinyness(); //not a real gl function and will likely change glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ; scanKeys(); u16 keys = keysHeld(); if((keys & KEY_UP)) rotateX += 3; if((keys & KEY_DOWN)) rotateX -= 3; if((keys & KEY_LEFT)) rotateY += 3; if((keys & KEY_RIGHT)) rotateY -= 3; if(keysDown() & KEY_A) { displayBlurred = !displayBlurred; if(displayBlurred) DisplayEnableMotionBlur(); else DisplayEnableNormal(); } glBindTexture(0, textureID); //draw the obj glBegin(GL_QUAD); for(i = 0; i < 6; i++) drawQuad(i); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); if(keys & KEY_START) break; //the display capture enable bit must be set again each frame if you want to continue capturing. REG_DISPCAPCNT |= DCAP_ENABLE; } return 0; }//end main
int main(void) { mmInitDefaultMem((mm_addr)soundbank_bin); //set video mode and map vram to the background videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE); //set video mode and map vram to the background videoSetModeSub(MODE_1_2D | DISPLAY_BG1_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); vramSetBankD(VRAM_D_MAIN_BG_0x06000000); vramSetBankE(VRAM_E_MAIN_SPRITE); lcdMainOnBottom(); #ifdef BBDEBUG consoleDemoInit(); #endif sound s; s.load_bank(0); sprites spr; machine m(&s); machine_view mv(&spr); #ifndef BBDEBUG thread_view tv; #endif cursor c(&m,&spr); pointer p(&spr); iprintf("%d\n",list::unit_test()); int frame=0; int x=0; int y=0; int tx=0; int ty=0; int dx=0; int dy=0; int touchedlast=0; int tempo=2; int bank=0; u8 flip=0; u8 flip_count=1; irqEnable( IRQ_VCOUNT ); while(1) { // wait until line 0 swiIntrWait( 0, IRQ_VCOUNT); u32 t=tempo; //t=t/(flip+1); //iprintf("%d\n",t); if (tempo==0 || frame%t==0) { m.run(); /* flip_count--; if (flip_count==0) { flip_count=4; if (flip) flip=0; else flip=1; }*/ } scanKeys(); frame++; touchPosition touch; touchRead(&touch); if (keysDown() & KEY_UP) m.slow_down_closest(c.get_cursor_addr()); if (keysDown() & KEY_DOWN) m.speed_up_closest(c.get_cursor_addr()); if (tempo<0) tempo=0; if (keysDown() & KEY_L) sound_check(m); if (keysDown() & KEY_LEFT) { bank--; s.load_bank(bank); } if (keysDown() & KEY_RIGHT) { bank++; s.load_bank(bank); } if(keysDown() & KEY_TOUCH) { tx=touch.px; ty=touch.py; if (!c.touch(tx,ty,&p)) { touchedlast=1; } } else if(keysHeld() & KEY_TOUCH) { if (!c.menu_shown() && !c.drag(touch.px+x,touch.py+y,(touch.px+x)/16,(touch.py+y)/16)) { if (touchedlast>0) touchedlast++; x+=tx-touch.px; y+=ty-touch.py; tx=touch.px; ty=touch.py; } } if (keysUp() & KEY_TOUCH) { if (touchedlast>0 && touchedlast<5) { int lx=(tx+x)/16; int ly=(ty+y)/16; c.set_pos(lx,ly,lx*16,ly*16); } touchedlast=0; } if (keysUp() & KEY_A) { for (u32 i=0; i<HEAP_SIZE; i++) { m.poke(i,rand()); } } c.update(x,y); if (c.menu_shown()) { dx=c.get_x()-128; dy=c.get_y()-82; if (dx!=x) x+=(dx-x)*0.1; if (dy!=y) y+=(dy-y)*0.1; } p.update(x,y,&m); REG_BG0HOFS = x; REG_BG0VOFS = y; spr.update(); mv.update(x,y,&m); s.update(); #ifndef BBDEBUG tv.update(&m); #endif BG_PALETTE_SUB[0]=13<<10; swiWaitForVBlank(); BG_PALETTE_SUB[0]=31; } return 0; }