From 66c0252a03d1790fd912f423de2dd3d23d434183 Mon Sep 17 00:00:00 2001 From: AJR Date: Tue, 9 Jan 2024 19:42:38 -0500 Subject: ata/cr589.cpp, isa/mcd.cpp, nscsi/hd.cpp, nscsi/s1410.cpp: Use multibyte.h helpers --- src/devices/bus/ata/cr589.cpp | 10 +++-- src/devices/bus/isa/mcd.cpp | 24 ++++------- src/devices/bus/nscsi/hd.cpp | 93 +++++++++++++++++++---------------------- src/devices/bus/nscsi/s1410.cpp | 6 ++- 4 files changed, 62 insertions(+), 71 deletions(-) diff --git a/src/devices/bus/ata/cr589.cpp b/src/devices/bus/ata/cr589.cpp index 5905a54bd54..f1b5add1c47 100644 --- a/src/devices/bus/ata/cr589.cpp +++ b/src/devices/bus/ata/cr589.cpp @@ -3,6 +3,8 @@ #include "emu.h" #include "cr589.h" +#include "multibyte.h" + static constexpr int identity_offset = 0x3ab; static constexpr char download_identity[] = "MATSHITA CD98Q4 DOWNLOADGS0N"; @@ -58,17 +60,17 @@ void matsushita_cr589_device::ExecCommand() break; case 0x3b: // WRITE BUFFER - bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ]; + bufferOffset = get_u24be( &command[ 3 ] ); m_phase = SCSI_PHASE_DATAOUT; m_status_code = SCSI_STATUS_CODE_GOOD; - m_transfer_length = ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ]; + m_transfer_length = get_u24be( &command[ 6 ] ); break; case 0x3c: // READ BUFFER - bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ]; + bufferOffset = get_u24be( &command[ 3 ] ); m_phase = SCSI_PHASE_DATAIN; m_status_code = SCSI_STATUS_CODE_GOOD; - m_transfer_length = ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ]; + m_transfer_length = get_u24be( &command[ 6 ] ); break; case 0xcc: // FIRMWARE DOWNLOAD ENABLE diff --git a/src/devices/bus/isa/mcd.cpp b/src/devices/bus/isa/mcd.cpp index 0b99c220cd1..085ab3676b9 100644 --- a/src/devices/bus/isa/mcd.cpp +++ b/src/devices/bus/isa/mcd.cpp @@ -3,9 +3,11 @@ #include "emu.h" #include "mcd.h" -#include "coreutil.h" #include "speaker.h" +#include "coreutil.h" +#include "multibyte.h" + void mcd_isa_device::map(address_map &map) { map(0x0, 0x0).rw(FUNC(mcd_isa_device::data_r), FUNC(mcd_isa_device::cmd_w)); @@ -165,8 +167,8 @@ uint16_t mcd_isa_device::dack16_r(int line) uint16_t ret = 0; if(m_buf_idx < 2351) { - ret = m_buf[m_buf_idx++]; - ret |= (m_buf[m_buf_idx++] << 8); + ret = get_u16le(&m_buf[m_buf_idx]); + m_buf_idx += 2; } m_buf_count -= 2; if(!m_buf_count) @@ -275,12 +277,8 @@ void mcd_isa_device::cmd_w(uint8_t data) uint32_t first = cdrom_file::lba_to_msf(150), last = cdrom_file::lba_to_msf(m_cdrom_handle->get_track_start(0xaa)); m_cmdbuf[1] = 1; m_cmdbuf[2] = dec_2_bcd(m_cdrom_handle->get_last_track()); - m_cmdbuf[3] = (last >> 16) & 0xff; - m_cmdbuf[4] = (last >> 8) & 0xff; - m_cmdbuf[5] = last & 0xff; - m_cmdbuf[6] = (first >> 16) & 0xff; - m_cmdbuf[7] = (first >> 8) & 0xff; - m_cmdbuf[8] = first & 0xff; + put_u24be(&m_cmdbuf[3], last); + put_u24be(&m_cmdbuf[6], first); m_cmdbuf[9] = 0; m_cmdbuf_count = 10; m_readcount = 0; @@ -301,13 +299,9 @@ void mcd_isa_device::cmd_w(uint8_t data) m_cmdbuf[1] = (m_cdrom_handle->get_adr_control(m_curtoctrk) << 4) & 0xf0; m_cmdbuf[2] = 0; // track num except when reading toc m_cmdbuf[3] = dec_2_bcd(m_curtoctrk + 1); // index - m_cmdbuf[4] = (len >> 16) & 0xff; - m_cmdbuf[5] = (len >> 8) & 0xff; - m_cmdbuf[6] = len & 0xff; + put_u24be(&m_cmdbuf[4], len); m_cmdbuf[7] = 0; - m_cmdbuf[8] = (start >> 16) & 0xff; - m_cmdbuf[9] = (start >> 8) & 0xff; - m_cmdbuf[10] = start & 0xff; + put_u24be(&m_cmdbuf[8], start); if(m_curtoctrk >= tracks) m_curtoctrk = 0; else if(m_mode & MODE_GET_TOC) diff --git a/src/devices/bus/nscsi/hd.cpp b/src/devices/bus/nscsi/hd.cpp index cbbeb0378d9..8e210e22d10 100644 --- a/src/devices/bus/nscsi/hd.cpp +++ b/src/devices/bus/nscsi/hd.cpp @@ -4,6 +4,8 @@ #include "bus/nscsi/hd.h" #include "imagedev/harddriv.h" +#include "multibyte.h" + #define LOG_COMMAND (1U << 1) #define LOG_DATA (1U << 2) #define LOG_UNSUPPORTED (1U << 3) @@ -108,7 +110,7 @@ void nscsi_harddisk_device::scsi_command() break; case SC_READ_6: - lba = ((scsi_cmdbuf[1] & 0x1f)<<16) | (scsi_cmdbuf[2]<<8) | scsi_cmdbuf[3]; + lba = get_u24be(&scsi_cmdbuf[1]) & 0x1fffff; blocks = scsi_cmdbuf[4]; if(!blocks) blocks = 256; @@ -127,7 +129,7 @@ void nscsi_harddisk_device::scsi_command() break; case SC_WRITE_6: - lba = ((scsi_cmdbuf[1] & 0x1f)<<16) | (scsi_cmdbuf[2]<<8) | scsi_cmdbuf[3]; + lba = get_u24be(&scsi_cmdbuf[1]) & 0x1fffff; blocks = scsi_cmdbuf[4]; if(!blocks) blocks = 256; @@ -221,13 +223,11 @@ void nscsi_harddisk_device::scsi_command() uint32_t dsize = info.cylinders * info.heads * info.sectors - 1; scsi_cmdbuf[pos++] = 0x08; // Block descriptor length scsi_cmdbuf[pos++] = 0x00; - scsi_cmdbuf[pos++] = (dsize>>16) & 0xff; - scsi_cmdbuf[pos++] = (dsize>>8) & 0xff; - scsi_cmdbuf[pos++] = (dsize & 0xff); + put_u24be(&scsi_cmdbuf[pos], dsize); + pos += 3; scsi_cmdbuf[pos++] = 0x00; - scsi_cmdbuf[pos++] = (info.sectorbytes>>16)&0xff; - scsi_cmdbuf[pos++] = (info.sectorbytes>>8)&0xff; - scsi_cmdbuf[pos++] = (info.sectorbytes & 0xff); + put_u24be(&scsi_cmdbuf[pos], info.sectorbytes); + pos += 3; int pmax = page == 0x3f ? 0x3e : page; int pmin = page == 0x3f ? 0x00 : page; @@ -279,18 +279,18 @@ void nscsi_harddisk_device::scsi_command() case 0x03: { // Format parameters page scsi_cmdbuf[pos++] = 0x83; // PS, page id scsi_cmdbuf[pos++] = 0x16; // Page length - scsi_cmdbuf[pos++] = (info.cylinders * info.heads) >> 8; // Track/zone - scsi_cmdbuf[pos++] = info.cylinders * info.heads; // Track/zone + put_u16be(&scsi_cmdbuf[pos], info.cylinders * info.heads); // Track/zone + pos += 2; scsi_cmdbuf[pos++] = 0x00; // Alt sect/zone scsi_cmdbuf[pos++] = 0x00; // Alt sect/zone scsi_cmdbuf[pos++] = 0x00; // Alt track/zone scsi_cmdbuf[pos++] = 0x00; // Alt track/zone scsi_cmdbuf[pos++] = 0x00; // Alt track/volume scsi_cmdbuf[pos++] = 0x00; // Alt track/volume - scsi_cmdbuf[pos++] = info.sectors >> 8; // Sectors/track - scsi_cmdbuf[pos++] = info.sectors; // Sectors/track - scsi_cmdbuf[pos++] = info.sectorbytes >> 8; // Bytes/sector - scsi_cmdbuf[pos++] = info.sectorbytes; // Bytes/sector + put_u16be(&scsi_cmdbuf[pos], info.sectors); // Sectors/track + pos += 2; + put_u16be(&scsi_cmdbuf[pos], info.sectorbytes); // Bytes/sector + pos += 2; scsi_cmdbuf[pos++] = 0x00; // Interleave scsi_cmdbuf[pos++] = 0x00; // Interleave scsi_cmdbuf[pos++] = 0x00; // Track skew @@ -307,28 +307,27 @@ void nscsi_harddisk_device::scsi_command() case 0x04: { // Rigid drive geometry page scsi_cmdbuf[pos++] = 0x84; // PS, page id scsi_cmdbuf[pos++] = 0x16; // Page length - scsi_cmdbuf[pos++] = info.cylinders >> 16; // Cylinders - scsi_cmdbuf[pos++] = info.cylinders >> 8; // Cylinders - scsi_cmdbuf[pos++] = info.cylinders; // Cylinders - scsi_cmdbuf[pos++] = info.heads; // Heads - scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp - scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp - scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp - scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - reduced write current - scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - reduced write current - scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - reduced write current - scsi_cmdbuf[pos++] = 0x00; // Drive step rate - scsi_cmdbuf[pos++] = 0x00; // Drive step rate - scsi_cmdbuf[pos++] = 0x00; // Landing zone cylinder - scsi_cmdbuf[pos++] = 0x00; // Landing zone cylinder - scsi_cmdbuf[pos++] = 0x00; // Landing zone cylinder - scsi_cmdbuf[pos++] = 0x00; // RPL - scsi_cmdbuf[pos++] = 0x00; // Rotational offset - scsi_cmdbuf[pos++] = 0x00; // Reserved - scsi_cmdbuf[pos++] = uint8_t(10000 >> 8); // Medium rotation rate - scsi_cmdbuf[pos++] = uint8_t(10000); // Medium rotation rate - scsi_cmdbuf[pos++] = 0x00; // Reserved - scsi_cmdbuf[pos++] = 0x00; // Reserved + put_u24be(&scsi_cmdbuf[pos], info.cylinders); // Cylinders + pos += 3; + scsi_cmdbuf[pos++] = info.heads; // Heads + scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp + scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp + scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp + scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - reduced write current + scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - reduced write current + scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - reduced write current + scsi_cmdbuf[pos++] = 0x00; // Drive step rate + scsi_cmdbuf[pos++] = 0x00; // Drive step rate + scsi_cmdbuf[pos++] = 0x00; // Landing zone cylinder + scsi_cmdbuf[pos++] = 0x00; // Landing zone cylinder + scsi_cmdbuf[pos++] = 0x00; // Landing zone cylinder + scsi_cmdbuf[pos++] = 0x00; // RPL + scsi_cmdbuf[pos++] = 0x00; // Rotational offset + scsi_cmdbuf[pos++] = 0x00; // Reserved + put_u16be(&scsi_cmdbuf[pos], 10000); // Medium rotation rate + pos += 2; + scsi_cmdbuf[pos++] = 0x00; // Reserved + scsi_cmdbuf[pos++] = 0x00; // Reserved break; } @@ -405,7 +404,7 @@ void nscsi_harddisk_device::scsi_command() case SC_RECEIVE_DIAGNOSTIC_RESULTS: { LOG("command RECEIVE DIAGNOSTIC RESULTS\n"); - int size = (scsi_cmdbuf[3] << 8) | scsi_cmdbuf[4]; + int size = get_u16be(&scsi_cmdbuf[3]); int pos = 0; scsi_cmdbuf[pos++] = 0; scsi_cmdbuf[pos++] = 6; @@ -423,7 +422,7 @@ void nscsi_harddisk_device::scsi_command() case SC_SEND_DIAGNOSTIC: { LOG("command SEND DIAGNOSTIC\n"); - int size = (scsi_cmdbuf[3] << 8) | scsi_cmdbuf[4]; + int size = get_u16be(&scsi_cmdbuf[3]); if(scsi_cmdbuf[1] & 4) { // Self-test scsi_status_complete(SS_GOOD); @@ -451,14 +450,8 @@ void nscsi_harddisk_device::scsi_command() const auto &info = image->get_info(); uint32_t size = info.cylinders * info.heads * info.sectors - 1; - scsi_cmdbuf[0] = (size>>24) & 0xff; - scsi_cmdbuf[1] = (size>>16) & 0xff; - scsi_cmdbuf[2] = (size>>8) & 0xff; - scsi_cmdbuf[3] = (size & 0xff); - scsi_cmdbuf[4] = (info.sectorbytes>>24)&0xff; - scsi_cmdbuf[5] = (info.sectorbytes>>16)&0xff; - scsi_cmdbuf[6] = (info.sectorbytes>>8)&0xff; - scsi_cmdbuf[7] = (info.sectorbytes & 0xff); + put_u32be(&scsi_cmdbuf[0], size); + put_u32be(&scsi_cmdbuf[4], info.sectorbytes); scsi_data_in(0, 8); scsi_status_complete(SS_GOOD); @@ -466,8 +459,8 @@ void nscsi_harddisk_device::scsi_command() } case SC_READ_10: - lba = (scsi_cmdbuf[2]<<24) | (scsi_cmdbuf[3]<<16) | (scsi_cmdbuf[4]<<8) | scsi_cmdbuf[5]; - blocks = (scsi_cmdbuf[7] << 8) | scsi_cmdbuf[8]; + lba = get_u32be(&scsi_cmdbuf[2]); + blocks = get_u16be(&scsi_cmdbuf[7]); LOG("command READ EXTENDED start=%08x blocks=%04x\n",lba, blocks); @@ -483,8 +476,8 @@ void nscsi_harddisk_device::scsi_command() break; case SC_WRITE_10: - lba = (scsi_cmdbuf[2]<<24) | (scsi_cmdbuf[3]<<16) | (scsi_cmdbuf[4]<<8) | scsi_cmdbuf[5]; - blocks = (scsi_cmdbuf[7] << 8) | scsi_cmdbuf[8]; + lba = get_u32be(&scsi_cmdbuf[2]); + blocks = get_u16be(&scsi_cmdbuf[7]); LOG("command WRITE EXTENDED start=%08x blocks=%04x\n", lba, blocks); diff --git a/src/devices/bus/nscsi/s1410.cpp b/src/devices/bus/nscsi/s1410.cpp index d6e66547870..52358d7e851 100644 --- a/src/devices/bus/nscsi/s1410.cpp +++ b/src/devices/bus/nscsi/s1410.cpp @@ -3,6 +3,8 @@ #include "emu.h" #include "bus/nscsi/s1410.h" +#include "multibyte.h" + #define LOG_COMMAND (1U << 1) #define LOG_DATA (1U << 2) @@ -87,7 +89,7 @@ void nscsi_s1410_device::scsi_command() const auto &info = image->get_info(); auto block = std::make_unique(info.sectorbytes); memset(&block[0], 0x6c, info.sectorbytes); - lba = ((scsi_cmdbuf[1] & 0x1f)<<16) | (scsi_cmdbuf[2]<<8) | scsi_cmdbuf[3]; + lba = get_u24be(&scsi_cmdbuf[1]) & 0x1fffff; for(; lba < (info.cylinders * info.heads * info.sectors); lba++) { image->write(lba, block.get()); } @@ -102,7 +104,7 @@ void nscsi_s1410_device::scsi_command() return; } - lba = ((scsi_cmdbuf[1] & 0x1f)<<16) | (scsi_cmdbuf[2]<<8) | scsi_cmdbuf[3]; + lba = get_u24be(&scsi_cmdbuf[1]) & 0x1fffff; blocks = (bytes_per_sector == 256) ? 32 : 17; int track_length = blocks*bytes_per_sector; -- cgit v1.2.3