/* get filename of cart with given type */ const char *cartridge_get_file_name(int type) { if (cart_getid_slotmain() == type) { return cartfile; } return cart_get_file_name(type); }
/* returns 1 if the cartridge of the given type is enabled - used by c64iec.c:iec_available_busses */ int cartridge_type_enabled(int type) { if (cart_getid_slotmain() == type) { return 1; } return cart_type_enabled(type); }
/* detach cartridge from "Main Slot" */ void cart_detach_slotmain(void) { int type = cart_getid_slotmain(); DBG(("CART: detach main %d: type: %d id: %d\n", type, c64cart_type, crttype)); if (type != CARTRIDGE_NONE) { cart_detach(type); DBG(("CART: unset cart config\n")); cart_config_changed_slotmain(CMODE_RAM, CMODE_RAM, CMODE_READ); cart_power_off(); /* reset "Main Slot" */ mem_cartridge_type = CARTRIDGE_NONE; c64cart_type = CARTRIDGE_NONE; crttype = CARTRIDGE_NONE; if (cartfile) { lib_free(cartfile); cartfile = NULL; } } }
static BYTE read_pa(tpi_context_t *tpi_context) { BYTE byte = 0; #ifdef USEPASSTHROUGHHACK if (cart_getid_slotmain() != CARTRIDGE_NONE) { /* passthrough */ byte |= (MV_GAME_GAMECART << 5); /* passthrough !GAME */ } else { byte |= (MV_GAME_NOCART << 5); /* passthrough !GAME */ } #else /* DBG(("MV: read pa extgame %d\n", mv_extgame)); */ byte |= ((mv_extgame ^ 1) << 5); #endif byte |= ((t6721->eos ^ 1) << 6); /* !EOS = End of Speech from T6721 */ byte |= (DTRD << 7); /* DIR = Data in Ready from 40105 */ byte = (byte & ~(tpi_context->c_tpi)[TPI_DDPA]) | (tpi_context->c_tpi[TPI_PA] & tpi_context->c_tpi[TPI_DDPA]); /* DBG(("MV: read pa %02x\n", byte)); */ return byte; }
/* 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; }