src/mess/machine/mb89352.c
| r0 | r10144 | |
| 1 | /* |
| 2 | * Fujitsu MB89352A SCSI Protocol Controller |
| 3 | * |
| 4 | * Should be compatible with the MB87030/31, and MB89351 |
| 5 | * |
| 6 | * Used on the Sharp X68000 Super, X68000 XVI and X68030 (internal), and on SCSI expansion cards for any X680x0 (external) |
| 7 | * |
| 8 | * Registers (based on datasheet): |
| 9 | * |
| 10 | * 0: BDID (Bus Device ID) |
| 11 | * bit = device ID (ie: bit 2 = device 2) (read) |
| 12 | * bit 0 = ID1, bit 1 = ID2, bit 2 = ID4 (write) |
| 13 | * |
| 14 | * 1: SCTL (SPC Control) |
| 15 | * (all read/write) |
| 16 | * bit 0 = INT Enable |
| 17 | * bit 1 = Reselect Enable |
| 18 | * bit 2 = Select Enable |
| 19 | * bit 3 = Parity Enable |
| 20 | * bit 4 = Arbitration Phase Enable |
| 21 | * bit 5 = Diag Mode |
| 22 | * bit 6 = Control Reset |
| 23 | * bit 7 = Reset and Disable |
| 24 | * |
| 25 | * 2: SCMD (Command) |
| 26 | * bits 0-2 = Transfer Modifier (read) |
| 27 | * bit 0 = Term Mode (write) |
| 28 | * bit 2 = PRG Xfer (write) |
| 29 | * bit 3 = Intercept Xfer (read/write) |
| 30 | * bit 4 = RST Out (read/write) |
| 31 | * bits 5-7 = Command code (read/write) (would have been nice if these codes were mentioned in the datasheet...) |
| 32 | * 000 = Bus release |
| 33 | * 001 = Selection |
| 34 | * 010 = Reset ATN |
| 35 | * 011 = Set ATN |
| 36 | * 100 = Transfer |
| 37 | * 101 = Transfer Pause |
| 38 | * 110 = Reset ACK/REQ |
| 39 | * 111 = Set ACK/REQ |
| 40 | * |
| 41 | * 3: Unused |
| 42 | * |
| 43 | * 4: INTS (Interrupt Sense) |
| 44 | * on write, clear interrupt |
| 45 | * on read: |
| 46 | * bit 0 = Reset Condition |
| 47 | * bit 1 = SPC Hard Error |
| 48 | * bit 2 = Timeout |
| 49 | * bit 3 = Service Required |
| 50 | * bit 4 = Command Complete |
| 51 | * bit 5 = Disconnect |
| 52 | * bit 6 = Reselected |
| 53 | * bit 7 = Selected |
| 54 | * |
| 55 | * 5: PSNS (Phase Sense) (read-only) |
| 56 | * b7 b0 |
| 57 | * | REQ | ACK | ATN | SEL | BSY | MSG | C/D | I/O | |
| 58 | * SDGC (SPC Diag. Control) (write-only) |
| 59 | * bit 5 = Xfer Enable |
| 60 | * bit 4 = Unused |
| 61 | * all other bits are Diag. of the matching inputs above. |
| 62 | * |
| 63 | * 6: SSTS (SPC Status) (read-only) |
| 64 | * bit 0 = DREG Empty |
| 65 | * bit 1 = DREG Full |
| 66 | * bit 2 = TC=0 |
| 67 | * bit 3 = SCSI RST |
| 68 | * bit 4 = Xfer in progress |
| 69 | * bit 5 = SPC BSY |
| 70 | * bit 6 = Connected to Target |
| 71 | * bit 7 = Connected to Initiator |
| 72 | * |
| 73 | * 7: SERR (SCSI Error Status) (read-only) |
| 74 | * bit 1 = Short Transfer Period |
| 75 | * bit 3 = TC Parity Error |
| 76 | * bit 5 = Xfer Out (related to SDGC bit 5) |
| 77 | * bits 6,7 = Data error (10 = undefined, 00 = no error, 01 and 11 = parity error) |
| 78 | * |
| 79 | * 8: PCTL (Phase Control) |
| 80 | * (read/write) |
| 81 | * bits 0-2 = transfer phase ( | MSG | C/D | I/O | ) |
| 82 | * bits 7 = Bus Free interrupt enable |
| 83 | * other bits read 0 |
| 84 | * |
| 85 | * 9: MBC (Modified Byte Counter) |
| 86 | * (read-only) |
| 87 | * bits 0-3 = MBC bits 0-3 |
| 88 | * other bits read 0 |
| 89 | * |
| 90 | * A: DREG (Data Register) |
| 91 | * 8-bit FIFO |
| 92 | * |
| 93 | * B: TEMP (Temporary Register) |
| 94 | * on read, from SCSI |
| 95 | * on write, to SCSI |
| 96 | * |
| 97 | * C, D, E: TCH, TCM, TCL (Transfer Counter High, Mid, Low) |
| 98 | * 24-bit transfer counter |
| 99 | * |
| 100 | */ |
| 101 | |
| 102 | #include "emu.h" |
| 103 | #include "machine/devhelpr.h" |
| 104 | #include "mb89352.h" |
| 105 | |
| 106 | /* |
| 107 | * Device config |
| 108 | */ |
| 109 | |
| 110 | const device_type MB89352A = mb89352_device_config::static_alloc_device_config; |
| 111 | |
| 112 | GENERIC_DEVICE_CONFIG_SETUP(mb89352, "MB89352A") |
| 113 | |
| 114 | void mb89352_device_config::device_config_complete() |
| 115 | { |
| 116 | // copy static configuration if present |
| 117 | const mb89352_interface *intf = reinterpret_cast<const mb89352_interface *>(static_config()); |
| 118 | if (intf != NULL) |
| 119 | *static_cast<mb89352_interface *>(this) = *intf; |
| 120 | |
| 121 | // otherwise, initialize it to defaults |
| 122 | else |
| 123 | { |
| 124 | scsidevs = NULL; |
| 125 | memset(&irq_callback,0,sizeof(irq_callback)); |
| 126 | memset(&drq_callback,0,sizeof(drq_callback)); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Device |
| 132 | */ |
| 133 | |
| 134 | mb89352_device::mb89352_device(running_machine &machine, const mb89352_device_config &config) |
| 135 | : device_t(machine, config), |
| 136 | m_config(config) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | void mb89352_device::device_start() |
| 141 | { |
| 142 | int x; |
| 143 | |
| 144 | m_phase = SCSI_PHASE_BUS_FREE; |
| 145 | m_target = 0; |
| 146 | m_command_index = 0; |
| 147 | m_line_status = 0x00; |
| 148 | m_spc_status = 0x01; // presumably the data reg is empty to start with |
| 149 | m_error_status = 0x00; |
| 150 | if(m_transfer_count == 0) |
| 151 | m_spc_status |= SSTS_TC_ZERO; |
| 152 | m_ints = 0x00; |
| 153 | |
| 154 | devcb_resolve_write_line(&m_irq_func,&m_config.irq_callback,this); |
| 155 | devcb_resolve_write_line(&m_drq_func,&m_config.drq_callback,this); |
| 156 | |
| 157 | memset(m_SCSIdevices,0,sizeof(m_SCSIdevices)); |
| 158 | |
| 159 | // initialise SCSI devices, if any present |
| 160 | for(x=0;x<m_config.scsidevs->devs_present;x++) |
| 161 | { |
| 162 | SCSIAllocInstance(machine, m_config.scsidevs->devices[x].scsiClass, |
| 163 | &m_SCSIdevices[m_config.scsidevs->devices[x].scsiID], |
| 164 | m_config.scsidevs->devices[x].diskregion ); |
| 165 | } |
| 166 | |
| 167 | // allocate read timer |
| 168 | m_transfer_timer = device_timer_alloc(*this,TIMER_TRANSFER); |
| 169 | } |
| 170 | |
| 171 | void mb89352_device::device_reset() |
| 172 | { |
| 173 | m_phase = SCSI_PHASE_BUS_FREE; |
| 174 | m_target = 0; |
| 175 | m_command_index = 0; |
| 176 | m_line_status = 0x00; |
| 177 | m_error_status = 0x00; |
| 178 | m_transfer_count = 0; |
| 179 | m_spc_status = 0x05; // presumably the data reg is empty to start with |
| 180 | m_ints = 0x00; |
| 181 | |
| 182 | mb89352_rescan(); |
| 183 | } |
| 184 | |
| 185 | void mb89352_device::device_stop() |
| 186 | { |
| 187 | int x; |
| 188 | |
| 189 | // clean up the devices |
| 190 | for (x=0;x<m_config.scsidevs->devs_present;x++) |
| 191 | { |
| 192 | SCSIDeleteInstance( m_SCSIdevices[m_config.scsidevs->devices[x].scsiID] ); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // get the length of a SCSI command based on it's command byte type |
| 197 | int mb89352_device::get_scsi_cmd_len(UINT8 cbyte) |
| 198 | { |
| 199 | int group; |
| 200 | |
| 201 | group = (cbyte>>5) & 7; |
| 202 | |
| 203 | if (group == 0) return 6; |
| 204 | if (group == 1 || group == 2) return 10; |
| 205 | if (group == 5) return 12; |
| 206 | |
| 207 | fatalerror("MB89352: Unknown SCSI command group %d", group); |
| 208 | |
| 209 | return 6; |
| 210 | } |
| 211 | |
| 212 | void mb89352_device::mb89352_rescan() |
| 213 | { |
| 214 | int i; |
| 215 | |
| 216 | // try to open the devices |
| 217 | for (i = 0; i < m_config.scsidevs->devs_present; i++) |
| 218 | { |
| 219 | // if a device wasn't already allocated |
| 220 | // if (!m_SCSIdevices[m_config.scsidevs->devices[i].scsiID]) |
| 221 | { |
| 222 | SCSIDeleteInstance( m_SCSIdevices[m_config.scsidevs->devices[i].scsiID] ); |
| 223 | SCSIAllocInstance( machine, |
| 224 | m_config.scsidevs->devices[i].scsiClass, |
| 225 | &m_SCSIdevices[m_config.scsidevs->devices[i].scsiID], |
| 226 | m_config.scsidevs->devices[i].diskregion ); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | void mb89352_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 232 | { |
| 233 | switch(id) |
| 234 | { |
| 235 | case TIMER_TRANSFER: |
| 236 | // TODO: check interrupts are actually enabled |
| 237 | { |
| 238 | devcb_call_write_line(&m_drq_func,1); |
| 239 | } |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | void mb89352_device::set_phase(int phase) |
| 245 | { |
| 246 | m_phase = phase; |
| 247 | switch(phase) |
| 248 | { |
| 249 | case SCSI_PHASE_BUS_FREE: |
| 250 | m_line_status = 0; |
| 251 | break; |
| 252 | case SCSI_PHASE_COMMAND: |
| 253 | m_line_status |= MB89352_LINE_REQ; |
| 254 | m_line_status &= ~MB89352_LINE_ACK; |
| 255 | m_line_status &= ~MB89352_LINE_MSG; |
| 256 | m_line_status |= MB89352_LINE_CD; |
| 257 | m_line_status &= ~MB89352_LINE_IO; |
| 258 | break; |
| 259 | case SCSI_PHASE_STATUS: |
| 260 | // m_line_status |= MB89352_LINE_REQ; |
| 261 | // m_line_status &= ~MB89352_LINE_ACK; |
| 262 | m_line_status &= ~MB89352_LINE_MSG; |
| 263 | m_line_status |= MB89352_LINE_CD; |
| 264 | m_line_status |= MB89352_LINE_IO; |
| 265 | break; |
| 266 | case SCSI_PHASE_DATAIN: |
| 267 | // m_line_status |= MB89352_LINE_REQ; |
| 268 | // m_line_status &= ~MB89352_LINE_ACK; |
| 269 | m_line_status &= ~MB89352_LINE_MSG; |
| 270 | m_line_status &= ~MB89352_LINE_CD; |
| 271 | m_line_status |= MB89352_LINE_IO; |
| 272 | break; |
| 273 | case SCSI_PHASE_DATAOUT: |
| 274 | // m_line_status |= MB89352_LINE_REQ; |
| 275 | // m_line_status &= ~MB89352_LINE_ACK; |
| 276 | m_line_status &= ~MB89352_LINE_MSG; |
| 277 | m_line_status &= ~MB89352_LINE_CD; |
| 278 | m_line_status &= ~MB89352_LINE_IO; |
| 279 | break; |
| 280 | case SCSI_PHASE_MESSAGE_IN: |
| 281 | // m_line_status |= MB89352_LINE_REQ; |
| 282 | // m_line_status &= ~MB89352_LINE_ACK; |
| 283 | m_line_status |= MB89352_LINE_MSG; |
| 284 | m_line_status |= MB89352_LINE_CD; |
| 285 | m_line_status |= MB89352_LINE_IO; |
| 286 | break; |
| 287 | case SCSI_PHASE_MESSAGE_OUT: |
| 288 | // m_line_status |= MB89352_LINE_REQ; |
| 289 | // m_line_status &= ~MB89352_LINE_ACK; |
| 290 | m_line_status |= MB89352_LINE_MSG; |
| 291 | m_line_status |= MB89352_LINE_CD; |
| 292 | m_line_status &= ~MB89352_LINE_IO; |
| 293 | break; |
| 294 | } |
| 295 | logerror("MB89352: phase set to %i\n",m_phase); |
| 296 | } |
| 297 | |
| 298 | int mb89352_device::get_phase(void) |
| 299 | { |
| 300 | return m_phase; |
| 301 | } |
| 302 | |
| 303 | READ8_MEMBER( mb89352_device::mb89352_r ) |
| 304 | { |
| 305 | UINT8 ret; |
| 306 | switch(offset & 0x0f) |
| 307 | { |
| 308 | case 0x00: // BDID - Bus Device ID |
| 309 | return (1 << m_bdid); |
| 310 | case 0x01: // SCTL - SPC Control |
| 311 | ret = 0x00; |
| 312 | if(m_arbit_enable) |
| 313 | ret |= 0x10; |
| 314 | if(m_parity_enable) |
| 315 | ret |= 0x08; |
| 316 | if(m_sel_enable) |
| 317 | ret |= 0x04; |
| 318 | if(m_resel_enable) |
| 319 | ret |= 0x02; |
| 320 | if(m_int_enable) |
| 321 | ret |= 0x01; |
| 322 | return ret; |
| 323 | case 0x02: // SCMD - Command |
| 324 | return m_scmd; |
| 325 | case 0x03: // Unused |
| 326 | return 0xff; |
| 327 | case 0x04: // INTS - Interrupt Sense |
| 328 | return m_ints; |
| 329 | case 0x05: // PSNS - Phase Sense |
| 330 | return m_line_status; // active low -- but Human68k expects it to be zero? |
| 331 | case 0x06: // SSTS - SPC Status |
| 332 | return m_spc_status; |
| 333 | case 0x08: // PCTL - Phase Control |
| 334 | return ((m_busfree_int_enable) ? 0x80 : 0x00); |
| 335 | case 0x0a: // DREG - Data register (for data transfers) |
| 336 | if(m_spc_status | SSTS_XFER_IN_PROGRESS) |
| 337 | { |
| 338 | m_data = m_buffer[m_transfer_index % 512]; |
| 339 | m_transfer_index++; |
| 340 | m_transfer_count--; |
| 341 | if(m_transfer_count == 0) |
| 342 | { |
| 343 | // End of transfer |
| 344 | m_spc_status &= ~SSTS_XFER_IN_PROGRESS; |
| 345 | m_spc_status |= SSTS_DREG_EMPTY; |
| 346 | m_ints |= INTS_COMMAND_COMPLETE; |
| 347 | set_phase(SCSI_PHASE_STATUS); |
| 348 | } |
| 349 | } |
| 350 | return 0x00; |
| 351 | case 0x0b: // TEMP - Temporary |
| 352 | return m_temp; |
| 353 | case 0x0c: // TCH - Transfer Counter High |
| 354 | return (m_transfer_count & 0x00ff0000) >> 16; |
| 355 | case 0x0d: // TCM - Transfer Counter Mid |
| 356 | return (m_transfer_count & 0x0000ff00) >> 8; |
| 357 | case 0x0e: // TCL - Transfer Counter Low |
| 358 | return (m_transfer_count & 0x000000ff); |
| 359 | default: |
| 360 | logerror("mb89352: read from register %02x\n",offset & 0x0f); |
| 361 | } |
| 362 | return 0xff; |
| 363 | } |
| 364 | |
| 365 | WRITE8_MEMBER( mb89352_device::mb89352_w ) |
| 366 | { |
| 367 | device_image_interface* image; |
| 368 | |
| 369 | switch(offset & 0x0f) |
| 370 | { |
| 371 | case 0x00: // BDID - Bus Device ID |
| 372 | m_bdid = data; |
| 373 | m_spc_status &= ~SSTS_TARG_CONNECTED; |
| 374 | m_spc_status |= SSTS_INIT_CONNECTED; |
| 375 | logerror("mb89352: BDID set to %i\n",data); |
| 376 | break; |
| 377 | case 0x01: // SCTL - SPC Control |
| 378 | if(data & 0x80) // reset and disable |
| 379 | { |
| 380 | m_ints |= INTS_RESET; |
| 381 | device_reset(); |
| 382 | logerror("mb89352: SCTL: Reset and disable.\n"); |
| 383 | } |
| 384 | if(data & 0x10) |
| 385 | { |
| 386 | m_arbit_enable = 1; |
| 387 | logerror("mb89352: SCTL: Arbitration enabled.\n"); |
| 388 | } |
| 389 | else |
| 390 | m_arbit_enable = 0; |
| 391 | if(data & 0x08) |
| 392 | { |
| 393 | m_parity_enable = 1; |
| 394 | logerror("mb89352: SCTL: Parity enabled.\n"); |
| 395 | } |
| 396 | else |
| 397 | m_parity_enable = 0; |
| 398 | if(data & 0x04) |
| 399 | { |
| 400 | m_resel_enable = 1; |
| 401 | logerror("mb89352: SCTL: Reselection enabled.\n"); |
| 402 | } |
| 403 | else |
| 404 | m_resel_enable = 0; |
| 405 | if(data & 0x02) |
| 406 | { |
| 407 | m_sel_enable = 1; |
| 408 | logerror("mb89352: SCTL: Selection enabled.\n"); |
| 409 | } |
| 410 | else |
| 411 | m_sel_enable = 0; |
| 412 | if(data & 0x01) |
| 413 | { |
| 414 | m_int_enable = 1; |
| 415 | logerror("mb89352: SCTL: Interrupts enabled.\n"); |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | m_int_enable = 0; |
| 420 | logerror("mb89352: SCTL: Interrupts disabled.\n"); |
| 421 | } |
| 422 | break; |
| 423 | case 0x02: // SCMD - Command |
| 424 | m_scmd = data; |
| 425 | switch((data & 0xe0) >> 5) |
| 426 | { |
| 427 | case 0x00: |
| 428 | // Bus Free |
| 429 | m_line_status = 0; |
| 430 | m_spc_status &= ~SSTS_TARG_CONNECTED; |
| 431 | m_spc_status &= ~SSTS_INIT_CONNECTED; |
| 432 | logerror("mb89352: SCMD: Bus free\n"); |
| 433 | break; |
| 434 | case 0x01: |
| 435 | // Selection |
| 436 | m_target = m_temp; |
| 437 | m_target &= ~(1 << m_bdid); // mask off the bit relating to initiator |
| 438 | switch(m_target) |
| 439 | { |
| 440 | case 0x01: m_target = 0; break; |
| 441 | case 0x02: m_target = 1; break; |
| 442 | case 0x04: m_target = 2; break; |
| 443 | case 0x08: m_target = 3; break; |
| 444 | case 0x10: m_target = 4; break; |
| 445 | case 0x20: m_target = 5; break; |
| 446 | case 0x40: m_target = 6; break; |
| 447 | case 0x80: m_target = 7; break; |
| 448 | } |
| 449 | if(m_sel_enable != 0) |
| 450 | { |
| 451 | m_ints |= INTS_SELECTION; |
| 452 | } |
| 453 | set_phase(SCSI_PHASE_COMMAND); // straight to command phase, may need a delay betweem selection and command phases |
| 454 | m_line_status |= MB89352_LINE_SEL; |
| 455 | m_line_status |= MB89352_LINE_BSY; |
| 456 | m_spc_status &= ~SSTS_TARG_CONNECTED; |
| 457 | m_spc_status |= SSTS_INIT_CONNECTED; |
| 458 | m_spc_status |= SSTS_SPC_BSY; |
| 459 | m_ints |= INTS_COMMAND_COMPLETE; |
| 460 | logerror("mb89352: SCMD: Selection (SCSI ID%i)\n",m_target); |
| 461 | break; |
| 462 | case 0x04: // Transfer |
| 463 | m_transfer_index = 0; |
| 464 | m_spc_status |= SSTS_XFER_IN_PROGRESS; |
| 465 | m_spc_status &= ~SSTS_DREG_EMPTY; // DREG is no longer empty, but apparently it's not full either. |
| 466 | SCSIReadData(m_SCSIdevices[m_target],m_buffer,512); |
| 467 | logerror("mb89352: SCMD: Start Transfer\n"); |
| 468 | break; |
| 469 | case 0x05: // Transfer pause |
| 470 | logerror("mb89352: SCMD: Pause Transfer\n"); |
| 471 | break; |
| 472 | case 0x06: // reset REQ/ACK |
| 473 | m_line_status &= ~MB89352_LINE_ACK; |
| 474 | if(m_phase != SCSI_PHASE_BUS_FREE) |
| 475 | { |
| 476 | m_line_status |= MB89352_LINE_REQ; |
| 477 | } |
| 478 | else |
| 479 | { |
| 480 | m_spc_status &= ~SSTS_INIT_CONNECTED; |
| 481 | m_spc_status &= ~SSTS_TARG_CONNECTED; |
| 482 | m_spc_status &= ~SSTS_SPC_BSY; |
| 483 | } |
| 484 | logerror("mb89352: SCMD: Reset REQ/ACK\n"); |
| 485 | break; |
| 486 | case 0x07: // set REQ/ACK |
| 487 | m_line_status &= ~MB89352_LINE_REQ; |
| 488 | m_line_status |= MB89352_LINE_ACK; |
| 489 | logerror("mb89352: SCMD: Set REQ/ACK\n"); |
| 490 | if(m_phase == SCSI_PHASE_COMMAND) |
| 491 | { |
| 492 | m_command[m_command_index++] = m_temp; // temp register puts data onto the SCSI bus |
| 493 | if(m_command_index >= get_scsi_cmd_len(m_command[0])) |
| 494 | { |
| 495 | int x; |
| 496 | int phase; |
| 497 | // execute SCSI command |
| 498 | SCSISetCommand(m_SCSIdevices[m_target],m_command,m_command_index); |
| 499 | SCSIExecCommand(m_SCSIdevices[m_target],&m_result_length); |
| 500 | SCSIGetPhase(m_SCSIdevices[m_target],&phase); |
| 501 | if(m_command[0] == 1) // Rezero Unit - not implemented in SCSI code |
| 502 | set_phase(SCSI_PHASE_STATUS); |
| 503 | else |
| 504 | set_phase(phase); |
| 505 | logerror("Command executed: "); |
| 506 | for(x=0;x<m_command_index;x++) |
| 507 | logerror(" %02x",m_command[x]); |
| 508 | logerror("\n"); |
| 509 | } |
| 510 | return; |
| 511 | } |
| 512 | if(m_phase == SCSI_PHASE_STATUS) |
| 513 | { |
| 514 | image = dynamic_cast<device_image_interface*>(machine->device(m_config.scsidevs->devices[m_target].diskregion)); |
| 515 | if(image->exists()) |
| 516 | m_temp = 0x00; |
| 517 | else |
| 518 | m_temp = 0x02; |
| 519 | set_phase(SCSI_PHASE_MESSAGE_IN); |
| 520 | return; |
| 521 | } |
| 522 | if(m_phase == SCSI_PHASE_MESSAGE_IN) |
| 523 | { |
| 524 | m_temp = 0x00; |
| 525 | set_phase(SCSI_PHASE_BUS_FREE); |
| 526 | m_command_index = 0; |
| 527 | return; |
| 528 | } |
| 529 | break; |
| 530 | default: |
| 531 | logerror("mb89352: SCMD: Unimplemented command %02x\n",(data & 0xe0) >> 5); |
| 532 | break; |
| 533 | } |
| 534 | break; |
| 535 | case 0x04: // INTS - Interrupt Sense |
| 536 | m_ints &= ~data; // resets relevant status bits to zero |
| 537 | devcb_call_write_line(&m_irq_func,0); // clear IRQ |
| 538 | logerror("mb89352: Reset INTS status bits %02x\n",data); |
| 539 | break; |
| 540 | case 0x08: // PCTL - Phase control |
| 541 | if((data & 0x80) == 0 && (m_phase == SCSI_PHASE_SELECT)) // if writing 0 to bit 7, selection phase is reset |
| 542 | { |
| 543 | m_ints &= ~INTS_SELECTION; |
| 544 | m_target = 0; |
| 545 | logerror("mb89352: PCTL selection cancelled\n"); |
| 546 | } |
| 547 | // writing to the low 3 bits sets the phase |
| 548 | m_phase = data & 0x07; |
| 549 | m_line_status |= (data & 0x07); |
| 550 | logerror("mb89352: PCTL write %02x\n",data); |
| 551 | break; |
| 552 | case 0x0b: // TEMP - Temporary |
| 553 | m_temp = data; |
| 554 | logerror("mb89352: Write %02x to temporary register\n",data); |
| 555 | break; |
| 556 | case 0x0c: // TCH - Transfer Counter High |
| 557 | m_transfer_count = (m_transfer_count & 0x0000ffff) | (data << 16); |
| 558 | if(m_transfer_count == 0) |
| 559 | m_spc_status |= SSTS_TC_ZERO; |
| 560 | else |
| 561 | m_spc_status &= ~SSTS_TC_ZERO; |
| 562 | logerror("mb89352: TCH: Write %02x [%06x]\n",data,m_transfer_count); |
| 563 | break; |
| 564 | case 0x0d: // TCM - Transfer Counter Mid |
| 565 | m_transfer_count = (m_transfer_count & 0x00ff00ff) | (data << 8); |
| 566 | if(m_transfer_count == 0) |
| 567 | m_spc_status |= SSTS_TC_ZERO; |
| 568 | else |
| 569 | m_spc_status &= ~SSTS_TC_ZERO; |
| 570 | logerror("mb89352: TCM: Write %02x [%06x]\n",data,m_transfer_count); |
| 571 | break; |
| 572 | case 0x0e: // TCL - Transfer Counter Low |
| 573 | m_transfer_count = (m_transfer_count & 0x00ffff00) | data; |
| 574 | if(m_transfer_count == 0) |
| 575 | m_spc_status |= SSTS_TC_ZERO; |
| 576 | else |
| 577 | m_spc_status &= ~SSTS_TC_ZERO; |
| 578 | logerror("mb89352: TCL: Write %02x [%06x]\n",data,m_transfer_count); |
| 579 | break; |
| 580 | default: |
| 581 | logerror("mb89352: write %02x to register %02x\n",data,offset & 0x0f); |
| 582 | } |
| 583 | } |
src/mess/machine/mb89352.h
| r0 | r10144 | |
| 1 | /* |
| 2 | * mb89352.h |
| 3 | * |
| 4 | * Created on: 16/01/2011 |
| 5 | */ |
| 6 | |
| 7 | #ifndef MB89352_H_ |
| 8 | #define MB89352_H_ |
| 9 | |
| 10 | #include "machine/scsidev.h" |
| 11 | |
| 12 | // SCSI lines readable via PSNS register (reg 5) |
| 13 | #define MB89352_LINE_REQ 0x80 |
| 14 | #define MB89352_LINE_ACK 0x40 |
| 15 | #define MB89352_LINE_ATN 0x20 |
| 16 | #define MB89352_LINE_SEL 0x10 |
| 17 | #define MB89352_LINE_BSY 0x08 |
| 18 | #define MB89352_LINE_MSG 0x04 |
| 19 | #define MB89352_LINE_CD 0x02 |
| 20 | #define MB89352_LINE_IO 0x01 |
| 21 | |
| 22 | // INTS bits |
| 23 | #define INTS_RESET 0x01 |
| 24 | #define INTS_HARD_ERROR 0x02 |
| 25 | #define INTS_TIMEOUT 0x04 |
| 26 | #define INTS_SERVICE_REQUIRED 0x08 |
| 27 | #define INTS_COMMAND_COMPLETE 0x10 |
| 28 | #define INTS_DISCONNECTED 0x20 |
| 29 | #define INTS_RESELECTION 0x40 |
| 30 | #define INTS_SELECTION 0x80 |
| 31 | |
| 32 | // SSTS status bits |
| 33 | #define SSTS_DREG_EMPTY 0x01 |
| 34 | #define SSTS_DREG_FULL 0x02 |
| 35 | #define SSTS_TC_ZERO 0x04 |
| 36 | #define SSTS_SCSI_RST 0x08 |
| 37 | #define SSTS_XFER_IN_PROGRESS 0x10 |
| 38 | #define SSTS_SPC_BSY 0x20 |
| 39 | #define SSTS_TARG_CONNECTED 0x40 |
| 40 | #define SSTS_INIT_CONNECTED 0x80 |
| 41 | |
| 42 | // these aren't defined in scsi.h |
| 43 | #define SCSI_PHASE_BUS_FREE 8 |
| 44 | #define SCSI_PHASE_SELECT 9 |
| 45 | |
| 46 | struct mb89352_interface |
| 47 | { |
| 48 | const SCSIConfigTable *scsidevs; /* SCSI devices */ |
| 49 | devcb_write_line irq_callback; /* irq callback */ |
| 50 | devcb_write_line drq_callback; /* drq callback */ |
| 51 | }; |
| 52 | |
| 53 | #define MCFG_MB89352A_ADD(_tag, _intrf) \ |
| 54 | MCFG_DEVICE_ADD(_tag, MB89352A, 0) \ |
| 55 | MCFG_DEVICE_CONFIG(_intrf) |
| 56 | |
| 57 | class mb89352_device_config : public device_config, public mb89352_interface |
| 58 | { |
| 59 | friend class mb89352_device; |
| 60 | |
| 61 | // construction/destruction |
| 62 | mb89352_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 63 | |
| 64 | public: |
| 65 | // allocators |
| 66 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 67 | virtual device_t *alloc_device(running_machine &machine) const; |
| 68 | |
| 69 | protected: |
| 70 | // device_config overrides |
| 71 | virtual void device_config_complete(); |
| 72 | }; |
| 73 | |
| 74 | class mb89352_device : public device_t |
| 75 | { |
| 76 | friend class mb89352_device_config; |
| 77 | |
| 78 | // construction/destruction |
| 79 | mb89352_device(running_machine &machine, const mb89352_device_config &config); |
| 80 | |
| 81 | public: |
| 82 | // any publically accessible interfaces needed for runtime |
| 83 | DECLARE_READ8_MEMBER( mb89352_r ); |
| 84 | DECLARE_WRITE8_MEMBER( mb89352_w ); |
| 85 | |
| 86 | void set_phase(int phase); |
| 87 | int get_phase(void); |
| 88 | |
| 89 | protected: |
| 90 | // device-level overrides (none are required, but these are common) |
| 91 | virtual void device_start(); |
| 92 | virtual void device_reset(); |
| 93 | virtual void device_stop(); |
| 94 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 95 | |
| 96 | private: |
| 97 | // internal device state goes here |
| 98 | const mb89352_device_config &m_config; |
| 99 | static const device_timer_id TIMER_TRANSFER = 0; |
| 100 | |
| 101 | void mb89352_rescan(void); |
| 102 | int get_scsi_cmd_len(UINT8 cbyte); |
| 103 | |
| 104 | devcb_resolved_write_line m_irq_func; |
| 105 | devcb_resolved_write_line m_drq_func; |
| 106 | |
| 107 | SCSIInstance* m_SCSIdevices[8]; |
| 108 | |
| 109 | UINT8 m_phase; // current SCSI phase |
| 110 | UINT8 m_target; // current SCSI target |
| 111 | UINT8 m_bdid; // Bus device ID (SCSI ID of the bus?) |
| 112 | UINT8 m_ints; // Interrupt Sense |
| 113 | UINT8 m_temp; // Temporary register (To/From SCSI bus) |
| 114 | UINT8 m_data; // Data register |
| 115 | UINT8 m_scmd; // SPC Command register |
| 116 | UINT32 m_transfer_count; // byte transfer counter, also used as a timeout counter for selection. |
| 117 | UINT8 m_int_enable; |
| 118 | UINT8 m_sel_enable; |
| 119 | UINT8 m_resel_enable; |
| 120 | UINT8 m_parity_enable; |
| 121 | UINT8 m_arbit_enable; |
| 122 | UINT8 m_busfree_int_enable; |
| 123 | UINT8 m_line_status; |
| 124 | UINT8 m_spc_status; |
| 125 | UINT8 m_error_status; |
| 126 | UINT8 m_command_index; |
| 127 | UINT8 m_command[16]; |
| 128 | UINT32 m_transfer_index; |
| 129 | int m_result_length; |
| 130 | UINT8 m_buffer[512]; |
| 131 | |
| 132 | emu_timer* m_transfer_timer; |
| 133 | }; |
| 134 | |
| 135 | extern const device_type MB89352A; |
| 136 | |
| 137 | #endif /* MB89352_H_ */ |