Improved "stop events" by using an event ID for every byte of memory.
[mercenary-reloaded.git] / src / mercenary / main.c
index d831d26..ef7ce5d 100644 (file)
@@ -63,6 +63,7 @@ static int config_debug_opengl = 0;
 #define IOSIZE         0x1000 /* bytes in io space */
 #define        MEMORY_SIZE     0x80000
 static uint8_t *memory = NULL;
+static uint8_t *stop_event = NULL;
 static uint8_t *image = NULL;
 #define SCREEN_WIDTH   320
 #define SCREEN_HEIGHT  200
@@ -212,7 +213,7 @@ static void main_loop(void)
                        /* execute until the rendered image is ready (wait for VBL) */
                        cycle_count = 0;
                        do {
-                               cycle_count += execute_cpu(0, mercenary_stop_at, &event);
+                               cycle_count += execute_cpu(0, &event);
                                /* handle special events */
                                if (event != STOP_AT_WAIT_VBL)
                                        special_event(event);
@@ -253,8 +254,8 @@ static void main_loop(void)
                        last_time = current_time - 1000 * SOUND_CHUNKS / IRQ_RATE;
                }
                while (diff > 1000 / IRQ_RATE) {
-                       execute_cpu(3, NULL, NULL);
-                       execute_cpu(4, NULL, NULL);
+                       execute_cpu(3, NULL);
+                       execute_cpu(4, NULL);
                        had_first_irq = 1;
                        /* render benson without game view
                         * because we only got benson refreshed during VBL IRQ
@@ -664,6 +665,11 @@ int main(int argc, char *argv[])
                print_error("Failed to allocate cpu's memory\n");
                goto done;
        }
+       stop_event = calloc(MEMORY_SIZE, 1);
+       if (!stop_event) {
+               print_error("Failed to allocate cpu's stop_event memory\n");
+               goto done;
+       }
        chipreg = calloc(IOSIZE, 1);
        if (!chipreg) {
                print_error("Failed to allocate chip register\n");
@@ -671,7 +677,7 @@ int main(int argc, char *argv[])
        }
 
        /* init cpu code */
-       execute_init(MEMORY_SIZE, memory, chipreg, io_read, io_write);
+       execute_init(MEMORY_SIZE, memory, stop_event, chipreg, io_read, io_write, mercenary_stop_at);
 
        /* init disk emulation */
        disk_init(disk_read, disk_write);
@@ -718,6 +724,8 @@ done:
 
        if (chipreg)
                free(chipreg);
+       if (stop_event)
+               free(stop_event);
        if (memory)
                free(memory);
        if (sound_buffer)