mirror of
https://github.com/holub/mame
synced 2025-04-20 07:22:04 +03:00
apple1.cpp, microtan.cpp, mtx.cpp, vtech1.cpp: Eliminate use of device_image_interface::ptr() method
* vtech1.cpp: Correct fencepost error in snapshot loader
This commit is contained in:
parent
2509d8b900
commit
810fd2a951
@ -174,14 +174,11 @@ static const uint8_t apple1_keymap[] =
|
||||
// header is "LOAD:abcdDATA:" where abcd is the starting address
|
||||
SNAPSHOT_LOAD_MEMBER(apple1_state::snapshot_cb)
|
||||
{
|
||||
uint64_t snapsize;
|
||||
uint8_t *data;
|
||||
uint16_t start, end;
|
||||
static const char hd1[6] = "LOAD:";
|
||||
static const char hd2[6] = "DATA:";
|
||||
|
||||
// get the snapshot's size
|
||||
snapsize = image.length();
|
||||
uint64_t snapsize = image.length();
|
||||
|
||||
if (snapsize < 12)
|
||||
{
|
||||
@ -195,21 +192,21 @@ SNAPSHOT_LOAD_MEMBER(apple1_state::snapshot_cb)
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
data = (uint8_t *)image.ptr();
|
||||
if (!data)
|
||||
auto data = std::make_unique<uint8_t []>(snapsize);
|
||||
if (image.fread(data.get(), snapsize) != snapsize)
|
||||
{
|
||||
logerror("Internal error loading snapshot\n");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
if ((memcmp(hd1, data, 5)) || (memcmp(hd2, &data[7], 5)))
|
||||
if ((memcmp(hd1, &data[0], 5)) || (memcmp(hd2, &data[7], 5)))
|
||||
{
|
||||
logerror("Snapshot is invalid\n");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
start = (data[5]<<8) | data[6];
|
||||
end = (snapsize - 12) + start;
|
||||
uint16_t start = (data[5]<<8) | data[6];
|
||||
uint16_t end = (snapsize - 12) + start;
|
||||
|
||||
// check if this fits in RAM; load below 0xe000 must fit in RAMSIZE,
|
||||
// load at 0xe000 must fit in 4K
|
||||
|
@ -157,14 +157,16 @@ private:
|
||||
|
||||
SNAPSHOT_LOAD_MEMBER(vtech1_base_state::snapshot_cb)
|
||||
{
|
||||
address_space &space = m_maincpu->space(AS_PROGRAM);
|
||||
uint8_t header[24];
|
||||
char pgmname[18];
|
||||
|
||||
// get the header
|
||||
image.fread(&header, sizeof(header));
|
||||
uint8_t header[24];
|
||||
if (image.fread(&header, sizeof(header)) != sizeof(header))
|
||||
{
|
||||
//image.seterror(image_error::UNSPECIFIED);
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
// get image name
|
||||
char pgmname[17];
|
||||
for (int i = 0; i < 16; i++)
|
||||
pgmname[i] = header[i+4];
|
||||
pgmname[16] = '\0';
|
||||
@ -175,9 +177,16 @@ SNAPSHOT_LOAD_MEMBER(vtech1_base_state::snapshot_cb)
|
||||
uint16_t size = end - start;
|
||||
|
||||
// write it to ram
|
||||
uint8_t *ptr = (uint8_t *)image.ptr() + sizeof(header);
|
||||
auto buf = std::make_unique<uint8_t []>(size);
|
||||
if (image.fread(buf.get(), size) != size)
|
||||
{
|
||||
//image.seterror(image_error::UNSPECIFIED);
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
uint8_t *ptr = &buf[0];
|
||||
|
||||
for (uint16_t addr = start; addr <= end; addr++, ptr++)
|
||||
address_space &space = m_maincpu->space(AS_PROGRAM);
|
||||
for (uint16_t addr = start; addr < end; addr++, ptr++)
|
||||
{
|
||||
uint8_t to_write = *ptr;
|
||||
space.write_byte(addr, to_write);
|
||||
|
@ -667,14 +667,27 @@ void microtan_state::snapshot_copy(uint8_t *snapshot_buff, int snapshot_size)
|
||||
|
||||
SNAPSHOT_LOAD_MEMBER(microtan_state::snapshot_cb)
|
||||
{
|
||||
uint8_t *snapshot_buff = (uint8_t*)image.ptr();
|
||||
if (!snapshot_buff)
|
||||
uint64_t snapshot_len = image.length();
|
||||
if (snapshot_len < 4 || snapshot_len >= 66000)
|
||||
{
|
||||
//image.seterror(image_error::INVALIDIMAGE);
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
if (verify_snapshot(snapshot_buff, image.length()) != image_verify_result::PASS)
|
||||
auto snapshot_buff = std::make_unique<uint8_t []>(snapshot_len);
|
||||
if (image.fread(snapshot_buff.get(), snapshot_len) != snapshot_len)
|
||||
{
|
||||
//image.seterror(image_error::UNSPECIFIED);
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
snapshot_copy(snapshot_buff, image.length());
|
||||
if (verify_snapshot(snapshot_buff.get(), snapshot_len) != image_verify_result::PASS)
|
||||
{
|
||||
//image.seterror(image_error::INVALIDIMAGE);
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
snapshot_copy(snapshot_buff.get(), snapshot_len);
|
||||
return image_init_result::PASS;
|
||||
}
|
||||
|
||||
|
@ -435,8 +435,26 @@ DEVICE_IMAGE_LOAD_MEMBER( mtx_state::rompak_load )
|
||||
// more data from tape. todo: tapes which autorun after loading
|
||||
SNAPSHOT_LOAD_MEMBER(mtx_state::snapshot_cb)
|
||||
{
|
||||
address_space &program = m_maincpu->space(AS_PROGRAM);
|
||||
uint8_t *data = (uint8_t*)image.ptr();
|
||||
uint64_t length = image.length();
|
||||
|
||||
if (length < 18)
|
||||
{
|
||||
image.seterror(image_error::INVALIDIMAGE, "File too short");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
if (length >= 0x10000 - 0x4000 + 18)
|
||||
{
|
||||
image.seterror(image_error::INVALIDIMAGE, "File too long");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
auto data = std::make_unique<uint8_t []>(length);
|
||||
if (image.fread(data.get(), length) != length)
|
||||
{
|
||||
image.seterror(image_error::UNSPECIFIED, "Error reading file");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
// verify first byte
|
||||
if (data[0] != 0xff)
|
||||
@ -451,11 +469,13 @@ SNAPSHOT_LOAD_MEMBER(mtx_state::snapshot_cb)
|
||||
tape_name[15] = '\0';
|
||||
image.message("Loading '%s'", tape_name);
|
||||
|
||||
address_space &program = m_maincpu->space(AS_PROGRAM);
|
||||
|
||||
// reset memory map
|
||||
bankswitch(0);
|
||||
|
||||
// start of system variables area
|
||||
uint16_t system_variables_base = pick_integer_le(data, 16, 2);
|
||||
uint16_t system_variables_base = pick_integer_le(data.get(), 16, 2);
|
||||
|
||||
// write system variables
|
||||
uint16_t system_variables_size = 0;
|
||||
@ -483,19 +503,31 @@ SNAPSHOT_LOAD_MEMBER(mtx_state::snapshot_cb)
|
||||
|
||||
QUICKLOAD_LOAD_MEMBER(mtx_state::quickload_cb)
|
||||
{
|
||||
address_space &program = m_maincpu->space(AS_PROGRAM);
|
||||
uint8_t *data = (uint8_t*)image.ptr();
|
||||
uint64_t length = image.length();
|
||||
|
||||
if (image.length() < 4)
|
||||
if (length < 4)
|
||||
{
|
||||
image.seterror(image_error::INVALIDIMAGE, "File too short");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
uint16_t code_base = pick_integer_le(data, 0, 2);
|
||||
uint16_t code_length = pick_integer_le(data, 2, 2);
|
||||
if (length >= 0x10000 - 0x4000 + 4)
|
||||
{
|
||||
image.seterror(image_error::INVALIDIMAGE, "File too long");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
if (image.length() < code_length)
|
||||
auto data = std::make_unique<uint8_t []>(length);
|
||||
if (image.fread(data.get(), length) != length)
|
||||
{
|
||||
image.seterror(image_error::UNSPECIFIED, "Error reading file");
|
||||
return image_init_result::FAIL;
|
||||
}
|
||||
|
||||
uint16_t code_base = pick_integer_le(data.get(), 0, 2);
|
||||
uint16_t code_length = pick_integer_le(data.get(), 2, 2);
|
||||
|
||||
if (length < code_length)
|
||||
{
|
||||
image.seterror(image_error::INVALIDIMAGE, "File too short");
|
||||
return image_init_result::FAIL;
|
||||
@ -511,6 +543,7 @@ QUICKLOAD_LOAD_MEMBER(mtx_state::quickload_cb)
|
||||
bankswitch(0);
|
||||
|
||||
// write image data
|
||||
address_space &program = m_maincpu->space(AS_PROGRAM);
|
||||
for (int i = 0; i < code_length; i++)
|
||||
program.write_byte(code_base + i, data[4 + i]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user