int autostart_prg_with_virtual_fs(const char *file_name, fileio_info_t *fh) { char *directory; char *file; /* 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); resources_set_int("DriveTrueEmulation", 0); resources_set_int("VirtualDevices", 1); resources_set_int("FSDevice8ConvertP00", 1); file_system_detach_disk(8); resources_set_int("FileSystemDevice8", ATTACH_DEVICE_FS); lib_free(directory); lib_free(file); return 0; }
/* Add one zfile to the list. `orig_name' is automatically expanded to the complete path. */ static void zfile_list_add(const char *tmp_name, const char *orig_name, enum compression_type type, int write_mode, FILE *stream, FILE *fd) { zfile_t *new_zfile = lib_malloc(sizeof(zfile_t)); /* Make sure we have the complete path of the file. */ archdep_expand_path(&new_zfile->orig_name, orig_name); /* The new zfile becomes first on the list. */ new_zfile->tmp_name = tmp_name ? lib_stralloc(tmp_name) : NULL; new_zfile->write_mode = write_mode; new_zfile->stream = stream; new_zfile->fd = fd; new_zfile->type = type; new_zfile->action = ZFILE_KEEP; new_zfile->request_string = NULL; new_zfile->next = zfile_list; new_zfile->prev = NULL; if (zfile_list != NULL) { zfile_list->prev = new_zfile; } zfile_list = new_zfile; }
char *archdep_filename_parameter(const char *name) { char *exp; char *a; archdep_expand_path(&exp, name); a = util_concat("\"", exp, "\"", NULL); lib_free(exp); return a; }
char *archdep_filename_parameter(const char *name) { char *exp; char *a; archdep_expand_path(&exp, name); a = archdep_quote_parameter(exp); lib_free(exp); return a; }
/* 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 int set_hvsc_root(const char *path, void *param) { char *result; /* expand ~, no effect on Windows */ archdep_expand_path(&result, path); util_string_set(&hvsc_root, result); /* "reboot" hvsclib */ hvsc_exit(); hvsc_init(result); lib_free(result); return 0; }
int zfile_close_action(const char *filename, zfile_action_t action, const char *request_str) { char *fullname = NULL; zfile_t *p = zfile_list; archdep_expand_path(&fullname, filename); while (p != NULL) { if (p->orig_name && !strcmp(p->orig_name, fullname)) { p->action = action; p->request_string = request_str ? lib_stralloc(request_str) : NULL; lib_free(fullname); return 0; } p = p->next; } lib_free(fullname); return -1; }
/* attach cartridge image type == -1 NONE type == 0 CRT format returns -1 on error, 0 on success */ int cartridge_attach_image(int type, const char *filename) { BYTE *rawcart; char *abs_filename; int carttype = CARTRIDGE_NONE; int cartid = CARTRIDGE_NONE; int oldmain = CARTRIDGE_NONE; int slotmain = 0; if (filename == NULL) { return -1; } /* Attaching no cartridge always works. */ if (type == CARTRIDGE_NONE || *filename == '\0') { return 0; } if (archdep_path_is_relative(filename)) { archdep_expand_path(&abs_filename, filename); } else { abs_filename = lib_stralloc(filename); } if (type == CARTRIDGE_CRT) { carttype = crt_getid(abs_filename); if (carttype == -1) { log_message(LOG_DEFAULT, "CART: '%s' is not a valid CRT file.", abs_filename); lib_free(abs_filename); return -1; } } else { carttype = type; } DBG(("CART: cartridge_attach_image type: %d ID: %d\n", type, carttype)); /* allocate temporary array */ rawcart = lib_malloc(C64CART_IMAGE_LIMIT); /* cart should always be detached. there is no reason for doing fancy checks here, and it will cause problems incase a cart MUST be detached before attaching another, or even itself. (eg for initialization reasons) most obvious reason: attaching a different ROM (software) for the same cartridge (hardware) */ slotmain = cart_is_slotmain(carttype); if (slotmain) { /* if the cart to be attached is in the "Main Slot", detach whatever cart currently is in the "Main Slot" */ oldmain = cart_getid_slotmain(); if (oldmain != CARTRIDGE_NONE) { DBG(("CART: detach slot main ID: %d\n", oldmain)); cartridge_detach_image(oldmain); } } if (oldmain != carttype) { DBG(("CART: detach %s ID: %d\n", slotmain ? "slot main" : "other slot", carttype)); cartridge_detach_image(carttype); } if (type == CARTRIDGE_CRT) { DBG(("CART: attach CRT ID: %d '%s'\n", carttype, filename)); cartid = crt_attach(abs_filename, rawcart); if (cartid == CARTRIDGE_NONE) { goto exiterror; } if (type < 0) { DBG(("CART: attach generic CRT ID: %d\n", type)); } } else { DBG(("CART: attach BIN ID: %d '%s'\n", carttype, filename)); cartid = carttype; if (cart_bin_attach(carttype, abs_filename, rawcart) < 0) { goto exiterror; } } if (cart_is_slotmain(cartid)) { DBG(("cartridge_attach MAIN ID: %d\n", cartid)); mem_cartridge_type = cartid; cart_romhbank_set_slotmain(0); cart_romlbank_set_slotmain(0); } else { DBG(("cartridge_attach (other) ID: %d\n", cartid)); } DBG(("CART: attach RAW ID: %d\n", cartid)); cart_attach(cartid, rawcart); cart_power_off(); if (cart_is_slotmain(cartid)) { /* "Main Slot" */ DBG(("CART: set main slot ID: %d type: %d\n", carttype, type)); c64cart_type = type; if (type == CARTRIDGE_CRT) { crttype = carttype; } util_string_set(&cartfile, abs_filename); } DBG(("CART: cartridge_attach_image type: %d ID: %d done.\n", type, carttype)); lib_free(rawcart); log_message(LOG_DEFAULT, "CART: attached '%s' as ID %d.", abs_filename, carttype); lib_free(abs_filename); return 0; exiterror: DBG(("CART: error\n")); lib_free(rawcart); log_message(LOG_DEFAULT, "CART: could not attach '%s'.", abs_filename); lib_free(abs_filename); return -1; }