image_init_result sega8_cart_slot_device::call_load() { if (m_cart) { UINT32 len = (software_entry() == nullptr) ? length() : get_software_region_length("rom"); UINT32 offset = 0; UINT8 *ROM; if (m_is_card && len > 0x8000) { seterror(IMAGE_ERROR_UNSPECIFIED, "Attempted loading a card larger than 32KB"); return image_init_result::FAIL; } // check for header if ((len % 0x4000) == 512) { offset = 512; len -= 512; } // make sure that we only get complete (0x4000) rom banks if (len & 0x3fff) len = ((len >> 14) + 1) << 14; m_cart->rom_alloc(len, tag()); ROM = m_cart->get_rom_base(); if (software_entry() == nullptr) { fseek(offset, SEEK_SET); fread(ROM, len); } else memcpy(ROM, get_software_region("rom"), get_software_region_length("rom")); /* check the image */ if (verify_cart(ROM, len) != image_verify_result::PASS) logerror("Warning loading image: verify_cart failed\n"); if (software_entry() != nullptr) m_type = sega8_get_pcb_id(get_feature("slot") ? get_feature("slot") : "rom"); else m_type = get_cart_type(ROM, len); set_lphaser_xoffset(ROM, len); setup_ram(); // Check for gamegear cartridges with PIN 42 set to SMS mode if (software_entry() != nullptr) { const char *pin_42 = get_feature("pin_42"); if (pin_42 && !strcmp(pin_42, "sms_mode")) m_cart->set_sms_mode(1); } // when loading from fullpath m_late_battery_enable can be TRUE and in that case // we attempt to load a battery because the game might have it! if (m_cart->get_ram_size() && (m_cart->get_has_battery() || m_cart->get_late_battery())) battery_load(m_cart->get_ram_base(), m_cart->get_ram_size(), 0x00); //printf("Type: %s\n", sega8_get_slot(type)); internal_header_logging(ROM + offset, len, m_cart->get_ram_size()); return image_init_result::PASS; } return image_init_result::PASS; }
bool a78_cart_slot_device::call_load() { if (m_cart) { UINT32 len; if (software_entry() != nullptr) { const char *pcb_name; bool has_ram = get_software_region("ram") ? TRUE : FALSE; bool has_nvram = get_software_region("nvram") ? TRUE : FALSE; len = get_software_region_length("rom"); m_cart->rom_alloc(len, tag()); memcpy(m_cart->get_rom_base(), get_software_region("rom"), len); if ((pcb_name = get_feature("slot")) != nullptr) m_type = a78_get_pcb_id(pcb_name); else m_type = A78_TYPE0; if (has_ram) m_cart->ram_alloc(get_software_region_length("ram")); if (has_nvram) { m_cart->nvram_alloc(get_software_region_length("nvram")); battery_load(m_cart->get_nvram_base(), get_software_region_length("nvram"), 0xff); } } else { // Load and check the header int mapper; char head[128]; fread(head, 128); if (verify_header((char *)head) == IMAGE_VERIFY_FAIL) return IMAGE_INIT_FAIL; len = (head[49] << 24) | (head[50] << 16) | (head[51] << 8) | head[52]; if (len + 128 > length()) { logerror("Invalid length in the header. The game might be corrupted.\n"); len = length() - 128; } // let's try to auto-fix some common errors in the header mapper = validate_header((head[53] << 8) | head[54], TRUE); switch (mapper & 0x2e) { case 0x0000: m_type = BIT(mapper, 0) ? A78_TYPE1 : A78_TYPE0; break; case 0x0002: m_type = BIT(mapper, 0) ? A78_TYPE3 : A78_TYPE2; break; case 0x0006: m_type = A78_TYPE6; break; case 0x000a: m_type = A78_TYPEA; break; case 0x0022: case 0x0026: if (len > 0x40000) m_type = A78_MEGACART; else m_type = A78_VERSABOARD; break; } // check if cart has a POKEY at $0450 (typically a VersaBoard variant) if (mapper & 0x40) { if (m_type != A78_TYPE2) { m_type &= ~0x02; m_type += A78_POKEY0450; } } // check special bits, which override the previous if ((mapper & 0xff00) == 0x0100) m_type = A78_ACTIVISION; else if ((mapper & 0xff00) == 0x0200) m_type = A78_ABSOLUTE; logerror("Cart type: 0x%x\n", m_type); if (head[58] == 1) { osd_printf_info("This cart supports external NVRAM using HSC.\n"); osd_printf_info("Run it with the High Score Cart mounted to exploit this feature.\n"); } else if (head[58] == 2) { osd_printf_info("This cart supports external NVRAM using SaveKey.\n"); osd_printf_info("This is not supported in MAME currently.\n"); } if (head[63]) { osd_printf_info("This cart requires XBoarD / XM expansion\n"); osd_printf_info("Run it through the expansion to exploit this feature.\n"); } internal_header_logging((UINT8 *)head, length()); m_cart->rom_alloc(len, tag()); fread(m_cart->get_rom_base(), len); if (m_type == A78_TYPE6) m_cart->ram_alloc(0x4000); if (m_type == A78_MEGACART || (m_type >= A78_VERSABOARD && m_type <= A78_VERSA_POK450)) m_cart->ram_alloc(0x8000); if (m_type == A78_XB_BOARD || m_type == A78_XM_BOARD) m_cart->ram_alloc(0x20000); if (m_type == A78_HSC || m_type == A78_XM_BOARD) { m_cart->nvram_alloc(0x800); battery_load(m_cart->get_nvram_base(), 0x800, 0xff); } } //printf("Type: %s\n", a78_get_slot(m_type)); } return IMAGE_INIT_PASS; }