src/emu/machine/ncr539x.c
| r0 | r13162 | |
| 1 | /* |
| 2 | * ncr539x.c |
| 3 | * |
| 4 | * NCR 53(CF)94/53(CF)96 SCSI controller |
| 5 | * Includes enhanced features of the AMD 53CF94/96 and compatibles |
| 6 | * |
| 7 | * All new emulation in 2011 by R. Belmont. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include "emu.h" |
| 12 | #include "ncr539x.h" |
| 13 | |
| 14 | #define VERBOSE (0) |
| 15 | #define VERBOSE_READS (0) |
| 16 | |
| 17 | enum |
| 18 | { |
| 19 | TIMER_539X_COMMAND, |
| 20 | |
| 21 | TIMER_539X_END |
| 22 | }; |
| 23 | |
| 24 | #define MAIN_STATUS_INTERRUPT 0x80 |
| 25 | #define MAIN_STATUS_ILLEGAL_OPER 0x40 |
| 26 | #define MAIN_STATUS_PARITY_ERROR 0x20 |
| 27 | #define MAIN_STATUS_COUNT_TO_ZERO 0x10 |
| 28 | #define MAIN_STATUS_GROUP_VALID 0x08 |
| 29 | #define MAIN_STATUS_MESSAGE 0x04 |
| 30 | #define MAIN_STATUS_CMD_DATA 0x02 |
| 31 | #define MAIN_STATUS_IO 0x01 |
| 32 | |
| 33 | #define IRQ_STATUS_RESET 0x80 |
| 34 | #define IRQ_STATUS_INVALID_COMMAND 0x40 |
| 35 | #define IRQ_STATUS_DISCONNECTED 0x20 |
| 36 | #define IRQ_STATUS_SERVICE_REQUEST 0x10 |
| 37 | #define IRQ_STATUS_SUCCESS 0x08 |
| 38 | #define IRQ_STATUS_RESELECTED 0x04 // we were reselected as a target |
| 39 | #define IRQ_STATUS_SELECTED_WITH_ATN 0x02 // we were selected as a target with ATN steps |
| 40 | #define IRQ_STATUS_SELECTED 0x01 // we were selected as a target |
| 41 | |
| 42 | #define CR2_ALIGN_ENABLE 0x80 |
| 43 | #define CR2_FEATURES_ENABLE 0x40 |
| 44 | #define CR2_BYTE_ORDER 0x20 |
| 45 | #define CR2_TRISTATE_DMA 0x10 |
| 46 | #define CR2_SCSI2_ENABLE 0x08 |
| 47 | #define CR2_ABORT_ON_PARITY_ERROR 0x04 |
| 48 | #define CR2_GENERATE_REGISTER_PARITY 0x02 |
| 49 | #define CR2_GENERATE_DATA_PARITY 0x01 |
| 50 | |
| 51 | #if VERBOSE |
| 52 | #if VERBOSE_READS |
| 53 | static const char *rdregs[16] = { |
| 54 | "Transfer count LSB", // 0 |
| 55 | "Transfer count MSB", // 1 |
| 56 | "FIFO", // 2 |
| 57 | "Command", // 3 |
| 58 | "Status", // 4 |
| 59 | "Interrupt Status", // 5 |
| 60 | "Internal State", |
| 61 | "Current FIFO/Internal State", |
| 62 | "Control Register 1", |
| 63 | "0x9", |
| 64 | "0xA", |
| 65 | "Control Register 2", |
| 66 | "Control Register 3", |
| 67 | "Control Register 4", |
| 68 | "Transfer count HSB/Chip ID", |
| 69 | "0xF" |
| 70 | }; |
| 71 | #endif |
| 72 | |
| 73 | static const char *wrregs[16] = { |
| 74 | "Start Transfer count LSB", |
| 75 | "Start Transfer count MSB", |
| 76 | "FIFO", |
| 77 | "Command", |
| 78 | "SCSI Destination ID", |
| 79 | "SCSI Timeout", |
| 80 | "Synchronous Transfer Period", |
| 81 | "Synchronous Offset", |
| 82 | "Control Register 1", |
| 83 | "Clock Factor", |
| 84 | "Forced Test Mode", |
| 85 | "Control Register 2", |
| 86 | "Control Register 3", |
| 87 | "Control Register 4", |
| 88 | "Start Transfer count HSB", |
| 89 | "Data Alignment" |
| 90 | }; |
| 91 | #endif |
| 92 | |
| 93 | // get the length of a SCSI command based on its command byte type |
| 94 | static int get_cmd_len(int cbyte) |
| 95 | { |
| 96 | int group; |
| 97 | |
| 98 | group = (cbyte>>5) & 7; |
| 99 | |
| 100 | if (group == 0) return 6; |
| 101 | if (group == 1 || group == 2) return 10; |
| 102 | if (group == 5) return 12; |
| 103 | |
| 104 | return 6; |
| 105 | } |
| 106 | |
| 107 | //------------------------------------------------- |
| 108 | // device_config_complete - perform any |
| 109 | // operations now that the configuration is |
| 110 | // complete |
| 111 | //------------------------------------------------- |
| 112 | |
| 113 | void ncr539x_device::device_config_complete() |
| 114 | { |
| 115 | // inherit a copy of the static data |
| 116 | const NCR539Xinterface *intf = reinterpret_cast<const NCR539Xinterface *>(static_config()); |
| 117 | if (intf != NULL) |
| 118 | { |
| 119 | *static_cast<NCR539Xinterface *>(this) = *intf; |
| 120 | } |
| 121 | |
| 122 | // or initialize to defaults if none provided |
| 123 | else |
| 124 | { |
| 125 | scsidevs = NULL; |
| 126 | memset(&m_out_irq_cb, 0, sizeof(m_out_irq_cb)); |
| 127 | memset(&m_out_drq_cb, 0, sizeof(m_out_drq_cb)); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | //************************************************************************** |
| 132 | // LIVE DEVICE |
| 133 | //************************************************************************** |
| 134 | |
| 135 | const device_type NCR539X = &device_creator<ncr539x_device>; |
| 136 | |
| 137 | //------------------------------------------------- |
| 138 | // ncr539x_device - constructor/destructor |
| 139 | //------------------------------------------------- |
| 140 | |
| 141 | ncr539x_device::ncr539x_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 142 | : device_t(mconfig, NCR539X, "539x SCSI", tag, owner, clock) |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | //------------------------------------------------- |
| 147 | // device_start - device-specific startup |
| 148 | //------------------------------------------------- |
| 149 | |
| 150 | void ncr539x_device::device_start() |
| 151 | { |
| 152 | int i; |
| 153 | |
| 154 | memset(m_scsi_devices, 0, sizeof(m_scsi_devices)); |
| 155 | |
| 156 | // resolve line callbacks |
| 157 | m_out_irq_func.resolve(m_out_irq_cb, *this); |
| 158 | m_out_drq_func.resolve(m_out_drq_cb, *this); |
| 159 | |
| 160 | // try to open the devices |
| 161 | for (i = 0; i < scsidevs->devs_present; i++) |
| 162 | { |
| 163 | SCSIAllocInstance( machine(), |
| 164 | scsidevs->devices[i].scsiClass, |
| 165 | &m_scsi_devices[scsidevs->devices[i].scsiID], |
| 166 | scsidevs->devices[i].diskregion ); |
| 167 | } |
| 168 | |
| 169 | m_operation_timer = timer_alloc(0, NULL); |
| 170 | } |
| 171 | |
| 172 | //------------------------------------------------- |
| 173 | // device_reset - device-specific reset |
| 174 | //------------------------------------------------- |
| 175 | |
| 176 | void ncr539x_device::device_reset() |
| 177 | { |
| 178 | memset(m_scsi_devices, 0, sizeof(m_scsi_devices)); |
| 179 | |
| 180 | m_fifo_ptr = 0; |
| 181 | m_irq_status = 0; |
| 182 | m_status = SCSI_PHASE_STATUS; |
| 183 | m_internal_state = 0; |
| 184 | m_buffer_offset = 512; |
| 185 | m_buffer_remaining = 0; |
| 186 | m_dma_size = 0; |
| 187 | m_xfer_count = 0; |
| 188 | m_total_data = 0; |
| 189 | m_selected = false; |
| 190 | m_control1 = m_control2 = m_control3 = m_control4 = 0; |
| 191 | m_chipid_available = false; |
| 192 | m_chipid_lock = false; |
| 193 | |
| 194 | m_out_irq_func(CLEAR_LINE); |
| 195 | m_out_drq_func(CLEAR_LINE); |
| 196 | |
| 197 | scan_devices(); |
| 198 | } |
| 199 | |
| 200 | //------------------------------------------------- |
| 201 | // device_stop - device-specific stop/shutdown |
| 202 | //------------------------------------------------- |
| 203 | void ncr539x_device::device_stop() |
| 204 | { |
| 205 | int i; |
| 206 | |
| 207 | // clean up the devices |
| 208 | for (i = 0; i < scsidevs->devs_present; i++) |
| 209 | { |
| 210 | SCSIDeleteInstance( m_scsi_devices[scsidevs->devices[i].scsiID] ); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void ncr539x_device::dma_read_data(int bytes, UINT8 *pData) |
| 215 | { |
| 216 | if (m_scsi_devices[m_last_id]) |
| 217 | { |
| 218 | if (VERBOSE) |
| 219 | logerror("NCR539x: issuing read for %d bytes\n", bytes); |
| 220 | SCSIReadData(m_scsi_devices[m_last_id], pData, bytes); |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | logerror("ncr539x: read unknown device SCSI ID %d\n", m_last_id); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | |
| 229 | void ncr539x_device::dma_write_data(int bytes, UINT8 *pData) |
| 230 | { |
| 231 | if (bytes) |
| 232 | { |
| 233 | if (m_scsi_devices[m_last_id]) |
| 234 | { |
| 235 | SCSIWriteData(m_scsi_devices[m_last_id], pData, bytes); |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | logerror("ncr539x: write to unknown device SCSI ID %d\n", m_last_id); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | void ncr539x_device::scan_devices() |
| 245 | { |
| 246 | int i; |
| 247 | |
| 248 | // try to open the devices |
| 249 | for (i = 0; i < scsidevs->devs_present; i++) |
| 250 | { |
| 251 | // if a device wasn't already allocated |
| 252 | if (!m_scsi_devices[scsidevs->devices[i].scsiID]) |
| 253 | { |
| 254 | SCSIAllocInstance( machine(), |
| 255 | scsidevs->devices[i].scsiClass, |
| 256 | &m_scsi_devices[scsidevs->devices[i].scsiID], |
| 257 | scsidevs->devices[i].diskregion ); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) |
| 263 | { |
| 264 | //printf("539X: device_timer expired, param = %d, m_command = %02x\n", param, m_command); |
| 265 | |
| 266 | switch (param) |
| 267 | { |
| 268 | case TIMER_539X_COMMAND: |
| 269 | // if this is a DMA command, raise DRQ now |
| 270 | if (m_command & 0x80) |
| 271 | { |
| 272 | m_out_drq_func(ASSERT_LINE); |
| 273 | } |
| 274 | |
| 275 | switch (m_command & 0x7f) |
| 276 | { |
| 277 | case 0x41: // select without ATN steps |
| 278 | if (m_scsi_devices[m_last_id]) |
| 279 | { |
| 280 | m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS; |
| 281 | // we should now be in the command phase |
| 282 | m_status &= ~7; // clear bus phases |
| 283 | m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; |
| 284 | m_fifo_ptr = 0; |
| 285 | m_selected = true; |
| 286 | |
| 287 | #if VERBOSE |
| 288 | printf("Selecting w/o ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); |
| 289 | #endif |
| 290 | |
| 291 | // if DMA is not enabled, there should already be a command loaded into the FIFO |
| 292 | if (!(m_command & 0x80)) |
| 293 | { |
| 294 | exec_fifo(); |
| 295 | } |
| 296 | update_fifo_internal_state(0); |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | #if VERBOSE |
| 301 | printf("Select failed, no device @ ID %d!\n", m_last_id); |
| 302 | #endif |
| 303 | m_status |= MAIN_STATUS_INTERRUPT; |
| 304 | m_irq_status |= IRQ_STATUS_DISCONNECTED; |
| 305 | } |
| 306 | m_out_irq_func(ASSERT_LINE); |
| 307 | break; |
| 308 | |
| 309 | case 0x42: // Select with ATN steps |
| 310 | if (m_scsi_devices[m_last_id]) |
| 311 | { |
| 312 | m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS; |
| 313 | // we should now be in the command phase |
| 314 | m_status &= ~7; // clear bus phases |
| 315 | m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; |
| 316 | m_fifo_ptr = 0; |
| 317 | m_selected = true; |
| 318 | #if VERBOSE |
| 319 | printf("Selecting with ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); |
| 320 | #endif |
| 321 | |
| 322 | // if DMA is not enabled, there should already be a command loaded into the FIFO |
| 323 | if (!(m_command & 0x80)) |
| 324 | { |
| 325 | exec_fifo(); |
| 326 | } |
| 327 | update_fifo_internal_state(0); |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | #if VERBOSE |
| 332 | printf("Select failed, no device @ ID %d!\n", m_last_id); |
| 333 | #endif |
| 334 | m_status |= MAIN_STATUS_INTERRUPT; |
| 335 | m_irq_status |= IRQ_STATUS_DISCONNECTED; |
| 336 | } |
| 337 | m_out_irq_func(ASSERT_LINE); |
| 338 | break; |
| 339 | |
| 340 | case 0x11: // initiator command complete |
| 341 | #if VERBOSE |
| 342 | printf("Initiator command complete\n"); |
| 343 | #endif |
| 344 | m_irq_status = IRQ_STATUS_SERVICE_REQUEST; |
| 345 | m_status &= ~7; // clear phase bits |
| 346 | m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_DATAIN; // go to data in phase (?) |
| 347 | m_out_irq_func(ASSERT_LINE); |
| 348 | |
| 349 | // this puts status and message bytes into the FIFO (todo: what are these?) |
| 350 | m_fifo_ptr = 0; |
| 351 | m_xfer_count = 2; |
| 352 | m_buffer_remaining = m_total_data = 0; |
| 353 | m_fifo[0] = 0; // status byte |
| 354 | m_fifo[1] = 0; // message byte |
| 355 | m_selected = false; |
| 356 | update_fifo_internal_state(2); |
| 357 | break; |
| 358 | |
| 359 | case 0x12: // message accepted |
| 360 | #if VERBOSE |
| 361 | printf("Message accepted\n"); |
| 362 | #endif |
| 363 | m_irq_status = IRQ_STATUS_SERVICE_REQUEST; |
| 364 | m_status |= MAIN_STATUS_INTERRUPT; |
| 365 | m_out_irq_func(ASSERT_LINE); |
| 366 | break; |
| 367 | |
| 368 | default: |
| 369 | fatalerror("539x: Unhandled command %02x\n", m_command); |
| 370 | break; |
| 371 | } |
| 372 | break; |
| 373 | |
| 374 | default: |
| 375 | break; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | READ8_MEMBER( ncr539x_device::read ) |
| 380 | { |
| 381 | UINT8 rv = 0; |
| 382 | |
| 383 | #if VERBOSE |
| 384 | #if VERBOSE_READS |
| 385 | printf("539x: Read @ %s (%02x) (PC=%x) (status %02x irq_status %02x)\n", rdregs[offset], offset, cpu_get_pc(&space.device()), m_status, m_irq_status); |
| 386 | #endif |
| 387 | #endif |
| 388 | |
| 389 | switch (offset) |
| 390 | { |
| 391 | case 0: |
| 392 | rv = m_xfer_count & 0xff; |
| 393 | break; |
| 394 | |
| 395 | case 1: |
| 396 | rv = (m_xfer_count>>8) & 0xff; |
| 397 | break; |
| 398 | |
| 399 | case 2: // FIFO |
| 400 | { |
| 401 | UINT8 fifo_bytes = m_fifo_internal_state & 0x1f; |
| 402 | |
| 403 | if (!fifo_bytes) |
| 404 | { |
| 405 | rv = 0; |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | rv = m_fifo[m_fifo_ptr++]; |
| 410 | |
| 411 | fifo_bytes--; |
| 412 | m_xfer_count--; |
| 413 | update_fifo_internal_state(fifo_bytes); |
| 414 | |
| 415 | #if VERBOSE |
| 416 | printf("Read %02x from FIFO[%d], FIFO now contains %d bytes (PC=%x, m_buffer_remaining %x)\n", rv, m_fifo_ptr-1, fifo_bytes, cpu_get_pc(&space.device()), m_buffer_remaining); |
| 417 | #endif |
| 418 | |
| 419 | if (fifo_bytes == 0) |
| 420 | { |
| 421 | // the last transfer command has more data for us |
| 422 | if (m_xfer_count > 0) |
| 423 | { |
| 424 | int fifo_fill_size = m_fifo_size; |
| 425 | if (m_xfer_count < fifo_fill_size) |
| 426 | { |
| 427 | fifo_fill_size = m_xfer_count; |
| 428 | } |
| 429 | memcpy(m_fifo, &m_buffer[m_buffer_offset], fifo_fill_size); |
| 430 | m_buffer_offset += fifo_fill_size; |
| 431 | m_buffer_remaining -= fifo_fill_size; |
| 432 | m_fifo_ptr = 0; |
| 433 | update_fifo_internal_state(fifo_fill_size); |
| 434 | #if VERBOSE |
| 435 | printf("Refreshing FIFO (%x remaining from transfer, %x in buffer, %x in total)\n", m_xfer_count, m_buffer_remaining, m_total_data); |
| 436 | #endif |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | #if VERBOSE |
| 441 | printf("FIFO empty, asserting service request (buffer_remaining %x)\n", m_buffer_remaining); |
| 442 | #endif |
| 443 | m_irq_status = IRQ_STATUS_SERVICE_REQUEST; |
| 444 | m_status &= 0x7; // clear everything but the phase bits |
| 445 | m_status |= MAIN_STATUS_INTERRUPT | MAIN_STATUS_COUNT_TO_ZERO; |
| 446 | m_out_irq_func(ASSERT_LINE); |
| 447 | |
| 448 | // if no data at all, drop the phase |
| 449 | if ((m_buffer_remaining + m_total_data) == 0) |
| 450 | { |
| 451 | #if VERBOSE |
| 452 | printf("Out of data, setting phase STATUS\n"); |
| 453 | #endif |
| 454 | m_status &= ~0x7; |
| 455 | m_status |= SCSI_PHASE_STATUS; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | break; |
| 462 | |
| 463 | case 3: |
| 464 | rv = m_command; |
| 465 | break; |
| 466 | |
| 467 | case 4: |
| 468 | rv = m_status; |
| 469 | break; |
| 470 | |
| 471 | case 5: |
| 472 | rv = m_irq_status; |
| 473 | // clear the interrupt state |
| 474 | m_status &= ~MAIN_STATUS_INTERRUPT; |
| 475 | m_out_irq_func(CLEAR_LINE); |
| 476 | break; |
| 477 | |
| 478 | case 6: |
| 479 | rv = m_internal_state; |
| 480 | break; |
| 481 | |
| 482 | case 7: |
| 483 | rv = m_fifo_internal_state; |
| 484 | break; |
| 485 | |
| 486 | case 8: |
| 487 | rv = m_control1; |
| 488 | break; |
| 489 | |
| 490 | case 0xb: |
| 491 | rv = m_control2; |
| 492 | break; |
| 493 | |
| 494 | case 0xc: |
| 495 | rv = m_control3; |
| 496 | break; |
| 497 | |
| 498 | case 0xd: |
| 499 | rv = m_control4; |
| 500 | break; |
| 501 | |
| 502 | case 0xe: |
| 503 | if (m_control2 & CR2_FEATURES_ENABLE) |
| 504 | { |
| 505 | if (m_chipid_available) |
| 506 | { |
| 507 | rv = 0xa2; // 0x12 for CF94, 0xa2 for CF96 |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | rv = (m_xfer_count>>16) & 0xff; |
| 512 | } |
| 513 | } |
| 514 | break; |
| 515 | |
| 516 | } |
| 517 | return rv; |
| 518 | } |
| 519 | |
| 520 | WRITE8_MEMBER( ncr539x_device::write ) |
| 521 | { |
| 522 | #if VERBOSE |
| 523 | if (offset != 2) printf("539x: Write %02x @ %s (%02x) (PC=%x)\n", data, wrregs[offset], offset, cpu_get_pc(&space.device())); |
| 524 | #endif |
| 525 | |
| 526 | switch (offset) |
| 527 | { |
| 528 | case 0: |
| 529 | m_dma_size &= 0xff00; |
| 530 | m_dma_size |= data; |
| 531 | break; |
| 532 | |
| 533 | case 1: |
| 534 | m_dma_size &= 0x00ff; |
| 535 | m_dma_size |= (data<<8); |
| 536 | break; |
| 537 | |
| 538 | case 2: // FIFO |
| 539 | fifo_write(data); |
| 540 | break; |
| 541 | |
| 542 | case 3: |
| 543 | m_command = data; |
| 544 | |
| 545 | // clear status bits (OK to do here?) |
| 546 | m_status &= ~MAIN_STATUS_INTERRUPT; |
| 547 | m_irq_status = 0; |
| 548 | |
| 549 | switch (data & 0x7f) |
| 550 | { |
| 551 | case 0x00: // NOP |
| 552 | m_irq_status = IRQ_STATUS_SUCCESS; |
| 553 | m_status |= MAIN_STATUS_INTERRUPT; |
| 554 | m_out_irq_func(ASSERT_LINE); |
| 555 | |
| 556 | // DMA NOP? allow chip ID |
| 557 | if ((m_command == 0x80) && (!m_chipid_lock)) |
| 558 | { |
| 559 | m_chipid_available = true; |
| 560 | } |
| 561 | break; |
| 562 | |
| 563 | case 0x01: // Clear FIFO (must not change buffer state) |
| 564 | m_fifo_ptr = 0; |
| 565 | update_fifo_internal_state(0); |
| 566 | m_irq_status = IRQ_STATUS_SUCCESS; |
| 567 | m_status |= MAIN_STATUS_INTERRUPT; |
| 568 | m_out_irq_func(ASSERT_LINE); |
| 569 | break; |
| 570 | |
| 571 | case 0x02: // Reset device |
| 572 | device_reset(); |
| 573 | |
| 574 | m_irq_status = IRQ_STATUS_SUCCESS; |
| 575 | m_status |= MAIN_STATUS_INTERRUPT; |
| 576 | m_out_irq_func(ASSERT_LINE); |
| 577 | break; |
| 578 | |
| 579 | case 0x03: // Reset SCSI bus |
| 580 | m_status = 0; |
| 581 | m_irq_status = IRQ_STATUS_SUCCESS; |
| 582 | m_status |= MAIN_STATUS_INTERRUPT; |
| 583 | m_out_irq_func(ASSERT_LINE); |
| 584 | break; |
| 585 | |
| 586 | case 0x10: // information transfer (must happen immediately) |
| 587 | m_status &= 0x7; // clear everything but the phase bits |
| 588 | m_status |= MAIN_STATUS_INTERRUPT; |
| 589 | m_irq_status = IRQ_STATUS_SUCCESS; |
| 590 | |
| 591 | int phase; |
| 592 | SCSIGetPhase( m_scsi_devices[m_last_id], &phase ); |
| 593 | |
| 594 | #if VERBOSE |
| 595 | printf("Information transfer: phase %d buffer remaining %x\n", phase, m_buffer_remaining); |
| 596 | #endif |
| 597 | |
| 598 | if (phase == SCSI_PHASE_DATAIN) // target -> initiator transfer |
| 599 | { |
| 600 | int amtToGet = m_buffer_size; |
| 601 | |
| 602 | // fill the internal sector buffer |
| 603 | if (m_buffer_remaining <= 0) |
| 604 | { |
| 605 | if (m_total_data < m_buffer_size) |
| 606 | { |
| 607 | amtToGet = m_total_data; |
| 608 | } |
| 609 | |
| 610 | #if VERBOSE |
| 611 | printf("amtToGet = %x\n", amtToGet); |
| 612 | #endif |
| 613 | |
| 614 | if (amtToGet > 0) |
| 615 | { |
| 616 | SCSIReadData(m_scsi_devices[m_last_id], m_buffer, amtToGet); |
| 617 | |
| 618 | m_total_data -= amtToGet; |
| 619 | m_buffer_offset = 0; |
| 620 | m_buffer_remaining = amtToGet; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | // copy the requested amount into the FIFO |
| 625 | if (amtToGet > 0) |
| 626 | { |
| 627 | if (m_buffer_remaining < m_dma_size) |
| 628 | { |
| 629 | m_dma_size = m_buffer_remaining; |
| 630 | } |
| 631 | |
| 632 | int fifo_fill_size = m_fifo_size; |
| 633 | |
| 634 | if (m_dma_size < fifo_fill_size) |
| 635 | { |
| 636 | fifo_fill_size = m_dma_size; |
| 637 | } |
| 638 | |
| 639 | #if VERBOSE |
| 640 | printf("filling FIFO from buffer[%x] for %x bytes\n", m_buffer_offset, fifo_fill_size); |
| 641 | #endif |
| 642 | |
| 643 | memcpy(m_fifo, &m_buffer[m_buffer_offset], fifo_fill_size); |
| 644 | m_buffer_offset += fifo_fill_size; |
| 645 | m_buffer_remaining -= fifo_fill_size; |
| 646 | |
| 647 | m_xfer_count = m_dma_size; |
| 648 | m_fifo_ptr = 0; |
| 649 | update_fifo_internal_state(fifo_fill_size); |
| 650 | m_out_drq_func(ASSERT_LINE); |
| 651 | } |
| 652 | |
| 653 | m_status |= MAIN_STATUS_COUNT_TO_ZERO; |
| 654 | |
| 655 | #if VERBOSE |
| 656 | printf("Information transfer: put %02x bytes into FIFO (dma size %x) (buffer remaining %x)\n", m_fifo_internal_state & 0x1f, m_dma_size, m_buffer_remaining); |
| 657 | #endif |
| 658 | } |
| 659 | else if (phase == SCSI_PHASE_DATAOUT) |
| 660 | { |
| 661 | m_xfer_count = m_dma_size; |
| 662 | if (m_xfer_count == 0) |
| 663 | { |
| 664 | m_xfer_count = 0x10000; |
| 665 | } |
| 666 | #if VERBOSE |
| 667 | printf("dma_size %x, xfer_count %x\n", m_dma_size, m_xfer_count); |
| 668 | #endif |
| 669 | m_status &= ~MAIN_STATUS_COUNT_TO_ZERO; |
| 670 | m_fifo_ptr = 0; |
| 671 | m_buffer_offset = 0; |
| 672 | m_buffer_remaining = 0; |
| 673 | } |
| 674 | m_out_irq_func(ASSERT_LINE); |
| 675 | break; |
| 676 | |
| 677 | case 0x24: // Terminate steps |
| 678 | #if VERBOSE |
| 679 | printf("Terminate steps\n"); |
| 680 | #endif |
| 681 | m_irq_status = IRQ_STATUS_SUCCESS | IRQ_STATUS_DISCONNECTED; |
| 682 | m_status |= MAIN_STATUS_INTERRUPT; |
| 683 | m_out_irq_func(ASSERT_LINE); |
| 684 | m_fifo_ptr = 0; |
| 685 | update_fifo_internal_state(0); |
| 686 | break; |
| 687 | |
| 688 | case 0x27: // Disconnect |
| 689 | #if VERBOSE |
| 690 | printf("Disconnect\n"); |
| 691 | #endif |
| 692 | m_irq_status = IRQ_STATUS_SUCCESS; |
| 693 | m_status |= MAIN_STATUS_INTERRUPT; |
| 694 | m_out_irq_func(ASSERT_LINE); |
| 695 | break; |
| 696 | |
| 697 | case 0x44: // Enable selection/reselection |
| 698 | #if VERBOSE |
| 699 | printf("Enable selection/reselection\n"); |
| 700 | #endif |
| 701 | m_irq_status = IRQ_STATUS_SUCCESS; |
| 702 | m_status |= MAIN_STATUS_INTERRUPT; |
| 703 | m_out_irq_func(ASSERT_LINE); |
| 704 | break; |
| 705 | |
| 706 | case 0x47: // Reselect with ATN3 steps |
| 707 | if (m_scsi_devices[m_last_id]) |
| 708 | { |
| 709 | m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS; |
| 710 | // we should now be in the command phase |
| 711 | m_status &= ~7; // clear bus phases |
| 712 | m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; |
| 713 | m_fifo_ptr = 0; |
| 714 | m_selected = true; |
| 715 | #if VERBOSE |
| 716 | printf("Reselecting with ATN3, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); |
| 717 | #endif |
| 718 | |
| 719 | // if DMA is not enabled, there should already be a command loaded into the FIFO |
| 720 | if (!(m_command & 0x80)) |
| 721 | { |
| 722 | exec_fifo(); |
| 723 | } |
| 724 | update_fifo_internal_state(0); |
| 725 | } |
| 726 | else |
| 727 | { |
| 728 | #if VERBOSE |
| 729 | printf("Reselect with ATN3 failed, no device @ ID %d!\n", m_last_id); |
| 730 | #endif |
| 731 | m_status |= MAIN_STATUS_INTERRUPT; |
| 732 | m_irq_status |= IRQ_STATUS_DISCONNECTED; |
| 733 | } |
| 734 | m_out_irq_func(ASSERT_LINE); |
| 735 | break; |
| 736 | |
| 737 | default: // other commands are not instantaneous |
| 738 | #if VERBOSE |
| 739 | printf("Setting timer for command %02x\n", data); |
| 740 | #endif |
| 741 | // 1x commands happen much faster |
| 742 | if ((m_command & 0x70) == 0x10) |
| 743 | { |
| 744 | m_operation_timer->adjust(attotime::from_hz(65536), TIMER_539X_COMMAND); |
| 745 | } |
| 746 | else |
| 747 | { |
| 748 | m_operation_timer->adjust(attotime::from_hz(16384), TIMER_539X_COMMAND); |
| 749 | } |
| 750 | break; |
| 751 | } |
| 752 | break; |
| 753 | |
| 754 | case 4: |
| 755 | m_last_id = data; |
| 756 | break; |
| 757 | |
| 758 | case 5: |
| 759 | m_timeout = data; |
| 760 | break; |
| 761 | |
| 762 | case 6: |
| 763 | m_sync_xfer_period = data; |
| 764 | break; |
| 765 | |
| 766 | case 7: |
| 767 | m_sync_offset = data; |
| 768 | break; |
| 769 | |
| 770 | case 8: |
| 771 | m_control1 = data; |
| 772 | break; |
| 773 | |
| 774 | case 9: |
| 775 | m_clock_factor = data; |
| 776 | break; |
| 777 | |
| 778 | case 0xa: |
| 779 | m_forced_test = data; |
| 780 | break; |
| 781 | |
| 782 | case 0xb: |
| 783 | m_control2 = data; |
| 784 | break; |
| 785 | |
| 786 | case 0xc: |
| 787 | m_control3 = data; |
| 788 | break; |
| 789 | |
| 790 | case 0xd: |
| 791 | m_control4 = data; |
| 792 | break; |
| 793 | |
| 794 | case 0xe: |
| 795 | if (m_control2 & CR2_FEATURES_ENABLE) |
| 796 | { |
| 797 | m_dma_size &= 0xffff; |
| 798 | m_dma_size |= (data<<16); |
| 799 | m_chipid_available = false; |
| 800 | m_chipid_lock = true; |
| 801 | } |
| 802 | break; |
| 803 | |
| 804 | case 0xf: |
| 805 | m_data_alignment = data; |
| 806 | break; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | void ncr539x_device::exec_fifo() |
| 811 | { |
| 812 | int length, phase; |
| 813 | |
| 814 | SCSISetCommand(m_scsi_devices[m_last_id], &m_fifo[0], 12); |
| 815 | SCSIExecCommand(m_scsi_devices[m_last_id], &length); |
| 816 | SCSIGetPhase(m_scsi_devices[m_last_id], &phase); |
| 817 | |
| 818 | #if VERBOSE |
| 819 | printf("Command executed (id %d), new phase %d, length %x\n", m_last_id, phase, length); |
| 820 | #endif |
| 821 | |
| 822 | m_buffer_offset = m_buffer_size; |
| 823 | m_buffer_remaining = 0; |
| 824 | m_total_data = length; |
| 825 | |
| 826 | m_status &= ~7; // clear bus phases |
| 827 | m_status |= (phase & 7); // set the phase reported by the device |
| 828 | } |
| 829 | |
| 830 | void ncr539x_device::check_fifo_executable() |
| 831 | { |
| 832 | if (get_cmd_len(m_fifo[0]) == m_fifo_ptr) |
| 833 | { |
| 834 | exec_fifo(); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | void ncr539x_device::fifo_write(UINT8 data) |
| 839 | { |
| 840 | int phase = (m_status & 7); |
| 841 | |
| 842 | if (phase != SCSI_PHASE_DATAOUT) |
| 843 | { |
| 844 | #if VERBOSE |
| 845 | printf("539x: Write %02x @ FIFO[%x]\n", data, m_fifo_ptr); |
| 846 | #endif |
| 847 | m_fifo[m_fifo_ptr++] = data; |
| 848 | |
| 849 | if (m_selected) |
| 850 | { |
| 851 | check_fifo_executable(); |
| 852 | } |
| 853 | } |
| 854 | else // phase is DATAOUT |
| 855 | { |
| 856 | m_buffer[m_buffer_offset++] = data; |
| 857 | m_xfer_count--; |
| 858 | m_total_data--; |
| 859 | #if VERBOSE |
| 860 | printf("539x: Write %02x @ buffer[%x], xfer_count %x, total %x\n", data, m_buffer_offset-1, m_xfer_count, m_total_data); |
| 861 | #endif |
| 862 | |
| 863 | // default to flushing our entire buffer |
| 864 | int flush_size = m_buffer_size; |
| 865 | |
| 866 | // if the actual size is less than the buffer size, flush that instead |
| 867 | if (m_dma_size < m_buffer_size) |
| 868 | { |
| 869 | flush_size = m_dma_size; |
| 870 | } |
| 871 | |
| 872 | if ((m_buffer_offset == flush_size) || (m_xfer_count == 0)) |
| 873 | { |
| 874 | #if VERBOSE |
| 875 | printf("Flushing buffer to device, %x bytes left in buffer (%x total)\n", m_xfer_count, m_total_data); |
| 876 | #endif |
| 877 | SCSIWriteData(m_scsi_devices[m_last_id], m_buffer, flush_size); |
| 878 | m_buffer_offset = 0; |
| 879 | |
| 880 | // need a service request here too |
| 881 | m_irq_status = IRQ_STATUS_SERVICE_REQUEST; |
| 882 | m_status &= 7; |
| 883 | m_status |= MAIN_STATUS_INTERRUPT; |
| 884 | m_out_irq_func(ASSERT_LINE); |
| 885 | } |
| 886 | |
| 887 | if ((m_xfer_count == 0) && (m_total_data == 0)) |
| 888 | { |
| 889 | #if VERBOSE |
| 890 | printf("End of write, asserting service request\n"); |
| 891 | #endif |
| 892 | |
| 893 | m_buffer_offset = 0; |
| 894 | m_irq_status = IRQ_STATUS_SERVICE_REQUEST; |
| 895 | m_status = MAIN_STATUS_INTERRUPT | SCSI_PHASE_STATUS; |
| 896 | m_out_irq_func(ASSERT_LINE); |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | void ncr539x_device::update_fifo_internal_state(int bytes) |
| 902 | { |
| 903 | if (bytes >= 0x1f) |
| 904 | { |
| 905 | m_fifo_internal_state |= 0x1f; |
| 906 | } |
| 907 | else |
| 908 | { |
| 909 | m_fifo_internal_state &= ~0x1f; |
| 910 | m_fifo_internal_state |= (bytes & 0x1f); |
| 911 | } |
| 912 | } |
src/mess/machine/mac.c
| r13161 | r13162 | |
| 21 | 21 | - PowerBook 100 68k (16 MHz) SWIM ADB-PMU PMU 640x400 B&W |
| 22 | 22 | - Mac II 020 IWM MacII ADB ext NuBus card |
| 23 | 23 | - Mac IIx 030 SWIM MacII ADB ext NuBus card |
| 24 | | - Mac IIfx 030 SWIM ADB-IOP ext NuBus card |
| 24 | - Mac IIfx 030 SWIM IOP ADB ext NuBus card |
| 25 | 25 | - Mac SE/30 030 SWIM MacII ADB ext Internal fake NuBus card |
| 26 | 26 | - Mac IIcx 030 SWIM MacII ADB ext NuBus card |
| 27 | | - Mac IIci 030 SWIM Egret ADB ext Internal "RBV" type |
| 27 | - Mac IIci 030 SWIM MacII ADB ext Internal "RBV" type |
| 28 | 28 | - Mac IIsi 030 SWIM Egret ADB n/a Internal "RBV" type |
| 29 | 29 | - PowerBook 140/145(B) 030 (16/25 MHz) SWIM ADB-PMU PMU 640x400 B&W (passive matrix) |
| 30 | 30 | - PowerBook 170 030 (25 MHz) SWIM ADB-PMU PMU 640x400 B&W (active matrix) |
| r13161 | r13162 | |
| 32 | 32 | - Mac LC 020 SWIM Egret ADB n/a Internal "V8" type |
| 33 | 33 | - Mac LC II 030 SWIM Egret ADB n/a Internal "V8" type |
| 34 | 34 | - Mac LC III 030 SWIM Egret ADB n/a Internal "Sonora" type |
| 35 | | - Mac Classic II 030 SWIM Egret ADB n/a Internal "Eagle" type |
| 36 | | |
| 35 | - Mac Classic II 030 SWIM Egret ADB n/a Internal "Eagle" type (V8 clone) |
| 36 | - Mac Color Classic 030 SWIM Cuda ADB n/a Internal "Spice" type (V8 clone) |
| 37 | - Mac Quadra 700 040 (25 MHz) SWIM II MacII ADB ext Internal "DAFB" type |
| 38 | - Mac Quadra 900 040 (33 MHz) SWIM II IOP ADB ext Internal "DAFB" type |
| 39 | |
| 37 | 40 | Notes: |
| 38 | 41 | - The Mac Plus boot code seems to check to see the extent of ROM |
| 39 | 42 | mirroring to determine if SCSI is available. If the ROM is mirrored, |
| r13161 | r13162 | |
| 47 | 50 | - There are 5 known kinds of host-side ADB hardware: |
| 48 | 51 | * "Mac II ADB" used in the SE, II, IIx, IIcx, SE/30, IIci, Quadra 610, Quadra 650, Quadra 700, |
| 49 | 52 | Quadra 800, Centris 610 and Centris 650. This is a bit-banger using the VIA and a simple PIC. |
| 50 | | * "ADB-PMU" used in the Mac Portable and all 680x0-based PowerBooks. |
| 51 | | * "ADB-EGRET" used in the IIsi, IIvi, IIvx, Classic II, LC, LC II, LC III, Performa 460, |
| 53 | * "PMU ADB" used in the Mac Portable and all 680x0-based PowerBooks. |
| 54 | * "Egret ADB" used in the IIsi, IIvi, IIvx, Classic II, LC, LC II, LC III, Performa 460, |
| 52 | 55 | and Performa 600. This is a 68HC05 with a different internal ROM than CUDA. |
| 53 | | * "ADB-IOP" (ADB driven by a 6502 coprocessor, similar to Lisa) used in the IIfx, |
| 56 | * "IOP ADB" (ADB driven by a 6502 coprocessor, similar to Lisa) used in the IIfx, |
| 54 | 57 | Quadra 900, and Quadra 950. |
| 55 | | * "ADB-CUDA" (Apple's CUDA chip, which is a 68HC05 MCU) used in the Color Classic, LC 520, |
| 58 | * "Cuda ADB" (Apple's CUDA chip, which is a 68HC05 MCU) used in the Color Classic, LC 520, |
| 56 | 59 | LC 55x, LC 57x, LC 58x, Quadra 630, Quadra 660AV, Quadra 840AV, PowerMac 6100/7100/8100, |
| 57 | 60 | IIci, and PowerMac 5200. |
| 58 | 61 | |
| r13161 | r13162 | |
| 88 | 91 | #include "machine/applefdc.h" |
| 89 | 92 | #include "devices/sonydriv.h" |
| 90 | 93 | #include "machine/ncr5380.h" |
| 91 | | #include "machine/am53cf96.h" |
| 92 | 94 | #include "sound/asc.h" |
| 93 | 95 | #include "includes/mac.h" |
| 94 | 96 | #include "debug/debugcpu.h" |
| r13161 | r13162 | |
| 537 | 539 | { |
| 538 | 540 | mac_install_memory(machine(), 0x00000000, memory_size-1, memory_size, memory_data, is_rom, "bank1"); |
| 539 | 541 | } |
| 542 | else if (m_model == MODEL_MAC_QUADRA_700) |
| 543 | { |
| 544 | mac_install_memory(machine(), 0x00000000, memory_size-1, memory_size, memory_data, is_rom, "bank1"); |
| 545 | } |
| 540 | 546 | else |
| 541 | 547 | { |
| 542 | 548 | mac_install_memory(machine(), 0x00000000, 0x003fffff, memory_size, memory_data, is_rom, "bank1"); |
| r13161 | r13162 | |
| 1091 | 1097 | }*/ |
| 1092 | 1098 | } |
| 1093 | 1099 | |
| 1100 | WRITE_LINE_MEMBER(mac_state::irq_539x_1_w) |
| 1101 | { |
| 1102 | if (state) // make sure a CB1 transition occurs |
| 1103 | { |
| 1104 | m_via2->write_cb2(0); |
| 1105 | m_via2->write_cb2(1); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | WRITE_LINE_MEMBER(mac_state::drq_539x_1_w) |
| 1110 | { |
| 1111 | m_dafb_scsi1_drq = state; |
| 1112 | } |
| 1113 | |
| 1094 | 1114 | /* ************************************************************************* |
| 1095 | 1115 | * SCC |
| 1096 | 1116 | * |
| r13161 | r13162 | |
| 3333 | 3353 | MAC_DRIVER_INIT(maciivx, MODEL_MAC_IIVX) |
| 3334 | 3354 | MAC_DRIVER_INIT(maciifx, MODEL_MAC_IIFX) |
| 3335 | 3355 | MAC_DRIVER_INIT(macpbduo210, MODEL_MAC_PBDUO_210) |
| 3356 | MAC_DRIVER_INIT(macquadra700, MODEL_MAC_QUADRA_700) |
| 3336 | 3357 | |
| 3337 | | static void scsi96_irq(running_machine &machine) |
| 3338 | | { |
| 3339 | | } |
| 3340 | | |
| 3341 | | static const SCSIConfigTable dev_table = |
| 3342 | | { |
| 3343 | | 2, /* 2 SCSI devices */ |
| 3344 | | { |
| 3345 | | { SCSI_ID_6, "harddisk1", SCSI_DEVICE_HARDDISK }, /* SCSI ID 6, using disk1, and it's a harddisk */ |
| 3346 | | { SCSI_ID_5, "harddisk2", SCSI_DEVICE_HARDDISK } /* SCSI ID 5, using disk2, and it's a harddisk */ |
| 3347 | | } |
| 3348 | | }; |
| 3349 | | |
| 3350 | | static const struct AM53CF96interface scsi_intf = |
| 3351 | | { |
| 3352 | | &dev_table, /* SCSI device table */ |
| 3353 | | &scsi96_irq, /* command completion IRQ */ |
| 3354 | | }; |
| 3355 | | |
| 3356 | | DRIVER_INIT(macquadra700) |
| 3357 | | { |
| 3358 | | mac_driver_init(machine, MODEL_MAC_QUADRA_700); |
| 3359 | | am53cf96_init(machine, &scsi_intf); |
| 3360 | | } |
| 3361 | | |
| 3362 | 3358 | // make the appletalk init fail instead of hanging on the II FDHD/IIx/IIcx/SE30 ROM |
| 3363 | 3359 | static void patch_appletalk_iix(running_machine &machine) |
| 3364 | 3360 | { |
| r13161 | r13162 | |
| 3410 | 3406 | mac->m_nubus_irq_state |= masks[slot]; |
| 3411 | 3407 | } |
| 3412 | 3408 | |
| 3413 | | if (mac->m_model != MODEL_MAC_IIFX) |
| 3409 | if ((mac->m_model != MODEL_MAC_IIFX) && (mac->m_model != MODEL_MAC_IICI) && (mac->m_model != MODEL_MAC_IISI)) |
| 3414 | 3410 | { |
| 3415 | 3411 | if ((mac->m_nubus_irq_state & mask) != mask) |
| 3416 | 3412 | { |
| r13161 | r13162 | |
| 3426 | 3422 | m_via2->write_ca1(1); |
| 3427 | 3423 | } |
| 3428 | 3424 | } |
| 3425 | |
| 3426 | if ((mac->m_model == MODEL_MAC_IICI) || (mac->m_model == MODEL_MAC_IISI) || (mac->m_model == MODEL_MAC_IIVX) || (mac->m_model == MODEL_MAC_IIVI)) |
| 3427 | { |
| 3428 | mac->m_rbv_regs[2] &= ~0x38; |
| 3429 | mac->m_rbv_regs[2] |= (mac->m_nubus_irq_state & 0x38); |
| 3430 | mac->rbv_recalc_irqs(); |
| 3431 | } |
| 3429 | 3432 | } |
| 3430 | 3433 | |
| 3431 | 3434 | void mac_state::vblank_irq() |
src/mess/video/mac.c
| r13161 | r13162 | |
| 7 | 7 | Emulates the video hardware for compact Macintosh series (original |
| 8 | 8 | Macintosh (128k, 512k, 512ke), Macintosh Plus, Macintosh SE, Macintosh |
| 9 | 9 | Classic) |
| 10 | |
| 11 | Also emulates on-board video for systems with the |
| 12 | RBV, V8, Sonora, and DAFB chips. |
| 13 | |
| 14 | ---------------------------------------------------------------------- |
| 15 | Monitor sense codes |
| 16 | |
| 17 | Apple assigns 3 pins for monitor IDs. These allow 8 possible codes: |
| 18 | |
| 19 | 000 - color 2-Page Display (21") |
| 20 | 001 - monochrome Full Page display (15") |
| 21 | 010 - color 512x384 (12") |
| 22 | 011 - monochrome 2 Page display (21") |
| 23 | 100 - NTSC |
| 24 | 101 - color Full Page display (15") |
| 25 | 110 - High-Resolution Color (13" 640x480) or use "type 6" extended codes |
| 26 | 111 - No monitor connected or use "type 7" extended codes |
| 27 | |
| 28 | For extended codes, you drive one of the 3 pins at a time and read the 2 |
| 29 | undriven pins. See http://support.apple.com/kb/TA21618?viewlocale=en_US |
| 30 | for details. |
| 31 | |
| 32 | Extended codes: |
| 33 | |
| 34 | Sense 2 Low Sense 1 Low Sense 0 Low |
| 35 | 1 & 0 2 & 0 2 & 1 |
| 10 | 36 | |
| 37 | Multiple Scan 14" 00 00 11 |
| 38 | Multiple Scan 16" 00 10 11 |
| 39 | Multiple Scan 21" 10 00 11 |
| 40 | PAL Encoder 00 00 00 |
| 41 | NTSC Encoder 01 01 00 |
| 42 | VGA/Super VGA 01 01 11 |
| 43 | RGB 16" 10 11 01 |
| 44 | PAL Monitor 11 00 00 |
| 45 | RGB 19" 11 10 10 |
| 46 | Radius color TPD 11 00 01 (TPD = Two Page Display) |
| 47 | Radius mono TPD 11 01 00 |
| 48 | Apple TPD 11 01 01 |
| 49 | Apple color FPD 01 11 10 (FPD = Full Page Display) |
| 50 | |
| 11 | 51 | ***************************************************************************/ |
| 12 | 52 | |
| 13 | 53 | #define ADDRESS_MAP_MODERN |
| r13161 | r13162 | |
| 474 | 514 | return 0; |
| 475 | 515 | } |
| 476 | 516 | break; |
| 477 | | |
| 478 | | case RBV_TYPE_DAFB: |
| 479 | | mode = 0; |
| 480 | | break; |
| 481 | 517 | } |
| 482 | 518 | |
| 483 | 519 | switch (mode) |
| r13161 | r13162 | |
| 507 | 543 | } |
| 508 | 544 | } |
| 509 | 545 | } |
| 510 | | else if (mac->m_rbv_type == RBV_TYPE_DAFB) |
| 511 | | { |
| 512 | | vram8 += 0x1000; |
| 513 | | |
| 514 | | for (y = 0; y < 480; y++) |
| 515 | | { |
| 516 | | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 517 | | for (x = 0; x < 640; x+=8) |
| 518 | | { |
| 519 | | pixels = vram8[(y * 256 * 4) + ((x/8)^3)]; |
| 520 | | |
| 521 | | *scanline++ = mac->m_rbv_palette[(pixels>>7)&1]; |
| 522 | | *scanline++ = mac->m_rbv_palette[(pixels>>6)&1]; |
| 523 | | *scanline++ = mac->m_rbv_palette[(pixels>>5)&1]; |
| 524 | | *scanline++ = mac->m_rbv_palette[(pixels>>4)&1]; |
| 525 | | *scanline++ = mac->m_rbv_palette[(pixels>>3)&1]; |
| 526 | | *scanline++ = mac->m_rbv_palette[(pixels>>2)&1]; |
| 527 | | *scanline++ = mac->m_rbv_palette[(pixels>>1)&1]; |
| 528 | | *scanline++ = mac->m_rbv_palette[(pixels&1)]; |
| 529 | | } |
| 530 | | } |
| 531 | | } |
| 532 | 546 | else |
| 533 | 547 | { |
| 534 | 548 | for (y = 0; y < 480; y++) |
| r13161 | r13162 | |
| 685 | 699 | mac->m_rbv_vbltime = 0; |
| 686 | 700 | mac->m_dafb_int_status = 0; |
| 687 | 701 | mac->m_rbv_type = RBV_TYPE_DAFB; |
| 702 | mac->m_dafb_mode = 0; |
| 703 | mac->m_dafb_base = 0x1000; |
| 704 | mac->m_dafb_stride = 256*4; |
| 688 | 705 | |
| 689 | 706 | memset(mac->m_rbv_palette, 0, sizeof(mac->m_rbv_palette)); |
| 690 | 707 | } |
| r13161 | r13162 | |
| 695 | 712 | |
| 696 | 713 | switch (offset<<2) |
| 697 | 714 | { |
| 698 | | case 0x1c: // monitor sense |
| 699 | | return 1; // 640x480 |
| 715 | case 0x1c: // inverse of monitor sense |
| 716 | return 7; // 21" color 2-page |
| 700 | 717 | break; |
| 701 | 718 | |
| 719 | case 0x24: // SCSI 539x #1 status |
| 720 | return m_dafb_scsi1_drq<<9; |
| 721 | break; |
| 722 | |
| 723 | case 0x28: // SCSI 539x #2 status |
| 724 | return m_dafb_scsi2_drq<<9; |
| 725 | break; |
| 726 | |
| 702 | 727 | case 0x108: // IRQ/VBL status |
| 703 | 728 | return m_dafb_int_status; |
| 704 | 729 | break; |
| r13161 | r13162 | |
| 718 | 743 | |
| 719 | 744 | WRITE32_MEMBER(mac_state::dafb_w) |
| 720 | 745 | { |
| 721 | | // printf("DAFB: Write %08x @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu)); |
| 746 | // if (offset != 0x10c/4) printf("DAFB: Write %08x @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu)); |
| 722 | 747 | |
| 723 | 748 | switch (offset<<2) |
| 724 | 749 | { |
| 750 | case 0: // bits 20-9 of base |
| 751 | m_dafb_base &= 0x1ff; |
| 752 | m_dafb_base |= (data & 0xffff) << 9; |
| 753 | // printf("DAFB baseH: %x\n", m_dafb_base); |
| 754 | break; |
| 755 | |
| 756 | case 4: // bits 8-5 of base |
| 757 | m_dafb_base &= ~0x1ff; |
| 758 | m_dafb_base |= (data & 0xf) << 5; |
| 759 | // printf("DAFB baseL: %x\n", m_dafb_base); |
| 760 | break; |
| 761 | |
| 762 | case 8: |
| 763 | m_dafb_stride = data<<2; // stride in DWORDs |
| 764 | // printf("DAFB stride: %x %x\n", m_dafb_stride, data); |
| 765 | break; |
| 766 | |
| 725 | 767 | case 0x104: |
| 726 | 768 | if (data & 1) // VBL enable |
| 727 | 769 | { |
| r13161 | r13162 | |
| 772 | 814 | |
| 773 | 815 | WRITE32_MEMBER(mac_state::dafb_dac_w) |
| 774 | 816 | { |
| 775 | | // printf("DAFB: Write %08x to DAC @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu)); |
| 817 | // if ((offset > 0) && (offset != 0x10/4)) printf("DAFB: Write %08x to DAC @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu)); |
| 776 | 818 | |
| 777 | 819 | switch (offset<<2) |
| 778 | 820 | { |
| r13161 | r13162 | |
| 792 | 834 | m_rbv_count = 0; |
| 793 | 835 | } |
| 794 | 836 | break; |
| 837 | |
| 838 | case 0x20: |
| 839 | printf("%x to DAFB mode\n", data); |
| 840 | switch (data & 0x9f) |
| 841 | { |
| 842 | case 0x80: |
| 843 | m_dafb_mode = 0; // 1bpp |
| 844 | break; |
| 845 | |
| 846 | case 0x88: |
| 847 | m_dafb_mode = 1; // 2bpp |
| 848 | break; |
| 849 | |
| 850 | case 0x90: |
| 851 | m_dafb_mode = 2; // 4bpp |
| 852 | break; |
| 853 | |
| 854 | case 0x98: |
| 855 | m_dafb_mode = 3; // 8bpp |
| 856 | break; |
| 857 | |
| 858 | case 0x9c: |
| 859 | m_dafb_mode = 4; // 24bpp |
| 860 | break; |
| 861 | } |
| 862 | break; |
| 795 | 863 | } |
| 796 | 864 | } |
| 797 | 865 | |
| 866 | SCREEN_UPDATE( macdafb ) |
| 867 | { |
| 868 | UINT32 *scanline; |
| 869 | int x, y; |
| 870 | mac_state *mac = screen->machine().driver_data<mac_state>(); |
| 871 | |
| 872 | switch (mac->m_dafb_mode) |
| 873 | { |
| 874 | case 0: // 1bpp |
| 875 | { |
| 876 | UINT8 *vram8 = (UINT8 *)mac->m_vram; |
| 877 | UINT8 pixels; |
| 878 | vram8 += mac->m_dafb_base; |
| 879 | |
| 880 | for (y = 0; y < 870; y++) |
| 881 | { |
| 882 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 883 | for (x = 0; x < 1152; x+=8) |
| 884 | { |
| 885 | pixels = vram8[(y * mac->m_dafb_stride) + ((x/8)^3)]; |
| 886 | |
| 887 | *scanline++ = mac->m_rbv_palette[(pixels>>7)&1]; |
| 888 | *scanline++ = mac->m_rbv_palette[(pixels>>6)&1]; |
| 889 | *scanline++ = mac->m_rbv_palette[(pixels>>5)&1]; |
| 890 | *scanline++ = mac->m_rbv_palette[(pixels>>4)&1]; |
| 891 | *scanline++ = mac->m_rbv_palette[(pixels>>3)&1]; |
| 892 | *scanline++ = mac->m_rbv_palette[(pixels>>2)&1]; |
| 893 | *scanline++ = mac->m_rbv_palette[(pixels>>1)&1]; |
| 894 | *scanline++ = mac->m_rbv_palette[(pixels&1)]; |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | break; |
| 899 | |
| 900 | case 1: // 2bpp |
| 901 | { |
| 902 | UINT8 *vram8 = (UINT8 *)mac->m_vram; |
| 903 | UINT8 pixels; |
| 904 | vram8 += mac->m_dafb_base; |
| 905 | |
| 906 | for (y = 0; y < 870; y++) |
| 907 | { |
| 908 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 909 | for (x = 0; x < 1152/4; x++) |
| 910 | { |
| 911 | pixels = vram8[(y * mac->m_dafb_stride) + (BYTE4_XOR_BE(x))]; |
| 912 | |
| 913 | *scanline++ = mac->m_rbv_palette[((pixels>>6)&3)]; |
| 914 | *scanline++ = mac->m_rbv_palette[((pixels>>4)&3)]; |
| 915 | *scanline++ = mac->m_rbv_palette[((pixels>>2)&3)]; |
| 916 | *scanline++ = mac->m_rbv_palette[(pixels&3)]; |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | break; |
| 921 | |
| 922 | case 2: // 4bpp |
| 923 | { |
| 924 | UINT8 *vram8 = (UINT8 *)mac->m_vram; |
| 925 | UINT8 pixels; |
| 926 | vram8 += mac->m_dafb_base; |
| 927 | |
| 928 | for (y = 0; y < 870; y++) |
| 929 | { |
| 930 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 931 | |
| 932 | for (x = 0; x < 1152/2; x++) |
| 933 | { |
| 934 | pixels = vram8[(y * mac->m_dafb_stride) + (BYTE4_XOR_BE(x))]; |
| 935 | |
| 936 | *scanline++ = mac->m_rbv_palette[(pixels>>4)]; |
| 937 | *scanline++ = mac->m_rbv_palette[(pixels&0xf)]; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | break; |
| 942 | |
| 943 | case 3: // 8bpp |
| 944 | { |
| 945 | UINT8 *vram8 = (UINT8 *)mac->m_vram; |
| 946 | UINT8 pixels; |
| 947 | vram8 += mac->m_dafb_base; |
| 948 | |
| 949 | for (y = 0; y < 870; y++) |
| 950 | { |
| 951 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 952 | |
| 953 | for (x = 0; x < 1152; x++) |
| 954 | { |
| 955 | pixels = vram8[(y * mac->m_dafb_stride) + (BYTE4_XOR_BE(x))]; |
| 956 | *scanline++ = mac->m_rbv_palette[pixels]; |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | break; |
| 961 | |
| 962 | case 4: // 24 bpp |
| 963 | for (y = 0; y < 480; y++) |
| 964 | { |
| 965 | UINT32 *base; |
| 966 | |
| 967 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 968 | base = (UINT32 *)&mac->m_vram[(y * (mac->m_dafb_stride/4)) + (mac->m_dafb_base/4)]; |
| 969 | for (x = 0; x < 640; x++) |
| 970 | { |
| 971 | *scanline++ = *base++; |
| 972 | } |
| 973 | } |
| 974 | break; |
| 975 | } |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
src/mess/drivers/mac.c
| r13161 | r13162 | |
| 44 | 44 | #include "cpu/m6805/m6805.h" |
| 45 | 45 | #include "machine/6522via.h" |
| 46 | 46 | #include "machine/ncr5380.h" |
| 47 | | #include "machine/am53cf96.h" |
| 48 | 47 | #include "machine/applefdc.h" |
| 49 | 48 | #include "devices/sonydriv.h" |
| 50 | 49 | #include "imagedev/harddriv.h" |
| r13161 | r13162 | |
| 201 | 200 | UINT8 slot_irqs = (~m_rbv_regs[2]) & 0x78; |
| 202 | 201 | slot_irqs &= (m_rbv_regs[0x12] & 0x78); |
| 203 | 202 | |
| 204 | | // printf("slot_irqs = %02x\n", slot_irqs); |
| 205 | 203 | if (slot_irqs) |
| 206 | 204 | { |
| 207 | 205 | m_rbv_regs[3] |= 2; // any slot |
| r13161 | r13162 | |
| 556 | 554 | |
| 557 | 555 | READ8_MEMBER(mac_state::mac_5396_r) |
| 558 | 556 | { |
| 557 | if (offset < 0x100) |
| 558 | { |
| 559 | return m_539x_1->read(space, offset>>4); |
| 560 | } |
| 561 | else // pseudo-DMA: read from the FIFO |
| 562 | { |
| 563 | return m_539x_1->read(space, 2); |
| 564 | } |
| 565 | |
| 559 | 566 | return 0; |
| 560 | 567 | } |
| 561 | 568 | |
| 562 | 569 | WRITE8_MEMBER(mac_state::mac_5396_w) |
| 563 | 570 | { |
| 564 | | // printf("%02x to 5396 @ %x\n", data, offset); |
| 571 | if (offset < 0x100) |
| 572 | { |
| 573 | m_539x_1->write(space, offset>>4, data); |
| 574 | } |
| 575 | else // pseudo-DMA: write to the FIFO |
| 576 | { |
| 577 | m_539x_1->write(space, 2, data); |
| 578 | } |
| 565 | 579 | } |
| 566 | 580 | |
| 567 | 581 | /*************************************************************************** |
| r13161 | r13162 | |
| 754 | 768 | static ADDRESS_MAP_START(quadra700_map, AS_PROGRAM, 32, mac_state ) |
| 755 | 769 | AM_RANGE(0x40000000, 0x400fffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0ff00000) |
| 756 | 770 | |
| 757 | | AM_RANGE(0x50000000, 0x50001fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000) |
| 758 | | AM_RANGE(0x50002000, 0x50003fff) AM_READWRITE16(mac_via2_r, mac_via2_w, 0xffffffff) AM_MIRROR(0x00f00000) |
| 771 | AM_RANGE(0x50000000, 0x50001fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00fc0000) |
| 772 | AM_RANGE(0x50002000, 0x50003fff) AM_READWRITE16(mac_via2_r, mac_via2_w, 0xffffffff) AM_MIRROR(0x00fc0000) |
| 759 | 773 | // 50008000 = Ethernet MAC ID PROM |
| 760 | 774 | // 5000a000 = Sonic (DP83932) ethernet |
| 761 | 775 | // 5000f000 = SCSI cf96, 5000f402 = SCSI #2 cf96 |
| 762 | | AM_RANGE(0x5000f000, 0x5000f3ff) AM_READWRITE8(mac_5396_r, mac_5396_w, 0xffffffff) AM_MIRROR(0x00f00000) |
| 763 | | AM_RANGE(0x5000c000, 0x5000dfff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff) AM_MIRROR(0x00f00000) |
| 764 | | AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00f00000) |
| 765 | | AM_RANGE(0x5001e000, 0x5001ffff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000) |
| 776 | AM_RANGE(0x5000f000, 0x5000f3ff) AM_READWRITE8(mac_5396_r, mac_5396_w, 0xffffffff) AM_MIRROR(0x00fc0000) |
| 777 | AM_RANGE(0x5000c000, 0x5000dfff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff) AM_MIRROR(0x00fc0000) |
| 778 | AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00fc0000) |
| 779 | AM_RANGE(0x5001e000, 0x5001ffff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00fc0000) |
| 766 | 780 | |
| 767 | | AM_RANGE(0x50040000, 0x50041fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000) |
| 781 | AM_RANGE(0x50040000, 0x50041fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00fc0000) |
| 768 | 782 | // f9800000 = VDAC / DAFB |
| 769 | 783 | AM_RANGE(0xf9000000, 0xf91fffff) AM_RAM AM_BASE(m_vram) |
| 770 | 784 | AM_RANGE(0xf9800000, 0xf98001ff) AM_READWRITE(dafb_r, dafb_w) |
| r13161 | r13162 | |
| 826 | 840 | mac_scsi_irq // IRQ (unconnected on the Mac Plus) |
| 827 | 841 | }; |
| 828 | 842 | |
| 843 | static const struct NCR539Xinterface mac_539x_intf = |
| 844 | { |
| 845 | &dev_table, // SCSI device table |
| 846 | DEVCB_DRIVER_LINE_MEMBER(mac_state, irq_539x_1_w), |
| 847 | DEVCB_DRIVER_LINE_MEMBER(mac_state, drq_539x_1_w) |
| 848 | }; |
| 849 | |
| 829 | 850 | static const struct nbbus_interface nubus_intf = |
| 830 | 851 | { |
| 831 | 852 | // interrupt lines |
| r13161 | r13162 | |
| 854 | 875 | /*************************************************************************** |
| 855 | 876 | MACHINE DRIVERS |
| 856 | 877 | ***************************************************************************/ |
| 857 | | static const floppy_interface mac128512_floppy_interface = //SONY_FLOPPY_ALLOW400K |
| 858 | | { |
| 859 | | DEVCB_NULL, |
| 860 | | DEVCB_NULL, |
| 861 | | DEVCB_NULL, |
| 862 | | DEVCB_NULL, |
| 863 | | DEVCB_NULL, |
| 864 | | FLOPPY_STANDARD_3_5_DSHD, |
| 865 | | LEGACY_FLOPPY_OPTIONS_NAME(apple35_mac), |
| 866 | | NULL, |
| 867 | | NULL |
| 868 | | }; |
| 869 | 878 | |
| 870 | | |
| 871 | 879 | static const floppy_interface mac_floppy_interface = |
| 872 | 880 | { |
| 873 | 881 | DEVCB_NULL, |
| r13161 | r13162 | |
| 913 | 921 | |
| 914 | 922 | /* devices */ |
| 915 | 923 | MCFG_IWM_ADD("fdc", mac_iwm_interface) |
| 916 | | MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac128512_floppy_interface) |
| 924 | MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac_floppy_interface) |
| 917 | 925 | |
| 918 | 926 | MCFG_SCC8530_ADD("scc", C7M) |
| 919 | 927 | MCFG_SCC8530_IRQ(mac_scc_irq) |
| r13161 | r13162 | |
| 994 | 1002 | MCFG_NCR5380_ADD("ncr5380", C7M, macplus_5380intf) |
| 995 | 1003 | |
| 996 | 1004 | MCFG_IWM_ADD("fdc", mac_iwm_interface) |
| 997 | | MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac128512_floppy_interface) |
| 1005 | MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac_floppy_interface) |
| 998 | 1006 | |
| 999 | 1007 | MCFG_SCC8530_ADD("scc", C7M) |
| 1000 | 1008 | MCFG_SCC8530_IRQ(mac_scc_irq) |
| r13161 | r13162 | |
| 1564 | 1572 | |
| 1565 | 1573 | MCFG_SCREEN_ADD(MAC_SCREEN_NAME, RASTER) |
| 1566 | 1574 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 1567 | | MCFG_SCREEN_RAW_PARAMS(25175000, 800, 0, 640, 525, 0, 480) |
| 1568 | | MCFG_SCREEN_VISIBLE_AREA(0, 640-1, 0, 480-1) |
| 1569 | | MCFG_SCREEN_UPDATE(macrbvvram) |
| 1575 | MCFG_SCREEN_REFRESH_RATE(75.08) |
| 1576 | MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1260)) |
| 1577 | MCFG_SCREEN_SIZE(1152, 870) |
| 1578 | MCFG_SCREEN_VISIBLE_AREA(0, 1152-1, 0, 870-1) |
| 1579 | MCFG_SCREEN_UPDATE(macdafb) |
| 1570 | 1580 | |
| 1571 | 1581 | MCFG_VIDEO_START(macdafb) |
| 1572 | 1582 | MCFG_VIDEO_RESET(macdafb) |
| r13161 | r13162 | |
| 1596 | 1606 | MCFG_VIA6522_ADD("via6522_0", C7M/10, mac_via6522_adb_intf) |
| 1597 | 1607 | MCFG_VIA6522_ADD("via6522_1", C7M/10, mac_via6522_2_intf) |
| 1598 | 1608 | |
| 1609 | MCFG_NCR539X_ADD(MAC_539X_1_TAG, C7M, mac_539x_intf) |
| 1610 | |
| 1599 | 1611 | MCFG_HARDDISK_ADD( "harddisk1" ) |
| 1600 | 1612 | MCFG_HARDDISK_ADD( "harddisk2" ) |
| 1601 | 1613 | |
| 1602 | 1614 | /* internal ram */ |
| 1603 | 1615 | MCFG_RAM_ADD(RAM_TAG) |
| 1604 | 1616 | MCFG_RAM_DEFAULT_SIZE("4M") |
| 1605 | | MCFG_RAM_EXTRA_OPTIONS("8M,20M,36M,68M") // QD700 has 4M on board and can take 4M, 8M, 16M, or 32M SIMMs |
| 1617 | MCFG_RAM_EXTRA_OPTIONS("8M,16M,32M,64M,68M,72M,80M,96M,128M") |
| 1606 | 1618 | MACHINE_CONFIG_END |
| 1607 | 1619 | |
| 1608 | 1620 | static INPUT_PORTS_START( macplus ) |