/** Read a character from the keyboard. * If input is closed, shutdown the program. */ static char sim_getchar (void) { char inbuf; ssize_t res = pth_read (sim_input_fd, &inbuf, 1); if (res <= 0) { task_sleep_sec (2); sim_exit (0); } return inbuf; }
int main() { debug_puts( "\n" "This program tests the simulator magic exit port.\n" "There should be no more messages after this one.\n" ); sim_exit(4); debug_puts( "ERROR - Simulation did not exit?\n" ); return 0; }
int simple_write_byte (target_addr_t addr, uint8_t val) { switch (addr) { case 0xFF00: putchar (val); need_flush = 1; return 0; case 0xFF01: sim_exit (val); return 0; default: return -1; } }
/** * Entry point for errors that are nonrecoverable. * error_code is one of the values in include/system/errno.h. */ __noreturn__ void fatal (errcode_t error_code) { new_fatal_error = TRUE; #ifdef __m6809__ set_stack_pointer (6133); #endif /* Don't allow any more interrupts, since they might be the source of the error. Since FIRQ is disabled, we can only do mono display at this point. Also note that idle cannot run anymore, because task scheduling can't proceed without the system clock moving. */ periodic_ok = 0; disable_interrupts (); /* Reset hardware outputs */ #ifdef CONFIG_GI pinio_write_gi (0); #endif /* TODO - this whole function needs porting to Whitestar */ /* Maybe just call platform_init again? */ #ifdef CONFIG_PLATFORM_WPC if (WPC_HAS_CAP (WPC_CAP_FLIPTRONIC)) wpc_write_flippers (0); #endif #ifdef CONFIG_TICKET pinio_write_ticket (0); #endif pinio_disable_flippers (); pinio_write_solenoid_set (0, 0); pinio_write_solenoid_set (1, 0); pinio_write_solenoid_set (2, 0); pinio_write_solenoid_set (3, 0); #ifdef MACHINE_SOL_EXTBOARD1 pinio_write_solenoid_set (5, 0); #endif /* Audit the error. */ audit_increment (&system_audits.fatal_errors); audit_assign (&system_audits.lockup1_addr, error_code); audit_assign (&system_audits.lockup1_pid_lef, task_getgid ()); log_event (SEV_ERROR, MOD_SYSTEM, EV_SYSTEM_FATAL, error_code); /* Dump all debugging information */ #ifdef DEBUGGER dbprintf ("Fatal error %d\n", error_code); db_dump_all (); #endif /* In native mode, exit whenever a fatal occurs. If the simulator is compiled in, let it clean up first. */ #ifdef CONFIG_SIM sim_exit (error_code); #else #ifdef CONFIG_NATIVE native_exit (); exit (error_code); #endif #endif /* Defining STOP_ON_ERROR is helpful during debugging a problem. Having the machine reset makes it hard to debug after the fact. */ #ifdef STOP_ON_ERROR while (1); #endif /* Restart the system */ warm_reboot (); }
/** 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); } } }
/** * Parse and execute a script command. */ void exec_script (char *cmd) { const char *t; uint32_t v, count; tlast = NULL; /* Blank lines and comments are ignored */ t = tfirst (cmd); if (!t) return; if (*t == '#') return; /*********** capture [subcommand] [args...] ***************/ if (teq (t, "capture")) { struct signal_expression *ex; t = tnext (); if (teq (t, "start")) { ex = texpr (); signal_capture_start (ex); } else if (teq (t, "stop")) { ex = texpr (); signal_capture_stop (ex); } else if (teq (t, "debug")) { } else if (teq (t, "file")) { t = tnext (); signal_capture_set_file (t); } else if (teq (t, "add")) { signal_capture_add (tsigno ()); } else if (teq (t, "del")) { signal_capture_del (tsigno ()); } } /*********** set [var] [value] ***************/ else if (teq (t, "set")) { t = tnext (); v = tconst (); conf_write (t, v); } /*********** p/print [var] ***************/ else if (teq (t, "p") || teq (t, "print")) { v = tconst (); simlog (SLC_DEBUG, "%d", v); } /*********** include [filename] ***************/ else if (teq (t, "include")) { t = tnext (); exec_script_file (t); } /*********** sw [id] ***************/ else if (teq (t, "sw")) { v = tsw (); count = tconst (); if (count == 0) count = 1; while (count > 0) { sim_switch_depress (v); count--; } } /*********** swtoggle [id] ***************/ else if (teq (t, "swtoggle")) { v = tsw (); count = tconst (); if (count == 0) count = 1; while (count > 0) { sim_switch_toggle (v); count--; } } /*********** key [keyname] [switch] ***************/ else if (teq (t, "key")) { t = tnext (); v = tsw (); simlog (SLC_DEBUG, "Key '%c' = %s", *t, names_of_switches[v]); sim_key_install (*t, v); } /*********** push [value] ***************/ else if (teq (t, "push")) { v = tconst (); conf_push (v); } /*********** pop [argcount] ***************/ else if (teq (t, "pop")) { v = tconst (); conf_pop (v); } /*********** sleep [time] ***************/ else if (teq (t, "sleep")) { v = tconst (); simlog (SLC_DEBUG, "Sleeping for %d ms", v); v /= IRQS_PER_TICK; do { task_sleep (TIME_16MS); } while (--v > 0); simlog (SLC_DEBUG, "Awake again.", v); } /*********** exit ***************/ else if (teq (t, "exit")) { sim_exit (0); } }