diff options
Diffstat (limited to 'src/devices/bus/ata/cr589.cpp')
-rw-r--r-- | src/devices/bus/ata/cr589.cpp | 100 |
1 files changed, 52 insertions, 48 deletions
diff --git a/src/devices/bus/ata/cr589.cpp b/src/devices/bus/ata/cr589.cpp index 6142f75ee7a..15309f6e41e 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"; @@ -14,8 +16,8 @@ static constexpr char download_identity[] = "MATSHITA CD98Q4 DOWNLOADGS0N"; void matsushita_cr589_device::nvram_default() { - memset( buffer, 0, sizeof(buffer)); - memcpy( &buffer[ identity_offset ], "MATSHITACD-ROM CR-589 GS0N", 28 ); + memset(buffer, 0, sizeof(buffer)); + memcpy(&buffer[identity_offset], "MATSHITACD-ROM CR-589 GS0N", 28); } @@ -25,9 +27,10 @@ void matsushita_cr589_device::nvram_default() // .nv file //------------------------------------------------- -void matsushita_cr589_device::nvram_read(emu_file &file) +bool matsushita_cr589_device::nvram_read(util::read_stream &file) { - file.read(buffer, sizeof(buffer)); + auto const [err, actual] = read(file, buffer, sizeof(buffer)); + return !err && (actual == sizeof(buffer)); } @@ -37,36 +40,37 @@ void matsushita_cr589_device::nvram_read(emu_file &file) // .nv file //------------------------------------------------- -void matsushita_cr589_device::nvram_write(emu_file &file) +bool matsushita_cr589_device::nvram_write(util::write_stream &file) { - file.write(buffer, sizeof(buffer)); + auto const [err, actual] = write(file, buffer, sizeof(buffer)); + return !err; } void matsushita_cr589_device::ExecCommand() { - switch( command[ 0 ] ) + switch( command[0] ) { case T10SPC_CMD_INQUIRY: logerror("T10MMC: INQUIRY\n"); m_phase = SCSI_PHASE_DATAIN; m_status_code = SCSI_STATUS_CODE_GOOD; - m_transfer_length = SCSILengthFromUINT8( &command[ 4 ] ); + m_transfer_length = SCSILengthFromUINT8( &command[4] ); 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 @@ -83,7 +87,7 @@ void matsushita_cr589_device::ExecCommand() void matsushita_cr589_device::ReadData( uint8_t *data, int dataLength ) { - switch( command[ 0 ] ) + switch( command[0] ) { case T10SPC_CMD_INQUIRY: memset(data, 0, dataLength); @@ -92,16 +96,16 @@ void matsushita_cr589_device::ReadData( uint8_t *data, int dataLength ) if( download ) { - memcpy( &data[ 8 ], download_identity, 28 ); + memcpy( &data[8], download_identity, 28 ); } else { - memcpy( &data[ 8 ], &buffer[ identity_offset ], 28 ); + memcpy( &data[8], &buffer[identity_offset], 28 ); } break; case 0x3c: // READ BUFFER - memcpy( data, &buffer[ bufferOffset ], dataLength ); + memcpy( data, &buffer[bufferOffset], dataLength ); bufferOffset += dataLength; break; @@ -113,15 +117,15 @@ void matsushita_cr589_device::ReadData( uint8_t *data, int dataLength ) void matsushita_cr589_device::WriteData( uint8_t *data, int dataLength ) { - switch( command[ 0 ] ) + switch( command[0] ) { case 0x3b: // WRITE BUFFER - memcpy( &buffer[ bufferOffset ], data + 32, dataLength - 32 ); + memcpy( &buffer[bufferOffset], data + 32, dataLength - 32 ); bufferOffset += dataLength; break; case 0xcc: // FIRMWARE DOWNLOAD ENABLE - if( memcmp( data, &buffer[ identity_offset ], 28 ) == 0 ) + if( memcmp( data, &buffer[identity_offset], 28 ) == 0 ) { download = 1; } @@ -157,35 +161,35 @@ void matsushita_cr589_device::device_start() /// TODO: split identify buffer into another method as device_start() should be called after it's filled in, but the atapi_cdrom_device has it's own. memset(m_identify_buffer, 0, sizeof(m_identify_buffer)); - m_identify_buffer[ 0 ] = 0x8500; // ATAPI device, cmd set 5 compliant, DRQ within 3 ms of PACKET command - - m_identify_buffer[ 23 ] = ('1' << 8) | '.'; - m_identify_buffer[ 24 ] = ('0' << 8) | ' '; - m_identify_buffer[ 25 ] = (' ' << 8) | ' '; - m_identify_buffer[ 26 ] = (' ' << 8) | ' '; - - m_identify_buffer[ 27 ] = ('M' << 8) | 'A'; - m_identify_buffer[ 28 ] = ('T' << 8) | 'S'; - m_identify_buffer[ 29 ] = ('H' << 8) | 'I'; - m_identify_buffer[ 30 ] = ('T' << 8) | 'A'; - m_identify_buffer[ 31 ] = (' ' << 8) | 'C'; - m_identify_buffer[ 32 ] = ('R' << 8) | '-'; - m_identify_buffer[ 33 ] = ('5' << 8) | '8'; - m_identify_buffer[ 34 ] = ('9' << 8) | ' '; - m_identify_buffer[ 35 ] = (' ' << 8) | ' '; - m_identify_buffer[ 36 ] = (' ' << 8) | ' '; - m_identify_buffer[ 37 ] = (' ' << 8) | ' '; - m_identify_buffer[ 38 ] = (' ' << 8) | ' '; - m_identify_buffer[ 39 ] = (' ' << 8) | ' '; - m_identify_buffer[ 40 ] = (' ' << 8) | ' '; - m_identify_buffer[ 41 ] = (' ' << 8) | ' '; - m_identify_buffer[ 42 ] = (' ' << 8) | ' '; - m_identify_buffer[ 43 ] = (' ' << 8) | ' '; - m_identify_buffer[ 44 ] = (' ' << 8) | ' '; - m_identify_buffer[ 45 ] = (' ' << 8) | ' '; - m_identify_buffer[ 46 ] = (' ' << 8) | ' '; - - m_identify_buffer[ 49 ] = 0x0400; // IORDY may be disabled + m_identify_buffer[0] = 0x8500; // ATAPI device, cmd set 5 compliant, DRQ within 3 ms of PACKET command + + m_identify_buffer[23] = ('1' << 8) | '.'; + m_identify_buffer[24] = ('0' << 8) | ' '; + m_identify_buffer[25] = (' ' << 8) | ' '; + m_identify_buffer[26] = (' ' << 8) | ' '; + + m_identify_buffer[27] = ('M' << 8) | 'A'; + m_identify_buffer[28] = ('T' << 8) | 'S'; + m_identify_buffer[29] = ('H' << 8) | 'I'; + m_identify_buffer[30] = ('T' << 8) | 'A'; + m_identify_buffer[31] = (' ' << 8) | 'C'; + m_identify_buffer[32] = ('R' << 8) | '-'; + m_identify_buffer[33] = ('5' << 8) | '8'; + m_identify_buffer[34] = ('9' << 8) | ' '; + m_identify_buffer[35] = (' ' << 8) | ' '; + m_identify_buffer[36] = (' ' << 8) | ' '; + m_identify_buffer[37] = (' ' << 8) | ' '; + m_identify_buffer[38] = (' ' << 8) | ' '; + m_identify_buffer[39] = (' ' << 8) | ' '; + m_identify_buffer[40] = (' ' << 8) | ' '; + m_identify_buffer[41] = (' ' << 8) | ' '; + m_identify_buffer[42] = (' ' << 8) | ' '; + m_identify_buffer[43] = (' ' << 8) | ' '; + m_identify_buffer[44] = (' ' << 8) | ' '; + m_identify_buffer[45] = (' ' << 8) | ' '; + m_identify_buffer[46] = (' ' << 8) | ' '; + + m_identify_buffer[49] = 0x0400; // IORDY may be disabled } void matsushita_cr589_device::device_reset() |