int main(int argc, char* argv[]) { if( Initialize() ) { #ifdef DAEDALUS_BATCH_TEST_ENABLED if( argc > 1 ) { BatchTestMain( argc, argv ); } #else //Makes it possible to load a ROM directly without using the GUI //There are no checks for wrong file name so be careful!!! //Ex. from PSPLink -> ./Daedalus.prx "Roms/StarFox 64.v64" //Corn if( argc > 1 ) { printf("Loading %s\n", argv[1] ); System_Open( argv[1] ); CPU_Run(); System_Close(); Finalise(); sceKernelExitGame(); return 0; } #endif //Translate_Init(); bool show_splash = true; for(;;) { DisplayRomsAndChoose( show_splash ); show_splash = false; // // Commit the preferences and roms databases before starting to run // CRomDB::Get()->Commit(); CPreferences::Get()->Commit(); CPU_Run(); System_Close(); } Finalise(); } sceKernelExitGame(); return 0; }
int main(void) { int i; defaultExceptionHandler(); irqEnable(IRQ_VBLANK); irqEnable(IRQ_HBLANK); irqSet(IRQ_VBLANK, vblank_idle); fifoSetValue32Handler(FIFO_USER_02, arm7print, NULL); fifoSetValue32Handler(FIFO_USER_03, sleepMode, NULL); //vramSetBankA(VRAM_A_LCD); videoSetMode(MODE_0_2D); // map some VRAM // bank C to ARM7, bank H for subscreen graphics *(vu8*)0x04000242 = 0x82; *(vu8*)0x04000248 = 0x81; videoSetModeSub(MODE_0_2D); consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, false, true); *(vu16*)0x0400100A = 0x0300; setBackdropColorSub(0x7C00); // configure BLDCNT so that backdrop becomes black *(vu16*)0x04001050 = 0x00E0; *(vu8*)0x04001054 = 16; // enable window 0 and disable color effects inside it *(vu16*)0x04001000 |= 0x2000; *(vu16*)0x04001048 = 0x001F; *(vu16*)0x0400104A = 0x003F; toggleConsole(false); #ifdef NITROFS_ROM if (!nitroFSInit()) #else if (!fatInitDefault()) #endif { toggleConsole(true); iprintf("FAT init failed\n"); return -1; } makeROMList(); makeMenu(); iprintf("lolSnes " VERSION " -- by Mega-Mario\n"); for (;;) { if (keypress != 0x03FF) { if (!(keypress & 0x0040)) // up { menusel--; if (menusel < 0) menusel = 0; if (menusel < menuscroll) menuscroll = menusel; makeMenu(); } else if (!(keypress & 0x0080)) // down { menusel++; if (menusel > nfiles-1) menusel = nfiles-1; if (menusel-21 > menuscroll) menuscroll = menusel-21; makeMenu(); } else if ((keypress & 0x0003) != 0x0003) // A/B { strncpy(fullpath, "snes/", 5); strncpy(fullpath + 5, &filelist[menusel << 8], 256); if (!Mem_LoadROM(fullpath)) { iprintf("ROM loading failed\n"); continue; } *(vu16*)0x04001000 &= 0xDFFF; toggleConsole(true); iprintf("ROM loaded, running\n"); CPU_Reset(); fifoSendValue32(FIFO_USER_01, 1); swiWaitForVBlank(); fifoSendValue32(FIFO_USER_01, 2); irqSet(IRQ_VBLANK, vblank); irqSet(IRQ_HBLANK, PPU_HBlank); swiWaitForVBlank(); CPU_Run(); } keypress = 0x03FF; } swiWaitForVBlank(); } return 0; }
void BatchTestMain( int argc, char* argv[] ) { // TODO: Allow other directories and configuration #ifdef DAEDALUS_PSP const char * const romdir = "host1:/"; #else const char * const romdir = g_DaedalusConfig.mRomsDir; #endif bool random_order( false ); // Whether to randomise the order of processing, to help avoid hangs bool update_results( false ); // Whether to update existing results s32 run_id( -1 ); // New run by default for(int i = 1; i < argc; ++i ) { const char * arg( argv[i] ); if( *arg == '-' ) { ++arg; if( strcmp( arg, "rand" ) == 0 || strcmp( arg, "random" ) == 0 ) { random_order = true; } else if( strcmp( arg, "u" ) == 0 || strcmp( arg, "update" ) == 0 ) { update_results = true; } else if( strcmp( arg, "r" ) == 0 || strcmp( arg, "run" ) == 0 ) { if( i+1 < argc ) { ++i; // Consume next arg run_id = atoi( argv[i] ); } } } } IO::Filename batchdir; Dump_GetDumpDirectory( batchdir, "batch" ); IO::Filename rundir; if( run_id < 0 ) { if( !MakeRunDirectory( rundir, batchdir ) ) { printf( "Couldn't start a new run\n" ); return; } } else { SprintRunDirectory( rundir, batchdir, run_id ); if( !IO::Directory::IsDirectory( rundir ) ) { printf( "Couldn't resume run %d\n", run_id ); return; } } gBatchTestEventHandler = new CBatchTestEventHandler(); IO::Filename logpath; MakeNewLogFilename( logpath, rundir ); gBatchFH = fopen(logpath, "w"); if( !gBatchFH ) { printf( "Unable to open '%s' for writing", logpath ); return; } std::vector< std::string > roms; MakeRomList( romdir, roms ); u64 time; if( NTiming::GetPreciseTime( &time ) ) srand( (int)time ); CTimer timer; // Set up an assert hook to capture all asserts SetAssertHook( BatchAssertHook ); // Hook in our Vbl handler. CPU_RegisterVblCallback( &BatchVblHandler, NULL ); IO::Filename tmpfilepath; IO::Path::Combine( tmpfilepath, rundir, "tmp.tmp" ); while( !roms.empty() ) { gBatchTestEventHandler->Reset(); u32 idx( 0 ); // Picking roms in a random order means we can work around roms which crash the emulator a little more easily if( random_order ) idx = rand() % roms.size(); std::string r; r.swap( roms[idx] ); roms.erase( roms.begin() + idx ); // Make a filename of the form: '<rundir>/<romfilename>.txt' IO::Filename rom_logpath; IO::Path::Combine( rom_logpath, rundir, IO::Path::FindFileName( r.c_str() ) ); IO::Path::SetExtension( rom_logpath, ".txt" ); bool result_exists( IO::File::Exists( rom_logpath ) ); if( !update_results && result_exists ) { // Already exists, skip fprintf( gBatchFH, "\n\n%#.3f: Skipping %s - log already exists\n", timer.GetElapsedSecondsSinceReset(), r.c_str() ); } else { fprintf( gBatchFH, "\n\n%#.3f: Processing: %s\n", timer.GetElapsedSecondsSinceReset(), r.c_str() ); gRomLogFH = fopen( tmpfilepath, "w" ); if( !gRomLogFH ) { fprintf( gBatchFH, "#%.3f: Unable to open temp file\n", timer.GetElapsedSecondsSinceReset() ); } else { fflush( gBatchFH ); // TODO: use ROM_GetRomDetailsByFilename and the alternative form of ROM_LoadFile with overridden preferences (allows us to test if roms break by changing prefs) System_Open( r.c_str() ); CPU_Run(); System_Close(); const char * reason( CBatchTestEventHandler::GetTerminationReasonString( gBatchTestEventHandler->GetTerminationReason() ) ); fprintf( gBatchFH, "%#.3f: Finished running: %s - %s\n", timer.GetElapsedSecondsSinceReset(), r.c_str(), reason ); // Copy temp file over rom_logpath gBatchTestEventHandler->PrintSummary( gRomLogFH ); fclose( gRomLogFH ); gRomLogFH = NULL; if( result_exists ) { IO::File::Delete( rom_logpath ); } if( !IO::File::Move( tmpfilepath, rom_logpath ) ) { fprintf( gBatchFH, "%#.3f: Coping %s -> %s failed\n", timer.GetElapsedSecondsSinceReset(), tmpfilepath, rom_logpath ); } } } } CPU_UnregisterVblCallback( &BatchVblHandler, NULL ); SetAssertHook( NULL ); fclose( gBatchFH ); gBatchFH = NULL; delete gBatchTestEventHandler; gBatchTestEventHandler = NULL; }
int main() { int i, x, y; touchPosition lastTouch; u32 repeatkeys = 0; int repeatstate = 0; int repeatcount = 0; running = 0; pause = 0; exitemu = 0; PPU_Init(); srvInit(); aptInit(); aptOpenSession(); APT_SetAppCpuTimeLimit(NULL, 30); // enables syscore usage aptCloseSession(); gfxInit(); hidInit(NULL); fsInit(); GPU_Init(NULL); gpuCmdSize = 0x40000; gpuCmd = (u32*)linearAlloc(gpuCmdSize*4); GPU_Reset(gxCmdBuf, gpuCmd, gpuCmdSize); shader = SHDR_ParseSHBIN((u32*)blarg_shbin, blarg_shbin_size); GX_SetMemoryFill(gxCmdBuf, (u32*)gpuOut, 0x404040FF, (u32*)&gpuOut[0x2EE00], 0x201, (u32*)gpuDOut, 0x00000000, (u32*)&gpuDOut[0x2EE00], 0x201); gfxSwapBuffersGpu(); UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL)); BorderTex = (u32*)linearAlloc(512*256*4); MainScreenTex = (u32*)linearAlloc(512*256*4); SubScreenTex = (u32*)linearAlloc(512*256*4); BrightnessTex = (u8*)linearAlloc(8*256); borderVertices = (float*)linearAlloc(5*3 * 2 * sizeof(float)); screenVertices = (float*)linearAlloc(7*3 * 2 * sizeof(float)); float* fptr = &vertexList[0]; for (i = 0; i < 5*3*2; i++) borderVertices[i] = *fptr++; for (i = 0; i < 7*3*2; i++) screenVertices[i] = *fptr++; sdmcArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}}; FSUSER_OpenArchive(NULL, &sdmcArchive); if (!LoadBorder("/blargSnesBorder.bmp")) CopyBitmapToTexture(defaultborder, BorderTex, 400, 240, 0xFF, 0, 64, true); CopyBitmapToTexture(screenfill, PPU_MainBuffer, 256, 224, 0, 16, 64, false); memset(PPU_SubBuffer, 0, 256*256*4); memset(PPU_Brightness, 0xFF, 224); UI_Switch(&UI_ROMMenu); svcCreateEvent(&SPCSync, 0); aptSetupEventHandler(); APP_STATUS status; while((status = aptGetStatus()) != APP_EXITING) { if(status == APP_RUNNING) { svcSignalEvent(SPCSync); hidScanInput(); u32 press = hidKeysDown(); u32 held = hidKeysHeld(); u32 release = hidKeysUp(); GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0); RenderTopScreen(); GPUCMD_Finalize(); GPUCMD_Run(gxCmdBuf); if (running) { // emulate CPU_Run(); // runs the SNES for one frame. Handles PPU rendering. // SRAM autosave check // TODO: also save SRAM under certain circumstances (pausing, returning to home menu, etc) framecount++; if (!(framecount & 7)) SNES_SaveSRAM(); } else { // update UI if (held & KEY_TOUCH) { hidTouchRead(&lastTouch); UI_Touch(true, lastTouch.px, lastTouch.py); held &= ~KEY_TOUCH; } else if (release & KEY_TOUCH) { UI_Touch(false, lastTouch.px, lastTouch.py); release &= ~KEY_TOUCH; } if (press) { UI_ButtonPress(press); // key repeat repeatkeys = press & (KEY_UP|KEY_DOWN|KEY_LEFT|KEY_RIGHT); repeatstate = 1; repeatcount = 15; } else if (held == repeatkeys) { repeatcount--; if (!repeatcount) { repeatcount = 7; if (repeatstate == 2) UI_ButtonPress(repeatkeys); else repeatstate = 2; } } } UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL)); UI_Render(); /*GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0); RenderTopScreen(); GPUCMD_Finalize(); GPUCMD_Run(gxCmdBuf);*/ // flush the bottomscreen cache while the PICA200 is busy rendering GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), 0x38400); // wait for the PICA200 to finish drawing gspWaitForP3D(); // copy new screen textures // SetDisplayTransfer with flags=2 converts linear graphics to the tiled format used for textures GX_SetDisplayTransfer(gxCmdBuf, PPU_MainBuffer, 0x01000200, MainScreenTex, 0x01000200, 0x2); gspWaitForPPF(); GX_SetDisplayTransfer(gxCmdBuf, PPU_SubBuffer, 0x01000200, SubScreenTex, 0x01000200, 0x2); gspWaitForPPF(); // copy brightness. // TODO do better u8* bptr = BrightnessTex; for (i = 0; i < 224;) { u32 pixels = *(u32*)&PPU_Brightness[i]; i += 4; *bptr = (u8)pixels; pixels >>= 8; bptr += 2; *bptr = (u8)pixels; pixels >>= 8; bptr += 6; *bptr = (u8)pixels; pixels >>= 8; bptr += 2; *bptr = (u8)pixels; pixels >>= 8; bptr += 22; } // transfer the final color buffer to the LCD and clear it // we can mostly overlap those two operations GX_SetDisplayTransfer(gxCmdBuf, gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000); svcSleepThread(20000); GX_SetMemoryFill(gxCmdBuf, gpuOut, 0x404040FF, &gpuOut[0x2EE00], 0x201, gpuDOut, 0x00000000, &gpuDOut[0x2EE00], 0x201); gspWaitForPPF(); gspWaitForPSC0(); gspWaitForEvent(GSPEVENT_VBlank0, false); gfxSwapBuffersGpu(); } else if(status == APP_SUSPENDING)