int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { emu_ReadConfig(0, 0); giz_init(hInstance, hPrevInstance); emu_Init(); menu_init(); engineState = PGS_Menu; for (;;) { switch (engineState) { case PGS_Menu: menu_loop(); break; case PGS_ReloadRom: if (emu_ReloadRom()) engineState = PGS_Running; else { lprintf("PGS_ReloadRom == 0\n"); engineState = PGS_Menu; } break; case PGS_RestartRun: engineState = PGS_Running; case PGS_Running: emu_Loop(); break; case PGS_Quit: goto endloop; default: lprintf("engine got into unknown state (%i), exitting\n", engineState); goto endloop; } } endloop: emu_Deinit(); giz_deinit(); return 0; }
int main(int argc, char *argv[]) { g_argv = argv; emu_ReadConfig(0, 0); gp2x_init(); if (currentConfig.EmuOpt&0x10) { int ret = mmuhack(); printf("squidge hack code finished and returned %i\n", ret); fflush(stdout); mmuhack_status = ret; } cpuctrl_init(); // Reset940(1); // Pause940(1); if (currentConfig.EmuOpt&0x100) { printf("setting RAM timings.. "); fflush(stdout); // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2 set_RAM_Timings(6, 4, 1, 1, 1, 2, 2); printf("done.\n"); fflush(stdout); } emu_Init(); menu_init(); engineState = PGS_Menu; if (argc > 1) parse_cmd_line(argc, argv); for (;;) { switch (engineState) { case PGS_Menu: menu_loop(); break; case PGS_ReloadRom: if (emu_ReloadRom()) engineState = PGS_Running; else { printf("PGS_ReloadRom == 0\n"); engineState = PGS_Menu; } break; case PGS_RestartRun: engineState = PGS_Running; case PGS_Running: emu_Loop(); break; case PGS_Quit: goto endloop; default: printf("engine got into unknown state (%i), exitting\n", engineState); goto endloop; } } endloop: emu_Deinit(); cpuctrl_deinit(); gp2x_deinit(); if(mmuhack_status) mmuunhack(); return 0; }
int emu_ReloadRom(void) { unsigned int rom_size = 0; char *used_rom_name = romFileName; char ext[5]; pm_file *rom; int ret, cd_state, cd_region, cfg_loaded = 0; lprintf("emu_ReloadRom(%s)\n", romFileName); get_ext(romFileName, ext); // detect wrong extensions if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz sprintf(menuErrorMsg, "Not a ROM selected."); return 0; } PicoPatchUnload(); // check for movie file if(movie_data) { free(movie_data); movie_data = 0; } #if 0 if(!strcmp(ext, ".gmv")) { // check for both gmv and rom int dummy; FILE *movie_file = fopen(romFileName, "rb"); if(!movie_file) { sprintf(menuErrorMsg, "Failed to open movie."); return 0; } fseek(movie_file, 0, SEEK_END); movie_size = ftell(movie_file); fseek(movie_file, 0, SEEK_SET); if(movie_size < 64+3) { sprintf(menuErrorMsg, "Invalid GMV file."); fclose(movie_file); return 0; } movie_data = malloc(movie_size); if(movie_data == NULL) { sprintf(menuErrorMsg, "low memory."); fclose(movie_file); return 0; } fread(movie_data, 1, movie_size, movie_file); fclose(movie_file); if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) { sprintf(menuErrorMsg, "Invalid GMV file."); return 0; } dummy = try_rfn_cut() || try_rfn_cut(); if (!dummy) { sprintf(menuErrorMsg, "Could't find a ROM for movie."); return 0; } get_ext(romFileName, ext); } else if (!strcmp(ext, ".pat")) { int dummy; PicoPatchLoad(romFileName); dummy = try_rfn_cut() || try_rfn_cut(); if (!dummy) { sprintf(menuErrorMsg, "Could't find a ROM to patch."); return 0; } get_ext(romFileName, ext); } #else // load GG patches list char ggFname[512]; romfname_ext(ggFname, NULL, ".cht"); PicoPatchLoad(ggFname); #endif if ((PicoMCD & 1) && Pico_mcd != NULL) Stop_CD(); // check for MegaCD image cd_state = emu_cdCheck(&cd_region); if (cd_state > 0) { // valid CD image, check for BIOS.. #if 0 // we need to have config loaded at this point ret = emu_ReadConfig(READ_CONFIG_FOR_GAME, READ_CONFIG_SKIP_DEF); if (!ret) emu_ReadConfig(READ_CONFIG_GLOBAL, READ_CONFIG_SKIP_DEF); #endif cfg_loaded = 1; if (PicoRegionOverride) { cd_region = PicoRegionOverride; lprintf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA"); } if (!emu_findBios(cd_region, &used_rom_name)) { // bios_help() ? return 0; } PicoMCD |= 1; get_ext(used_rom_name, ext); } else { if (PicoMCD & 1) Stop_CD(); PicoMCD &= ~1; } ips_define(ipsFileName); rom = pm_open(used_rom_name); if(!rom) { sprintf(menuErrorMsg, "Failed to open rom."); return 0; } menu_romload_prepare(used_rom_name); // also CD load if(rom_data) { free(rom_data); rom_data = 0; rom_size = 0; } if( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) { sprintf(menuErrorMsg, "PicoCartLoad() failed."); lprintf("%s\n", menuErrorMsg); pm_close(rom); menu_romload_end(); return 0; } pm_close(rom); // detect wrong files (Pico crashes on very small files), also see if ROM EP is good if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 || ((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) { if (rom_data) free(rom_data); rom_data = 0; sprintf(menuErrorMsg, "Not a ROM selected."); menu_romload_end(); return 0; } #if 0 // load config for this ROM (do this before insert to get correct region) if (!cfg_loaded) { ret = emu_ReadConfig(READ_CONFIG_FOR_GAME, READ_CONFIG_SKIP_DEF); if (!ret) emu_ReadConfig(READ_CONFIG_GLOBAL, READ_CONFIG_SKIP_DEF); } #endif lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size); if(PicoCartInsert(rom_data, rom_size)) { sprintf(menuErrorMsg, "Failed to load ROM."); menu_romload_end(); return 0; } Pico.m.frame_count = 0; // insert CD if it was detected if (cd_state > 0) { ret = Insert_CD(romFileName, cd_state == 2); if (ret != 0) { sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?"); lprintf("%s\n", menuErrorMsg); menu_romload_end(); return 0; } } menu_romload_end(); #if 0 if (!emu_isBios(romFileName)) { // emu_ReadConfig() might have messed currentConfig.lastRomFile strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1); currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0; } #endif if (PicoPatches) { PicoPatchPrepare(); PicoPatchApply(); } // additional movie stuff if (movie_data) { if(movie_data[0x14] == '6') PicoOpt |= PicoOpt_6button_gamepad; // 6 button pad else PicoOpt &= ~PicoOpt_6button_gamepad; PicoOpt |= (PicoOpt_accurate_timing | PicoOpt_disable_vdp_fifo); // accurate timing, no VDP fifo timing if(movie_data[0xF] >= 'A') { if(movie_data[0x16] & 0x80) { PicoRegionOverride = 8; } else { PicoRegionOverride = 4; } PicoReset(0); // TODO: bits 6 & 5 } movie_data[0x18+30] = 0; sprintf(noticeMsg, "MOVIE: %s", (char *) &movie_data[0x18]); } else { PicoOpt &= ~PicoOpt_disable_vdp_fifo; if(Pico.m.pal) { strcpy(noticeMsg, "PAL SYSTEM / 50 FPS"); } else { strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS"); } } emu_noticeMsgUpdated(); // load SRAM for this ROM emu_SaveLoadSRAM(1); return 1; }
int main(int argc, char *argv[]) { gp2x_init(1000, 16, 11025,16,1,60, 1); gp2x_sound_volume(100,100); screen16 = (unsigned short *)gp2x_video_RGB[0].screen; int i,j; char temp[255]; FILE *in = NULL; if(argc <= 1) { printf("\nnot enough arguments\n"); //return(TRUE); } else { // the hard-core UI, a command line: for (i=0; (i < argc || argv[i] != NULL); i++) { if(strcmp(argv[i], "--double") == 0) { //screen_size = 1; } if(strcmp(argv[i], "--color white") == 0) { supervision_set_colour_scheme(COLOUR_SCHEME_DEFAULT); } if(strcmp(argv[i], "--color amber") == 0) { supervision_set_colour_scheme(COLOUR_SCHEME_AMBER); } if(strcmp(argv[i], "--color green") == 0) { supervision_set_colour_scheme(COLOUR_SCHEME_GREEN); } if(strcmp(argv[i], "--color blue") == 0) { supervision_set_colour_scheme(COLOUR_SCHEME_BLUE); } } romname = strdup(argv[1]); in = fopen(romname, "r"); if(in == NULL) { printf("The file %s doesn't exist.\n",romname); exit(0); } fflush(in); fclose(in); } supervision_init(); //Init the emulator getRunDir(); if(romname!=NULL){ loadROM(romname); supervision_load((u8*)buffer, (uint32)buffer_size); } else { handleFileMenu(); // File menu } emu_ReadConfig(); gp2x_sound_volume(255,255); gp2x_sound_pause(0); while(1) { CheckKeys(); while(!paused) { CheckKeys(); //key control controls_update(); switch(currentConfig.videoMode){ case 0: supervision_exec((int16*)screenbuffer,1); for(j=0; j < 160; j++) gp2x_memcpy(screen16+(80+(j+40)*320),screenbuffer+(j * 160),160*2); break; case 1: supervision_exec2((int16*)screen16,1); break; case 2: supervision_exec3((int16*)screen16,1); break; default: break; } /*gp2x_video_waitvsync(); sprintf(temp,"FPS: %3d", FPS); gp2x_printf(NULL,0,0,temp); ++svFrm;*/ gp2x_video_RGB_flip(0); controls_reset(); } } supervision_done(); //shutsdown the system gp2x_deinit(); }
void handleOptionsMenu(void) { BOOL isSelected = FALSE; int menuOption = 0; emu_ReadConfig(); gp2x_video_RGB_setscaling(320, 240); textClear(); while(!isSelected) { int clock = currentConfig.CPUclock; int frameskip = currentConfig.Frameskip; int videomode = currentConfig.videoMode; int vol = currentConfig.volume; unsigned long pad = gp2x_joystick_read(0); gp2x_printf(0, 1, 1, "Potator2x 1.0 by Normmatt\n\n"); gp2x_printf(0, 15, 15 + 2*8, "videoMode %s",videoMode); gp2x_printf(0, 15, 15 + 3*8, "show_fps %d",currentConfig.show_fps); gp2x_printf(0, 15, 15 + 4*8, "enable_sound %d",currentConfig.enable_sound); gp2x_printf(0, 15, 15 + 5*8, "SoundRate %d",currentConfig.SoundRate); gp2x_printf(0, 15, 15 + 6*8, "Frameskip %d",currentConfig.Frameskip); gp2x_printf(0, 15, 15 + 7*8, "CPUclock %d",clocklist[currentConfig.CPUclock]); gp2x_printf(0, 15, 15 + 8*8, "volume %d",currentConfig.volume); gp2x_printf(0, 15, 15 + 9*8, "Save and Exit"); gp2x_printf(0, 15, 15 + 10*8, "Exit"); gp2x_printf(0, 170, 1, "MenuOption = %d",menuOption); gp2x_printf(0, 0, (31 + (menuOption*8)), "->"); gp2x_video_RGB_flip(0); if(pad & GP2X_RIGHT) { if(menuOption == OPTION_VIDEOMODE) if(videomode < 2) currentConfig.videoMode++; if(menuOption == OPTION_SHOWFPS) if(currentConfig.show_fps==0) currentConfig.show_fps=1; else currentConfig.show_fps=0; if(menuOption == OPTION_ENABLESOUND) if(currentConfig.enable_sound==0) currentConfig.enable_sound=1; else currentConfig.enable_sound=0; if(menuOption == OPTION_SOUNDRATE) currentConfig.SoundRate*=2; if(menuOption == OPTION_FRAMESKIP) if (frameskip < 9) frameskip++; if(menuOption == OPTION_CPUCLOCK) if(clock < sizeof(clocklist)) clock++; if(menuOption == OPTION_VOLUME) if (vol < 255) vol+= (pad & GP2X_RIGHT) ? 1 : 0; } if(pad & GP2X_LEFT) { if(menuOption == OPTION_VIDEOMODE) if(videomode > 0) currentConfig.videoMode--; if(menuOption == OPTION_SHOWFPS) if(currentConfig.show_fps==0) currentConfig.show_fps=1; else currentConfig.show_fps=0; if(menuOption == OPTION_ENABLESOUND) if(currentConfig.enable_sound==0) currentConfig.enable_sound=1; else currentConfig.enable_sound=0; if(menuOption == OPTION_SOUNDRATE) currentConfig.SoundRate/=2; if(menuOption == OPTION_FRAMESKIP) if (frameskip > 0) frameskip--; if(menuOption == OPTION_CPUCLOCK) if(clock > 0) clock--; if(menuOption == OPTION_VOLUME) if (vol > 0) vol-= (pad & GP2X_LEFT) ? 1 : 0; } if(pad & GP2X_DOWN) { menuOption++; textClear(); } if(pad & GP2X_UP) { menuOption--; textClear(); } if(pad & GP2X_VOL_DOWN) if(pad & GP2X_START) exitMenu(); if(pad & GP2X_X) { switch(menuOption){ case OPTION_SAVEEXIT: emu_WriteConfig(); return; case OPTION_EXIT: //gp2x_sound_rate(currentConfig.SoundRate); return; default: break; } } switch(currentConfig.videoMode) { case 0: sprintf(videoMode,"Slow"); break; case 1: sprintf(videoMode,"Quick"); break; case 2: sprintf(videoMode,"Full Screen"); break; default: sprintf(videoMode,""); break; } if(currentConfig.SoundRate <= 11025) currentConfig.SoundRate = 11025; if(currentConfig.SoundRate >= 44100) currentConfig.SoundRate = 44100; currentConfig.Frameskip = frameskip; currentConfig.CPUclock = clock; currentConfig.volume = vol; if(menuOption < 0) menuOption = 0; if(menuOption > 8) menuOption = 8; while(pad == gp2x_joystick_read(0)); pad = gp2x_joystick_read(0); textClear(); } }