void Emulator_Start() { if(need_load_rom) { LOG_DBG("need_load_rom: %d\n", need_load_rom); if(Emulator_Initialize()) { need_load_rom = false; } } //bring down dbgfont Graphics->DeinitDbgFont(); if (Graphics->GetCurrentResolution() == CELL_VIDEO_OUT_RESOLUTION_576) { if(Graphics->CheckResolution(CELL_VIDEO_OUT_RESOLUTION_576)) { if(vdp_pal) { if(Graphics->GetPAL60Hz()) { //PAL60 is ON, turn it off for PAL Graphics->SetPAL60Hz(false); Settings.PS3PALTemporalMode60Hz = false; Graphics->SwitchResolution(Graphics->GetCurrentResolution(), Settings.PS3PALTemporalMode60Hz); } } else { if(!Graphics->GetPAL60Hz()) { //PAL60 is OFF, turn it on for NTSC Graphics->SetPAL60Hz(true); Settings.PS3PALTemporalMode60Hz = true; Graphics->SwitchResolution(Graphics->GetCurrentResolution(), Settings.PS3PALTemporalMode60Hz); } } } } CellAudio->unpause(); while(emulation_running) { system_frame(0); Graphics->Draw(bitmap.viewport.w,bitmap.viewport.h,bitmap.data); Graphics->Swap(); PlaySound(); //check interlaced mode change if (bitmap.viewport.changed & 4) { //stub bitmap.viewport.changed &= ~4; } cellSysutilCheckCallback(); } SaveSRAM(); Graphics->InitDbgFont(); emulation_running = true; }
void Application::step(const JNIEnv *env) { // quick exit if no rom loaded to step if (!_romLoaded) { return; } processInput(); // calculate frameskipping _frameSkipCount=(_frameSkipCount+1)%(_frameSkip+1); // calc framerate /*_timeStart = _timeEnd; _timeEnd = now_ms(); _timeDelta = (_timeEnd - _timeStart); FCEUI_printf("FPS: %g", _timeDelta); */ // check for viewport change from last frame int update = bitmap.viewport.changed & 1; if (update) { int vwidth = bitmap.viewport.w + (2 * bitmap.viewport.x); int vheight = bitmap.viewport.h + (2 * bitmap.viewport.y); // interlaced mode if (config.render && interlaced) { vheight = vheight << 1; } LOGD("Bitmap Changed: %d, %d, %d, pitch: %d", bitmap.viewport.changed, vwidth, vheight, bitmap.pitch); Graphics.ReshapeEmuTexture(vwidth, vheight, SCREEN_RENDER_TEXTURE_WIDTH); _viewPortW = vwidth; _viewPortH = vheight; bitmap.viewport.changed &= ~1; bitmap.pitch = bitmap.viewport.w * bitmap.granularity; } // step emulation system_frame(_frameSkipCount); // draw the texture/fbo Graphics.DrawEMU(bitmap.data, _viewPortW, _viewPortH); // retrieve audio _ssize = audio_update() << 1; //if (!_audioInitialized) _ssize = 0; //LOGD("AudioSamples: %d", _ssize); //LOGD("DONE STEP"); }
static void genesis_loop() { // set genesis config SetGenConfig(); // restore viewport // update_texture_viewport(bitmap.viewport.w, bitmap.viewport.h); /* emulation loop */ while (running) { system_frame(0); SYSUpdate(); } if (gen_exit == 1) genesis_leave(); }
static void Emulate(EmulateSpecStruct *espec) { MDFNMP_ApplyPeriodicCheats(); MDIO_BeginTimePeriod(md_timestamp); MDINPUT_Frame(); if(espec->VideoFormatChanged) MainVDP.SetPixelFormat(espec->surface->format); //.Rshift, espec->surface->format.Gshift, espec->surface->format.Bshift); if(espec->SoundFormatChanged) MDSound_SetSoundRate(espec->SoundRate); MainVDP.SetSurface(espec); //espec->surface, &espec->DisplayRect); system_frame(0); espec->MasterCycles = md_timestamp; espec->SoundBufSize = MDSound_Flush(espec->SoundBuf, espec->SoundBufMaxSize); #if 0 { static double avg = 0; static double s_avg = 0; avg += (espec->MasterCycles - avg) * 0.05; s_avg += (espec->SoundBufSize - s_avg) * 0.05; printf("%f, %f\n", avg / 262 / 10, 48000 / s_avg); } #endif MDIO_EndTimePeriod(md_timestamp); md_timestamp = 0; z80_last_ts = 0; Main68K.timestamp = 0; MainVDP.ResetTS(); //MainVDP.SetSurface(NULL); }
int genesis_init() { static int bfirstRun = true; if (bfirstRun) { FirstRun(); bfirstRun = false; } /* set default config */ error_init(); set_config_defaults(); /* Load ROM file */ cart.rom = (unsigned char*) malloc(10 * 1024 * 1024); memset(cart.rom, 0, 10 * 1024 * 1024); // //if (!load_rom("uda:/sonic.smd")) { if (!load_rom(romname)) { char buf[1024]; sprintf(buf, "Error loading file `%s'.", romname); ErrorPrompt(buf); free(cart.rom); return 1; } // now running running = 1; // not exit gen_exit = 0; SYSInputReset(); /* load BIOS */ memset(bios_rom, 0, sizeof (bios_rom)); FILE *f = fopen(OS_ROM, "rb"); if (f != NULL) { fread(&bios_rom, 0x800, 1, f); fclose(f); int i; for (i = 0; i < 0x800; i += 2) { uint8 temp = bios_rom[i]; bios_rom[i] = bios_rom[i + 1]; bios_rom[i + 1] = temp; } config.tmss |= 2; } /* initialize Genesis virtual system */ memset(&bitmap, 0, sizeof (t_bitmap)); // bitmap.width = g_pTexture->width; // bitmap.height = g_pTexture->height; // bitmap.pitch = g_pTexture->wpitch; bitmap.width = 1024; bitmap.height = 576; bitmap.pitch = bitmap.width * 4; bitmap.data = screen; bitmap.viewport.changed = 3; //config.overscan = 0; // disabled /* initialize emulation */ printf("audio_init\r\n"); audio_init(SOUND_FREQUENCY, vdp_pal ? 50.0 : 60.0); printf("system_init\r\n"); system_init(); printf("sramname\r\n"); /* load SRAM */ if (gensettings.saves & SAVES_SRAM) { load_sram(sramname); } /* user cfg */ SetGenConfig(); /* reset emulation */ system_reset(); /* run 1 frame */ system_frame(0); if (gensettings.saves & SAVES_STATES) { load_state(statename); } return 0; }
int main (int argc, char *argv[]) { #ifdef HW_RVL /* initialize DVD device */ DI_Init(); #endif u16 usBetweenFrames; long long now, prev; /* Initialize OGC subsystems */ ogc_video__init(); ogc_input__init(); ogc_audio__init(); #ifdef HW_DOL /* Initialize GC DVD interface */ DVD_Init (); dvd_drive_detect(); #endif #ifdef HW_RVL /* Power Button callback */ SYS_SetPowerCallback(Power_Off); #endif /* Initialize FAT Interface */ if (fatInitDefault() == true) { fat_enabled = 1; } /* Default Config */ legal(); set_option_defaults (); config_load(); #ifdef HW_RVL /* Load SMB Settings */ loadSettings(); #endif /* Restore Recent Files list */ set_history_defaults(); history_load(); /* Initialize Virtual Machine */ init_machine (); /* Show Menu */ MainMenu(); ConfigRequested = 0; /* Initialize Frame timings */ frameticker = 0; usBetweenFrames = sms.display ? 20000 : 16666; prev = gettime(); /* Emulation Loop */ while (1) { /* update inputs */ ogc_input__update(); /* Frame synchronization */ if (gc_pal != sms.display) { /* use timers */ now = gettime(); if (diff_usec(prev, now) > usBetweenFrames) { /* Frame skipping */ prev = now; system_frame(1); } else { /* Delay */ while (diff_usec(prev, now) < usBetweenFrames) now = gettime(); /* Render Frame */ prev = now; system_frame(0); } } else { /* use VSync */ if (frameticker > 1) { /* Frame skipping */ frameticker--; system_frame (1); } else { /* Delay */ while (!frameticker) usleep(10); system_frame (0); } frameticker--; } /* update video & audio */ ogc_video__update(); ogc_audio__update(); /* Check for Menu request */ if (ConfigRequested) { /* reset AUDIO */ ogc_audio__reset(); /* go to menu */ MainMenu (); ConfigRequested = 0; ogc_video__reset(); /* reset frame timings */ frameticker = 0; usBetweenFrames = sms.display ? 20000 : 16666; prev = gettime(); } } return 0; }
static void Emulate(EmulateSpecStruct *espec) { if(espec->VideoFormatChanged) SMS_VDPSetPixelFormat(espec->surface->format, espec->CustomPalette); if(espec->SoundFormatChanged) SMS_SetSoundRate(espec->SoundRate); sms.timestamp = 0; input.pad[0] = *InputPtrs[0] & 0x3F; if(IS_SMS) { input.pad[1] = *InputPtrs[1] & 0x3F; if((*InputPtrs[0] | *InputPtrs[1]) & 0x40) input.system |= INPUT_PAUSE; else input.system &= ~INPUT_PAUSE; } else // GG: { if(*InputPtrs[0] & 0x40) { input.system |= INPUT_START; } else input.system &= ~INPUT_START; } //NGPJoyLatch = *chee; MDFNMP_ApplyPeriodicCheats(); if(sms.console == CONSOLE_GG) { espec->DisplayRect.x = 48; espec->DisplayRect.y = 48; espec->DisplayRect.w = 160; espec->DisplayRect.h = 144; } else { espec->DisplayRect.x = 0; espec->DisplayRect.y = 0; espec->DisplayRect.w = 256; espec->DisplayRect.h = 240; } bitmap.data = (uint8*)espec->surface->pixels; bitmap.width = 256; bitmap.height = 240; bitmap.pitch = 256 * sizeof(uint32); system_frame(espec->skip); espec->MasterCycles = sms.timestamp; espec->SoundBufSize = SMS_SoundFlush(espec->SoundBuf, espec->SoundBufMaxSize); }
int main(int argc, char *argp[]){ // Init More Stuff... // Initialize Osl oslInit(3); // Based on Onelua xD // Init Crls Functions.. sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); // Init Configs Stuff. InitConfig(); memcpy(menuConfigDefault, &menuConfig, sizeof(menuConfig)); //Sauvegarde pour plus tard // Init Stuff GU "Video" oslInitGfx(OSL_PF_8888, 1);// OSL_PF_5650 Aqui estaba esto.. Cambiado a 8888 oslInitConsole(); oslStartDrawing(); VideoGuScreenClear();// Check If really its vital /* Añadido oslIntraFontInit(INTRAFONT_CACHE_ALL | INTRAFONT_STRING_UTF8); OSL_FONT * oneFont = oslLoadFontFile("flash0:/font/jpn0.pgf"); oslIntraFontSetStyle(oneFont, 0.7, RGB(255,255,255), RGBA(0,0,0,0), INTRAFONT_ALIGN_LEFT); oslSetFont(oneFont); */ //Main screen: in VRAM for speed Screen.scrBuffer = oslGetUncachedPtr(oslVramMgrAllocBlock(SCR_BUFFER_SIZE)); Screen.pal = oslGetUncachedPtr(oslVramMgrAllocBlock(256*2)); //Sub screen: in RAM for mem sparing ScreenTemp.scrBuffer = oslGetUncachedPtr(malloc(SCR_BUFFER_SIZE)); ScreenTemp.pal = NULL; bitmap.data = (unsigned char*)Screen.scrBuffer; /* Term of stuff gu */ // Init More Vars.. u32 nFrame, nDrawnFrames, skip=0, framerate; int nbRenderedFramesPerSec, nbVirtualFramesPerSec = 0, lastVCount = 0; int frameskip = 0; memset(&bitmap, 0, sizeof(bitmap_t)); bitmap.width = 256; bitmap.height = 192; bitmap.depth = menuConfig.video.renderDepth; bitmap.pitch = 256 * menuConfig.video.renderDepth / 8; menuConfig.file.filename[0] = '\0'; sms.save = 1; // Display the menu to load up the ROM // displayMenu(); menuIsInGame = 0; //menuPlusShowMenu(); MenuPlusAction(MA_LOADROM, "ms0:/Poke_Oro.gbc"); //Bidouille pour détecter les choses qui ont changé MenuOptionsConfigure(-1); MenuOptionsConfigure(0); VideoGuScreenClear(); //Système SmsInit(); nFrame = nDrawnFrames = 0; menuConfig.video.turbo = menuConfig.video.pause = 0; nbRenderedFramesPerSec = 0; gblFramerate = gblVirtualFramerate = 0; menuUpdateRender = 0; //Système if (gblMachineType == EM_SMS) system_poweron(); while(1){ // Principal Cycle //Pal support if (menuConfig.video.country == 1) framerate = 50; else framerate = 60; oslSetFramerate(framerate); if (menuUpdateRender) nDrawnFrames = 0, menuUpdateRender = 0; if (gblMachineType == EM_SMS) ControlsUpdate(); else if (gblMachineType == EM_GBC){ gbe_refresh(); gbe_updatePad(); } if (osl_quit) break; //Framerate if (menuConfig.video.cpuTime == 2){ int vcount = osl_vblCount; if (!skip) nbRenderedFramesPerSec++; nbVirtualFramesPerSec++; if (vcount / framerate > lastVCount / framerate) { gblFramerate = nbRenderedFramesPerSec; gblVirtualFramerate = nbVirtualFramesPerSec; nbRenderedFramesPerSec = 0; nbVirtualFramesPerSec = 0; } lastVCount = vcount; } if (!menuConfig.video.pause){ if (gblMachineType == EM_SMS){ system_frame(skip); if (menuConfig.sound.turboSound /*== 2*/ || !menuConfig.video.turbo){ //On peut commencer à jouer le son: tout est initialisé (sinon il faut attendre) soundPause = 0; if (!menuConfig.sound.perfectSynchro){ SoundUpdate(); } } } else if (gblMachineType == EM_GBC){ //Run one GB frame gb_doFrame(skip); soundPause = 0; if (menuConfig.sound.turboSound /*== 2*/ || !menuConfig.video.turbo) { soundPause = 0; if (!menuConfig.sound.perfectSynchro) { snd_render_orig(snd.output, snd.sample_count); SoundUpdate(); } } } } if (!skip && menuConfig.video.syncMode == 0){ //if (gblMachineType == EM_SMS) VideoGuUpdate(nDrawnFrames, menuConfig.video.render); frameReady = 1; nDrawnFrames++; } oslDrawString(10,10,"Mod By Davis"); //vsyncAdd = 0; //redo: if (menuConfig.video.turbo){ if (!skip){ oslEndDrawing(); oslSwapBuffers(); } skip = nFrame % (menuConfig.video.turboSkip + 1); } else{ int vsync = 4 /*+ vsyncAdd*/; if (menuConfig.video.vsync == 2) vsync |= 1; /*else if (menuConfig.video.vsync == 1) vsync |= 8;*/ /*if (autoFskip && !skip) tmp = oslMeanBenchmarkTestEx(OSL_BENCH_END, 0);*/ skip = oslSyncFrameEx(oslMinMax(frameskip+1, menuConfig.video.frameskip, menuConfig.video.frameskipMax), menuConfig.video.frameskipMax, vsync); /*if (autoFskip && !skip) { //Store the CPU usage (in percent) cpuTime = tmp * 6 / 1000; oslBenchmarkTest(OSL_BENCH_START); }*/ } /*if (autoFskip){ if (!skip){ cpuTime = oslMeanBenchmarkTestEx(OSL_BENCH_GET_LAST, 0) * 6 / 1000; oslMeanBenchmarkTestEx(OSL_BENCH_START, 0); targetFrameskip = skippedFrames; skippedFrames = 0; } else{ skippedFrames++; } }*/ if (!skip && menuConfig.video.syncMode == 1) { //if (gblMachineType == EM_SMS) VideoGuUpdate(nDrawnFrames, menuConfig.video.render); frameReady = 1; nDrawnFrames++; } nFrame++; //Pal /*if (menuConfig.video.country == 1 && nFrame % 6 == 0) { if (!skip) vsyncAdd = 16; goto redo; }*/ //In game, menu not currently shown - WARNING: DONT MOVE THIS, THE MESSAGEBOX CODE RELIES ON menuIsInGame == 2 TO KNOW IF THE GAME IS CURRENTLY RUNNING (or menuIsInGame == 1 = menu is shown) menuIsInGame = 2; if (menuDisplaySpecialMessage) MenuSpecialMessageDisplay(); } // End Of While SmsTerm(); //SmsEmulate(); // End Emulate SaveMyPlacesFile(); sceKernelExitGame(); return 0; }
int main (int argc, char *argv[]) { #ifdef HW_RVL /* initialize DVDX */ DI_Init(); #endif /* initialize hardware */ gx_video_Init(); gx_input_Init(); #ifdef HW_DOL DVD_Init (); dvd_drive_detect(); #endif /* initialize FAT devices */ if (fatInitDefault()) { /* check for default directories */ DIR_ITER *dir = NULL; /* base directory */ char pathname[MAXPATHLEN]; sprintf (pathname, DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); /* SRAM & Savestate files directory */ sprintf (pathname, "%s/saves",DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); /* Snapshot files directory */ sprintf (pathname, "%s/snaps",DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); /* Cheat files directory */ sprintf (pathname, "%s/cheats",DEFAULT_PATH); dir = diropen(pathname); if (dir == NULL) mkdir(pathname,S_IRWXU); else dirclose(dir); } /* initialize sound engine */ gx_audio_Init(); /* initialize core engine */ legal(); config_default(); history_default(); init_machine(); /* run any injected rom */ if (cart.romsize) { ARAMFetch((char *)cart.rom, (void *)0x8000, cart.romsize); reloadrom (cart.romsize,"INJECT.bin"); gx_video_Start(); gx_audio_Start(); frameticker = 1; } else { /* Main Menu */ ConfigRequested = 1; } /* initialize GUI engine */ GUI_Initialize(); #ifdef HW_RVL /* Power button callback */ SYS_SetPowerCallback(Power_Off); #endif /* main emulation loop */ while (1) { /* Main Menu request */ if (ConfigRequested) { /* stop video & audio */ gx_audio_Stop(); gx_video_Stop(); /* show menu */ MainMenu (); ConfigRequested = 0; /* start video & audio */ gx_audio_Start(); gx_video_Start(); frameticker = 1; } if (frameticker > 1) { /* skip frame */ system_frame(1); --frameticker; } else { while (frameticker < 1) usleep(10); /* render frame */ system_frame(0); --frameticker; /* update video */ gx_video_Update(); } /* update audio */ gx_audio_Update(); } return 0; }
//Does a frame void machine_frame(int skip) { if (gblMachineType == EM_SMS) system_frame(skip); else if (gblMachineType == EM_GBC) gb_doFrame(skip); }