From c95313c5a35b542fbb6e9200a51e6df579980a66 Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 4 Nov 2023 15:07:14 -0400 Subject: k573mcal.cpp: Clean up code further using multibyte.h helpers --- src/mame/konami/k573mcal.cpp | 76 ++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 49 deletions(-) diff --git a/src/mame/konami/k573mcal.cpp b/src/mame/konami/k573mcal.cpp index b9c447349c5..3fa74763fe3 100644 --- a/src/mame/konami/k573mcal.cpp +++ b/src/mame/konami/k573mcal.cpp @@ -87,21 +87,16 @@ int k573mcal_device::handle_message(const uint8_t* send_buffer, uint32_t send_si system_time systime; machine().base_datetime(systime); - uint8_t resp[] = { - 0x01, // status, must be 1 - uint8_t(systime.local_time.year % 100), - uint8_t(systime.local_time.month + 1), - systime.local_time.mday, - systime.local_time.weekday, - systime.local_time.hour, - systime.local_time.minute, - seconds // Can't be the same value twice in a row - }; - + *recv_buffer++ = 0x01; // status, must be 1 + *recv_buffer++ = uint8_t(systime.local_time.year % 100); + *recv_buffer++ = uint8_t(systime.local_time.month + 1); + *recv_buffer++ = systime.local_time.mday; + *recv_buffer++ = systime.local_time.weekday; + *recv_buffer++ = systime.local_time.hour; + *recv_buffer++ = systime.local_time.minute; + *recv_buffer++ = seconds; // Can't be the same value twice in a row seconds = (seconds + 1) % 60; - memcpy(recv_buffer, resp, sizeof(resp)); - recv_buffer += sizeof(resp); return 1; } @@ -112,13 +107,9 @@ int k573mcal_device::handle_message(const uint8_t* send_buffer, uint32_t send_si // Only encountered and tested on Hornet games. // msg: 71 ff ff 01 -> Offset = 0xffff, requested size = 0x01 bytes, special request for the area specification flag? Used by Sys573 - uint8_t resp[] = { - 0x01, // status, must be 1 - uint8_t(m_in1->read() & 0x0f), // Area specification - }; + *recv_buffer++ = 0x01; // status, must be 1 + *recv_buffer++ = uint8_t(m_in1->read() & 0x0f); // Area specification - memcpy(recv_buffer, resp, sizeof(resp)); - recv_buffer += sizeof(resp); return 4; } @@ -128,25 +119,22 @@ int k573mcal_device::handle_message(const uint8_t* send_buffer, uint32_t send_si if (val == 0x7f00) { // Return main ID - uint8_t resp[] = { - 0x01, // status, must be 1 - uint8_t((mainId >> 24) & 0xff), uint8_t((mainId >> 16) & 0xff), uint8_t((mainId >> 8) & 0xff), uint8_t(mainId & 0xff), - }; - - memcpy(recv_buffer, resp, sizeof(resp)); - recv_buffer += sizeof(resp); + *recv_buffer++ = 0x01; // status, must be 1 + put_u32be(recv_buffer, mainId); + recv_buffer += 4; } else if (val == 0x8000) { + using namespace std::literals; + static const std::string_view init_complete = ""sv; + // Return sub ID - uint8_t resp[] = { - 0x01, // status, must be 1 - '<', 'I', 'N', 'I', 'T', ' ', 'C', 'O', 'M', 'P', 'L', 'E', 'T', 'E', '!', '>', - uint8_t((subId >> 24) & 0xff), uint8_t((subId >> 16) & 0xff), uint8_t((subId >> 8) & 0xff), uint8_t(subId & 0xff), - uint8_t((~subId >> 24) & 0xff), uint8_t((~subId >> 16) & 0xff), uint8_t((~subId >> 8) & 0xff), uint8_t(~subId & 0xff), - }; - - memcpy(recv_buffer, resp, sizeof(resp)); - recv_buffer += sizeof(resp); + *recv_buffer++ = 0x01; // status, must be 1 + memcpy(recv_buffer, init_complete.data(), init_complete.size()); + recv_buffer += init_complete.size(); + put_u32be(recv_buffer, subId); + recv_buffer += 4; + put_u32be(recv_buffer, ~subId); + recv_buffer += 4; } return 4; @@ -160,12 +148,7 @@ int k573mcal_device::handle_message(const uint8_t* send_buffer, uint32_t send_si // Set next sub ID subId = get_u32be(&send_buffer[4]); - uint8_t resp[] = { - 0x01, // status, must be 1 - }; - - memcpy(recv_buffer, resp, sizeof(resp)); - recv_buffer += sizeof(resp); + *recv_buffer++ = 0x01; // status, must be 1 } return 12; @@ -179,14 +162,9 @@ int k573mcal_device::handle_message(const uint8_t* send_buffer, uint32_t send_si // 000000000000B5 is ??? // msg: 7e xx - uint8_t resp[] = { - // 0x01 - Breaks loop, sends next byte - // 0x04 - Resends byte - 0x01, - }; - - memcpy(recv_buffer, resp, sizeof(resp)); - recv_buffer += sizeof(resp); + // status: 0x01 - Breaks loop, sends next byte + // 0x04 - Resends byte + *recv_buffer++ = 0x01; return 2; } -- cgit v1.2.3