]> git.sesse.net Git - pistorm/blobdiff - emulator.c
handle keyboard/mouse autoconnect
[pistorm] / emulator.c
index acf6a1f18d31db910e3e935fb6e1207744f464be..1174bd06f455e61f6fa2852d3214a0b6c5313ecf 100644 (file)
@@ -61,6 +61,8 @@ uint8_t realtime_disassembly, int2_enabled = 0;
 uint32_t do_disasm = 0, old_level;
 uint32_t last_irq = 8, last_last_irq = 8;
 
+uint8_t end_signal = 0;
+
 char disasm_buf[4096];
 
 #define KICKBASE 0xF80000
@@ -238,7 +240,6 @@ cpu_loop:
 //    printf("CPU emulation reset.\n");
   }
 
-
   if (mouse_hook_enabled && (mouse_extra != 0x00)) {
     // mouse wheel events have occurred; unlike l/m/r buttons, these are queued as keypresses, so add to end of buffer
     switch (mouse_extra) {
@@ -255,9 +256,13 @@ cpu_loop:
     // dampen the scroll wheel until next while loop iteration
     mouse_extra = 0x00;
   }
+
+  if (end_signal)
+         goto stop_cpu_emulation;
+
   goto cpu_loop;
 
-//stop_cpu_emulation:
+stop_cpu_emulation:
   printf("[CPU] End of CPU thread\n");
 }
 
@@ -342,11 +347,11 @@ key_loop:
         //m68k_pulse_reset();
         printf("CPU emulation reset.\n");
       }
-      // @todo work out how to signal the main process that we want to quit
-      // if (c == 'q') {
-      //   printf("Quitting and exiting emulator.\n");
-      //   goto stop_cpu_emulation;
-      // }
+      if (c == 'q') {
+        printf("Quitting and exiting emulator.\n");
+             end_signal = 1;
+        goto key_end;
+      }
       if (c == 'd') {
         realtime_disassembly ^= 1;
         do_disasm = 1;
@@ -374,6 +379,10 @@ key_loop:
 
 key_end:
   printf("[KBD] Keyboard thread ending\n");
+  if (cfg->keyboard_grab) {
+    printf(ungrab_message);
+    release_device(keyboard_fd);
+  }
   return (void*)NULL;
 }
 
@@ -510,6 +519,12 @@ int main(int argc, char *argv[]) {
     printf("Failed to open keyboard event source.\n");
   }
 
+  if (cfg->mouse_autoconnect)
+    mouse_hook_enabled = 1;
+
+  if (cfg->keyboard_autoconnect)
+    kb_hook_enabled = 1;
+
   InitGayle();
 
   signal(SIGINT, sigint_handler);