trunk/src/emu/machine/scsibus.c
| r18131 | r18132 | |
| 64 | 64 | { |
| 65 | 65 | data_last = (bytes_left >= sectorbytes) ? sectorbytes : bytes_left; |
| 66 | 66 | |
| 67 | | LOG(2,"SCSIBUS:scsibus_read_data bytes_left=%04X, data_last=%04X, xfer_count=%04X\n",bytes_left,data_last,xfer_count); |
| 67 | LOG(2,"SCSIBUS:scsibus_read_data bytes_left=%04X, data_last=%04X\n",bytes_left,data_last); |
| 68 | 68 | |
| 69 | 69 | if (data_last > 0) |
| 70 | 70 | { |
| 71 | 71 | devices[last_id]->ReadData(buffer, data_last); |
| 72 | 72 | bytes_left-=data_last; |
| 73 | | data_idx=0; |
| 74 | 73 | } |
| 74 | |
| 75 | data_idx=0; |
| 75 | 76 | } |
| 76 | 77 | |
| 77 | 78 | void scsibus_device::scsibus_write_data() |
| 78 | 79 | { |
| 79 | | if(bytes_left >= sectorbytes) |
| 80 | if (data_last > 0) |
| 80 | 81 | { |
| 81 | | devices[last_id]->WriteData(buffer, sectorbytes); |
| 82 | | |
| 83 | | bytes_left-=sectorbytes; |
| 84 | | data_idx=0; |
| 82 | devices[last_id]->WriteData(buffer, data_last); |
| 83 | bytes_left-=data_last; |
| 85 | 84 | } |
| 85 | |
| 86 | data_idx=0; |
| 86 | 87 | } |
| 87 | 88 | |
| 88 | 89 | /* SCSI Bus read/write */ |
| r18131 | r18132 | |
| 94 | 95 | switch (phase) |
| 95 | 96 | { |
| 96 | 97 | case SCSI_PHASE_DATAIN: |
| 97 | | result=buffer[data_idx++]; |
| 98 | | |
| 99 | | // check to see if we have reached the end of the block buffer |
| 100 | | // and that there is more data to read from the scsi disk |
| 101 | | if((data_idx==sectorbytes) && (bytes_left>0) && IS_READ_COMMAND()) |
| 102 | | { |
| 103 | | scsibus_read_data(); |
| 104 | | } |
| 98 | result=buffer[data_idx]; |
| 105 | 99 | break; |
| 106 | 100 | |
| 107 | 101 | case SCSI_PHASE_STATUS: |
| r18131 | r18132 | |
| 134 | 128 | break; |
| 135 | 129 | |
| 136 | 130 | case SCSI_PHASE_COMMAND: |
| 137 | | command[cmd_idx++]=data; |
| 131 | command[cmd_idx]=data; |
| 138 | 132 | break; |
| 139 | 133 | |
| 140 | 134 | case SCSI_PHASE_DATAOUT: |
| 141 | 135 | |
| 142 | | //LOG(1,"SCSIBUS:xfer_count=%02X, bytes_left=%02X data_idx=%02X\n",xfer_count,bytes_left,data_idx); |
| 136 | //LOG(1,"SCSIBUS:bytes_left=%02X data_idx=%02X\n",bytes_left,data_idx); |
| 143 | 137 | |
| 144 | 138 | if(IS_COMMAND(SCSI_CMD_FORMAT_UNIT)) |
| 145 | 139 | { |
| 146 | 140 | // Only store the first 4 bytes of the bad block list (the header) |
| 147 | 141 | //if(data_idx<4) |
| 148 | | buffer[data_idx++]=data; |
| 142 | buffer[data_idx]=data; |
| 149 | 143 | dump_data_bytes(4); |
| 150 | 144 | //else |
| 151 | 145 | // data_idx++; |
| 152 | 146 | |
| 153 | 147 | // If we have the first byte, then cancel the dataout timout |
| 154 | | if(data_idx==1) |
| 148 | if(data_idx==0) |
| 155 | 149 | dataout_timer->adjust(attotime::never); |
| 156 | 150 | |
| 157 | 151 | // When we have the first 3 bytes, calculate how many more are in the |
| 158 | 152 | // bad block list. |
| 159 | | if(data_idx==3) |
| 153 | if(data_idx==2) |
| 160 | 154 | { |
| 161 | | xfer_count+=((buffer[2]<<8)+buffer[3]); |
| 162 | | data_last=xfer_count; |
| 163 | | LOG(1,"format_unit reading an extra %d bytes\n",xfer_count-4); |
| 155 | bytes_left+=((buffer[2]<<8)+buffer[3]); |
| 156 | LOG(1,"format_unit reading an extra %d bytes\n",bytes_left-4); |
| 164 | 157 | dump_data_bytes(4); |
| 165 | 158 | } |
| 166 | 159 | } |
| 167 | 160 | else |
| 168 | 161 | { |
| 169 | | buffer[data_idx++]=data; |
| 162 | buffer[data_idx]=data; |
| 170 | 163 | } |
| 171 | | |
| 172 | | // If the data buffer is full, and we are writing blocks flush it to the SCSI disk |
| 173 | | if((data_idx == sectorbytes) && IS_WRITE_COMMAND()) |
| 174 | | scsibus_write_data(); |
| 175 | 164 | break; |
| 176 | 165 | } |
| 177 | 166 | } |
| r18131 | r18132 | |
| 277 | 266 | else |
| 278 | 267 | devices[last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 279 | 268 | |
| 280 | | xfer_count=4; |
| 281 | | data_last=xfer_count; |
| 282 | | bytes_left=0; |
| 269 | bytes_left=4; |
| 283 | 270 | dataout_timer->adjust(attotime::from_seconds(FORMAT_UNIT_TIMEOUT)); |
| 284 | 271 | break; |
| 285 | 272 | |
| 286 | 273 | case SCSI_CMD_SEARCH_DATA_EQUAL: |
| 287 | 274 | LOG(1,"SCSIBUS: Search_data_equaln"); |
| 288 | 275 | command_local=1; |
| 289 | | xfer_count=0; |
| 290 | | data_last=xfer_count; |
| 291 | 276 | bytes_left=0; |
| 292 | 277 | devices[last_id]->SetPhase(SCSI_PHASE_STATUS); |
| 293 | 278 | break; |
| r18131 | r18132 | |
| 301 | 286 | buffer[3] = 0x00; // defect list len msb |
| 302 | 287 | buffer[4] = 0x00; // defect list len lsb |
| 303 | 288 | |
| 304 | | xfer_count=4; |
| 305 | | data_last=xfer_count; |
| 306 | | bytes_left=0; |
| 289 | bytes_left=4; |
| 307 | 290 | devices[last_id]->SetPhase(SCSI_PHASE_DATAIN); |
| 308 | 291 | break; |
| 309 | 292 | |
| r18131 | r18132 | |
| 311 | 294 | case SCSI_CMD_BUFFER_WRITE: |
| 312 | 295 | LOG(1,"SCSIBUS: write_buffer\n"); |
| 313 | 296 | command_local=1; |
| 314 | | xfer_count=(command[7]<<8)+command[8]; |
| 315 | | data_last=xfer_count; |
| 316 | | bytes_left=0; |
| 297 | bytes_left=(command[7]<<8)+command[8]; |
| 317 | 298 | devices[last_id]->SetPhase(SCSI_PHASE_DATAOUT); |
| 318 | 299 | break; |
| 319 | 300 | |
| r18131 | r18132 | |
| 321 | 302 | case SCSI_CMD_BUFFER_READ: |
| 322 | 303 | LOG(1,"SCSIBUS: read_buffer\n"); |
| 323 | 304 | command_local=1; |
| 324 | | xfer_count=(command[7]<<8)+command[8]; |
| 325 | | data_last=xfer_count; |
| 326 | | bytes_left=0; |
| 305 | bytes_left=(command[7]<<8)+command[8]; |
| 327 | 306 | devices[last_id]->SetPhase(SCSI_PHASE_DATAIN); |
| 328 | 307 | break; |
| 329 | 308 | } |
| r18131 | r18132 | |
| 334 | 313 | if(!command_local) |
| 335 | 314 | { |
| 336 | 315 | devices[last_id]->SetCommand(command, cmd_idx); |
| 337 | | devices[last_id]->ExecCommand(&xfer_count); |
| 338 | | bytes_left=xfer_count; |
| 339 | | data_last=xfer_count; |
| 316 | devices[last_id]->ExecCommand(&bytes_left); |
| 340 | 317 | data_idx=0; |
| 341 | 318 | } |
| 342 | 319 | |
| r18131 | r18132 | |
| 344 | 321 | |
| 345 | 322 | scsi_change_phase(newphase); |
| 346 | 323 | |
| 347 | | LOG(1,"SCSIBUS:xfer_count=%02X, bytes_left=%02X data_idx=%02X\n",xfer_count,bytes_left,data_idx); |
| 324 | LOG(1,"SCSIBUS:bytes_left=%02X data_idx=%02X\n",bytes_left,data_idx); |
| 348 | 325 | |
| 349 | 326 | // This is correct as we need to read from disk for commands other than just read data |
| 350 | 327 | if ((phase == SCSI_PHASE_DATAIN) && (!command_local)) |
| 351 | 328 | scsibus_read_data(); |
| 352 | 329 | } |
| 353 | 330 | |
| 354 | | int scsibus_device::datain_done() |
| 355 | | { |
| 356 | | int result=0; |
| 357 | | |
| 358 | | // Read data commands |
| 359 | | if(IS_READ_COMMAND() && (data_idx == data_last) && (bytes_left == 0)) |
| 360 | | result=1; |
| 361 | | else if (data_idx==data_last) |
| 362 | | result=1; |
| 363 | | |
| 364 | | return result; |
| 365 | | } |
| 366 | | |
| 367 | | int scsibus_device::dataout_done() |
| 368 | | { |
| 369 | | int result=0; |
| 370 | | |
| 371 | | // Write data commands |
| 372 | | if(IS_WRITE_COMMAND() && (data_idx == 0) && (bytes_left == 0)) |
| 373 | | result=1; |
| 374 | | else if (data_idx==data_last) |
| 375 | | result=1; |
| 376 | | |
| 377 | | return result; |
| 378 | | } |
| 379 | | |
| 380 | 331 | void scsibus_device::check_process_dataout() |
| 381 | 332 | { |
| 382 | 333 | int capacity=0; |
| r18131 | r18132 | |
| 438 | 389 | { |
| 439 | 390 | if(state) |
| 440 | 391 | { |
| 392 | cmd_idx++; |
| 393 | |
| 441 | 394 | // If the command is ready go and execute it |
| 442 | 395 | if(cmd_idx==get_scsi_cmd_len(command[0])) |
| 443 | 396 | { |
| r18131 | r18132 | |
| 456 | 409 | { |
| 457 | 410 | if(state) |
| 458 | 411 | { |
| 459 | | if(datain_done()) |
| 412 | data_idx++; |
| 413 | |
| 414 | // check to see if we have reached the end of the block buffer |
| 415 | // and that there is more data to read from the scsi disk |
| 416 | if(data_idx==sectorbytes) |
| 417 | { |
| 418 | scsibus_read_data(); |
| 419 | } |
| 420 | |
| 421 | if(data_idx == data_last && bytes_left == 0) |
| 460 | 422 | scsi_change_phase(SCSI_PHASE_STATUS); |
| 461 | 423 | else |
| 462 | 424 | scsi_out_line_change(SCSI_LINE_REQ,0); |
| r18131 | r18132 | |
| 471 | 433 | { |
| 472 | 434 | if(state) |
| 473 | 435 | { |
| 474 | | if(dataout_done()) |
| 436 | data_idx++; |
| 437 | |
| 438 | // If the data buffer is full flush it to the SCSI disk |
| 439 | |
| 440 | data_last = (bytes_left >= sectorbytes) ? sectorbytes : bytes_left; |
| 441 | |
| 442 | if(data_idx == data_last) |
| 443 | scsibus_write_data(); |
| 444 | |
| 445 | if(data_idx == 0 && bytes_left == 0) |
| 475 | 446 | { |
| 476 | 447 | check_process_dataout(); |
| 477 | 448 | scsi_change_phase(SCSI_PHASE_STATUS); |