int main (int argc, char * argv[]) { struct vic20_config config = { .memory_expansion_3k = FALSE, .memory_expansion = 0, .use_paddles = FALSE, .manual_screen_updates = FALSE, .frames_per_second = 50, .frame_interceptor = NULL }; printf ("shadowVIC 6502 CPU emulation test\n"); joystick_open (); video_open (); video_map (); vic20_open (&config); memcpy (&m[0x1000], tests_image, sizeof (tests_image)); vic20_emulate (0x1000); vic20_close (); video_close (); joystick_close (); printf ("Tests passed.\n"); return 0; }
void open_picovic () { struct vic20_config config = { .memory_expansion = have_memory_expansion, .memory_expansion_3k = have_memory_expansion_3k, .use_paddles = FALSE, .manual_screen_updates = FALSE, .frames_per_second = 50, .frame_interceptor = NULL }; struct vic20_config * cfg = malloc (sizeof (struct vic20_config)); memcpy (cfg, &config, sizeof (struct vic20_config)); joystick_open (); video_open (); video_map (); vic20_open (cfg); init_debugger (); } void close_picovic () { vic20_close (); video_close (); joystick_close (); }
void joystickb_svgalib_done(void) { unsigned i; log_std(("josytickb:svgalib: joystickb_svgalib_done()\n")); for(i=0;i<svgalib_state.counter;++i) joystick_close(i); }
void exit_gmameui (void) { g_message (_("Exiting GMAMEUI...")); save_games_ini (); /* FIXME TODO Remove when we save the gamelist after each update */ joystick_close (joydata); joydata = NULL; /* Clear the gamelist (which clears all the romset GObjects) */ g_object_unref (gui_prefs.gl); gui_prefs.gl = NULL; g_object_unref (gui_prefs.audit); gui_prefs.audit = NULL; g_object_unref (gui_prefs.io_handler); gui_prefs.io_handler = NULL; g_object_unref (gui_prefs.fixes); gui_prefs.fixes = NULL; g_object_unref (main_gui.exec_list); main_gui.exec_list = NULL; xmame_options_free (); /* Clear the gamelist view */ g_object_unref (main_gui.displayed_list); main_gui.displayed_list = NULL; g_object_unref (main_gui.options); main_gui.options = NULL; g_object_unref (main_gui.filters_list); main_gui.filters_list = NULL; g_object_unref (main_gui.gui_prefs); main_gui.gui_prefs = NULL; /* FIXME TODO g_object_unref (main_gui.statusbar); main_gui.statusbar = NULL; */ /* FIXME TODO gtk_widget_destroy (MainWindow);*/ g_message (_("Finished cleaning up GMAMEUI")); gtk_main_quit (); }
static void joystick_dispose(Base *base) { Joystick *self = JOYSTICK(base); if(self->opened) { g_warning("Joystick %s not close yet", self->name); joystick_close(self); } if(self->name) { g_free(self->name); } }
static int init_stick( int which ) { if( !joystick_init( which, JOY_CALIB_STDOUT ) ) { ui_error( UI_ERROR_ERROR, "failed to initialise joystick %i: %s", which + 1, errno ? strerror (errno) : "not configured?" ); return 1; } if( joystick_getnumaxes( which ) < 2 || joystick_getnumbuttons( which ) < 1 ) { joystick_close( which ); ui_error( UI_ERROR_ERROR, "sorry, joystick %i is inadequate!", which + 1 ); return 1; } buttons[which] = joystick_getnumbuttons( which ); if( buttons[which] > NUM_JOY_BUTTONS ) buttons[which] = NUM_JOY_BUTTONS; return 0; }
void machine_shutdown(void) { file_system_detach_disk_shutdown(); machine_specific_shutdown(); autostart_shutdown(); #ifdef HAS_JOYSTICK joystick_close(); #endif sound_close(); printer_shutdown(); gfxoutput_shutdown(); fliplist_shutdown(); file_system_shutdown(); fsdevice_shutdown(); tape_shutdown(); traps_shutdown(); kbdbuf_shutdown(); keyboard_shutdown(); monitor_shutdown(); console_close_all(); cmdline_shutdown(); resources_shutdown(); drive_shutdown(); machine_maincpu_shutdown(); video_shutdown(); ui_shutdown(); sysfile_shutdown(); log_close_all(); event_shutdown(); network_shutdown(); autostart_resources_shutdown(); fsdevice_resources_shutdown(); disk_image_resources_shutdown(); machine_resources_shutdown(); sysfile_resources_shutdown(); zfile_shutdown(); ui_resources_shutdown(); log_resources_shutdown(); fliplist_resources_shutdown(); romset_resources_shutdown(); #ifdef HAVE_NETWORK monitor_network_resources_shutdown(); #endif archdep_shutdown(); lib_debug_check(); }
void ui_joystick_end( void ) { joystick_close( -1 ); }
int main(int argc, char **argv) { struct config conf; const char*config_filename; struct packet pkt = {0,}; char buf[64] = {0,}; int16_t crc; int default_cfg = 0; int bad_pkts_cnt = 0; int pkt_cnt = 0; if(argc == 2 && !strcmp("--help", argv[1])) { puts("Usage: quadcontrol [config_file.cfg]"); exit(1); } if(argc == 2) config_filename = argv[1]; else config_filename = CONFIG_DEFAULT_FILE; if(config_load(config_filename, &conf)) { fputs("WARNING: Could not load configuration file. Reverting to defaults.\n", stderr); config_default(&conf); config_save(CONFIG_DEFAULT_FILE, &conf); default_cfg = 1; } if(signal(SIGINT, sig_handler) == SIG_ERR) { fputs("ERROR: Could not set a signal handler.\n", stderr); exit(1); } if(joystick_init(conf.joystick_device)) { perror("could not open joystick device"); exit(1); } joystick_set_axis_mapping(conf.joystick_mapping); joystick_set_axis_calibration(conf.joystick_calibration); if(default_cfg) { joystick_calibrate(conf.joystick_calibration); config_save(CONFIG_DEFAULT_FILE, &conf); } if(serial_init(conf.serial_device, conf.serial_speed)) { perror("could not open serial port"); exit(1); } link_init(); active = 1; while(active) { // Prepare & send a packet memset(&pkt, 0, PACKET_TOTAL_SIZE); #ifdef REQUEST_REPORTS // Report request if(pkt_cnt % 2 == 0) { pkt.type = PT_REPORT | RPT_IMU; /*printf("\nreport request sent\n");*/ } else #endif { pkt.type = PT_JOYSTICK; pkt.data.joy.throttle = joystick_get_control_val(THROTTLE_AXIS); pkt.data.joy.yaw = joystick_get_control_val(YAW_AXIS); pkt.data.joy.pitch = joystick_get_control_val(PITCH_AXIS); pkt.data.joy.roll = joystick_get_control_val(ROLL_AXIS); pkt.data.joy.buttons = joystick_get_buttons(); #ifdef SHOW_JOY printf("\nthrottle: %6d\tyaw:%6d\tpitch:%6d\troll:%6d\tbuttons:%6d", pkt.data.joy.throttle, pkt.data.joy.yaw, pkt.data.joy.pitch, pkt.data.joy.roll, pkt.data.joy.buttons); #endif } crc = link_crc(&pkt); serial_write((const uint8_t*) &pkt, PACKET_TOTAL_SIZE); serial_write((const uint8_t*) &crc, CRC_SIZE); #ifdef SHOW_SEND_RAW printf("\nsent: "); for(int i = 0; i < PACKET_TOTAL_SIZE; ++i) printf("%.2x ", ((uint8_t*)(&pkt))[i]); printf("\tcrc = %.2x", crc); #endif // Show response from the radio int cnt = serial_read(buf, sizeof(buf)); if(cnt > 0) { #ifdef SHOW_RECV_RAW // HEX version printf("\treceived: "); for(int i = 0; i < cnt; ++i) printf("%.2x ", (uint8_t) buf[i]); // ASCII version printf(" ("); for(int i = 0; i < cnt; ++i) printf("%c", buf[i]); printf(")"); #endif if(cnt == 1 && buf[0] == 'E') printf("\n!!! DRONE IS NOT RESPONDING !!!\n"); // Parse reports if(buf[0] == 'T' && buf[1] == 'R') { struct packet* pkt = (struct packet*) &buf[2]; if(pkt->type & PT_REPORT) { int report_type = pkt->type & ~PT_REPORT; switch(report_type) { case RPT_MOTOR: printf("motors = FL: %d FR:%d BL:%d BR:%d\n", pkt->data.rpt_motor.fl, pkt->data.rpt_motor.fr, pkt->data.rpt_motor.bl, pkt->data.rpt_motor.br); break; case RPT_IMU: printf("imu = yaw: %d pitch:%d roll:%d\n", pkt->data.rpt_imu.yaw, pkt->data.rpt_imu.pitch, pkt->data.rpt_imu.roll); break; default: printf("invalid report type\n"); break; } } } memset(buf, 0, sizeof(buf)); bad_pkts_cnt = 0; } else { if(++bad_pkts_cnt == 10) { printf("\n!!! CONTROLLER IS NOT RESPONDING !!!\n"); //link_init(); } } ++pkt_cnt; fflush(stdout); usleep(45000); } serial_close(); joystick_close(); config_save(CONFIG_DEFAULT_FILE, &conf); return 1; }
/* launch following the commandline prepared by play_game, playback_game and record_game then test if the game is launched, detect error and update game status */ void launch_emulation (MameRomEntry *rom, const gchar *options) { FILE *xmame_pipe; gchar line [BUFFER_SIZE]; gchar *p, *p2; gfloat done = 0; gint nb_loaded = 0; gint num_roms; GList *extra_output = NULL; gboolean error_rom, error_mame; /* Error with the load */ gboolean warning_rom; /* Warning with the load */ ProgressWindow *progress_window; #ifdef ENABLE_JOYSTICK gboolean usejoyingui; joystick_close (joydata); joydata = NULL; #endif g_object_get (rom, "num-roms", &num_roms, NULL); /* FIXME Progress of loading ROMs is not reported in newer versions of MAME (e.g. SDLMame), so there is no way of updating a progress window */ progress_window = progress_window_new (TRUE); progress_window_set_title (progress_window, _("Loading %s:"), mame_rom_entry_get_list_name (rom)); progress_window_show (progress_window); gtk_widget_hide (MainWindow); /* need to use printf otherwise, with GMAMEUI_DEBUG, we dont see the complete command line */ GMAMEUI_DEBUG ("Message: running command %s\n", options); xmame_pipe = popen (options, "r"); GMAMEUI_DEBUG (_("Loading %s:"), mame_rom_entry_get_gamename (rom)); /* Loading */ /* XMAME loads the ROM first and then prepares the display. We watch the pipe during the ROM loading until we reach "done.", which is XMAME's way of indicating the ROM has loaded. Errors with particular ROMs are not displayed until after "done.", which is why we have two clauses looking for NOT FOUND below */ /* The following are examples of output lines from MAME: sv02.bin NOT FOUND (SDLMAME) WARNING: the game might not run correctly. (SDLMAME) mcu.bin NOT FOUND (NO GOOD DUMP KNOWN) (XMAME) s92-23c NOT FOUND (XMAME) ERROR: required files are missing, the game cannot be run. SDL found mode:720x450x32 (XMAME - SDL) XMAME generates the following output which can be parsed: loading rom 0: epr11282.a4 loading rom 1: epr11280.a1 info: sysdep_mixer: using oss plugin OSD: Info: Ideal mode for this game = 384x225 SVGAlib: Info: Found videomode 640x400x32 svgalib: Failed to initialize mouse */ error_rom = error_mame = warning_rom = FALSE; while (fgets (line, BUFFER_SIZE, xmame_pipe)) { /* remove the last \n */ for (p = line; (*p && (*p != '\n')); p++); *p = '\0'; GMAMEUI_DEBUG ("xmame: %s", line); if (!strncmp (line,"loading", 7)) { /* Only works with XMAME */ /* xmame: loading rom 16: s92_18.bin */ nb_loaded++; /*search for the : */ for (p = line; (*p && (*p != ':')); p++); p = p + 2; for (p2 = p; (*p2 && (*p2 != '\n')); p2++); p2 = '\0'; done = (gfloat) (nb_loaded / num_roms); progress_window_set_value (progress_window, done); progress_window_set_text (progress_window, p); } else if (!g_ascii_strncasecmp (line, "Ignoring", 8)) { /* Ignore any errors starting with 'Ignoring' */ continue; } else if (g_str_has_suffix (line, "NOT FOUND")) { /* Catch errors relating to missing ROMs (SDLMAME catches them here) */ error_rom = TRUE; extra_output = g_list_append (extra_output, g_strdup (line)); } else if (g_str_has_suffix (line, "(NO GOOD DUMP KNOWN)")) { /* Catch errors relating to best available ROMs (SDLMAME catches them here) */ warning_rom = TRUE; } /* XMAME writes "done." to the command line once the ROMs have been loaded, but before they are checked and before the display is prepared. SDLMAME doesn't do this */ if (!strncmp (line, "done", 4)) break; while (gtk_events_pending ()) gtk_main_iteration (); } progress_window_destroy (progress_window); while (gtk_events_pending ()) gtk_main_iteration (); /* Parse the output and check for errors */ while (fgets (line, BUFFER_SIZE, xmame_pipe)) { for (p = line; (*p && (*p != '\n')); p++); *p = '\0'; GMAMEUI_DEBUG ("xmame: %s", line); if (!strncmp (line, "X Error", 7) || /* X11 mode not found*/ !strncmp (line, "GLERROR", 7) || /* OpenGL initialization errors */ !strncmp (line, "SDL: Unsupported", 16) || !strncmp (line, "Unable to start", 15) || !strncmp (line, "svgalib: ", 9)) /* XMAME SVGA */ { GMAMEUI_DEBUG (_("Error with MAME graphics creation: %s"), line); error_mame = TRUE; extra_output = g_list_append (extra_output, g_strdup (line)); } else if (g_str_has_suffix (line, "NOT FOUND")) { /* Catch errors relating to missing ROMs (XMAME catches them here) */ error_rom = TRUE; extra_output = g_list_append (extra_output, g_strdup (line)); } else if (g_str_has_suffix (line, "(NO GOOD DUMP KNOWN)")) { /* Catch errors relating to best available ROMs (XMAME catches them here) */ warning_rom = TRUE; } } extra_output = glist_remove_duplicates (extra_output); pclose (xmame_pipe); if (error_rom || error_mame) { /* There was an error during the load. Create a dialog to present the errors */ GtkWidget *dialog; gchar *title = NULL; gchar *secmessage = NULL; if (error_rom) { title = g_strdup (_("GMAMEUI could not load the ROM")); secmessage = g_strdup (_("The following ROMs were not found:\n")); } else if (error_mame) { title = g_strdup (_("MAME did not start successfully")); secmessage = g_strdup (_("The following errors were reported:\n")); } GMAMEUI_DEBUG ("error during load"); GList *node; for (node = g_list_first (extra_output); node; node = node->next) { secmessage = g_strconcat (secmessage, node->data, "\n", NULL); } dialog = gmameui_dialog_create (ERROR, NULL, title); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), secmessage); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (title); g_free (secmessage); } /* Update game information */ mame_rom_entry_rom_played (rom, warning_rom, error_rom); g_list_foreach (extra_output, (GFunc)g_free, NULL); g_list_free (extra_output); gtk_widget_show (MainWindow); /* Update the ROM with the times played or status if there was any error */ mame_gamelist_view_update_game_in_list (main_gui.displayed_list, rom); #ifdef ENABLE_JOYSTICK gchar *joystick_device; g_object_get (main_gui.gui_prefs, "usejoyingui", &usejoyingui, "joystick-name", &joystick_device, NULL); if (usejoyingui) joydata = joystick_new (joystick_device); g_free (joystick_device); #endif }