static UI_CALLBACK(save_resources_file) { char *filename; ui_button_t button; int len = 1024; #ifndef HAVE_DIRNAME char *tmp; #endif uilib_file_filter_enum_t filter = UILIB_FILTER_ALL; vsync_suspend_speed_eval(); filename = lib_malloc(len + 1); strcpy(filename, ""); filename = ui_select_file(_("File to save settings to"), NULL, 0, resources_last_dir, &filter, 1, &button, 0, NULL, UI_FC_SAVE); if (button == UI_BUTTON_OK && filename != NULL) { if (resources_save(filename) < 0) { ui_error(_("Cannot save settings.")); } else { if (w != NULL) { ui_message(_("Settings saved successfully.")); } } lib_free(resources_last_dir); util_fname_split(filename, &resources_last_dir, NULL); } lib_free(filename); ui_update_menus(); }
static UI_CALLBACK(load_resources_file) { char *filename; ui_button_t button; int r; uilib_file_filter_enum_t filter = UILIB_FILTER_ALL; vsync_suspend_speed_eval(); filename = ui_select_file(_("Resource file name"), NULL, 0, resources_last_dir, &filter, 1, &button, 0, NULL, UI_FC_LOAD); if (button == UI_BUTTON_OK && filename != NULL) { r = resources_load(filename); if (r < 0) { if (r == RESERR_FILE_INVALID) { ui_error(_("Cannot load settings:\nresource file not valid.")); } else { ui_error(_("Cannot load settings:\nresource file not found.")); } } else { lib_free(resources_last_dir); util_fname_split(filename, &resources_last_dir, NULL); } } lib_free(filename); ui_update_menus(); }
static void pet_select_keymap(ui_window_t w, int check, char *name, int sympos) { char filename[0x20]; const char *resname; int kindex; const char *wd; const char *maps[6] = {"x11_buks", "x11_bukp", "x11_bgrs", "x11_bgrp", "x11_bdes", "x11_bdep"}; resources_get_int("KeymapIndex", &kindex); strcpy(filename, maps[kindex]); strcat(filename, name); kindex = (kindex & ~1) + sympos; resname = machine_keymap_res_name_list[kindex]; if (name) { if (!check) { resources_set_string(resname, filename); ui_update_menus(); } else { resources_get_string(resname, &wd); if (!strcmp(wd, filename)) { ui_menu_set_tick(w, 1); } else { ui_menu_set_tick(w, 0); } } } }
static UI_CALLBACK(set_maximum_speed) { int current_speed; resources_get_int("Speed", ¤t_speed); if (!CHECK_MENUS) { if (current_speed != vice_ptr_to_int(UI_MENU_CB_PARAM)) { resources_set_int("Speed", vice_ptr_to_int(UI_MENU_CB_PARAM)); ui_update_menus(); } } else { if (current_speed == vice_ptr_to_int(UI_MENU_CB_PARAM)) { ui_menu_set_tick(w, 1); } else { ui_menu_set_tick(w, 0); } if (UI_MENU_CB_PARAM == 0) { int current_refresh_rate; resources_get_int("RefreshRate", ¤t_refresh_rate); ui_menu_set_sensitive(w, current_refresh_rate != 0); } } }
static TUI_MENU_CALLBACK(radio_type_check_callback) { int drive = (int)param >> 16; int type = (int)param & 0xffff; int value; int i; int support = (is_fs(type) || drive_check_type(type, drive - 8)); if (!support) { return "N/A"; } if (been_activated) { if (is_fs(type)) { resources_set_int_sprintf("IECDevice%i", 1, drive); resources_set_int_sprintf("FileSystemDevice%i", type, drive); } else { if (has_fs()) { resources_set_int_sprintf("IECDevice%i", 0, drive); } resources_set_int_sprintf("Drive%iType", type, drive); } *become_default = 1; ui_update_menus(); } else { if (check_current_drive_type(type, drive)) { *become_default = 1; } } }
static TUI_MENU_CALLBACK(set_directory_callback) { char s[256]; int drive = (int)param; const char *v; if (!(check_current_drive_type(ATTACH_DEVICE_FS, drive))) { return "N/A"; } if (been_activated) { *s = '\0'; if (tui_input_string("Change directory name", "New name:", s, 255) == -1) { return NULL; } if (*s == '\0') { return NULL; } resources_set_string_sprintf("FSDevice%iDir", s, drive); ui_update_menus(); } resources_get_string_sprintf("FSDevice%iDir", &v, drive); return v; }
static void load_snapshot_trap(WORD unused_addr, void *unused_data) { if (autostart_program_name && machine_read_snapshot((char *)autostart_program_name, 0) < 0) ui_error(translate_text(IDGS_CANNOT_LOAD_SNAPSHOT_FILE)); ui_update_menus(); }
/* Autostart PRG file `file_name'. The PRG file can either be a raw CBM file or a P00 file */ int autostart_prg(const char *file_name, unsigned int runmode) { fileio_info_t *finfo; int result; const char *boot_file_name; int mode; if (event_record_active() || event_playback_active()) return -1; /* open prg file */ finfo = fileio_open(file_name, NULL, FILEIO_FORMAT_RAW | FILEIO_FORMAT_P00, FILEIO_COMMAND_READ | FILEIO_COMMAND_FSNAME, FILEIO_TYPE_PRG); /* can't open file */ if (finfo == NULL) { #ifdef CELL_DEBUG printf("ERROR: Cannot open `%s'.\n", file_name); #endif return -1; } /* determine how to load file */ switch(AutostartPrgMode) { case AUTOSTART_PRG_MODE_VFS: //log_message(autostart_log, "Loading PRG file `%s' with virtual FS on unit #8.", file_name); result = autostart_prg_with_virtual_fs(file_name, finfo); mode = AUTOSTART_HASDISK; boot_file_name = (const char *)finfo->name; break; case AUTOSTART_PRG_MODE_INJECT: //log_message(autostart_log, "Loading PRG file `%s' with direct RAM injection.", file_name); result = autostart_prg_with_ram_injection(file_name, finfo); mode = AUTOSTART_INJECT; boot_file_name = NULL; break; case AUTOSTART_PRG_MODE_DISK: //log_message(autostart_log, "Loading PRG file `%s' with autostart disk image.", file_name); result = autostart_prg_with_disk_image(file_name, finfo, AutostartPrgDiskImage); mode = AUTOSTART_HASDISK; boot_file_name = "*"; break; default: //log_error(autostart_log, "Invalid PRG autostart mode: %d", AutostartPrgMode); result = -1; break; } /* Now either proceed with disk image booting or prg injection after reset */ if (result >= 0) { ui_update_menus(); reboot_for_autostart(boot_file_name, mode, runmode); } /* close prg file */ fileio_close(finfo); return result; }
static UI_CALLBACK(attach_cartridge) { int type = vice_ptr_to_int(UI_MENU_CB_PARAM); char *filename; ui_button_t button; static char *last_dir; uilib_file_filter_enum_t filter[] = { UILIB_FILTER_VIC20CART, UILIB_FILTER_ALL }; vsync_suspend_speed_eval(); filename = ui_select_file(_("Attach cartridge image"), NULL, 0, last_dir, filter, sizeof(filter) / sizeof(*filter), &button, 0, NULL, UI_FC_LOAD); switch (button) { case UI_BUTTON_OK: if (cartridge_attach_image(type, filename) < 0) { ui_error(_("Invalid cartridge image")); } lib_free(last_dir); util_fname_split(filename, &last_dir, NULL); ui_update_menus(); break; default: /* Do nothing special. */ break; } lib_free(filename); }
static UI_CALLBACK(set_refresh_rate) { int current_refresh_rate; resources_get_int("RefreshRate", ¤t_refresh_rate); if (!CHECK_MENUS) { if (current_refresh_rate != vice_ptr_to_int(UI_MENU_CB_PARAM)) { resources_set_int("RefreshRate", vice_ptr_to_int(UI_MENU_CB_PARAM)); ui_update_menus(); } } else { if (vice_ptr_to_int(UI_MENU_CB_PARAM) == current_refresh_rate) { ui_menu_set_tick(w, 1); } else { ui_menu_set_tick(w, 0); } if (UI_MENU_CB_PARAM == 0) { int speed; resources_get_int("Speed", &speed); if (speed == 0) { /* Cannot enable the `automatic' setting if a speed limit is not specified. */ ui_menu_set_sensitive(w, 0); } else { ui_menu_set_sensitive(w, 1); } } } }
static TUI_MENU_CALLBACK(create_disk_image_callback) { if (been_activated) { unsigned int drive; drive = (unsigned int)param; if (file_name == NULL) { tui_error("Specify a disk image name."); return NULL; } if (vdrive_internal_create_format_disk_image(file_name, format_name, image_type[file_type]) < 0) { tui_error("Could not create disk image!"); return NULL; } if (drive > 0) { if (file_system_attach_disk(drive, file_name) < 0) { tui_error("Could not attach disk image!"); return NULL; } } ui_update_menus(); } return NULL; }
static TUI_MENU_CALLBACK(attach_cartridge_callback) { const char *s; int type = (int)param; if (been_activated) { char *default_item, *directory; char *name; s = cartridge_get_file_name(cartridge_type_to_address(type)); if (s == NULL) { directory = default_item = NULL; } else { util_fname_split(s, &directory, &default_item); } name = tui_file_selector("Attach cartridge image", directory, "*", default_item, NULL, NULL, NULL); if (name != NULL && (s == NULL || strcasecmp(name, s) != 0) && cartridge_attach_image(type, name) < 0) { tui_error("Invalid cartridge image."); } ui_update_menus(); lib_free(name); } /* This is redundant if `been_activated' is nonzero, but let's stay on the safe side. */ s = cartridge_get_file_name(cartridge_type_to_address(type)); if (s == NULL || *s == '\0') { return "(none)"; } else { return s; } }
static TUI_MENU_CALLBACK(set_joy_device_callback) { int port = (int)param >> 8; char *resource; switch (port) { case 1: default: resource = "JoyDevice1"; break; case 2: resource = "JoyDevice2"; break; case 3: resource = "JoyDevice3"; break; case 4: resource = "JoyDevice4"; break; } if (been_activated) { resources_set_int(resource, ((int)param & 0xff)); ui_update_menus(); } else { int value; resources_get_int(resource, &value); if (value == ((int)param & 0xff)) { *become_default = 1; } } return NULL; }
static void load_snapshot_trap(WORD unused_addr, void *data) { ui_button_t button; char *filename; vsync_suspend_speed_eval(); if (data) { log_debug("Quickloading file %s.", (char *)data); filename = (char *)data; } else { uilib_file_filter_enum_t filter[] = { UILIB_FILTER_SNAPSHOT, UILIB_FILTER_ALL }; filename = ui_select_file(_("Load snapshot image"), NULL, 0, load_snapshot_last_dir, filter, sizeof(filter) / sizeof(*filter), &button, 0, NULL, UI_FC_LOAD); if (button != UI_BUTTON_OK) { lib_free(filename); return; } } lib_free(load_snapshot_last_dir); util_fname_split(filename, &load_snapshot_last_dir, NULL); if (machine_read_snapshot(filename, 0) < 0) { ui_error(_("Cannot load snapshot file\n`%s'"), filename); } ui_update_menus(); lib_free(filename); }
void ui_select_renderer(ui_window_t w, int check, int type, char *chip) { char r1[0x20], r2[0x20]; int renderer = 0, crt, have_scale2x, scale2x, doublesize; strcpy(r1, chip); strcpy(r2, chip); strcat(r1, "Scale2x"); strcat(r2, "DoubleSize"); resources_get_int("PalEmulation", &crt); if (resources_query_type(r1) == RES_INTEGER) { resources_get_int(r1, &scale2x); have_scale2x = 1; } else { scale2x = 0; have_scale2x = 0; } resources_get_int(r2, &doublesize); if (crt) { renderer = 1; } else if ((scale2x > 0) && (doublesize > 0)) { renderer = 2; } if (!check) { switch (type) { case 0: /* unfiltered */ crt = 0; scale2x = 0; break; case 1: /* CRT */ crt = 1; scale2x = 0; break; case 2: /* scale 2x */ crt = 0; scale2x = 1; doublesize = 1; break; } resources_set_int("PalEmulation", crt); if (have_scale2x) { resources_set_int(r1, scale2x); } resources_set_int(r2, doublesize); ui_update_menus(); } else { if (renderer == type) { ui_menu_set_tick(w, 1); } else { ui_menu_set_tick(w, 0); } } }
static UI_CALLBACK(ui_netplay_set_port) { static char input_string[32]; char *msg_string; ui_button_t button; int i; int current_port; resources_get_int("NetworkServerPort", ¤t_port); if (!*input_string) { sprintf(input_string, "%d", current_port); } vsync_suspend_speed_eval(); msg_string = lib_stralloc(_("Enter port")); button = ui_input_string(_("Netplay TCP port"), msg_string, input_string, 32); lib_free(msg_string); if (button == UI_BUTTON_OK) { i = atoi(input_string); if (i > 0 && i < 65536) { resources_set_int("NetworkServerPort", i); ui_update_menus(); } else { ui_error(_("Invalid TCP port")); } } }
static void load_snapshot_trap(WORD unused_addr, void *data) { ui_button_t button; char *filename; vsync_suspend_speed_eval(); if (data) { log_debug(_("Quickloading file %s."), (char *)data); filename = (char *)data; } else { filename = ui_select_file(_("Load snapshot"), NULL, 0, 0, load_snapshot_last_dir, "*.vsf", &button, 0, NULL); if (button != UI_BUTTON_OK) { if (filename) lib_free(filename); return; } } if (load_snapshot_last_dir) lib_free(load_snapshot_last_dir); util_fname_split(filename, &load_snapshot_last_dir, NULL); if (machine_read_snapshot(filename, 0) < 0) ui_error(_("Cannot load snapshot file\n`%s'"), filename); ui_update_menus(); if (filename != NULL) lib_free(filename); }
static int mem_read_rom_snapshot_module(snapshot_t *s) { BYTE major_version, minor_version; snapshot_module_t *m; int trapfl; /* Main memory module. */ m = snapshot_module_open(s, snap_rom_module_name, &major_version, &minor_version); /* This module is optional. */ if (m == NULL) return 0; /* disable traps before loading the ROM */ resources_get_int("VirtualDevices", &trapfl); resources_set_int("VirtualDevices", 0); if (major_version > SNAP_ROM_MAJOR || minor_version > SNAP_ROM_MINOR) { log_error(c128_snapshot_log, "MEM: Snapshot module version (%d.%d) newer than %d.%d.", major_version, minor_version, SNAP_ROM_MAJOR, SNAP_ROM_MINOR); goto fail; } if (0 || SMR_BA(m, c128memrom_kernal_rom, C128_KERNAL_ROM_SIZE) < 0 || SMR_BA(m, c128memrom_basic_rom, C128_BASIC_ROM_SIZE) < 0 || SMR_BA(m, c128memrom_basic_rom + C128_BASIC_ROM_SIZE, C128_EDITOR_ROM_SIZE) < 0 || SMR_BA(m, mem_chargen_rom, C128_CHARGEN_ROM_SIZE) < 0) goto fail; log_warning(c128_snapshot_log,"Dumped Romset files and saved settings will " "represent\nthe state before loading the snapshot!"); memcpy(c128memrom_kernal_trap_rom, c128memrom_kernal_rom, C128_KERNAL_ROM_SIZE); c128rom_basic_checksum(); c128rom_kernal_checksum(); /* enable traps again when necessary */ resources_set_int("VirtualDevices", trapfl); /* to get all the checkmarks right */ ui_update_menus(); return 0; fail: /* enable traps again when necessary */ resources_set_int("VirtualDevices", trapfl); if (m != NULL) snapshot_module_close(m); return -1; }
static void load_snapshot_trap(WORD unused_addr, void *unused_data) { if (autostart_program_name && machine_read_snapshot((char *)autostart_program_name, 0) < 0) { snapshot_display_error(); } ui_update_menus(); }
static TUI_MENU_CALLBACK(restore_default_settings_callback) { if (been_activated) { resources_set_defaults(); tui_message("Default settings restored."); ui_update_menus(); } return NULL; }
static UI_CALLBACK(radio_SidModel) { int engine, model, selected; selected = vice_ptr_to_int(UI_MENU_CB_PARAM); if (!CHECK_MENUS) { engine = selected >> 8; model = selected & 0xff; sid_set_engine_model(engine, model); ui_update_menus(); } else {
int c128_snapshot_read_module(snapshot_t *s) { BYTE major_version, minor_version; snapshot_module_t *m; WORD i; BYTE byte; /* Main memory module. */ m = snapshot_module_open(s, snap_module_name, &major_version, &minor_version); if (m == NULL) return -1; if (major_version > SNAP_MAJOR || minor_version > SNAP_MINOR) { log_error(c128_snapshot_log, "MEM: Snapshot module version (%d.%d) newer than %d.%d.", major_version, minor_version, SNAP_MAJOR, SNAP_MINOR); goto fail; } for (i = 0; i < 11; i++) { if (SMR_B(m, &byte) < 0) goto fail; mmu_store(i, byte); /* Assuming no side-effects */ } if (0 || SMR_BA(m, mem_ram, C128_RAM_SIZE) < 0) goto fail; /* pla_config_changed(); */ if (snapshot_module_close(m) < 0) goto fail; m = NULL; if (mem_read_rom_snapshot_module(s) < 0) goto fail; if (cartridge_snapshot_read_modules(s) < 0) { goto fail; } ui_update_menus(); return 0; fail: if (m != NULL) snapshot_module_close(m); return -1; }
static TUI_MENU_CALLBACK(set_model_callback) { if (been_activated) { pet_set_model(param, NULL); ui_update_menus(); } /* This way, the "Not Really!" item is always the default one. */ *become_default = 0; return NULL; }
static void load_snapshot_trap(WORD unused_addr, void *unused_data) { if (autostart_program_name && machine_read_snapshot((char *)autostart_program_name, 0) < 0) #ifdef HAS_TRANSLATION ui_error(translate_text(IDGS_CANNOT_LOAD_SNAPSHOT_FILE)); #else ui_error(_("Cannot load snapshot file.")); #endif ui_update_menus(); }
static UI_CALLBACK(set_joystick_device_4) { int tmp; if (!CHECK_MENUS) { resources_set_int("JoyDevice4", vice_ptr_to_int(UI_MENU_CB_PARAM)); ui_update_menus(); } else { resources_get_int("JoyDevice4", &tmp); ui_menu_set_tick(w, tmp == vice_ptr_to_int(UI_MENU_CB_PARAM)); } }
/* Autostart PRG file `file_name'. The PRG file can either be a raw CBM file or a P00 file, and the FS-based drive emulation is set up so that its directory becomes the current one on unit #8. */ int autostart_prg(const char *file_name, unsigned int runmode) { char *directory; char *file; fileio_info_t *finfo; if (network_connected()) return -1; finfo = fileio_open(file_name, NULL, FILEIO_FORMAT_RAW | FILEIO_FORMAT_P00, FILEIO_COMMAND_READ | FILEIO_COMMAND_FSNAME, FILEIO_TYPE_PRG); if (finfo == NULL) { log_error(autostart_log, "Cannot open `%s'.", file_name); return -1; } /* Extract the directory path to allow FS-based drive emulation to work. */ util_fname_split(file_name, &directory, &file); if (archdep_path_is_relative(directory)) { char *tmp; archdep_expand_path(&tmp, directory); lib_free(directory); directory = tmp; /* FIXME: We should actually eat `.'s and `..'s from `directory' instead. */ } /* Setup FS-based drive emulation. */ fsdevice_set_directory(directory ? directory : ".", 8); set_true_drive_emulation_mode(0); orig_drive_true_emulation_state =0; resources_set_int("VirtualDevices", 1); resources_set_int("FSDevice8ConvertP00", 1); file_system_detach_disk(8); ui_update_menus(); /* Now it's the same as autostarting a disk image. */ reboot_for_autostart((char *)(finfo->name), AUTOSTART_HASDISK, runmode); lib_free(directory); lib_free(file); fileio_close(finfo); log_message(autostart_log, "Preparing to load PRG file `%s'.", file_name); return 0; }
static UI_CALLBACK(swap_joystick_ports) { int tmp1, tmp2; if (w != NULL) { vsync_suspend_speed_eval(); } resources_get_int("JoyDevice1", &tmp1); resources_get_int("JoyDevice2", &tmp2); resources_set_int("JoyDevice1", tmp2); resources_set_int("JoyDevice2", tmp1); ui_update_menus(); }
static UI_CALLBACK(swap_userport_joystick_ports) { int tmp3, tmp4; if (w != NULL) { vsync_suspend_speed_eval(); } resources_get_int("JoyDevice3", &tmp3); resources_get_int("JoyDevice4", &tmp4); resources_set_int("JoyDevice3", tmp4); resources_set_int("JoyDevice4", tmp3); ui_update_menus(); }
static UI_CALLBACK(toggle_pause) { static int pause = 0; if (!CHECK_MENUS) { pause = !pause; ui_update_menus(); ui_pause_emulation(pause); return; } ui_menu_set_tick(w, pause); }
static TUI_MENU_CALLBACK(load_settings_callback) { if (been_activated) { if (resources_load(NULL) < 0) { tui_error("Cannot load settings."); } else { tui_message("Settings loaded successfully."); ui_update_menus(); } } return NULL; }