devices/bus/c64/exp: reworked cart loading [hap]

This commit is contained in:
Ivan Vangelista 2021-02-17 13:08:45 +01:00
parent 181040bf3b
commit 83bc1bcdc0
2 changed files with 22 additions and 16 deletions

View File

@ -105,6 +105,11 @@ image_init_result c64_expansion_slot_device::call_load()
{
if (m_card)
{
m_card->m_roml_size = 0;
m_card->m_romh_size = 0;
m_card->m_exrom = 1;
m_card->m_game = 1;
size_t size;
if (!loaded_through_softlist())
@ -114,7 +119,8 @@ image_init_result c64_expansion_slot_device::call_load()
if (is_filetype("80"))
{
fread(m_card->m_roml, size);
m_card->m_exrom = (0);
m_card->m_roml_size = size;
m_card->m_exrom = 0;
if (size == 0x4000)
{
@ -124,6 +130,7 @@ image_init_result c64_expansion_slot_device::call_load()
else if (is_filetype("a0"))
{
fread(m_card->m_romh, 0x2000);
m_card->m_romh_size = 0x2000;
m_card->m_exrom = 0;
m_card->m_game = 0;
@ -131,32 +138,25 @@ image_init_result c64_expansion_slot_device::call_load()
else if (is_filetype("e0"))
{
fread(m_card->m_romh, 0x2000);
m_card->m_romh_size = 0x2000;
m_card->m_game = 0;
}
else if (is_filetype("crt"))
{
size_t roml_size = 0;
size_t romh_size = 0;
int exrom = 1;
int game = 1;
if (cbm_crt_read_header(image_core_file(), &roml_size, &romh_size, &exrom, &game))
if (cbm_crt_read_header(image_core_file(), &m_card->m_roml_size, &m_card->m_romh_size, &m_card->m_exrom, &m_card->m_game))
{
uint8_t *roml = nullptr;
uint8_t *romh = nullptr;
m_card->m_roml = std::make_unique<uint8_t[]>(roml_size);
m_card->m_romh = std::make_unique<uint8_t[]>(romh_size);
m_card->m_roml = std::make_unique<uint8_t[]>(m_card->m_roml_size);
m_card->m_romh = std::make_unique<uint8_t[]>(m_card->m_romh_size);
if (roml_size) roml = m_card->m_roml.get();
if (romh_size) romh = m_card->m_romh.get();
if (m_card->m_roml_size) roml = m_card->m_roml.get();
if (m_card->m_romh_size) romh = m_card->m_romh.get();
cbm_crt_read_data(image_core_file(), roml, romh);
}
m_card->m_exrom = exrom;
m_card->m_game = game;
}
}
else
@ -188,6 +188,12 @@ image_init_result c64_expansion_slot_device::call_load()
if (get_feature("game") != nullptr) m_card->m_game = atol(get_feature("game"));
}
}
if ((m_card->m_roml_size & (m_card->m_roml_size - 1)) || (m_card->m_romh_size & (m_card->m_romh_size - 1)))
{
seterror(IMAGE_ERROR_UNSPECIFIED, "ROM size must be power of 2");
return image_init_result::FAIL;
}
}
return image_init_result::PASS;

View File

@ -153,8 +153,8 @@ protected:
std::unique_ptr<uint8_t[]> m_romx;
std::unique_ptr<uint8_t[]> m_nvram;
uint32_t m_roml_size;
uint32_t m_romh_size;
size_t m_roml_size;
size_t m_romh_size;
int m_game;
int m_exrom;