summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Ivan Vangelista <mesgnet@yahoo.it>2021-02-17 13:08:45 +0100
committer Ivan Vangelista <mesgnet@yahoo.it>2021-02-17 13:08:45 +0100
commit83bc1bcdc09d6d134c1964375195230c5cf4f7bd (patch)
treef32ebcd47be471f46fc63d38db71ef583ad16951
parent181040bf3bd1964e5919198dca5f960bc9bdbac6 (diff)
devices/bus/c64/exp: reworked cart loading [hap]
-rw-r--r--src/devices/bus/c64/exp.cpp34
-rw-r--r--src/devices/bus/c64/exp.h4
2 files changed, 22 insertions, 16 deletions
diff --git a/src/devices/bus/c64/exp.cpp b/src/devices/bus/c64/exp.cpp
index 00fa6310ce4..e4cc42f61d8 100644
--- a/src/devices/bus/c64/exp.cpp
+++ b/src/devices/bus/c64/exp.cpp
@@ -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;
diff --git a/src/devices/bus/c64/exp.h b/src/devices/bus/c64/exp.h
index ed0beb8caa2..391827b271f 100644
--- a/src/devices/bus/c64/exp.h
+++ b/src/devices/bus/c64/exp.h
@@ -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;