From 747a76dc4bdf74bd4bf86f36688427d12f1b150f Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 7 Jan 2024 17:26:04 -0500 Subject: a7800/a78_slot.cpp, nes/nes_unif.hxx: Use multibyte.h helpers --- src/devices/bus/a7800/a78_slot.cpp | 22 ++++++++++---------- src/devices/bus/a7800/a78_slot.h | 4 ++-- src/devices/bus/nes/nes_unif.hxx | 41 +++++++++++++++++++------------------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/devices/bus/a7800/a78_slot.cpp b/src/devices/bus/a7800/a78_slot.cpp index 2163b7e80b1..481e60faf90 100644 --- a/src/devices/bus/a7800/a78_slot.cpp +++ b/src/devices/bus/a7800/a78_slot.cpp @@ -28,6 +28,8 @@ #include "emu.h" #include "a78_slot.h" +#include "multibyte.h" + //************************************************************************** // GLOBAL VARIABLES //************************************************************************** @@ -365,14 +367,14 @@ std::pair a78_cart_slot_device::call_load() { // Load and check the header int mapper; - char head[128]; + uint8_t head[128]; fread(head, 128); auto err = verify_header(head); if (err.first) return err; - len = (head[49] << 24) | (head[50] << 16) | (head[51] << 8) | head[52]; + len = get_u32be(&head[49]); if (len + 128 > length()) { logerror("Invalid length in the header. The game might be corrupted.\n"); @@ -380,7 +382,7 @@ std::pair a78_cart_slot_device::call_load() } // let's try to auto-fix some common errors in the header - mapper = validate_header((head[53] << 8) | head[54], true); + mapper = validate_header(get_u16be(&head[53]), true); switch (mapper & 0x2e) { @@ -444,7 +446,7 @@ std::pair a78_cart_slot_device::call_load() osd_printf_info("Run it through the expansion to exploit this feature.\n"); } - internal_header_logging((uint8_t *)head, length()); + internal_header_logging(head, length()); m_cart->rom_alloc(len); fread(m_cart->get_rom_base(), len); @@ -485,11 +487,11 @@ void a78_cart_slot_device::call_unload() has an admissible header -------------------------------------------------*/ -std::pair a78_cart_slot_device::verify_header(const char *header) +std::pair a78_cart_slot_device::verify_header(const uint8_t *header) { const char *magic = "ATARI7800"; - if (strncmp(magic, header + 1, 9)) + if (strncmp(magic, reinterpret_cast(header + 1), 9)) return std::make_pair(image_error::INVALIDIMAGE, "Not a valid A7800 image"); logerror("returning ID_OK\n"); @@ -514,7 +516,7 @@ std::string a78_cart_slot_device::get_default_card_software(get_default_card_sof hook.image_file()->read(&head[0], 128, actual); // 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((head[53] << 8) | head[54], false); + int const mapper = validate_header(get_u16be(&head[53]), false); int type = A78_TYPE0; switch (mapper & 0x2e) @@ -699,11 +701,11 @@ void a78_cart_slot_device::write_40xx(offs_t offset, uint8_t data) -------------------------------------------------*/ -void a78_cart_slot_device::internal_header_logging(uint8_t *header, uint32_t len) +void a78_cart_slot_device::internal_header_logging(const uint8_t *header, uint32_t len) { char head_title[35]; - uint32_t head_length = (header[49] << 24) | (header[50] << 16) | (header[51] << 8) | header[52]; - uint16_t head_mapper = (header[53] << 8) | header[54]; + uint32_t head_length = get_u32be(&header[49]); + uint16_t head_mapper = get_u16be(&header[53]); uint8_t head_ctrl1 = header[55]; uint8_t head_ctrl2 = header[56]; uint8_t head_ispal = header[57]; diff --git a/src/devices/bus/a7800/a78_slot.h b/src/devices/bus/a7800/a78_slot.h index fbb5a455666..9f9b8126c82 100644 --- a/src/devices/bus/a7800/a78_slot.h +++ b/src/devices/bus/a7800/a78_slot.h @@ -129,9 +129,9 @@ private: // device_t implementation virtual void device_start() override; - std::pair verify_header(const char *header); + std::pair verify_header(const uint8_t *header); int validate_header(int head, bool log) const; - void internal_header_logging(uint8_t *header, uint32_t len); + void internal_header_logging(const uint8_t *header, uint32_t len); device_a78_cart_interface *m_cart; int m_type; diff --git a/src/devices/bus/nes/nes_unif.hxx b/src/devices/bus/nes/nes_unif.hxx index ff900d88913..b4955cd9b8d 100644 --- a/src/devices/bus/nes/nes_unif.hxx +++ b/src/devices/bus/nes/nes_unif.hxx @@ -12,6 +12,7 @@ ****************************************************************************************/ #include "corestr.h" +#include "multibyte.h" /* Set to generate prg & chr files when the cart is loaded */ #define SPLIT_PRG 0 @@ -220,7 +221,7 @@ void nes_cart_slot_device::call_load_unif() fseek(4, SEEK_SET); fread(&buffer, 4); - unif_ver = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + unif_ver = get_u32le(buffer); logerror("Loaded game in UNIF format, version %d\n", unif_ver); do @@ -241,7 +242,7 @@ void nes_cart_slot_device::call_load_unif() mapr_chunk_found = true; logerror("[MAPR] chunk found: "); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); if (chunk_length <= 0x20) fread(&unif_mapr, chunk_length); @@ -255,7 +256,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("Skip this chunk. We need a [MAPR] chunk before anything else.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -269,7 +270,7 @@ void nes_cart_slot_device::call_load_unif() /* TO DO: it would be nice to check if more than one MAPR chunk is present */ logerror("[MAPR] chunk found (in the 2nd run). Already loaded.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -277,7 +278,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[READ] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -285,7 +286,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[NAME] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -293,7 +294,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[WRTR] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -301,7 +302,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[TVCI] chunk found.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); fread(&temp_byte, 1); logerror("Television Standard : %s\n", (temp_byte == 0) ? "NTSC" : (temp_byte == 1) ? "PAL" : "Does not matter"); @@ -312,7 +313,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[TVSC] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -320,7 +321,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[DINF] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -328,7 +329,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[CTRL] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -336,7 +337,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[BATR] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -344,7 +345,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[VROR] chunk found. No support yet.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -352,7 +353,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[MIRR] chunk found.\n"); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); fread(&mirror, 1); @@ -362,7 +363,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[PCK%c] chunk found. No support yet.\n", magic2[3]); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -370,7 +371,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[CCK%c] chunk found. No support yet.\n", magic2[3]); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); read_length += (chunk_length + 8); } @@ -378,7 +379,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[PRG%c] chunk found. ", magic2[3]); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); prg_size += chunk_length; if (chunk_length / 0x4000) @@ -399,7 +400,7 @@ void nes_cart_slot_device::call_load_unif() { logerror("[CHR%c] chunk found. ", magic2[3]); fread(&buffer, 4); - chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); + chunk_length = get_u32le(buffer); vrom_size += chunk_length; logerror("It consists of %d 8K-blocks.\n", chunk_length / 0x2000); @@ -562,7 +563,7 @@ const char * nes_cart_slot_device::get_default_card_unif(const uint8_t *ROM, uin { if ((ROM[read_length + 0] == 'M') && (ROM[read_length + 1] == 'A') && (ROM[read_length + 2] == 'P') && (ROM[read_length + 3] == 'R')) { - chunk_length = ROM[read_length + 4] | (ROM[read_length + 5] << 8) | (ROM[read_length + 6] << 16) | (ROM[read_length + 7] << 24); + chunk_length = get_u32le(&ROM[read_length + 4]); if (chunk_length <= 0x20) memcpy(unif_mapr, ROM + read_length + 8, chunk_length); @@ -571,7 +572,7 @@ const char * nes_cart_slot_device::get_default_card_unif(const uint8_t *ROM, uin } else { - chunk_length = ROM[read_length + 4] | (ROM[read_length + 5] << 8) | (ROM[read_length + 6] << 16) | (ROM[read_length + 7] << 24); + chunk_length = get_u32le(&ROM[read_length + 4]); read_length += (chunk_length + 8); } } while (len > read_length); -- cgit v1.2.3