/** Main loop for handling the user interface. */ static void sim_interface_thread (void) { char inbuf[2]; struct key_binding *kb; int simulator_keys = 1; int toggle_mode = 1; #ifndef CONFIG_UI_SDL /* Put stdin in raw mode so that 'enter' doesn't have to be pressed after each keystroke. */ keybuffering (0); /* Let the system initialize before accepting keystrokes */ task_sleep_sec (3); #endif if (exec_file && exec_late_flag) exec_script_file (exec_file); for (;;) { task_yield (); #ifdef CONFIG_GTK gtk_poll (); #endif #ifdef CONFIG_UI_SDL ui_refresh_all (); *inbuf = ui_poll_events (); #else *inbuf = sim_getchar (); #endif /* Try again if no character was read */ if (*inbuf == '\0') continue; /* If switch simulation is turned off, then keystrokes are fed into the simulated serial port... meaning it is interpreted by the game program itself, and not the simulator. Use the tilde to toggle between the two modes. */ if (simulator_keys == 0) { /* Except tilde turns it off as usual. */ if (*inbuf == '`') { simlog (SLC_DEBUG, "Input directed to switch matrix."); simulator_keys ^= 1; } else { wpc_key_press (*inbuf); } continue; } switch (*inbuf) { /* Carriage returns and line feeds are ignored so that you can put these commands into a script file. */ case '\r': case '\n': break; case ':': { /* Read and execute a script command */ char cmd[128]; char *p = cmd; memset (p, 0, 128); ui_print_command (" "); for (;;) { *p = sim_getchar (); if (*p == '\x1B') { break; } else if (*p == '\010') { *p = '\0'; p--; } else if ((*p == '\r') || (*p == '\n')) { *p = '\0'; exec_script (cmd); break; } ui_print_command (cmd); p++; } ui_print_command (""); break; } case 'C': gdb_break (); break; case '{': signal_trace_start (signo_under_trace); break; case '}': signal_trace_stop (signo_under_trace); break; case 'q': node_kick (&open_node); break; case '`': /* The tilde toggles between keystrokes being treated as switches, and as input into the runtime debugger. */ simulator_keys ^= 1; simlog (SLC_DEBUG, "Input directed to built-in debugger."); break; case '\x1b': sim_exit (0); break; case 'T': task_dump (); break; case '#': /* Treat '#' as a comment until end of line. This is useful for creating scripts. */ do { *inbuf = sim_getchar (); } while (*inbuf != '\n'); break; case '"': simlog (SLC_DEBUG, "next key will toggle, not press"); toggle_mode = 0; break; default: /* For all other keystrokes, use the keymap table to turn the keystroke into a switch trigger. */ kb = &keymaps[(int)*inbuf]; #ifdef MACHINE_SHOOTER_SWITCH if (kb->flags & KEY_SHOOTER) { node_kick (&shooter_node); } else #endif if (kb->flags & KEY_NODE) { node_move (kb->node, &open_node); } else if (kb->flags & KEY_SW) { if ((switch_table[kb->sw].flags & SW_EDGE) || !toggle_mode) { simlog (SLC_DEBUG, "switch %d toggled", kb->sw); sim_switch_toggle (kb->sw); toggle_mode = 1; } #if (MACHINE_FLIPTRONIC == 1) else if (kb->sw >= 72) { flipper_button_depress (kb->sw); } #endif else { sim_switch_depress (kb->sw); } } else simlog (SLC_DEBUG, "invalid key '%c' pressed (0x%02X)", *inbuf, *inbuf); } } }
static void player_idle(gpointer data) { gtk_poll(); g_main_context_wakeup(NULL); }