Skip to content

Commit

Permalink
util/ioprocs.cpp: Added wrappers for common patterns.
Browse files Browse the repository at this point in the history
emu/diimage.h: Removed fread overloads that allocate memory for output.

util/core_file.cpp: Changed output size of load to size_t.
  • Loading branch information
cuavas committed Feb 22, 2024
1 parent 53082b4 commit 050d231
Show file tree
Hide file tree
Showing 251 changed files with 3,395 additions and 2,579 deletions.
16 changes: 8 additions & 8 deletions src/devices/bus/a2bus/a2cffa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ void a2bus_cffa2_device::nvram_default()

bool a2bus_cffa2_device::nvram_read(util::read_stream &file)
{
size_t actual;
return !file.read(m_eeprom, 0x1000, actual) && actual == 0x1000;
auto const [err, actual] = read(file, m_eeprom, 0x1000);
return !err && (actual == 0x1000);
}

bool a2bus_cffa2_device::nvram_write(util::write_stream &file)
{
size_t actual;
return !file.write(m_eeprom, 0x1000, actual) && actual == 0x1000;
auto const [err, actual] = write(file, m_eeprom, 0x1000);
return !err;
}

void a2bus_cffa2_6502_device::nvram_default()
Expand All @@ -314,14 +314,14 @@ void a2bus_cffa2_6502_device::nvram_default()

bool a2bus_cffa2_6502_device::nvram_read(util::read_stream &file)
{
size_t actual;
return !file.read(m_eeprom, 0x1000, actual) && actual == 0x1000;
auto const [err, actual] = read(file, m_eeprom, 0x1000);
return !err && (actual == 0x1000);
}

