Turn VBL break point list into a structure to make game stop at various events
[mercenary-reloaded.git] / src / mercenary / main.c
index 10d002a..6e1af1c 100644 (file)
@@ -143,13 +143,17 @@ illegal_parameter:
        return 0;
 }
 
+static void special_event(int event)
+{
+}
+
 static void main_loop(void)
 {
        int had_first_irq = 0;
        static uint32_t current_time, last_time = 0, diff;
        int i, rc;
        int space, length;
-       int cycle_count;
+       int cycle_count, event;
        double render_delay = 0.0;
        uint32_t palette_address;
        uint16_t palette[16];
@@ -161,8 +165,14 @@ static void main_loop(void)
                /* STEP 1: let the CPU render/process the game */
                /* don't render if we still delay */
                if (!render_delay) {
-                       /* execute until the rendered image is ready */
-                       cycle_count = execute_cpu(0, mercenary_stop_at);
+                       /* execute until the rendered image is ready (wait for VBL) */
+                       cycle_count = 0;
+                       do {
+                               cycle_count += execute_cpu(0, mercenary_stop_at, &event);
+                               /* handle special events */
+                               if (event != STOP_AT_WAIT_VBL)
+                                       special_event(event);
+                       } while (event != STOP_AT_WAIT_VBL);
                        /* copy palette */
                        palette_address = mercenary_palette();
                        for (i = 0; i < 16; i++)
@@ -194,8 +204,8 @@ static void main_loop(void)
                        last_time = current_time - 1000 * SOUND_CHUNKS / IRQ_RATE;
                }
                while (diff > 1000 / IRQ_RATE) {
-                       execute_cpu(3, NULL);
-                       execute_cpu(4, NULL);
+                       execute_cpu(3, NULL, NULL);
+                       execute_cpu(4, NULL, NULL);
                        had_first_irq = 1;
                        /* render benson without game view
                         * because we only got benson refreshed during VBL IRQ