src/mess/machine/z80sti.c
| r4952 | r4953 | |
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | | Mostek Z80STI Serial Timer Interrupt Controller emulation |
| 3 | Mostek MK3801 Serial Timer Interrupt Controller (Z80-STI) emulation |
| 4 | 4 | |
| 5 | | Copyright (c) 2009, The MESS Team. |
| 5 | Copyright MESS Team. |
| 6 | 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | 7 | |
| 8 | 8 | ***************************************************************************/ |
| r4952 | r4953 | |
| 11 | 11 | |
| 12 | 12 | TODO: |
| 13 | 13 | |
| 14 | | - timers |
| 15 | | - serial |
| 14 | - timers (other than delay mode) |
| 15 | - serial I/O |
| 16 | - reset behavior |
| 16 | 17 | |
| 17 | 18 | */ |
| 18 | 19 | |
| r4952 | r4953 | |
| 29 | 30 | |
| 30 | 31 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 31 | 32 | |
| 33 | /* registers */ |
| 32 | 34 | enum |
| 33 | 35 | { |
| 34 | 36 | Z80STI_REGISTER_IR = 0, |
| r4952 | r4953 | |
| 49 | 51 | Z80STI_REGISTER_UDR |
| 50 | 52 | }; |
| 51 | 53 | |
| 54 | /* variable registers */ |
| 52 | 55 | enum |
| 53 | 56 | { |
| 54 | 57 | Z80STI_REGISTER_IR_SCR = 0, |
| r4952 | r4953 | |
| 61 | 64 | Z80STI_REGISTER_IR_TCDC |
| 62 | 65 | }; |
| 63 | 66 | |
| 67 | /* timers */ |
| 64 | 68 | enum |
| 65 | 69 | { |
| 66 | | Z80STI_TIMER_A = 0, |
| 67 | | Z80STI_TIMER_B, |
| 68 | | Z80STI_TIMER_C, |
| 69 | | Z80STI_TIMER_D, |
| 70 | | Z80STI_MAX_TIMERS |
| 70 | TIMER_A = 0, |
| 71 | TIMER_B, |
| 72 | TIMER_C, |
| 73 | TIMER_D, |
| 74 | TIMER_COUNT |
| 71 | 75 | }; |
| 72 | 76 | |
| 77 | /* interrupt levels */ |
| 73 | 78 | enum |
| 74 | 79 | { |
| 75 | 80 | Z80STI_IR_P0 = 0, |
| r4952 | r4953 | |
| 90 | 95 | Z80STI_IR_P7 |
| 91 | 96 | }; |
| 92 | 97 | |
| 98 | /* timer C/D control register */ |
| 99 | #define Z80STI_TCDC_TARS 0x80 |
| 100 | #define Z80STI_TCDC_TBRS 0x08 |
| 101 | |
| 102 | /* interrupt vector register */ |
| 103 | #define Z80STI_PVR_ISE 0x08 |
| 104 | #define Z80STI_PVR_VR4 0x10 |
| 105 | |
| 106 | /* general purpose I/O interrupt levels */ |
| 93 | 107 | static const int INT_LEVEL_GPIP[] = |
| 94 | 108 | { |
| 95 | 109 | Z80STI_IR_P0, Z80STI_IR_P1, Z80STI_IR_P2, Z80STI_IR_P3, Z80STI_IR_P4, Z80STI_IR_P5, Z80STI_IR_P6, Z80STI_IR_P7 |
| 96 | 110 | }; |
| 97 | 111 | |
| 112 | /* timer interrupt levels */ |
| 98 | 113 | static const int INT_LEVEL_TIMER[] = |
| 99 | 114 | { |
| 100 | 115 | Z80STI_IR_TA, Z80STI_IR_TB, Z80STI_IR_TC, Z80STI_IR_TD |
| 101 | 116 | }; |
| 102 | 117 | |
| 118 | /* interrupt vectors */ |
| 103 | 119 | static const UINT8 INT_VECTOR[] = |
| 104 | 120 | { |
| 105 | | 0x00, 0x01, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e |
| 121 | 0x00, 0x01, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, |
| 122 | 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e |
| 106 | 123 | }; |
| 107 | 124 | |
| 125 | /* timer prescaler divisors */ |
| 108 | 126 | static const int PRESCALER[] = { 0, 4, 10, 16, 50, 64, 100, 200 }; |
| 109 | 127 | |
| 110 | 128 | /*************************************************************************** |
| r4952 | r4953 | |
| 114 | 132 | typedef struct _z80sti_t z80sti_t; |
| 115 | 133 | struct _z80sti_t |
| 116 | 134 | { |
| 117 | | devcb_resolved_read8 in_gpio_func; |
| 118 | | devcb_resolved_write8 out_gpio_func; |
| 119 | | devcb_resolved_read_line in_si_func; |
| 120 | | devcb_resolved_write_line out_so_func; |
| 121 | | devcb_resolved_write_line out_tao_func; |
| 122 | | devcb_resolved_write_line out_tbo_func; |
| 123 | | devcb_resolved_write_line out_tco_func; |
| 124 | | devcb_resolved_write_line out_tdo_func; |
| 125 | | devcb_resolved_write_line out_int_func; |
| 135 | /* device callbacks */ |
| 136 | devcb_resolved_read8 in_gpio_func; |
| 137 | devcb_resolved_write8 out_gpio_func; |
| 138 | devcb_resolved_read_line in_si_func; |
| 139 | devcb_resolved_write_line out_so_func; |
| 140 | devcb_resolved_write_line out_tao_func; |
| 141 | devcb_resolved_write_line out_tbo_func; |
| 142 | devcb_resolved_write_line out_tco_func; |
| 143 | devcb_resolved_write_line out_tdo_func; |
| 144 | devcb_resolved_write_line out_int_func; |
| 126 | 145 | |
| 127 | 146 | /* I/O state */ |
| 128 | 147 | UINT8 gpip; /* general purpose I/O register */ |
| r4952 | r4953 | |
| 134 | 153 | UINT16 ipr; /* interrupt pending register */ |
| 135 | 154 | UINT16 isr; /* interrupt in-service register */ |
| 136 | 155 | UINT16 imr; /* interrupt mask register */ |
| 137 | | UINT8 pvr; /* */ |
| 156 | UINT8 pvr; /* interrupt vector register */ |
| 138 | 157 | int int_state[16]; /* interrupt state */ |
| 139 | 158 | |
| 140 | 159 | /* timer state */ |
| 141 | 160 | UINT8 tabc; /* timer A/B control register */ |
| 142 | 161 | UINT8 tcdc; /* timer C/D control register */ |
| 143 | | UINT8 tdr[Z80STI_MAX_TIMERS]; /* timer data registers */ |
| 144 | | UINT8 tmc[Z80STI_MAX_TIMERS]; /* timer main counters */ |
| 145 | | int to[Z80STI_MAX_TIMERS]; /* timer out latch */ |
| 162 | UINT8 tdr[TIMER_COUNT]; /* timer data registers */ |
| 163 | UINT8 tmc[TIMER_COUNT]; /* timer main counters */ |
| 164 | int to[TIMER_COUNT]; /* timer out latch */ |
| 146 | 165 | |
| 147 | 166 | /* serial state */ |
| 148 | 167 | UINT8 scr; /* synchronous character register */ |
| r4952 | r4953 | |
| 152 | 171 | UINT8 udr; /* USART data register */ |
| 153 | 172 | |
| 154 | 173 | /* timers */ |
| 155 | | emu_timer *timer[Z80STI_MAX_TIMERS]; /* counter timers */ |
| 156 | | emu_timer *rx_timer; /* serial receive timer */ |
| 157 | | emu_timer *tx_timer; /* serial transmit timer */ |
| 174 | emu_timer *timer[TIMER_COUNT]; /* counter timers */ |
| 175 | emu_timer *rx_timer; /* serial receive timer */ |
| 176 | emu_timer *tx_timer; /* serial transmit timer */ |
| 158 | 177 | }; |
| 159 | 178 | |
| 160 | 179 | /*************************************************************************** |
| r4952 | r4953 | |
| 210 | 229 | |
| 211 | 230 | static void take_interrupt(z80sti_t *z80sti, int level) |
| 212 | 231 | { |
| 232 | /* set interrupt pending register bit */ |
| 213 | 233 | z80sti->ipr |= 1 << level; |
| 214 | 234 | |
| 215 | 235 | /* trigger interrupt */ |
| r4952 | r4953 | |
| 272 | 292 | switch (z80sti->pvr & 0x07) |
| 273 | 293 | { |
| 274 | 294 | case Z80STI_REGISTER_IR_SCR: return z80sti->scr; |
| 275 | | case Z80STI_REGISTER_IR_TDDR: return z80sti->tmc[Z80STI_TIMER_D]; |
| 276 | | case Z80STI_REGISTER_IR_TCDR: return z80sti->tmc[Z80STI_TIMER_C]; |
| 295 | case Z80STI_REGISTER_IR_TDDR: return z80sti->tmc[TIMER_D]; |
| 296 | case Z80STI_REGISTER_IR_TCDR: return z80sti->tmc[TIMER_C]; |
| 277 | 297 | case Z80STI_REGISTER_IR_AER: return z80sti->aer; |
| 278 | 298 | case Z80STI_REGISTER_IR_IERB: return z80sti->ier & 0xff; |
| 279 | 299 | case Z80STI_REGISTER_IR_IERA: return z80sti->ier >> 8; |
| r4952 | r4953 | |
| 291 | 311 | case Z80STI_REGISTER_IMRA: return z80sti->imr >> 8; |
| 292 | 312 | case Z80STI_REGISTER_PVR: return z80sti->pvr; |
| 293 | 313 | case Z80STI_REGISTER_TABC: return z80sti->tabc; |
| 294 | | case Z80STI_REGISTER_TBDR: return z80sti->tmc[Z80STI_TIMER_B]; |
| 295 | | case Z80STI_REGISTER_TADR: return z80sti->tmc[Z80STI_TIMER_A]; |
| 314 | case Z80STI_REGISTER_TBDR: return z80sti->tmc[TIMER_B]; |
| 315 | case Z80STI_REGISTER_TADR: return z80sti->tmc[TIMER_A]; |
| 296 | 316 | case Z80STI_REGISTER_UCR: return z80sti->ucr; |
| 297 | 317 | case Z80STI_REGISTER_RSR: return z80sti->rsr; |
| 298 | 318 | case Z80STI_REGISTER_TSR: return z80sti->tsr; |
| r4952 | r4953 | |
| 315 | 335 | case Z80STI_REGISTER_IR: |
| 316 | 336 | switch (z80sti->pvr & 0x07) |
| 317 | 337 | { |
| 318 | | /* |
| 319 | 338 | case Z80STI_REGISTER_IR_SCR: |
| 320 | 339 | LOG(("Z80STI '%s' Sync Character Register: %x\n", device->tag, data)); |
| 321 | 340 | z80sti->scr = data; |
| 322 | 341 | break; |
| 323 | | */ |
| 342 | |
| 324 | 343 | case Z80STI_REGISTER_IR_TDDR: |
| 325 | 344 | LOG(("Z80STI '%s' Timer D Data Register: %x\n", device->tag, data)); |
| 326 | | z80sti->tdr[Z80STI_TIMER_D] = data; |
| 345 | z80sti->tdr[TIMER_D] = data; |
| 327 | 346 | break; |
| 328 | 347 | |
| 329 | 348 | case Z80STI_REGISTER_IR_TCDR: |
| 330 | 349 | LOG(("Z80STI '%s' Timer C Data Register: %x\n", device->tag, data)); |
| 331 | | z80sti->tdr[Z80STI_TIMER_C] = data; |
| 350 | z80sti->tdr[TIMER_C] = data; |
| 332 | 351 | break; |
| 333 | 352 | |
| 334 | 353 | case Z80STI_REGISTER_IR_AER: |
| r4952 | r4953 | |
| 337 | 356 | break; |
| 338 | 357 | |
| 339 | 358 | case Z80STI_REGISTER_IR_IERB: |
| 340 | | LOG(("Z80STI '%s' Interrupt Enable B Register: %x\n", device->tag, data)); |
| 359 | LOG(("Z80STI '%s' Interrupt Enable Register B: %x\n", device->tag, data)); |
| 341 | 360 | z80sti->ier = (z80sti->ier & 0xff00) | data; |
| 342 | 361 | check_interrupts(z80sti); |
| 343 | 362 | break; |
| 344 | 363 | |
| 345 | 364 | case Z80STI_REGISTER_IR_IERA: |
| 346 | | LOG(("Z80STI '%s' Interrupt Enable A Register: %x\n", device->tag, data)); |
| 365 | LOG(("Z80STI '%s' Interrupt Enable Register A: %x\n", device->tag, data)); |
| 347 | 366 | z80sti->ier = (data << 8) | (z80sti->ier & 0xff); |
| 348 | 367 | check_interrupts(z80sti); |
| 349 | 368 | break; |
| r4952 | r4953 | |
| 354 | 373 | break; |
| 355 | 374 | |
| 356 | 375 | case Z80STI_REGISTER_IR_TCDC: |
| 376 | { |
| 377 | int tcc = PRESCALER[(data >> 4) & 0x07]; |
| 378 | int tdc = PRESCALER[data & 0x07]; |
| 379 | |
| 357 | 380 | z80sti->tcdc = data; |
| 381 | |
| 382 | LOG(("Z80STI '%s' Timer C Prescaler: %u\n", device->tag, tcc)); |
| 383 | LOG(("Z80STI '%s' Timer D Prescaler: %u\n", device->tag, tdc)); |
| 384 | |
| 385 | if (tcc) |
| 386 | timer_adjust_periodic(z80sti->timer[TIMER_C], ATTOTIME_IN_HZ(device->clock / tcc), 0, ATTOTIME_IN_HZ(device->clock / tcc)); |
| 387 | else |
| 388 | timer_enable(z80sti->timer[TIMER_C], 0); |
| 389 | |
| 390 | if (tdc) |
| 391 | timer_adjust_periodic(z80sti->timer[TIMER_D], ATTOTIME_IN_HZ(device->clock / tdc), 0, ATTOTIME_IN_HZ(device->clock / tdc)); |
| 392 | else |
| 393 | timer_enable(z80sti->timer[TIMER_D], 0); |
| 394 | |
| 395 | if (BIT(data, 7)) |
| 396 | { |
| 397 | LOG(("Z80STI '%s' Timer A Reset\n", device->tag)); |
| 398 | z80sti->to[TIMER_A] = 0; |
| 399 | |
| 400 | devcb_call_write_line(&z80sti->out_tao_func, z80sti->to[TIMER_A]); |
| 401 | } |
| 402 | |
| 403 | if (BIT(data, 3)) |
| 404 | { |
| 405 | LOG(("Z80STI '%s' Timer B Reset\n", device->tag)); |
| 406 | z80sti->to[TIMER_B] = 0; |
| 407 | |
| 408 | devcb_call_write_line(&z80sti->out_tbo_func, z80sti->to[TIMER_B]); |
| 409 | } |
| 410 | } |
| 358 | 411 | break; |
| 359 | | |
| 360 | | default: |
| 361 | | LOG(("Z80STI '%s' Unimplemented IR Register %x\n", device->tag, z80sti->pvr & 0x07)); |
| 362 | 412 | } |
| 363 | 413 | break; |
| 364 | 414 | |
| r4952 | r4953 | |
| 369 | 419 | break; |
| 370 | 420 | |
| 371 | 421 | case Z80STI_REGISTER_IPRB: |
| 372 | | LOG(("Z80STI '%s' Interrupt Pending B Register: %x\n", device->tag, data)); |
| 422 | LOG(("Z80STI '%s' Interrupt Pending Register B: %x\n", device->tag, data)); |
| 373 | 423 | z80sti->ipr = (z80sti->ipr & 0xff00) | data; |
| 374 | 424 | check_interrupts(z80sti); |
| 375 | 425 | break; |
| 376 | 426 | |
| 377 | 427 | case Z80STI_REGISTER_IPRA: |
| 378 | | LOG(("Z80STI '%s' Interrupt Pending A Register: %x\n", device->tag, data)); |
| 428 | LOG(("Z80STI '%s' Interrupt Pending Register A: %x\n", device->tag, data)); |
| 379 | 429 | z80sti->ipr = (data << 8) | (z80sti->ipr & 0xff); |
| 380 | 430 | check_interrupts(z80sti); |
| 381 | 431 | break; |
| 382 | 432 | |
| 383 | 433 | case Z80STI_REGISTER_ISRB: |
| 384 | | LOG(("Z80STI '%s' Interrupt In-Service B Register: %x\n", device->tag, data)); |
| 434 | LOG(("Z80STI '%s' Interrupt In-Service Register B: %x\n", device->tag, data)); |
| 385 | 435 | z80sti->isr = (z80sti->isr & 0xff00) | data; |
| 386 | 436 | break; |
| 387 | 437 | |
| 388 | 438 | case Z80STI_REGISTER_ISRA: |
| 389 | | LOG(("Z80STI '%s' Interrupt In-Service A Register: %x\n", device->tag, data)); |
| 439 | LOG(("Z80STI '%s' Interrupt In-Service Register A: %x\n", device->tag, data)); |
| 390 | 440 | z80sti->isr = (data << 8) | (z80sti->isr & 0xff); |
| 391 | 441 | break; |
| 392 | 442 | |
| 393 | 443 | case Z80STI_REGISTER_IMRB: |
| 394 | | LOG(("Z80STI '%s' Interrupt Mask B Register: %x\n", device->tag, data)); |
| 444 | LOG(("Z80STI '%s' Interrupt Mask Register B: %x\n", device->tag, data)); |
| 395 | 445 | z80sti->imr = (data << 8) | (z80sti->imr & 0xff); |
| 396 | 446 | check_interrupts(z80sti); |
| 397 | 447 | break; |
| 398 | 448 | |
| 399 | 449 | case Z80STI_REGISTER_IMRA: |
| 400 | | LOG(("Z80STI '%s' Interrupt Mask A Register: %x\n", device->tag, data)); |
| 450 | LOG(("Z80STI '%s' Interrupt Mask Register A: %x\n", device->tag, data)); |
| 401 | 451 | z80sti->imr = (data << 8) | (z80sti->imr & 0xff); |
| 402 | 452 | check_interrupts(z80sti); |
| 403 | 453 | break; |
| 404 | 454 | |
| 405 | 455 | case Z80STI_REGISTER_PVR: |
| 456 | LOG(("Z80STI '%s' Interrupt Vector: %02x\n", device->tag, data & 0xe0)); |
| 457 | LOG(("Z80STI '%s' IR Address: %01x\n", device->tag, data & 0x07)); |
| 406 | 458 | z80sti->pvr = data; |
| 407 | 459 | break; |
| 408 | 460 | |
| 409 | 461 | case Z80STI_REGISTER_TABC: |
| 462 | { |
| 463 | int tac = PRESCALER[(data >> 4) & 0x07]; |
| 464 | int tbc = PRESCALER[data & 0x07]; |
| 465 | |
| 410 | 466 | z80sti->tabc = data; |
| 467 | |
| 468 | LOG(("Z80STI '%s' Timer A Prescaler: %u\n", device->tag, tac)); |
| 469 | LOG(("Z80STI '%s' Timer B Prescaler: %u\n", device->tag, tbc)); |
| 470 | |
| 471 | if (tac) |
| 472 | timer_adjust_periodic(z80sti->timer[TIMER_A], ATTOTIME_IN_HZ(device->clock / tac), 0, ATTOTIME_IN_HZ(device->clock / tac)); |
| 473 | else |
| 474 | timer_enable(z80sti->timer[TIMER_A], 0); |
| 475 | |
| 476 | if (tbc) |
| 477 | timer_adjust_periodic(z80sti->timer[TIMER_B], ATTOTIME_IN_HZ(device->clock / tbc), 0, ATTOTIME_IN_HZ(device->clock / tbc)); |
| 478 | else |
| 479 | timer_enable(z80sti->timer[TIMER_B], 0); |
| 480 | } |
| 411 | 481 | break; |
| 412 | 482 | |
| 413 | 483 | case Z80STI_REGISTER_TBDR: |
| 414 | 484 | LOG(("Z80STI '%s' Timer B Data Register: %x\n", device->tag, data)); |
| 415 | | z80sti->tdr[Z80STI_TIMER_B] = data; |
| 485 | z80sti->tdr[TIMER_B] = data; |
| 416 | 486 | break; |
| 417 | 487 | |
| 418 | 488 | case Z80STI_REGISTER_TADR: |
| 419 | 489 | LOG(("Z80STI '%s' Timer A Data Register: %x\n", device->tag, data)); |
| 420 | | z80sti->tdr[Z80STI_TIMER_A] = data; |
| 490 | z80sti->tdr[TIMER_A] = data; |
| 421 | 491 | break; |
| 422 | 492 | /* |
| 423 | 493 | case Z80STI_REGISTER_UCR: |
| r4952 | r4953 | |
| 437 | 507 | break; |
| 438 | 508 | */ |
| 439 | 509 | default: |
| 440 | | LOG(("Z80STI '%s' Unimplemented Register %x\n", device->tag, offset & 0x0f)); |
| 510 | LOG(("Z80STI '%s' Unsupported Register %x\n", device->tag, offset & 0x0f)); |
| 441 | 511 | } |
| 442 | 512 | } |
| 443 | 513 | |
| r4952 | r4953 | |
| 473 | 543 | timer_count - timer count down |
| 474 | 544 | -------------------------------------------------*/ |
| 475 | 545 | |
| 476 | | static void timer_count(z80sti_t *z80sti, int index) |
| 546 | static void timer_count(const device_config *device, int index) |
| 477 | 547 | { |
| 548 | z80sti_t *z80sti = get_safe_token(device); |
| 549 | |
| 478 | 550 | if (z80sti->tmc[index] == 0x01) |
| 479 | 551 | { |
| 552 | //LOG(("Z80STI '%s' Timer %c Expired\n", device->tag, 'A' + index)); |
| 553 | |
| 480 | 554 | /* toggle timer output signal */ |
| 481 | 555 | z80sti->to[index] = !z80sti->to[index]; |
| 482 | 556 | |
| 483 | 557 | switch (index) |
| 484 | 558 | { |
| 485 | | case Z80STI_TIMER_A: devcb_call_write_line(&z80sti->out_tao_func, z80sti->to[index]); break; |
| 486 | | case Z80STI_TIMER_B: devcb_call_write_line(&z80sti->out_tbo_func, z80sti->to[index]); break; |
| 487 | | case Z80STI_TIMER_C: devcb_call_write_line(&z80sti->out_tco_func, z80sti->to[index]); break; |
| 488 | | case Z80STI_TIMER_D: devcb_call_write_line(&z80sti->out_tdo_func, z80sti->to[index]); break; |
| 559 | case TIMER_A: devcb_call_write_line(&z80sti->out_tao_func, z80sti->to[index]); break; |
| 560 | case TIMER_B: devcb_call_write_line(&z80sti->out_tbo_func, z80sti->to[index]); break; |
| 561 | case TIMER_C: devcb_call_write_line(&z80sti->out_tco_func, z80sti->to[index]); break; |
| 562 | case TIMER_D: devcb_call_write_line(&z80sti->out_tdo_func, z80sti->to[index]); break; |
| 489 | 563 | } |
| 490 | 564 | |
| 491 | | if (z80sti->ier & INT_LEVEL_TIMER[index]) |
| 565 | if (z80sti->ier & (1 << INT_LEVEL_TIMER[index])) |
| 492 | 566 | { |
| 567 | LOG(("Z80STI '%s' Interrupt Pending for Timer %c\n", device->tag, 'A' + index)); |
| 568 | |
| 493 | 569 | /* signal timer elapsed interrupt */ |
| 494 | 570 | take_interrupt(z80sti, INT_LEVEL_TIMER[index]); |
| 495 | 571 | } |
| 496 | 572 | |
| 497 | | /* load main counter */ |
| 573 | /* load timer main counter */ |
| 498 | 574 | z80sti->tmc[index] = z80sti->tdr[index]; |
| 499 | 575 | } |
| 500 | 576 | else |
| r4952 | r4953 | |
| 508 | 584 | TIMER_CALLBACK( timer_# ) |
| 509 | 585 | -------------------------------------------------*/ |
| 510 | 586 | |
| 511 | | static TIMER_CALLBACK( timer_a ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_A); } |
| 512 | | static TIMER_CALLBACK( timer_b ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_B); } |
| 513 | | static TIMER_CALLBACK( timer_c ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_C); } |
| 514 | | static TIMER_CALLBACK( timer_d ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_D); } |
| 587 | static TIMER_CALLBACK( timer_a ) { timer_count(ptr, TIMER_A); } |
| 588 | static TIMER_CALLBACK( timer_b ) { timer_count(ptr, TIMER_B); } |
| 589 | static TIMER_CALLBACK( timer_c ) { timer_count(ptr, TIMER_C); } |
| 590 | static TIMER_CALLBACK( timer_d ) { timer_count(ptr, TIMER_D); } |
| 515 | 591 | |
| 516 | 592 | /*------------------------------------------------- |
| 517 | | gpip_input - GPIP input write |
| 593 | gpip_input - GPIP input line write |
| 518 | 594 | -------------------------------------------------*/ |
| 519 | 595 | |
| 520 | 596 | static void gpip_input(const device_config *device, int bit, int state) |
| r4952 | r4953 | |
| 528 | 604 | { |
| 529 | 605 | LOG(("Z80STI '%s' Edge Transition Detected on Bit: %u\n", device->tag, bit)); |
| 530 | 606 | |
| 531 | | if (z80sti->ier & INT_LEVEL_GPIP[bit]) |
| 607 | if (z80sti->ier & (1 << INT_LEVEL_GPIP[bit])) |
| 532 | 608 | { |
| 533 | 609 | LOG(("Z80STI '%s' Interrupt Pending for P%u\n", device->tag, bit)); |
| 534 | 610 | |
| r4952 | r4953 | |
| 540 | 616 | } |
| 541 | 617 | |
| 542 | 618 | /*------------------------------------------------- |
| 543 | | z80sti_i#_w - input # write |
| 619 | z80sti_i#_w - GPIP input line # write |
| 544 | 620 | -------------------------------------------------*/ |
| 545 | 621 | |
| 546 | 622 | WRITE_LINE_DEVICE_HANDLER( z80sti_i0_w ) { gpip_input(device, 0, state); } |
| r4952 | r4953 | |
| 673 | 749 | devcb_resolve_write_line(&z80sti->out_int_func, &intf->out_int_func, device); |
| 674 | 750 | |
| 675 | 751 | /* create the counter timers */ |
| 676 | | z80sti->timer[Z80STI_TIMER_A] = timer_alloc(device->machine, timer_a, (void *)device); |
| 677 | | z80sti->timer[Z80STI_TIMER_B] = timer_alloc(device->machine, timer_b, (void *)device); |
| 678 | | z80sti->timer[Z80STI_TIMER_C] = timer_alloc(device->machine, timer_c, (void *)device); |
| 679 | | z80sti->timer[Z80STI_TIMER_D] = timer_alloc(device->machine, timer_d, (void *)device); |
| 752 | z80sti->timer[TIMER_A] = timer_alloc(device->machine, timer_a, (void *)device); |
| 753 | z80sti->timer[TIMER_B] = timer_alloc(device->machine, timer_b, (void *)device); |
| 754 | z80sti->timer[TIMER_C] = timer_alloc(device->machine, timer_c, (void *)device); |
| 755 | z80sti->timer[TIMER_D] = timer_alloc(device->machine, timer_d, (void *)device); |
| 680 | 756 | |
| 681 | 757 | /* create serial receive clock timer */ |
| 682 | 758 | if (intf->rx_clock > 0) |
| r4952 | r4953 | |
| 745 | 821 | |
| 746 | 822 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 747 | 823 | case DEVINFO_STR_NAME: strcpy(info->s, "Mostek MK3801"); break; |
| 748 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Z80 STI"); break; |
| 824 | case DEVINFO_STR_FAMILY: strcpy(info->s, "Z80-STI"); break; |
| 749 | 825 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 750 | 826 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 751 | 827 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
src/mess/drivers/prof80.c
| r4952 | r4953 | |
| 1 | 1 | /* |
| 2 | 2 | |
| 3 | 3 | PROF-80 (Prozessor RAM-Floppy Kontroller) |
| 4 | | GRIP-1/2/3/5 (Grafik-Interface-Prozessor) |
| 4 | GRIP-1/2/3/4/5 (Grafik-Interface-Prozessor) |
| 5 | UNIO-1 (?) |
| 5 | 6 | |
| 6 | 7 | http://www.prof80.de/ |
| 7 | 8 | http://oldcomputers.dyndns.org/public/pub/rechner/conitec/info.html |
| r4952 | r4953 | |
| 12 | 13 | |
| 13 | 14 | TODO: |
| 14 | 15 | |
| 16 | - PPI8255 Mode 2 is broken |
| 17 | - MC6845 DE callback is broken |
| 15 | 18 | - Z80 STI (Mostek MK3801) push-model |
| 16 | | - PROF-GRIP communications |
| 19 | - RAM banking |
| 20 | - floppy access |
| 17 | 21 | - UNIO card (Z80-STI, Z80-SIO, 2x centronics) |
| 18 | 22 | - GRIP-COLOR (192kB color RAM) |
| 19 | | - GRIP 1/2/3/5 selection |
| 23 | - GRIP 1/2/3/4/5 selection |
| 20 | 24 | |
| 21 | 25 | */ |
| 22 | 26 | |
| r4952 | r4953 | |
| 260 | 264 | prof80_bankswitch(space->machine); |
| 261 | 265 | } |
| 262 | 266 | |
| 267 | static READ8_HANDLER( gripc_r ) |
| 268 | { |
| 269 | prof80_state *state = space->machine->driver_data; |
| 270 | |
| 271 | return state->ecb_status; |
| 272 | } |
| 273 | |
| 274 | static READ8_HANDLER( gripd_r ) |
| 275 | { |
| 276 | prof80_state *state = space->machine->driver_data; |
| 277 | |
| 278 | /* trigger GRIP 8255 port C bit 6 (_ACKA) */ |
| 279 | ppi8255_set_port_c(state->ppi8255, 0x54); |
| 280 | ppi8255_set_port_c(state->ppi8255, 0x14); |
| 281 | ppi8255_set_port_c(state->ppi8255, 0x54); |
| 282 | |
| 283 | return state->ecb_data; |
| 284 | } |
| 285 | |
| 286 | static WRITE8_HANDLER( gripd_w ) |
| 287 | { |
| 288 | prof80_state *state = space->machine->driver_data; |
| 289 | |
| 290 | state->ecb_data = data; |
| 291 | |
| 292 | /* trigger GRIP 8255 port C bit 4 (_STBA) */ |
| 293 | ppi8255_set_port_c(state->ppi8255, 0x54); |
| 294 | ppi8255_set_port_c(state->ppi8255, 0x44); |
| 295 | ppi8255_set_port_c(state->ppi8255, 0x54); |
| 296 | } |
| 297 | |
| 263 | 298 | /* GRIP */ |
| 264 | 299 | |
| 265 | 300 | static WRITE8_HANDLER( page_w ) |
| r4952 | r4953 | |
| 327 | 362 | centronics_strobe_w(state->centronics, 1); |
| 328 | 363 | } |
| 329 | 364 | |
| 330 | | static READ8_HANDLER( gripc_r ) |
| 331 | | { |
| 332 | | prof80_state *state = space->machine->driver_data; |
| 365 | /* UNIO */ |
| 333 | 366 | |
| 334 | | return state->ecb_status; |
| 335 | | } |
| 336 | | |
| 337 | | static READ8_HANDLER( gripd_r ) |
| 367 | static WRITE8_HANDLER( unio_ctrl_w ) |
| 338 | 368 | { |
| 339 | | prof80_state *state = space->machine->driver_data; |
| 369 | // prof80_state *state = space->machine->driver_data; |
| 340 | 370 | |
| 341 | | /* trigger GRIP 8255 port C */ |
| 342 | | ppi8255_set_port_c(state->ppi8255, 0x44); |
| 371 | // int flag = BIT(data, 0); |
| 372 | int flad = (data >> 1) & 0x07; |
| 343 | 373 | |
| 344 | | return state->ecb_data; |
| 374 | switch (flad) |
| 375 | { |
| 376 | case 0: /* CG1 */ |
| 377 | case 1: /* CG2 */ |
| 378 | case 2: /* _STB1 */ |
| 379 | case 3: /* _STB2 */ |
| 380 | case 4: /* _INIT */ |
| 381 | case 5: /* JSO0 */ |
| 382 | case 6: /* JSO1 */ |
| 383 | case 7: /* JSO2 */ |
| 384 | break; |
| 385 | } |
| 345 | 386 | } |
| 346 | 387 | |
| 347 | | static WRITE8_HANDLER( gripd_w ) |
| 348 | | { |
| 349 | | prof80_state *state = space->machine->driver_data; |
| 350 | | |
| 351 | | state->ecb_data = data; |
| 352 | | |
| 353 | | /* trigger GRIP 8255 port C */ |
| 354 | | ppi8255_set_port_c(state->ppi8255, 0x14); |
| 355 | | } |
| 356 | | |
| 357 | 388 | /* Memory Maps */ |
| 358 | 389 | |
| 359 | 390 | static ADDRESS_MAP_START( prof80_mem, ADDRESS_SPACE_PROGRAM, 8 ) |
| r4952 | r4953 | |
| 376 | 407 | ADDRESS_MAP_END |
| 377 | 408 | |
| 378 | 409 | static ADDRESS_MAP_START( prof80_io, ADDRESS_SPACE_IO, 8 ) |
| 379 | | // AM_RANGE(0x80, 0x8f) AM_MIRROR(0xff00) AM_DEVREADWRITE(Z80STI_TAG, z80sti_r, z80sti_w) |
| 380 | | // AM_RANGE(0x94, 0x95) AM_MIRROR(0xff00) AM_DEVREADWRITE(Z80SIO_TAG, z80sio_d_r, z80sio_d_w) |
| 381 | | // AM_RANGE(0x96, 0x97) AM_MIRROR(0xff00) AM_DEVREADWRITE(Z80SIO_TAG, z80sio_c_r, z80sio_c_w) |
| 382 | | // AM_RANGE(0x9e, 0x9e) AM_MIRROR(0xff00) AM_WRITE(unio_w) (4=_STB1, 6=_STB2, 8=INIT) |
| 383 | | // AM_RANGE(0x9c, 0x9c) AM_MIRROR(0xff00) AM_DEVWRITE("centronics1", centronics_data_w) |
| 384 | | // AM_RANGE(0x9d, 0x9d) AM_MIRROR(0xff00) AM_DEVWRITE("centronics2", centronics_data_w) |
| 410 | // AM_RANGE(0x80, 0x8f) AM_MIRROR(0xff00) AM_DEVREADWRITE(UNIO_Z80STI_TAG, z80sti_r, z80sti_w) |
| 411 | // AM_RANGE(0x94, 0x95) AM_MIRROR(0xff00) AM_DEVREADWRITE(UNIO_Z80SIO_TAG, z80sio_d_r, z80sio_d_w) |
| 412 | // AM_RANGE(0x96, 0x97) AM_MIRROR(0xff00) AM_DEVREADWRITE(UNIO_Z80SIO_TAG, z80sio_c_r, z80sio_c_w) |
| 413 | AM_RANGE(0x9e, 0x9e) AM_MIRROR(0xff00) AM_WRITE(unio_ctrl_w) |
| 414 | // AM_RANGE(0x9c, 0x9c) AM_MIRROR(0xff00) AM_DEVWRITE(UNIO_CENTRONICS1_TAG, centronics_data_w) |
| 415 | // AM_RANGE(0x9d, 0x9d) AM_MIRROR(0xff00) AM_DEVWRITE(UNIO_CENTRONICS1_TAG, centronics_data_w) |
| 385 | 416 | AM_RANGE(0xc0, 0xc0) AM_MIRROR(0xff00) AM_READ(gripc_r) |
| 386 | 417 | AM_RANGE(0xc1, 0xc1) AM_MIRROR(0xff00) AM_READWRITE(gripd_r, gripd_w) |
| 387 | 418 | AM_RANGE(0xd8, 0xd8) AM_MIRROR(0xff00) AM_WRITE(flr_w) |
| r4952 | r4953 | |
| 449 | 480 | { |
| 450 | 481 | prof80_state *state = device->machine->driver_data; |
| 451 | 482 | |
| 483 | // logerror("DE changed to %u\n", display_enabled); |
| 484 | |
| 452 | 485 | z80sti_i1_w(state->z80sti, display_enabled); |
| 453 | 486 | } |
| 454 | 487 | |
| r4952 | r4953 | |
| 582 | 615 | |
| 583 | 616 | bit signal description |
| 584 | 617 | |
| 585 | | PC0 STI I4 |
| 586 | | PC1 KBF |
| 587 | | PC2 _KBSTB |
| 588 | | PC3 STI I7 |
| 589 | | PC4 1 when PROF-80 reads port 0xc0 |
| 590 | | PC5 PA6 |
| 591 | | PC6 1 when PROF-80 writes port 0xc0 |
| 592 | | PC7 PA7 |
| 618 | PC0 INTRB interrupt B output (keyboard) |
| 619 | PC1 KBF input buffer B full output (keyboard) |
| 620 | PC2 _KBSTB strobe B input (keyboard) |
| 621 | PC3 INTRA interrupt A output (PROF-80) |
| 622 | PC4 _STBA strobe A input (PROF-80) |
| 623 | PC5 IBFA input buffer A full output (PROF-80) |
| 624 | PC6 _ACKA acknowledge A input (PROF-80) |
| 625 | PC7 _OBFA output buffer full output (PROF-80) |
| 593 | 626 | |
| 594 | 627 | */ |
| 595 | 628 | |
| 596 | | return 0x04; |
| 629 | return 0x54; |
| 597 | 630 | } |
| 598 | 631 | |
| 599 | 632 | static WRITE8_DEVICE_HANDLER( grip_ppi8255_c_w ) |
| r4952 | r4953 | |
| 602 | 635 | |
| 603 | 636 | bit signal description |
| 604 | 637 | |
| 605 | | PC0 STI I4 |
| 606 | | PC1 KBF |
| 607 | | PC2 _KBSTB |
| 608 | | PC3 STI I7 |
| 609 | | PC4 1 when PROF-80 reads port 0xc0 |
| 610 | | PC5 PA6 |
| 611 | | PC6 1 when PROF-80 writes port 0xc0 |
| 612 | | PC7 PA7 |
| 638 | PC0 INTRB interrupt B output (keyboard) |
| 639 | PC1 KBF input buffer B full output (keyboard) |
| 640 | PC2 _KBSTB strobe B input (keyboard) |
| 641 | PC3 INTRA interrupt A output (PROF-80) |
| 642 | PC4 _STBA strobe A input (PROF-80) |
| 643 | PC5 IBFA input buffer A full output (PROF-80) |
| 644 | PC6 _ACKA acknowledge A input (PROF-80) |
| 645 | PC7 _OBFA output buffer full output (PROF-80) |
| 613 | 646 | |
| 614 | 647 | */ |
| 615 | 648 | |
| 616 | 649 | prof80_state *state = device->machine->driver_data; |
| 617 | 650 | |
| 618 | | state->ecb_status = (BIT(data, 7) << 7) | (BIT(data, 5) << 6); |
| 651 | /* keyboard interrupt */ |
| 652 | z80sti_i4_w(state->z80sti, BIT(data, 0)); |
| 653 | |
| 654 | /* PROF-80 interrupt */ |
| 655 | z80sti_i7_w(state->z80sti, BIT(data, 3)); |
| 656 | |
| 657 | /* PROF-80 handshaking */ |
| 658 | state->ecb_status = (!BIT(data, 7) << 7) | (!BIT(data, 5) << 6); |
| 659 | logerror("IBF %u OBF %u status %02x\n", BIT(data, 5), BIT(data, 7), state->ecb_status); |
| 619 | 660 | } |
| 620 | 661 | |
| 621 | 662 | static const ppi8255_interface grip_ppi8255_interface = |
| r4952 | r4953 | |
| 630 | 671 | |
| 631 | 672 | /* Z80-STI Interface */ |
| 632 | 673 | |
| 674 | static READ8_DEVICE_HANDLER( grip_z80sti_gpio_r ) |
| 675 | { |
| 676 | /* |
| 677 | |
| 678 | bit signal description |
| 679 | |
| 680 | I0 CTS RS-232 clear to send input |
| 681 | I1 DE MC6845 display enable input |
| 682 | I2 CURSOR MC6845 cursor input |
| 683 | I3 BUSY Centronics busy input |
| 684 | I4 PC0 PPI8255 PC0 input |
| 685 | I5 SKBD Serial keyboard input |
| 686 | I6 EXIN External interrupt input |
| 687 | I7 PC3 PPI8255 PC3 input |
| 688 | |
| 689 | */ |
| 690 | |
| 691 | // prof80_state *state = device->machine->driver_data; |
| 692 | |
| 693 | // return state->pc3 << 7 | state->exin << 6 | state->skbd << 5 | state->pc0 << 4 | busy << 3 | state->cursor << 2 | state->de << 1 | state->cts; |
| 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | static WRITE_LINE_DEVICE_HANDLER( grip_z80sti_tbo_w ) |
| 699 | { |
| 700 | // connected to speaker |
| 701 | } |
| 702 | |
| 633 | 703 | static WRITE_LINE_DEVICE_HANDLER( grip_z80sti_irq_w ) |
| 634 | 704 | { |
| 635 | | cputag_set_input_line(device->machine, "grip", INPUT_LINE_IRQ0, state); |
| 705 | cputag_set_input_line(device->machine, GRIP_Z80_TAG, INPUT_LINE_IRQ0, state); |
| 636 | 706 | } |
| 637 | 707 | |
| 638 | 708 | static Z80STI_INTERFACE( grip_z80sti_interface ) |
| 639 | 709 | { |
| 640 | | 0, |
| 641 | | 0, |
| 642 | | DEVCB_NULL, |
| 643 | | DEVCB_NULL, |
| 644 | | DEVCB_NULL, |
| 645 | | DEVCB_NULL, |
| 646 | | DEVCB_NULL, |
| 647 | | DEVCB_NULL, |
| 648 | | DEVCB_NULL, |
| 649 | | DEVCB_NULL, |
| 650 | | DEVCB_LINE(grip_z80sti_irq_w) |
| 710 | 0, /* serial receive clock */ |
| 711 | 0, /* serial transmit clock */ |
| 712 | DEVCB_DEVICE_HANDLER(Z80STI_TAG, grip_z80sti_gpio_r), /* GPIO read */ |
| 713 | DEVCB_NULL, /* GPIO write */ |
| 714 | DEVCB_NULL, /* serial input */ |
| 715 | DEVCB_NULL, /* serial output */ |
| 716 | DEVCB_NULL, /* timer A output */ |
| 717 | DEVCB_LINE(grip_z80sti_tbo_w), /* timer B output */ |
| 718 | DEVCB_LINE(z80sti_tc_w), /* timer C output */ |
| 719 | DEVCB_LINE(z80sti_rc_w), /* timer D output */ |
| 720 | DEVCB_LINE(grip_z80sti_irq_w) /* interrupt */ |
| 651 | 721 | }; |
| 652 | 722 | |
| 653 | 723 | /* Z80 Daisy Chain */ |
| r4952 | r4953 | |
| 707 | 777 | |
| 708 | 778 | static MACHINE_RESET( prof80 ) |
| 709 | 779 | { |
| 780 | prof80_state *state = machine->driver_data; |
| 781 | |
| 710 | 782 | int i; |
| 711 | 783 | |
| 712 | 784 | for (i = 0; i < 8; i++) |
| r4952 | r4953 | |
| 714 | 786 | // write all zeroes 0 flr_W |
| 715 | 787 | //UINT8 data = (i << 4) | (i << 1); |
| 716 | 788 | } |
| 789 | |
| 790 | state->ecb_status = 0x40; |
| 717 | 791 | } |
| 718 | 792 | |
| 719 | 793 | /* Machine Drivers */ |
| r4952 | r4953 | |
| 726 | 800 | MDRV_CPU_PROGRAM_MAP(prof80_mem) |
| 727 | 801 | MDRV_CPU_IO_MAP(prof80_io) |
| 728 | 802 | |
| 729 | | MDRV_CPU_ADD("grip", Z80, XTAL_16MHz/4) |
| 803 | MDRV_CPU_ADD(GRIP_Z80_TAG, Z80, XTAL_16MHz/4) |
| 730 | 804 | MDRV_CPU_CONFIG(grip_daisy_chain) |
| 731 | 805 | MDRV_CPU_PROGRAM_MAP(grip_mem) |
| 732 | 806 | MDRV_CPU_IO_MAP(grip_io) |
| r4952 | r4953 | |
| 779 | 853 | ROM_COPY( Z80_TAG, 0xf0000, 0x70000, 0x10000 ) // block 7 |
| 780 | 854 | ROM_COPY( Z80_TAG, 0xf0000, 0x60000, 0x10000 ) // block 6 |
| 781 | 855 | |
| 782 | | ROM_REGION( 0x10000, "grip", 0 ) |
| 856 | ROM_REGION( 0x10000, GRIP_Z80_TAG, 0 ) |
| 783 | 857 | ROM_LOAD( "grip21.z2", 0x0000, 0x4000, CRC(7f6a37dd) SHA1(2e89f0b0c378257ff7e41c50d57d90865c6e214b) ) |
| 784 | 858 | ROM_LOAD( "grip26.z2", 0x0000, 0x4000, CRC(a1c424f0) SHA1(83942bc75b9475f044f936b8d9d7540551d87db9) ) |
| 785 | 859 | ROM_LOAD( "grip31.z2", 0x0000, 0x4000, CRC(e0e4e8ab) SHA1(73d3d14c9b06fed0c187fb0fffe5ec035d8dd256) ) |