X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.c;h=4189309a78ca855ef73caed5a58667259e65b65a;hb=108c704a364e89d071c67f929a292f05d019236a;hp=ad79024bbf0752b582d72207e32b6760130ddca2;hpb=eb3668fc5dab138073cd4844208ac05b94086a4a;p=gpsp.git diff --git a/main.c b/main.c index ad79024..4189309 100644 --- a/main.c +++ b/main.c @@ -82,7 +82,7 @@ u32 clock_speed = 200; #else u32 clock_speed = 333; #endif -u8 main_path[512]; +char main_path[512]; void trigger_ext_event(); @@ -131,10 +131,10 @@ void trigger_ext_event(); } \ } \ -u8 *file_ext[] = { ".gba", ".bin", ".zip", NULL }; +static const char *file_ext[] = { ".gba", ".bin", ".zip", NULL }; -#ifdef ARM_ARCH -void ChangeWorkingDirectory(char *exe) +#ifndef PSP_BUILD +static void ChangeWorkingDirectory(char *exe) { #ifndef _WIN32_WCE char *s = strrchr(exe, '/'); @@ -145,6 +145,48 @@ void ChangeWorkingDirectory(char *exe) } #endif } + +static void switch_to_romdir(void) +{ + char buff[256]; + int r; + + file_open(romdir_file, "romdir.txt", read); + + if(file_check_valid(romdir_file)) + { + r = file_read(romdir_file, buff, sizeof(buff) - 1); + if (r > 0) + { + buff[r] = 0; + while (r > 0 && isspace(buff[r-1])) + buff[--r] = 0; + chdir(buff); + } + file_close(romdir_file); + } +} + +static void save_romdir(void) +{ + char buff[512]; + + snprintf(buff, sizeof(buff), "%s" PATH_SEPARATOR "romdir.txt", main_path); + file_open(romdir_file, buff, write); + + if(file_check_valid(romdir_file)) + { + if (getcwd(buff, sizeof(buff))) + { + file_write(romdir_file, buff, strlen(buff)); + } + file_close(romdir_file); + } +} +#else +void ChangeWorkingDirectory(char *exe) {} +static void switch_to_romdir(void) {} +static void save_romdir(void) {} #endif void init_main() @@ -178,12 +220,8 @@ void init_main() int main(int argc, char *argv[]) { - u32 i; - u32 vcount = 0; - u32 ticks; - u32 dispstat; - u8 load_filename[512]; - u8 bios_filename[512]; + char bios_filename[512]; + int ret; #ifdef PSP_BUILD sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, @@ -191,16 +229,12 @@ int main(int argc, char *argv[]) sceKernelEnableSubIntr(PSP_VBLANK_INT, 0); #endif - extern char *cpu_mode_names[]; - init_gamepak_buffer(); // Copy the directory path of the executable into main_path -#ifdef ARM_ARCH // ChangeWorkingDirectory will null out the filename out of the path ChangeWorkingDirectory(argv[0]); -#endif getcwd(main_path, 512); @@ -217,16 +251,16 @@ int main(int argc, char *argv[]) init_video(); -#ifdef GP2X_BUILD - sprintf(bios_filename, "%s/%s", main_path, "gba_bios.bin"); - if(load_bios(bios_filename) == -1) -#else - if(load_bios("gba_bios.bin") == -1) -#endif + sprintf(bios_filename, "%s" PATH_SEPARATOR "%s", main_path, "gba_bios.bin"); + ret = load_bios(bios_filename); + if (ret != 0) + ret = load_bios("gba_bios.bin"); + if (ret != 0) { gui_action_type gui_action = CURSOR_NONE; debug_screen_start(); + debug_screen_printl(" "); debug_screen_printl("Sorry, but gpSP requires a Gameboy Advance BIOS "); debug_screen_printl("image to run correctly. Make sure to get an "); debug_screen_printl("authentic one, it'll be exactly 16384 bytes large "); @@ -236,7 +270,7 @@ int main(int argc, char *argv[]) debug_screen_printl(" "); debug_screen_printl("When you do get it name it gba_bios.bin and put it"); #ifdef PND_BUILD - debug_screen_printl("in /pandora/appdata/gpsp/ . "); + debug_screen_printl("in /pandora/appdata/gpsp/ . "); #else debug_screen_printl("in the same directory as gpSP. "); #endif @@ -281,7 +315,7 @@ int main(int argc, char *argv[]) } init_main(); - init_sound(); + init_sound(1); init_input(); @@ -292,7 +326,7 @@ int main(int argc, char *argv[]) if(load_gamepak(argv[1]) == -1) { #ifndef PSP_BUILD - printf("Failed to load gamepak %s, exiting.\n", load_filename); + printf("Failed to load gamepak %s, exiting.\n", argv[1]); #endif exit(-1); } @@ -305,6 +339,8 @@ int main(int argc, char *argv[]) } else { + char load_filename[512]; + switch_to_romdir(); if(load_file(file_ext, load_filename) == -1) { menu(copy_screen()); @@ -392,7 +428,7 @@ void trigger_ext_event() static u32 event_number = 0; static u64 benchmark_ticks[16]; u64 new_ticks; - u8 current_savestate_filename[512]; + char current_savestate_filename[512]; return; @@ -586,10 +622,10 @@ u32 update_gba() frame_ticks++; #ifdef PC_BUILD - printf("frame update (%x), %d instructions total, %d RAM flushes\n", +/* printf("frame update (%x), %d instructions total, %d RAM flushes\n", reg[REG_PC], instruction_count - last_frame, flush_ram_count); last_frame = instruction_count; - +*/ /* printf("%d gbc audio updates\n", gbc_update_count); printf("%d oam updates\n", oam_update_count); */ gbc_update_count = 0; @@ -842,6 +878,8 @@ void synchronize() void quit() { + save_romdir(); + if(!update_backup_flag) update_backup_force(); @@ -874,7 +912,7 @@ void reset_gba() #ifdef PSP_BUILD -u32 file_length(u8 *filename, s32 dummy) +u32 file_length(char *filename, s32 dummy) { SceIoStat stats; sceIoGetstat(filename, &stats); @@ -896,7 +934,7 @@ void get_ticks_us(u64 *tick_return) #else -u32 file_length(u8 *dummy, FILE *fp) +u32 file_length(char *dummy, FILE *fp) { u32 length; @@ -940,9 +978,9 @@ void get_ticks_us(u64 *ticks_return) #endif -void change_ext(u8 *src, u8 *buffer, u8 *extension) +void change_ext(const char *src, char *buffer, const char *extension) { - u8 *dot_position; + char *dot_position; strcpy(buffer, src); dot_position = strrchr(buffer, '.'); @@ -950,6 +988,20 @@ void change_ext(u8 *src, u8 *buffer, u8 *extension) strcpy(dot_position, extension); } +// make path: /. +void make_rpath(char *buff, size_t size, const char *ext) +{ + char *p; + p = strrchr(gamepak_filename, PATH_SEPARATOR_CHAR); + if (p == NULL) + p = gamepak_filename; + + snprintf(buff, size, "%s/%s", main_path, p); + p = strrchr(buff, '.'); + if (p != NULL) + strcpy(p, ext); +} + #define main_savestate_builder(type) \ void main_##type##_savestate(file_tag_type savestate_file) \ { \