void printMenuOptions() { gp2x_printf(0, 1, 1, "Potator2x 1.0 by Normmatt\n\n"); gp2x_printf(0, 15, 15 + 2*8, "Continue"); gp2x_printf(0, 15, 15 + 3*8, "Reset"); gp2x_printf(0, 15, 15 + 4*8, "File Selector"); gp2x_printf(0, 15, 15 + 5*8, "Options"); gp2x_printf(0, 15, 15 + 6*8, "Save State %d",saveSlot); gp2x_printf(0, 15, 15 + 7*8, "Load State %d",saveSlot); gp2x_printf(0, 15, 15 + 8*8, "Exit"); }
void printList(u32 startPos) { u32 i = startPos; u32 shown; if(fileCounter > 18) shown = 19; else shown = fileCounter; gp2x_printf(0, 1, 1, "Potator2x 1.0 by Normmatt\n\n"); for(; i < startPos + shown; ++i) { if(FileList[i].fType == FT_DIR){ gp2x_printf(0, 15, 15 + ((i-startPos)+1)*8, "\n<%s>", FileList[i].fName); } else if(FileList[i].fType == FT_FILE) { gp2x_printf(0, 15, 15 + ((i-startPos)+1)*8, "\n%s", FileList[i].fName); } else break; } }
void fillList(void) { textClear(); int i; int curFile = 0; DIR *dir = opendir("."); if(dir) { struct dirent *ent; while((ent = readdir(dir)) != NULL) { sprintf(FileList[curFile].fName,"%s",ent->d_name); if(ent->d_type==DT_DIR) FileList[curFile].fType = FT_DIR; else FileList[curFile].fType = FT_FILE; FileList[curFile].isRunable = !strcasestr(FileList[curFile].fName, ".sv"); ++curFile; } closedir(dir); /*struct dirent **namelist; int i,k,l,n; n = scandir(".", &namelist, 0, alphasort); if (n < 0) printf("scandir"); for(i=0;i<n-1;i++) { l=strlen(namelist[i]->d_name); if(namelist[i]->d_type==DT_DIR) FileList[curFile].fType = FT_DIR; else FileList[curFile].fType = FT_FILE; strncat (FileList[curFile].fName, namelist[i]->d_name, strlen(namelist[i]->d_name)); ++curFile; FileList[curFile].isRunable = !strcasestr(FileList[curFile].fName, ".sv"); } closedir(dir);*/ } else { gp2x_printf(0,10,2,"Error opening directory\n"); gp2x_video_RGB_flip(0); } fileCounter = curFile; }
int sv_saveState(char *statepath, int id) { FILE* fp; char newPath[256]; strcpy(newPath,statepath); sprintf(newPath+strlen(newPath)-3,".s%d",id); #ifdef GP2X gp2x_printf(0,10,220,"newPath = %s",newPath); gp2x_video_RGB_flip(0); #endif #ifdef NDS iprintf("\nnewPath = %s",newPath); #endif #ifdef HOME_SUPPORT char tmp[256]; snprintf(tmp, sizeof(tmp), "%s/.potator/%s", getenv("HOME"), newPath); snprintf(newPath, sizeof(newPath), "%s", tmp); printf("%s \n", newPath); #endif fp=fopen(newPath,"wb"); if (fp) { fwrite(&m6502_registers, 1, sizeof(m6502_registers), fp); fwrite(memorymap_programRom, 1, sizeof(memorymap_programRom), fp); fwrite(memorymap_lowerRam, 1, 0x2000, fp); fwrite(memorymap_upperRam, 1, 0x2000, fp); fwrite(memorymap_lowerRomBank, 1, sizeof(memorymap_lowerRomBank), fp); fwrite(memorymap_upperRomBank, 1, sizeof(memorymap_upperRomBank), fp); fwrite(memorymap_regs, 1, 0x2000, fp); fflush(fp); fclose(fp); #ifdef GP2X sync(); #endif } #ifdef GP2X sleep(1); #endif return(1); }
void SysPrintf(const char *fmt, ...) { va_list list; va_start(list, fmt); vsprintf(__sysmsg, fmt, list); va_end(list); __sysmsg[1023]=0; if (Config.PsxOut) printf (PSX4ALL_STR, __sysmsg); #if defined(__WIN32__) && !defined(GIZMONDO) OutputDebugString(__sysmsg); #endif gp2x_printf(NULL, 0, 90, __sysmsg); gp2x_video_flip_single(); #ifdef EMU_LOG fprintf(emuLog, PSX4ALL_STR, __sysmsg); #endif }
u16 ReadZodKeys() { u16 pad_status = 0xffff; u32 keys = gp2x_joystick_read(); /* DEBUG */ #ifdef WITH_REG_STATS if( keys & GP2X_PUSH ) { int regcounter=0; for(regcounter = 0; regcounter < 32; regcounter++) { reg_count[regcounter] = 0; reg_mapped_count[regcounter] = 0; } } #endif //Read key state #ifndef IPHONE if ( keys & GP2X_L && keys & GP2X_R && keys & GP2X_A && keys & GP2X_B && keys & GP2X_X && keys & GP2X_Y ) { psx4all_prof_show(); psxShutdown(); CloseComponents(); gp2x_deinit(); exit(0); } #endif #if 0 if( keys & GP2X_SELECT ) { SkipReset = !SkipReset; gp2x_printf(NULL, 0, 0, "SkipReset %s ", SkipReset == 0 ? "OFF" : "ON" ); gp2x_video_flip(); gp2x_timer_delay(1000); } if( keys & GP2X_L ) { if( skipCount > 0 ) skipCount--; gp2x_printf(NULL, 0, 0, "skipCount %d ", skipCount); gp2x_video_flip(); gp2x_timer_delay(250); } if( keys & GP2X_R ) { skipCount++; gp2x_printf(NULL, 0, 0, "skipCount %d ", skipCount); gp2x_video_flip(); gp2x_timer_delay(250); } if( keys & GP2X_VOL_DOWN ) { if( skipRate > 0 ) skipRate--; gp2x_printf(NULL, 0, 0, "skipRate %d ", skipRate); gp2x_video_flip(); gp2x_timer_delay(250); } if( keys & GP2X_VOL_UP ) { skipRate++; gp2x_printf(NULL, 0, 0, "skipRate %d ", skipRate); gp2x_video_flip(); gp2x_timer_delay(250); } #endif if( keys & GP2X_VOL_DOWN && keys & GP2X_VOL_UP ) { #ifdef GP2X_SDL // Menu system u32 w = sdlscreen->w; u32 h = sdlscreen->h; gp2x_change_res(320, 240); #endif if( 0 != SelectGame() ) { psx4all_emulating=1; psx4all_prof_start(PROFILER_TOTAL); psxCpu->Execute(); psx4all_prof_end(PROFILER_TOTAL); psx4all_emulating=0; psx4all_prof_show(); } #ifdef GP2X_SDL gp2x_change_res(w, h); #endif } /* if( keys & GP2X_PUSH && displayVideoMemory) primitiveDebugMode = true; else primitiveDebugMode = false; */ if( keys & GP2X_R && keys & GP2X_VOL_DOWN ) { // Underclock u32 newClock = (PsxClockMult>2) ? (PsxClockMult-1) : PsxClockMult; UpdateClock (newClock); gp2x_printf(NULL, 0, 0, "PSX CLOCK %d %% ", newClock); gp2x_video_flip(); gp2x_timer_delay(250); } if( keys & GP2X_R && keys & GP2X_VOL_UP ) { // Overclock u32 newClock = (PsxClockMult<200) ? (PsxClockMult+1) : PsxClockMult; UpdateClock (newClock); gp2x_printf(NULL, 0, 0, "PSX CLOCK %d %% ", newClock); gp2x_video_flip(); gp2x_timer_delay(250); } if( keys & GP2X_L && keys & GP2X_VOL_DOWN ) { // Underclock PsxCycleMult = (PsxCycleMult>0.2) ? (PsxCycleMult-0.1) : PsxCycleMult; gp2x_printf(NULL, 0, 0, "PSX CYCLE %f ", PsxCycleMult); #ifdef DYNAREC psxCpu->Reset(); #endif gp2x_video_flip(); gp2x_timer_delay(250); } if( keys & GP2X_L && keys & GP2X_VOL_UP ) { // Overclock PsxCycleMult = (PsxCycleMult<10.0) ? (PsxCycleMult+0.1) : PsxCycleMult; gp2x_printf(NULL, 0, 0, "PSX CYCLE %f ", PsxCycleMult); #ifdef DYNAREC psxCpu->Reset(); #endif gp2x_video_flip(); gp2x_timer_delay(250); } if( keys & GP2X_VOL_DOWN ) // L2 { pad_status &= ~(1<<8); } if( keys & GP2X_VOL_UP ) // R2 { pad_status &= ~(1<<9); } if (keys & GP2X_UP) { pad_status &= ~(1<<4); } if (keys & GP2X_DOWN) { pad_status &= ~(1<<6); } if (keys & GP2X_LEFT) { pad_status &= ~(1<<7); } if (keys & GP2X_RIGHT) { pad_status &= ~(1<<5); } if (keys & GP2X_START) { pad_status &= ~(1<<3); } if (keys & GP2X_SELECT) { pad_status &= ~(1); } if (keys & GP2X_L) { pad_status &= ~(1<<10); // L ? } if (keys & GP2X_R) { pad_status &= ~(1<<11); // R ? } if (keys & GP2X_X) { pad_status &= ~(1<<14); } if (keys & GP2X_B) { pad_status &= ~(1<<13); } if (keys & GP2X_A) { pad_status &= ~(1<<15); } if (keys & GP2X_Y) { pad_status &= ~(1<<12); } return pad_status; }
s32 SelectGame() { u32 keys; s32 loadst = 0; s32 menu_state = 0; s32 menu_pos = 0; s8* newpackfile = NULL; gp2x_video_RGB_clearscreen16(); gp2x_video_flip(); #if 1 for(;;) { gp2x_video_RGB_clearscreen16(); backg(); //exems(); //gp2x_timer_delay(500000); keys = gp2x_joystick_read(); gp2x_printf(NULL, 10, (menu_pos * 10) + PSX4ALL_MENU_START_POS, PSX4ALL_ROW2); if( keys & GP2X_UP ) { if( menu_pos > 0 ) menu_pos--; } switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: if( keys & GP2X_DOWN ) { if (psx4all_emulating) { if( menu_pos < 4 ) menu_pos++; }else{ if( menu_pos < 3 ) menu_pos++; } } break; case PSX4ALL_MENU_OPTIONS_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 2 ) menu_pos++; } break; case PSX4ALL_MENU_GPU_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 15 ) menu_pos++; } break; case PSX4ALL_MENU_SPU_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 1 ) menu_pos++; } break; /*case PSX4ALL_MENU_ABOUT_STATE: if( keys & GP2X_B ) { if( menu_pos < 0 ) menu_pos++; } break;*/ case PSX4ALL_MENU_GAMESTATE_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 4 ) menu_pos++; } break; } switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_OPT); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_FO); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 20, PSX4ALL_ABOUT); if (psx4all_emulating) { gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 30, PSX4ALL_RES); if(psx4all_emulating){ gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 40, PSX4ALL_QT); break; } }else { gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 30, PSX4ALL_QT); } break; case PSX4ALL_MENU_OPTIONS_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_GS); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_SS); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 20, PSX4ALL_BK); break; case PSX4ALL_MENU_GPU_STATE: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, PSX4ALL_FPS, (displayFrameInfo == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 10, PSX4ALL_GPU, (displayGpuStats == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 20, PSX4ALL_MEM, (displayVideoMemory == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 30, PSX4ALL_GPUS, (activeNullGPU == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 40, PSX4ALL_IC, linesInterlace_user ); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 50, PSX4ALL_FL, (enableFrameLimit == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 60, PSX4ALL_SKIP, skipCount, skipRate); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 70, PSX4ALL_HACK, (enableAbbeyHack == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 80, PSX4ALL_CM, PsxCycleMult); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 90, PSX4ALL_FRL, hardframeskip_line ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 100, PSX4ALL_FPL, hardframeskip_poly ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 110, PSX4ALL_FST, hardframeskip_sprite ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 120, PSX4ALL_FIM, hardframeskip_image ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 130, PSX4ALL_FBT, hardframeskip_blit ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 140, PSX4ALL_WTM, use_wall_clock_time ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 150, PSX4ALL_BK); break; case PSX4ALL_MENU_SPU_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_SND, (iSoundMuted == 0 ? "ON" : "OFF")); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_BK); break; case PSX4ALL_MENU_GAMESTATE_STATE: gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 0, PSX4ALL_SST); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 10, PSX4ALL_LST); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 20, PSX4ALL_LG); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 30, PSX4ALL_LGW); gp2x_printf(NULL, 100, PSX4ALL_MENU_START_POS + 40, PSX4ALL_BK); break; case PSX4ALL_MENU_ABOUT_STATE: gp2x_printf(NULL, 0, 50, PSX4ALL_NAME " V " PSX4ALL_VERSION "." PSX4ALL_BUILD " By " PSX4ALL_BY); gp2x_printf(NULL, 0, 60, PSX4ALL_CREDITS); gp2x_printf(NULL, 0, 70, PSX4ALL_PORT); gp2x_printf(NULL, 0, 80, PSX4ALL_PTI " " PSX4ALL_PLAT); gp2x_printf(NULL, 0, 100, PSX4ALL_PRM); break; } switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: if (psx4all_emulating) { if( keys & GP2X_B ) { switch(menu_pos) { case 0: menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; break; case 1: menu_state = PSX4ALL_MENU_GAMESTATE_STATE; menu_pos = 0; break; case 2: menu_state = PSX4ALL_MENU_ABOUT_STATE; menu_pos = 0; break; case 3: gp2x_video_RGB_clearscreen16(); return 0; case 4: SDL_Quit(); default: break; } } }else{ if( keys & GP2X_B ) { switch(menu_pos) { case 0: menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; break; case 1: menu_state = PSX4ALL_MENU_GAMESTATE_STATE; menu_pos = 0; break; case 2: menu_state = PSX4ALL_MENU_ABOUT_STATE; menu_pos = 0; break; case 3: gp2x_video_RGB_clearscreen16(); return 0; default: break; } } } if (keys & GP2X_L && psx4all_emulating) { gp2x_video_RGB_clearscreen16(); return 0; } break; case PSX4ALL_MENU_OPTIONS_STATE: switch(menu_pos) { case 0: if (keys & GP2X_B){ menu_state = PSX4ALL_MENU_GPU_STATE; menu_pos = 0; }break; case 1: if( keys & GP2X_B){ menu_state = PSX4ALL_MENU_SPU_STATE; menu_pos = 0; } break; case 2: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_GPU_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { displayFrameInfo = !displayFrameInfo; } break; case 1: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { displayGpuStats = !displayGpuStats; } break; case 2: if( keys & GP2X_B ) { displayVideoMemory = !displayVideoMemory; } break; case 3: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { activeNullGPU = !activeNullGPU; } break; case 4: if ( keys & GP2X_LEFT && linesInterlace_user > 0) linesInterlace_user--; if ( keys & GP2X_RIGHT && linesInterlace_user < 7) linesInterlace_user++; break; case 5: if( keys & GP2X_B ) { enableFrameLimit = !enableFrameLimit; } break; case 6: if( keys & GP2X_LEFT ) { if( skipValue > 0 ) { skipValue--; skipCount = skipCountTable[skipValue]; skipRate = skipRateTable[skipValue]; } } if( keys & GP2X_RIGHT ) { if( skipValue < 8 ) { skipValue++; skipCount = skipCountTable[skipValue]; skipRate = skipRateTable[skipValue]; } } break; case 7: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { enableAbbeyHack = !enableAbbeyHack; } break; case 8: if ( keys & GP2X_LEFT && PsxCycleMult > 1) PsxCycleMult--; if ( keys & GP2X_RIGHT && PsxCycleMult < 10) PsxCycleMult++; break; case 9: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_line = !hardframeskip_line; } break; case 10: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_poly = !hardframeskip_poly; } break; case 11: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_sprite = !hardframeskip_sprite; } break; case 12: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_image = !hardframeskip_image; } break; case 13: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { hardframeskip_blit = !hardframeskip_blit; } break; case 14: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { use_wall_clock_time = !use_wall_clock_time; } break; case 15: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_SPU_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { #ifndef NOSOUND iSoundMuted = !iSoundMuted; #endif } break; case 1: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_OPTIONS_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_GAMESTATE_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B ) { #ifndef IPHONE if( 1 == psx4all_emulating ) { s32 ret; char buffer[360]; char filename[260]; struct stat s; for(int count = 1;; count++) { sprintf(filename, "%s-%04d.svs", packfile, count); if (stat(filename, &s)) break; } gp2x_printf(NULL, 100, 130, PSX4ALL_SV); gp2x_video_flip(); GPU_freeze(2, NULL); ret = SaveState(filename); if (ret == 0) sprintf(buffer, PSX4ALL_SVD); else sprintf(buffer, PSX4ALL_ESV); gp2x_printf(NULL, 100, 140, PSX4ALL_STR, buffer); gp2x_video_flip(); gp2x_timer_delay(900); } #endif } break; case 1: if( keys & GP2X_B ) { #ifndef IPHONE gp2x_timer_delay(500); newpackfile = FileReq(NULL, FORMAT_SV); #endif } break; case 2: if( keys & GP2X_B ) { #ifndef IPHONE Config.HLE = 0; gp2x_timer_delay(500); newpackfile = FileReq(NULL, NULL); #endif } break; case 3: if( keys & GP2X_B ) { #ifndef IPHONE Config.HLE = 1; gp2x_timer_delay(500); newpackfile = FileReq(NULL, NULL); #endif } break; case 4: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_ABOUT_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; } if( newpackfile != NULL ) { break; } gp2x_video_flip(); gp2x_timer_delay(90); if(keys & (GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_L|GP2X_R|GP2X_PUSH| GP2X_LEFT|GP2X_RIGHT|GP2X_UP|GP2X_DOWN) ) { gp2x_timer_delay(50); } } #else Config.HLE = 1; //newpackfile = "Cotton Jap.cbn"; #endif DEBUGF("loaded "PSX4ALL_STR, newpackfile); packfile = newpackfile; gp2x_video_RGB_clearscreen16(); keys = gp2x_joystick_read(); backg(); LoadCdBios = 0; if( (!strcasecmp(packfile + (strlen(packfile)-4), FORMAT_SV)) ) { char *pos; loadst = 1; sprintf(svsfilename, PSX4ALL_STR, packfile); pos = strrchr(packfile, '-'); if (pos) *pos = '\0'; } else { loadst = 0; } if( loadst > 0 ) { gp2x_printf(NULL, 120, 90, PSX4ALL_LDG); } else { gp2x_printf(NULL, 120, 90, PSX4ALL_LDB); } gp2x_video_flip(); if( 1 == psx4all_emulating ) { psxShutdown(); CloseComponents(); } if (SysInit() == -1) { gp2x_deinit(); return 0; } if (InitComponents() == -1) { gp2x_deinit(); return 0; } SysReset(); CheckCdrom(); if( Config.HLE ) { LoadCdBios = 0; if( LoadCdrom() == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LDD); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); backg(); return 0; } } else { gp2x_printf(NULL, 120, 120, PSX4ALL_LDY); gp2x_video_flip(); gp2x_timer_delay(90); backg(); } if (loadst) { if( LoadState(svsfilename) == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LSF); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); return 0; } } return 1; }
char *FileReq(char *dir, const char *ext) { static s8 *cwd=NULL; static s32 cursor_pos=1; static s32 first_visible; static s32 num_items=0; DIR *dirstream; struct dirent *direntry; s8 *path; struct stat item; static s32 row; s32 pathlength; s8 tmp_string[32]; s8 *selected; u32 keys; #define MENU_Y 90 #define MENU_LS MENU_Y+10 #define MENU_HEIGHT 12 if(dir!=NULL) cwd=dir; if(cwd==NULL) { sprintf(filereq_fullgamepath, "%s/", gamepath); cwd=filereq_fullgamepath; } for(;;) { keys = gp2x_joystick_read(); gp2x_video_RGB_clearscreen16(); backg(); //exems(); //gp2x_timer_delay(500000); //gp2x_printf(NULL, 0, 10, PSX4ALL_NAME " V " PSX4ALL_VERSION "." PSX4ALL_BUILD " By " PSX4ALL_BY); //gp2x_printf(NULL, 0, 20, PSX4ALL_CREDITS); //gp2x_printf(NULL, 0, 30, PSX4ALL_PORT); //gp2x_printf(NULL, 0, 40, PSX4ALL_OR); if( keys & GP2X_L ) { for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; gp2x_timer_delay(90); return NULL; } if(num_items==0) { s32 i2; dirstream=opendir(cwd); if(dirstream==NULL) { gp2x_printf(NULL, 0, 20, PSX4ALL_ER); return NULL; } while((direntry=readdir(dirstream))) { if( (ext == NULL && ((NULL == strstr(direntry->d_name, ".")) || (strlen(direntry->d_name) > 1 && 0 == strnicmp(direntry->d_name, "..", 2)) || (strlen(direntry->d_name) > 2 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-2), ".z", 2)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".iso", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".bin", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".img", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".znx", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".cbn", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".pbp", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".cue", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".psx", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".zip", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".mdf", 4))) ) || (ext != NULL && (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-strlen(ext)), ext, strlen(ext)))) ) { filereq_dir_items[num_items].name=(s8 *)malloc(strlen(direntry->d_name)+1); strcpy(filereq_dir_items[num_items].name, direntry->d_name); num_items++; if(num_items>1024) break; } } closedir(dirstream); for(i2=0; i2<num_items; i2++) { path=(s8 *)malloc(strlen(cwd)+strlen(filereq_dir_items[i2].name)+2); sprintf(path, PSX4ALL_SSR, cwd, filereq_dir_items[i2].name); if(!stat(path, &item)) { if(S_ISDIR(item.st_mode)) { filereq_dir_items[i2].type=0; } else { s32 len = strlen(filereq_dir_items[i2].name); filereq_dir_items[i2].type = 2; if (len >= 4) { if (!strnicmp(filereq_dir_items[i2].name+(len-2), ".Z", 2)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".bin", 4)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".ZNX", 4)) { filereq_dir_items[i2].type = 1; } } } } else { filereq_dir_items[i2].type=0; } free(path); } sort_dir(filereq_dir_items, num_items, 1); cursor_pos=0; first_visible=0; } gp2x_printf(NULL, 90, MENU_Y, cwd); if(keys & GP2X_DOWN) { if(cursor_pos<(num_items-1)) cursor_pos++; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible++; } else if(keys & GP2X_UP) { if(cursor_pos>0) cursor_pos--; if(cursor_pos<first_visible) first_visible--; } else if(keys & GP2X_LEFT) { if(cursor_pos>=10) cursor_pos-=10; else cursor_pos=0; if(cursor_pos<first_visible) first_visible=cursor_pos; } else if(keys & GP2X_RIGHT) { if(cursor_pos<(num_items-11)) cursor_pos+=10; else cursor_pos=num_items-1; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible=cursor_pos-(MENU_HEIGHT-1); } else if(keys & GP2X_B) { path=(s8 *)malloc(strlen(cwd) +strlen(filereq_dir_items[cursor_pos].name) +2); sprintf(path, PSX4ALL_SSR, cwd, filereq_dir_items[cursor_pos].name); for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; if(filereq_dir_items[cursor_pos].type==0) { pathlength=strlen(path); if( path[pathlength-1]=='.' && path[pathlength-2]=='/') { path[pathlength-2]='\0'; cwd=path; } else if(path[pathlength-1]=='.' && path[pathlength-2]=='.' && path[pathlength-3]=='/' ) { if( pathlength > 4 ) { s8* p = strrchr(path, '/'); p[0] = '\0'; p = strrchr(path, '/'); p[0] = '\0'; p = strrchr(path, '/'); p[1] = '\0'; cwd=path; } } else { if( path[0] == '/' && path[1] == '/' ) { cwd = path + 1; } else { cwd = path; } } } else { //gp2x_video_RGB_clearscreen16(); gp2x_printf(NULL, 10, 120, PSX4ALL_SL); gp2x_printf(NULL, 10, 130, PSX4ALL_STR, path); gp2x_printf(NULL, 10, 140, PSX4ALL_YN); gp2x_video_flip(); for(;;) { u32 keys = gp2x_joystick_read(); if( keys & GP2X_SELECT ) { return NULL; } if( keys & GP2X_START ) { char* p = strrchr(path, '/'); if( p != NULL ) { sprintf(CdromLabel, "%10.10s", p + 1); } return path; } gp2x_timer_delay(90); } } } row=0; while(row<num_items && row<MENU_HEIGHT) { if(row==(cursor_pos-first_visible)) { gp2x_printf(NULL, 90, MENU_LS+(10*row), PSX4ALL_ROW); selected=filereq_dir_items[row+first_visible].name; } if(filereq_dir_items[row+first_visible].type==0) { gp2x_printf(NULL, 90, MENU_LS+(10*row), "DIR "); } snprintf(tmp_string, 30, PSX4ALL_STR, filereq_dir_items[row+first_visible].name); gp2x_printf(NULL, 90+(10*6), MENU_LS+(10*row), tmp_string); row++; } while(row<MENU_HEIGHT) { row++; } gp2x_video_flip(); gp2x_timer_delay(75); if(keys & (GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_L|GP2X_R|GP2X_PUSH| GP2X_LEFT|GP2X_RIGHT|GP2X_UP|GP2X_DOWN) ) { gp2x_timer_delay(50); } } return NULL; }
int main(int argc, char *argv[]) #endif { #ifndef IPHONE #if defined(ARM_ARCH) ChangeWorkingDirectory(argv[0]); getcwd(gamepath, 256); #else #if defined(__WIN32__) if(argc == 1) strncpy(gamepath,"E:\\ps1",256); else strncpy(gamepath,argv[1],256); #else strncpy(gamepath,ROM_PREFIX,256); #endif #endif #endif #ifdef PSP sprintf(gamepath,""); #endif #ifdef IPHONE sprintf(gamepath,""); #endif memset(&Config, 0, sizeof(PsxConfig)); Config.PsxAuto = 1; Config.Cdda = 1; Config.Xa = 0; #ifdef DYNAREC Config.Cpu = 0; #else Config.Cpu = 1; #endif #ifdef WITH_HLE Config.HLE = 1; #else Config.HLE = 0; #endif Config.Mdec = 0; Config.PsxOut = 0; Config.PsxType = 0; Config.QKeys = 0; Config.RCntFix = 0; Config.Sio = 0; Config.SpuIrq = 1; Config.VSyncWA = 0; #if defined(PSP) || defined(SDL) || defined(IPHONE) sprintf(Config.BiosDir, "%s/Media/ROMs/PSX/", appworkdir); sprintf(Config.Bios, "scph1001.bin"); sprintf(Config.Mcd1, "mcd001.mcr"); sprintf(Config.Mcd2, "mcd002.mcr"); #else sprintf(Config.BiosDir, PSX4ALL_STR, gamepath); sprintf(Config.Bios, "/bios/scph1000.bin"); sprintf(Config.Mcd1, "%s/memory_card/mcd001.mcr", gamepath); sprintf(Config.Mcd2, "%s/memory_card/mcd002.mcr", gamepath); #endif gp2x_init(900, 16, 11025, 16, 1, 60, 1); #ifndef GP2X gp2x_video_flip_single(); #endif #ifdef IPHONE u32 loadsvs = 0; linesInterlace_user = preferences.interlace; skipCount = skipCountTablePhone[preferences.frameSkip]; skipRate = skipRateTablePhone[preferences.frameSkip]; iSoundMuted = preferences.muted; Config.Cdda = preferences.muted; Config.Xa = preferences.muted; #ifdef WITH_HLE Config.HLE = !preferences.bios; #else Config.HLE = 0; #endif if( (!strcasecmp(filename + (strlen(filename)-4), FORMAT_SV )) ) { u32 pos; loadsvs = 1; sprintf(svsfilename, PSX4ALL_STR, filename); sprintf(iphonefile, PSX4ALL_STR, filename); pos = strlen(iphonefile)-18; iphonefile[pos] = '\0'; packfile = iphonefile; } else { loadsvs = 0; sprintf(iphonefile, PSX4ALL_STR, filename); packfile = iphonefile; } gp2x_video_RGB_clearscreen16(); LoadCdBios = 0; if (SysInit() == -1) { gp2x_deinit(); return 0; } if (InitComponents() == -1) { gp2x_deinit(); return 0; } SysReset(); CheckCdrom(); if( Config.HLE ) { LoadCdBios = 0; if( LoadCdrom() == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LDD); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); return 0; } } if (loadsvs) { if( LoadState(svsfilename) == -1 ) { gp2x_printf(NULL, 120, 120, PSX4ALL_LSF); gp2x_video_flip(); gp2x_timer_delay(2000); gp2x_video_RGB_clearscreen16(); psxShutdown(); CloseComponents(); gp2x_deinit(); pthread_exit(NULL); } } psx4all_emulating=1; psx4all_prof_start(PROFILER_TOTAL); psxCpu->Execute(); psx4all_prof_end(PROFILER_TOTAL); psx4all_emulating=0; psx4all_prof_show(); #else if( 0 != SelectGame() ) { psx4all_emulating=1; psx4all_prof_start(PROFILER_TOTAL); psxCpu->Execute(); psx4all_prof_end(PROFILER_TOTAL); psx4all_emulating=0; psx4all_prof_show(); } #endif gp2x_deinit(); return 0; }
void handleMainMenu(void) { BOOL isSelected = FALSE; int menuOption = 0; textClear(); gp2x_video_RGB_setscaling(320, 240); while(!isSelected) { unsigned long pad = gp2x_joystick_read(0); printMenuOptions(); 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 == MMOPTION_SAVESTATE) || (menuOption == MMOPTION_LOADSTATE)) saveSlot++; } if(pad & GP2X_LEFT) { if((menuOption == MMOPTION_SAVESTATE) || (menuOption == MMOPTION_LOADSTATE)) saveSlot--; } 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 MMOPTION_CONTINUE: RESIZE(); textClear(); return; case MMOPTION_RESTART: RESIZE(); supervision_reset(); textClear(); return; case MMOPTION_SELECTOR: handleFileMenu(); return; case MMOPTION_OPTIONS: handleOptionsMenu(); textClear(); return; case MMOPTION_SAVESTATE: sv_saveState(romname,saveSlot); textClear();return; case MMOPTION_LOADSTATE: sv_loadState(romname,saveSlot); textClear();return; case MMOPTION_EXIT: exitMenu(); break; default: return; } } /*if(pad & GP2X_B) { textClear(); return; }*/ if(menuOption < 0) menuOption = 0; if(menuOption > 6) menuOption = 6; if(saveSlot < 0) saveSlot = 0; if(saveSlot > 9) saveSlot = 9; while(pad == gp2x_joystick_read(0)); pad = gp2x_joystick_read(0); textClear(); } }
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(); } }
void handleFileMenu(void) { BOOL isSelected = FALSE; s32 curFile = 0; int virtualFile = 0; fillList(); textClear(); while(!isSelected) { unsigned long pad = gp2x_joystick_read(0); printList(curFile); gp2x_printf(0, 170, 1, "VirtualFile = %d",virtualFile); gp2x_printf(0, 170, 10, "File Count = %d",fileCounter); if(FileList[virtualFile].isRunable){ gp2x_default_font.fg = 0x6700; gp2x_printf(NULL, 0, (33 + (virtualFile*8)), "->"); } else { gp2x_default_font.fg = 0xFFFF; gp2x_printf(NULL, 0, (33 + (virtualFile*8)), "->"); } gp2x_default_font.fg = 0xFFFF; if(curFile) gp2x_printf(NULL, 200, 22, "^\n|"); if((curFile + 18 != fileCounter) && fileCounter > 19) gp2x_printf(NULL, 200, 200, "|\nv"); gp2x_video_RGB_flip(0); if(pad & GP2X_RIGHT) { virtualFile += 5; if(virtualFile > 18) curFile += virtualFile - 18; textClear(); } if(pad & GP2X_LEFT) { virtualFile -= 5; if(virtualFile < 0) curFile += virtualFile; textClear(); } if(pad & GP2X_DOWN) { virtualFile++; textClear(); } if(pad & GP2X_UP) { virtualFile--; textClear(); } if(pad & GP2X_VOL_DOWN) if(pad & GP2X_START) exitMenu(); if(pad & GP2X_X) { if(FileList[curFile + virtualFile].fType == FT_DIR) { chdir(FileList[curFile + virtualFile].fName); fillList(); virtualFile = curFile = 0; } else if(FileList[curFile + virtualFile].isRunable) { //textClear(); //gp2x_printf(0, 1, 1, "Loading...\n\n%s", FileList[curFile + virtualFile].fName); //gp2x_video_RGB_flip(0); RESIZE(); loadROM(FileList[curFile + virtualFile].fName); textClear(); supervision_load((u8*)buffer, (uint32)buffer_size); textClear(); return; } } //if(pad & GP2X_A) return; if(virtualFile < 0) { virtualFile = 0; --curFile; if(curFile < 0) curFile = 0; } if(fileCounter < 19) { if(virtualFile >= fileCounter) virtualFile = fileCounter-1; } else { if(virtualFile > 18) { virtualFile = 18; ++curFile; if(curFile + 18 > fileCounter) curFile = fileCounter - 19; } } while(pad == gp2x_joystick_read(0)); pad = gp2x_joystick_read(0); textClear(); } }
int readroms(void) { int region; const struct RomModule *romp; int warning = 0; int fatalerror = 0; int total_roms,current_rom; char buf[4096] = ""; total_roms = current_rom = 0; romp = Machine->gamedrv->rom; if (!romp) return 0; while (romp->name || romp->offset || romp->length) { if (romp->name && romp->name != (char *)-1) total_roms++; romp++; } romp = Machine->gamedrv->rom; for (region = 0;region < MAX_MEMORY_REGIONS;region++) Machine->memory_region[region] = 0; region = 0; while (romp->name || romp->offset || romp->length) { unsigned int region_size; const char *name; /* Mish: An 'optional' rom region, only loaded if sound emulation is turned on */ if (Machine->sample_rate==0 && (romp->crc & REGIONFLAG_SOUNDONLY)) { logerror("readroms(): Ignoring rom region %d\n",region); Machine->memory_region_type[region] = romp->crc; region++; romp++; while (romp->name || romp->length) romp++; continue; } if (romp->name || romp->length) { gp2x_printf("Error in RomModule definition: expecting ROM_REGION\n"); goto getout; } region_size = romp->offset; if ((Machine->memory_region[region] = (unsigned char *) malloc(region_size)) == 0) { gp2x_printf("readroms(): Unable to allocate %d bytes of RAM\n",region_size); goto getout; } Machine->memory_region_length[region] = region_size; Machine->memory_region_type[region] = romp->crc; /* some games (i.e. Pleiades) want the memory clear on startup */ if (region_size <= 0x400000) /* don't clear large regions which will be filled anyway */ memset(Machine->memory_region[region],0,region_size); romp++; while (romp->length) { void *f; int expchecksum = romp->crc; int explength = 0; if (romp->name == 0) { gp2x_printf("Error in RomModule definition: ROM_CONTINUE not preceded by ROM_LOAD\n"); goto getout; } else if (romp->name == (char *)-1) { gp2x_printf("Error in RomModule definition: ROM_RELOAD not preceded by ROM_LOAD\n"); goto getout; } name = romp->name; /* update status display */ if (osd_display_loading_rom_message(name,++current_rom,total_roms) != 0) goto getout; { const struct GameDriver *drv; drv = Machine->gamedrv; do { f = osd_fopen(drv->name,name,OSD_FILETYPE_ROM,0); drv = drv->clone_of; } while (f == 0 && drv); if (f == 0) { /* NS981003: support for "load by CRC" */ char crc[9]; sprintf(crc,"%08x",romp->crc); drv = Machine->gamedrv; do { f = osd_fopen(drv->name,crc,OSD_FILETYPE_ROM,0); drv = drv->clone_of; } while (f == 0 && drv); } } if (f) { do { unsigned char *c; unsigned int i; int length = romp->length & ~ROMFLAG_MASK; if (romp->name == (char *)-1) osd_fseek(f,0,SEEK_SET); /* ROM_RELOAD */ else explength += length; if (romp->offset + length > region_size || (!(romp->length & ROMFLAG_NIBBLE) && (romp->length & ROMFLAG_ALTERNATE) && (romp->offset&~1) + 2*length > region_size)) { gp2x_printf("Error in RomModule definition: %s out of memory region space\n",name); osd_fclose(f); goto getout; } if (romp->length & ROMFLAG_NIBBLE) { unsigned char *temp; temp = (unsigned char *) malloc(length); if (!temp) { gp2x_printf("Out of memory reading ROM %s\n",name); osd_fclose(f); goto getout; } if (osd_fread(f,temp,length) != length) { printf("Unable to read ROM %s\n",name); } /* ROM_LOAD_NIB_LOW and ROM_LOAD_NIB_HIGH */ c = Machine->memory_region[region] + romp->offset; if (romp->length & ROMFLAG_ALTERNATE) { /* Load into the high nibble */ for (i = 0;i < length;i ++) { c[i] = (c[i] & 0x0f) | ((temp[i] & 0x0f) << 4); } } else { /* Load into the low nibble */ for (i = 0;i < length;i ++) { c[i] = (c[i] & 0xf0) | (temp[i] & 0x0f); } } free(temp); } else if (romp->length & ROMFLAG_ALTERNATE) { /* ROM_LOAD_EVEN and ROM_LOAD_ODD */ /* copy the ROM data */ #ifdef LSB_FIRST c = Machine->memory_region[region] + (romp->offset ^ 1); #else c = Machine->memory_region[region] + romp->offset; #endif if (osd_fread_scatter(f,c,length,2) != length) { printf("Unable to read ROM %s\n",name); } } else if (romp->length & ROMFLAG_QUAD) { static int which_quad=0; /* This is multi session friendly, as we only care about the modulus */ unsigned char *temp; int base=0; temp = (unsigned char *) malloc(length); /* Need to load rom to temporary space */ osd_fread(f,temp,length); /* Copy quad to region */ c = Machine->memory_region[region] + romp->offset; #ifdef LSB_FIRST switch (which_quad%4) { case 0: base=1; break; case 1: base=0; break; case 2: base=3; break; case 3: base=2; break; } #else switch (which_quad%4) { case 0: base=0; break; case 1: base=1; break; case 2: base=2; break; case 3: base=3; break; } #endif for (i=base; i< length*4; i += 4) c[i]=temp[i/4]; which_quad++; free(temp); } else { int wide = romp->length & ROMFLAG_WIDE; #ifdef LSB_FIRST int swap = (romp->length & ROMFLAG_SWAP) ^ ROMFLAG_SWAP; #else int swap = romp->length & ROMFLAG_SWAP; #endif osd_fread(f,Machine->memory_region[region] + romp->offset,length); /* apply swappage */ c = Machine->memory_region[region] + romp->offset; if (wide && swap) { for (i = 0; i < length; i += 2) { int temp = c[i]; c[i] = c[i+1]; c[i+1] = temp; } } } romp++; } while (romp->length && (romp->name == 0 || romp->name == (char *)-1)); if (explength != osd_fsize (f)) { sprintf (&buf[strlen(buf)], "%-12s WRONG LENGTH (expected: %08x found: %08x)\n", name,explength,osd_fsize(f)); warning = 1; } if (expchecksum != osd_fcrc (f)) { warning = 1; if (expchecksum == 0) sprintf(&buf[strlen(buf)],"%-12s NO GOOD DUMP KNOWN\n",name); else if (expchecksum == BADCRC(osd_fcrc(f))) sprintf(&buf[strlen(buf)],"%-12s ROM NEEDS REDUMP\n",name); else sprintf(&buf[strlen(buf)], "%-12s WRONG CRC (expected: %08x found: %08x)\n", name,expchecksum,osd_fcrc(f)); } osd_fclose(f); } else if (romp->length & ROMFLAG_OPTIONAL) { sprintf (&buf[strlen(buf)], "OPTIONAL %-12s NOT FOUND\n",name); romp ++; } else { /* allow for a NO GOOD DUMP KNOWN rom to be missing */ if (expchecksum == 0) { sprintf (&buf[strlen(buf)], "%-12s NOT FOUND (NO GOOD DUMP KNOWN)\n",name); warning = 1; } else { sprintf (&buf[strlen(buf)], "%-12s NOT FOUND\n",name); fatalerror = 1; } do { if (fatalerror == 0) { int i; /* fill space with random data */ if (romp->length & ROMFLAG_ALTERNATE) { unsigned char *c; /* ROM_LOAD_EVEN and ROM_LOAD_ODD */ #ifdef LSB_FIRST c = Machine->memory_region[region] + (romp->offset ^ 1); #else c = Machine->memory_region[region] + romp->offset; #endif for (i = 0;i < (romp->length & ~ROMFLAG_MASK);i++) c[2*i] = rand(); } else { for (i = 0;i < (romp->length & ~ROMFLAG_MASK);i++) Machine->memory_region[region][romp->offset + i] = rand(); } } romp++; } while (romp->length && (romp->name == 0 || romp->name == (char *)-1)); } } region++; } /* final status display */ osd_display_loading_rom_message(0,current_rom,total_roms); if (warning || fatalerror) { extern int bailing; if (fatalerror) { strcat (buf, "ERROR: required files are missing, the game cannot be run.\n"); bailing = 1; } else strcat (buf, "WARNING: the game might not run correctly.\n"); gp2x_printf ("%s", buf); //sq if (!options.gui_host && !bailing) //sq { //sq printf ("Press any key to continue\n"); //sq keyboard_read_sync(); //sq if (keyboard_pressed(KEYCODE_LCONTROL) && keyboard_pressed(KEYCODE_C)) //sq return 1; //sq } } if (fatalerror) return 1; else return 0; getout: /* final status display */ osd_display_loading_rom_message(0,current_rom,total_roms); for (region = 0;region < MAX_MEMORY_REGIONS;region++) { free(Machine->memory_region[region]); Machine->memory_region[region] = 0; } return 1; }
s32 SelectGame() { u32 keys; s32 loadst = 0; s32 menu_state = 0; s32 menu_pos = 0; s8* newpackfile = NULL; gp2x_video_RGB_clearscreen16(); gp2x_video_flip(); #if 1 // pick a game for(;;) { gp2x_video_RGB_clearscreen16(); gp2x_printf(NULL, 0, 10, "psx4all http://github.com/uli/psx4all-dingoo"); gp2x_printf(NULL, 0, 20, "CREDITS: UNAI - ZODTTD - HLIDE - CHUI - TINNUS"); gp2x_printf(NULL, 0, 30, "Dingoo/MIPS port by Ulrich Hecht"); keys = gp2x_joystick_read(); // draw arrow gp2x_printf(NULL, 10, (menu_pos * 10) + PSX4ALL_MENU_START_POS, "----> "); // read key input for up and down for menu position if( keys & GP2X_UP ) { if( menu_pos > 0 ) menu_pos--; } switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 4 ) menu_pos++; } break; case PSX4ALL_MENU_GPU_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 15 ) menu_pos++; } break; case PSX4ALL_MENU_SPU_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 1 ) menu_pos++; } break; case PSX4ALL_MENU_BIOS_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 1 ) menu_pos++; } break; case PSX4ALL_MENU_GAMESTATE_STATE: if( keys & GP2X_DOWN ) { if( menu_pos < 4 ) menu_pos++; } break; } // text to display for each option switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "GRAPHICS OPTIONS"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 10, "SOUND OPTIONS"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 20, "BIOS OPTIONS"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 30, "FILE OPTIONS"); if (psx4all_emulating) gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 40, "RESUME EMULATION"); else gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 40, "QUIT"); break; case PSX4ALL_MENU_GPU_STATE: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Show FPS %s", (displayFrameInfo == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 10, "Show GPU Stats %s", (displayGpuStats == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 20, "Display Video Memory %s", (displayVideoMemory == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 30, "Set NULL GPU %s", (activeNullGPU == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 40, "Interlace Count %d", linesInterlace_user ); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 50, "Frame Limit %s", (enableFrameLimit == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 60, "Frame Skip %d/%d", skipCount, skipRate); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 70, "Abe's Oddysee Fix %s", (enableAbbeyHack == false ? "OFF" : "ON")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 80, "Cycle Multiplier %d", PsxCycleMult); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 90, "Frameskip: Line %s", hardframeskip_line ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 100, "Frameskip: Poly %s", hardframeskip_poly ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 110, "Frameskip: Sprite %s", hardframeskip_sprite ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 120, "Frameskip: Image %s", hardframeskip_image ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 130, "Frameskip: Blit %s", hardframeskip_blit ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 140, "Wall Clock Timing %s", use_wall_clock_time ? "ON" : "OFF"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 150, "<-Back"); break; case PSX4ALL_MENU_SPU_STATE: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "SOUND IS %s", (iSoundMuted == 0 ? "ON" : "OFF")); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 10, "BACK"); break; case PSX4ALL_MENU_BIOS_STATE: switch(biosVersion) { case 0: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph1000 (Japanese)"); break; case 1: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph1001 (North American)"); break; case 2: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph1002 (European)"); break; case 3: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph5500 (Japanese)"); break; case 4: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph5501 (North American)"); break; case 5: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph5502 (European)"); break; case 6: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph7001 (North American)"); break; case 7: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph7002 (European)"); break; case 8: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph7003 (Asian)"); break; case 9: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph7500 (Japanese)"); break; case 10: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph7501 (North American)"); break; case 11: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph7502 (European)"); break; case 12: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "Bios file: scph7503 (Japanese updated)"); break; default: break; } gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 10, "BACK"); break; case PSX4ALL_MENU_GAMESTATE_STATE: gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 0, "SAVE GAME STATE" ); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 10, "LOAD GAME STATE"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 20, "LOAD A GAME"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 30, "LOAD A GAME WITHOUT BIOS"); gp2x_printf(NULL, 80, PSX4ALL_MENU_START_POS + 40, "BACK"); break; } // logic for each option switch(menu_state) { case PSX4ALL_MENU_DEFAULT_STATE: if( keys & GP2X_B ) { switch(menu_pos) { case 0: menu_state = PSX4ALL_MENU_GPU_STATE; menu_pos = 0; break; case 1: menu_state = PSX4ALL_MENU_SPU_STATE; menu_pos = 0; break; case 2: menu_state = PSX4ALL_MENU_BIOS_STATE; menu_pos = 0; break; case 3: menu_state = PSX4ALL_MENU_GAMESTATE_STATE; menu_pos = 0; break; case 4: // clear screen so interlaced screens look ok gp2x_video_RGB_clearscreen16(); return 0; default: break; } } if (keys & GP2X_L && psx4all_emulating) { gp2x_video_RGB_clearscreen16(); return 0; } break; case PSX4ALL_MENU_GPU_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { displayFrameInfo = !displayFrameInfo; } break; case 1: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { displayGpuStats = !displayGpuStats; } break; case 2: if( keys & GP2X_B ) { displayVideoMemory = !displayVideoMemory; } break; case 3: if( keys & GP2X_B ) { activeNullGPU = !activeNullGPU; } break; case 4: if( keys & GP2X_LEFT ) { switch( linesInterlace_user ) { case 0: linesInterlace_user = 7; break; case 1: linesInterlace_user = 0; break; case 3: linesInterlace_user = 1; break; case 7: linesInterlace_user = 3; break; } } if( keys & GP2X_RIGHT ) { switch( linesInterlace_user ) { case 0: linesInterlace_user = 1; break; case 1: linesInterlace_user = 3; break; case 3: linesInterlace_user = 7; break; case 7: linesInterlace_user = 0; break; } } break; case 5: if( keys & GP2X_B ) { enableFrameLimit = !enableFrameLimit; } break; case 6: if( keys & GP2X_LEFT ) { if( skipValue > 0 ) { skipValue--; skipCount = skipCountTable[skipValue]; skipRate = skipRateTable[skipValue]; } } if( keys & GP2X_RIGHT ) { if( skipValue < 8 ) { skipValue++; skipCount = skipCountTable[skipValue]; skipRate = skipRateTable[skipValue]; } } break; case 7: if( keys & GP2X_B ) { enableAbbeyHack = !enableAbbeyHack; } break; case 8: if (keys & GP2X_LEFT && PsxCycleMult > 1) PsxCycleMult--; if (keys & GP2X_RIGHT && PsxCycleMult < 10) PsxCycleMult++; break; case 9: if( keys & GP2X_B ) { hardframeskip_line = !hardframeskip_line; } break; case 10: if( keys & GP2X_B ) { hardframeskip_poly = !hardframeskip_poly; } break; case 11: if( keys & GP2X_B ) { hardframeskip_sprite = !hardframeskip_sprite; } break; case 12: if( keys & GP2X_B ) { hardframeskip_image = !hardframeskip_image; } break; case 13: if( keys & GP2X_B ) { hardframeskip_blit = !hardframeskip_blit; } break; case 14: if( keys & GP2X_B ) { use_wall_clock_time = !use_wall_clock_time; } break; case 15: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; default: break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_SPU_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B || keys & GP2X_LEFT || keys & GP2X_RIGHT ) { #ifndef NOSOUND iSoundMuted = !iSoundMuted; #endif } break; case 1: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_BIOS_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B || keys & GP2X_RIGHT ) { biosVersion++; } else if( keys & GP2X_LEFT) { biosVersion--; } if(biosVersion < 0) biosVersion = 12; if(biosVersion > 12) biosVersion = 0; switch(biosVersion) { case 0: sprintf(Config.Bios, "/scph1000.bin"); break; case 1: sprintf(Config.Bios, "/scph1001.bin"); break; case 2: sprintf(Config.Bios, "/scph1002.bin"); break; case 3: sprintf(Config.Bios, "/scph5500.bin"); break; case 4: sprintf(Config.Bios, "/scph5501.bin"); break; case 5: sprintf(Config.Bios, "/scph5502.bin"); break; case 6: sprintf(Config.Bios, "/scph7001.bin"); break; case 7: sprintf(Config.Bios, "/scph7002.bin"); break; case 8: sprintf(Config.Bios, "/scph7003.bin"); break; case 9: sprintf(Config.Bios, "/scph7500.bin"); break; case 10: sprintf(Config.Bios, "/scph7501.bin"); break; case 11: sprintf(Config.Bios, "/scph7502.bin"); break; case 12: sprintf(Config.Bios, "/scph7503.bin"); break; default: break; } break; case 1: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; case PSX4ALL_MENU_GAMESTATE_STATE: switch(menu_pos) { case 0: if( keys & GP2X_B ) { #ifndef IPHONE if( 1 == psx4all_emulating ) { s32 ret; char buffer[360]; char filename[260]; struct stat s; for(int count = 1;; count++) { sprintf(filename, "%s-%04d.svs", packfile, count); if (stat(filename, &s)) break; } gp2x_printf(NULL, 80, 130, "Saving..."); gp2x_video_flip(); GPU_freeze(2, NULL); ret = SaveState(filename); if (ret == 0) sprintf(buffer, "Saved!"); else sprintf(buffer, "Error Saving!"); gp2x_printf(NULL, 80, 140, "%s", buffer); gp2x_video_flip(); gp2x_timer_delay(1000); } #endif } break; case 1: if( keys & GP2X_B ) { #ifndef IPHONE // pause so keys won't be accidently inputted in FileReq gp2x_timer_delay(500); newpackfile = FileReq(NULL, ".svs"); #endif } break; case 2: if( keys & GP2X_B ) { #ifndef IPHONE Config.HLE = 0; // pause so keys won't be accidently inputted in FileReq gp2x_timer_delay(500); newpackfile = FileReq(NULL, NULL); #endif } break; case 3: if( keys & GP2X_B ) { #ifndef IPHONE Config.HLE = 1; // pause so keys won't be accidently inputted in FileReq gp2x_timer_delay(500); newpackfile = FileReq(NULL, NULL); #endif } break; case 4: if( keys & GP2X_B ) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; } if (keys & GP2X_L) { menu_state = PSX4ALL_MENU_DEFAULT_STATE; menu_pos = 0; } break; } if( newpackfile != NULL ) { break; } gp2x_video_flip(); gp2x_timer_delay(100); if(keys & (GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_L|GP2X_R|GP2X_PUSH| GP2X_LEFT|GP2X_RIGHT|GP2X_UP|GP2X_DOWN) ) { //gp2x_video_flip(); gp2x_timer_delay(50); } } #else //newpackfile = "Einhander.bin"; //newpackfile = "Einhander.cbn"; Config.HLE = 1; //newpackfile = "Cotton Jap.bin"; newpackfile = "Cotton Jap.cbn"; #endif DEBUGF("loaded %s", newpackfile); packfile = newpackfile; // clear screen gp2x_video_RGB_clearscreen16(); keys = gp2x_joystick_read(); LoadCdBios = 0; if( (!strcasecmp(packfile + (strlen(packfile)-4), ".svs")) ) { char *pos; loadst = 1; sprintf(svsfilename, "%s", packfile); pos = strrchr(packfile, '-'); if (pos) *pos = '\0'; } else { loadst = 0; } if( loadst > 0 ) { gp2x_printf(NULL, 120, 100, "LOADING SAVE STATE"); } else { gp2x_printf(NULL, 120, 100, "LOADING BIOS"); } gp2x_video_flip(); if( 1 == psx4all_emulating ) { psxShutdown(); CloseComponents(); } if (SysInit() == -1) { gp2x_deinit(); return 0; } if (InitComponents() == -1) { gp2x_deinit(); return 0; } SysReset(); CheckCdrom(); if( Config.HLE ) { LoadCdBios = 0; if( LoadCdrom() == -1 ) { gp2x_printf(NULL, 120, 120, "LOAD FAILED"); gp2x_video_flip(); gp2x_timer_delay(2000); // clear screen gp2x_video_RGB_clearscreen16(); return 0; } } else { gp2x_printf(NULL, 120, 120, "LOADED!"); gp2x_video_flip(); gp2x_timer_delay(100); } if (loadst) { if( LoadState(svsfilename) == -1 ) { gp2x_printf(NULL, 120, 120, "LOAD SAVE FAILED"); gp2x_video_flip(); gp2x_timer_delay(2000); // clear screen gp2x_video_RGB_clearscreen16(); return 0; } } return 1; }
char *FileReq(char *dir, const char *ext) { static s8 *cwd=NULL; static s32 cursor_pos=1; static s32 first_visible; static s32 num_items=0; DIR *dirstream; struct dirent *direntry; s8 *path; struct stat item; static s32 row; s32 pathlength; s8 tmp_string[32]; s8 *selected; u32 keys; #define MENU_Y 90 #define MENU_LS MENU_Y+10 #define MENU_HEIGHT 12 if(dir!=NULL) cwd=dir; if(cwd==NULL) { sprintf(filereq_fullgamepath, "%s/", gamepath); cwd=filereq_fullgamepath; } for(;;) { keys = gp2x_joystick_read(); gp2x_video_RGB_clearscreen16(); gp2x_printf(NULL, 0, 10, "psx4all-dingoo http://github.com/uli/psx4all-dingoo"); gp2x_printf(NULL, 0, 20, "CREDITS: UNAI - ZODTTD - HLIDE - CHUI - TINNUS"); gp2x_printf(NULL, 0, 30, "Dingoo/MIPS port by Ulrich Hecht"); gp2x_printf(NULL, 0, 40, "CHOOSE A GAME OR PRESS L TO EXIT"); if( keys & GP2X_L ) { for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; gp2x_timer_delay(100); return NULL; } if(num_items==0) { s32 i2; dirstream=opendir(cwd); if(dirstream==NULL) { gp2x_printf(NULL, 0, 20, "error opening directory"); return NULL; } // read directory entries while((direntry=readdir(dirstream))) { // this is a very ugly way of only accepting a certain extension if( (ext == NULL && ((NULL == strstr(direntry->d_name, ".")) || (strlen(direntry->d_name) > 1 && 0 == strnicmp(direntry->d_name, "..", 2)) || (strlen(direntry->d_name) > 2 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-2), ".z", 2)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".iso", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".bin", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".img", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".znx", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".cbn", 4))) ) || (ext != NULL && (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-strlen(ext)), ext, strlen(ext)))) ) { filereq_dir_items[num_items].name=(s8 *)malloc(strlen(direntry->d_name)+1); strcpy(filereq_dir_items[num_items].name, direntry->d_name); num_items++; if(num_items>1024) break; } } closedir(dirstream); // get entry types for(i2=0; i2<num_items; i2++) { path=(s8 *)malloc(strlen(cwd)+strlen(filereq_dir_items[i2].name)+2); sprintf(path, "%s/%s", cwd, filereq_dir_items[i2].name); if(!stat(path, &item)) { if(S_ISDIR(item.st_mode)) { filereq_dir_items[i2].type=0; } else { s32 len = strlen(filereq_dir_items[i2].name); filereq_dir_items[i2].type = 2; /* Not Used */ if (len >= 4) { if (!strnicmp(filereq_dir_items[i2].name+(len-2), ".Z", 2)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".bin", 4)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".ZNX", 4)) { filereq_dir_items[i2].type = 1; } } } } else { filereq_dir_items[i2].type=0; } free(path); } sort_dir(filereq_dir_items, num_items, 1); cursor_pos=0; first_visible=0; } // display current directory gp2x_printf(NULL, 80, MENU_Y, cwd); if(keys & GP2X_DOWN) { //down if(cursor_pos<(num_items-1)) cursor_pos++; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible++; } else if(keys & GP2X_UP) { // up if(cursor_pos>0) cursor_pos--; if(cursor_pos<first_visible) first_visible--; } else if(keys & GP2X_LEFT) { //left if(cursor_pos>=10) cursor_pos-=10; else cursor_pos=0; if(cursor_pos<first_visible) first_visible=cursor_pos; } else if(keys & GP2X_RIGHT) { //right if(cursor_pos<(num_items-11)) cursor_pos+=10; else cursor_pos=num_items-1; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible=cursor_pos-(MENU_HEIGHT-1); } else if(keys & GP2X_B) // button 1 { //s32 i; path=(s8 *)malloc(strlen(cwd) +strlen(filereq_dir_items[cursor_pos].name) +2); sprintf(path, "%s/%s", cwd, filereq_dir_items[cursor_pos].name); for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; if(filereq_dir_items[cursor_pos].type==0) { // directory selected pathlength=strlen(path); if( path[pathlength-1]=='.' && path[pathlength-2]=='/') // check for . selected { path[pathlength-2]='\0'; cwd=path; } else if(path[pathlength-1]=='.' && path[pathlength-2]=='.' && path[pathlength-3]=='/' ) // check for .. selected { if( pathlength > 4 ) { s8* p = strrchr(path, '/'); // PATH: /x/y/z/..[/] p[0] = '\0'; p = strrchr(path, '/'); // PATH: /x/y/z[/]../ p[0] = '\0'; p = strrchr(path, '/'); // PATH: /x/y[/]z/../ p[1] = '\0'; // PATH: /x/y/ cwd=path; } } else { // dirty fix if( path[0] == '/' && path[1] == '/' ) { cwd = path + 1; // Add 1 to ignore the first slash. This occurs when traversing to root dir. } else { cwd = path; } } } else { gp2x_video_RGB_clearscreen16(); gp2x_printf(NULL, 10, 120, "ARE YOU SURE YOU WANT TO SELECT..."); gp2x_printf(NULL, 10, 130, "%s", path); gp2x_printf(NULL, 10, 140, "PRESS START FOR YES OR SELECT FOR NO"); gp2x_video_flip(); // file selected check if it was intended for(;;) { u32 keys = gp2x_joystick_read(); if( keys & GP2X_SELECT ) { return NULL; } if( keys & GP2X_START ) { /* Store the 10 character filename in CdromLabel so save states work */ char* p = strrchr(path, '/'); if( p != NULL ) { sprintf(CdromLabel, "%10.10s", p + 1); } return path; } gp2x_timer_delay(100); } } } // display directory contents row=0; while(row<num_items && row<MENU_HEIGHT) { if(row==(cursor_pos-first_visible)) { // draw cursor gp2x_printf(NULL, 80, MENU_LS+(10*row), "------>"); selected=filereq_dir_items[row+first_visible].name; } if(filereq_dir_items[row+first_visible].type==0) { gp2x_printf(NULL, 80, MENU_LS+(10*row), "DIR "); } snprintf(tmp_string, 30, "%s", filereq_dir_items[row+first_visible].name); gp2x_printf(NULL, 80+(10*6), MENU_LS+(10*row), tmp_string); row++; } while(row<MENU_HEIGHT) { row++; } gp2x_video_flip(); gp2x_timer_delay(75); if(keys & (GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_L|GP2X_R|GP2X_PUSH| GP2X_LEFT|GP2X_RIGHT|GP2X_UP|GP2X_DOWN) ) { gp2x_timer_delay(50); } } return NULL; }