Add copyright message to gles_video
[gpsp.git] / main.c
diff --git a/main.c b/main.c
index 340b0be..c084181 100644 (file)
--- a/main.c
+++ b/main.c
@@ -38,8 +38,14 @@ debug_state current_debug_state = RUN;
 
 //u32 breakpoint_value = 0;
 
+#ifdef RPI_BUILD
+frameskip_type current_frameskip_type = manual_frameskip; //manual; //auto_frameskip;
+u32 global_cycles_per_instruction = 1;
+#else
 frameskip_type current_frameskip_type = auto_frameskip;
 u32 global_cycles_per_instruction = 1;
+#endif
+
 u32 random_skip = 0;
 u32 fps_debug = 0;
 
@@ -133,8 +139,8 @@ void trigger_ext_event();
 
 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 +151,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,6 +226,9 @@ void init_main()
 
 int main(int argc, char *argv[])
 {
+  char bios_filename[512];
+  int ret;
+
 #ifdef PSP_BUILD
   sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0,
    vblank_interrupt_handler, NULL);
@@ -188,10 +239,8 @@ int main(int argc, char *argv[])
 
   // 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);
 
@@ -208,17 +257,16 @@ int main(int argc, char *argv[])
 
   init_video();
 
-#ifdef GP2X_BUILD
-  char bios_filename[512];
-  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 ");
@@ -228,7 +276,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 <CD card>/pandora/appdata/gpsp/ .              ");
+    debug_screen_printl("in <SD card>/pandora/appdata/gpsp/ .              ");
 #else
     debug_screen_printl("in the same directory as gpSP.                    ");
 #endif
@@ -273,7 +321,7 @@ int main(int argc, char *argv[])
   }
 
   init_main();
-  init_sound();
+  init_sound(1);
 
   init_input();
 
@@ -298,6 +346,7 @@ 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());
@@ -579,10 +628,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;
@@ -778,7 +827,7 @@ void synchronize()
   }
   else if (synchronize_flag)
   {
-#if defined(PND_BUILD)
+#if defined(PND_BUILD) || defined(RPI_BUILD)
     fb_wait_vsync();
 #elif !defined(GP2X_BUILD) // sleeping on GP2X is a bad idea
     delay_us((u64)virtual_frame_count * 50000 / 3 - new_ticks + 2);
@@ -824,7 +873,7 @@ void synchronize()
 
   interval_skipped_frames += skip_next_frame;
 
-#if !defined(GP2X_BUILD) && !defined(PND_BUILD)
+#if !defined(GP2X_BUILD) && !defined(PND_BUILD) && !defined(RPI_BUILD)
   char char_buffer[64];
   sprintf(char_buffer, "gpSP: %2d (%2d) fps", fps, frames_drawn);
   SDL_WM_SetCaption(char_buffer, "gpSP");
@@ -835,6 +884,8 @@ void synchronize()
 
 void quit()
 {
+  save_romdir();
+
   if(!update_backup_flag)
     update_backup_force();
 
@@ -943,6 +994,20 @@ void change_ext(const char *src, char *buffer, const char *extension)
     strcpy(dot_position, extension);
 }
 
+// make path: <main_path>/<romname>.<ext>
+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)                    \
 {                                                                             \