bool a2bus_cffa2_6502_device::nvram_write(util::write_stream &file)
{
size_t actual;
return !file.write(m_eeprom, 0x1000, actual) && actual == 0x1000;
auto const [err, actual] = write(file, m_eeprom, 0x1000);
return !err;
}

} // anonymous namespace
Expand Down
3 changes: 1 addition & 2 deletions src/devices/bus/a7800/a78_slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ std::string a78_cart_slot_device::get_default_card_software(get_default_card_sof

// Load and check the header
uint8_t head[128];
std::size_t actual;
hook.image_file()->read(&head[0], 128, actual); // FIXME: check error return or read returning short
/*auto const [err, actual] =*/ read(*hook.image_file(), &head[0], 128); // FIXME: check error return or read returning short

// let's try to auto-fix some common errors in the header
int const mapper = validate_header(get_u16be(&head[53]), false);
Expand Down
6 changes: 2 additions & 4 deletions src/devices/bus/a800/a800_slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,8 @@ std::string a800_cart_slot_device::get_default_card_software(get_default_card_so
// check whether there is an header, to identify the cart type
if ((len % 0x1000) == 0x10)
{
size_t actual;
uint8_t head[0x10];
hook.image_file()->read(&head[0], 0x10, actual); // FIXME: check error return or read returning short
/*auto const [err, actual] =*/ read(*hook.image_file(), &head[0], 0x10); // FIXME: check error return or read returning short
type = identify_cart_type(&head[0]);
}
else // otherwise try to guess based on size
Expand Down Expand Up @@ -701,9 +700,8 @@ std::string a5200_cart_slot_device::get_default_card_software(get_default_card_s
int type = A5200_8K;
if ((len % 0x1000) == 0x10)
{
size_t actual;
uint8_t head[0x10];
hook.image_file()->read(&head[0], 0x10, actual); // FIXME: check error return or read returning short
/*auto const [err, actual] =*/ read(*hook.image_file(), &head[0], 0x10); // FIXME: check error return or read returning short
type = identify_cart_type(&head[0]);
}
else
Expand Down
17 changes: 17 additions & 0 deletions src/devices/bus/abcbus/ssa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ void abc_super_smartaid_device::device_reset()
}


void abc_super_smartaid_device::nvram_default()
{
}

bool abc_super_smartaid_device::nvram_read(util::read_stream &file)
{
auto const [err, actual] = read(file, m_nvram, m_nvram.bytes());
return !err && (actual == m_nvram.bytes());
}

bool abc_super_smartaid_device::nvram_write(util::write_stream &file)
{
auto const [err, actual] = write(file, m_nvram, m_nvram.bytes());
return !err;
}



//**************************************************************************
// ABC BUS INTERFACE
Expand Down
6 changes: 3 additions & 3 deletions src/devices/bus/abcbus/ssa.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class abc_super_smartaid_device : public device_t,
virtual void device_reset() override;

// device_nvram_interface implementation
virtual void nvram_default() override { }
virtual bool nvram_read(util::read_stream &file) override { size_t actual; return !file.read(m_nvram, m_nvram.bytes(), actual) && actual == m_nvram.bytes(); }
virtual bool nvram_write(util::write_stream &file) override { size_t actual; return !file.write(m_nvram, m_nvram.bytes(), actual) && actual == m_nvram.bytes(); }
virtual void nvram_default() override;
virtual bool nvram_read(util::read_stream &file) override;
virtual bool nvram_write(util::write_stream &file) override;

// device_abcbus_interface implementation
virtual void abcbus_cs(uint8_t data) override { m_bus->write_cs(data); }
Expand Down
11 changes: 9 additions & 2 deletions src/devices/bus/adam/exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "emu.h"
#include "exp.h"

#include <tuple>



//**************************************************************************
Expand Down Expand Up @@ -76,21 +78,26 @@ void adam_expansion_slot_device::device_start()

std::pair<std::error_condition, std::string> adam_expansion_slot_device::call_load()
{
std::error_condition err;

if (m_card)
{
if (!loaded_through_softlist())
{
size_t const size = length();

fread(m_card->m_rom, size);
std::size_t actual;
std::tie(err, m_card->m_rom, actual) = read(image_core_file(), size);
if (!err && (actual != size))
err = std::errc::io_error;
}
else
{
load_software_region("rom", m_card->m_rom);
}
}

return std::make_pair(std::error_condition(), std::string());
return std::make_pair(err, std::string());
}


Expand Down
3 changes: 1 addition & 2 deletions src/devices/bus/aquarius/slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ std::string aquarius_cartridge_slot_device::get_default_card_software(get_defaul
{
uint8_t header[16];

size_t actual;
hook.image_file()->seek(len - 0x2000, SEEK_SET); // FIXME: check error return
hook.image_file()->read(&header[0], 16, actual); // FIXME: check error return or read returning short
read(*hook.image_file(), &header[0], 16); // FIXME: check error return or read returning short

// detect SuperCart header
if (!memcmp(&header[0], SC08_HEADER, 16) || !memcmp(&header[0], SC16_HEADER, 16))
Expand Down
8 changes: 4 additions & 4 deletions src/devices/bus/ata/cr589.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void matsushita_cr589_device::nvram_default()

bool matsushita_cr589_device::nvram_read(util::read_stream &file)
{
size_t actual;
return !file.read(buffer, sizeof(buffer), actual) && actual == sizeof(buffer);
auto const [err, actual] = read(file, buffer, sizeof(buffer));
return !err && (actual == sizeof(buffer));
}


Expand All @@ -42,8 +42,8 @@ bool matsushita_cr589_device::nvram_read(util::read_stream &file)

bool matsushita_cr589_device::nvram_write(util::write_stream &file)
{
size_t actual;
return !file.write(buffer, sizeof(buffer), actual) && actual == sizeof(buffer);
auto const [err, actual] = write(file, buffer, sizeof(buffer));
return !err;
}


Expand Down
19 changes: 19 additions & 0 deletions src/devices/bus/c64/dqbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ void c64_dqbb_cartridge_device::device_reset()
}


void c64_dqbb_cartridge_device::nvram_default()
{
}


bool c64_dqbb_cartridge_device::nvram_read(util::read_stream &file)
{
auto const [err, actual] = read(file, m_nvram.get(), 0x4000);
return !err && (actual == 0x4000);
}


bool c64_dqbb_cartridge_device::nvram_write(util::write_stream &file)
{
auto const [err, actual] = write(file, m_nvram.get(), 0x4000);
return !err;
}


//-------------------------------------------------
// c64_cd_r - cartridge data read
//-------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/devices/bus/c64/dqbb.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class c64_dqbb_cartridge_device : public device_t,
virtual void device_reset() override;

// device_nvram_interface implementation
virtual void nvram_default() override { }
virtual bool nvram_read(util::read_stream &file) override { size_t actual; return !file.read(m_nvram.get(), 0x4000, actual) && actual == 0x4000; }
virtual bool nvram_write(util::write_stream &file) override { size_t actual; return !file.write(m_nvram.get(), 0x4000, actual) && actual == 0x4000; }
virtual void nvram_default() override;
virtual bool nvram_read(util::read_stream &file) override;
virtual bool nvram_write(util::write_stream &file) override;

// device_c64_expansion_card_interface implementation
virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override;
Expand Down
25 changes: 20 additions & 5 deletions src/devices/bus/c64/exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "formats/cbm_crt.h"

#include <tuple>



//**************************************************************************
Expand Down Expand Up @@ -110,11 +112,16 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa

if (!loaded_through_softlist())
{
util::core_file &file = image_core_file();
size = length();

if (is_filetype("80"))
{
fread(m_card->m_roml, size);
std::size_t actual;
std::tie(err, m_card->m_roml, actual) = read(file, size);
if (!err && (actual != size))
err = std::errc::io_error;

m_card->m_roml_size = size;
m_card->m_exrom = 0;

Expand All @@ -125,22 +132,30 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa
}
else if (is_filetype("a0"))
{
fread(m_card->m_romh, 0x2000);
std::size_t actual;
std::tie(err, m_card->m_roml, actual) = read(file, 0x2000);
if (!err && (actual != 0x2000))
err = std::errc::io_error;

m_card->m_romh_size = 0x2000;

m_card->m_exrom = 0;
m_card->m_game = 0;
}
else if (is_filetype("e0"))
{
fread(m_card->m_romh, 0x2000);
std::size_t actual;
std::tie(err, m_card->m_roml, actual) = read(file, 0x2000);
if (!err && (actual != 0x2000))
err = std::errc::io_error;

m_card->m_romh_size = 0x2000;

m_card->m_game = 0;
}
else if (is_filetype("crt"))
{
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))
if (cbm_crt_read_header(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;
Expand All @@ -151,7 +166,7 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa
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);
cbm_crt_read_data(file, roml, romh);
}
}
else
Expand Down
19 changes: 19 additions & 0 deletions src/devices/bus/c64/fcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ void c64_final_chesscard_device::device_reset()
}


void c64_final_chesscard_device::nvram_default()
{
}


bool c64_final_chesscard_device::nvram_read(util::read_stream &file)
{
auto const [err, actual] = read(file, m_nvram.get(), 0x2000);
return !err && (actual == 0x2000);
}


bool c64_final_chesscard_device::nvram_write(util::write_stream &file)
{
auto const [err, actual] = write(file, m_nvram.get(), 0x2000);
return !err;
}


//-------------------------------------------------
// c64_cd_r - cartridge data read
//-------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/devices/bus/c64/fcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class c64_final_chesscard_device : public device_t,
virtual void device_reset() override;

// device_nvram_interface implementation
virtual void nvram_default() override { }
virtual bool nvram_read(util::read_stream &file) override { size_t actual; return !file.read(m_nvram.get(), 0x2000, actual) && actual == 0x2000; }
virtual bool nvram_write(util::write_stream &file) override { size_t actual; return !file.write(m_nvram.get(), 0x2000, actual) && actual == 0x2000; }
virtual void nvram_default() override;
virtual bool nvram_read(util::read_stream &file) override;
virtual bool nvram_write(util::write_stream &file) override;

// device_c64_expansion_card_interface implementation
virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override;
Expand Down
19 changes: 19 additions & 0 deletions src/devices/bus/c64/neoram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ uint8_t c64_neoram_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int s
}


