src/emu/machine/z80sio.c
| r3352 | r3353 | |
| 167 | 167 | int inbuf; /* input buffer */ |
| 168 | 168 | int outbuf; /* output buffer */ |
| 169 | 169 | UINT8 int_on_next_rx; /* interrupt on next rx? */ |
| 170 | | emu_timer *receive_timer; /* timer to clock data in */ |
| 170 | emu_timer * receive_timer; /* timer to clock data in */ |
| 171 | 171 | UINT8 receive_buffer[16]; /* buffer for incoming data */ |
| 172 | 172 | UINT8 receive_inptr; /* index of data coming in */ |
| 173 | 173 | UINT8 receive_outptr; /* index of data going out */ |
| r3352 | r3353 | |
| 179 | 179 | { |
| 180 | 180 | sio_channel chan[2]; /* 2 channels */ |
| 181 | 181 | UINT8 int_state[8]; /* interrupt states */ |
| 182 | UINT32 clock; /* clock value */ |
| 182 | 183 | |
| 183 | | void (*irq_cb)(running_machine *machine, int state); |
| 184 | | write8_machine_func dtr_changed_cb; |
| 185 | | write8_machine_func rts_changed_cb; |
| 186 | | write8_machine_func break_changed_cb; |
| 187 | | write8_machine_func transmit_cb; |
| 188 | | int (*receive_poll_cb)(int which); |
| 184 | void (*irq_cb)(const device_config *device, int state); |
| 185 | write8_device_func dtr_changed_cb; |
| 186 | write8_device_func rts_changed_cb; |
| 187 | write8_device_func break_changed_cb; |
| 188 | write8_device_func transmit_cb; |
| 189 | int (*receive_poll_cb)(const device_config *device, int channel); |
| 189 | 190 | }; |
| 190 | 191 | |
| 191 | 192 | |
| r3352 | r3353 | |
| 198 | 199 | |
| 199 | 200 | |
| 200 | 201 | |
| 201 | | /*************************************************************************** |
| 202 | | GLOBAL VARIABLES |
| 203 | | ***************************************************************************/ |
| 204 | | |
| 205 | | static z80sio sios[MAX_SIO]; |
| 206 | | |
| 207 | | |
| 208 | 202 | /* |
| 209 | 203 | |
| 210 | 204 | Interrupt priorities: |
| r3352 | r3353 | |
| 258 | 252 | |
| 259 | 253 | |
| 260 | 254 | /*************************************************************************** |
| 255 | FUNCTION PROTOTYPES |
| 256 | ***************************************************************************/ |
| 257 | |
| 258 | static int z80sio_irq_state(const device_config *device); |
| 259 | static int z80sio_irq_ack(const device_config *device); |
| 260 | static void z80sio_irq_reti(const device_config *device); |
| 261 | |
| 262 | |
| 263 | |
| 264 | /*************************************************************************** |
| 261 | 265 | INLINE FUNCTIONS |
| 262 | 266 | ***************************************************************************/ |
| 263 | 267 | |
| 264 | | INLINE void interrupt_check(running_machine *machine, z80sio *sio) |
| 268 | INLINE z80sio *get_safe_token(const device_config *device) |
| 265 | 269 | { |
| 270 | assert(device != NULL); |
| 271 | assert(device->token != NULL); |
| 272 | assert(device->type == Z80SIO); |
| 273 | return (z80sio *)device->token; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | INLINE void interrupt_check(const device_config *device) |
| 278 | { |
| 266 | 279 | /* if we have a callback, update it with the current state */ |
| 280 | z80sio *sio = get_safe_token(device); |
| 267 | 281 | if (sio->irq_cb != NULL) |
| 268 | | (*sio->irq_cb)(machine, (z80sio_irq_state(sio - sios) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE); |
| 282 | (*sio->irq_cb)(device, (z80sio_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE); |
| 269 | 283 | } |
| 270 | 284 | |
| 271 | 285 | |
| r3352 | r3353 | |
| 282 | 296 | ***************************************************************************/ |
| 283 | 297 | |
| 284 | 298 | /*------------------------------------------------- |
| 285 | | z80sio_init - initialize a single SIO chip |
| 286 | | -------------------------------------------------*/ |
| 287 | | |
| 288 | | void z80sio_init(int which, z80sio_interface *intf) |
| 289 | | { |
| 290 | | z80sio *sio = sios + which; |
| 291 | | |
| 292 | | assert(which < MAX_SIO); |
| 293 | | |
| 294 | | memset(sio, 0, sizeof(*sio)); |
| 295 | | |
| 296 | | sio->chan[0].receive_timer = timer_alloc(serial_callback, NULL); |
| 297 | | sio->chan[1].receive_timer = timer_alloc(serial_callback, NULL); |
| 298 | | |
| 299 | | sio->irq_cb = intf->irq_cb; |
| 300 | | sio->dtr_changed_cb = intf->dtr_changed_cb; |
| 301 | | sio->rts_changed_cb = intf->rts_changed_cb; |
| 302 | | sio->break_changed_cb = intf->break_changed_cb; |
| 303 | | sio->transmit_cb = intf->transmit_cb; |
| 304 | | sio->receive_poll_cb = intf->receive_poll_cb; |
| 305 | | |
| 306 | | z80sio_reset(which); |
| 307 | | } |
| 308 | | |
| 309 | | |
| 310 | | /*------------------------------------------------- |
| 311 | 299 | reset_channel - reset a single SIO channel |
| 312 | 300 | -------------------------------------------------*/ |
| 313 | 301 | |
| 314 | | static void reset_channel(running_machine *machine, z80sio *sio, int ch) |
| 302 | static void reset_channel(const device_config *device, int ch) |
| 315 | 303 | { |
| 304 | z80sio *sio = get_safe_token(device); |
| 316 | 305 | attotime tpc = compute_time_per_character(sio, ch); |
| 317 | 306 | sio_channel *chan = &sio->chan[ch]; |
| 318 | 307 | |
| r3352 | r3353 | |
| 327 | 316 | sio->int_state[2 + 4*ch] = 0; |
| 328 | 317 | sio->int_state[3 + 4*ch] = 0; |
| 329 | 318 | |
| 330 | | interrupt_check(machine, sio); |
| 319 | interrupt_check(device); |
| 331 | 320 | |
| 332 | 321 | /* start the receive timer running */ |
| 333 | | timer_adjust_periodic(chan->receive_timer, tpc, ((sio - sios) << 1) | ch, tpc); |
| 322 | timer_adjust_periodic(chan->receive_timer, tpc, ch, tpc); |
| 334 | 323 | } |
| 335 | 324 | |
| 336 | 325 | |
| 337 | | /*------------------------------------------------- |
| 338 | | z80sio_reset - reset a single SIO chip |
| 339 | | -------------------------------------------------*/ |
| 340 | 326 | |
| 341 | | void z80sio_reset(int which) |
| 342 | | { |
| 343 | | z80sio *sio = sios + which; |
| 344 | | int ch; |
| 345 | | |
| 346 | | assert(which < MAX_SIO); |
| 347 | | |
| 348 | | /* loop over channels */ |
| 349 | | for (ch = 0; ch < 2; ch++) |
| 350 | | reset_channel(Machine, sio, ch); |
| 351 | | } |
| 352 | | |
| 353 | | |
| 354 | | |
| 355 | 327 | /*************************************************************************** |
| 356 | 328 | CONTROL REGISTER READ/WRITE |
| 357 | 329 | ***************************************************************************/ |
| r3352 | r3353 | |
| 360 | 332 | z80sio_c_w - write to a control register |
| 361 | 333 | -------------------------------------------------*/ |
| 362 | 334 | |
| 363 | | void z80sio_c_w(running_machine *machine, int which, int ch, UINT8 data) |
| 335 | WRITE8_DEVICE_HANDLER( z80sio_c_w ) |
| 364 | 336 | { |
| 365 | | z80sio *sio = sios + which; |
| 337 | z80sio *sio = get_safe_token(device); |
| 338 | int ch = offset & 1; |
| 366 | 339 | sio_channel *chan = &sio->chan[ch]; |
| 367 | 340 | int reg = chan->regs[0] & 7; |
| 368 | 341 | UINT8 old = chan->regs[reg]; |
| r3352 | r3353 | |
| 386 | 359 | { |
| 387 | 360 | case SIO_WR0_COMMAND_CH_RESET: |
| 388 | 361 | VPRINTF(("%04X:SIO reset channel %c\n", activecpu_get_pc(), 'A' + ch)); |
| 389 | | reset_channel(machine, sio, ch); |
| 362 | reset_channel(device, ch); |
| 390 | 363 | break; |
| 391 | 364 | |
| 392 | 365 | case SIO_WR0_COMMAND_RES_STATUS_INT: |
| 393 | 366 | sio->int_state[INT_CHA_STATUS - 4*ch] &= ~Z80_DAISY_INT; |
| 394 | | interrupt_check(machine, sio); |
| 367 | interrupt_check(device); |
| 395 | 368 | break; |
| 396 | 369 | |
| 397 | 370 | case SIO_WR0_COMMAND_ENA_RX_INT: |
| 398 | 371 | chan->int_on_next_rx = TRUE; |
| 399 | | interrupt_check(machine, sio); |
| 372 | interrupt_check(device); |
| 400 | 373 | break; |
| 401 | 374 | |
| 402 | 375 | case SIO_WR0_COMMAND_RES_TX_INT: |
| 403 | 376 | sio->int_state[INT_CHA_TRANSMIT - 4*ch] &= ~Z80_DAISY_INT; |
| 404 | | interrupt_check(machine, sio); |
| 377 | interrupt_check(device); |
| 405 | 378 | break; |
| 406 | 379 | |
| 407 | 380 | case SIO_WR0_COMMAND_RES_ERROR: |
| 408 | 381 | sio->int_state[INT_CHA_ERROR - 4*ch] &= ~Z80_DAISY_INT; |
| 409 | | interrupt_check(machine, sio); |
| 382 | interrupt_check(device); |
| 410 | 383 | break; |
| 411 | 384 | } |
| 412 | 385 | break; |
| 413 | 386 | |
| 414 | 387 | /* SIO write register 1 */ |
| 415 | 388 | case 1: |
| 416 | | interrupt_check(machine, sio); |
| 389 | interrupt_check(device); |
| 417 | 390 | break; |
| 418 | 391 | |
| 419 | 392 | /* SIO write register 5 */ |
| 420 | 393 | case 5: |
| 421 | 394 | if (((old ^ data) & SIO_WR5_DTR) && sio->dtr_changed_cb) |
| 422 | | (*sio->dtr_changed_cb)(machine, ch, (data & SIO_WR5_DTR) != 0); |
| 395 | (*sio->dtr_changed_cb)(device, ch, (data & SIO_WR5_DTR) != 0); |
| 423 | 396 | if (((old ^ data) & SIO_WR5_SEND_BREAK) && sio->break_changed_cb) |
| 424 | | (*sio->break_changed_cb)(machine, ch, (data & SIO_WR5_SEND_BREAK) != 0); |
| 397 | (*sio->break_changed_cb)(device, ch, (data & SIO_WR5_SEND_BREAK) != 0); |
| 425 | 398 | if (((old ^ data) & SIO_WR5_RTS) && sio->rts_changed_cb) |
| 426 | | (*sio->rts_changed_cb)(machine, ch, (data & SIO_WR5_RTS) != 0); |
| 399 | (*sio->rts_changed_cb)(device, ch, (data & SIO_WR5_RTS) != 0); |
| 427 | 400 | break; |
| 428 | 401 | } |
| 429 | 402 | } |
| r3352 | r3353 | |
| 433 | 406 | z80sio_c_r - read from a control register |
| 434 | 407 | -------------------------------------------------*/ |
| 435 | 408 | |
| 436 | | UINT8 z80sio_c_r(int which, int ch) |
| 409 | READ8_DEVICE_HANDLER( z80sio_c_r ) |
| 437 | 410 | { |
| 438 | | z80sio *sio = sios + which; |
| 411 | z80sio *sio = get_safe_token(device); |
| 412 | int ch = offset & 1; |
| 439 | 413 | sio_channel *chan = &sio->chan[ch]; |
| 440 | 414 | int reg = chan->regs[0] & 7; |
| 441 | 415 | UINT8 result = chan->status[reg]; |
| r3352 | r3353 | |
| 446 | 420 | /* SIO read register 0 */ |
| 447 | 421 | case 0: |
| 448 | 422 | result &= ~SIO_RR0_INT_PENDING; |
| 449 | | if (z80sio_irq_state(which) & Z80_DAISY_INT) |
| 423 | if (z80sio_irq_state(device) & Z80_DAISY_INT) |
| 450 | 424 | result |= SIO_RR0_INT_PENDING; |
| 451 | 425 | break; |
| 452 | 426 | } |
| r3352 | r3353 | |
| 467 | 441 | z80sio_d_w - write to a data register |
| 468 | 442 | -------------------------------------------------*/ |
| 469 | 443 | |
| 470 | | void z80sio_d_w(running_machine *machine, int which, int ch, UINT8 data) |
| 444 | WRITE8_DEVICE_HANDLER( z80sio_d_w ) |
| 471 | 445 | { |
| 472 | | z80sio *sio = sios + which; |
| 446 | z80sio *sio = get_safe_token(device); |
| 447 | int ch = offset & 1; |
| 473 | 448 | sio_channel *chan = &sio->chan[ch]; |
| 474 | 449 | |
| 475 | 450 | VPRINTF(("%04X:sio_data_w(%c) = %02X\n", activecpu_get_pc(), 'A' + ch, data)); |
| r3352 | r3353 | |
| 483 | 458 | |
| 484 | 459 | /* reset the transmit interrupt */ |
| 485 | 460 | sio->int_state[INT_CHA_TRANSMIT - 4*ch] &= ~Z80_DAISY_INT; |
| 486 | | interrupt_check(machine, sio); |
| 461 | interrupt_check(device); |
| 487 | 462 | |
| 488 | 463 | /* stash the character */ |
| 489 | 464 | chan->outbuf = data; |
| r3352 | r3353 | |
| 494 | 469 | z80sio_d_r - read from a data register |
| 495 | 470 | -------------------------------------------------*/ |
| 496 | 471 | |
| 497 | | UINT8 z80sio_d_r(running_machine *machine, int which, int ch) |
| 472 | READ8_DEVICE_HANDLER( z80sio_d_r ) |
| 498 | 473 | { |
| 499 | | z80sio *sio = sios + which; |
| 474 | z80sio *sio = get_safe_token(device); |
| 475 | int ch = offset & 1; |
| 500 | 476 | sio_channel *chan = &sio->chan[ch]; |
| 501 | 477 | |
| 502 | 478 | /* update the status register */ |
| r3352 | r3353 | |
| 504 | 480 | |
| 505 | 481 | /* reset the receive interrupt */ |
| 506 | 482 | sio->int_state[INT_CHA_RECEIVE - 4*ch] &= ~Z80_DAISY_INT; |
| 507 | | interrupt_check(machine, sio); |
| 483 | interrupt_check(device); |
| 508 | 484 | |
| 509 | 485 | VPRINTF(("%04X:sio_data_r(%c) = %02X\n", activecpu_get_pc(), 'A' + ch, chan->inbuf)); |
| 510 | 486 | |
| r3352 | r3353 | |
| 522 | 498 | line |
| 523 | 499 | -------------------------------------------------*/ |
| 524 | 500 | |
| 525 | | int z80sio_get_dtr(int which, int ch) |
| 501 | READ8_DEVICE_HANDLER( z80sio_get_dtr ) |
| 526 | 502 | { |
| 527 | | z80sio *sio = sios + which; |
| 528 | | sio_channel *chan = &sio->chan[ch]; |
| 503 | z80sio *sio = get_safe_token(device); |
| 504 | sio_channel *chan = &sio->chan[offset & 1]; |
| 529 | 505 | return ((chan->regs[5] & SIO_WR5_DTR) != 0); |
| 530 | 506 | } |
| 531 | 507 | |
| r3352 | r3353 | |
| 535 | 511 | line |
| 536 | 512 | -------------------------------------------------*/ |
| 537 | 513 | |
| 538 | | int z80sio_get_rts(int which, int ch) |
| 514 | READ8_DEVICE_HANDLER( z80sio_get_rts ) |
| 539 | 515 | { |
| 540 | | z80sio *sio = sios + which; |
| 541 | | sio_channel *chan = &sio->chan[ch]; |
| 516 | z80sio *sio = get_safe_token(device); |
| 517 | sio_channel *chan = &sio->chan[offset & 1]; |
| 542 | 518 | return ((chan->regs[5] & SIO_WR5_RTS) != 0); |
| 543 | 519 | } |
| 544 | 520 | |
| r3352 | r3353 | |
| 550 | 526 | |
| 551 | 527 | static TIMER_CALLBACK( change_input_line ) |
| 552 | 528 | { |
| 553 | | z80sio *sio = sios + ((param >> 1) & 0x3f); |
| 529 | const device_config *device = ptr; |
| 530 | z80sio *sio = get_safe_token(device); |
| 554 | 531 | sio_channel *chan = &sio->chan[param & 1]; |
| 555 | 532 | UINT8 line = (param >> 8) & 0xff; |
| 556 | 533 | int state = (param >> 7) & 1; |
| r3352 | r3353 | |
| 571 | 548 | if (((old ^ chan->status[0]) & line) && (chan->regs[1] & SIO_WR1_STATUSINT_ENABLE)) |
| 572 | 549 | { |
| 573 | 550 | sio->int_state[INT_CHA_STATUS - 4*ch] |= Z80_DAISY_INT; |
| 574 | | interrupt_check(machine, sio); |
| 551 | interrupt_check(device); |
| 575 | 552 | } |
| 576 | 553 | } |
| 577 | 554 | |
| r3352 | r3353 | |
| 581 | 558 | line |
| 582 | 559 | -------------------------------------------------*/ |
| 583 | 560 | |
| 584 | | void z80sio_set_cts(int which, int ch, int state) |
| 561 | WRITE8_DEVICE_HANDLER( z80sio_set_cts ) |
| 585 | 562 | { |
| 586 | 563 | /* operate deferred */ |
| 587 | | timer_call_after_resynch(NULL, (SIO_RR0_CTS << 8) + (state != 0) * 0x80 + which * 2 + ch, change_input_line); |
| 564 | void *ptr = (void *)device; |
| 565 | timer_call_after_resynch(ptr, (SIO_RR0_CTS << 8) + (data != 0) * 0x80 + (offset & 1), change_input_line); |
| 588 | 566 | } |
| 589 | 567 | |
| 590 | 568 | |
| r3352 | r3353 | |
| 593 | 571 | line |
| 594 | 572 | -------------------------------------------------*/ |
| 595 | 573 | |
| 596 | | void z80sio_set_dcd(int which, int ch, int state) |
| 574 | WRITE8_DEVICE_HANDLER( z80sio_set_dcd ) |
| 597 | 575 | { |
| 598 | 576 | /* operate deferred */ |
| 599 | | timer_call_after_resynch(NULL, (SIO_RR0_DCD << 8) + (state != 0) * 0x80 + which * 2 + ch, change_input_line); |
| 577 | void *ptr = (void *)device; |
| 578 | timer_call_after_resynch(ptr, (SIO_RR0_DCD << 8) + (data != 0) * 0x80 + (offset & 1), change_input_line); |
| 600 | 579 | } |
| 601 | 580 | |
| 602 | 581 | |
| r3352 | r3353 | |
| 605 | 584 | input lines |
| 606 | 585 | -------------------------------------------------*/ |
| 607 | 586 | |
| 608 | | void z80sio_receive_data(int which, int ch, UINT8 data) |
| 587 | WRITE8_DEVICE_HANDLER( z80sio_receive_data ) |
| 609 | 588 | { |
| 610 | | z80sio *sio = sios + which; |
| 611 | | sio_channel *chan = &sio->chan[ch]; |
| 589 | z80sio *sio = get_safe_token(device); |
| 590 | sio_channel *chan = &sio->chan[offset & 1]; |
| 612 | 591 | int newinptr; |
| 613 | 592 | |
| 614 | 593 | /* put it on the queue */ |
| r3352 | r3353 | |
| 630 | 609 | |
| 631 | 610 | static TIMER_CALLBACK( serial_callback ) |
| 632 | 611 | { |
| 633 | | z80sio *sio = sios + (param >> 1); |
| 634 | | sio_channel *chan = &sio->chan[param & 1]; |
| 635 | | int ch = param & 1; |
| 612 | const device_config *device = ptr; |
| 613 | z80sio *sio = get_safe_token(device); |
| 614 | sio_channel *chan = &sio->chan[param]; |
| 615 | int ch = param; |
| 636 | 616 | int data = -1; |
| 637 | 617 | |
| 638 | 618 | /* first perform any outstanding transmits */ |
| r3352 | r3353 | |
| 642 | 622 | |
| 643 | 623 | /* actually transmit the character */ |
| 644 | 624 | if (sio->transmit_cb != NULL) |
| 645 | | (*sio->transmit_cb)(machine, ch, chan->outbuf); |
| 625 | (*sio->transmit_cb)(device, ch, chan->outbuf); |
| 646 | 626 | |
| 647 | 627 | /* update the status register */ |
| 648 | 628 | chan->status[0] |= SIO_RR0_TX_BUFFER_EMPTY; |
| r3352 | r3353 | |
| 651 | 631 | if (chan->regs[1] & SIO_WR1_TXINT_ENABLE) |
| 652 | 632 | { |
| 653 | 633 | sio->int_state[INT_CHA_TRANSMIT - 4*ch] |= Z80_DAISY_INT; |
| 654 | | interrupt_check(machine, sio); |
| 634 | interrupt_check(device); |
| 655 | 635 | } |
| 656 | 636 | |
| 657 | 637 | /* reset the output buffer */ |
| r3352 | r3353 | |
| 660 | 640 | |
| 661 | 641 | /* ask the polling callback if there is data to receive */ |
| 662 | 642 | if (sio->receive_poll_cb != NULL) |
| 663 | | data = (*sio->receive_poll_cb)(ch); |
| 643 | data = (*sio->receive_poll_cb)(device, ch); |
| 664 | 644 | |
| 665 | 645 | /* if we have buffered data, pull it */ |
| 666 | 646 | if (chan->receive_inptr != chan->receive_outptr) |
| r3352 | r3353 | |
| 695 | 675 | case SIO_WR1_RXINT_ALL_NOPARITY: |
| 696 | 676 | case SIO_WR1_RXINT_ALL_PARITY: |
| 697 | 677 | sio->int_state[INT_CHA_RECEIVE - 4*ch] |= Z80_DAISY_INT; |
| 698 | | interrupt_check(machine, sio); |
| 678 | interrupt_check(device); |
| 699 | 679 | break; |
| 700 | 680 | } |
| 701 | 681 | chan->int_on_next_rx = FALSE; |
| r3352 | r3353 | |
| 721 | 701 | }; |
| 722 | 702 | |
| 723 | 703 | |
| 724 | | int z80sio_irq_state(int which) |
| 704 | static int z80sio_irq_state(const device_config *device) |
| 725 | 705 | { |
| 726 | | z80sio *sio = sios + which; |
| 706 | z80sio *sio = get_safe_token(device); |
| 727 | 707 | int state = 0; |
| 728 | 708 | int i; |
| 729 | 709 | |
| r3352 | r3353 | |
| 749 | 729 | } |
| 750 | 730 | |
| 751 | 731 | |
| 752 | | int z80sio_irq_ack(int which) |
| 732 | static int z80sio_irq_ack(const device_config *device) |
| 753 | 733 | { |
| 754 | | z80sio *sio = sios + which; |
| 734 | z80sio *sio = get_safe_token(device); |
| 755 | 735 | int i; |
| 756 | 736 | |
| 757 | 737 | /* loop over all interrupt sources */ |
| r3352 | r3353 | |
| 766 | 746 | |
| 767 | 747 | /* clear interrupt, switch to the IEO state, and update the IRQs */ |
| 768 | 748 | sio->int_state[inum] = Z80_DAISY_IEO; |
| 769 | | interrupt_check(Machine, sio); |
| 749 | interrupt_check(device); |
| 770 | 750 | return sio->chan[1].regs[2] + inum * 2; |
| 771 | 751 | } |
| 772 | 752 | } |
| r3352 | r3353 | |
| 776 | 756 | } |
| 777 | 757 | |
| 778 | 758 | |
| 779 | | void z80sio_irq_reti(int which) |
| 759 | static void z80sio_irq_reti(const device_config *device) |
| 780 | 760 | { |
| 781 | | z80sio *sio = sios + which; |
| 761 | z80sio *sio = get_safe_token(device); |
| 782 | 762 | int i; |
| 783 | 763 | |
| 784 | 764 | /* loop over all interrupt sources */ |
| r3352 | r3353 | |
| 793 | 773 | |
| 794 | 774 | /* clear the IEO state and update the IRQs */ |
| 795 | 775 | sio->int_state[inum] &= ~Z80_DAISY_IEO; |
| 796 | | interrupt_check(Machine, sio); |
| 776 | interrupt_check(device); |
| 797 | 777 | return; |
| 798 | 778 | } |
| 799 | 779 | } |
| 800 | 780 | |
| 801 | 781 | logerror("z80sio_irq_reti: failed to find an interrupt to clear IEO on!\n"); |
| 802 | 782 | } |
| 783 | |
| 784 | |
| 785 | static DEVICE_START( z80sio ) |
| 786 | { |
| 787 | const z80sio_interface *intf = device->static_config; |
| 788 | z80sio *sio = get_safe_token(device); |
| 789 | void *ptr = (void *)device; |
| 790 | int cpunum = -1; |
| 791 | |
| 792 | if (intf->cpu != NULL) |
| 793 | cpunum = mame_find_cpu_index(device->machine, intf->cpu); |
| 794 | if (cpunum != -1) |
| 795 | sio->clock = device->machine->config->cpu[cpunum].clock; |
| 796 | else |
| 797 | sio->clock = intf->baseclock; |
| 798 | |
| 799 | sio->chan[0].receive_timer = timer_alloc(serial_callback, ptr); |
| 800 | sio->chan[1].receive_timer = timer_alloc(serial_callback, ptr); |
| 801 | |
| 802 | sio->irq_cb = intf->irq_cb; |
| 803 | sio->dtr_changed_cb = intf->dtr_changed_cb; |
| 804 | sio->rts_changed_cb = intf->rts_changed_cb; |
| 805 | sio->break_changed_cb = intf->break_changed_cb; |
| 806 | sio->transmit_cb = intf->transmit_cb; |
| 807 | sio->receive_poll_cb = intf->receive_poll_cb; |
| 808 | |
| 809 | return DEVICE_START_OK; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | static DEVICE_RESET( z80sio ) |
| 814 | { |
| 815 | int ch; |
| 816 | |
| 817 | /* loop over channels */ |
| 818 | for (ch = 0; ch < 2; ch++) |
| 819 | reset_channel(device, ch); |
| 820 | } |
| 821 | |
| 822 | |
| 823 | static DEVICE_SET_INFO( z80sio ) |
| 824 | { |
| 825 | switch (state) |
| 826 | { |
| 827 | /* no parameters to set */ |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | |
| 832 | DEVICE_GET_INFO( z80sio ) |
| 833 | { |
| 834 | switch (state) |
| 835 | { |
| 836 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 837 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(z80sio); break; |
| 838 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 839 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 840 | |
| 841 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 842 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(z80sio); break; |
| 843 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(z80sio);break; |
| 844 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 845 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(z80sio);break; |
| 846 | case DEVINFO_FCT_IRQ_STATE: info->f = (genf *)z80sio_irq_state; break; |
| 847 | case DEVINFO_FCT_IRQ_ACK: info->f = (genf *)z80sio_irq_ack; break; |
| 848 | case DEVINFO_FCT_IRQ_RETI: info->f = (genf *)z80sio_irq_reti; break; |
| 849 | |
| 850 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 851 | case DEVINFO_STR_NAME: info->s = "Zilog Z80 SIO"; break; |
| 852 | case DEVINFO_STR_FAMILY: info->s = "Z80"; break; |
| 853 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 854 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 855 | case DEVINFO_STR_CREDITS: info->s = "Copyright Nicola Salmoria and the MAME Team"; break; |
| 856 | } |
| 857 | } |
| 858 | |
src/emu/machine/z80ctc.c
| r3352 | r3353 | |
| 10 | 10 | ***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | #include "driver.h" |
| 13 | | #include "deprecat.h" |
| 14 | 13 | #include "z80ctc.h" |
| 15 | 14 | #include "cpu/z80/z80.h" |
| 16 | 15 | #include "cpu/z80/z80daisy.h" |
| r3352 | r3353 | |
| 73 | 72 | TYPE DEFINITIONS |
| 74 | 73 | ***************************************************************************/ |
| 75 | 74 | |
| 75 | typedef struct _ctc_channel ctc_channel; |
| 76 | struct _ctc_channel |
| 77 | { |
| 78 | write8_device_func zc; /* zero crossing callbacks */ |
| 79 | UINT8 notimer; /* no timer masks */ |
| 80 | UINT16 mode; /* current mode */ |
| 81 | UINT16 tconst; /* time constant */ |
| 82 | UINT16 down; /* down counter (clock mode only) */ |
| 83 | UINT8 extclk; /* current signal from the external clock */ |
| 84 | emu_timer * timer; /* array of active timers */ |
| 85 | UINT8 int_state; /* interrupt status (for daisy chain) */ |
| 86 | }; |
| 87 | |
| 88 | |
| 76 | 89 | typedef struct _z80ctc z80ctc; |
| 77 | 90 | struct _z80ctc |
| 78 | 91 | { |
| 79 | | UINT8 vector; /* interrupt vector */ |
| 80 | | UINT32 clock; /* system clock */ |
| 81 | | attotime period16; /* 16/system clock */ |
| 82 | | attotime period256; /* 256/system clock */ |
| 83 | | void (*intr)(running_machine *machine, int which); /* interrupt callback */ |
| 84 | | write8_machine_func zc[4]; /* zero crossing callbacks */ |
| 85 | | UINT8 notimer; /* no timer masks */ |
| 86 | | UINT16 mode[4]; /* current mode */ |
| 87 | | UINT16 tconst[4]; /* time constant */ |
| 88 | | UINT16 down[4]; /* down counter (clock mode only) */ |
| 89 | | UINT8 extclk[4]; /* current signal from the external clock */ |
| 90 | | emu_timer *timer[4]; /* array of active timers */ |
| 91 | | UINT8 int_state[4]; /* interrupt status (for daisy chain) */ |
| 92 | UINT8 vector; /* interrupt vector */ |
| 93 | UINT32 clock; /* system clock */ |
| 94 | attotime period16; /* 16/system clock */ |
| 95 | attotime period256; /* 256/system clock */ |
| 96 | void (*intr)(const device_config *device, int which); /* interrupt callback */ |
| 97 | ctc_channel channel[4]; /* data for each channel */ |
| 92 | 98 | }; |
| 93 | 99 | |
| 94 | 100 | |
| 95 | 101 | |
| 96 | 102 | /*************************************************************************** |
| 97 | | GLOBAL VARIABLES |
| 103 | FUNCTION PROTOTYPES |
| 98 | 104 | ***************************************************************************/ |
| 99 | 105 | |
| 100 | | static z80ctc ctcs[MAX_CTC]; |
| 106 | static int z80ctc_irq_state(const device_config *device); |
| 107 | static int z80ctc_irq_ack(const device_config *device); |
| 108 | static void z80ctc_irq_reti(const device_config *device); |
| 101 | 109 | |
| 102 | 110 | |
| 103 | 111 | |
| 104 | 112 | /*************************************************************************** |
| 113 | INLINE FUNCTIONS |
| 114 | ***************************************************************************/ |
| 115 | |
| 116 | INLINE z80ctc *get_safe_token(const device_config *device) |
| 117 | { |
| 118 | assert(device != NULL); |
| 119 | assert(device->token != NULL); |
| 120 | assert(device->type == Z80CTC); |
| 121 | return (z80ctc *)device->token; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | |
| 126 | /*************************************************************************** |
| 105 | 127 | INTERNAL STATE MANAGEMENT |
| 106 | 128 | ***************************************************************************/ |
| 107 | 129 | |
| 108 | | static void interrupt_check(running_machine *machine, int which) |
| 130 | static void interrupt_check(const device_config *device) |
| 109 | 131 | { |
| 110 | | z80ctc *ctc = ctcs + which; |
| 132 | z80ctc *ctc = get_safe_token(device); |
| 111 | 133 | |
| 112 | 134 | /* if we have a callback, update it with the current state */ |
| 113 | | if (ctc->intr) |
| 114 | | (*ctc->intr)(machine, (z80ctc_irq_state(which) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE); |
| 135 | if (ctc->intr != NULL) |
| 136 | (*ctc->intr)(device, (z80ctc_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE); |
| 115 | 137 | } |
| 116 | 138 | |
| 117 | 139 | |
| 118 | 140 | static TIMER_CALLBACK( timercallback ) |
| 119 | 141 | { |
| 120 | | int which = param >> 2; |
| 121 | | int ch = param & 3; |
| 122 | | z80ctc *ctc = ctcs + which; |
| 142 | const device_config *device = ptr; |
| 143 | z80ctc *ctc = get_safe_token(device); |
| 144 | ctc_channel *channel = &ctc->channel[param]; |
| 123 | 145 | |
| 124 | 146 | /* down counter has reached zero - see if we should interrupt */ |
| 125 | | if ((ctc->mode[ch] & INTERRUPT) == INTERRUPT_ON) |
| 147 | if ((channel->mode & INTERRUPT) == INTERRUPT_ON) |
| 126 | 148 | { |
| 127 | | ctc->int_state[ch] |= Z80_DAISY_INT; |
| 128 | | VPRINTF(("CTC timer ch%d\n", ch)); |
| 129 | | interrupt_check(machine, which); |
| 149 | channel->int_state |= Z80_DAISY_INT; |
| 150 | VPRINTF(("CTC timer ch%d\n", param)); |
| 151 | interrupt_check(device); |
| 130 | 152 | } |
| 131 | 153 | |
| 132 | 154 | /* generate the clock pulse */ |
| 133 | | if (ctc->zc[ch]) |
| 155 | if (channel->zc != NULL) |
| 134 | 156 | { |
| 135 | | (*ctc->zc[ch])(machine,0,1); |
| 136 | | (*ctc->zc[ch])(machine,0,0); |
| 157 | (*channel->zc)(device, 0, 1); |
| 158 | (*channel->zc)(device, 0, 0); |
| 137 | 159 | } |
| 138 | 160 | |
| 139 | 161 | /* reset the down counter */ |
| 140 | | ctc->down[ch] = ctc->tconst[ch]; |
| 162 | channel->down = channel->tconst; |
| 141 | 163 | } |
| 142 | 164 | |
| 143 | 165 | |
| r3352 | r3353 | |
| 146 | 168 | INITIALIZATION/CONFIGURATION |
| 147 | 169 | ***************************************************************************/ |
| 148 | 170 | |
| 149 | | void z80ctc_init(int which, z80ctc_interface *intf) |
| 171 | attotime z80ctc_getperiod(const device_config *device, int ch) |
| 150 | 172 | { |
| 151 | | z80ctc *ctc = &ctcs[which]; |
| 152 | | |
| 153 | | assert(which < MAX_CTC); |
| 154 | | |
| 155 | | memset(ctc, 0, sizeof(*ctc)); |
| 156 | | |
| 157 | | ctc->clock = intf->baseclock; |
| 158 | | ctc->period16 = attotime_mul(ATTOTIME_IN_HZ(intf->baseclock), 16); |
| 159 | | ctc->period256 = attotime_mul(ATTOTIME_IN_HZ(intf->baseclock), 256); |
| 160 | | ctc->notimer = intf->notimer; |
| 161 | | ctc->intr = intf->intr; |
| 162 | | ctc->timer[0] = timer_alloc(timercallback, NULL); |
| 163 | | ctc->timer[1] = timer_alloc(timercallback, NULL); |
| 164 | | ctc->timer[2] = timer_alloc(timercallback, NULL); |
| 165 | | ctc->timer[3] = timer_alloc(timercallback, NULL); |
| 166 | | ctc->zc[0] = intf->zc0; |
| 167 | | ctc->zc[1] = intf->zc1; |
| 168 | | ctc->zc[2] = intf->zc2; |
| 169 | | ctc->zc[3] = 0; |
| 170 | | z80ctc_reset(which); |
| 171 | | |
| 172 | | state_save_register_item("z80ctc", which, ctc->vector); |
| 173 | | state_save_register_item_array("z80ctc", which, ctc->mode); |
| 174 | | state_save_register_item_array("z80ctc", which, ctc->tconst); |
| 175 | | state_save_register_item_array("z80ctc", which, ctc->down); |
| 176 | | state_save_register_item_array("z80ctc", which, ctc->extclk); |
| 177 | | state_save_register_item_array("z80ctc", which, ctc->int_state); |
| 178 | | } |
| 179 | | |
| 180 | | |
| 181 | | void z80ctc_reset(int which) |
| 182 | | { |
| 183 | | z80ctc *ctc = ctcs + which; |
| 184 | | int i; |
| 185 | | |
| 186 | | /* set up defaults */ |
| 187 | | for (i = 0; i < 4; i++) |
| 188 | | { |
| 189 | | ctc->mode[i] = RESET_ACTIVE; |
| 190 | | ctc->tconst[i] = 0x100; |
| 191 | | timer_adjust_oneshot(ctc->timer[i], attotime_never, 0); |
| 192 | | ctc->int_state[i] = 0; |
| 193 | | } |
| 194 | | interrupt_check(Machine, which); |
| 195 | | VPRINTF(("CTC Reset\n")); |
| 196 | | } |
| 197 | | |
| 198 | | |
| 199 | | attotime z80ctc_getperiod(int which, int ch) |
| 200 | | { |
| 201 | | z80ctc *ctc = ctcs + which; |
| 173 | z80ctc *ctc = get_safe_token(device); |
| 174 | ctc_channel *channel = &ctc->channel[ch]; |
| 202 | 175 | attotime period; |
| 203 | 176 | |
| 204 | 177 | /* if reset active, no period */ |
| 205 | | if ((ctc->mode[ch] & RESET) == RESET_ACTIVE) |
| 178 | if ((channel->mode & RESET) == RESET_ACTIVE) |
| 206 | 179 | return attotime_zero; |
| 207 | 180 | |
| 208 | 181 | /* if counter mode, no real period */ |
| 209 | | if ((ctc->mode[ch] & MODE) == MODE_COUNTER) |
| 182 | if ((channel->mode & MODE) == MODE_COUNTER) |
| 210 | 183 | { |
| 211 | 184 | logerror("CTC %d is CounterMode : Can't calculate period\n", ch ); |
| 212 | 185 | return attotime_zero; |
| 213 | 186 | } |
| 214 | 187 | |
| 215 | 188 | /* compute the period */ |
| 216 | | period = ((ctc->mode[ch] & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256; |
| 217 | | return attotime_mul(period, ctc->tconst[ch]); |
| 189 | period = ((channel->mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256; |
| 190 | return attotime_mul(period, channel->tconst); |
| 218 | 191 | } |
| 219 | 192 | |
| 220 | 193 | |
| r3352 | r3353 | |
| 223 | 196 | WRITE HANDLERS |
| 224 | 197 | ***************************************************************************/ |
| 225 | 198 | |
| 226 | | void z80ctc_w(int which, int ch, UINT8 data) |
| 199 | WRITE8_DEVICE_HANDLER( z80ctc_w ) |
| 227 | 200 | { |
| 228 | | z80ctc *ctc = ctcs + which; |
| 201 | z80ctc *ctc = get_safe_token(device); |
| 202 | int ch = offset & 3; |
| 203 | ctc_channel *channel = &ctc->channel[ch]; |
| 229 | 204 | int mode; |
| 230 | 205 | |
| 231 | 206 | /* get the current mode */ |
| 232 | | mode = ctc->mode[ch]; |
| 207 | mode = channel->mode; |
| 233 | 208 | |
| 234 | 209 | /* if we're waiting for a time constant, this is it */ |
| 235 | 210 | if ((mode & CONSTANT) == CONSTANT_LOAD) |
| r3352 | r3353 | |
| 237 | 212 | VPRINTF(("CTC ch.%d constant = %02x\n", ch, data)); |
| 238 | 213 | |
| 239 | 214 | /* set the time constant (0 -> 0x100) */ |
| 240 | | ctc->tconst[ch] = data ? data : 0x100; |
| 215 | channel->tconst = data ? data : 0x100; |
| 241 | 216 | |
| 242 | 217 | /* clear the internal mode -- we're no longer waiting */ |
| 243 | | ctc->mode[ch] &= ~CONSTANT; |
| 218 | channel->mode &= ~CONSTANT; |
| 244 | 219 | |
| 245 | 220 | /* also clear the reset, since the constant gets it going again */ |
| 246 | | ctc->mode[ch] &= ~RESET; |
| 221 | channel->mode &= ~RESET; |
| 247 | 222 | |
| 248 | 223 | /* if we're in timer mode.... */ |
| 249 | 224 | if ((mode & MODE) == MODE_TIMER) |
| r3352 | r3353 | |
| 251 | 226 | /* if we're triggering on the time constant, reset the down counter now */ |
| 252 | 227 | if ((mode & TRIGGER) == TRIGGER_AUTO) |
| 253 | 228 | { |
| 254 | | if (!(ctc->notimer & (1<<ch))) |
| 229 | if (!channel->notimer) |
| 255 | 230 | { |
| 256 | 231 | attotime period = ((mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256; |
| 257 | | period = attotime_mul(period, ctc->tconst[ch]); |
| 232 | period = attotime_mul(period, channel->tconst); |
| 258 | 233 | |
| 259 | | timer_adjust_periodic(ctc->timer[ch], period, (which << 2) + ch, period); |
| 234 | timer_adjust_periodic(channel->timer, period, ch, period); |
| 260 | 235 | } |
| 261 | 236 | else |
| 262 | | timer_adjust_oneshot(ctc->timer[ch], attotime_never, 0); |
| 237 | timer_adjust_oneshot(channel->timer, attotime_never, 0); |
| 263 | 238 | } |
| 264 | 239 | |
| 265 | 240 | /* else set the bit indicating that we're waiting for the appropriate trigger */ |
| 266 | 241 | else |
| 267 | | ctc->mode[ch] |= WAITING_FOR_TRIG; |
| 242 | channel->mode |= WAITING_FOR_TRIG; |
| 268 | 243 | } |
| 269 | 244 | |
| 270 | 245 | /* also set the down counter in case we're clocking externally */ |
| 271 | | ctc->down[ch] = ctc->tconst[ch]; |
| 246 | channel->down = channel->tconst; |
| 272 | 247 | |
| 273 | 248 | /* all done here */ |
| 274 | 249 | return; |
| r3352 | r3353 | |
| 292 | 267 | if ((data & CONTROL) == CONTROL_WORD) |
| 293 | 268 | { |
| 294 | 269 | /* set the new mode */ |
| 295 | | ctc->mode[ch] = data; |
| 270 | channel->mode = data; |
| 296 | 271 | VPRINTF(("CTC ch.%d mode = %02x\n", ch, data)); |
| 297 | 272 | |
| 298 | 273 | /* if we're being reset, clear out any pending timers for this channel */ |
| 299 | 274 | if ((data & RESET) == RESET_ACTIVE) |
| 300 | 275 | { |
| 301 | | timer_adjust_oneshot(ctc->timer[ch], attotime_never, 0); |
| 276 | timer_adjust_oneshot(channel->timer, attotime_never, 0); |
| 302 | 277 | /* note that we don't clear the interrupt state here! */ |
| 303 | 278 | } |
| 304 | 279 | |
| r3352 | r3353 | |
| 307 | 282 | } |
| 308 | 283 | } |
| 309 | 284 | |
| 310 | | WRITE8_HANDLER( z80ctc_0_w ) { z80ctc_w(0, offset, data); } |
| 311 | | WRITE8_HANDLER( z80ctc_1_w ) { z80ctc_w(1, offset, data); } |
| 312 | 285 | |
| 313 | 286 | |
| 314 | | |
| 315 | 287 | /*************************************************************************** |
| 316 | 288 | READ HANDLERS |
| 317 | 289 | ***************************************************************************/ |
| 318 | 290 | |
| 319 | | UINT8 z80ctc_r(int which, int ch) |
| 291 | READ8_DEVICE_HANDLER( z80ctc_r ) |
| 320 | 292 | { |
| 321 | | z80ctc *ctc = ctcs + which; |
| 293 | z80ctc *ctc = get_safe_token(device); |
| 294 | int ch = offset & 3; |
| 295 | ctc_channel *channel = &ctc->channel[ch]; |
| 322 | 296 | |
| 323 | 297 | /* if we're in counter mode, just return the count */ |
| 324 | | if ((ctc->mode[ch] & MODE) == MODE_COUNTER || (ctc->mode[ch] & WAITING_FOR_TRIG)) |
| 325 | | return ctc->down[ch]; |
| 298 | if ((channel->mode & MODE) == MODE_COUNTER || (channel->mode & WAITING_FOR_TRIG)) |
| 299 | return channel->down; |
| 326 | 300 | |
| 327 | 301 | /* else compute the down counter value */ |
| 328 | 302 | else |
| 329 | 303 | { |
| 330 | | attotime period = ((ctc->mode[ch] & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256; |
| 304 | attotime period = ((channel->mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256; |
| 331 | 305 | |
| 332 | 306 | VPRINTF(("CTC clock %f\n",ATTOSECONDS_TO_HZ(period.attoseconds))); |
| 333 | 307 | |
| 334 | | if (ctc->timer[ch]) |
| 335 | | return ((int)(attotime_to_double(timer_timeleft(ctc->timer[ch])) * attotime_to_double(period)) + 1) & 0xff; |
| 308 | if (channel->timer != NULL) |
| 309 | return ((int)(attotime_to_double(timer_timeleft(channel->timer)) * attotime_to_double(period)) + 1) & 0xff; |
| 336 | 310 | else |
| 337 | 311 | return 0; |
| 338 | 312 | } |
| 339 | 313 | } |
| 340 | 314 | |
| 341 | | READ8_HANDLER( z80ctc_0_r ) { return z80ctc_r(0, offset); } |
| 342 | | READ8_HANDLER( z80ctc_1_r ) { return z80ctc_r(1, offset); } |
| 343 | 315 | |
| 344 | 316 | |
| 345 | | |
| 346 | 317 | /*************************************************************************** |
| 347 | 318 | EXTERNAL TRIGGERS |
| 348 | 319 | ***************************************************************************/ |
| 349 | 320 | |
| 350 | | void z80ctc_trg_w(running_machine *machine, int which, int ch, UINT8 data) |
| 321 | void z80ctc_trg_w(const device_config *device, int ch, UINT8 data) |
| 351 | 322 | { |
| 352 | | z80ctc *ctc = ctcs + which; |
| 323 | z80ctc *ctc = get_safe_token(device); |
| 324 | ctc_channel *channel = &ctc->channel[ch]; |
| 353 | 325 | |
| 354 | 326 | /* normalize data */ |
| 355 | 327 | data = data ? 1 : 0; |
| 356 | 328 | |
| 357 | 329 | /* see if the trigger value has changed */ |
| 358 | | if (data != ctc->extclk[ch]) |
| 330 | if (data != channel->extclk) |
| 359 | 331 | { |
| 360 | | ctc->extclk[ch] = data; |
| 332 | channel->extclk = data; |
| 361 | 333 | |
| 362 | 334 | /* see if this is the active edge of the trigger */ |
| 363 | | if (((ctc->mode[ch] & EDGE) == EDGE_RISING && data) || ((ctc->mode[ch] & EDGE) == EDGE_FALLING && !data)) |
| 335 | if (((channel->mode & EDGE) == EDGE_RISING && data) || ((channel->mode & EDGE) == EDGE_FALLING && !data)) |
| 364 | 336 | { |
| 365 | 337 | /* if we're waiting for a trigger, start the timer */ |
| 366 | | if ((ctc->mode[ch] & WAITING_FOR_TRIG) && (ctc->mode[ch] & MODE) == MODE_TIMER) |
| 338 | if ((channel->mode & WAITING_FOR_TRIG) && (channel->mode & MODE) == MODE_TIMER) |
| 367 | 339 | { |
| 368 | | if (!(ctc->notimer & (1<<ch))) |
| 340 | if (!channel->notimer) |
| 369 | 341 | { |
| 370 | | attotime period = ((ctc->mode[ch] & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256; |
| 371 | | period = attotime_mul(period, ctc->tconst[ch]); |
| 342 | attotime period = ((channel->mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256; |
| 343 | period = attotime_mul(period, channel->tconst); |
| 372 | 344 | |
| 373 | 345 | VPRINTF(("CTC period %s\n", attotime_string(period, 9))); |
| 374 | | timer_adjust_periodic(ctc->timer[ch], period, (which << 2) + ch, period); |
| 346 | timer_adjust_periodic(channel->timer, period, ch, period); |
| 375 | 347 | } |
| 376 | 348 | else |
| 377 | 349 | { |
| 378 | 350 | VPRINTF(("CTC disabled\n")); |
| 379 | 351 | |
| 380 | | timer_adjust_oneshot(ctc->timer[ch], attotime_never, 0); |
| 352 | timer_adjust_oneshot(channel->timer, attotime_never, 0); |
| 381 | 353 | } |
| 382 | 354 | } |
| 383 | 355 | |
| 384 | 356 | /* we're no longer waiting */ |
| 385 | | ctc->mode[ch] &= ~WAITING_FOR_TRIG; |
| 357 | channel->mode &= ~WAITING_FOR_TRIG; |
| 386 | 358 | |
| 387 | 359 | /* if we're clocking externally, decrement the count */ |
| 388 | | if ((ctc->mode[ch] & MODE) == MODE_COUNTER) |
| 360 | if ((channel->mode & MODE) == MODE_COUNTER) |
| 389 | 361 | { |
| 390 | | ctc->down[ch]--; |
| 362 | channel->down--; |
| 391 | 363 | |
| 392 | 364 | /* if we hit zero, do the same thing as for a timer interrupt */ |
| 393 | | if (!ctc->down[ch]) |
| 394 | | timercallback(machine, NULL, (which << 2) + ch); |
| 365 | if (!channel->down) |
| 366 | { |
| 367 | void *ptr = (void *)device; |
| 368 | timercallback(device->machine, ptr, ch); |
| 369 | } |
| 395 | 370 | } |
| 396 | 371 | } |
| 397 | 372 | } |
| 398 | 373 | } |
| 374 | WRITE8_DEVICE_HANDLER( z80ctc_trg0_w ) { z80ctc_trg_w(device, 0, data); } |
| 375 | WRITE8_DEVICE_HANDLER( z80ctc_trg1_w ) { z80ctc_trg_w(device, 1, data); } |
| 376 | WRITE8_DEVICE_HANDLER( z80ctc_trg2_w ) { z80ctc_trg_w(device, 2, data); } |
| 377 | WRITE8_DEVICE_HANDLER( z80ctc_trg3_w ) { z80ctc_trg_w(device, 3, data); } |
| 399 | 378 | |
| 400 | | WRITE8_HANDLER( z80ctc_0_trg0_w ) { z80ctc_trg_w(machine, 0, 0, data); } |
| 401 | | WRITE8_HANDLER( z80ctc_0_trg1_w ) { z80ctc_trg_w(machine, 0, 1, data); } |
| 402 | | WRITE8_HANDLER( z80ctc_0_trg2_w ) { z80ctc_trg_w(machine, 0, 2, data); } |
| 403 | | WRITE8_HANDLER( z80ctc_0_trg3_w ) { z80ctc_trg_w(machine, 0, 3, data); } |
| 404 | | WRITE8_HANDLER( z80ctc_1_trg0_w ) { z80ctc_trg_w(machine, 1, 0, data); } |
| 405 | | WRITE8_HANDLER( z80ctc_1_trg1_w ) { z80ctc_trg_w(machine, 1, 1, data); } |
| 406 | | WRITE8_HANDLER( z80ctc_1_trg2_w ) { z80ctc_trg_w(machine, 1, 2, data); } |
| 407 | | WRITE8_HANDLER( z80ctc_1_trg3_w ) { z80ctc_trg_w(machine, 1, 3, data); } |
| 408 | 379 | |
| 409 | 380 | |
| 410 | | |
| 411 | 381 | /*************************************************************************** |
| 412 | 382 | DAISY CHAIN INTERFACE |
| 413 | 383 | ***************************************************************************/ |
| 414 | 384 | |
| 415 | | int z80ctc_irq_state(int which) |
| 385 | static int z80ctc_irq_state(const device_config *device) |
| 416 | 386 | { |
| 417 | | z80ctc *ctc = ctcs + which; |
| 387 | z80ctc *ctc = get_safe_token(device); |
| 418 | 388 | int state = 0; |
| 419 | 389 | int ch; |
| 420 | 390 | |
| 421 | | VPRINTF(("CTC IRQ state = %d%d%d%d\n", ctc->int_state[0], ctc->int_state[1], ctc->int_state[2], ctc->int_state[3])); |
| 391 | VPRINTF(("CTC IRQ state = %d%d%d%d\n", ctc->channel[0].int_state, ctc->channel[1].int_state, ctc->channel[2].int_state, ctc->channel[3].int_state)); |
| 422 | 392 | |
| 423 | 393 | /* loop over all channels */ |
| 424 | 394 | for (ch = 0; ch < 4; ch++) |
| 425 | 395 | { |
| 396 | ctc_channel *channel = &ctc->channel[ch]; |
| 397 | |
| 426 | 398 | /* if we're servicing a request, don't indicate more interrupts */ |
| 427 | | if (ctc->int_state[ch] & Z80_DAISY_IEO) |
| 399 | if (channel->int_state & Z80_DAISY_IEO) |
| 428 | 400 | { |
| 429 | 401 | state |= Z80_DAISY_IEO; |
| 430 | 402 | break; |
| 431 | 403 | } |
| 432 | | state |= ctc->int_state[ch]; |
| 404 | state |= channel->int_state; |
| 433 | 405 | } |
| 434 | 406 | |
| 435 | 407 | return state; |
| 436 | 408 | } |
| 437 | 409 | |
| 438 | 410 | |
| 439 | | int z80ctc_irq_ack(int which) |
| 411 | static int z80ctc_irq_ack(const device_config *device) |
| 440 | 412 | { |
| 441 | | z80ctc *ctc = ctcs + which; |
| 413 | z80ctc *ctc = get_safe_token(device); |
| 442 | 414 | int ch; |
| 443 | 415 | |
| 444 | 416 | /* loop over all channels */ |
| 445 | 417 | for (ch = 0; ch < 4; ch++) |
| 418 | { |
| 419 | ctc_channel *channel = &ctc->channel[ch]; |
| 446 | 420 | |
| 447 | 421 | /* find the first channel with an interrupt requested */ |
| 448 | | if (ctc->int_state[ch] & Z80_DAISY_INT) |
| 422 | if (channel->int_state & Z80_DAISY_INT) |
| 449 | 423 | { |
| 450 | 424 | VPRINTF(("CTC IRQAck ch%d\n", ch)); |
| 451 | 425 | |
| 452 | 426 | /* clear interrupt, switch to the IEO state, and update the IRQs */ |
| 453 | | ctc->int_state[ch] = Z80_DAISY_IEO; |
| 454 | | interrupt_check(Machine, which); |
| 427 | channel->int_state = Z80_DAISY_IEO; |
| 428 | interrupt_check(device); |
| 455 | 429 | return ctc->vector + ch * 2; |
| 456 | 430 | } |
| 431 | } |
| 457 | 432 | |
| 458 | 433 | logerror("z80ctc_irq_ack: failed to find an interrupt to ack!\n"); |
| 459 | 434 | return ctc->vector; |
| 460 | 435 | } |
| 461 | 436 | |
| 462 | 437 | |
| 463 | | void z80ctc_irq_reti(int which) |
| 438 | static void z80ctc_irq_reti(const device_config *device) |
| 464 | 439 | { |
| 465 | | z80ctc *ctc = ctcs + which; |
| 440 | z80ctc *ctc = get_safe_token(device); |
| 466 | 441 | int ch; |
| 467 | 442 | |
| 468 | 443 | /* loop over all channels */ |
| 469 | 444 | for (ch = 0; ch < 4; ch++) |
| 445 | { |
| 446 | ctc_channel *channel = &ctc->channel[ch]; |
| 470 | 447 | |
| 471 | 448 | /* find the first channel with an IEO pending */ |
| 472 | | if (ctc->int_state[ch] & Z80_DAISY_IEO) |
| 449 | if (channel->int_state & Z80_DAISY_IEO) |
| 473 | 450 | { |
| 474 | 451 | VPRINTF(("CTC IRQReti ch%d\n", ch)); |
| 475 | 452 | |
| 476 | 453 | /* clear the IEO state and update the IRQs */ |
| 477 | | ctc->int_state[ch] &= ~Z80_DAISY_IEO; |
| 478 | | interrupt_check(Machine, which); |
| 454 | channel->int_state &= ~Z80_DAISY_IEO; |
| 455 | interrupt_check(device); |
| 479 | 456 | return; |
| 480 | 457 | } |
| 458 | } |
| 481 | 459 | |
| 482 | 460 | logerror("z80ctc_irq_reti: failed to find an interrupt to clear IEO on!\n"); |
| 483 | 461 | } |
| 462 | |
| 463 | static DEVICE_START( z80ctc ) |
| 464 | { |
| 465 | const z80ctc_interface *intf = device->static_config; |
| 466 | z80ctc *ctc = get_safe_token(device); |
| 467 | char unique_tag[30]; |
| 468 | int cpunum = -1; |
| 469 | int ch; |
| 470 | |
| 471 | if (intf->cpu != NULL) |
| 472 | cpunum = mame_find_cpu_index(device->machine, intf->cpu); |
| 473 | if (cpunum != -1) |
| 474 | ctc->clock = device->machine->config->cpu[cpunum].clock; |
| 475 | else |
| 476 | ctc->clock = intf->baseclock; |
| 477 | ctc->period16 = attotime_mul(ATTOTIME_IN_HZ(ctc->clock), 16); |
| 478 | ctc->period256 = attotime_mul(ATTOTIME_IN_HZ(ctc->clock), 256); |
| 479 | for (ch = 0; ch < 4; ch++) |
| 480 | { |
| 481 | ctc_channel *channel = &ctc->channel[ch]; |
| 482 | void *ptr = (void *)device; |
| 483 | channel->notimer = (intf->notimer >> ch) & 1; |
| 484 | channel->timer = timer_alloc(timercallback, ptr); |
| 485 | } |
| 486 | ctc->intr = intf->intr; |
| 487 | ctc->channel[0].zc = intf->zc0; |
| 488 | ctc->channel[1].zc = intf->zc1; |
| 489 | ctc->channel[2].zc = intf->zc2; |
| 490 | ctc->channel[3].zc = NULL; |
| 491 | |
| 492 | /* register for save states */ |
| 493 | state_save_combine_module_and_tag(unique_tag, "z80ctc", device->tag); |
| 494 | |
| 495 | state_save_register_item(unique_tag, 0, ctc->vector); |
| 496 | for (ch = 0; ch < 4; ch++) |
| 497 | { |
| 498 | ctc_channel *channel = &ctc->channel[ch]; |
| 499 | state_save_register_item(unique_tag, ch, channel->mode); |
| 500 | state_save_register_item(unique_tag, ch, channel->tconst); |
| 501 | state_save_register_item(unique_tag, ch, channel->down); |
| 502 | state_save_register_item(unique_tag, ch, channel->extclk); |
| 503 | state_save_register_item(unique_tag, ch, channel->int_state); |
| 504 | } |
| 505 | |
| 506 | return DEVICE_START_OK; |
| 507 | } |
| 508 | |
| 509 | |
| 510 | static DEVICE_RESET( z80ctc ) |
| 511 | { |
| 512 | z80ctc *ctc = get_safe_token(device); |
| 513 | int ch; |
| 514 | |
| 515 | /* set up defaults */ |
| 516 | for (ch = 0; ch < 4; ch++) |
| 517 | { |
| 518 | ctc_channel *channel = &ctc->channel[ch]; |
| 519 | channel->mode = RESET_ACTIVE; |
| 520 | channel->tconst = 0x100; |
| 521 | timer_adjust_oneshot(channel->timer, attotime_never, 0); |
| 522 | channel->int_state = 0; |
| 523 | } |
| 524 | interrupt_check(device); |
| 525 | VPRINTF(("CTC Reset\n")); |
| 526 | } |
| 527 | |
| 528 | |
| 529 | static DEVICE_SET_INFO( z80ctc ) |
| 530 | { |
| 531 | switch (state) |
| 532 | { |
| 533 | /* no parameters to set */ |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | DEVICE_GET_INFO( z80ctc ) |
| 539 | { |
| 540 | switch (state) |
| 541 | { |
| 542 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 543 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(z80ctc); break; |
| 544 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 545 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 546 | |
| 547 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 548 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(z80ctc); break; |
| 549 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(z80ctc);break; |
| 550 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 551 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(z80ctc);break; |
| 552 | case DEVINFO_FCT_IRQ_STATE: info->f = (genf *)z80ctc_irq_state; break; |
| 553 | case DEVINFO_FCT_IRQ_ACK: info->f = (genf *)z80ctc_irq_ack; break; |
| 554 | case DEVINFO_FCT_IRQ_RETI: info->f = (genf *)z80ctc_irq_reti; break; |
| 555 | |
| 556 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 557 | case DEVINFO_STR_NAME: info->s = "Zilog Z80 CTC"; break; |
| 558 | case DEVINFO_STR_FAMILY: info->s = "Z80"; break; |
| 559 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 560 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 561 | case DEVINFO_STR_CREDITS: info->s = "Copyright Nicola Salmoria and the MAME Team"; break; |
| 562 | } |
| 563 | } |
| 564 | |
src/mess/machine/osborne1.c
| r3352 | r3353 | |
| 27 | 27 | |
| 28 | 28 | #define RAMMODE (0x01) |
| 29 | 29 | |
| 30 | | static struct osborne1 { |
| 30 | |
| 31 | static struct osborne1 |
| 32 | { |
| 31 | 33 | UINT8 bank2_enabled; |
| 32 | 34 | UINT8 bank3_enabled; |
| 33 | 35 | UINT8 *bank4_ptr; |
| r3352 | r3353 | |
| 49 | 51 | UINT8 beep; |
| 50 | 52 | } osborne1; |
| 51 | 53 | |
| 52 | | /* Prototypes */ |
| 53 | | static void osborne1_z80_reset(int); |
| 54 | | static int osborne1_z80_irq_state(int); |
| 55 | | static int osborne1_z80_irq_ack(int); |
| 56 | | static void osborne1_z80_irq_reti(int); |
| 57 | 54 | |
| 58 | | const struct z80_irq_daisy_chain osborne1_daisy_chain[] = { |
| 59 | | { osborne1_z80_reset, osborne1_z80_irq_state, osborne1_z80_irq_ack, osborne1_z80_irq_reti, 0 }, |
| 60 | | { NULL, NULL, NULL, NULL, -1 } |
| 61 | | }; |
| 62 | | |
| 63 | | |
| 64 | | WRITE8_HANDLER( osborne1_0000_w ) { |
| 55 | WRITE8_HANDLER( osborne1_0000_w ) |
| 56 | { |
| 65 | 57 | /* Check whether regular RAM is enabled */ |
| 66 | | if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) { |
| 58 | if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) |
| 59 | { |
| 67 | 60 | mess_ram[ offset ] = data; |
| 68 | 61 | } |
| 69 | 62 | } |
| 70 | 63 | |
| 71 | | WRITE8_HANDLER( osborne1_1000_w ) { |
| 64 | |
| 65 | WRITE8_HANDLER( osborne1_1000_w ) |
| 66 | { |
| 72 | 67 | /* Check whether regular RAM is enabled */ |
| 73 | | if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) { |
| 68 | if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) |
| 69 | { |
| 74 | 70 | mess_ram[ 0x1000 + offset ] = data; |
| 75 | 71 | } |
| 76 | 72 | } |
| 77 | 73 | |
| 78 | | READ8_HANDLER( osborne1_2000_r ) { |
| 74 | |
| 75 | READ8_HANDLER( osborne1_2000_r ) |
| 76 | { |
| 79 | 77 | UINT8 data = 0xFF; |
| 80 | 78 | |
| 81 | 79 | /* Check whether regular RAM is enabled */ |
| 82 | | if ( ! osborne1.bank2_enabled ) { |
| 80 | if ( ! osborne1.bank2_enabled ) |
| 81 | { |
| 83 | 82 | data = mess_ram[ 0x2000 + offset ]; |
| 84 | | } else { |
| 85 | | switch( offset & 0x0F00 ) { |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | switch( offset & 0x0F00 ) |
| 87 | { |
| 86 | 88 | case 0x100: /* Floppy */ |
| 87 | 89 | data = wd17xx_r( machine, offset ); |
| 88 | 90 | break; |
| r3352 | r3353 | |
| 117 | 119 | return data; |
| 118 | 120 | } |
| 119 | 121 | |
| 120 | | WRITE8_HANDLER( osborne1_2000_w ) { |
| 122 | |
| 123 | WRITE8_HANDLER( osborne1_2000_w ) |
| 124 | { |
| 121 | 125 | /* Check whether regular RAM is enabled */ |
| 122 | | if ( ! osborne1.bank2_enabled ) { |
| 126 | if ( ! osborne1.bank2_enabled ) |
| 127 | { |
| 123 | 128 | mess_ram[ 0x2000 + offset ] = data; |
| 124 | | } else { |
| 125 | | if ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) { |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | if ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) |
| 133 | { |
| 126 | 134 | mess_ram[ 0x2000 + offset ] = data; |
| 127 | 135 | } |
| 128 | 136 | /* Handle writes to the I/O area */ |
| 129 | | switch( offset & 0x0F00 ) { |
| 137 | switch( offset & 0x0F00 ) |
| 138 | { |
| 130 | 139 | case 0x100: /* Floppy */ |
| 131 | 140 | wd17xx_w( machine, offset, data ); |
| 132 | 141 | break; |
| r3352 | r3353 | |
| 142 | 151 | } |
| 143 | 152 | } |
| 144 | 153 | |
| 145 | | WRITE8_HANDLER( osborne1_3000_w ) { |
| 154 | |
| 155 | WRITE8_HANDLER( osborne1_3000_w ) |
| 156 | { |
| 146 | 157 | /* Check whether regular RAM is enabled */ |
| 147 | | if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) { |
| 158 | if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) |
| 159 | { |
| 148 | 160 | mess_ram[ 0x3000 + offset ] = data; |
| 149 | 161 | } |
| 150 | 162 | } |
| 151 | 163 | |
| 152 | | WRITE8_HANDLER( osborne1_videoram_w ) { |
| 164 | |
| 165 | WRITE8_HANDLER( osborne1_videoram_w ) |
| 166 | { |
| 153 | 167 | /* Check whether the video attribute section is enabled */ |
| 154 | | if ( osborne1.bank3_enabled ) { |
| 168 | if ( osborne1.bank3_enabled ) |
| 169 | { |
| 155 | 170 | data |= 0x7F; |
| 156 | 171 | } |
| 157 | 172 | osborne1.bank4_ptr[offset] = data; |
| 158 | 173 | } |
| 159 | 174 | |
| 160 | | WRITE8_HANDLER( osborne1_bankswitch_w ) { |
| 161 | | switch( offset ) { |
| 175 | |
| 176 | WRITE8_HANDLER( osborne1_bankswitch_w ) |
| 177 | { |
| 178 | switch( offset ) |
| 179 | { |
| 162 | 180 | case 0x00: |
| 163 | 181 | osborne1.bank2_enabled = 1; |
| 164 | 182 | osborne1.bank3_enabled = 0; |
| r3352 | r3353 | |
| 176 | 194 | osborne1.bank3_enabled = 0; |
| 177 | 195 | break; |
| 178 | 196 | } |
| 179 | | if ( osborne1.bank2_enabled ) { |
| 197 | if ( osborne1.bank2_enabled ) |
| 198 | { |
| 180 | 199 | memory_set_bankptr( 1, memory_region(machine, "main") ); |
| 181 | 200 | memory_set_bankptr( 2, osborne1.empty_4K ); |
| 182 | 201 | memory_set_bankptr( 3, osborne1.empty_4K ); |
| 183 | | } else { |
| 202 | } |
| 203 | else |
| 204 | { |
| 184 | 205 | memory_set_bankptr( 1, mess_ram ); |
| 185 | 206 | memory_set_bankptr( 2, mess_ram + 0x1000 ); |
| 186 | 207 | memory_set_bankptr( 3, mess_ram + 0x3000 ); |
| r3352 | r3353 | |
| 191 | 212 | osborne1.in_irq_handler = 0; |
| 192 | 213 | } |
| 193 | 214 | |
| 194 | | static OPBASE_HANDLER( osborne1_opbase ) { |
| 195 | | if ( ( address & 0xF000 ) == 0x2000 ) { |
| 196 | | if ( ! osborne1.bank2_enabled ) { |
| 215 | |
| 216 | static OPBASE_HANDLER( osborne1_opbase ) |
| 217 | { |
| 218 | if ( ( address & 0xF000 ) == 0x2000 ) |
| 219 | { |
| 220 | if ( ! osborne1.bank2_enabled ) |
| 221 | { |
| 197 | 222 | opbase->mask = 0x0fff; |
| 198 | 223 | opbase->ram = mess_ram + 0x2000; |
| 199 | 224 | opbase->rom = mess_ram + 0x2000; |
| r3352 | r3353 | |
| 205 | 230 | return address; |
| 206 | 231 | } |
| 207 | 232 | |
| 208 | | static void osborne1_z80_reset(int param) { |
| 209 | | osborne1.pia_1_irq_state = 0; |
| 210 | | osborne1.in_irq_handler = 0; |
| 211 | | } |
| 212 | 233 | |
| 213 | | static int osborne1_z80_irq_state(int param) { |
| 214 | | return ( osborne1.pia_1_irq_state ? Z80_DAISY_INT : 0 ); |
| 215 | | } |
| 216 | | |
| 217 | | static int osborne1_z80_irq_ack(int param) { |
| 218 | | /* Enable ROM and I/O when IRQ is acknowledged */ |
| 219 | | UINT8 old_bankswitch = osborne1.bankswitch; |
| 220 | | osborne1_bankswitch_w( Machine, 0, 0 ); |
| 221 | | osborne1.bankswitch = old_bankswitch; |
| 222 | | osborne1.in_irq_handler = 1; |
| 223 | | return 0xF8; |
| 224 | | } |
| 225 | | |
| 226 | | static void osborne1_z80_irq_reti(int param) { |
| 227 | | } |
| 228 | | |
| 229 | | static void osborne1_update_irq_state(running_machine *machine) { |
| 234 | static void osborne1_update_irq_state(running_machine *machine) |
| 235 | { |
| 230 | 236 | //logerror("Changing irq state; pia_0_irq_state = %s, pia_1_irq_state = %s\n", osborne1.pia_0_irq_state ? "SET" : "CLEARED", osborne1.pia_1_irq_state ? "SET" : "CLEARED" ); |
| 231 | 237 | |
| 232 | | if ( osborne1.pia_1_irq_state ) { |
| 238 | if ( osborne1.pia_1_irq_state ) |
| 239 | { |
| 233 | 240 | cpunum_set_input_line(machine, 0, 0, ASSERT_LINE ); |
| 234 | | } else { |
| 241 | } |
| 242 | else |
| 243 | { |
| 235 | 244 | cpunum_set_input_line(machine, 0, 0, CLEAR_LINE ); |
| 236 | 245 | } |
| 237 | 246 | } |
| 238 | 247 | |
| 239 | | static void ieee_pia_irq_a_func(running_machine *machine, int state) { |
| 248 | |
| 249 | static void ieee_pia_irq_a_func(running_machine *machine, int state) |
| 250 | { |
| 240 | 251 | osborne1.pia_0_irq_state = state; |
| 241 | 252 | osborne1_update_irq_state(machine); |
| 242 | 253 | } |
| 243 | 254 | |
| 244 | | static const pia6821_interface osborne1_ieee_pia_config = { |
| 255 | |
| 256 | static const pia6821_interface osborne1_ieee_pia_config = |
| 257 | { |
| 245 | 258 | NULL, /* in_a_func */ |
| 246 | 259 | NULL, /* in_b_func */ |
| 247 | 260 | NULL, /* in_ca1_func */ |
| r3352 | r3353 | |
| 256 | 269 | NULL /* irq_b_func */ |
| 257 | 270 | }; |
| 258 | 271 | |
| 259 | | static WRITE8_HANDLER( video_pia_out_cb2_dummy ) { |
| 272 | |
| 273 | static WRITE8_HANDLER( video_pia_out_cb2_dummy ) |
| 274 | { |
| 260 | 275 | } |
| 261 | 276 | |
| 262 | | static WRITE8_HANDLER( video_pia_port_a_w ) { |
| 277 | |
| 278 | static WRITE8_HANDLER( video_pia_port_a_w ) |
| 279 | { |
| 263 | 280 | osborne1.new_start_x = data >> 1; |
| 264 | 281 | wd17xx_set_density( ( data & 0x01 ) ? DEN_FM_LO : DEN_FM_HI ); |
| 265 | 282 | |
| 266 | 283 | //logerror("Video pia port a write: %02X, density set to %s\n", data, data & 1 ? "DEN_FM_LO" : "DEN_FM_HI" ); |
| 267 | 284 | } |
| 268 | 285 | |
| 269 | | static WRITE8_HANDLER( video_pia_port_b_w ) { |
| 286 | |
| 287 | static WRITE8_HANDLER( video_pia_port_b_w ) |
| 288 | { |
| 270 | 289 | osborne1.new_start_y = data & 0x1F; |
| 271 | 290 | osborne1.beep = ( data & 0x20 ) ? 1 : 0; |
| 272 | | if ( data & 0x40 ) { |
| 291 | if ( data & 0x40 ) |
| 292 | { |
| 273 | 293 | wd17xx_set_drive( 0 ); |
| 274 | | } else if ( data & 0x80 ) { |
| 294 | } |
| 295 | else if ( data & 0x80 ) |
| 296 | { |
| 275 | 297 | wd17xx_set_drive( 1 ); |
| 276 | 298 | } |
| 277 | 299 | //logerror("Video pia port b write: %02X\n", data ); |
| 278 | 300 | } |
| 279 | 301 | |
| 280 | | static void video_pia_irq_a_func(running_machine *machine, int state) { |
| 302 | |
| 303 | static void video_pia_irq_a_func(running_machine *machine, int state) |
| 304 | { |
| 281 | 305 | osborne1.pia_1_irq_state = state; |
| 282 | 306 | osborne1_update_irq_state(machine); |
| 283 | 307 | } |
| 284 | 308 | |
| 285 | | static const pia6821_interface osborne1_video_pia_config = { |
| 309 | |
| 310 | static const pia6821_interface osborne1_video_pia_config = |
| 311 | { |
| 286 | 312 | NULL, /* in_a_func */ |
| 287 | 313 | NULL, /* in_b_func */ |
| 288 | 314 | NULL, /* in_ca1_func */ |
| r3352 | r3353 | |
| 297 | 323 | NULL /* irq_b_func */ |
| 298 | 324 | }; |
| 299 | 325 | |
| 300 | | //static const struct aica6850_interface osborne1_6850_config = { |
| 326 | |
| 327 | //static const struct aica6850_interface osborne1_6850_config = |
| 328 | //{ |
| 301 | 329 | // 10, /* tx_clock */ |
| 302 | 330 | // 10, /* rx_clock */ |
| 303 | 331 | // NULL, /* rx_pin */ |
| r3352 | r3353 | |
| 308 | 336 | // NULL /* int_callback */ |
| 309 | 337 | //}; |
| 310 | 338 | |
| 311 | | static TIMER_CALLBACK(osborne1_video_callback) { |
| 339 | |
| 340 | static TIMER_CALLBACK(osborne1_video_callback) |
| 341 | { |
| 312 | 342 | int y = video_screen_get_vpos(machine->primary_screen); |
| 313 | 343 | |
| 314 | 344 | /* Check for start of frame */ |
| 315 | | if ( y == 0 ) { |
| 345 | if ( y == 0 ) |
| 346 | { |
| 316 | 347 | /* Clear CA1 on video PIA */ |
| 317 | 348 | osborne1.start_y = ( osborne1.new_start_y - 1 ) & 0x1F; |
| 318 | 349 | osborne1.charline = 0; |
| 319 | 350 | pia_1_ca1_w( machine, 0, 0 ); |
| 320 | 351 | } |
| 321 | | if ( y == 240 ) { |
| 352 | if ( y == 240 ) |
| 353 | { |
| 322 | 354 | /* Set CA1 on video PIA */ |
| 323 | 355 | pia_1_ca1_w( machine, 0, 0xFF ); |
| 324 | 356 | } |
| 325 | | if ( y < 240 ) { |
| 357 | if ( y < 240 ) |
| 358 | { |
| 326 | 359 | /* Draw a line of the display */ |
| 327 | 360 | UINT16 address = osborne1.start_y * 128 + osborne1.new_start_x + 11; |
| 328 | 361 | UINT16 *p = BITMAP_ADDR16( tmpbitmap, y, 0 ); |
| 329 | 362 | int x; |
| 330 | 363 | |
| 331 | | for ( x = 0; x < 52; x++ ) { |
| 364 | for ( x = 0; x < 52; x++ ) |
| 365 | { |
| 332 | 366 | UINT8 character = mess_ram[ 0xF000 + ( ( address + x ) & 0xFFF ) ]; |
| 333 | 367 | UINT8 cursor = character & 0x80; |
| 334 | 368 | UINT8 dim = mess_ram[ 0x10000 + ( ( address + x ) & 0xFFF ) ] & 0x80; |
| 335 | 369 | UINT8 bits = osborne1.charrom[ osborne1.charline * 128 + ( character & 0x7F ) ]; |
| 336 | 370 | int bit; |
| 337 | 371 | |
| 338 | | if ( cursor && osborne1.charline == 9 ) { |
| 372 | if ( cursor && osborne1.charline == 9 ) |
| 373 | { |
| 339 | 374 | bits = 0xFF; |
| 340 | 375 | } |
| 341 | | for ( bit = 0; bit < 8; bit++ ) { |
| 376 | for ( bit = 0; bit < 8; bit++ ) |
| 377 | { |
| 342 | 378 | p[x * 8 + bit] = ( bits & 0x80 ) ? ( dim ? 1 : 2 ) : 0; |
| 343 | 379 | bits = bits << 1; |
| 344 | 380 | } |
| 345 | 381 | } |
| 346 | 382 | |
| 347 | 383 | osborne1.charline += 1; |
| 348 | | if ( osborne1.charline == 10 ) { |
| 384 | if ( osborne1.charline == 10 ) |
| 385 | { |
| 349 | 386 | osborne1.start_y += 1; |
| 350 | 387 | osborne1.charline = 0; |
| 351 | 388 | } |
| 352 | 389 | } |
| 353 | 390 | |
| 354 | | if ( ( y % 10 ) == 2 || ( y % 10 ) == 6 ) { |
| 391 | if ( ( y % 10 ) == 2 || ( y % 10 ) == 6 ) |
| 392 | { |
| 355 | 393 | beep_set_state( 0, osborne1.beep ); |
| 356 | | } else { |
| 394 | } |
| 395 | else |
| 396 | { |
| 357 | 397 | beep_set_state( 0, 0 ); |
| 358 | 398 | } |
| 359 | 399 | |
| r3352 | r3353 | |
| 369 | 409 | * - DEC 1820 double density: 40 tracks, 9 sectors per track, 512-byte sectors (180 KByte) |
| 370 | 410 | * |
| 371 | 411 | */ |
| 372 | | DEVICE_IMAGE_LOAD( osborne1_floppy ) { |
| 412 | DEVICE_IMAGE_LOAD( osborne1_floppy ) |
| 413 | { |
| 373 | 414 | int size, sectors, sectorsize; |
| 374 | 415 | |
| 375 | | if ( ! image_has_been_created( image ) ) { |
| 416 | if ( ! image_has_been_created( image ) ) |
| 417 | { |
| 376 | 418 | size = image_length( image ); |
| 377 | 419 | |
| 378 | | switch( size ) { |
| 420 | switch( size ) |
| 421 | { |
| 379 | 422 | case 40 * 10 * 256: |
| 380 | 423 | sectors = 10; |
| 381 | 424 | sectorsize = 256; |
| r3352 | r3353 | |
| 404 | 447 | default: |
| 405 | 448 | return INIT_FAIL; |
| 406 | 449 | } |
| 407 | | } else { |
| 450 | } |
| 451 | else |
| 452 | { |
| 408 | 453 | return INIT_FAIL; |
| 409 | 454 | } |
| 410 | 455 | |
| 411 | | if ( device_load_basicdsk_floppy( image ) != INIT_PASS ) { |
| 456 | if ( device_load_basicdsk_floppy( image ) != INIT_PASS ) |
| 457 | { |
| 412 | 458 | return INIT_FAIL; |
| 413 | 459 | } |
| 414 | 460 | |
| r3352 | r3353 | |
| 417 | 463 | return INIT_PASS; |
| 418 | 464 | } |
| 419 | 465 | |
| 420 | | static TIMER_CALLBACK( setup_beep ) { |
| 466 | |
| 467 | static TIMER_CALLBACK( setup_beep ) |
| 468 | { |
| 421 | 469 | beep_set_state( 0, 0 ); |
| 422 | 470 | beep_set_frequency( 0, 300 /* 60 * 240 / 2 */ ); |
| 423 | 471 | } |
| 424 | 472 | |
| 473 | |
| 425 | 474 | MACHINE_START( osborne1 ) |
| 426 | 475 | { |
| 427 | 476 | /* Configure the floppy disk interface */ |
| 428 | 477 | wd17xx_init( machine, WD_TYPE_MB8877, NULL, NULL ); |
| 429 | 478 | } |
| 430 | 479 | |
| 431 | | MACHINE_RESET( osborne1 ) { |
| 480 | |
| 481 | MACHINE_RESET( osborne1 ) |
| 482 | { |
| 432 | 483 | /* Initialize memory configuration */ |
| 433 | 484 | osborne1_bankswitch_w( machine, 0x00, 0 ); |
| 434 | 485 | |
| 435 | 486 | osborne1.pia_0_irq_state = FALSE; |
| 436 | 487 | osborne1.pia_1_irq_state = FALSE; |
| 437 | 488 | |
| 489 | osborne1.pia_1_irq_state = 0; |
| 490 | osborne1.in_irq_handler = 0; |
| 491 | |
| 438 | 492 | osborne1.charrom = memory_region( machine, "gfx1" ); |
| 439 | 493 | |
| 440 | 494 | memset( mess_ram + 0x10000, 0xFF, 0x1000 ); |
| r3352 | r3353 | |
| 448 | 502 | memory_set_opbase_handler( 0, osborne1_opbase ); |
| 449 | 503 | } |
| 450 | 504 | |
| 451 | | DRIVER_INIT( osborne1 ) { |
| 505 | |
| 506 | DRIVER_INIT( osborne1 ) |
| 507 | { |
| 452 | 508 | memset( &osborne1, 0, sizeof( osborne1 ) ); |
| 453 | 509 | |
| 454 | 510 | osborne1.empty_4K = auto_malloc( 0x1000 ); |
| r3352 | r3353 | |
| 462 | 518 | // acia6850_config( 0, &osborne1_6850_config ); |
| 463 | 519 | } |
| 464 | 520 | |
| 521 | |
| 522 | /**************************************************************** |
| 523 | Osborne1 specific daisy chain code |
| 524 | ****************************************************************/ |
| 525 | |
| 526 | |
| 527 | static int osborne1_daisy_irq_state(const device_config *device) |
| 528 | { |
| 529 | return ( osborne1.pia_1_irq_state ? Z80_DAISY_INT : 0 ); |
| 530 | } |
| 531 | |
| 532 | |
| 533 | static int osborne1_daisy_irq_ack(const device_config *device) |
| 534 | { |
| 535 | /* Enable ROM and I/O when IRQ is acknowledged */ |
| 536 | UINT8 old_bankswitch = osborne1.bankswitch; |
| 537 | osborne1_bankswitch_w( Machine, 0, 0 ); |
| 538 | osborne1.bankswitch = old_bankswitch; |
| 539 | osborne1.in_irq_handler = 1; |
| 540 | return 0xF8; |
| 541 | } |
| 542 | |
| 543 | static void osborne1_daisy_irq_reti(const device_config *device) |
| 544 | { |
| 545 | } |
| 546 | |
| 547 | |
| 548 | static DEVICE_START( osborne1_daisy ) |
| 549 | { |
| 550 | return DEVICE_START_OK; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | static DEVICE_RESET( osborne1_daisy ) |
| 555 | { |
| 556 | } |
| 557 | |
| 558 | |
| 559 | static DEVICE_SET_INFO( osborne1_daisy ) |
| 560 | { |
| 561 | } |
| 562 | |
| 563 | |
| 564 | DEVICE_GET_INFO( osborne1_daisy ) |
| 565 | { |
| 566 | switch (state) |
| 567 | { |
| 568 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 569 | case DEVINFO_INT_TOKEN_BYTES: info->i = 4; break; |
| 570 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 571 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 572 | |
| 573 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 574 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(osborne1_daisy); break; |
| 575 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(osborne1_daisy); break; |
| 576 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 577 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(osborne1_daisy); break; |
| 578 | case DEVINFO_FCT_IRQ_STATE: info->f = (genf *)osborne1_daisy_irq_state; break; |
| 579 | case DEVINFO_FCT_IRQ_ACK: info->f = (genf *)osborne1_daisy_irq_ack; break; |
| 580 | case DEVINFO_FCT_IRQ_RETI: info->f = (genf *)osborne1_daisy_irq_reti; break; |
| 581 | |
| 582 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 583 | case DEVINFO_STR_NAME: info->s = "Osborne1 daisy"; break; |
| 584 | case DEVINFO_STR_FAMILY: info->s = "Z80"; break; |
| 585 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 586 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 587 | case DEVINFO_STR_CREDITS: info->s = "Copyright the MESS Team"; break; |
| 588 | } |
| 589 | } |
| 590 | |
src/mess/machine/kc.c
| r3352 | r3353 | |
| 154 | 154 | } |
| 155 | 155 | #endif |
| 156 | 156 | |
| 157 | | READ8_HANDLER(kc85_disk_hw_ctc_r) |
| 157 | READ8_DEVICE_HANDLER(kc85_disk_hw_ctc_r) |
| 158 | 158 | { |
| 159 | | return z80ctc_1_r(machine, offset); |
| 159 | return z80ctc_r(device, offset); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | | WRITE8_HANDLER(kc85_disk_hw_ctc_w) |
| 162 | WRITE8_DEVICE_HANDLER(kc85_disk_hw_ctc_w) |
| 163 | 163 | { |
| 164 | | z80ctc_1_w(machine, offset, data); |
| 164 | z80ctc_w(device, offset, data); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | WRITE8_HANDLER(kc85_disc_interface_ram_w) |
| r3352 | r3353 | |
| 242 | 242 | |
| 243 | 243 | nec765_init(machine, &kc_fdc_interface,NEC765A,NEC765_RDY_PIN_CONNECTED); |
| 244 | 244 | |
| 245 | | /* reset ctc */ |
| 246 | | z80ctc_reset(1); |
| 247 | | |
| 248 | 245 | /* hold cpu at reset */ |
| 249 | 246 | cpunum_set_input_line(machine, 1, INPUT_LINE_RESET, ASSERT_LINE); |
| 250 | 247 | } |
| r3352 | r3353 | |
| 1710 | 1707 | } |
| 1711 | 1708 | |
| 1712 | 1709 | |
| 1713 | | READ8_HANDLER ( kc85_ctc_r ) |
| 1710 | READ8_DEVICE_HANDLER ( kc85_ctc_r ) |
| 1714 | 1711 | { |
| 1715 | 1712 | unsigned char data; |
| 1716 | 1713 | |
| 1717 | | data = z80ctc_0_r(machine, offset); |
| 1714 | data = z80ctc_r(device, offset); |
| 1718 | 1715 | //LOG_KBD(("ctc data r:%02x\n",data)); |
| 1719 | 1716 | return data; |
| 1720 | 1717 | } |
| 1721 | 1718 | |
| 1722 | | WRITE8_HANDLER ( kc85_ctc_w ) |
| 1719 | WRITE8_DEVICE_HANDLER ( kc85_ctc_w ) |
| 1723 | 1720 | { |
| 1724 | 1721 | //logerror("ctc data w:%02x\n",data); |
| 1725 | 1722 | |
| 1726 | | z80ctc_0_w(machine, offset,data); |
| 1723 | z80ctc_w(device, offset,data); |
| 1727 | 1724 | } |
| 1728 | 1725 | |
| 1729 | 1726 | |
| 1730 | | static void kc85_pio_interrupt(running_machine *machine, int state) |
| 1727 | static void kc85_pio_interrupt(const device_config *device, int state) |
| 1731 | 1728 | { |
| 1732 | | cpunum_set_input_line(machine, 0, 0, state); |
| 1729 | cpunum_set_input_line(device->machine, 0, 0, state); |
| 1733 | 1730 | } |
| 1734 | 1731 | |
| 1735 | | static void kc85_ctc_interrupt(running_machine *machine, int state) |
| 1732 | static void kc85_ctc_interrupt(const device_config *device, int state) |
| 1736 | 1733 | { |
| 1737 | | cpunum_set_input_line(machine, 0, 1, state); |
| 1734 | cpunum_set_input_line(device->machine, 0, 1, state); |
| 1738 | 1735 | } |
| 1739 | 1736 | |
| 1740 | 1737 | /* callback for ardy output from PIO */ |
| r3352 | r3353 | |
| 1772 | 1769 | kc85_pio_brdy_callback /* portB ready active callback */ |
| 1773 | 1770 | }; |
| 1774 | 1771 | |
| 1775 | | static void kc85_z80pio_reset(int which) |
| 1776 | | { |
| 1777 | | z80pio_reset(kc85_z80pio); |
| 1778 | | } |
| 1779 | 1772 | |
| 1780 | 1773 | /* pio is last in chain and therefore has highest priority */ |
| 1781 | 1774 | |
| 1782 | | const struct z80_irq_daisy_chain kc85_daisy_chain[] = |
| 1775 | const z80_daisy_chain kc85_daisy_chain[] = |
| 1783 | 1776 | { |
| 1784 | | {kc85_z80pio_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0}, |
| 1785 | | {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0}, |
| 1786 | | {0,0,0,0,-1} |
| 1777 | { Z80PIO, "z80pio" }, |
| 1778 | { Z80CTC, "z80ctc" }, |
| 1779 | { NULL } |
| 1787 | 1780 | }; |
| 1788 | 1781 | |
| 1789 | 1782 | /* used in cassette write -> K0 */ |
| 1790 | | static WRITE8_HANDLER(kc85_zc0_callback) |
| 1783 | static WRITE8_DEVICE_HANDLER(kc85_zc0_callback) |
| 1791 | 1784 | { |
| 1792 | 1785 | |
| 1793 | 1786 | |
| 1794 | 1787 | } |
| 1795 | 1788 | |
| 1796 | 1789 | /* used in cassette write -> K1 */ |
| 1797 | | static WRITE8_HANDLER(kc85_zc1_callback) |
| 1790 | static WRITE8_DEVICE_HANDLER(kc85_zc1_callback) |
| 1798 | 1791 | { |
| 1799 | 1792 | |
| 1800 | 1793 | } |
| r3352 | r3353 | |
| 1802 | 1795 | |
| 1803 | 1796 | static TIMER_CALLBACK(kc85_15khz_timer_callback) |
| 1804 | 1797 | { |
| 1798 | const device_config *device = ptr; |
| 1799 | |
| 1805 | 1800 | /* toggle state of square wave */ |
| 1806 | 1801 | kc85_15khz_state^=1; |
| 1807 | 1802 | |
| 1808 | 1803 | /* set clock input for channel 2 and 3 to ctc */ |
| 1809 | | z80ctc_0_trg0_w(machine, 0,kc85_15khz_state); |
| 1810 | | z80ctc_0_trg1_w(machine, 0,kc85_15khz_state); |
| 1804 | z80ctc_trg0_w(device, 0,kc85_15khz_state); |
| 1805 | z80ctc_trg1_w(device, 0,kc85_15khz_state); |
| 1811 | 1806 | |
| 1812 | 1807 | kc85_15khz_count++; |
| 1813 | 1808 | |
| r3352 | r3353 | |
| 1819 | 1814 | kc85_50hz_state^=1; |
| 1820 | 1815 | |
| 1821 | 1816 | /* set clock input for channel 2 and 3 to ctc */ |
| 1822 | | z80ctc_0_trg2_w(machine, 0, kc85_50hz_state); |
| 1823 | | z80ctc_0_trg3_w(machine, 0, kc85_50hz_state); |
| 1817 | z80ctc_trg2_w(device, 0, kc85_50hz_state); |
| 1818 | z80ctc_trg3_w(device, 0, kc85_50hz_state); |
| 1824 | 1819 | } |
| 1825 | 1820 | } |
| 1826 | 1821 | |
| 1827 | 1822 | /* video blink */ |
| 1828 | | static WRITE8_HANDLER(kc85_zc2_callback) |
| 1823 | static WRITE8_DEVICE_HANDLER(kc85_zc2_callback) |
| 1829 | 1824 | { |
| 1830 | 1825 | /* is blink enabled? */ |
| 1831 | 1826 | if (kc85_pio_data[1] & (1<<7)) |
| 1832 | 1827 | { |
| 1833 | 1828 | /* yes */ |
| 1834 | 1829 | /* toggle state of blink to video hardware */ |
| 1835 | | kc85_video_set_blink_state(machine, data); |
| 1830 | kc85_video_set_blink_state(device->machine, data); |
| 1836 | 1831 | } |
| 1837 | 1832 | } |
| 1838 | 1833 | |
| 1839 | | static z80ctc_interface kc85_ctc_intf = |
| 1834 | const z80ctc_interface kc85_ctc_intf = |
| 1840 | 1835 | { |
| 1836 | "main", |
| 1841 | 1837 | 1379310.344828, |
| 1842 | 1838 | 0, |
| 1843 | 1839 | kc85_ctc_interrupt, |
| r3352 | r3353 | |
| 1848 | 1844 | |
| 1849 | 1845 | static void kc85_common_init(running_machine *machine) |
| 1850 | 1846 | { |
| 1851 | | z80ctc_init(0, &kc85_ctc_intf); |
| 1852 | | |
| 1853 | | z80ctc_reset(0); |
| 1854 | | |
| 1855 | 1847 | kc_cassette_init(); |
| 1856 | 1848 | kc_keyboard_init(machine); |
| 1857 | 1849 | |
| r3352 | r3353 | |
| 1862 | 1854 | kc85_50hz_state = 0; |
| 1863 | 1855 | kc85_15khz_state = 0; |
| 1864 | 1856 | kc85_15khz_count = 0; |
| 1865 | | timer_pulse(ATTOTIME_IN_HZ(15625), NULL, 0, kc85_15khz_timer_callback); |
| 1857 | timer_pulse(ATTOTIME_IN_HZ(15625), (void *)device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), 0, kc85_15khz_timer_callback); |
| 1866 | 1858 | timer_set(attotime_zero, NULL, 0, kc85_reset_timer_callback); |
| 1867 | 1859 | kc85_module_system_init(); |
| 1868 | 1860 | } |
src/mess/drivers/abc80x.c
| r3352 | r3353 | |
| 174 | 174 | |
| 175 | 175 | // Z80 SIO/2 |
| 176 | 176 | |
| 177 | | static READ8_HANDLER( sio2_r ) |
| 177 | static READ8_DEVICE_HANDLER( sio2_r ) |
| 178 | 178 | { |
| 179 | 179 | switch (offset) |
| 180 | 180 | { |
| 181 | 181 | case 0: |
| 182 | | return z80sio_d_r(machine, 0, 0); |
| 182 | return z80sio_d_r(device, 0); |
| 183 | 183 | case 1: |
| 184 | | return z80sio_c_r(0, 0); |
| 184 | return z80sio_c_r(device, 0); |
| 185 | 185 | case 2: |
| 186 | | return z80sio_d_r(machine, 0, 1); |
| 186 | return z80sio_d_r(device, 1); |
| 187 | 187 | case 3: |
| 188 | | return z80sio_c_r(0, 1); |
| 188 | return z80sio_c_r(device, 1); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | return 0; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | | static WRITE8_HANDLER( sio2_w ) |
| 194 | static WRITE8_DEVICE_HANDLER( sio2_w ) |
| 195 | 195 | { |
| 196 | 196 | switch (offset) |
| 197 | 197 | { |
| 198 | 198 | case 0: |
| 199 | | z80sio_d_w(machine, 0, 0, data); |
| 199 | z80sio_d_w(device, 0, data); |
| 200 | 200 | break; |
| 201 | 201 | case 1: |
| 202 | | z80sio_c_w(machine, 0, 0, data); |
| 202 | z80sio_c_w(device, 0, data); |
| 203 | 203 | break; |
| 204 | 204 | case 2: |
| 205 | | z80sio_d_w(machine, 0, 1, data); |
| 205 | z80sio_d_w(device, 1, data); |
| 206 | 206 | break; |
| 207 | 207 | case 3: |
| 208 | | z80sio_c_w(machine, 0, 1, data); |
| 208 | z80sio_c_w(device, 1, data); |
| 209 | 209 | break; |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // Z80 DART |
| 214 | 214 | |
| 215 | | static READ8_HANDLER( dart_r ) |
| 215 | static READ8_DEVICE_HANDLER( dart_r ) |
| 216 | 216 | { |
| 217 | 217 | switch (offset) |
| 218 | 218 | { |
| 219 | 219 | case 0: |
| 220 | | return z80dart_d_r(0, 0); |
| 220 | return z80dart_d_r(device, 0); |
| 221 | 221 | case 1: |
| 222 | | return z80dart_c_r(0, 0); |
| 222 | return z80dart_c_r(device, 0); |
| 223 | 223 | case 2: |
| 224 | | return z80dart_d_r(0, 1); |
| 224 | return z80dart_d_r(device, 1); |
| 225 | 225 | case 3: |
| 226 | | return z80dart_c_r(0, 0); // this gets ABC806 booting, should be z80dart_c_r(0, 1) |
| 226 | return z80dart_c_r(device, 0); // this gets ABC806 booting, should be z80dart_c_r(0, 1) |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | return 0xff; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | | static WRITE8_HANDLER( dart_w ) |
| 232 | static WRITE8_DEVICE_HANDLER( dart_w ) |
| 233 | 233 | { |
| 234 | 234 | switch (offset) |
| 235 | 235 | { |
| 236 | 236 | case 0: |
| 237 | | z80dart_d_w(0, 0, data); |
| 237 | z80dart_d_w(device, 0, data); |
| 238 | 238 | break; |
| 239 | 239 | case 1: |
| 240 | | z80dart_c_w(machine, 0, 0, data); |
| 240 | z80dart_c_w(device, 0, data); |
| 241 | 241 | break; |
| 242 | 242 | case 2: |
| 243 | | z80dart_d_w(0, 1, data); |
| 243 | z80dart_d_w(device, 1, data); |
| 244 | 244 | break; |
| 245 | 245 | case 3: |
| 246 | | z80dart_c_w(machine, 0, 1, data); |
| 246 | z80dart_c_w(device, 1, data); |
| 247 | 247 | break; |
| 248 | 248 | } |
| 249 | 249 | } |
| r3352 | r3353 | |
| 294 | 294 | abc77_keydown = BIT(data, 6); |
| 295 | 295 | abc77_hys = BIT(data, 7); |
| 296 | 296 | |
| 297 | | z80dart_set_dcd(0, 0, abc77_keydown); |
| 297 | z80dart_set_dcd(device_list_find_by_tag(machine->config->devicelist, Z80DART, "z80dart"), 0, abc77_keydown); |
| 298 | 298 | //z80dart_set_cts(0, 0, abc77_keydown); on ABC802 only |
| 299 | 299 | |
| 300 | 300 | // write abc77_txd to Z80DART TxD |
| r3352 | r3353 | |
| 333 | 333 | AM_RANGE(0x02, 0x05) AM_MIRROR(0x18) AM_WRITE(abcbus_command_w) |
| 334 | 334 | AM_RANGE(0x06, 0x06) AM_MIRROR(0x18) AM_WRITE(abc800m_hrs_w) |
| 335 | 335 | AM_RANGE(0x07, 0x07) AM_MIRROR(0x18) AM_READWRITE(abcbus_reset_r, abc800m_hrc_w) |
| 336 | | AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_READWRITE(dart_r, dart_w) |
| 336 | AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w) |
| 337 | 337 | AM_RANGE(0x30, 0x32) AM_WRITE(abc800_ram_ctrl_w) |
| 338 | 338 | AM_RANGE(0x31, 0x31) AM_MIRROR(0x06) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r) |
| 339 | 339 | AM_RANGE(0x38, 0x38) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w) |
| 340 | 340 | AM_RANGE(0x39, 0x39) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w) |
| 341 | | AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_READWRITE(sio2_r, sio2_w) |
| 342 | | AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_READWRITE(z80ctc_0_r, z80ctc_0_w) |
| 341 | AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w) |
| 342 | AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w) |
| 343 | 343 | AM_RANGE(0x80, 0x80) AM_MIRROR(0x7f) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w) |
| 344 | 344 | ADDRESS_MAP_END |
| 345 | 345 | |
| r3352 | r3353 | |
| 361 | 361 | AM_RANGE(0x02, 0x05) AM_MIRROR(0x18) AM_WRITE(abcbus_command_w) |
| 362 | 362 | AM_RANGE(0x06, 0x06) AM_MIRROR(0x18) AM_WRITE(abc800c_hrs_w) |
| 363 | 363 | AM_RANGE(0x07, 0x07) AM_MIRROR(0x18) AM_READWRITE(abcbus_reset_r, abc800c_hrc_w) |
| 364 | | AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_READWRITE(dart_r, dart_w) |
| 364 | AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w) |
| 365 | 365 | AM_RANGE(0x30, 0x32) AM_WRITE(abc800_ram_ctrl_w) |
| 366 | 366 | AM_RANGE(0x31, 0x31) AM_MIRROR(0x06) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r) |
| 367 | 367 | AM_RANGE(0x38, 0x38) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w) |
| 368 | 368 | AM_RANGE(0x39, 0x39) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w) |
| 369 | | AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_READWRITE(sio2_r, sio2_w) |
| 370 | | AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_READWRITE(z80ctc_0_r, z80ctc_0_w) |
| 369 | AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w) |
| 370 | AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w) |
| 371 | 371 | AM_RANGE(0x80, 0x80) AM_MIRROR(0x7f) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w) |
| 372 | 372 | ADDRESS_MAP_END |
| 373 | 373 | |
| r3352 | r3353 | |
| 387 | 387 | AM_RANGE(0x01, 0x01) AM_READWRITE(abcbus_status_r, abcbus_channel_w) |
| 388 | 388 | AM_RANGE(0x02, 0x05) AM_WRITE(abcbus_command_w) |
| 389 | 389 | AM_RANGE(0x07, 0x07) AM_READ(abcbus_reset_r) |
| 390 | | AM_RANGE(0x20, 0x23) AM_READWRITE(dart_r, dart_w) |
| 390 | AM_RANGE(0x20, 0x23) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w) |
| 391 | 391 | AM_RANGE(0x31, 0x31) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r) |
| 392 | | AM_RANGE(0x32, 0x35) AM_READWRITE(sio2_r, sio2_w) |
| 392 | AM_RANGE(0x32, 0x35) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w) |
| 393 | 393 | AM_RANGE(0x38, 0x38) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w) |
| 394 | 394 | AM_RANGE(0x39, 0x39) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w) |
| 395 | | AM_RANGE(0x60, 0x63) AM_READWRITE(z80ctc_0_r, z80ctc_0_w) |
| 395 | AM_RANGE(0x60, 0x63) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w) |
| 396 | 396 | AM_RANGE(0x80, 0xff) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w) |
| 397 | 397 | ADDRESS_MAP_END |
| 398 | 398 | |
| r3352 | r3353 | |
| 429 | 429 | AM_RANGE(0x02, 0x05) AM_MIRROR(0xff18) AM_WRITE(abcbus_command_w) |
| 430 | 430 | AM_RANGE(0x06, 0x06) AM_MIRROR(0xff18) AM_WRITE(abc806_hrs_w) |
| 431 | 431 | AM_RANGE(0x07, 0x07) AM_MIRROR(0xff18) AM_READWRITE(abcbus_reset_r, abc806_hrc_w) |
| 432 | | AM_RANGE(0x20, 0x23) AM_MIRROR(0xff0c) AM_READWRITE(dart_r, dart_w) |
| 432 | AM_RANGE(0x20, 0x23) AM_MIRROR(0xff0c) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w) |
| 433 | 433 | AM_RANGE(0x31, 0x31) AM_MIRROR(0xff06) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r) |
| 434 | 434 | AM_RANGE(0x34, 0x34) AM_MIRROR(0xff00) AM_MASK(0xff00) AM_READWRITE(abc806_bankswitch_r, abc806_bankswitch_w) |
| 435 | 435 | AM_RANGE(0x35, 0x35) AM_MIRROR(0xff00) AM_READWRITE(abc806_colorram_r, abc806_colorram_w) |
| r3352 | r3353 | |
| 437 | 437 | AM_RANGE(0x37, 0x37) AM_MIRROR(0xff00) AM_READWRITE(abc806_fgctlprom_r, abc806_sync_w) |
| 438 | 438 | AM_RANGE(0x38, 0x38) AM_MIRROR(0xff06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w) |
| 439 | 439 | AM_RANGE(0x39, 0x39) AM_MIRROR(0xff06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w) |
| 440 | | AM_RANGE(0x40, 0x41) AM_MIRROR(0xff1c) AM_READWRITE(sio2_r, sio2_w) |
| 441 | | AM_RANGE(0x60, 0x63) AM_MIRROR(0xff1c) AM_READWRITE(z80ctc_0_r, z80ctc_0_w) |
| 440 | AM_RANGE(0x40, 0x41) AM_MIRROR(0xff1c) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w) |
| 441 | AM_RANGE(0x60, 0x63) AM_MIRROR(0xff1c) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w) |
| 442 | 442 | AM_RANGE(0x80, 0x80) AM_MIRROR(0xff7f) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w) |
| 443 | 443 | ADDRESS_MAP_END |
| 444 | 444 | |
| r3352 | r3353 | |
| 597 | 597 | |
| 598 | 598 | /* Machine Initialization */ |
| 599 | 599 | |
| 600 | | static WRITE8_HANDLER( abc800_ctc_z2_w ) |
| 600 | static WRITE8_DEVICE_HANDLER( abc800_ctc_z2_w ) |
| 601 | 601 | { |
| 602 | 602 | // write to DART channel A RxC/TxC |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | | static z80ctc_interface abc800_ctc_intf = |
| 605 | static const z80ctc_interface abc800_ctc_intf = |
| 606 | 606 | { |
| 607 | "main", /* cpu */ |
| 607 | 608 | ABC800_X01/2/2, /* clock */ |
| 608 | 609 | 0, /* timer disables */ |
| 609 | 610 | 0, /* interrupt handler */ |
| r3352 | r3353 | |
| 612 | 613 | abc800_ctc_z2_w /* ZC/TO2 callback */ |
| 613 | 614 | }; |
| 614 | 615 | |
| 615 | | static WRITE8_HANDLER( sio_serial_transmit ) |
| 616 | static WRITE8_DEVICE_HANDLER( sio_serial_transmit ) |
| 616 | 617 | { |
| 617 | 618 | } |
| 618 | 619 | |
| 619 | | static int sio_serial_receive(int ch) |
| 620 | static int sio_serial_receive( const device_config *device, int channel ) |
| 620 | 621 | { |
| 621 | 622 | return -1; |
| 622 | 623 | } |
| 623 | 624 | |
| 624 | 625 | static z80sio_interface abc800_sio_intf = |
| 625 | 626 | { |
| 627 | "main", /* cpu */ |
| 626 | 628 | ABC800_X01/2/2, /* clock */ |
| 627 | 629 | 0, /* interrupt handler */ |
| 628 | 630 | 0, /* DTR changed handler */ |
| r3352 | r3353 | |
| 632 | 634 | sio_serial_receive /* receive handler */ |
| 633 | 635 | }; |
| 634 | 636 | |
| 635 | | static WRITE8_HANDLER( dart_serial_transmit ) |
| 637 | static WRITE8_DEVICE_HANDLER( dart_serial_transmit ) |
| 636 | 638 | { |
| 637 | 639 | } |
| 638 | 640 | |
| 639 | | static int dart_serial_receive(int ch) |
| 641 | static int dart_serial_receive(const device_config *device, int ch) |
| 640 | 642 | { |
| 641 | 643 | return -1; |
| 642 | 644 | } |
| 643 | 645 | |
| 644 | 646 | static const z80dart_interface abc800_dart_intf = |
| 645 | 647 | { |
| 648 | "main", /* cpu */ |
| 646 | 649 | ABC800_X01/2/2, /* clock */ |
| 647 | 650 | 0, /* interrupt handler */ |
| 648 | 651 | 0, /* DTR changed handler */ |
| r3352 | r3353 | |
| 652 | 655 | dart_serial_receive /* receive handler */ |
| 653 | 656 | }; |
| 654 | 657 | |
| 655 | | static WRITE8_HANDLER( abc802_dart_dtr_w ) |
| 658 | static WRITE8_DEVICE_HANDLER( abc802_dart_dtr_w ) |
| 656 | 659 | { |
| 657 | 660 | if (offset == 1) |
| 658 | 661 | { |
| r3352 | r3353 | |
| 660 | 663 | } |
| 661 | 664 | } |
| 662 | 665 | |
| 663 | | static WRITE8_HANDLER( abc802_dart_rts_w ) |
| 666 | static WRITE8_DEVICE_HANDLER( abc802_dart_rts_w ) |
| 664 | 667 | { |
| 665 | 668 | if (offset == 1) |
| 666 | 669 | { |
| r3352 | r3353 | |
| 670 | 673 | |
| 671 | 674 | static const z80dart_interface abc802_dart_intf = |
| 672 | 675 | { |
| 676 | "main", /* cpu */ |
| 673 | 677 | ABC800_X01/2/2, /* clock */ |
| 674 | 678 | 0, /* interrupt handler */ |
| 675 | 679 | abc802_dart_dtr_w, /* DTR changed handler */ |
| r3352 | r3353 | |
| 679 | 683 | dart_serial_receive /* receive handler */ |
| 680 | 684 | }; |
| 681 | 685 | |
| 682 | | static const struct z80_irq_daisy_chain abc800_daisy_chain[] = |
| 686 | static const z80_daisy_chain abc800_daisy_chain[] = |
| 683 | 687 | { |
| 684 | | { z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0 }, |
| 685 | | { z80sio_reset, z80sio_irq_state, z80sio_irq_ack, z80sio_irq_reti, 0 }, |
| 686 | | { z80dart_reset, z80dart_irq_state, z80dart_irq_ack, z80dart_irq_reti, 0 }, |
| 687 | | { 0, 0, 0, 0, -1 } |
| 688 | { Z80CTC, "z80ctc" }, |
| 689 | { Z80SIO, "z80sio" }, |
| 690 | { Z80DART, "z80dart" }, |
| 691 | { NULL } |
| 688 | 692 | }; |
| 689 | 693 | |
| 690 | 694 | static TIMER_CALLBACK(abc800_ctc_tick) |
| 691 | 695 | { |
| 692 | | z80ctc_trg_w(machine, 0, 0, 1); |
| 693 | | z80ctc_trg_w(machine, 0, 0, 0); |
| 694 | | z80ctc_trg_w(machine, 0, 1, 1); |
| 695 | | z80ctc_trg_w(machine, 0, 1, 0); |
| 696 | | z80ctc_trg_w(machine, 0, 2, 1); |
| 697 | | z80ctc_trg_w(machine, 0, 2, 0); |
| 696 | const device_config *device = ptr; |
| 697 | |
| 698 | z80ctc_trg_w(device, 0, 1); |
| 699 | z80ctc_trg_w(device, 0, 0); |
| 700 | z80ctc_trg_w(device, 1, 1); |
| 701 | z80ctc_trg_w(device, 1, 0); |
| 702 | z80ctc_trg_w(device, 2, 1); |
| 703 | z80ctc_trg_w(device, 2, 0); |
| 698 | 704 | } |
| 699 | 705 | |
| 700 | 706 | static MACHINE_START( abc800 ) |
| r3352 | r3353 | |
| 702 | 708 | state_save_register_global(abc77_keylatch); |
| 703 | 709 | state_save_register_global(abc77_clock); |
| 704 | 710 | |
| 705 | | abc800_ctc_timer = timer_alloc(abc800_ctc_tick, NULL); |
| 711 | abc800_ctc_timer = timer_alloc(abc800_ctc_tick, (void *)device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc") ); |
| 706 | 712 | timer_adjust_periodic(abc800_ctc_timer, attotime_zero, 0, ATTOTIME_IN_HZ(ABC800_X01/2/2/2)); |
| 707 | | |
| 708 | | z80ctc_init(0, &abc800_ctc_intf); |
| 709 | | z80sio_init(0, &abc800_sio_intf); |
| 710 | | z80dart_init(0, &abc800_dart_intf); |
| 711 | 713 | } |
| 712 | 714 | |
| 713 | 715 | static MACHINE_START( abc802 ) |
| 714 | 716 | { |
| 715 | 717 | MACHINE_START_CALL(abc800); |
| 716 | 718 | |
| 717 | | z80dart_init(0, &abc802_dart_intf); |
| 718 | | |
| 719 | 719 | memory_configure_bank(1, 0, 1, memory_region(machine, "main"), 0); |
| 720 | 720 | memory_configure_bank(1, 1, 1, mess_ram, 0); |
| 721 | 721 | } |
| r3352 | r3353 | |
| 798 | 798 | |
| 799 | 799 | MDRV_MACHINE_START(abc800) |
| 800 | 800 | |
| 801 | MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf ) |
| 802 | MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf ) |
| 803 | MDRV_Z80DART_ADD( "z80dart", abc800_dart_intf ) |
| 804 | |
| 801 | 805 | MDRV_IMPORT_FROM(abc800m_video) |
| 802 | 806 | |
| 803 | 807 | MDRV_DEVICE_ADD("printer", PRINTER) |
| r3352 | r3353 | |
| 819 | 823 | |
| 820 | 824 | MDRV_MACHINE_START(abc800) |
| 821 | 825 | |
| 826 | MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf ) |
| 827 | MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf ) |
| 828 | MDRV_Z80DART_ADD( "z80dart", abc800_dart_intf ) |
| 829 | |
| 822 | 830 | MDRV_IMPORT_FROM(abc800c_video) |
| 823 | 831 | |
| 824 | 832 | MDRV_DEVICE_ADD("printer", PRINTER) |
| r3352 | r3353 | |
| 841 | 849 | MDRV_MACHINE_START(abc802) |
| 842 | 850 | MDRV_MACHINE_RESET(abc802) |
| 843 | 851 | |
| 852 | MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf ) |
| 853 | MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf ) |
| 854 | MDRV_Z80DART_ADD( "z80dart", abc802_dart_intf ) |
| 855 | |
| 844 | 856 | MDRV_IMPORT_FROM(abc802_video) |
| 845 | 857 | |
| 846 | 858 | MDRV_DEVICE_ADD("printer", PRINTER) |
| r3352 | r3353 | |
| 863 | 875 | MDRV_MACHINE_START(abc806) |
| 864 | 876 | MDRV_MACHINE_RESET(abc806) |
| 865 | 877 | |
| 878 | MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf ) |
| 879 | MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf ) |
| 880 | MDRV_Z80DART_ADD( "z80dart", abc800_dart_intf ) |
| 881 | |
| 866 | 882 | MDRV_IMPORT_FROM(abc806_video) |
| 867 | 883 | |
| 868 | 884 | MDRV_DEVICE_ADD("printer", PRINTER) |
src/mess/drivers/einstein.c
| r3352 | r3353 | |
| 327 | 327 | |
| 328 | 328 | static TIMER_CALLBACK(einstein_ctc_trigger_callback) |
| 329 | 329 | { |
| 330 | const device_config *device = ptr; |
| 331 | |
| 330 | 332 | einstein_ctc_trigger^=1; |
| 331 | 333 | |
| 332 | 334 | /* channel 0 and 1 have a 2Mhz input clock for triggering */ |
| 333 | | z80ctc_0_trg0_w(machine, 0, einstein_ctc_trigger); |
| 334 | | z80ctc_0_trg1_w(machine, 0, einstein_ctc_trigger); |
| 335 | z80ctc_trg0_w(device, 0, einstein_ctc_trigger); |
| 336 | z80ctc_trg1_w(device, 0, einstein_ctc_trigger); |
| 335 | 337 | } |
| 336 | 338 | |
| 337 | 339 | /* refresh keyboard data. It is refreshed when the keyboard line is written */ |
| r3352 | r3353 | |
| 403 | 405 | |
| 404 | 406 | |
| 405 | 407 | /* interrupt state callback for ctc */ |
| 406 | | static void einstein_ctc_interrupt(running_machine *machine, int state) |
| 408 | static void einstein_ctc_interrupt(const device_config *device, int state) |
| 407 | 409 | { |
| 408 | 410 | logerror("ctc irq state: %02x\n",state); |
| 409 | | cpunum_set_input_line(machine, 0, 1, state); |
| 411 | cpunum_set_input_line(device->machine, 0, 1, state); |
| 410 | 412 | } |
| 411 | 413 | |
| 412 | | static void einstein_pio_interrupt(running_machine *machine, int state) |
| 414 | static void einstein_pio_interrupt(const device_config *device, int state) |
| 413 | 415 | { |
| 414 | 416 | logerror("pio irq state: %02x\n",state); |
| 415 | | cpunum_set_input_line(machine, 0, 3, state); |
| 417 | cpunum_set_input_line(device->machine, 0, 3, state); |
| 416 | 418 | } |
| 417 | 419 | |
| 418 | | static WRITE8_HANDLER(einstein_serial_transmit_clock) |
| 420 | static WRITE8_DEVICE_HANDLER(einstein_serial_transmit_clock) |
| 419 | 421 | { |
| 420 | 422 | msm8251_transmit_clock(); |
| 421 | 423 | } |
| 422 | 424 | |
| 423 | | static WRITE8_HANDLER(einstein_serial_receive_clock) |
| 425 | static WRITE8_DEVICE_HANDLER(einstein_serial_receive_clock) |
| 424 | 426 | { |
| 425 | 427 | msm8251_receive_clock(); |
| 426 | 428 | } |
| 427 | 429 | |
| 428 | 430 | static z80ctc_interface einstein_ctc_intf = |
| 429 | 431 | { |
| 432 | "main", |
| 430 | 433 | EINSTEIN_SYSTEM_CLOCK, |
| 431 | 434 | 0, |
| 432 | 435 | einstein_ctc_interrupt, |
| 433 | 436 | einstein_serial_transmit_clock, |
| 434 | 437 | einstein_serial_receive_clock, |
| 435 | | z80ctc_0_trg3_w |
| 438 | z80ctc_trg3_w |
| 436 | 439 | }; |
| 437 | 440 | |
| 438 | 441 | static void einstein_pio_ardy(int data) |
| r3352 | r3353 | |
| 461 | 464 | NULL |
| 462 | 465 | }; |
| 463 | 466 | |
| 464 | | /* not required for this interrupt source */ |
| 465 | | static void einstein_keyboard_int_reset(int which) |
| 467 | |
| 468 | /**************************************************************** |
| 469 | Einstein specific keyboard daisy chain code |
| 470 | ****************************************************************/ |
| 471 | |
| 472 | static int einstein_daisy_irq_state(const device_config *device) |
| 466 | 473 | { |
| 467 | | einstein_int_mask &= ~EINSTEIN_KEY_INT; |
| 474 | return 0xFF; |
| 475 | } |
| 468 | 476 | |
| 469 | | einstein_update_interrupts(Machine); |
| 477 | |
| 478 | static void einstein_daisy_irq_reti(const device_config *device) |
| 479 | { |
| 470 | 480 | } |
| 471 | 481 | |
| 472 | 482 | |
| 473 | | /* not required for this interrupt source */ |
| 474 | | static void einstein_adc_int_reset(int which) |
| 483 | static DEVICE_START( einstein_daisy ) |
| 475 | 484 | { |
| 476 | | einstein_int_mask &= ~EINSTEIN_ADC_INT; |
| 485 | return DEVICE_START_OK; |
| 486 | } |
| 477 | 487 | |
| 478 | | einstein_update_interrupts(Machine); |
| 488 | |
| 489 | static DEVICE_RESET( einstein_daisy ) |
| 490 | { |
| 479 | 491 | } |
| 480 | 492 | |
| 493 | |
| 494 | static DEVICE_SET_INFO( einstein_daisy ) |
| 495 | { |
| 496 | } |
| 497 | |
| 498 | |
| 499 | static DEVICE_GET_INFO( einstein_daisy ) |
| 500 | { |
| 501 | switch (state) |
| 502 | { |
| 503 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 504 | case DEVINFO_INT_TOKEN_BYTES: info->i = 4; break; |
| 505 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 506 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 507 | |
| 508 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 509 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(einstein_daisy); break; |
| 510 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(einstein_daisy); break; |
| 511 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 512 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(einstein_daisy); break; |
| 513 | case DEVINFO_FCT_IRQ_STATE: info->f = (genf *)einstein_daisy_irq_state; break; |
| 514 | case DEVINFO_FCT_IRQ_RETI: info->f = (genf *)einstein_daisy_irq_reti; break; |
| 515 | |
| 516 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 517 | case DEVINFO_STR_NAME: info->s = "Einstein daisy"; break; |
| 518 | case DEVINFO_STR_FAMILY: info->s = "Z80"; break; |
| 519 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 520 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 521 | case DEVINFO_STR_CREDITS: info->s = "Copyright the MESS Team"; break; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | |
| 481 | 526 | #ifdef UNUSED_FUNCTION |
| 482 | 527 | /* not required for this interrupt source */ |
| 483 | 528 | static void einstein_fire_int_reset(int which) |
| r3352 | r3353 | |
| 486 | 531 | |
| 487 | 532 | einstein_update_interrupts(Machine); |
| 488 | 533 | } |
| 489 | | #endif |
| 490 | 534 | |
| 491 | | static int einstein_keyboard_interrupt(int which) |
| 492 | | { |
| 493 | | logerror("keyboard int routine in daisy chain\n"); |
| 494 | 535 | |
| 495 | | /* return vector */ |
| 496 | | return 0x0ff; |
| 497 | | } |
| 498 | | |
| 499 | | static int einstein_adc_interrupt(int which) |
| 500 | | { |
| 501 | | logerror("adc int routine in daisy chain\n"); |
| 502 | | /* return vector */ |
| 503 | | return 0x0ff; |
| 504 | | } |
| 505 | | |
| 506 | | #ifdef UNUSED_FUNCTION |
| 507 | 536 | static int einstein_fire_interrupt(int which) |
| 508 | 537 | { |
| 509 | 538 | logerror("fire int routine in daisy chain\n"); |
| 510 | 539 | /* return vector */ |
| 511 | 540 | return 0x0ff; |
| 512 | 541 | } |
| 513 | | #endif |
| 514 | 542 | |
| 515 | | /* reti has no effect on this interrupt */ |
| 516 | | static void einstein_keyboard_reti(int which) |
| 517 | | { |
| 518 | | } |
| 519 | 543 | |
| 520 | 544 | /* reti has no effect on this interrupt */ |
| 521 | | static void einstein_adc_reti(int which) |
| 522 | | { |
| 523 | | } |
| 524 | | |
| 525 | | #ifdef UNUSED_FUNCTION |
| 526 | | /* reti has no effect on this interrupt */ |
| 527 | 545 | static void einstein_fire_reti(int which) |
| 528 | 546 | { |
| 529 | 547 | } |
| 530 | 548 | #endif |
| 531 | 549 | |
| 532 | | static void einstein_z80pio_reset(int which) |
| 550 | static const z80_daisy_chain einstein_daisy_chain[] = |
| 533 | 551 | { |
| 534 | | z80pio_reset( einstein_z80pio ); |
| 535 | | } |
| 536 | | |
| 537 | | static int einstein_z80pio_irq_state(int which) |
| 538 | | { |
| 539 | | return z80pio_irq_state( einstein_z80pio ); |
| 540 | | } |
| 541 | | |
| 542 | | static int einstein_z80pio_irq_ack(int which) |
| 543 | | { |
| 544 | | return z80pio_irq_ack( einstein_z80pio ); |
| 545 | | } |
| 546 | | |
| 547 | | static void einstein_z80pio_irq_reti(int which) |
| 548 | | { |
| 549 | | z80pio_irq_reti( einstein_z80pio ); |
| 550 | | } |
| 551 | | |
| 552 | | static const struct z80_irq_daisy_chain einstein_daisy_chain[] = |
| 553 | | { |
| 554 | | {einstein_keyboard_int_reset, einstein_keyboard_interrupt, 0, einstein_keyboard_reti, 0}, |
| 555 | | {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0}, |
| 556 | | {einstein_adc_int_reset,einstein_adc_interrupt, 0, einstein_adc_reti, 0}, |
| 557 | | {einstein_z80pio_reset, einstein_z80pio_irq_state, einstein_z80pio_irq_ack, einstein_z80pio_irq_reti, 0}, |
| 552 | { DEVICE_GET_INFO_NAME( einstein_daisy ), "keyboard_daisy" }, |
| 553 | // {einstein_keyboard_int_reset, einstein_keyboard_interrupt, 0, einstein_keyboard_reti, 0}, |
| 554 | { Z80CTC, "z80ctc" }, |
| 555 | { DEVICE_GET_INFO_NAME( einstein_daisy ), "adc_daisy" }, |
| 556 | // {einstein_adc_int_reset,einstein_adc_interrupt, 0, einstein_adc_reti, 0}, |
| 557 | { Z80PIO, "z80pio" }, |
| 558 | 558 | // {einstein_fire_int_reset,einstein_fire_interrupt, einstein_fire_reti, 0}, |
| 559 | | {0,0,0,0,-1} |
| 559 | { NULL } |
| 560 | 560 | }; |
| 561 | 561 | |
| 562 | 562 | static READ8_HANDLER(einstein_vdp_r) |
| r3352 | r3353 | |
| 675 | 675 | return z80pio_r( einstein_z80pio, offset ); |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | | static READ8_HANDLER(einstein_ctc_r) |
| 678 | static READ8_DEVICE_HANDLER(einstein_ctc_r) |
| 679 | 679 | { |
| 680 | 680 | logerror("ctc r: %04x\n",offset); |
| 681 | 681 | |
| 682 | | return z80ctc_0_r(machine, offset & 0x03); |
| 682 | return z80ctc_r(device, offset & 0x03); |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | | static WRITE8_HANDLER(einstein_ctc_w) |
| 685 | static WRITE8_DEVICE_HANDLER(einstein_ctc_w) |
| 686 | 686 | { |
| 687 | 687 | logerror("ctc w: %04x %02x\n",offset,data); |
| 688 | 688 | |
| 689 | | z80ctc_0_w(machine, offset & 0x03,data); |
| 689 | z80ctc_w(device, offset & 0x03,data); |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | static WRITE8_HANDLER(einstein_serial_w) |
| r3352 | r3353 | |
| 1019 | 1019 | case 0x2d: |
| 1020 | 1020 | case 0x2e: |
| 1021 | 1021 | case 0x2f: |
| 1022 | | return einstein_ctc_r(machine, offset); |
| 1022 | return einstein_ctc_r( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset); |
| 1023 | 1023 | case 0x30: |
| 1024 | 1024 | case 0x31: |
| 1025 | 1025 | case 0x32: |
| r3352 | r3353 | |
| 1123 | 1123 | case 0x2d: |
| 1124 | 1124 | case 0x2e: |
| 1125 | 1125 | case 0x2f: |
| 1126 | | einstein_ctc_w(machine, offset,data); |
| 1126 | einstein_ctc_w( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset,data); |
| 1127 | 1127 | return; |
| 1128 | 1128 | case 0x30: |
| 1129 | 1129 | case 0x31: |
| r3352 | r3353 | |
| 1212 | 1212 | case 0x2d: |
| 1213 | 1213 | case 0x2e: |
| 1214 | 1214 | case 0x2f: |
| 1215 | | return einstein_ctc_r(machine, offset); |
| 1215 | return einstein_ctc_r( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset); |
| 1216 | 1216 | case 0x30: |
| 1217 | 1217 | case 0x31: |
| 1218 | 1218 | case 0x32: |
| r3352 | r3353 | |
| 1299 | 1299 | case 0x2d: |
| 1300 | 1300 | case 0x2e: |
| 1301 | 1301 | case 0x2f: |
| 1302 | | einstein_ctc_w(machine, offset,data); |
| 1302 | einstein_ctc_w( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset,data); |
| 1303 | 1303 | return; |
| 1304 | 1304 | case 0x30: |
| 1305 | 1305 | case 0x31: |
| r3352 | r3353 | |
| 1438 | 1438 | memory_set_bankptr(3, mess_ram); |
| 1439 | 1439 | memory_set_bankptr(4, mess_ram+0x02000); |
| 1440 | 1440 | |
| 1441 | | z80ctc_init(0, &einstein_ctc_intf); |
| 1442 | 1441 | msm8251_init(&einstein_msm8251_intf); |
| 1443 | 1442 | |
| 1444 | | z80ctc_reset(0); |
| 1445 | | |
| 1446 | 1443 | TMS9928A_reset (); |
| 1447 | 1444 | |
| 1448 | 1445 | einstein_rom_enabled = 1; |
| r3352 | r3353 | |
| 1465 | 1462 | |
| 1466 | 1463 | /* the input to channel 0 and 1 of the ctc is a 2mhz clock */ |
| 1467 | 1464 | einstein_ctc_trigger = 0; |
| 1468 | | timer_pulse(ATTOTIME_IN_HZ(2000000), NULL, 0, einstein_ctc_trigger_callback); |
| 1465 | timer_pulse(ATTOTIME_IN_HZ(2000000), (void *)device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), 0, einstein_ctc_trigger_callback); |
| 1469 | 1466 | |
| 1470 | 1467 | centronics_config(0, einstein_cent_config); |
| 1471 | 1468 | /* assumption: select is tied low */ |
| r3352 | r3353 | |
| 1731 | 1728 | MDRV_MACHINE_RESET( einstein ) |
| 1732 | 1729 | |
| 1733 | 1730 | MDRV_Z80PIO_ADD( "z80pio", einstein_pio_intf ) |
| 1731 | MDRV_Z80CTC_ADD( "z80ctc", einstein_ctc_intf ) |
| 1732 | MDRV_DEVICE_ADD( "keyboard_daisy", DEVICE_GET_INFO_NAME( einstein_daisy ) ) |
| 1733 | MDRV_DEVICE_ADD( "adc_daisy", DEVICE_GET_INFO_NAME( einstein_daisy ) ) |
| 1734 | 1734 | |
| 1735 | 1735 | /* video hardware */ |
| 1736 | 1736 | MDRV_IMPORT_FROM(tms9928a) |