Add function to skip intro during emulation or at startup
authorAndreas Eversberg <jolly@eversberg.eu>
Mon, 2 Apr 2018 17:29:00 +0000 (19:29 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Thu, 5 Apr 2018 16:01:58 +0000 (18:01 +0200)
src/mercenary/main.c

index 866d795..5272f8a 100644 (file)
@@ -105,6 +105,7 @@ static double benson_size; /* render size of benson */
 static int render_legacy = 0; /* render original amiga screen, if set */
 static int render_improved = 0; /* render improved image, if set */
 static int debug_opengl = 0; /* render both, amiga screen and  improved image, if set */
+static int intro_skipped = 0; /* indicated if we already have landed */
 
 static const char *home_dir;
 
@@ -255,6 +256,39 @@ illegal_parameter:
        return 0;
 }
 
+static void skip_intro(void)
+{
+       int event;
+       double render_delay = 0.0;
+       double cycle_count;
+
+       if (intro_skipped)
+               return;
+
+       print_info("*** Skipping intro, fast forwarding... ***\n\n");
+       do {
+               /* render, if not delayed */
+               if (render_delay <= 0.0) {
+                       cycle_count = 0;
+                       do {
+                               cycle_count += execute_cpu(0, &event);
+                       } while (event != STOP_AT_WAIT_VBL && event != STOP_AT_CLEAR_SCREEN1);
+                       render_delay += (double)cycle_count / CPU_SPEED;
+               }
+               /* VBL */
+               execute_cpu(3, NULL);
+               execute_cpu(4, NULL);
+               /* count down render delay */
+               if (render_delay) {
+                       render_delay -= 1.0 / (double)IRQ_RATE;
+                       if (render_delay < 0.0)
+                               render_delay = 0.0;
+               }
+       } while (event != STOP_AT_CLEAR_SCREEN1);
+
+       intro_skipped = 1;
+}
+
 static void special_event(int event)
 {
        if (render_improved)
@@ -329,6 +363,8 @@ static void main_loop(void)
                                cycle_count += execute_cpu(0, &event);
                                /* handle special events */
                                special_event(event);
+                               if (event == STOP_AT_CLEAR_SCREEN1)
+                                       intro_skipped = 1;
                        } while (event != STOP_AT_WAIT_VBL && event != STOP_AT_WAIT_INPUT);
                        /* stop capturing for improved graphics */
                        if (render_improved)
@@ -636,6 +672,12 @@ static void keyboard_sdl(int down, SDL_Keycode sym)
                        }
                        osd_info("Benson size", (config_benson_size == 0.5) ? "half" : "normal");
                        break;
+               case SDLK_i:
+                       if (!intro_skipped)
+                               skip_intro();
+                       else
+                               osd_info("", "not applicable");
+                       break;
                case SDLK_c:
                        if (config_ctrl_c)
                                quit = 1;
@@ -964,17 +1006,8 @@ int main(int argc, char *argv[])
        /* start cpu */
        reset_cpu();
 
-       if (config_skip_intro) {
-               int event;
-
-               print_info("*** Skipping intro, fast forwarding... ***\n\n");
-               do {
-                       execute_cpu(0, &event);
-               } while (event != STOP_AT_CLEAR_SCREEN1);
-               do {
-                       execute_cpu(0, &event);
-               } while (event != STOP_AT_WAIT_VBL);
-       }
+       if (config_skip_intro)
+               skip_intro();
 
        /* run game */
        main_loop();