void c64_neoram_cartridge_device::nvram_default()
{
}


bool c64_neoram_cartridge_device::nvram_read(util::read_stream &file)
{
auto const [err, actual] = read(file, m_nvram.get(), 0x200000);
return !err && (actual == 0x200000);
}


bool c64_neoram_cartridge_device::nvram_write(util::write_stream &file)
{
auto const [err, actual] = write(file, m_nvram.get(), 0x200000);
return !err;
}


//-------------------------------------------------
// c64_cd_w - cartridge data write
//-------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/devices/bus/c64/neoram.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class c64_neoram_cartridge_device : public device_t,
virtual void device_reset() override;

// device_nvram_interface implementation
virtual void nvram_default() override { }
virtual bool nvram_read(util::read_stream &file) override { size_t actual; return !file.read(m_nvram.get(), 0x200000, actual) && actual == 0x200000; }
virtual bool nvram_write(util::write_stream &file) override { size_t actual; return !file.write(m_nvram.get(), 0x200000, actual) && actual == 0x200000; }
virtual void nvram_default() override;
virtual bool nvram_read(util::read_stream &file) override;
virtual bool nvram_write(util::write_stream &file) override;

// device_c64_expansion_card_interface implementation
virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override;
Expand Down
Loading

0 comments on commit 050d231

Please sign in to comment.