diff options
Diffstat (limited to 'src/devices/bus/snes/snes_slot.cpp')
-rw-r--r-- | src/devices/bus/snes/snes_slot.cpp | 122 |
1 files changed, 62 insertions, 60 deletions
diff --git a/src/devices/bus/snes/snes_slot.cpp b/src/devices/bus/snes/snes_slot.cpp index d97e08e16d0..d447c390bd2 100644 --- a/src/devices/bus/snes/snes_slot.cpp +++ b/src/devices/bus/snes/snes_slot.cpp @@ -48,7 +48,6 @@ ***********************************************************************************************************/ - #include "emu.h" #include "snes_slot.h" @@ -89,11 +88,11 @@ device_sns_cart_interface::~device_sns_cart_interface() // rom_alloc - alloc the space for the cart //------------------------------------------------- -void device_sns_cart_interface::rom_alloc(uint32_t size, const char *tag) +void device_sns_cart_interface::rom_alloc(uint32_t size) { if (m_rom == nullptr) { - m_rom = device().machine().memory().region_alloc(std::string(tag).append(SNSSLOT_ROM_REGION_TAG).c_str(), size, 1, ENDIANNESS_LITTLE)->base(); + m_rom = device().machine().memory().region_alloc(device().subtag("^cart:rom"), size, 1, ENDIANNESS_LITTLE)->base(); m_rom_size = size; } } @@ -171,7 +170,7 @@ void device_sns_cart_interface::rom_map_setup(uint32_t size) // write_irq - set the cart IRQ output //------------------------------------------------- -WRITE_LINE_MEMBER(device_sns_cart_interface::write_irq) +void device_sns_cart_interface::write_irq(int state) { if (m_slot != nullptr) m_slot->write_irq(state); @@ -189,6 +188,30 @@ uint8_t device_sns_cart_interface::read_open_bus() return 0xff; } +//------------------------------------------------- +// scanlines_r - get motherboard scanline count +//------------------------------------------------- + +int device_sns_cart_interface::scanlines_r() +{ + if (m_slot != nullptr) + return m_slot->scanlines_r(); + + return 0xff; +} + +//------------------------------------------------- +// address_r - get address pin from S-CPU +//------------------------------------------------- + +offs_t device_sns_cart_interface::address_r() +{ + if (m_slot != nullptr) + return m_slot->address_r(); + + return 0xff; +} + //************************************************************************** // LIVE DEVICE //************************************************************************** @@ -198,13 +221,13 @@ uint8_t device_sns_cart_interface::read_open_bus() //------------------------------------------------- base_sns_cart_slot_device::base_sns_cart_slot_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock), - device_image_interface(mconfig, *this), + device_cartrom_image_interface(mconfig, *this), device_slot_interface(mconfig, *this), m_addon(ADDON_NONE), m_type(SNES_MODE20), m_cart(nullptr), m_irq_callback(*this), - m_open_bus_callback(*this) + m_open_bus_callback(*this, 0xff) { } @@ -240,9 +263,6 @@ void base_sns_cart_slot_device::device_start() m_cart = dynamic_cast<device_sns_cart_interface *>(get_card_device()); if (m_cart != nullptr) m_cart->m_slot = this; - - m_irq_callback.resolve_safe(); - m_open_bus_callback.resolve_safe(0xff); } @@ -312,7 +332,7 @@ static int sns_get_pcb_id(const char *slot) { for (auto & elem : slot_list) { - if (!core_stricmp(elem.slot_option, slot)) + if (!strcmp(elem.slot_option, slot)) return elem.pcb_id; } @@ -626,15 +646,12 @@ static int snes_find_addon_chip(const uint8_t *buffer, uint32_t start_offs, uint -------------------------------------------------*/ -image_init_result base_sns_cart_slot_device::call_load() +std::pair<std::error_condition, std::string> base_sns_cart_slot_device::call_load() { if (m_cart) { - uint8_t *ROM; - uint32_t len, offset = 0; - const char *slot_name; - - /* Check for a header (512 bytes), and skip it if found */ + // Check for a header (512 bytes), and skip it if found + uint32_t offset = 0; if (!loaded_through_softlist()) { uint32_t tmplen = length(); @@ -644,10 +661,10 @@ image_init_result base_sns_cart_slot_device::call_load() fseek(offset, SEEK_SET); } - len = !loaded_through_softlist() ? (length() - offset) : get_software_region_length("rom"); + uint32_t const len = !loaded_through_softlist() ? (length() - offset) : get_software_region_length("rom"); - m_cart->rom_alloc(len, tag()); - ROM = m_cart->get_rom_base(); + m_cart->rom_alloc(len); + uint8_t *const ROM = m_cart->get_rom_base(); if (!loaded_through_softlist()) fread(ROM, len); else @@ -670,13 +687,14 @@ image_init_result base_sns_cart_slot_device::call_load() get_cart_type_addon(ROM, len, m_type, m_addon); else { + const char *slot_name; if ((slot_name = get_feature("slot")) == nullptr) m_type = SNES_MODE20; else m_type = sns_get_pcb_id(slot_name); if (m_type == SNES_DSP && len > 0x100000) - m_type = SNES_DSP_2MB; + m_type = SNES_DSP_2MB; } if (!loaded_through_softlist()) @@ -702,11 +720,9 @@ image_init_result base_sns_cart_slot_device::call_load() //printf("Type %d\n", m_type); internal_header_logging(ROM, len); - - return image_init_result::PASS; } - return image_init_result::PASS; + return std::make_pair(std::error_condition(), std::string()); } @@ -828,37 +844,37 @@ void base_sns_cart_slot_device::setup_addon_from_fullpath() switch (m_addon) { case ADDON_DSP1: - ROM = machine().root_device().memregion(region.c_str())->base(); + ROM = machine().root_device().memregion(region)->base(); m_cart->addon_bios_alloc(0x2800); memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800); break; case ADDON_DSP1B: - ROM = machine().root_device().memregion(region.c_str())->base(); + ROM = machine().root_device().memregion(region)->base(); m_cart->addon_bios_alloc(0x2800); memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800); break; case ADDON_DSP2: - ROM = machine().root_device().memregion(region.c_str())->base(); + ROM = machine().root_device().memregion(region)->base(); m_cart->addon_bios_alloc(0x2800); memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800); break; case ADDON_DSP3: - ROM = machine().root_device().memregion(region.c_str())->base(); + ROM = machine().root_device().memregion(region)->base(); m_cart->addon_bios_alloc(0x2800); memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800); break; case ADDON_DSP4: - ROM = machine().root_device().memregion(region.c_str())->base(); + ROM = machine().root_device().memregion(region)->base(); m_cart->addon_bios_alloc(0x2800); memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800); break; case ADDON_ST010: - ROM = machine().root_device().memregion(region.c_str())->base(); + ROM = machine().root_device().memregion(region)->base(); m_cart->addon_bios_alloc(0x11000); memcpy(m_cart->get_addon_bios_base(), ROM, 0x11000); break; case ADDON_ST011: - ROM = machine().root_device().memregion(region.c_str())->base(); + ROM = machine().root_device().memregion(region)->base(); m_cart->addon_bios_alloc(0x11000); memcpy(m_cart->get_addon_bios_base(), ROM, 0x11000); break; @@ -1022,13 +1038,13 @@ std::string base_sns_cart_slot_device::get_default_card_software(get_default_car { if (hook.image_file()) { - const char *slot_string; uint32_t offset; - uint32_t len = hook.image_file()->size(); + uint64_t len; + hook.image_file()->length(len); // FIXME: check error return, guard against excessively large file std::vector<uint8_t> rom(len); int type = 0, addon = 0; - hook.image_file()->read(&rom[0], len); + /*auto const [err, actual] =*/ read(*hook.image_file(), &rom[0], len); // FIXME: check for error result or read returning short offset = snes_skip_header(&rom[0], len); @@ -1071,7 +1087,7 @@ std::string base_sns_cart_slot_device::get_default_card_software(get_default_car break; } - slot_string = sns_get_slot(type); + char const *const slot_string = sns_get_slot(type); return std::string(slot_string); } @@ -1152,26 +1168,12 @@ void base_sns_cart_slot_device::chip_write(offs_t offset, uint8_t data) /* We use this to convert the company_id in the header to int value to be passed in companies[] */ static int char_to_int_conv( char id ) { - int value; - - if (id == '1') value = 0x01; - else if (id == '2') value = 0x02; - else if (id == '3') value = 0x03; - else if (id == '4') value = 0x04; - else if (id == '5') value = 0x05; - else if (id == '6') value = 0x06; - else if (id == '7') value = 0x07; - else if (id == '8') value = 0x08; - else if (id == '9') value = 0x09; - else if (id == 'A') value = 0x0a; - else if (id == 'B') value = 0x0b; - else if (id == 'C') value = 0x0c; - else if (id == 'D') value = 0x0d; - else if (id == 'E') value = 0x0e; - else if (id == 'F') value = 0x0f; - else value = 0x00; - - return value; + if (id >= '0' && id <= '9') + return id - '0'; + else if (id >= 'A' && id <= 'F') + return id - 'A' + 0x0a; + else + return 0; } #define UNK "UNKNOWN" @@ -1361,7 +1363,7 @@ void base_sns_cart_slot_device::internal_header_logging(uint8_t *ROM, uint32_t l logerror( "HEADER DETAILS\n" ); logerror( "==============\n\n" ); logerror( "\tName: %.21s\n", title ); - logerror( "\tSpeed: %s [%d]\n", (ROM[hilo_mode + 0x15] & 0xf0) ? "FastROM" : "SlowROM", (ROM[hilo_mode + 0x15] & 0xf0) >> 4); + logerror( "\tSpeed: %s [%d]\n", (ROM[hilo_mode + 0x15] & 0x10) ? "FastROM" : "SlowROM", (ROM[hilo_mode + 0x15] & 0xf0) >> 4); logerror( "\tBank size: %s [%d]\n", (ROM[hilo_mode + 0x15] & 0xf) ? "HiROM" : "LoROM", ROM[hilo_mode + 0x15] & 0xf); logerror( "\tType: %s", cart_types[type]); @@ -1373,16 +1375,16 @@ void base_sns_cart_slot_device::internal_header_logging(uint8_t *ROM, uint32_t l logerror( "\tSize: %d megabits [%d]\n", 1 << (ROM[hilo_mode + 0x17] - 7), ROM[hilo_mode + 0x17]); logerror( "\tSRAM: %d kilobits [%d]\n", ROM[hilo_mode + 0x18] * 8, ROM[hilo_mode + 0x18] ); - if (ROM[hilo_mode + 0x19] < ARRAY_LENGTH(countries)) + if (ROM[hilo_mode + 0x19] < std::size(countries)) logerror( "\tCountry: %s [%d]\n", countries[ROM[hilo_mode + 0x19]], ROM[hilo_mode + 0x19]); else logerror( "\tCountry: Unknown [%d]\n", ROM[hilo_mode + 0x19]); logerror( "\tLicense: %s [%X]\n", companies[ROM[hilo_mode + 0x1a]], ROM[hilo_mode + 0x1a]); logerror( "\tVersion: 1.%d\n", ROM[hilo_mode + 0x1b]); - logerror( "\tInv Checksum: %X %X\n", ROM[hilo_mode + 0x1d], ROM[hilo_mode + 0x1c]); - logerror( "\tChecksum: %X %X\n", ROM[hilo_mode + 0x1f], ROM[hilo_mode + 0x1e]); - logerror( "\tNMI Address: %2X%2Xh\n", ROM[hilo_mode + 0x3b], ROM[hilo_mode + 0x3a]); - logerror( "\tStart Address: %2X%2Xh\n\n", ROM[hilo_mode + 0x3d], ROM[hilo_mode + 0x3c]); + logerror( "\tInv Checksum: %02X%02Xh\n", ROM[hilo_mode + 0x1d], ROM[hilo_mode + 0x1c]); + logerror( "\tChecksum: %02X%02Xh\n", ROM[hilo_mode + 0x1f], ROM[hilo_mode + 0x1e]); + logerror( "\tNMI Address: %02X%02Xh\n", ROM[hilo_mode + 0x3b], ROM[hilo_mode + 0x3a]); + logerror( "\tStart Address: %02X%02Xh\n\n", ROM[hilo_mode + 0x3d], ROM[hilo_mode + 0x3c]); logerror( "\tMode: %d\n", type); } |