src/mame/machine/gdrom.c
| r15370 | r15371 | |
| 11 | 11 | #include "imagedev/chd_cd.h" |
| 12 | 12 | #include "gdrom.h" |
| 13 | 13 | |
| 14 | | typedef struct |
| 15 | | { |
| 16 | | UINT32 lba; |
| 17 | | UINT32 blocks; |
| 18 | | UINT32 last_lba; |
| 19 | | UINT32 bytes_per_sector; |
| 20 | | UINT32 num_subblocks; |
| 21 | | UINT32 cur_subblock; |
| 22 | | UINT32 play_err_flag; |
| 23 | | UINT32 read_type; // for command 0x30 only |
| 24 | | UINT32 data_select; // for command 0x30 only |
| 25 | | cdrom_file *cdrom; |
| 26 | | bool is_file; |
| 27 | | } SCSIGd; |
| 28 | | |
| 29 | 14 | static const UINT8 GDROM_Cmd11_Reply[32] = |
| 30 | 15 | { |
| 31 | 16 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x19, 0x00, 0x00, 0x08, 0x53, 0x45, 0x20, 0x20, 0x20, 0x20, |
| r15370 | r15371 | |
| 40 | 25 | *f = phys_frame % 75; |
| 41 | 26 | } |
| 42 | 27 | |
| 28 | // device type definition |
| 29 | const device_type GDROM = &device_creator<gdrom_device>; |
| 43 | 30 | |
| 31 | gdrom_device::gdrom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 32 | : scsidev_device(mconfig, GDROM, "GDROM", tag, owner, clock) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | void gdrom_device::device_start() |
| 37 | { |
| 38 | save_item( NAME( lba ) ); |
| 39 | save_item( NAME( blocks ) ); |
| 40 | save_item( NAME( last_lba ) ); |
| 41 | save_item( NAME( bytes_per_sector ) ); |
| 42 | save_item( NAME( num_subblocks ) ); |
| 43 | save_item( NAME( cur_subblock ) ); |
| 44 | save_item( NAME( play_err_flag ) ); |
| 45 | } |
| 46 | |
| 47 | void gdrom_device::device_reset() |
| 48 | { |
| 49 | scsidev_device::device_reset(); |
| 50 | |
| 51 | is_file = TRUE; |
| 52 | cdrom = subdevice<cdrom_image_device>("image")->get_cdrom_file(); |
| 53 | if( !cdrom ) |
| 54 | { |
| 55 | // try to locate the CHD from a DISK_REGION |
| 56 | chd_file *chd = get_disk_handle( machine(), tag() ); |
| 57 | if( chd != NULL ) |
| 58 | { |
| 59 | is_file = FALSE; |
| 60 | cdrom = cdrom_open( chd ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (!cdrom) |
| 65 | { |
| 66 | logerror("GDROM: no CD found!\n"); |
| 67 | } |
| 68 | |
| 69 | lba = 0; |
| 70 | blocks = 0; |
| 71 | last_lba = 0; |
| 72 | bytes_per_sector = 2048; |
| 73 | num_subblocks = 1; |
| 74 | cur_subblock = 0; |
| 75 | play_err_flag = 0; |
| 76 | } |
| 77 | |
| 78 | void gdrom_device::device_stop() |
| 79 | { |
| 80 | if (!is_file) |
| 81 | { |
| 82 | if( cdrom ) |
| 83 | { |
| 84 | cdrom_close( cdrom ); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | cdrom_interface gdrom_device::cd_intf = { 0, 0 }; |
| 90 | |
| 91 | static MACHINE_CONFIG_FRAGMENT(scsi_cdrom) |
| 92 | MCFG_CDROM_ADD("image", gdrom_device::cd_intf) |
| 93 | MACHINE_CONFIG_END |
| 94 | |
| 95 | machine_config_constructor gdrom_device::device_mconfig_additions() const |
| 96 | { |
| 97 | return MACHINE_CONFIG_NAME(scsi_cdrom); |
| 98 | } |
| 99 | |
| 44 | 100 | // scsicd_exec_command |
| 45 | 101 | // |
| 46 | 102 | // Execute a SCSI command. |
| 47 | 103 | |
| 48 | | static int scsicd_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode ) |
| 104 | void gdrom_device::ExecCommand( int *transferLength ) |
| 49 | 105 | { |
| 50 | 106 | UINT8 *command; |
| 51 | 107 | int commandLength; |
| 52 | | SCSIGd *our_this = (SCSIGd *)SCSIThis( &SCSIClassGDROM, scsiInstance ); |
| 53 | 108 | |
| 54 | | cdrom_file *cdrom = our_this->cdrom; |
| 55 | 109 | device_t *cdda; |
| 56 | 110 | int trk; |
| 57 | 111 | |
| 58 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 112 | GetCommand( &command, &commandLength ); |
| 59 | 113 | |
| 60 | 114 | switch ( command[0] ) |
| 61 | 115 | { |
| 62 | | |
| 63 | | |
| 64 | 116 | case 0x03: // REQUEST SENSE |
| 65 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 66 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 117 | SetPhase( SCSI_PHASE_DATAIN ); |
| 118 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 119 | break; |
| 67 | 120 | |
| 68 | 121 | case 0x11: // REQ_MODE |
| 69 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 122 | SetPhase( SCSI_PHASE_DATAIN ); |
| 70 | 123 | printf("REQ_MODE %02x %02x %02x %02x %02x %02x\n", |
| 71 | 124 | command[0], command[1], |
| 72 | 125 | command[2], command[3], |
| 73 | 126 | command[4], command[5]); |
| 74 | 127 | // if (SCSILengthFromUINT8( &command[ 4 ] ) < 32) return -1; |
| 75 | | return 32; //SCSILengthFromUINT8( &command[ 4 ] ); |
| 128 | *transferLength = 32; //SCSILengthFromUINT8( &command[ 4 ] ); |
| 129 | break; |
| 76 | 130 | |
| 77 | 131 | case 0x12: // INQUIRY |
| 78 | 132 | logerror("GDROM: REQUEST SENSE\n"); |
| 79 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 80 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 133 | SetPhase( SCSI_PHASE_DATAIN ); |
| 134 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 135 | break; |
| 81 | 136 | |
| 82 | 137 | case 0x15: // MODE SELECT(6) |
| 83 | 138 | logerror("GDROM: MODE SELECT(6) length %x control %x\n", command[4], command[5]); |
| 84 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 85 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 139 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 140 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 141 | break; |
| 86 | 142 | |
| 87 | 143 | case 0x1a: // MODE SENSE(6) |
| 88 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 89 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 144 | SetPhase( SCSI_PHASE_DATAIN ); |
| 145 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 146 | break; |
| 90 | 147 | |
| 91 | 148 | case 0x1b: // START STOP UNIT |
| 92 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 149 | cdda = cdda_from_cdrom( machine(), cdrom); |
| 93 | 150 | if (cdda != NULL) |
| 94 | 151 | { |
| 95 | 152 | cdda_stop_audio(cdda); |
| 96 | 153 | } |
| 97 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 98 | | return 0; |
| 154 | SetPhase( SCSI_PHASE_STATUS ); |
| 155 | *transferLength = 0; |
| 156 | break; |
| 99 | 157 | |
| 100 | 158 | case 0x1e: // PREVENT ALLOW MEDIUM REMOVAL |
| 101 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 102 | | return 0; |
| 159 | SetPhase( SCSI_PHASE_STATUS ); |
| 160 | *transferLength = 0; |
| 161 | break; |
| 103 | 162 | |
| 104 | 163 | case 0x25: // READ CAPACITY |
| 105 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 106 | | return 8; |
| 164 | SetPhase( SCSI_PHASE_DATAIN ); |
| 165 | *transferLength = 8; |
| 166 | break; |
| 107 | 167 | |
| 108 | 168 | case 0x28: // READ(10) |
| 109 | 169 | |
| 110 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 111 | | our_this->blocks = SCSILengthFromUINT16( &command[7] ); |
| 170 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 171 | blocks = SCSILengthFromUINT16( &command[7] ); |
| 112 | 172 | |
| 113 | | logerror("GDROM: READ(10) at LBA %x for %d blocks (%d bytes)\n", our_this->lba, our_this->blocks, our_this->blocks * our_this->bytes_per_sector); |
| 173 | logerror("GDROM: READ(10) at LBA %x for %d blocks (%d bytes)\n", lba, blocks, blocks * bytes_per_sector); |
| 114 | 174 | |
| 115 | | if (our_this->num_subblocks > 1) |
| 175 | if (num_subblocks > 1) |
| 116 | 176 | { |
| 117 | | our_this->cur_subblock = our_this->lba % our_this->num_subblocks; |
| 118 | | our_this->lba /= our_this->num_subblocks; |
| 177 | cur_subblock = lba % num_subblocks; |
| 178 | lba /= num_subblocks; |
| 119 | 179 | } |
| 120 | 180 | else |
| 121 | 181 | { |
| 122 | | our_this->cur_subblock = 0; |
| 182 | cur_subblock = 0; |
| 123 | 183 | } |
| 124 | 184 | |
| 125 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 185 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 126 | 186 | if (cdda != NULL) |
| 127 | 187 | { |
| 128 | 188 | cdda_stop_audio(cdda); |
| 129 | 189 | } |
| 130 | 190 | |
| 131 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 132 | | return our_this->blocks * our_this->bytes_per_sector; |
| 191 | SetPhase( SCSI_PHASE_DATAIN ); |
| 192 | *transferLength = blocks * bytes_per_sector; |
| 193 | break; |
| 133 | 194 | |
| 134 | 195 | case 0x30: // CD_READ |
| 135 | 196 | if (command[1] & 1) |
| 136 | 197 | { |
| 137 | 198 | fatalerror("GDROM: MSF mode used for CD_READ, unsupported"); |
| 138 | | return 0; |
| 199 | *transferLength = 0; |
| 139 | 200 | } |
| 140 | 201 | else |
| 141 | 202 | { |
| 142 | | our_this->lba = (command[2]<<16 | command[3]<<8 | command[4]) - 150; |
| 143 | | our_this->blocks = command[8]<<16 | command[9]<<8 | command[10]; |
| 203 | lba = (command[2]<<16 | command[3]<<8 | command[4]) - 150; |
| 204 | blocks = command[8]<<16 | command[9]<<8 | command[10]; |
| 144 | 205 | |
| 145 | | our_this->read_type = (command[1] >> 1) & 7; |
| 146 | | our_this->data_select = (command[1]>>4) & 0xf; |
| 206 | read_type = (command[1] >> 1) & 7; |
| 207 | data_select = (command[1]>>4) & 0xf; |
| 147 | 208 | |
| 148 | | if (our_this->read_type != 2) // mode 1 |
| 209 | if (read_type != 2) // mode 1 |
| 149 | 210 | { |
| 150 | | fatalerror("GDROM: Unhandled read_type %d", our_this->read_type); |
| 211 | fatalerror("GDROM: Unhandled read_type %d", read_type); |
| 151 | 212 | } |
| 152 | 213 | |
| 153 | | if (our_this->data_select != 2) // just sector data |
| 214 | if (data_select != 2) // just sector data |
| 154 | 215 | { |
| 155 | | fatalerror("GDROM: Unhandled data_select %d", our_this->data_select); |
| 216 | fatalerror("GDROM: Unhandled data_select %d", data_select); |
| 156 | 217 | } |
| 157 | 218 | |
| 158 | | printf("GDROM: CD_READ at LBA %x for %d blocks (%d bytes, read type %d, data select %d)\n", our_this->lba, our_this->blocks, our_this->blocks * our_this->bytes_per_sector, our_this->read_type, our_this->data_select); |
| 219 | printf("GDROM: CD_READ at LBA %x for %d blocks (%d bytes, read type %d, data select %d)\n", lba, blocks, blocks * bytes_per_sector, read_type, data_select); |
| 159 | 220 | |
| 160 | | if (our_this->num_subblocks > 1) |
| 221 | if (num_subblocks > 1) |
| 161 | 222 | { |
| 162 | | our_this->cur_subblock = our_this->lba % our_this->num_subblocks; |
| 163 | | our_this->lba /= our_this->num_subblocks; |
| 223 | cur_subblock = lba % num_subblocks; |
| 224 | lba /= num_subblocks; |
| 164 | 225 | } |
| 165 | 226 | else |
| 166 | 227 | { |
| 167 | | our_this->cur_subblock = 0; |
| 228 | cur_subblock = 0; |
| 168 | 229 | } |
| 169 | 230 | |
| 170 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 231 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 171 | 232 | if (cdda != NULL) |
| 172 | 233 | { |
| 173 | 234 | cdda_stop_audio(cdda); |
| 174 | 235 | } |
| 175 | 236 | |
| 176 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 177 | | return our_this->blocks * our_this->bytes_per_sector; |
| 237 | SetPhase( SCSI_PHASE_DATAIN ); |
| 238 | *transferLength = blocks * bytes_per_sector; |
| 178 | 239 | } |
| 240 | break; |
| 179 | 241 | |
| 180 | 242 | case 0x42: // READ SUB-CHANNEL |
| 181 | 243 | // logerror("GDROM: READ SUB-CHANNEL type %d\n", command[3]); |
| 182 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 183 | | return SCSILengthFromUINT16( &command[ 7 ] ); |
| 244 | SetPhase( SCSI_PHASE_DATAIN ); |
| 245 | *transferLength = SCSILengthFromUINT16( &command[ 7 ] ); |
| 246 | break; |
| 184 | 247 | |
| 185 | 248 | case 0x43: // READ TOC |
| 186 | 249 | { |
| r15370 | r15371 | |
| 208 | 271 | length = 4; |
| 209 | 272 | } |
| 210 | 273 | |
| 211 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 274 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 212 | 275 | if (cdda != NULL) |
| 213 | 276 | { |
| 214 | 277 | cdda_stop_audio(cdda); |
| 215 | 278 | } |
| 216 | 279 | |
| 217 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 218 | | return length; |
| 280 | SetPhase( SCSI_PHASE_DATAIN ); |
| 281 | *transferLength = length; |
| 282 | break; |
| 219 | 283 | } |
| 220 | 284 | case 0x45: // PLAY AUDIO(10) |
| 221 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 222 | | our_this->blocks = SCSILengthFromUINT16( &command[7] ); |
| 285 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 286 | blocks = SCSILengthFromUINT16( &command[7] ); |
| 223 | 287 | |
| 224 | 288 | // special cases: lba of 0 means MSF of 00:02:00 |
| 225 | | if (our_this->lba == 0) |
| 289 | if (lba == 0) |
| 226 | 290 | { |
| 227 | | our_this->lba = 150; |
| 291 | lba = 150; |
| 228 | 292 | } |
| 229 | | else if (our_this->lba == 0xffffffff) |
| 293 | else if (lba == 0xffffffff) |
| 230 | 294 | { |
| 231 | 295 | logerror("GDROM: play audio from current not implemented!\n"); |
| 232 | 296 | } |
| 233 | 297 | |
| 234 | | logerror("GDROM: PLAY AUDIO(10) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 298 | logerror("GDROM: PLAY AUDIO(10) at LBA %x for %x blocks\n", lba, blocks); |
| 235 | 299 | |
| 236 | | trk = cdrom_get_track(cdrom, our_this->lba); |
| 300 | trk = cdrom_get_track(cdrom, lba); |
| 237 | 301 | |
| 238 | 302 | if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO) |
| 239 | 303 | { |
| 240 | | our_this->play_err_flag = 0; |
| 241 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 304 | play_err_flag = 0; |
| 305 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 242 | 306 | if (cdda != NULL) |
| 243 | | cdda_start_audio(cdda, our_this->lba, our_this->blocks); |
| 307 | cdda_start_audio(cdda, lba, blocks); |
| 244 | 308 | } |
| 245 | 309 | else |
| 246 | 310 | { |
| 247 | 311 | logerror("GDROM: track is NOT audio!\n"); |
| 248 | | our_this->play_err_flag = 1; |
| 312 | play_err_flag = 1; |
| 249 | 313 | } |
| 250 | 314 | |
| 251 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 252 | | return 0; |
| 315 | SetPhase( SCSI_PHASE_STATUS ); |
| 316 | *transferLength = 0; |
| 317 | break; |
| 253 | 318 | |
| 254 | 319 | case 0x48: // PLAY AUDIO TRACK/INDEX |
| 255 | 320 | // be careful: tracks here are zero-based, but the SCSI command |
| 256 | 321 | // uses the real CD track number which is 1-based! |
| 257 | | our_this->lba = cdrom_get_track_start(cdrom, command[4]-1); |
| 258 | | our_this->blocks = cdrom_get_track_start(cdrom, command[7]-1) - our_this->lba; |
| 322 | lba = cdrom_get_track_start(cdrom, command[4]-1); |
| 323 | blocks = cdrom_get_track_start(cdrom, command[7]-1) - lba; |
| 259 | 324 | if (command[4] > command[7]) |
| 260 | 325 | { |
| 261 | | our_this->blocks = 0; |
| 326 | blocks = 0; |
| 262 | 327 | } |
| 263 | 328 | |
| 264 | 329 | if (command[4] == command[7]) |
| 265 | 330 | { |
| 266 | | our_this->blocks = cdrom_get_track_start(cdrom, command[4]) - our_this->lba; |
| 331 | blocks = cdrom_get_track_start(cdrom, command[4]) - lba; |
| 267 | 332 | } |
| 268 | 333 | |
| 269 | | if (our_this->blocks && cdrom) |
| 334 | if (blocks && cdrom) |
| 270 | 335 | { |
| 271 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 336 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 272 | 337 | if (cdda != NULL) |
| 273 | | cdda_start_audio(cdda, our_this->lba, our_this->blocks); |
| 338 | cdda_start_audio(cdda, lba, blocks); |
| 274 | 339 | } |
| 275 | 340 | |
| 276 | | logerror("GDROM: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", command[4], command[5], command[7], command[8], our_this->blocks); |
| 277 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 278 | | return 0; |
| 341 | logerror("GDROM: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", command[4], command[5], command[7], command[8], blocks); |
| 342 | SetPhase( SCSI_PHASE_STATUS ); |
| 343 | *transferLength = 0; |
| 344 | break; |
| 279 | 345 | |
| 280 | 346 | case 0x4b: // PAUSE/RESUME |
| 281 | 347 | if (cdrom) |
| 282 | 348 | { |
| 283 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 349 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 284 | 350 | if (cdda != NULL) |
| 285 | 351 | cdda_pause_audio(cdda, (command[8] & 0x01) ^ 0x01); |
| 286 | 352 | } |
| 287 | 353 | |
| 288 | 354 | logerror("GDROM: PAUSE/RESUME: %s\n", command[8]&1 ? "RESUME" : "PAUSE"); |
| 289 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 290 | | return 0; |
| 355 | SetPhase( SCSI_PHASE_STATUS ); |
| 356 | *transferLength = 0; |
| 357 | break; |
| 291 | 358 | |
| 292 | 359 | case 0x55: // MODE SELECT(10) |
| 293 | 360 | logerror("GDROM: MODE SELECT length %x control %x\n", command[7]<<8 | command[8], command[1]); |
| 294 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 295 | | return SCSILengthFromUINT16( &command[ 7 ] ); |
| 361 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 362 | *transferLength = SCSILengthFromUINT16( &command[ 7 ] ); |
| 363 | break; |
| 296 | 364 | |
| 297 | 365 | case 0x5a: // MODE SENSE(10) |
| 298 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 299 | | return SCSILengthFromUINT16( &command[ 7 ] ); |
| 366 | SetPhase( SCSI_PHASE_DATAIN ); |
| 367 | *transferLength = SCSILengthFromUINT16( &command[ 7 ] ); |
| 368 | break; |
| 300 | 369 | |
| 301 | 370 | case 0xa5: // PLAY AUDIO(12) |
| 302 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 303 | | our_this->blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9]; |
| 371 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 372 | blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9]; |
| 304 | 373 | |
| 305 | 374 | // special cases: lba of 0 means MSF of 00:02:00 |
| 306 | | if (our_this->lba == 0) |
| 375 | if (lba == 0) |
| 307 | 376 | { |
| 308 | | our_this->lba = 150; |
| 377 | lba = 150; |
| 309 | 378 | } |
| 310 | | else if (our_this->lba == 0xffffffff) |
| 379 | else if (lba == 0xffffffff) |
| 311 | 380 | { |
| 312 | 381 | logerror("GDROM: play audio from current not implemented!\n"); |
| 313 | 382 | } |
| 314 | 383 | |
| 315 | | logerror("GDROM: PLAY AUDIO(12) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 384 | logerror("GDROM: PLAY AUDIO(12) at LBA %x for %x blocks\n", lba, blocks); |
| 316 | 385 | |
| 317 | | trk = cdrom_get_track(cdrom, our_this->lba); |
| 386 | trk = cdrom_get_track(cdrom, lba); |
| 318 | 387 | |
| 319 | 388 | if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO) |
| 320 | 389 | { |
| 321 | | our_this->play_err_flag = 0; |
| 322 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 390 | play_err_flag = 0; |
| 391 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 323 | 392 | if (cdda != NULL) |
| 324 | | cdda_start_audio(cdda, our_this->lba, our_this->blocks); |
| 393 | cdda_start_audio(cdda, lba, blocks); |
| 325 | 394 | } |
| 326 | 395 | else |
| 327 | 396 | { |
| 328 | 397 | logerror("GDROM: track is NOT audio!\n"); |
| 329 | | our_this->play_err_flag = 1; |
| 398 | play_err_flag = 1; |
| 330 | 399 | } |
| 331 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 332 | | return 0; |
| 400 | SetPhase( SCSI_PHASE_STATUS ); |
| 401 | *transferLength = 0; |
| 402 | break; |
| 333 | 403 | |
| 334 | 404 | case 0xa8: // READ(12) |
| 335 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 336 | | our_this->blocks = command[7]<<16 | command[8]<<8 | command[9]; |
| 405 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 406 | blocks = command[7]<<16 | command[8]<<8 | command[9]; |
| 337 | 407 | |
| 338 | | logerror("GDROM: READ(12) at LBA %x for %x blocks (%x bytes)\n", our_this->lba, our_this->blocks, our_this->blocks * our_this->bytes_per_sector); |
| 408 | logerror("GDROM: READ(12) at LBA %x for %x blocks (%x bytes)\n", lba, blocks, blocks * bytes_per_sector); |
| 339 | 409 | |
| 340 | | if (our_this->num_subblocks > 1) |
| 410 | if (num_subblocks > 1) |
| 341 | 411 | { |
| 342 | | our_this->cur_subblock = our_this->lba % our_this->num_subblocks; |
| 343 | | our_this->lba /= our_this->num_subblocks; |
| 412 | cur_subblock = lba % num_subblocks; |
| 413 | lba /= num_subblocks; |
| 344 | 414 | } |
| 345 | 415 | else |
| 346 | 416 | { |
| 347 | | our_this->cur_subblock = 0; |
| 417 | cur_subblock = 0; |
| 348 | 418 | } |
| 349 | 419 | |
| 350 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 420 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 351 | 421 | if (cdda != NULL) |
| 352 | 422 | { |
| 353 | 423 | cdda_stop_audio(cdda); |
| 354 | 424 | } |
| 355 | 425 | |
| 356 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 357 | | return our_this->blocks * our_this->bytes_per_sector; |
| 426 | SetPhase( SCSI_PHASE_DATAIN ); |
| 427 | *transferLength = blocks * bytes_per_sector; |
| 428 | break; |
| 358 | 429 | |
| 359 | 430 | case 0xbb: // SET CD SPEED |
| 360 | 431 | logerror("GDROM: SET CD SPEED to %d kbytes/sec.\n", command[2]<<8 | command[3]); |
| 361 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 362 | | return 0; |
| 432 | SetPhase( SCSI_PHASE_STATUS ); |
| 433 | *transferLength = 0; |
| 434 | break; |
| 363 | 435 | |
| 364 | 436 | default: |
| 365 | | return SCSIBase( &SCSIClassGDROM, SCSIOP_EXEC_COMMAND, scsiInstance, 0, NULL ); |
| 437 | scsidev_device::ExecCommand( transferLength ); |
| 438 | break; |
| 366 | 439 | } |
| 367 | 440 | } |
| 368 | 441 | |
| r15370 | r15371 | |
| 370 | 443 | // |
| 371 | 444 | // Read data from the device resulting from the execution of a command |
| 372 | 445 | |
| 373 | | static void scsicd_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 446 | void gdrom_device::ReadData( UINT8 *data, int dataLength ) |
| 374 | 447 | { |
| 375 | 448 | UINT8 *command; |
| 376 | 449 | int commandLength; |
| 377 | | SCSIGd *our_this = (SCSIGd *)SCSIThis( &SCSIClassGDROM, scsiInstance ); |
| 378 | 450 | |
| 379 | 451 | int i; |
| 380 | 452 | UINT32 last_phys_frame; |
| 381 | | cdrom_file *cdrom = our_this->cdrom; |
| 382 | 453 | UINT32 temp; |
| 383 | 454 | UINT8 tmp_buffer[2048]; |
| 384 | 455 | device_t *cdda; |
| 385 | 456 | |
| 386 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 457 | GetCommand( &command, &commandLength ); |
| 387 | 458 | |
| 388 | 459 | switch ( command[0] ) |
| 389 | 460 | { |
| r15370 | r15371 | |
| 394 | 465 | |
| 395 | 466 | data[0] = 0x71; // deferred error |
| 396 | 467 | |
| 397 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 468 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 398 | 469 | if (cdda != NULL && cdda_audio_active(cdda)) |
| 399 | 470 | { |
| 400 | 471 | data[12] = 0x00; |
| 401 | 472 | data[13] = 0x11; // AUDIO PLAY OPERATION IN PROGRESS |
| 402 | 473 | } |
| 403 | | else if (our_this->play_err_flag) |
| 474 | else if (play_err_flag) |
| 404 | 475 | { |
| 405 | | our_this->play_err_flag = 0; |
| 476 | play_err_flag = 0; |
| 406 | 477 | data[12] = 0x64; // ILLEGAL MODE FOR THIS TRACK |
| 407 | 478 | data[13] = 0x00; |
| 408 | 479 | } |
| r15370 | r15371 | |
| 439 | 510 | data[3] = (temp & 0xff); |
| 440 | 511 | data[4] = 0; |
| 441 | 512 | data[5] = 0; |
| 442 | | data[6] = (our_this->bytes_per_sector>>8)&0xff; |
| 443 | | data[7] = (our_this->bytes_per_sector & 0xff); |
| 513 | data[6] = (bytes_per_sector>>8)&0xff; |
| 514 | data[7] = (bytes_per_sector & 0xff); |
| 444 | 515 | break; |
| 445 | 516 | |
| 446 | 517 | case 0x28: // READ(10) |
| 447 | 518 | case 0xa8: // READ(12) |
| 448 | 519 | logerror("GDROM: read %x dataLength, \n", dataLength); |
| 449 | | if ((our_this->cdrom) && (our_this->blocks)) |
| 520 | if ((cdrom) && (blocks)) |
| 450 | 521 | { |
| 451 | 522 | while (dataLength > 0) |
| 452 | 523 | { |
| 453 | | if (!cdrom_read_data(our_this->cdrom, our_this->lba, tmp_buffer, CD_TRACK_MODE1)) |
| 524 | if (!cdrom_read_data(cdrom, lba, tmp_buffer, CD_TRACK_MODE1)) |
| 454 | 525 | { |
| 455 | 526 | logerror("GDROM: CD read error!\n"); |
| 456 | 527 | } |
| 457 | 528 | |
| 458 | | logerror("True LBA: %d, buffer half: %d\n", our_this->lba, our_this->cur_subblock * our_this->bytes_per_sector); |
| 529 | logerror("True LBA: %d, buffer half: %d\n", lba, cur_subblock * bytes_per_sector); |
| 459 | 530 | |
| 460 | | memcpy(data, &tmp_buffer[our_this->cur_subblock * our_this->bytes_per_sector], our_this->bytes_per_sector); |
| 531 | memcpy(data, &tmp_buffer[cur_subblock * bytes_per_sector], bytes_per_sector); |
| 461 | 532 | |
| 462 | | our_this->cur_subblock++; |
| 463 | | if (our_this->cur_subblock >= our_this->num_subblocks) |
| 533 | cur_subblock++; |
| 534 | if (cur_subblock >= num_subblocks) |
| 464 | 535 | { |
| 465 | | our_this->cur_subblock = 0; |
| 536 | cur_subblock = 0; |
| 466 | 537 | |
| 467 | | our_this->lba++; |
| 468 | | our_this->blocks--; |
| 538 | lba++; |
| 539 | blocks--; |
| 469 | 540 | } |
| 470 | 541 | |
| 471 | | our_this->last_lba = our_this->lba; |
| 472 | | dataLength -= our_this->bytes_per_sector; |
| 473 | | data += our_this->bytes_per_sector; |
| 542 | last_lba = lba; |
| 543 | dataLength -= bytes_per_sector; |
| 544 | data += bytes_per_sector; |
| 474 | 545 | } |
| 475 | 546 | } |
| 476 | 547 | break; |
| 477 | 548 | |
| 478 | 549 | case 0x30: // CD_READ |
| 479 | 550 | logerror("GDROM: read %x dataLength, \n", dataLength); |
| 480 | | if ((our_this->cdrom) && (our_this->blocks)) |
| 551 | if ((cdrom) && (blocks)) |
| 481 | 552 | { |
| 482 | 553 | while (dataLength > 0) |
| 483 | 554 | { |
| 484 | | if (!cdrom_read_data(our_this->cdrom, our_this->lba, tmp_buffer, CD_TRACK_MODE1)) |
| 555 | if (!cdrom_read_data(cdrom, lba, tmp_buffer, CD_TRACK_MODE1)) |
| 485 | 556 | { |
| 486 | 557 | logerror("GDROM: CD read error!\n"); |
| 487 | 558 | } |
| 488 | 559 | |
| 489 | | logerror("True LBA: %d, buffer half: %d\n", our_this->lba, our_this->cur_subblock * our_this->bytes_per_sector); |
| 560 | logerror("True LBA: %d, buffer half: %d\n", lba, cur_subblock * bytes_per_sector); |
| 490 | 561 | |
| 491 | | memcpy(data, &tmp_buffer[our_this->cur_subblock * our_this->bytes_per_sector], our_this->bytes_per_sector); |
| 562 | memcpy(data, &tmp_buffer[cur_subblock * bytes_per_sector], bytes_per_sector); |
| 492 | 563 | |
| 493 | | our_this->cur_subblock++; |
| 494 | | if (our_this->cur_subblock >= our_this->num_subblocks) |
| 564 | cur_subblock++; |
| 565 | if (cur_subblock >= num_subblocks) |
| 495 | 566 | { |
| 496 | | our_this->cur_subblock = 0; |
| 567 | cur_subblock = 0; |
| 497 | 568 | |
| 498 | | our_this->lba++; |
| 499 | | our_this->blocks--; |
| 569 | lba++; |
| 570 | blocks--; |
| 500 | 571 | } |
| 501 | 572 | |
| 502 | | our_this->last_lba = our_this->lba; |
| 503 | | dataLength -= our_this->bytes_per_sector; |
| 504 | | data += our_this->bytes_per_sector; |
| 573 | last_lba = lba; |
| 574 | dataLength -= bytes_per_sector; |
| 575 | data += bytes_per_sector; |
| 505 | 576 | } |
| 506 | 577 | } |
| 507 | 578 | |
| r15370 | r15371 | |
| 522 | 593 | |
| 523 | 594 | msf = command[1] & 0x2; |
| 524 | 595 | |
| 525 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 596 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 526 | 597 | audio_active = cdda != NULL && cdda_audio_active(cdda); |
| 527 | 598 | if (audio_active) |
| 528 | 599 | { |
| r15370 | r15371 | |
| 551 | 622 | // if audio is playing, get the latest LBA from the CDROM layer |
| 552 | 623 | if (audio_active) |
| 553 | 624 | { |
| 554 | | our_this->last_lba = cdda_get_audio_lba(cdda); |
| 625 | last_lba = cdda_get_audio_lba(cdda); |
| 555 | 626 | } |
| 556 | 627 | else |
| 557 | 628 | { |
| 558 | | our_this->last_lba = 0; |
| 629 | last_lba = 0; |
| 559 | 630 | } |
| 560 | 631 | |
| 561 | 632 | data[2] = 0; |
| 562 | 633 | data[3] = 12; // data length |
| 563 | 634 | data[4] = 0x01; // sub-channel format code |
| 564 | 635 | data[5] = 0x10 | (audio_active ? 0 : 4); |
| 565 | | data[6] = cdrom_get_track(cdrom, our_this->last_lba) + 1; // track |
| 636 | data[6] = cdrom_get_track(cdrom, last_lba) + 1; // track |
| 566 | 637 | data[7] = 0; // index |
| 567 | 638 | |
| 568 | | last_phys_frame = our_this->last_lba; |
| 639 | last_phys_frame = last_lba; |
| 569 | 640 | |
| 570 | 641 | if (msf) |
| 571 | 642 | { |
| r15370 | r15371 | |
| 715 | 786 | break; |
| 716 | 787 | |
| 717 | 788 | default: |
| 718 | | SCSIBase( &SCSIClassGDROM, SCSIOP_READ_DATA, scsiInstance, dataLength, data ); |
| 789 | scsidev_device::ReadData( data, dataLength ); |
| 719 | 790 | break; |
| 720 | 791 | } |
| 721 | 792 | } |
| r15370 | r15371 | |
| 724 | 795 | // |
| 725 | 796 | // Write data to the CD-ROM device as part of the execution of a command |
| 726 | 797 | |
| 727 | | static void scsicd_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 798 | void gdrom_device::WriteData( UINT8 *data, int dataLength ) |
| 728 | 799 | { |
| 729 | 800 | UINT8 *command; |
| 730 | 801 | int commandLength; |
| 731 | | SCSIGd *our_this = (SCSIGd *)SCSIThis( &SCSIClassGDROM, scsiInstance ); |
| 732 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 802 | GetCommand( &command, &commandLength ); |
| 733 | 803 | |
| 734 | 804 | switch (command[ 0 ]) |
| 735 | 805 | { |
| r15370 | r15371 | |
| 745 | 815 | { |
| 746 | 816 | logerror("GDROM: Experimental SGI 512-byte block extension enabled\n"); |
| 747 | 817 | |
| 748 | | our_this->bytes_per_sector = 512; |
| 749 | | our_this->num_subblocks = 4; |
| 818 | bytes_per_sector = 512; |
| 819 | num_subblocks = 4; |
| 750 | 820 | } |
| 751 | 821 | else |
| 752 | 822 | { |
| r15370 | r15371 | |
| 764 | 834 | break; |
| 765 | 835 | |
| 766 | 836 | default: |
| 767 | | SCSIBase( &SCSIClassGDROM, SCSIOP_WRITE_DATA, scsiInstance, dataLength, data ); |
| 837 | scsidev_device::WriteData( data, dataLength ); |
| 768 | 838 | break; |
| 769 | 839 | } |
| 770 | 840 | } |
| 771 | 841 | |
| 772 | | static void scsicd_alloc_instance( SCSIInstance *scsiInstance, const char *diskregion ) |
| 842 | void gdrom_device::GetDevice( void **_cdrom ) |
| 773 | 843 | { |
| 774 | | running_machine &machine = scsiInstance->machine(); |
| 775 | | SCSIGd *our_this = (SCSIGd *)SCSIThis( &SCSIClassGDROM, scsiInstance ); |
| 776 | | |
| 777 | | our_this->lba = 0; |
| 778 | | our_this->blocks = 0; |
| 779 | | our_this->last_lba = 0; |
| 780 | | our_this->bytes_per_sector = 2048; |
| 781 | | our_this->num_subblocks = 1; |
| 782 | | our_this->cur_subblock = 0; |
| 783 | | our_this->play_err_flag = 0; |
| 784 | | |
| 785 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->lba ); |
| 786 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->blocks ); |
| 787 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->last_lba ); |
| 788 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->bytes_per_sector ); |
| 789 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->num_subblocks ); |
| 790 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->cur_subblock ); |
| 791 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->play_err_flag ); |
| 792 | | |
| 793 | | if (machine.device( diskregion )) { |
| 794 | | our_this->is_file = TRUE; |
| 795 | | cdrom_image_device *cdrom = machine.device<cdrom_image_device>(diskregion); |
| 796 | | our_this->cdrom = cdrom->get_cdrom_file(); |
| 797 | | } else { |
| 798 | | our_this->is_file = FALSE; |
| 799 | | our_this->cdrom = cdrom_open(get_disk_handle( machine, diskregion )); |
| 800 | | } |
| 801 | | |
| 802 | | if (!our_this->cdrom) |
| 803 | | { |
| 804 | | logerror("GDROM: no CD found!\n"); |
| 805 | | } |
| 844 | *(cdrom_file **)_cdrom = cdrom; |
| 806 | 845 | } |
| 807 | 846 | |
| 808 | | static void scsicd_delete_instance( SCSIInstance *scsiInstance ) |
| 847 | void gdrom_device::SetDevice( void *_cdrom ) |
| 809 | 848 | { |
| 810 | | SCSIGd *our_this = (SCSIGd *)SCSIThis( &SCSIClassGDROM, scsiInstance ); |
| 811 | | if (!our_this->is_file) { |
| 812 | | if( our_this->cdrom ) |
| 813 | | { |
| 814 | | cdrom_close( our_this->cdrom ); |
| 815 | | } |
| 816 | | } |
| 849 | cdrom = (cdrom_file *) _cdrom; |
| 817 | 850 | } |
| 818 | | |
| 819 | | static void scsicd_get_device( SCSIInstance *scsiInstance, cdrom_file **cdrom ) |
| 820 | | { |
| 821 | | SCSIGd *our_this = (SCSIGd *)SCSIThis( &SCSIClassGDROM, scsiInstance ); |
| 822 | | *cdrom = our_this->cdrom; |
| 823 | | } |
| 824 | | |
| 825 | | static void scsicd_set_device( SCSIInstance *scsiInstance, cdrom_file *cdrom ) |
| 826 | | { |
| 827 | | SCSIGd *our_this = (SCSIGd *)SCSIThis( &SCSIClassGDROM, scsiInstance ); |
| 828 | | our_this->cdrom = cdrom; |
| 829 | | } |
| 830 | | |
| 831 | | static int scsigd_dispatch(int operation, void *file, INT64 intparm, void *ptrparm) |
| 832 | | { |
| 833 | | SCSIAllocInstanceParams *params; |
| 834 | | |
| 835 | | switch (operation) |
| 836 | | { |
| 837 | | case SCSIOP_EXEC_COMMAND: |
| 838 | | return scsicd_exec_command( (SCSIInstance *)file, (UINT8 *)ptrparm ); |
| 839 | | |
| 840 | | case SCSIOP_READ_DATA: |
| 841 | | scsicd_read_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 842 | | return 0; |
| 843 | | |
| 844 | | case SCSIOP_WRITE_DATA: |
| 845 | | scsicd_write_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 846 | | return 0; |
| 847 | | |
| 848 | | case SCSIOP_ALLOC_INSTANCE: |
| 849 | | params = (SCSIAllocInstanceParams *)ptrparm; |
| 850 | | SCSIBase( &SCSIClassGDROM, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 851 | | scsicd_alloc_instance( params->instance, params->diskregion ); |
| 852 | | return 0; |
| 853 | | |
| 854 | | case SCSIOP_DELETE_INSTANCE: |
| 855 | | scsicd_delete_instance( (SCSIInstance *)file ); |
| 856 | | break; |
| 857 | | |
| 858 | | case SCSIOP_GET_DEVICE: |
| 859 | | scsicd_get_device( (SCSIInstance *)file, (cdrom_file **)ptrparm ); |
| 860 | | return 0; |
| 861 | | |
| 862 | | case SCSIOP_SET_DEVICE: |
| 863 | | scsicd_set_device( (SCSIInstance *)file, (cdrom_file *)ptrparm ); |
| 864 | | return 0; |
| 865 | | } |
| 866 | | |
| 867 | | return SCSIBase( &SCSIClassGDROM, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 868 | | } |
| 869 | | |
| 870 | | const SCSIClass SCSIClassGDROM = |
| 871 | | { |
| 872 | | &SCSIClassDevice, |
| 873 | | scsigd_dispatch, |
| 874 | | sizeof( SCSIGd ) |
| 875 | | }; |
src/emu/machine/scsihd.c
| r15370 | r15371 | |
| 10 | 10 | #include "imagedev/harddriv.h" |
| 11 | 11 | #include "scsihd.h" |
| 12 | 12 | |
| 13 | | typedef struct |
| 13 | // device type definition |
| 14 | const device_type SCSIHD = &device_creator<scsihd_device>; |
| 15 | |
| 16 | scsihd_device::scsihd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 17 | : scsidev_device(mconfig, SCSIHD, "SCSIHD", tag, owner, clock) |
| 14 | 18 | { |
| 15 | | UINT32 lba; |
| 16 | | UINT32 blocks; |
| 17 | | int sectorbytes; |
| 18 | | chd_file *handle; |
| 19 | | hard_disk_file *disk; |
| 20 | | bool is_image_device; |
| 21 | | } SCSIHd; |
| 19 | } |
| 22 | 20 | |
| 21 | void scsihd_device::device_start() |
| 22 | { |
| 23 | save_item( NAME( lba ) ); |
| 24 | save_item( NAME( blocks ) ); |
| 25 | } |
| 23 | 26 | |
| 24 | | // scsihd_exec_command |
| 27 | void scsihd_device::device_reset() |
| 28 | { |
| 29 | scsidev_device::device_reset(); |
| 25 | 30 | |
| 26 | | static int scsihd_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode ) |
| 31 | is_image_device = true; |
| 32 | disk = subdevice<harddisk_image_device>("image")->get_hard_disk_file(); |
| 33 | if( !disk ) |
| 34 | { |
| 35 | // try to locate the CHD from a DISK_REGION |
| 36 | chd_file *handle = get_disk_handle(machine(), tag()); |
| 37 | if (handle != NULL) |
| 38 | { |
| 39 | is_image_device = false; |
| 40 | disk = hard_disk_open(handle); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | lba = 0; |
| 45 | blocks = 0; |
| 46 | sectorbytes = 512; |
| 47 | |
| 48 | if (!disk) |
| 49 | { |
| 50 | logerror("SCSIHD: no HD found!\n"); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | // get hard disk sector size from CHD metadata |
| 55 | const hard_disk_info *hdinfo = hard_disk_get_info(disk); |
| 56 | sectorbytes = hdinfo->sectorbytes; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void scsihd_device::device_stop() |
| 27 | 61 | { |
| 62 | if (!is_image_device) |
| 63 | { |
| 64 | if( disk ) |
| 65 | { |
| 66 | hard_disk_close( disk ); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | static MACHINE_CONFIG_FRAGMENT(scsi_harddisk) |
| 72 | MCFG_HARDDISK_ADD("image") |
| 73 | MACHINE_CONFIG_END |
| 74 | |
| 75 | machine_config_constructor scsihd_device::device_mconfig_additions() const |
| 76 | { |
| 77 | return MACHINE_CONFIG_NAME(scsi_harddisk); |
| 78 | } |
| 79 | |
| 80 | // scsihd_exec_command |
| 81 | void scsihd_device::ExecCommand( int *transferLength ) |
| 82 | { |
| 28 | 83 | UINT8 *command; |
| 29 | 84 | int commandLength; |
| 30 | | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 31 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 85 | GetCommand( &command, &commandLength ); |
| 32 | 86 | |
| 33 | 87 | switch ( command[0] ) |
| 34 | 88 | { |
| 35 | 89 | case 0x03: // REQUEST SENSE |
| 36 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 37 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 90 | SetPhase( SCSI_PHASE_DATAIN ); |
| 91 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 92 | break; |
| 38 | 93 | |
| 39 | 94 | case 0x04: // FORMAT UNIT |
| 40 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 41 | | return 0; |
| 95 | SetPhase( SCSI_PHASE_STATUS ); |
| 96 | *transferLength = 0; |
| 97 | break; |
| 42 | 98 | |
| 43 | 99 | case 0x08: // READ(6) |
| 44 | | our_this->lba = (command[1]&0x1f)<<16 | command[2]<<8 | command[3]; |
| 45 | | our_this->blocks = SCSILengthFromUINT8( &command[4] ); |
| 100 | lba = (command[1]&0x1f)<<16 | command[2]<<8 | command[3]; |
| 101 | blocks = SCSILengthFromUINT8( &command[4] ); |
| 46 | 102 | |
| 47 | | logerror("SCSIHD: READ at LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 103 | logerror("SCSIHD: READ at LBA %x for %x blocks\n", lba, blocks); |
| 48 | 104 | |
| 49 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 50 | | return our_this->blocks * our_this->sectorbytes; |
| 105 | SetPhase( SCSI_PHASE_DATAIN ); |
| 106 | *transferLength = blocks * sectorbytes; |
| 107 | break; |
| 51 | 108 | |
| 52 | 109 | case 0x0a: // WRITE(6) |
| 53 | | our_this->lba = (command[1]&0x1f)<<16 | command[2]<<8 | command[3]; |
| 54 | | our_this->blocks = SCSILengthFromUINT8( &command[4] ); |
| 110 | lba = (command[1]&0x1f)<<16 | command[2]<<8 | command[3]; |
| 111 | blocks = SCSILengthFromUINT8( &command[4] ); |
| 55 | 112 | |
| 56 | | logerror("SCSIHD: WRITE to LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 113 | logerror("SCSIHD: WRITE to LBA %x for %x blocks\n", lba, blocks); |
| 57 | 114 | |
| 58 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 59 | | return our_this->blocks * our_this->sectorbytes; |
| 115 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 116 | *transferLength = blocks * sectorbytes; |
| 117 | break; |
| 60 | 118 | |
| 61 | 119 | case 0x12: // INQUIRY |
| 62 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 63 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 120 | SetPhase( SCSI_PHASE_DATAIN ); |
| 121 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 122 | break; |
| 64 | 123 | |
| 65 | 124 | case 0x15: // MODE SELECT (used to set CDDA volume) |
| 66 | 125 | logerror("SCSIHD: MODE SELECT length %x control %x\n", command[4], command[5]); |
| 67 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 68 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 126 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 127 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 128 | break; |
| 69 | 129 | |
| 70 | 130 | case 0x1a: // MODE SENSE(6) |
| 71 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 72 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 131 | SetPhase( SCSI_PHASE_DATAIN ); |
| 132 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 133 | break; |
| 73 | 134 | |
| 74 | 135 | case 0x25: // READ CAPACITY |
| 75 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 76 | | return 8; |
| 136 | SetPhase( SCSI_PHASE_DATAIN ); |
| 137 | *transferLength = 8; |
| 138 | break; |
| 77 | 139 | |
| 78 | 140 | case 0x28: // READ(10) |
| 79 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 80 | | our_this->blocks = SCSILengthFromUINT16( &command[7] ); |
| 141 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 142 | blocks = SCSILengthFromUINT16( &command[7] ); |
| 81 | 143 | |
| 82 | | logerror("SCSIHD: READ at LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 144 | logerror("SCSIHD: READ at LBA %x for %x blocks\n", lba, blocks); |
| 83 | 145 | |
| 84 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 85 | | return our_this->blocks * our_this->sectorbytes; |
| 146 | SetPhase( SCSI_PHASE_DATAIN ); |
| 147 | *transferLength = blocks * sectorbytes; |
| 148 | break; |
| 86 | 149 | |
| 87 | 150 | case 0x2a: // WRITE (10) |
| 88 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 89 | | our_this->blocks = SCSILengthFromUINT16( &command[7] ); |
| 151 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 152 | blocks = SCSILengthFromUINT16( &command[7] ); |
| 90 | 153 | |
| 91 | | logerror("SCSIHD: WRITE to LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 154 | logerror("SCSIHD: WRITE to LBA %x for %x blocks\n", lba, blocks); |
| 92 | 155 | |
| 93 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 156 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 94 | 157 | |
| 95 | | return our_this->blocks * our_this->sectorbytes; |
| 158 | *transferLength = blocks * sectorbytes; |
| 159 | break; |
| 96 | 160 | |
| 97 | 161 | case 0xa8: // READ(12) |
| 98 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 99 | | our_this->blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9]; |
| 162 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 163 | blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9]; |
| 100 | 164 | |
| 101 | | logerror("SCSIHD: READ at LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 165 | logerror("SCSIHD: READ at LBA %x for %x blocks\n", lba, blocks); |
| 102 | 166 | |
| 103 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 104 | | return our_this->blocks * our_this->sectorbytes; |
| 167 | SetPhase( SCSI_PHASE_DATAIN ); |
| 168 | *transferLength = blocks * sectorbytes; |
| 169 | break; |
| 105 | 170 | |
| 106 | 171 | default: |
| 107 | | return SCSIBase( &SCSIClassHARDDISK, SCSIOP_EXEC_COMMAND, scsiInstance, 0, NULL ); |
| 172 | scsidev_device::ExecCommand( transferLength ); |
| 173 | break; |
| 108 | 174 | } |
| 109 | 175 | } |
| 110 | 176 | |
| 111 | | static void scsihd_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 177 | void scsihd_device::ReadData( UINT8 *data, int dataLength ) |
| 112 | 178 | { |
| 113 | 179 | int i; |
| 114 | 180 | UINT8 *command; |
| 115 | 181 | int commandLength; |
| 116 | | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 117 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 182 | GetCommand( &command, &commandLength ); |
| 118 | 183 | |
| 119 | 184 | // if we're a drive without a disk, return all zeroes |
| 120 | | if (!our_this->disk) |
| 185 | if (!disk) |
| 121 | 186 | { |
| 122 | 187 | memset(data, 0, dataLength); |
| 123 | 188 | return; |
| r15370 | r15371 | |
| 160 | 225 | case 0x08: // READ(6) |
| 161 | 226 | case 0x28: // READ(10) |
| 162 | 227 | case 0xa8: // READ(12) |
| 163 | | if ((our_this->disk) && (our_this->blocks)) |
| 228 | if ((disk) && (blocks)) |
| 164 | 229 | { |
| 165 | 230 | while (dataLength > 0) |
| 166 | 231 | { |
| 167 | | if (!hard_disk_read(our_this->disk, our_this->lba, data)) |
| 232 | if (!hard_disk_read(disk, lba, data)) |
| 168 | 233 | { |
| 169 | 234 | logerror("SCSIHD: HD read error!\n"); |
| 170 | 235 | } |
| 171 | | our_this->lba++; |
| 172 | | our_this->blocks--; |
| 173 | | dataLength -= our_this->sectorbytes; |
| 174 | | data += our_this->sectorbytes; |
| 236 | lba++; |
| 237 | blocks--; |
| 238 | dataLength -= sectorbytes; |
| 239 | data += sectorbytes; |
| 175 | 240 | } |
| 176 | 241 | } |
| 177 | 242 | break; |
| r15370 | r15371 | |
| 182 | 247 | hard_disk_info *info; |
| 183 | 248 | UINT32 temp; |
| 184 | 249 | |
| 185 | | info = hard_disk_get_info(our_this->disk); |
| 250 | info = hard_disk_get_info(disk); |
| 186 | 251 | |
| 187 | 252 | logerror("SCSIHD: READ CAPACITY\n"); |
| 188 | 253 | |
| r15370 | r15371 | |
| 202 | 267 | break; |
| 203 | 268 | |
| 204 | 269 | default: |
| 205 | | SCSIBase( &SCSIClassHARDDISK, SCSIOP_READ_DATA, scsiInstance, dataLength, data ); |
| 270 | scsidev_device::ReadData( data, dataLength ); |
| 206 | 271 | break; |
| 207 | 272 | } |
| 208 | 273 | } |
| 209 | 274 | |
| 210 | | static void scsihd_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 275 | void scsihd_device::WriteData( UINT8 *data, int dataLength ) |
| 211 | 276 | { |
| 212 | 277 | UINT8 *command; |
| 213 | 278 | int commandLength; |
| 214 | | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 215 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 279 | GetCommand( &command, &commandLength ); |
| 216 | 280 | |
| 217 | | if (!our_this->disk) |
| 281 | if (!disk) |
| 218 | 282 | { |
| 219 | 283 | return; |
| 220 | 284 | } |
| r15370 | r15371 | |
| 223 | 287 | { |
| 224 | 288 | case 0x0a: // WRITE(6) |
| 225 | 289 | case 0x2a: // WRITE(10) |
| 226 | | if ((our_this->disk) && (our_this->blocks)) |
| 290 | if ((disk) && (blocks)) |
| 227 | 291 | { |
| 228 | 292 | while (dataLength > 0) |
| 229 | 293 | { |
| 230 | | if (!hard_disk_write(our_this->disk, our_this->lba, data)) |
| 294 | if (!hard_disk_write(disk, lba, data)) |
| 231 | 295 | { |
| 232 | 296 | logerror("SCSIHD: HD write error!\n"); |
| 233 | 297 | } |
| 234 | | our_this->lba++; |
| 235 | | our_this->blocks--; |
| 236 | | dataLength -= our_this->sectorbytes; |
| 237 | | data += our_this->sectorbytes; |
| 298 | lba++; |
| 299 | blocks--; |
| 300 | dataLength -= sectorbytes; |
| 301 | data += sectorbytes; |
| 238 | 302 | } |
| 239 | 303 | } |
| 240 | 304 | break; |
| 241 | 305 | |
| 242 | 306 | default: |
| 243 | | SCSIBase( &SCSIClassHARDDISK, SCSIOP_WRITE_DATA, scsiInstance, dataLength, data ); |
| 307 | scsidev_device::WriteData( data, dataLength ); |
| 244 | 308 | break; |
| 245 | 309 | } |
| 246 | 310 | } |
| 247 | 311 | |
| 248 | | static void scsihd_alloc_instance( SCSIInstance *scsiInstance, const char *diskregion ) |
| 249 | | { |
| 250 | | running_machine &machine = scsiInstance->machine(); |
| 251 | | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 252 | 312 | |
| 253 | | our_this->lba = 0; |
| 254 | | our_this->blocks = 0; |
| 255 | | our_this->sectorbytes = 512; |
| 256 | | |
| 257 | | // Attempt to register save state entry after state registration is closed! |
| 258 | | state_save_register_item( machine, "scsihd", diskregion, 0, our_this->lba ); |
| 259 | | state_save_register_item( machine, "scsihd", diskregion, 0, our_this->blocks ); |
| 260 | | |
| 261 | | // try to locate the CHD from a DISK_REGION |
| 262 | | our_this->handle = get_disk_handle(machine, diskregion); |
| 263 | | our_this->disk = hard_disk_open(our_this->handle); |
| 264 | | our_this->is_image_device = false; |
| 265 | | |
| 266 | | if (our_this->disk == NULL) |
| 267 | | { |
| 268 | | // try to locate the CHD from an image device |
| 269 | | harddisk_image_device *image_device = machine.device<harddisk_image_device>(diskregion); |
| 270 | | |
| 271 | | if (image_device != NULL) |
| 272 | | { |
| 273 | | our_this->handle = image_device->get_chd_file(); |
| 274 | | our_this->disk = hard_disk_open(our_this->handle); |
| 275 | | our_this->is_image_device = true; |
| 276 | | } |
| 277 | | } |
| 278 | | |
| 279 | | if (our_this->disk == NULL) |
| 280 | | { |
| 281 | | // try to locate the CHD from an image subdevice |
| 282 | | device_iterator iter(machine.root_device()); |
| 283 | | for (device_t *device = iter.first(); device != NULL; device = iter.next()) |
| 284 | | { |
| 285 | | if (device->subdevice(diskregion) != NULL) |
| 286 | | { |
| 287 | | our_this->handle = device->subdevice<harddisk_image_device>(diskregion)->get_chd_file(); |
| 288 | | our_this->disk = hard_disk_open(our_this->handle); |
| 289 | | our_this->is_image_device = true; |
| 290 | | } |
| 291 | | } |
| 292 | | } |
| 293 | | |
| 294 | | if (our_this->disk != NULL) |
| 295 | | { |
| 296 | | // get hard disk sector size from CHD metadata |
| 297 | | const hard_disk_info *hdinfo = hard_disk_get_info(our_this->disk); |
| 298 | | our_this->sectorbytes = hdinfo->sectorbytes; |
| 299 | | } |
| 300 | | else |
| 301 | | { |
| 302 | | logerror("SCSIHD: no HD found!\n"); |
| 303 | | } |
| 304 | | } |
| 305 | | |
| 306 | | static void scsihd_delete_instance( SCSIInstance *scsiInstance ) |
| 313 | void scsihd_device::GetDevice( void **_disk ) |
| 307 | 314 | { |
| 308 | | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 309 | | if (!our_this->is_image_device) { |
| 310 | | if( our_this->disk ) |
| 311 | | { |
| 312 | | hard_disk_close( our_this->disk ); |
| 313 | | } |
| 314 | | } |
| 315 | *(hard_disk_file **)_disk = disk; |
| 315 | 316 | } |
| 316 | 317 | |
| 317 | | static void scsihd_get_device( SCSIInstance *scsiInstance, hard_disk_file **disk ) |
| 318 | void scsihd_device::SetDevice( void *_disk ) |
| 318 | 319 | { |
| 319 | | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 320 | | *disk = our_this->disk; |
| 320 | disk = (hard_disk_file *)_disk; |
| 321 | 321 | } |
| 322 | | |
| 323 | | static void scsihd_set_device( SCSIInstance *scsiInstance, hard_disk_file *disk ) |
| 324 | | { |
| 325 | | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 326 | | our_this->disk = disk; |
| 327 | | } |
| 328 | | |
| 329 | | static int scsihd_dispatch(int operation, void *file, INT64 intparm, void *ptrparm) |
| 330 | | { |
| 331 | | SCSIAllocInstanceParams *params; |
| 332 | | |
| 333 | | switch (operation) |
| 334 | | { |
| 335 | | case SCSIOP_EXEC_COMMAND: |
| 336 | | return scsihd_exec_command( (SCSIInstance *)file, (UINT8 *)ptrparm ); |
| 337 | | |
| 338 | | case SCSIOP_READ_DATA: |
| 339 | | scsihd_read_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 340 | | return 0; |
| 341 | | |
| 342 | | case SCSIOP_WRITE_DATA: |
| 343 | | scsihd_write_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 344 | | return 0; |
| 345 | | |
| 346 | | case SCSIOP_ALLOC_INSTANCE: |
| 347 | | params = (SCSIAllocInstanceParams *)ptrparm; |
| 348 | | SCSIBase( &SCSIClassHARDDISK, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 349 | | scsihd_alloc_instance( params->instance, params->diskregion ); |
| 350 | | return 0; |
| 351 | | |
| 352 | | case SCSIOP_DELETE_INSTANCE: |
| 353 | | scsihd_delete_instance( (SCSIInstance *)file ); |
| 354 | | break; |
| 355 | | |
| 356 | | case SCSIOP_GET_DEVICE: |
| 357 | | scsihd_get_device( (SCSIInstance *)file, (hard_disk_file **)ptrparm ); |
| 358 | | return 0; |
| 359 | | |
| 360 | | case SCSIOP_SET_DEVICE: |
| 361 | | scsihd_set_device( (SCSIInstance *)file, (hard_disk_file *)ptrparm ); |
| 362 | | return 0; |
| 363 | | } |
| 364 | | |
| 365 | | return SCSIBase( &SCSIClassHARDDISK, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 366 | | } |
| 367 | | |
| 368 | | const SCSIClass SCSIClassHARDDISK = |
| 369 | | { |
| 370 | | &SCSIClassDevice, |
| 371 | | scsihd_dispatch, |
| 372 | | sizeof( SCSIHd ) |
| 373 | | }; |
src/emu/machine/scsidev.c
| r15370 | r15371 | |
| 5 | 5 | ***************************************************************************/ |
| 6 | 6 | |
| 7 | 7 | #include "emu.h" |
| 8 | | #include "scsidev.h" |
| 8 | #include "scsidev.h" |
| 9 | 9 | |
| 10 | | typedef struct |
| 10 | scsidev_device::scsidev_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) : |
| 11 | device_t(mconfig, type, name, tag, owner, clock) |
| 11 | 12 | { |
| 12 | | UINT8 command[16]; |
| 13 | | int commandLength; |
| 14 | | int phase; |
| 15 | | } SCSIDev; |
| 13 | } |
| 16 | 14 | |
| 17 | | static int scsidev_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode ) |
| 15 | void scsidev_device::device_start() |
| 18 | 16 | { |
| 17 | save_item( NAME( command ) ); |
| 18 | save_item( NAME( commandLength ) ); |
| 19 | save_item( NAME( phase ) ); |
| 20 | } |
| 21 | |
| 22 | void scsidev_device::ExecCommand( int *transferLength ) |
| 23 | { |
| 19 | 24 | UINT8 *command; |
| 20 | 25 | int commandLength; |
| 21 | | // SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 22 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 26 | GetCommand( &command, &commandLength ); |
| 23 | 27 | |
| 24 | 28 | switch( command[ 0 ] ) |
| 25 | 29 | { |
| 26 | 30 | case 0x00: // TEST UNIT READY |
| 27 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 28 | | return 0; |
| 31 | SetPhase( SCSI_PHASE_STATUS ); |
| 32 | *transferLength = 0; |
| 33 | break; |
| 29 | 34 | |
| 30 | 35 | default: |
| 31 | | logerror( "%s: SCSIDEV unknown command %02x\n", scsiInstance->machine().describe_context(), command[ 0 ] ); |
| 32 | | return 0; |
| 36 | logerror( "%s: SCSIDEV unknown command %02x\n", machine().describe_context(), command[ 0 ] ); |
| 37 | *transferLength = 0; |
| 38 | break; |
| 33 | 39 | } |
| 34 | 40 | } |
| 35 | 41 | |
| 36 | | static void scsidev_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 42 | void scsidev_device::ReadData( UINT8 *data, int dataLength ) |
| 37 | 43 | { |
| 38 | 44 | UINT8 *command; |
| 39 | 45 | int commandLength; |
| 40 | | // SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 41 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 46 | GetCommand( &command, &commandLength ); |
| 42 | 47 | |
| 43 | 48 | switch( command[ 0 ] ) |
| 44 | 49 | { |
| 45 | 50 | default: |
| 46 | | logerror( "%s: SCSIDEV unknown read %02x\n", scsiInstance->machine().describe_context(), command[ 0 ] ); |
| 51 | logerror( "%s: SCSIDEV unknown read %02x\n", machine().describe_context(), command[ 0 ] ); |
| 47 | 52 | break; |
| 48 | 53 | } |
| 49 | 54 | } |
| 50 | 55 | |
| 51 | | static void scsidev_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 56 | void scsidev_device::WriteData( UINT8 *data, int dataLength ) |
| 52 | 57 | { |
| 53 | 58 | UINT8 *command; |
| 54 | 59 | int commandLength; |
| 55 | | // SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 56 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 60 | GetCommand( &command, &commandLength ); |
| 57 | 61 | |
| 58 | 62 | switch( command[ 0 ] ) |
| 59 | 63 | { |
| 60 | 64 | default: |
| 61 | | logerror( "%s: SCSIDEV unknown write %02x\n", scsiInstance->machine().describe_context(), command[ 0 ] ); |
| 65 | logerror( "%s: SCSIDEV unknown write %02x\n", machine().describe_context(), command[ 0 ] ); |
| 62 | 66 | break; |
| 63 | 67 | } |
| 64 | 68 | } |
| 65 | 69 | |
| 66 | | static void scsidev_set_phase( SCSIInstance *scsiInstance, int phase ) |
| 70 | void scsidev_device::SetPhase( int _phase ) |
| 67 | 71 | { |
| 68 | | SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 69 | | our_this->phase = phase; |
| 72 | phase = _phase; |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | | static int scsidev_get_phase( SCSIInstance *scsiInstance ) |
| 75 | void scsidev_device::GetPhase( int *_phase) |
| 73 | 76 | { |
| 74 | | SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 75 | | return our_this->phase; |
| 77 | *_phase = phase; |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | | static void scsidev_set_command( SCSIInstance *scsiInstance, void *command, int commandLength ) |
| 80 | void scsidev_device::SetCommand( UINT8 *_command, int _commandLength ) |
| 79 | 81 | { |
| 80 | | SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 81 | | |
| 82 | | if( commandLength > sizeof( our_this->command ) ) |
| 82 | if( _commandLength > sizeof( command ) ) |
| 83 | 83 | { |
| 84 | 84 | /// TODO: output an error. |
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | | memcpy( our_this->command, command, commandLength ); |
| 89 | | our_this->commandLength = commandLength; |
| 88 | memcpy( command, _command, _commandLength ); |
| 89 | commandLength = _commandLength; |
| 90 | 90 | |
| 91 | | SCSISetPhase( scsiInstance, SCSI_PHASE_COMMAND ); |
| 91 | SetPhase( SCSI_PHASE_COMMAND ); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | | static int scsidev_get_command( SCSIInstance *scsiInstance, void **command ) |
| 94 | void scsidev_device::GetCommand( UINT8 **_command, int *_commandLength ) |
| 95 | 95 | { |
| 96 | | SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 97 | | *command = our_this->command; |
| 98 | | return our_this->commandLength; |
| 96 | *_command = command; |
| 97 | *_commandLength = commandLength; |
| 99 | 98 | } |
| 100 | | |
| 101 | | static void scsidev_alloc_instance( SCSIInstance *scsiInstance, const char *diskregion ) |
| 102 | | { |
| 103 | | running_machine &machine = scsiInstance->machine(); |
| 104 | | SCSIDev *our_this = (SCSIDev *)SCSIThis( &SCSIClassDevice, scsiInstance ); |
| 105 | | |
| 106 | | state_save_register_item_array( machine, "scsidev", diskregion, 0, our_this->command ); |
| 107 | | state_save_register_item( machine, "scsidev", diskregion, 0, our_this->commandLength ); |
| 108 | | state_save_register_item( machine, "scsidev", diskregion, 0, our_this->phase ); |
| 109 | | } |
| 110 | | |
| 111 | | static int scsidev_dispatch( int operation, void *file, INT64 intparm, void *ptrparm ) |
| 112 | | { |
| 113 | | SCSIAllocInstanceParams *params; |
| 114 | | |
| 115 | | switch( operation ) |
| 116 | | { |
| 117 | | case SCSIOP_EXEC_COMMAND: |
| 118 | | return scsidev_exec_command( (SCSIInstance *)file, (UINT8 *)ptrparm ); |
| 119 | | |
| 120 | | case SCSIOP_READ_DATA: |
| 121 | | scsidev_read_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 122 | | break; |
| 123 | | |
| 124 | | case SCSIOP_WRITE_DATA: |
| 125 | | scsidev_write_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 126 | | break; |
| 127 | | |
| 128 | | case SCSIOP_SET_PHASE: |
| 129 | | scsidev_set_phase( (SCSIInstance *)file, intparm ); |
| 130 | | return 0; |
| 131 | | |
| 132 | | case SCSIOP_GET_PHASE: |
| 133 | | return scsidev_get_phase( (SCSIInstance *)file ); |
| 134 | | |
| 135 | | case SCSIOP_SET_COMMAND: |
| 136 | | scsidev_set_command( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 137 | | return 0; |
| 138 | | |
| 139 | | case SCSIOP_GET_COMMAND: |
| 140 | | return scsidev_get_command( (SCSIInstance *)file, (void **)ptrparm ); |
| 141 | | |
| 142 | | case SCSIOP_ALLOC_INSTANCE: |
| 143 | | params = (SCSIAllocInstanceParams *)ptrparm; |
| 144 | | params->instance = SCSIMalloc( params->machine(), (const SCSIClass *)file ); |
| 145 | | scsidev_alloc_instance( params->instance, params->diskregion ); |
| 146 | | return 0; |
| 147 | | |
| 148 | | case SCSIOP_DELETE_INSTANCE: |
| 149 | | auto_free( ((SCSIInstance *)file)->machine(), file ); |
| 150 | | return 0; |
| 151 | | } |
| 152 | | return 0; |
| 153 | | } |
| 154 | | |
| 155 | | const SCSIClass SCSIClassDevice = |
| 156 | | { |
| 157 | | NULL, |
| 158 | | scsidev_dispatch, |
| 159 | | sizeof( SCSIDev ) |
| 160 | | }; |
src/emu/machine/scsicd.c
| r15370 | r15371 | |
| 11 | 11 | #include "imagedev/chd_cd.h" |
| 12 | 12 | #include "scsicd.h" |
| 13 | 13 | |
| 14 | | typedef struct |
| 15 | | { |
| 16 | | UINT32 lba; |
| 17 | | UINT32 blocks; |
| 18 | | UINT32 last_lba; |
| 19 | | UINT32 bytes_per_sector; |
| 20 | | UINT32 num_subblocks; |
| 21 | | UINT32 cur_subblock; |
| 22 | | UINT32 play_err_flag; |
| 23 | | cdrom_file *cdrom; |
| 24 | | bool is_file; |
| 25 | | } SCSICd; |
| 26 | | |
| 27 | 14 | static void phys_frame_to_msf(int phys_frame, int *m, int *s, int *f) |
| 28 | 15 | { |
| 29 | 16 | *m = phys_frame / (60*75); |
| r15370 | r15371 | |
| 32 | 19 | *f = phys_frame % 75; |
| 33 | 20 | } |
| 34 | 21 | |
| 22 | // device type definition |
| 23 | const device_type SCSICD = &device_creator<scsicd_device>; |
| 35 | 24 | |
| 25 | scsicd_device::scsicd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 26 | : scsidev_device(mconfig, SCSICD, "SCSICD", tag, owner, clock) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | scsicd_device::scsicd_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) : |
| 31 | scsidev_device(mconfig, type, name, tag, owner, clock) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | void scsicd_device::device_start() |
| 36 | { |
| 37 | save_item( NAME( lba ) ); |
| 38 | save_item( NAME( blocks ) ); |
| 39 | save_item( NAME( last_lba ) ); |
| 40 | save_item( NAME( bytes_per_sector ) ); |
| 41 | save_item( NAME( num_subblocks ) ); |
| 42 | save_item( NAME( cur_subblock ) ); |
| 43 | save_item( NAME( play_err_flag ) ); |
| 44 | } |
| 45 | |
| 46 | void scsicd_device::device_reset() |
| 47 | { |
| 48 | scsidev_device::device_reset(); |
| 49 | |
| 50 | is_file = TRUE; |
| 51 | cdrom = subdevice<cdrom_image_device>("image")->get_cdrom_file(); |
| 52 | if( !cdrom ) |
| 53 | { |
| 54 | // try to locate the CHD from a DISK_REGION |
| 55 | chd_file *chd = get_disk_handle( machine(), tag() ); |
| 56 | if( chd != NULL ) |
| 57 | { |
| 58 | is_file = FALSE; |
| 59 | cdrom = cdrom_open( chd ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if( !cdrom ) |
| 64 | { |
| 65 | logerror( "SCSICD %s: no CD found!\n", tag() ); |
| 66 | } |
| 67 | |
| 68 | lba = 0; |
| 69 | blocks = 0; |
| 70 | last_lba = 0; |
| 71 | bytes_per_sector = 2048; |
| 72 | num_subblocks = 1; |
| 73 | cur_subblock = 0; |
| 74 | play_err_flag = 0; |
| 75 | } |
| 76 | |
| 77 | void scsicd_device::device_stop() |
| 78 | { |
| 79 | if (!is_file) |
| 80 | { |
| 81 | if( cdrom ) |
| 82 | { |
| 83 | cdrom_close( cdrom ); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | cdrom_interface scsicd_device::cd_intf = { 0, 0 }; |
| 89 | |
| 90 | static MACHINE_CONFIG_FRAGMENT(scsi_cdrom) |
| 91 | MCFG_CDROM_ADD("image", scsicd_device::cd_intf) |
| 92 | MACHINE_CONFIG_END |
| 93 | |
| 94 | machine_config_constructor scsicd_device::device_mconfig_additions() const |
| 95 | { |
| 96 | return MACHINE_CONFIG_NAME(scsi_cdrom); |
| 97 | } |
| 98 | |
| 36 | 99 | // scsicd_exec_command |
| 37 | 100 | // |
| 38 | 101 | // Execute a SCSI command. |
| 39 | 102 | |
| 40 | | static int scsicd_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode ) |
| 103 | void scsicd_device::ExecCommand( int *transferLength ) |
| 41 | 104 | { |
| 42 | 105 | UINT8 *command; |
| 43 | 106 | int commandLength; |
| 44 | | SCSICd *our_this = (SCSICd *)SCSIThis( &SCSIClassCDROM, scsiInstance ); |
| 45 | | |
| 46 | | cdrom_file *cdrom = our_this->cdrom; |
| 47 | 107 | device_t *cdda; |
| 48 | 108 | int trk; |
| 49 | 109 | |
| 50 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 110 | GetCommand( &command, &commandLength ); |
| 51 | 111 | |
| 52 | 112 | switch ( command[0] ) |
| 53 | 113 | { |
| 54 | 114 | case 0x03: // REQUEST SENSE |
| 55 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 56 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 115 | SetPhase( SCSI_PHASE_DATAIN ); |
| 116 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 117 | break; |
| 57 | 118 | |
| 58 | 119 | case 0x12: // INQUIRY |
| 59 | 120 | logerror("SCSICD: REQUEST SENSE\n"); |
| 60 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 61 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 121 | SetPhase( SCSI_PHASE_DATAIN ); |
| 122 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 123 | break; |
| 62 | 124 | |
| 63 | 125 | case 0x15: // MODE SELECT(6) |
| 64 | 126 | logerror("SCSICD: MODE SELECT(6) length %x control %x\n", command[4], command[5]); |
| 65 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 66 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 127 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 128 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 129 | break; |
| 67 | 130 | |
| 68 | 131 | case 0x1a: // MODE SENSE(6) |
| 69 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 70 | | return SCSILengthFromUINT8( &command[ 4 ] ); |
| 132 | SetPhase( SCSI_PHASE_DATAIN ); |
| 133 | *transferLength = SCSILengthFromUINT8( &command[ 4 ] ); |
| 134 | break; |
| 71 | 135 | |
| 72 | 136 | case 0x1b: // START STOP UNIT |
| 73 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 137 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 74 | 138 | if (cdda != NULL) |
| 75 | 139 | { |
| 76 | 140 | cdda_stop_audio(cdda); |
| 77 | 141 | } |
| 78 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 79 | | return 0; |
| 142 | SetPhase( SCSI_PHASE_STATUS ); |
| 143 | *transferLength = 0; |
| 144 | break; |
| 80 | 145 | |
| 81 | 146 | case 0x1e: // PREVENT ALLOW MEDIUM REMOVAL |
| 82 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 83 | | return 0; |
| 147 | SetPhase( SCSI_PHASE_STATUS ); |
| 148 | *transferLength = 0; |
| 149 | break; |
| 84 | 150 | |
| 85 | 151 | case 0x25: // READ CAPACITY |
| 86 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 87 | | return 8; |
| 152 | SetPhase( SCSI_PHASE_DATAIN ); |
| 153 | *transferLength = 8; |
| 154 | break; |
| 88 | 155 | |
| 89 | 156 | case 0x28: // READ(10) |
| 90 | 157 | |
| 91 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 92 | | our_this->blocks = SCSILengthFromUINT16( &command[7] ); |
| 158 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 159 | blocks = SCSILengthFromUINT16( &command[7] ); |
| 93 | 160 | |
| 94 | | logerror("SCSICD: READ(10) at LBA %x for %d blocks (%d bytes)\n", our_this->lba, our_this->blocks, our_this->blocks * our_this->bytes_per_sector); |
| 161 | logerror("SCSICD: READ(10) at LBA %x for %d blocks (%d bytes)\n", lba, blocks, blocks * bytes_per_sector); |
| 95 | 162 | |
| 96 | | if (our_this->num_subblocks > 1) |
| 163 | if (num_subblocks > 1) |
| 97 | 164 | { |
| 98 | | our_this->cur_subblock = our_this->lba % our_this->num_subblocks; |
| 99 | | our_this->lba /= our_this->num_subblocks; |
| 165 | cur_subblock = lba % num_subblocks; |
| 166 | lba /= num_subblocks; |
| 100 | 167 | } |
| 101 | 168 | else |
| 102 | 169 | { |
| 103 | | our_this->cur_subblock = 0; |
| 170 | cur_subblock = 0; |
| 104 | 171 | } |
| 105 | 172 | |
| 106 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 173 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 107 | 174 | if (cdda != NULL) |
| 108 | 175 | { |
| 109 | 176 | cdda_stop_audio(cdda); |
| 110 | 177 | } |
| 111 | 178 | |
| 112 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 113 | | return our_this->blocks * our_this->bytes_per_sector; |
| 179 | SetPhase( SCSI_PHASE_DATAIN ); |
| 180 | *transferLength = blocks * bytes_per_sector; |
| 181 | break; |
| 114 | 182 | |
| 115 | 183 | case 0x42: // READ SUB-CHANNEL |
| 116 | 184 | // logerror("SCSICD: READ SUB-CHANNEL type %d\n", command[3]); |
| 117 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 118 | | return SCSILengthFromUINT16( &command[ 7 ] ); |
| 185 | SetPhase( SCSI_PHASE_DATAIN ); |
| 186 | *transferLength = SCSILengthFromUINT16( &command[ 7 ] ); |
| 187 | break; |
| 119 | 188 | |
| 120 | 189 | case 0x43: // READ TOC |
| 121 | 190 | { |
| r15370 | r15371 | |
| 143 | 212 | length = 4; |
| 144 | 213 | } |
| 145 | 214 | |
| 146 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 215 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 147 | 216 | if (cdda != NULL) |
| 148 | 217 | { |
| 149 | 218 | cdda_stop_audio(cdda); |
| 150 | 219 | } |
| 151 | 220 | |
| 152 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 153 | | return length; |
| 221 | SetPhase( SCSI_PHASE_DATAIN ); |
| 222 | *transferLength = length; |
| 223 | break; |
| 154 | 224 | } |
| 155 | 225 | case 0x45: // PLAY AUDIO(10) |
| 156 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 157 | | our_this->blocks = SCSILengthFromUINT16( &command[7] ); |
| 226 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 227 | blocks = SCSILengthFromUINT16( &command[7] ); |
| 158 | 228 | |
| 159 | 229 | // special cases: lba of 0 means MSF of 00:02:00 |
| 160 | | if (our_this->lba == 0) |
| 230 | if (lba == 0) |
| 161 | 231 | { |
| 162 | | our_this->lba = 150; |
| 232 | lba = 150; |
| 163 | 233 | } |
| 164 | | else if (our_this->lba == 0xffffffff) |
| 234 | else if (lba == 0xffffffff) |
| 165 | 235 | { |
| 166 | 236 | logerror("SCSICD: play audio from current not implemented!\n"); |
| 167 | 237 | } |
| 168 | 238 | |
| 169 | | logerror("SCSICD: PLAY AUDIO(10) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 239 | logerror("SCSICD: PLAY AUDIO(10) at LBA %x for %x blocks\n", lba, blocks); |
| 170 | 240 | |
| 171 | | trk = cdrom_get_track(cdrom, our_this->lba); |
| 241 | trk = cdrom_get_track(cdrom, lba); |
| 172 | 242 | |
| 173 | 243 | if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO) |
| 174 | 244 | { |
| 175 | | our_this->play_err_flag = 0; |
| 176 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 245 | play_err_flag = 0; |
| 246 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 177 | 247 | if (cdda != NULL) |
| 178 | | cdda_start_audio(cdda, our_this->lba, our_this->blocks); |
| 248 | cdda_start_audio(cdda, lba, blocks); |
| 179 | 249 | } |
| 180 | 250 | else |
| 181 | 251 | { |
| 182 | 252 | logerror("SCSICD: track is NOT audio!\n"); |
| 183 | | our_this->play_err_flag = 1; |
| 253 | play_err_flag = 1; |
| 184 | 254 | } |
| 185 | 255 | |
| 186 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 187 | | return 0; |
| 256 | SetPhase( SCSI_PHASE_STATUS ); |
| 257 | *transferLength = 0; |
| 258 | break; |
| 188 | 259 | |
| 189 | 260 | case 0x48: // PLAY AUDIO TRACK/INDEX |
| 190 | 261 | // be careful: tracks here are zero-based, but the SCSI command |
| 191 | 262 | // uses the real CD track number which is 1-based! |
| 192 | | our_this->lba = cdrom_get_track_start(cdrom, command[4]-1); |
| 193 | | our_this->blocks = cdrom_get_track_start(cdrom, command[7]-1) - our_this->lba; |
| 263 | lba = cdrom_get_track_start(cdrom, command[4]-1); |
| 264 | blocks = cdrom_get_track_start(cdrom, command[7]-1) - lba; |
| 194 | 265 | if (command[4] > command[7]) |
| 195 | 266 | { |
| 196 | | our_this->blocks = 0; |
| 267 | blocks = 0; |
| 197 | 268 | } |
| 198 | 269 | |
| 199 | 270 | if (command[4] == command[7]) |
| 200 | 271 | { |
| 201 | | our_this->blocks = cdrom_get_track_start(cdrom, command[4]) - our_this->lba; |
| 272 | blocks = cdrom_get_track_start(cdrom, command[4]) - lba; |
| 202 | 273 | } |
| 203 | 274 | |
| 204 | | if (our_this->blocks && cdrom) |
| 275 | if (blocks && cdrom) |
| 205 | 276 | { |
| 206 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 277 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 207 | 278 | if (cdda != NULL) |
| 208 | | cdda_start_audio(cdda, our_this->lba, our_this->blocks); |
| 279 | cdda_start_audio(cdda, lba, blocks); |
| 209 | 280 | } |
| 210 | 281 | |
| 211 | | logerror("SCSICD: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", command[4], command[5], command[7], command[8], our_this->blocks); |
| 212 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 213 | | return 0; |
| 282 | logerror("SCSICD: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", command[4], command[5], command[7], command[8], blocks); |
| 283 | SetPhase( SCSI_PHASE_STATUS ); |
| 284 | *transferLength = 0; |
| 285 | break; |
| 214 | 286 | |
| 215 | 287 | case 0x4b: // PAUSE/RESUME |
| 216 | 288 | if (cdrom) |
| 217 | 289 | { |
| 218 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 290 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 219 | 291 | if (cdda != NULL) |
| 220 | 292 | cdda_pause_audio(cdda, (command[8] & 0x01) ^ 0x01); |
| 221 | 293 | } |
| 222 | 294 | |
| 223 | 295 | logerror("SCSICD: PAUSE/RESUME: %s\n", command[8]&1 ? "RESUME" : "PAUSE"); |
| 224 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 225 | | return 0; |
| 296 | SetPhase( SCSI_PHASE_STATUS ); |
| 297 | *transferLength = 0; |
| 298 | break; |
| 226 | 299 | |
| 227 | 300 | case 0x55: // MODE SELECT(10) |
| 228 | 301 | logerror("SCSICD: MODE SELECT length %x control %x\n", command[7]<<8 | command[8], command[1]); |
| 229 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 230 | | return SCSILengthFromUINT16( &command[ 7 ] ); |
| 302 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 303 | *transferLength = SCSILengthFromUINT16( &command[ 7 ] ); |
| 304 | break; |
| 231 | 305 | |
| 232 | 306 | case 0x5a: // MODE SENSE(10) |
| 233 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 234 | | return SCSILengthFromUINT16( &command[ 7 ] ); |
| 307 | SetPhase( SCSI_PHASE_DATAIN ); |
| 308 | *transferLength = SCSILengthFromUINT16( &command[ 7 ] ); |
| 309 | break; |
| 235 | 310 | |
| 236 | 311 | case 0xa5: // PLAY AUDIO(12) |
| 237 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 238 | | our_this->blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9]; |
| 312 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 313 | blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9]; |
| 239 | 314 | |
| 240 | 315 | // special cases: lba of 0 means MSF of 00:02:00 |
| 241 | | if (our_this->lba == 0) |
| 316 | if (lba == 0) |
| 242 | 317 | { |
| 243 | | our_this->lba = 150; |
| 318 | lba = 150; |
| 244 | 319 | } |
| 245 | | else if (our_this->lba == 0xffffffff) |
| 320 | else if (lba == 0xffffffff) |
| 246 | 321 | { |
| 247 | 322 | logerror("SCSICD: play audio from current not implemented!\n"); |
| 248 | 323 | } |
| 249 | 324 | |
| 250 | | logerror("SCSICD: PLAY AUDIO(12) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks); |
| 325 | logerror("SCSICD: PLAY AUDIO(12) at LBA %x for %x blocks\n", lba, blocks); |
| 251 | 326 | |
| 252 | | trk = cdrom_get_track(cdrom, our_this->lba); |
| 327 | trk = cdrom_get_track(cdrom, lba); |
| 253 | 328 | |
| 254 | 329 | if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO) |
| 255 | 330 | { |
| 256 | | our_this->play_err_flag = 0; |
| 257 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 331 | play_err_flag = 0; |
| 332 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 258 | 333 | if (cdda != NULL) |
| 259 | | cdda_start_audio(cdda, our_this->lba, our_this->blocks); |
| 334 | cdda_start_audio(cdda, lba, blocks); |
| 260 | 335 | } |
| 261 | 336 | else |
| 262 | 337 | { |
| 263 | 338 | logerror("SCSICD: track is NOT audio!\n"); |
| 264 | | our_this->play_err_flag = 1; |
| 339 | play_err_flag = 1; |
| 265 | 340 | } |
| 266 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 267 | | return 0; |
| 341 | SetPhase( SCSI_PHASE_STATUS ); |
| 342 | *transferLength = 0; |
| 343 | break; |
| 268 | 344 | |
| 269 | 345 | case 0xa8: // READ(12) |
| 270 | | our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 271 | | our_this->blocks = command[7]<<16 | command[8]<<8 | command[9]; |
| 346 | lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5]; |
| 347 | blocks = command[7]<<16 | command[8]<<8 | command[9]; |
| 272 | 348 | |
| 273 | | logerror("SCSICD: READ(12) at LBA %x for %x blocks (%x bytes)\n", our_this->lba, our_this->blocks, our_this->blocks * our_this->bytes_per_sector); |
| 349 | logerror("SCSICD: READ(12) at LBA %x for %x blocks (%x bytes)\n", lba, blocks, blocks * bytes_per_sector); |
| 274 | 350 | |
| 275 | | if (our_this->num_subblocks > 1) |
| 351 | if (num_subblocks > 1) |
| 276 | 352 | { |
| 277 | | our_this->cur_subblock = our_this->lba % our_this->num_subblocks; |
| 278 | | our_this->lba /= our_this->num_subblocks; |
| 353 | cur_subblock = lba % num_subblocks; |
| 354 | lba /= num_subblocks; |
| 279 | 355 | } |
| 280 | 356 | else |
| 281 | 357 | { |
| 282 | | our_this->cur_subblock = 0; |
| 358 | cur_subblock = 0; |
| 283 | 359 | } |
| 284 | 360 | |
| 285 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 361 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 286 | 362 | if (cdda != NULL) |
| 287 | 363 | { |
| 288 | 364 | cdda_stop_audio(cdda); |
| 289 | 365 | } |
| 290 | 366 | |
| 291 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 292 | | return our_this->blocks * our_this->bytes_per_sector; |
| 367 | SetPhase( SCSI_PHASE_DATAIN ); |
| 368 | *transferLength = blocks * bytes_per_sector; |
| 369 | break; |
| 293 | 370 | |
| 294 | 371 | case 0xbb: // SET CD SPEED |
| 295 | 372 | logerror("SCSICD: SET CD SPEED to %d kbytes/sec.\n", command[2]<<8 | command[3]); |
| 296 | | SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS ); |
| 297 | | return 0; |
| 373 | SetPhase( SCSI_PHASE_STATUS ); |
| 374 | *transferLength = 0; |
| 375 | break; |
| 298 | 376 | |
| 299 | 377 | default: |
| 300 | | return SCSIBase( &SCSIClassCDROM, SCSIOP_EXEC_COMMAND, scsiInstance, 0, NULL ); |
| 378 | scsidev_device::ExecCommand( transferLength ); |
| 301 | 379 | } |
| 302 | 380 | } |
| 303 | 381 | |
| r15370 | r15371 | |
| 305 | 383 | // |
| 306 | 384 | // Read data from the device resulting from the execution of a command |
| 307 | 385 | |
| 308 | | static void scsicd_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 386 | void scsicd_device::ReadData( UINT8 *data, int dataLength ) |
| 309 | 387 | { |
| 310 | 388 | UINT8 *command; |
| 311 | 389 | int commandLength; |
| 312 | | SCSICd *our_this = (SCSICd *)SCSIThis( &SCSIClassCDROM, scsiInstance ); |
| 313 | 390 | |
| 314 | 391 | int i; |
| 315 | 392 | UINT32 last_phys_frame; |
| 316 | | cdrom_file *cdrom = our_this->cdrom; |
| 317 | 393 | UINT32 temp; |
| 318 | 394 | UINT8 tmp_buffer[2048]; |
| 319 | 395 | device_t *cdda; |
| 320 | 396 | |
| 321 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 397 | GetCommand( &command, &commandLength ); |
| 322 | 398 | |
| 323 | 399 | switch ( command[0] ) |
| 324 | 400 | { |
| r15370 | r15371 | |
| 329 | 405 | |
| 330 | 406 | data[0] = 0x71; // deferred error |
| 331 | 407 | |
| 332 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 408 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 333 | 409 | if (cdda != NULL && cdda_audio_active(cdda)) |
| 334 | 410 | { |
| 335 | 411 | data[12] = 0x00; |
| 336 | 412 | data[13] = 0x11; // AUDIO PLAY OPERATION IN PROGRESS |
| 337 | 413 | } |
| 338 | | else if (our_this->play_err_flag) |
| 414 | else if (play_err_flag) |
| 339 | 415 | { |
| 340 | | our_this->play_err_flag = 0; |
| 416 | play_err_flag = 0; |
| 341 | 417 | data[12] = 0x64; // ILLEGAL MODE FOR THIS TRACK |
| 342 | 418 | data[13] = 0x00; |
| 343 | 419 | } |
| r15370 | r15371 | |
| 369 | 445 | data[3] = (temp & 0xff); |
| 370 | 446 | data[4] = 0; |
| 371 | 447 | data[5] = 0; |
| 372 | | data[6] = (our_this->bytes_per_sector>>8)&0xff; |
| 373 | | data[7] = (our_this->bytes_per_sector & 0xff); |
| 448 | data[6] = (bytes_per_sector>>8)&0xff; |
| 449 | data[7] = (bytes_per_sector & 0xff); |
| 374 | 450 | break; |
| 375 | 451 | |
| 376 | 452 | case 0x28: // READ(10) |
| 377 | 453 | case 0xa8: // READ(12) |
| 378 | 454 | logerror("SCSICD: read %x dataLength, \n", dataLength); |
| 379 | | if ((our_this->cdrom) && (our_this->blocks)) |
| 455 | if ((cdrom) && (blocks)) |
| 380 | 456 | { |
| 381 | 457 | while (dataLength > 0) |
| 382 | 458 | { |
| 383 | | if (!cdrom_read_data(our_this->cdrom, our_this->lba, tmp_buffer, CD_TRACK_MODE1)) |
| 459 | if (!cdrom_read_data(cdrom, lba, tmp_buffer, CD_TRACK_MODE1)) |
| 384 | 460 | { |
| 385 | 461 | logerror("SCSICD: CD read error!\n"); |
| 386 | 462 | } |
| 387 | 463 | |
| 388 | | logerror("True LBA: %d, buffer half: %d\n", our_this->lba, our_this->cur_subblock * our_this->bytes_per_sector); |
| 464 | logerror("True LBA: %d, buffer half: %d\n", lba, cur_subblock * bytes_per_sector); |
| 389 | 465 | |
| 390 | | memcpy(data, &tmp_buffer[our_this->cur_subblock * our_this->bytes_per_sector], our_this->bytes_per_sector); |
| 466 | memcpy(data, &tmp_buffer[cur_subblock * bytes_per_sector], bytes_per_sector); |
| 391 | 467 | |
| 392 | | our_this->cur_subblock++; |
| 393 | | if (our_this->cur_subblock >= our_this->num_subblocks) |
| 468 | cur_subblock++; |
| 469 | if (cur_subblock >= num_subblocks) |
| 394 | 470 | { |
| 395 | | our_this->cur_subblock = 0; |
| 471 | cur_subblock = 0; |
| 396 | 472 | |
| 397 | | our_this->lba++; |
| 398 | | our_this->blocks--; |
| 473 | lba++; |
| 474 | blocks--; |
| 399 | 475 | } |
| 400 | 476 | |
| 401 | | our_this->last_lba = our_this->lba; |
| 402 | | dataLength -= our_this->bytes_per_sector; |
| 403 | | data += our_this->bytes_per_sector; |
| 477 | last_lba = lba; |
| 478 | dataLength -= bytes_per_sector; |
| 479 | data += bytes_per_sector; |
| 404 | 480 | } |
| 405 | 481 | } |
| 406 | 482 | break; |
| r15370 | r15371 | |
| 422 | 498 | |
| 423 | 499 | msf = command[1] & 0x2; |
| 424 | 500 | |
| 425 | | cdda = cdda_from_cdrom(scsiInstance->machine(), cdrom); |
| 501 | cdda = cdda_from_cdrom(machine(), cdrom); |
| 426 | 502 | audio_active = cdda != NULL && cdda_audio_active(cdda); |
| 427 | 503 | if (audio_active) |
| 428 | 504 | { |
| r15370 | r15371 | |
| 451 | 527 | // if audio is playing, get the latest LBA from the CDROM layer |
| 452 | 528 | if (audio_active) |
| 453 | 529 | { |
| 454 | | our_this->last_lba = cdda_get_audio_lba(cdda); |
| 530 | last_lba = cdda_get_audio_lba(cdda); |
| 455 | 531 | } |
| 456 | 532 | else |
| 457 | 533 | { |
| 458 | | our_this->last_lba = 0; |
| 534 | last_lba = 0; |
| 459 | 535 | } |
| 460 | 536 | |
| 461 | 537 | data[2] = 0; |
| 462 | 538 | data[3] = 12; // data length |
| 463 | 539 | data[4] = 0x01; // sub-channel format code |
| 464 | 540 | data[5] = 0x10 | (audio_active ? 0 : 4); |
| 465 | | data[6] = cdrom_get_track(cdrom, our_this->last_lba) + 1; // track |
| 541 | data[6] = cdrom_get_track(cdrom, last_lba) + 1; // track |
| 466 | 542 | data[7] = 0; // index |
| 467 | 543 | |
| 468 | | last_phys_frame = our_this->last_lba; |
| 544 | last_phys_frame = last_lba; |
| 469 | 545 | |
| 470 | 546 | if (msf) |
| 471 | 547 | { |
| r15370 | r15371 | |
| 635 | 711 | break; |
| 636 | 712 | |
| 637 | 713 | default: |
| 638 | | SCSIBase( &SCSIClassCDROM, SCSIOP_READ_DATA, scsiInstance, dataLength, data ); |
| 714 | scsidev_device::ReadData( data, dataLength ); |
| 639 | 715 | break; |
| 640 | 716 | } |
| 641 | 717 | } |
| r15370 | r15371 | |
| 644 | 720 | // |
| 645 | 721 | // Write data to the CD-ROM device as part of the execution of a command |
| 646 | 722 | |
| 647 | | static void scsicd_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 723 | void scsicd_device::WriteData( UINT8 *data, int dataLength ) |
| 648 | 724 | { |
| 649 | 725 | UINT8 *command; |
| 650 | 726 | int commandLength; |
| 651 | | SCSICd *our_this = (SCSICd *)SCSIThis( &SCSIClassCDROM, scsiInstance ); |
| 652 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 727 | GetCommand( &command, &commandLength ); |
| 653 | 728 | |
| 654 | 729 | switch (command[ 0 ]) |
| 655 | 730 | { |
| r15370 | r15371 | |
| 665 | 740 | { |
| 666 | 741 | logerror("SCSICD: Experimental SGI 512-byte block extension enabled\n"); |
| 667 | 742 | |
| 668 | | our_this->bytes_per_sector = 512; |
| 669 | | our_this->num_subblocks = 4; |
| 743 | bytes_per_sector = 512; |
| 744 | num_subblocks = 4; |
| 670 | 745 | } |
| 671 | 746 | else |
| 672 | 747 | { |
| r15370 | r15371 | |
| 684 | 759 | break; |
| 685 | 760 | |
| 686 | 761 | default: |
| 687 | | SCSIBase( &SCSIClassCDROM, SCSIOP_WRITE_DATA, scsiInstance, dataLength, data ); |
| 762 | scsidev_device::WriteData( data, dataLength ); |
| 688 | 763 | break; |
| 689 | 764 | } |
| 690 | 765 | } |
| 691 | 766 | |
| 692 | | static void scsicd_alloc_instance( SCSIInstance *scsiInstance, const char *diskregion ) |
| 767 | void scsicd_device::GetDevice( void **_cdrom ) |
| 693 | 768 | { |
| 694 | | running_machine &machine = scsiInstance->machine(); |
| 695 | | SCSICd *our_this = (SCSICd *)SCSIThis( &SCSIClassCDROM, scsiInstance ); |
| 696 | | |
| 697 | | our_this->lba = 0; |
| 698 | | our_this->blocks = 0; |
| 699 | | our_this->last_lba = 0; |
| 700 | | our_this->bytes_per_sector = 2048; |
| 701 | | our_this->num_subblocks = 1; |
| 702 | | our_this->cur_subblock = 0; |
| 703 | | our_this->play_err_flag = 0; |
| 704 | | |
| 705 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->lba ); |
| 706 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->blocks ); |
| 707 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->last_lba ); |
| 708 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->bytes_per_sector ); |
| 709 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->num_subblocks ); |
| 710 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->cur_subblock ); |
| 711 | | state_save_register_item( machine, "scsicd", diskregion, 0, our_this->play_err_flag ); |
| 712 | | |
| 713 | | if (machine.device( diskregion )) { |
| 714 | | our_this->is_file = TRUE; |
| 715 | | cdrom_image_device *cdrom = machine.device<cdrom_image_device>(diskregion); |
| 716 | | our_this->cdrom = cdrom->get_cdrom_file(); |
| 717 | | } else { |
| 718 | | our_this->is_file = FALSE; |
| 719 | | our_this->cdrom = cdrom_open(get_disk_handle( machine, diskregion )); |
| 720 | | } |
| 721 | | |
| 722 | | if (!our_this->cdrom) |
| 723 | | { |
| 724 | | logerror("SCSICD: no CD found!\n"); |
| 725 | | } |
| 769 | *(cdrom_file **)_cdrom = cdrom; |
| 726 | 770 | } |
| 727 | 771 | |
| 728 | | static void scsicd_delete_instance( SCSIInstance *scsiInstance ) |
| 772 | void scsicd_device::SetDevice( void *_cdrom ) |
| 729 | 773 | { |
| 730 | | SCSICd *our_this = (SCSICd *)SCSIThis( &SCSIClassCDROM, scsiInstance ); |
| 731 | | if (!our_this->is_file) { |
| 732 | | if( our_this->cdrom ) |
| 733 | | { |
| 734 | | cdrom_close( our_this->cdrom ); |
| 735 | | } |
| 736 | | } |
| 774 | cdrom = (cdrom_file *)_cdrom; |
| 737 | 775 | } |
| 738 | | |
| 739 | | static void scsicd_get_device( SCSIInstance *scsiInstance, cdrom_file **cdrom ) |
| 740 | | { |
| 741 | | SCSICd *our_this = (SCSICd *)SCSIThis( &SCSIClassCDROM, scsiInstance ); |
| 742 | | *cdrom = our_this->cdrom; |
| 743 | | } |
| 744 | | |
| 745 | | static void scsicd_set_device( SCSIInstance *scsiInstance, cdrom_file *cdrom ) |
| 746 | | { |
| 747 | | SCSICd *our_this = (SCSICd *)SCSIThis( &SCSIClassCDROM, scsiInstance ); |
| 748 | | our_this->cdrom = cdrom; |
| 749 | | } |
| 750 | | |
| 751 | | static int scsicd_dispatch(int operation, void *file, INT64 intparm, void *ptrparm) |
| 752 | | { |
| 753 | | SCSIAllocInstanceParams *params; |
| 754 | | |
| 755 | | switch (operation) |
| 756 | | { |
| 757 | | case SCSIOP_EXEC_COMMAND: |
| 758 | | return scsicd_exec_command( (SCSIInstance *)file, (UINT8 *)ptrparm ); |
| 759 | | |
| 760 | | case SCSIOP_READ_DATA: |
| 761 | | scsicd_read_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 762 | | return 0; |
| 763 | | |
| 764 | | case SCSIOP_WRITE_DATA: |
| 765 | | scsicd_write_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 766 | | return 0; |
| 767 | | |
| 768 | | case SCSIOP_ALLOC_INSTANCE: |
| 769 | | params = (SCSIAllocInstanceParams *)ptrparm; |
| 770 | | SCSIBase( &SCSIClassCDROM, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 771 | | scsicd_alloc_instance( params->instance, params->diskregion ); |
| 772 | | return 0; |
| 773 | | |
| 774 | | case SCSIOP_DELETE_INSTANCE: |
| 775 | | scsicd_delete_instance( (SCSIInstance *)file ); |
| 776 | | break; |
| 777 | | |
| 778 | | case SCSIOP_GET_DEVICE: |
| 779 | | scsicd_get_device( (SCSIInstance *)file, (cdrom_file **)ptrparm ); |
| 780 | | return 0; |
| 781 | | |
| 782 | | case SCSIOP_SET_DEVICE: |
| 783 | | scsicd_set_device( (SCSIInstance *)file, (cdrom_file *)ptrparm ); |
| 784 | | return 0; |
| 785 | | } |
| 786 | | |
| 787 | | return SCSIBase( &SCSIClassCDROM, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 788 | | } |
| 789 | | |
| 790 | | const SCSIClass SCSIClassCDROM = |
| 791 | | { |
| 792 | | &SCSIClassDevice, |
| 793 | | scsicd_dispatch, |
| 794 | | sizeof( SCSICd ) |
| 795 | | }; |
src/emu/machine/cr589.c
| r15370 | r15371 | |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | #include "emu.h" |
| 7 | | #include "cr589.h" |
| 7 | #include "machine/cr589.h" |
| 8 | 8 | |
| 9 | | typedef struct |
| 9 | // device type definition |
| 10 | const device_type CR589 = &device_creator<cr589_device>; |
| 11 | |
| 12 | cr589_device::cr589_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 13 | : scsicd_device(mconfig, CR589, "CR589", tag, owner, clock) |
| 10 | 14 | { |
| 11 | | int download; |
| 12 | | UINT8 buffer[ 65536 ]; |
| 13 | | int bufferOffset; |
| 14 | | } SCSICr589; |
| 15 | } |
| 15 | 16 | |
| 16 | 17 | static const int identity_offset = 0x3ab; |
| 17 | 18 | static const char download_identity[] = "MATSHITA CD98Q4 DOWNLOADGS0N"; |
| 18 | 19 | |
| 19 | | static int cr589_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode ) |
| 20 | void cr589_device::device_start() |
| 20 | 21 | { |
| 22 | scsicd_device::device_start(); |
| 23 | |
| 24 | download = 0; |
| 25 | memcpy( &buffer[ identity_offset ], "MATSHITACD-ROM CR-589 GS0N", 28 ); |
| 26 | |
| 27 | save_item(NAME(download)); |
| 28 | save_item(NAME(buffer)); |
| 29 | save_item(NAME(bufferOffset)); |
| 30 | } |
| 31 | |
| 32 | void cr589_device::ExecCommand( int *transferLength ) |
| 33 | { |
| 21 | 34 | UINT8 *command; |
| 22 | 35 | int commandLength; |
| 23 | | SCSICr589 *our_this = (SCSICr589 *)SCSIThis( &SCSIClassCr589, scsiInstance ); |
| 24 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 36 | GetCommand( &command, &commandLength ); |
| 25 | 37 | |
| 26 | 38 | switch( command[ 0 ] ) |
| 27 | 39 | { |
| 28 | 40 | case 0x3b: // WRITE BUFFER |
| 29 | | our_this->bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ]; |
| 30 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 31 | | return ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ]; |
| 41 | bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ]; |
| 42 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 43 | *transferLength = ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ]; |
| 44 | break; |
| 32 | 45 | |
| 33 | 46 | case 0x3c: // READ BUFFER |
| 34 | | our_this->bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ]; |
| 35 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN ); |
| 36 | | return ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ]; |
| 47 | bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ]; |
| 48 | SetPhase( SCSI_PHASE_DATAIN ); |
| 49 | *transferLength = ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ]; |
| 50 | break; |
| 37 | 51 | |
| 38 | 52 | case 0xcc: // FIRMWARE DOWNLOAD ENABLE |
| 39 | | SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT ); |
| 40 | | return SCSILengthFromUINT16( &command[7] ); |
| 53 | SetPhase( SCSI_PHASE_DATAOUT ); |
| 54 | *transferLength = SCSILengthFromUINT16( &command[7] ); |
| 55 | break; |
| 41 | 56 | |
| 42 | 57 | default: |
| 43 | | return SCSIBase( &SCSIClassCr589, SCSIOP_EXEC_COMMAND, scsiInstance, 0, NULL ); |
| 58 | scsicd_device::ExecCommand( transferLength ); |
| 44 | 59 | } |
| 45 | 60 | } |
| 46 | 61 | |
| 47 | | static void cr589_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 62 | void cr589_device::ReadData( UINT8 *data, int dataLength ) |
| 48 | 63 | { |
| 49 | 64 | UINT8 *command; |
| 50 | 65 | int commandLength; |
| 51 | | SCSICr589 *our_this = (SCSICr589 *)SCSIThis( &SCSIClassCr589, scsiInstance ); |
| 52 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 66 | GetCommand( &command, &commandLength ); |
| 53 | 67 | |
| 54 | 68 | switch( command[ 0 ] ) |
| 55 | 69 | { |
| 56 | 70 | case 0x12: // INQUIRY |
| 57 | | SCSIBase( &SCSIClassCr589, SCSIOP_READ_DATA, scsiInstance, dataLength, data ); |
| 71 | scsicd_device::ReadData( data, dataLength ); |
| 58 | 72 | |
| 59 | | if( our_this->download ) |
| 73 | if( download ) |
| 60 | 74 | { |
| 61 | 75 | memcpy( &data[ 8 ], download_identity, 28 ); |
| 62 | 76 | } |
| 63 | 77 | else |
| 64 | 78 | { |
| 65 | | memcpy( &data[ 8 ], &our_this->buffer[ identity_offset ], 28 ); |
| 79 | memcpy( &data[ 8 ], &buffer[ identity_offset ], 28 ); |
| 66 | 80 | } |
| 67 | 81 | break; |
| 68 | 82 | |
| 69 | 83 | case 0x3c: // READ BUFFER |
| 70 | | memcpy( data, &our_this->buffer[ our_this->bufferOffset ], dataLength ); |
| 71 | | our_this->bufferOffset += dataLength; |
| 84 | memcpy( data, &buffer[ bufferOffset ], dataLength ); |
| 85 | bufferOffset += dataLength; |
| 72 | 86 | break; |
| 73 | 87 | |
| 74 | 88 | default: |
| 75 | | SCSIBase( &SCSIClassCr589, SCSIOP_READ_DATA, scsiInstance, dataLength, data ); |
| 89 | scsicd_device::ReadData( data, dataLength ); |
| 76 | 90 | break; |
| 77 | 91 | } |
| 78 | 92 | } |
| 79 | 93 | |
| 80 | | static void cr589_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength ) |
| 94 | void cr589_device::WriteData( UINT8 *data, int dataLength ) |
| 81 | 95 | { |
| 82 | 96 | UINT8 *command; |
| 83 | 97 | int commandLength; |
| 84 | | SCSICr589 *our_this = (SCSICr589 *)SCSIThis( &SCSIClassCr589, scsiInstance ); |
| 85 | | SCSIGetCommand( scsiInstance, &command, &commandLength ); |
| 98 | GetCommand( &command, &commandLength ); |
| 86 | 99 | |
| 87 | 100 | switch( command[ 0 ] ) |
| 88 | 101 | { |
| 89 | 102 | case 0x3b: // WRITE BUFFER |
| 90 | | memcpy( &our_this->buffer[ our_this->bufferOffset ], data + 32, dataLength - 32 ); |
| 91 | | our_this->bufferOffset += dataLength; |
| 103 | memcpy( &buffer[ bufferOffset ], data + 32, dataLength - 32 ); |
| 104 | bufferOffset += dataLength; |
| 92 | 105 | break; |
| 93 | 106 | |
| 94 | 107 | case 0xcc: // FIRMWARE DOWNLOAD ENABLE |
| 95 | | if( memcmp( data, &our_this->buffer[ identity_offset ], 28 ) == 0 ) |
| 108 | if( memcmp( data, &buffer[ identity_offset ], 28 ) == 0 ) |
| 96 | 109 | { |
| 97 | | our_this->download = 1; |
| 110 | download = 1; |
| 98 | 111 | } |
| 99 | 112 | else if( memcmp( data, download_identity, 28 ) == 0 ) |
| 100 | 113 | { |
| 101 | | our_this->download = 0; |
| 114 | download = 0; |
| 102 | 115 | } |
| 103 | 116 | break; |
| 104 | 117 | |
| 105 | 118 | default: |
| 106 | | SCSIBase( &SCSIClassCr589, SCSIOP_WRITE_DATA, scsiInstance, dataLength, data ); |
| 119 | scsicd_device::WriteData( data, dataLength ); |
| 107 | 120 | break; |
| 108 | 121 | } |
| 109 | 122 | } |
| 110 | | |
| 111 | | static void cr589_alloc_instance( SCSIInstance *scsiInstance, const char *diskregion ) |
| 112 | | { |
| 113 | | running_machine &machine = scsiInstance->machine(); |
| 114 | | SCSICr589 *our_this = (SCSICr589 *)SCSIThis( &SCSIClassCr589, scsiInstance ); |
| 115 | | |
| 116 | | our_this->download = 0; |
| 117 | | memcpy( &our_this->buffer[ identity_offset ], "MATSHITACD-ROM CR-589 GS0N", 28 ); |
| 118 | | |
| 119 | | state_save_register_item( machine, "cr589", diskregion, 0, our_this->download ); |
| 120 | | state_save_register_item_array( machine, "cr589", diskregion, 0, our_this->buffer ); |
| 121 | | state_save_register_item( machine, "cr589", diskregion, 0, our_this->bufferOffset ); |
| 122 | | } |
| 123 | | |
| 124 | | static int cr589_dispatch( int operation, void *file, INT64 intparm, void *ptrparm ) |
| 125 | | { |
| 126 | | SCSIAllocInstanceParams *params; |
| 127 | | |
| 128 | | switch( operation ) |
| 129 | | { |
| 130 | | case SCSIOP_EXEC_COMMAND: |
| 131 | | return cr589_exec_command( (SCSIInstance *)file, (UINT8 *)ptrparm ); |
| 132 | | |
| 133 | | case SCSIOP_READ_DATA: |
| 134 | | cr589_read_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 135 | | return 0; |
| 136 | | |
| 137 | | case SCSIOP_WRITE_DATA: |
| 138 | | cr589_write_data( (SCSIInstance *)file, (UINT8 *)ptrparm, intparm ); |
| 139 | | return 0; |
| 140 | | |
| 141 | | case SCSIOP_ALLOC_INSTANCE: |
| 142 | | params = (SCSIAllocInstanceParams *)ptrparm; |
| 143 | | SCSIBase( &SCSIClassCr589, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 144 | | cr589_alloc_instance( params->instance, params->diskregion ); |
| 145 | | return 0; |
| 146 | | } |
| 147 | | |
| 148 | | return SCSIBase( &SCSIClassCr589, operation, (SCSIInstance *)file, intparm, (UINT8 *)ptrparm ); |
| 149 | | } |
| 150 | | |
| 151 | | const SCSIClass SCSIClassCr589 = |
| 152 | | { |
| 153 | | &SCSIClassCDROM, |
| 154 | | cr589_dispatch, |
| 155 | | sizeof( SCSICr589 ) |
| 156 | | }; |
src/mess/machine/scsibus.c
| r15370 | r15371 | |
| 9 | 9 | |
| 10 | 10 | #include "emu.h" |
| 11 | 11 | #include "machine/scsi.h" |
| 12 | #include "machine/scsidev.h" |
| 12 | 13 | #include "machine/scsibus.h" |
| 13 | 14 | #include "debugger.h" |
| 14 | 15 | #include "debug/debugcpu.h" |
| r15370 | r15371 | |
| 30 | 31 | typedef struct _scsibus_t scsibus_t; |
| 31 | 32 | struct _scsibus_t |
| 32 | 33 | { |
| 33 | | SCSIInstance *devices[8]; |
| 34 | scsidev_device *devices[8]; |
| 34 | 35 | const SCSIBus_interface *interface; |
| 35 | 36 | |
| 36 | 37 | devcb_resolved_write_line out_bsy_func; |
| r15370 | r15371 | |
| 63 | 64 | emu_timer *ack_timer; |
| 64 | 65 | emu_timer *sel_timer; |
| 65 | 66 | emu_timer *dataout_timer; |
| 66 | | |
| 67 | | UINT8 initialised; |
| 68 | 67 | }; |
| 69 | 68 | |
| 70 | 69 | static void set_scsi_line_now(device_t *device, UINT8 line, UINT8 state); |
| r15370 | r15371 | |
| 134 | 133 | |
| 135 | 134 | if (bus->data_last > 0) |
| 136 | 135 | { |
| 137 | | SCSIReadData(bus->devices[bus->last_id], bus->data, bus->data_last); |
| 136 | bus->devices[bus->last_id]->ReadData(bus->data, bus->data_last); |
| 138 | 137 | bus->bytes_left-=bus->data_last; |
| 139 | 138 | bus->data_idx=0; |
| 140 | 139 | } |
| r15370 | r15371 | |
| 144 | 143 | { |
| 145 | 144 | if(bus->bytes_left >= bus->sectorbytes) |
| 146 | 145 | { |
| 147 | | SCSIWriteData(bus->devices[bus->last_id], bus->data, bus->sectorbytes); |
| 146 | bus->devices[bus->last_id]->WriteData(bus->data, bus->sectorbytes); |
| 148 | 147 | |
| 149 | 148 | bus->bytes_left-=bus->sectorbytes; |
| 150 | 149 | bus->data_idx=0; |
| r15370 | r15371 | |
| 361 | 360 | bus->xfer_count=0; |
| 362 | 361 | bus->data_last=bus->xfer_count; |
| 363 | 362 | bus->bytes_left=0; |
| 364 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS); |
| 363 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 365 | 364 | break; |
| 366 | 365 | |
| 367 | 366 | // Recalibrate drive |
| r15370 | r15371 | |
| 371 | 370 | bus->xfer_count=0; |
| 372 | 371 | bus->data_last=bus->xfer_count; |
| 373 | 372 | bus->bytes_left=0; |
| 374 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS); |
| 373 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 375 | 374 | break; |
| 376 | 375 | |
| 377 | 376 | // Request sense, return previous error codes |
| r15370 | r15371 | |
| 386 | 385 | bus->data[2]=0x00; |
| 387 | 386 | bus->data[3]=0x00; |
| 388 | 387 | SET_STATUS_SENSE(SCSI_STATUS_OK,SCSI_SENSE_NO_SENSE); |
| 389 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 388 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 390 | 389 | break; |
| 391 | 390 | |
| 392 | 391 | // Format unit |
| r15370 | r15371 | |
| 394 | 393 | LOG(1,"SCSIBUS: format unit bus->command[1]=%02X & 0x10\n",(bus->command[1] & 0x10)); |
| 395 | 394 | command_local=1; |
| 396 | 395 | if((bus->command[1] & 0x10)==0x10) |
| 397 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 396 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 398 | 397 | else |
| 399 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS); |
| 398 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 400 | 399 | |
| 401 | 400 | bus->xfer_count=4; |
| 402 | 401 | bus->data_last=bus->xfer_count; |
| r15370 | r15371 | |
| 411 | 410 | bus->xfer_count=0; |
| 412 | 411 | bus->data_last=bus->xfer_count; |
| 413 | 412 | bus->bytes_left=0; |
| 414 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS); |
| 413 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 415 | 414 | break; |
| 416 | 415 | |
| 417 | 416 | // Setup drive parameters Xebec |
| r15370 | r15371 | |
| 421 | 420 | bus->xfer_count=XEBEC_PARAMS_SIZE; |
| 422 | 421 | bus->data_last=bus->xfer_count; |
| 423 | 422 | bus->bytes_left=0; |
| 424 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 423 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 425 | 424 | break; |
| 426 | 425 | |
| 427 | 426 | // Format bad track Xebec |
| r15370 | r15371 | |
| 431 | 430 | bus->xfer_count=XEBEC_ALT_TRACK_SIZE; |
| 432 | 431 | bus->data_last=bus->xfer_count; |
| 433 | 432 | bus->bytes_left=0; |
| 434 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 433 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 435 | 434 | break; |
| 436 | 435 | |
| 437 | 436 | // Write buffer Xebec S1410 specific |
| r15370 | r15371 | |
| 441 | 440 | bus->xfer_count=XEBEC_SECTOR_BUFFER_SIZE; |
| 442 | 441 | bus->data_last=bus->xfer_count; |
| 443 | 442 | bus->bytes_left=0; |
| 444 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 443 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 445 | 444 | break; |
| 446 | 445 | |
| 447 | 446 | // Read buffer Xebec S1410 specific |
| r15370 | r15371 | |
| 451 | 450 | bus->xfer_count=XEBEC_SECTOR_BUFFER_SIZE; |
| 452 | 451 | bus->data_last=bus->xfer_count; |
| 453 | 452 | bus->bytes_left=0; |
| 454 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAIN); |
| 453 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAIN); |
| 455 | 454 | break; |
| 456 | 455 | |
| 457 | 456 | // Write buffer, Adaptec ACB40x0 specific |
| r15370 | r15371 | |
| 461 | 460 | bus->xfer_count=ADAPTEC_DATA_BUFFER_SIZE; |
| 462 | 461 | bus->data_last=bus->xfer_count; |
| 463 | 462 | bus->bytes_left=0; |
| 464 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 463 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 465 | 464 | break; |
| 466 | 465 | |
| 467 | 466 | // Read buffer, Adaptec ACB40x0 specific |
| r15370 | r15371 | |
| 471 | 470 | bus->xfer_count=ADAPTEC_DATA_BUFFER_SIZE; |
| 472 | 471 | bus->data_last=bus->xfer_count; |
| 473 | 472 | bus->bytes_left=0; |
| 474 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAIN); |
| 473 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAIN); |
| 475 | 474 | break; |
| 476 | 475 | |
| 477 | 476 | // Send diagnostic info |
| r15370 | r15371 | |
| 481 | 480 | bus->xfer_count=(bus->command[3]<<8)+bus->command[4]; |
| 482 | 481 | bus->data_last=bus->xfer_count; |
| 483 | 482 | bus->bytes_left=0; |
| 484 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 483 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 485 | 484 | break; |
| 486 | 485 | |
| 487 | 486 | case SCSI_CMD_SEARCH_DATA_EQUAL : |
| r15370 | r15371 | |
| 490 | 489 | bus->xfer_count=0; |
| 491 | 490 | bus->data_last=bus->xfer_count; |
| 492 | 491 | bus->bytes_left=0; |
| 493 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS); |
| 492 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 494 | 493 | break; |
| 495 | 494 | |
| 496 | 495 | case SCSI_CMD_READ_DEFECT : |
| r15370 | r15371 | |
| 505 | 504 | bus->xfer_count=4; |
| 506 | 505 | bus->data_last=bus->xfer_count; |
| 507 | 506 | bus->bytes_left=0; |
| 508 | | SCSISetPhase(bus->devices[bus->last_id], SCSI_PHASE_DATAIN ); |
| 507 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAIN); |
| 509 | 508 | break; |
| 510 | 509 | |
| 511 | 510 | // write buffer |
| r15370 | r15371 | |
| 515 | 514 | bus->xfer_count=(bus->command[7]<<8)+bus->command[8]; |
| 516 | 515 | bus->data_last=bus->xfer_count; |
| 517 | 516 | bus->bytes_left=0; |
| 518 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAOUT); |
| 517 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 519 | 518 | break; |
| 520 | 519 | |
| 521 | 520 | // read buffer |
| r15370 | r15371 | |
| 525 | 524 | bus->xfer_count=(bus->command[7]<<8)+bus->command[8]; |
| 526 | 525 | bus->data_last=bus->xfer_count; |
| 527 | 526 | bus->bytes_left=0; |
| 528 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_DATAIN); |
| 527 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_DATAIN); |
| 529 | 528 | break; |
| 530 | 529 | |
| 531 | 530 | // Xebec S1410 |
| r15370 | r15371 | |
| 537 | 536 | bus->xfer_count=0; |
| 538 | 537 | bus->data_last=bus->xfer_count; |
| 539 | 538 | bus->bytes_left=0; |
| 540 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS); |
| 539 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 541 | 540 | break; |
| 542 | 541 | |
| 543 | 542 | // Commodore D9060/9090 |
| r15370 | r15371 | |
| 547 | 546 | bus->xfer_count=0; |
| 548 | 547 | bus->data_last=bus->xfer_count; |
| 549 | 548 | bus->bytes_left=0; |
| 550 | | SCSISetPhase(bus->devices[bus->last_id],SCSI_PHASE_STATUS); |
| 549 | bus->devices[bus->last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 551 | 550 | break; |
| 552 | 551 | } |
| 553 | 552 | |
| r15370 | r15371 | |
| 556 | 555 | // to the disk driver |
| 557 | 556 | if(!command_local) |
| 558 | 557 | { |
| 559 | | SCSISetCommand(bus->devices[bus->last_id], bus->command, bus->cmd_idx); |
| 560 | | SCSIExecCommand(bus->devices[bus->last_id], &bus->xfer_count); |
| 558 | bus->devices[bus->last_id]->SetCommand(bus->command, bus->cmd_idx); |
| 559 | bus->devices[bus->last_id]->ExecCommand(&bus->xfer_count); |
| 561 | 560 | bus->bytes_left=bus->xfer_count; |
| 562 | 561 | bus->data_last=bus->xfer_count; |
| 563 | 562 | bus->data_idx=0; |
| 564 | 563 | } |
| 565 | 564 | |
| 566 | | SCSIGetPhase(bus->devices[bus->last_id], &newphase); |
| 565 | bus->devices[bus->last_id]->GetPhase(&newphase); |
| 567 | 566 | |
| 568 | 567 | scsi_change_phase(device,newphase); |
| 569 | 568 | |
| r15370 | r15371 | |
| 655 | 654 | { |
| 656 | 655 | // Check to see if device had image file mounted, if not, do not set busy, |
| 657 | 656 | // and stay busfree. |
| 658 | | SCSIGetDevice(bus->devices[bus->last_id],&hdfile); |
| 657 | bus->devices[bus->last_id]->GetDevice(&hdfile); |
| 659 | 658 | if(hdfile!=(void *)NULL) |
| 660 | 659 | { |
| 661 | 660 | if(state==0) |
| r15370 | r15371 | |
| 945 | 944 | const SCSIConfigTable *scsidevs = bus->interface->scsidevs; |
| 946 | 945 | int devno; |
| 947 | 946 | |
| 948 | | if(!bus->initialised) |
| 947 | // try to open the devices |
| 948 | for (devno = 0; devno < scsidevs->devs_present; devno++) |
| 949 | 949 | { |
| 950 | | // try to open the devices |
| 951 | | for (devno = 0; devno < scsidevs->devs_present; devno++) |
| 952 | | { |
| 953 | | LOG(1,"SCSIBUS:init devno=%d \n",devno); |
| 954 | | SCSIAllocInstance( device->machine(), scsidevs->devices[devno].scsiClass, &bus->devices[scsidevs->devices[devno].scsiID], scsidevs->devices[devno].diskregion ); |
| 955 | | } |
| 956 | | |
| 957 | | bus->initialised=1; |
| 950 | LOG(1,"SCSIBUS:init devno=%d \n",devno); |
| 951 | bus->devices[scsidevs->devices[devno].scsiID] = device->machine().device<scsidev_device>( scsidevs->devices[devno].tag ); |
| 958 | 952 | } |
| 959 | 953 | |
| 960 | 954 | bus->sectorbytes = sectorbytes; |
| r15370 | r15371 | |
| 977 | 971 | bus->out_req_func.resolve(bus->interface->out_req_func, *device); |
| 978 | 972 | bus->out_rst_func.resolve(bus->interface->out_rst_func, *device); |
| 979 | 973 | |
| 980 | | // Flag not initialised |
| 981 | | bus->initialised=0; |
| 982 | | |
| 983 | 974 | // All lines start high - inactive |
| 984 | 975 | bus->linestate=0xFF; |
| 985 | 976 | |
| r15370 | r15371 | |
| 996 | 987 | |
| 997 | 988 | static DEVICE_STOP( scsibus ) |
| 998 | 989 | { |
| 999 | | scsibus_t *bus = get_token(device); |
| 1000 | | int devno; |
| 1001 | | |
| 1002 | | for (devno = 0; devno < bus->interface->scsidevs->devs_present; devno++) |
| 1003 | | { |
| 1004 | | SCSIDeleteInstance( bus->devices[devno] ); |
| 1005 | | } |
| 1006 | 990 | } |
| 1007 | 991 | |
| 1008 | 992 | static DEVICE_RESET( scsibus ) |
src/mess/drivers/mac.c
| r15370 | r15371 | |
| 48 | 48 | #include "imagedev/harddriv.h" |
| 49 | 49 | #include "formats/ap_dsk35.h" |
| 50 | 50 | #include "machine/ram.h" |
| 51 | #include "machine/scsihd.h" |
| 51 | 52 | #include "imagedev/chd_cd.h" |
| 52 | 53 | #include "sound/asc.h" |
| 53 | 54 | #include "sound/awacs.h" |
| r15370 | r15371 | |
| 817 | 818 | { |
| 818 | 819 | 2, /* 2 SCSI devices */ |
| 819 | 820 | { |
| 820 | | { SCSI_ID_6, "harddisk1", SCSI_DEVICE_HARDDISK }, /* SCSI ID 6, using disk1, and it's a harddisk */ |
| 821 | | { SCSI_ID_5, "harddisk2", SCSI_DEVICE_HARDDISK } /* SCSI ID 5, using disk2, and it's a harddisk */ |
| 821 | { SCSI_ID_6, "harddisk1" }, /* SCSI ID 6, using harddisk1 */ |
| 822 | { SCSI_ID_5, "harddisk2" } /* SCSI ID 5, using harddisk2 */ |
| 822 | 823 | } |
| 823 | 824 | }; |
| 824 | 825 | |
| r15370 | r15371 | |
| 878 | 879 | NULL |
| 879 | 880 | }; |
| 880 | 881 | |
| 881 | | static const struct harddisk_interface mac_harddisk_config = |
| 882 | | { |
| 883 | | NULL, |
| 884 | | NULL, |
| 885 | | "mac_hdd", |
| 886 | | NULL |
| 887 | | }; |
| 888 | | |
| 889 | 882 | static const cuda_interface mac_cuda_interface = |
| 890 | 883 | { |
| 891 | 884 | DEVCB_DRIVER_LINE_MEMBER(mac_state, cuda_reset_w) |
| r15370 | r15371 | |
| 948 | 941 | |
| 949 | 942 | MCFG_NCR5380_ADD("ncr5380", C7M, macplus_5380intf) |
| 950 | 943 | |
| 951 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 952 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 944 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 945 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 953 | 946 | |
| 954 | 947 | MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_MODIFY(mac_floppy_interface) |
| 955 | 948 | |
| r15370 | r15371 | |
| 1013 | 1006 | MCFG_SCC8530_ADD("scc", C7M, line_cb_t(FUNC(mac_state::set_scc_interrupt), static_cast<mac_state *>(owner))) |
| 1014 | 1007 | MCFG_VIA6522_ADD("via6522_0", 783360, mac_via6522_intf) |
| 1015 | 1008 | |
| 1016 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1017 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1009 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1010 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1018 | 1011 | |
| 1019 | 1012 | /* internal ram */ |
| 1020 | 1013 | MCFG_RAM_ADD(RAM_TAG) |
| r15370 | r15371 | |
| 1061 | 1054 | MCFG_VIA6522_ADD("via6522_0", C7M/10, mac_via6522_adb_intf) |
| 1062 | 1055 | MCFG_VIA6522_ADD("via6522_1", C7M/10, mac_via6522_2_intf) |
| 1063 | 1056 | |
| 1064 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1065 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1057 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1058 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1066 | 1059 | |
| 1067 | 1060 | /* internal ram */ |
| 1068 | 1061 | MCFG_RAM_ADD(RAM_TAG) |
| r15370 | r15371 | |
| 1112 | 1105 | |
| 1113 | 1106 | MCFG_VIA6522_ADD("via6522_0", C7M/10, mac_via6522_adb_intf) |
| 1114 | 1107 | |
| 1115 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1116 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1108 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1109 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1117 | 1110 | |
| 1118 | 1111 | /* internal ram */ |
| 1119 | 1112 | MCFG_RAM_ADD(RAM_TAG) |
| r15370 | r15371 | |
| 1311 | 1304 | MCFG_VIA6522_ADD("via6522_0", 783360, mac_via6522_adb_intf) |
| 1312 | 1305 | MCFG_VIA6522_ADD("via6522_1", 783360, mac_via6522_2_intf) |
| 1313 | 1306 | |
| 1314 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1315 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1307 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1308 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1316 | 1309 | |
| 1317 | 1310 | /* internal ram */ |
| 1318 | 1311 | MCFG_RAM_ADD(RAM_TAG) |
| r15370 | r15371 | |
| 1362 | 1355 | MCFG_VIA6522_ADD("via6522_0", 783360, mac_via6522_adb_intf) |
| 1363 | 1356 | MCFG_VIA6522_ADD("via6522_1", 783360, mac_via6522_2_intf) |
| 1364 | 1357 | |
| 1365 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1366 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1358 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1359 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1367 | 1360 | |
| 1368 | 1361 | /* internal ram */ |
| 1369 | 1362 | MCFG_RAM_ADD(RAM_TAG) |
| r15370 | r15371 | |
| 1433 | 1426 | MCFG_VIA6522_ADD("via6522_0", 783360, mac_via6522_adb_intf) |
| 1434 | 1427 | MCFG_VIA6522_ADD("via6522_1", 783360, mac_via6522_2_intf) |
| 1435 | 1428 | |
| 1436 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1437 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1429 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1430 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1438 | 1431 | |
| 1439 | 1432 | /* internal ram */ |
| 1440 | 1433 | MCFG_RAM_ADD(RAM_TAG) |
| r15370 | r15371 | |
| 1604 | 1597 | MCFG_VIA6522_ADD("via6522_0", 783360, mac_via6522_adb_intf) |
| 1605 | 1598 | MCFG_VIA6522_ADD("via6522_1", 783360, mac_via6522_2_intf) |
| 1606 | 1599 | |
| 1607 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1608 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1600 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1601 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1609 | 1602 | |
| 1610 | 1603 | /* internal ram */ |
| 1611 | 1604 | MCFG_RAM_ADD(RAM_TAG) |
| r15370 | r15371 | |
| 1656 | 1649 | |
| 1657 | 1650 | MCFG_NCR539X_ADD(MAC_539X_1_TAG, C7M, mac_539x_intf) |
| 1658 | 1651 | |
| 1659 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk1", mac_harddisk_config ) |
| 1660 | | MCFG_HARDDISK_CONFIG_ADD( "harddisk2", mac_harddisk_config ) |
| 1652 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 1653 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 1661 | 1654 | |
| 1662 | 1655 | /* internal ram */ |
| 1663 | 1656 | MCFG_RAM_ADD(RAM_TAG) |
src/mess/drivers/x68k.c
| r15370 | r15371 | |
| 140 | 140 | #include "machine/nvram.h" |
| 141 | 141 | #include "machine/x68kexp.h" |
| 142 | 142 | #include "machine/x68k_neptunex.h" |
| 143 | #include "machine/scsihd.h" |
| 143 | 144 | #include "x68000.lh" |
| 144 | 145 | |
| 145 | 146 | |
| r15370 | r15371 | |
| 2532 | 2533 | { |
| 2533 | 2534 | 7, /* 7 SCSI devices */ |
| 2534 | 2535 | { |
| 2535 | | { SCSI_ID_0, "harddisk0", SCSI_DEVICE_HARDDISK }, |
| 2536 | | { SCSI_ID_1, "harddisk1", SCSI_DEVICE_HARDDISK }, |
| 2537 | | { SCSI_ID_2, "harddisk2", SCSI_DEVICE_HARDDISK }, |
| 2538 | | { SCSI_ID_3, "harddisk3", SCSI_DEVICE_HARDDISK }, |
| 2539 | | { SCSI_ID_4, "harddisk4", SCSI_DEVICE_HARDDISK }, |
| 2540 | | { SCSI_ID_5, "harddisk5", SCSI_DEVICE_HARDDISK }, |
| 2541 | | { SCSI_ID_6, "harddisk6", SCSI_DEVICE_HARDDISK }, |
| 2536 | { SCSI_ID_0, "harddisk0" }, |
| 2537 | { SCSI_ID_1, "harddisk1" }, |
| 2538 | { SCSI_ID_2, "harddisk2" }, |
| 2539 | { SCSI_ID_3, "harddisk3" }, |
| 2540 | { SCSI_ID_4, "harddisk4" }, |
| 2541 | { SCSI_ID_5, "harddisk5" }, |
| 2542 | { SCSI_ID_6, "harddisk6" }, |
| 2542 | 2543 | } |
| 2543 | 2544 | }; |
| 2544 | 2545 | |
| r15370 | r15371 | |
| 2835 | 2836 | MCFG_CPU_PROGRAM_MAP(x68kxvi_map) |
| 2836 | 2837 | |
| 2837 | 2838 | MCFG_MB89352A_ADD("mb89352_int",x68k_scsi_intf) |
| 2838 | | MCFG_HARDDISK_ADD("harddisk0") |
| 2839 | | MCFG_HARDDISK_ADD("harddisk1") |
| 2840 | | MCFG_HARDDISK_ADD("harddisk2") |
| 2841 | | MCFG_HARDDISK_ADD("harddisk3") |
| 2842 | | MCFG_HARDDISK_ADD("harddisk4") |
| 2843 | | MCFG_HARDDISK_ADD("harddisk5") |
| 2844 | | MCFG_HARDDISK_ADD("harddisk6") |
| 2839 | MCFG_DEVICE_ADD("harddisk0", SCSIHD, 0) |
| 2840 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 2841 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 2842 | MCFG_DEVICE_ADD("harddisk3", SCSIHD, 0) |
| 2843 | MCFG_DEVICE_ADD("harddisk4", SCSIHD, 0) |
| 2844 | MCFG_DEVICE_ADD("harddisk5", SCSIHD, 0) |
| 2845 | MCFG_DEVICE_ADD("harddisk6", SCSIHD, 0) |
| 2845 | 2846 | MACHINE_CONFIG_END |
| 2846 | 2847 | |
| 2847 | 2848 | static MACHINE_CONFIG_START( x68kxvi, x68k_state ) |
| r15370 | r15371 | |
| 2855 | 2856 | MCFG_CPU_PROGRAM_MAP(x68kxvi_map) |
| 2856 | 2857 | |
| 2857 | 2858 | MCFG_MB89352A_ADD("mb89352_int",x68k_scsi_intf) |
| 2858 | | MCFG_HARDDISK_ADD("harddisk0") |
| 2859 | | MCFG_HARDDISK_ADD("harddisk1") |
| 2860 | | MCFG_HARDDISK_ADD("harddisk2") |
| 2861 | | MCFG_HARDDISK_ADD("harddisk3") |
| 2862 | | MCFG_HARDDISK_ADD("harddisk4") |
| 2863 | | MCFG_HARDDISK_ADD("harddisk5") |
| 2864 | | MCFG_HARDDISK_ADD("harddisk6") |
| 2859 | MCFG_DEVICE_ADD("harddisk0", SCSIHD, 0) |
| 2860 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 2861 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 2862 | MCFG_DEVICE_ADD("harddisk3", SCSIHD, 0) |
| 2863 | MCFG_DEVICE_ADD("harddisk4", SCSIHD, 0) |
| 2864 | MCFG_DEVICE_ADD("harddisk5", SCSIHD, 0) |
| 2865 | MCFG_DEVICE_ADD("harddisk6", SCSIHD, 0) |
| 2865 | 2866 | MACHINE_CONFIG_END |
| 2866 | 2867 | |
| 2867 | 2868 | static MACHINE_CONFIG_START( x68030, x68k_state ) |
| r15370 | r15371 | |
| 2876 | 2877 | MCFG_NVRAM_ADD_0FILL("nvram32") |
| 2877 | 2878 | |
| 2878 | 2879 | MCFG_MB89352A_ADD("mb89352_int",x68k_scsi_intf) |
| 2879 | | MCFG_HARDDISK_ADD("harddisk0") |
| 2880 | | MCFG_HARDDISK_ADD("harddisk1") |
| 2881 | | MCFG_HARDDISK_ADD("harddisk2") |
| 2882 | | MCFG_HARDDISK_ADD("harddisk3") |
| 2883 | | MCFG_HARDDISK_ADD("harddisk4") |
| 2884 | | MCFG_HARDDISK_ADD("harddisk5") |
| 2885 | | MCFG_HARDDISK_ADD("harddisk6") |
| 2880 | MCFG_DEVICE_ADD("harddisk0", SCSIHD, 0) |
| 2881 | MCFG_DEVICE_ADD("harddisk1", SCSIHD, 0) |
| 2882 | MCFG_DEVICE_ADD("harddisk2", SCSIHD, 0) |
| 2883 | MCFG_DEVICE_ADD("harddisk3", SCSIHD, 0) |
| 2884 | MCFG_DEVICE_ADD("harddisk4", SCSIHD, 0) |
| 2885 | MCFG_DEVICE_ADD("harddisk5", SCSIHD, 0) |
| 2886 | MCFG_DEVICE_ADD("harddisk6", SCSIHD, 0) |
| 2886 | 2887 | MACHINE_CONFIG_END |
| 2887 | 2888 | |
| 2888 | 2889 | ROM_START( x68000 ) |