src/mess/machine/z80dart.c
| r3353 | r3354 | |
| 158 | 158 | dart_channel chan[2]; /* 2 channels */ |
| 159 | 159 | UINT8 int_state[8]; /* interrupt states */ |
| 160 | 160 | |
| 161 | | void (*irq_cb)(int state); |
| 162 | | write8_machine_func dtr_changed_cb; |
| 163 | | write8_machine_func rts_changed_cb; |
| 164 | | write8_machine_func break_changed_cb; |
| 165 | | write8_machine_func transmit_cb; |
| 166 | | int (*receive_poll_cb)(int which); |
| 161 | void (*irq_cb)(const device_config *device, int state); |
| 162 | write8_device_func dtr_changed_cb; |
| 163 | write8_device_func rts_changed_cb; |
| 164 | write8_device_func break_changed_cb; |
| 165 | write8_device_func transmit_cb; |
| 166 | int (*receive_poll_cb)(const device_config *device, int ch); |
| 167 | 167 | }; |
| 168 | 168 | |
| 169 | 169 | |
| r3353 | r3354 | |
| 173 | 173 | ***************************************************************************/ |
| 174 | 174 | |
| 175 | 175 | static TIMER_CALLBACK(serial_callback); |
| 176 | static int z80dart_irq_state(const device_config *device); |
| 176 | 177 | |
| 177 | 178 | |
| 178 | 179 | |
| 179 | | /*************************************************************************** |
| 180 | | GLOBAL VARIABLES |
| 181 | | ***************************************************************************/ |
| 182 | | |
| 183 | | static z80dart darts[MAX_DART]; |
| 184 | | |
| 185 | | |
| 186 | 180 | /* |
| 187 | 181 | |
| 188 | 182 | Interrupt priorities: |
| r3353 | r3354 | |
| 239 | 233 | INLINE FUNCTIONS |
| 240 | 234 | ***************************************************************************/ |
| 241 | 235 | |
| 242 | | INLINE void interrupt_check(z80dart *dart) |
| 236 | INLINE z80dart *get_safe_token(const device_config *device) |
| 243 | 237 | { |
| 238 | assert(device != NULL); |
| 239 | assert(device->token != NULL); |
| 240 | assert(device->type == Z80DART); |
| 241 | return (z80dart *)device->token; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | INLINE void interrupt_check(const device_config *device) |
| 246 | { |
| 247 | z80dart *dart = get_safe_token( device ); |
| 248 | |
| 244 | 249 | /* if we have a callback, update it with the current state */ |
| 245 | 250 | if (dart->irq_cb != NULL) |
| 246 | | (*dart->irq_cb)((z80dart_irq_state(dart - darts) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE); |
| 251 | dart->irq_cb(device, (z80dart_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE); |
| 247 | 252 | } |
| 248 | 253 | |
| 249 | 254 | |
| 250 | | INLINE attotime compute_time_per_character(z80dart *dart, int which) |
| 255 | INLINE attotime compute_time_per_character(const device_config *device, int ch) |
| 251 | 256 | { |
| 252 | 257 | /* fix me -- should compute properly and include data, stop, parity bits */ |
| 253 | 258 | return ATTOTIME_IN_HZ(9600 / 10); |
| 254 | 259 | } |
| 255 | 260 | |
| 256 | 261 | |
| 257 | | |
| 258 | | /*************************************************************************** |
| 259 | | INITIALIZATION/CONFIGURATION |
| 260 | | ***************************************************************************/ |
| 261 | | |
| 262 | | /*------------------------------------------------- |
| 263 | | z80dart_init - initialize a single DART chip |
| 264 | | -------------------------------------------------*/ |
| 265 | | |
| 266 | | void z80dart_init(int which, const z80dart_interface *intf) |
| 262 | INLINE void reset_channel(const device_config *device, int ch) |
| 267 | 263 | { |
| 268 | | z80dart *dart = darts + which; |
| 269 | | |
| 270 | | assert(which < MAX_DART); |
| 271 | | |
| 272 | | memset(dart, 0, sizeof(*dart)); |
| 273 | | |
| 274 | | dart->chan[0].receive_timer = timer_alloc(serial_callback, NULL); |
| 275 | | dart->chan[1].receive_timer = timer_alloc(serial_callback, NULL); |
| 276 | | |
| 277 | | dart->irq_cb = intf->irq_cb; |
| 278 | | dart->dtr_changed_cb = intf->dtr_changed_cb; |
| 279 | | dart->rts_changed_cb = intf->rts_changed_cb; |
| 280 | | dart->break_changed_cb = intf->break_changed_cb; |
| 281 | | dart->transmit_cb = intf->transmit_cb; |
| 282 | | dart->receive_poll_cb = intf->receive_poll_cb; |
| 283 | | |
| 284 | | z80dart_reset(which); |
| 285 | | } |
| 286 | | |
| 287 | | |
| 288 | | /*------------------------------------------------- |
| 289 | | reset_channel - reset a single DART channel |
| 290 | | -------------------------------------------------*/ |
| 291 | | |
| 292 | | static void reset_channel(z80dart *dart, int ch) |
| 293 | | { |
| 294 | | attotime tpc = compute_time_per_character(dart, ch); |
| 264 | z80dart *dart = get_safe_token( device ); |
| 265 | attotime tpc = compute_time_per_character(device, ch); |
| 295 | 266 | dart_channel *chan = &dart->chan[ch]; |
| 296 | 267 | |
| 297 | 268 | chan->status[0] = DART_RR0_TX_BUFFER_EMPTY; |
| r3353 | r3354 | |
| 305 | 276 | dart->int_state[2 + 4*ch] = 0; |
| 306 | 277 | dart->int_state[3 + 4*ch] = 0; |
| 307 | 278 | |
| 308 | | interrupt_check(dart); |
| 309 | | |
| 310 | 279 | /* start the receive timer running */ |
| 311 | | timer_adjust_periodic(chan->receive_timer, tpc, ((dart - darts) << 1) | ch, tpc); |
| 280 | timer_adjust_periodic(chan->receive_timer, tpc, ch, tpc); |
| 312 | 281 | } |
| 313 | 282 | |
| 314 | 283 | |
| 315 | | /*------------------------------------------------- |
| 316 | | z80dart_reset - reset a single DART chip |
| 317 | | -------------------------------------------------*/ |
| 318 | 284 | |
| 319 | | void z80dart_reset(int which) |
| 320 | | { |
| 321 | | z80dart *dart = darts + which; |
| 322 | | int ch; |
| 323 | | |
| 324 | | assert(which < MAX_DART); |
| 325 | | |
| 326 | | /* loop over channels */ |
| 327 | | for (ch = 0; ch < 2; ch++) |
| 328 | | reset_channel(dart, ch); |
| 329 | | } |
| 330 | | |
| 331 | | |
| 332 | | |
| 333 | 285 | /*************************************************************************** |
| 334 | 286 | CONTROL REGISTER READ/WRITE |
| 335 | 287 | ***************************************************************************/ |
| r3353 | r3354 | |
| 338 | 290 | z80dart_c_w - write to a control register |
| 339 | 291 | -------------------------------------------------*/ |
| 340 | 292 | |
| 341 | | void z80dart_c_w(running_machine *machine, int which, int ch, UINT8 data) |
| 293 | WRITE8_DEVICE_HANDLER( z80dart_c_w ) |
| 342 | 294 | { |
| 343 | | z80dart *dart = darts + which; |
| 344 | | dart_channel *chan = &dart->chan[ch]; |
| 295 | z80dart *dart = get_safe_token( device ); |
| 296 | dart_channel *chan = &dart->chan[offset]; |
| 345 | 297 | int reg = chan->regs[0] & 7; |
| 346 | 298 | UINT8 old = chan->regs[reg]; |
| 347 | 299 | |
| 348 | 300 | if (reg != 0 || (reg & 0xf8)) |
| 349 | | VPRINTF(("%04X:dart_reg_w(%c,%d) = %02X\n", activecpu_get_pc(), 'A' + ch, reg, data)); |
| 301 | VPRINTF(("%04X:dart_reg_w(%c,%d) = %02X\n", activecpu_get_pc(), 'A' + offset, reg, data)); |
| 350 | 302 | |
| 351 | 303 | /* write a new value to the selected register */ |
| 352 | 304 | chan->regs[reg] = data; |
| r3353 | r3354 | |
| 363 | 315 | switch (data & DART_WR0_COMMAND_MASK) |
| 364 | 316 | { |
| 365 | 317 | case DART_WR0_COMMAND_CH_RESET: |
| 366 | | VPRINTF(("%04X:DART reset channel %c\n", activecpu_get_pc(), 'A' + ch)); |
| 367 | | reset_channel(dart, ch); |
| 318 | VPRINTF(("%04X:DART reset channel %c\n", activecpu_get_pc(), 'A' + offset)); |
| 319 | reset_channel(device, offset); |
| 320 | interrupt_check(device); |
| 368 | 321 | break; |
| 369 | 322 | |
| 370 | 323 | case DART_WR0_COMMAND_RES_STATUS_INT: |
| 371 | | dart->int_state[INT_CHA_STATUS - 4*ch] &= ~Z80_DAISY_INT; |
| 372 | | interrupt_check(dart); |
| 324 | dart->int_state[INT_CHA_STATUS - 4*offset] &= ~Z80_DAISY_INT; |
| 325 | interrupt_check(device); |
| 373 | 326 | break; |
| 374 | 327 | |
| 375 | 328 | case DART_WR0_COMMAND_ENA_RX_INT: |
| 376 | 329 | chan->int_on_next_rx = TRUE; |
| 377 | | interrupt_check(dart); |
| 330 | interrupt_check(device); |
| 378 | 331 | break; |
| 379 | 332 | |
| 380 | 333 | case DART_WR0_COMMAND_RES_TX_INT: |
| 381 | | dart->int_state[INT_CHA_TRANSMIT - 4*ch] &= ~Z80_DAISY_INT; |
| 382 | | interrupt_check(dart); |
| 334 | dart->int_state[INT_CHA_TRANSMIT - 4*offset] &= ~Z80_DAISY_INT; |
| 335 | interrupt_check(device); |
| 383 | 336 | break; |
| 384 | 337 | |
| 385 | 338 | case DART_WR0_COMMAND_RES_ERROR: |
| 386 | | dart->int_state[INT_CHA_ERROR - 4*ch] &= ~Z80_DAISY_INT; |
| 387 | | interrupt_check(dart); |
| 339 | dart->int_state[INT_CHA_ERROR - 4*offset] &= ~Z80_DAISY_INT; |
| 340 | interrupt_check(device); |
| 388 | 341 | break; |
| 389 | 342 | } |
| 390 | 343 | break; |
| 391 | 344 | |
| 392 | 345 | /* DART write register 1 */ |
| 393 | 346 | case 1: |
| 394 | | interrupt_check(dart); |
| 347 | interrupt_check(device); |
| 395 | 348 | break; |
| 396 | 349 | |
| 397 | 350 | /* DART write register 5 */ |
| 398 | 351 | case 5: |
| 399 | 352 | if (((old ^ data) & DART_WR5_DTR) && dart->dtr_changed_cb) |
| 400 | | (*dart->dtr_changed_cb)(machine, ch, (data & DART_WR5_DTR) != 0); |
| 353 | (*dart->dtr_changed_cb)(device, offset, (data & DART_WR5_DTR) != 0); |
| 401 | 354 | if (((old ^ data) & DART_WR5_SEND_BREAK) && dart->break_changed_cb) |
| 402 | | (*dart->break_changed_cb)(machine, ch, (data & DART_WR5_SEND_BREAK) != 0); |
| 355 | (*dart->break_changed_cb)(device, offset, (data & DART_WR5_SEND_BREAK) != 0); |
| 403 | 356 | if (((old ^ data) & DART_WR5_RTS) && dart->rts_changed_cb) |
| 404 | | (*dart->rts_changed_cb)(machine, ch, (data & DART_WR5_RTS) != 0); |
| 357 | (*dart->rts_changed_cb)(device, offset, (data & DART_WR5_RTS) != 0); |
| 405 | 358 | break; |
| 406 | 359 | } |
| 407 | 360 | } |
| r3353 | r3354 | |
| 411 | 364 | z80dart_c_r - read from a control register |
| 412 | 365 | -------------------------------------------------*/ |
| 413 | 366 | |
| 414 | | UINT8 z80dart_c_r(int which, int ch) |
| 367 | READ8_DEVICE_HANDLER( z80dart_c_r ) |
| 415 | 368 | { |
| 416 | | z80dart *dart = darts + which; |
| 417 | | dart_channel *chan = &dart->chan[ch]; |
| 369 | z80dart *dart = get_safe_token( device ); |
| 370 | dart_channel *chan = &dart->chan[offset]; |
| 418 | 371 | int reg = chan->regs[0] & 7; |
| 419 | 372 | UINT8 result = chan->status[reg]; |
| 420 | 373 | |
| r3353 | r3354 | |
| 424 | 377 | /* DART read register 0 */ |
| 425 | 378 | case 0: |
| 426 | 379 | result &= ~DART_RR0_INT_PENDING; |
| 427 | | if (z80dart_irq_state(which) & Z80_DAISY_INT) |
| 380 | if (z80dart_irq_state(device) & Z80_DAISY_INT) |
| 428 | 381 | result |= DART_RR0_INT_PENDING; |
| 429 | 382 | break; |
| 430 | 383 | } |
| 431 | 384 | |
| 432 | | VPRINTF(("%04X:dart_reg_r(%c,%d) = %02x\n", activecpu_get_pc(), 'A' + ch, reg, chan->status[reg])); |
| 385 | VPRINTF(("%04X:dart_reg_r(%c,%d) = %02x\n", activecpu_get_pc(), 'A' + offset, reg, chan->status[reg])); |
| 433 | 386 | |
| 434 | 387 | return chan->status[reg]; |
| 435 | 388 | } |
| r3353 | r3354 | |
| 445 | 398 | z80dart_d_w - write to a data register |
| 446 | 399 | -------------------------------------------------*/ |
| 447 | 400 | |
| 448 | | void z80dart_d_w(int which, int ch, UINT8 data) |
| 401 | WRITE8_DEVICE_HANDLER( z80dart_d_w ) |
| 449 | 402 | { |
| 450 | | z80dart *dart = darts + which; |
| 451 | | dart_channel *chan = &dart->chan[ch]; |
| 403 | z80dart *dart = get_safe_token( device ); |
| 404 | dart_channel *chan = &dart->chan[offset]; |
| 452 | 405 | |
| 453 | | VPRINTF(("%04X:dart_data_w(%c) = %02X\n", activecpu_get_pc(), 'A' + ch, data)); |
| 406 | VPRINTF(("%04X:dart_data_w(%c) = %02X\n", activecpu_get_pc(), 'A' + offset, data)); |
| 454 | 407 | |
| 455 | 408 | /* if tx not enabled, just ignore it */ |
| 456 | 409 | if (!(chan->regs[5] & DART_WR5_TX_ENABLE)) |
| r3353 | r3354 | |
| 460 | 413 | chan->status[0] &= ~DART_RR0_TX_BUFFER_EMPTY; |
| 461 | 414 | |
| 462 | 415 | /* reset the transmit interrupt */ |
| 463 | | dart->int_state[INT_CHA_TRANSMIT - 4*ch] &= ~Z80_DAISY_INT; |
| 464 | | interrupt_check(dart); |
| 416 | dart->int_state[INT_CHA_TRANSMIT - 4*offset] &= ~Z80_DAISY_INT; |
| 417 | interrupt_check(device); |
| 465 | 418 | |
| 466 | 419 | /* stash the character */ |
| 467 | 420 | chan->outbuf = data; |
| r3353 | r3354 | |
| 472 | 425 | z80dart_d_r - read from a data register |
| 473 | 426 | -------------------------------------------------*/ |
| 474 | 427 | |
| 475 | | UINT8 z80dart_d_r(int which, int ch) |
| 428 | READ8_DEVICE_HANDLER( z80dart_d_r ) |
| 476 | 429 | { |
| 477 | | z80dart *dart = darts + which; |
| 478 | | dart_channel *chan = &dart->chan[ch]; |
| 430 | z80dart *dart = get_safe_token( device ); |
| 431 | dart_channel *chan = &dart->chan[offset]; |
| 479 | 432 | |
| 480 | 433 | /* update the status register */ |
| 481 | 434 | chan->status[0] &= ~DART_RR0_RX_CHAR_AVAILABLE; |
| 482 | 435 | |
| 483 | 436 | /* reset the receive interrupt */ |
| 484 | | dart->int_state[INT_CHA_RECEIVE - 4*ch] &= ~Z80_DAISY_INT; |
| 485 | | interrupt_check(dart); |
| 437 | dart->int_state[INT_CHA_RECEIVE - 4*offset] &= ~Z80_DAISY_INT; |
| 438 | interrupt_check(device); |
| 486 | 439 | |
| 487 | | VPRINTF(("%04X:dart_data_r(%c) = %02X\n", activecpu_get_pc(), 'A' + ch, chan->inbuf)); |
| 440 | VPRINTF(("%04X:dart_data_r(%c) = %02X\n", activecpu_get_pc(), 'A' + offset, chan->inbuf)); |
| 488 | 441 | |
| 489 | 442 | return chan->inbuf; |
| 490 | 443 | } |
| r3353 | r3354 | |
| 500 | 453 | line |
| 501 | 454 | -------------------------------------------------*/ |
| 502 | 455 | |
| 503 | | int z80dart_get_dtr(int which, int ch) |
| 456 | int z80dart_get_dtr(const device_config *device, int ch) |
| 504 | 457 | { |
| 505 | | z80dart *dart = darts + which; |
| 458 | z80dart *dart = get_safe_token( device ); |
| 506 | 459 | dart_channel *chan = &dart->chan[ch]; |
| 507 | 460 | return ((chan->regs[5] & DART_WR5_DTR) != 0); |
| 508 | 461 | } |
| r3353 | r3354 | |
| 513 | 466 | line |
| 514 | 467 | -------------------------------------------------*/ |
| 515 | 468 | |
| 516 | | int z80dart_get_rts(int which, int ch) |
| 469 | int z80dart_get_rts(const device_config *device, int ch) |
| 517 | 470 | { |
| 518 | | z80dart *dart = darts + which; |
| 471 | z80dart *dart = get_safe_token( device ); |
| 519 | 472 | dart_channel *chan = &dart->chan[ch]; |
| 520 | 473 | return ((chan->regs[5] & DART_WR5_RTS) != 0); |
| 521 | 474 | } |
| r3353 | r3354 | |
| 528 | 481 | |
| 529 | 482 | static TIMER_CALLBACK(change_input_line) |
| 530 | 483 | { |
| 531 | | z80dart *dart = darts + ((param >> 1) & 0x3f); |
| 484 | const device_config *device = ptr; |
| 485 | z80dart *dart = get_safe_token( device ); |
| 532 | 486 | dart_channel *chan = &dart->chan[param & 1]; |
| 533 | 487 | UINT8 line = (param >> 8) & 0xff; |
| 534 | 488 | int state = (param >> 7) & 1; |
| r3353 | r3354 | |
| 562 | 516 | if (((old ^ chan->status[0]) & line) && (chan->regs[1] & DART_WR1_STATUSINT_ENABLE)) |
| 563 | 517 | { |
| 564 | 518 | dart->int_state[INT_CHA_STATUS - 4*ch] |= Z80_DAISY_INT; |
| 565 | | interrupt_check(dart); |
| 519 | interrupt_check(device); |
| 566 | 520 | } |
| 567 | 521 | } |
| 568 | 522 | |
| r3353 | r3354 | |
| 572 | 526 | line |
| 573 | 527 | -------------------------------------------------*/ |
| 574 | 528 | |
| 575 | | void z80dart_set_cts(int which, int ch, int state) |
| 529 | void z80dart_set_cts(const device_config *device, int ch, int state) |
| 576 | 530 | { |
| 577 | 531 | /* operate deferred */ |
| 578 | | timer_set(attotime_zero, NULL, (DART_RR0_CTS << 8) + (state != 0) * 0x80 + which * 2 + ch, change_input_line); |
| 532 | timer_set(attotime_zero, (void *)device, (DART_RR0_CTS << 8) + (state != 0) * 0x80 + ch, change_input_line); |
| 579 | 533 | } |
| 580 | 534 | |
| 581 | 535 | |
| r3353 | r3354 | |
| 584 | 538 | line |
| 585 | 539 | -------------------------------------------------*/ |
| 586 | 540 | |
| 587 | | void z80dart_set_dcd(int which, int ch, int state) |
| 541 | void z80dart_set_dcd(const device_config *device, int ch, int state) |
| 588 | 542 | { |
| 589 | 543 | /* operate deferred */ |
| 590 | | timer_set(attotime_zero, NULL, (DART_RR0_DCD << 8) + (state != 0) * 0x80 + which * 2 + ch, change_input_line); |
| 544 | timer_set(attotime_zero, (void *)device, (DART_RR0_DCD << 8) + (state != 0) * 0x80 + ch, change_input_line); |
| 591 | 545 | } |
| 592 | 546 | |
| 593 | 547 | |
| r3353 | r3354 | |
| 596 | 550 | line |
| 597 | 551 | -------------------------------------------------*/ |
| 598 | 552 | |
| 599 | | void z80dart_set_ri(int which, int state) |
| 553 | void z80dart_set_ri(const device_config *device, int state) |
| 600 | 554 | { |
| 601 | 555 | /* operate deferred */ |
| 602 | | timer_set(attotime_zero, NULL, (DART_RR0_RI << 8) + (state != 0) * 0x80 + which * 2, change_input_line); |
| 556 | timer_set(attotime_zero, (void *)device, (DART_RR0_RI << 8) + (state != 0) * 0x80, change_input_line); |
| 603 | 557 | } |
| 604 | 558 | |
| 605 | 559 | |
| r3353 | r3354 | |
| 608 | 562 | input lines |
| 609 | 563 | -------------------------------------------------*/ |
| 610 | 564 | |
| 611 | | void z80dart_receive_data(int which, int ch, UINT8 data) |
| 565 | void z80dart_receive_data(const device_config *device, int ch, UINT8 data) |
| 612 | 566 | { |
| 613 | | z80dart *dart = darts + which; |
| 567 | z80dart *dart = get_safe_token( device ); |
| 614 | 568 | dart_channel *chan = &dart->chan[ch]; |
| 615 | 569 | int newinptr; |
| 616 | 570 | |
| r3353 | r3354 | |
| 633 | 587 | |
| 634 | 588 | static TIMER_CALLBACK(serial_callback) |
| 635 | 589 | { |
| 636 | | z80dart *dart = darts + (param >> 1); |
| 590 | const device_config *device = ptr; |
| 591 | z80dart *dart = get_safe_token( device ); |
| 637 | 592 | dart_channel *chan = &dart->chan[param & 1]; |
| 638 | 593 | int ch = param & 1; |
| 639 | 594 | int data = -1; |
| r3353 | r3354 | |
| 645 | 600 | |
| 646 | 601 | /* actually transmit the character */ |
| 647 | 602 | if (dart->transmit_cb != NULL) |
| 648 | | (*dart->transmit_cb)(machine, ch, chan->outbuf); |
| 603 | (*dart->transmit_cb)(device, ch, chan->outbuf); |
| 649 | 604 | |
| 650 | 605 | /* update the status register */ |
| 651 | 606 | chan->status[0] |= DART_RR0_TX_BUFFER_EMPTY; |
| r3353 | r3354 | |
| 654 | 609 | if (chan->regs[1] & DART_WR1_TXINT_ENABLE) |
| 655 | 610 | { |
| 656 | 611 | dart->int_state[INT_CHA_TRANSMIT - 4*ch] |= Z80_DAISY_INT; |
| 657 | | interrupt_check(dart); |
| 612 | interrupt_check(device); |
| 658 | 613 | } |
| 659 | 614 | |
| 660 | 615 | /* reset the output buffer */ |
| r3353 | r3354 | |
| 663 | 618 | |
| 664 | 619 | /* ask the polling callback if there is data to receive */ |
| 665 | 620 | if (dart->receive_poll_cb != NULL) |
| 666 | | data = (*dart->receive_poll_cb)(ch); |
| 621 | data = (*dart->receive_poll_cb)(device, ch); |
| 667 | 622 | |
| 668 | 623 | /* if we have buffered data, pull it */ |
| 669 | 624 | if (chan->receive_inptr != chan->receive_outptr) |
| r3353 | r3354 | |
| 698 | 653 | case DART_WR1_RXINT_ALL_NOPARITY: |
| 699 | 654 | case DART_WR1_RXINT_ALL_PARITY: |
| 700 | 655 | dart->int_state[INT_CHA_RECEIVE - 4*ch] |= Z80_DAISY_INT; |
| 701 | | interrupt_check(dart); |
| 656 | interrupt_check(device); |
| 702 | 657 | break; |
| 703 | 658 | } |
| 704 | 659 | chan->int_on_next_rx = FALSE; |
| r3353 | r3354 | |
| 724 | 679 | }; |
| 725 | 680 | |
| 726 | 681 | |
| 727 | | int z80dart_irq_state(int which) |
| 682 | static int z80dart_irq_state(const device_config *device) |
| 728 | 683 | { |
| 729 | | z80dart *dart = darts + which; |
| 684 | z80dart *dart = get_safe_token( device ); |
| 730 | 685 | int state = 0; |
| 731 | 686 | int i; |
| 732 | 687 | |
| r3353 | r3354 | |
| 752 | 707 | } |
| 753 | 708 | |
| 754 | 709 | |
| 755 | | int z80dart_irq_ack(int which) |
| 710 | static int z80dart_irq_ack(const device_config *device) |
| 756 | 711 | { |
| 757 | | z80dart *dart = darts + which; |
| 712 | z80dart *dart = get_safe_token( device ); |
| 758 | 713 | int i; |
| 759 | 714 | |
| 760 | 715 | /* loop over all interrupt sources */ |
| r3353 | r3354 | |
| 769 | 724 | |
| 770 | 725 | /* clear interrupt, switch to the IEO state, and update the IRQs */ |
| 771 | 726 | dart->int_state[inum] = Z80_DAISY_IEO; |
| 772 | | interrupt_check(dart); |
| 727 | interrupt_check(device); |
| 773 | 728 | return dart->chan[1].regs[2] + inum * 2; |
| 774 | 729 | } |
| 775 | 730 | } |
| r3353 | r3354 | |
| 779 | 734 | } |
| 780 | 735 | |
| 781 | 736 | |
| 782 | | void z80dart_irq_reti(int which) |
| 737 | static void z80dart_irq_reti(const device_config *device) |
| 783 | 738 | { |
| 784 | | z80dart *dart = darts + which; |
| 739 | z80dart *dart = get_safe_token( device ); |
| 785 | 740 | int i; |
| 786 | 741 | |
| 787 | 742 | /* loop over all interrupt sources */ |
| r3353 | r3354 | |
| 796 | 751 | |
| 797 | 752 | /* clear the IEO state and update the IRQs */ |
| 798 | 753 | dart->int_state[inum] &= ~Z80_DAISY_IEO; |
| 799 | | interrupt_check(dart); |
| 754 | interrupt_check(device); |
| 800 | 755 | return; |
| 801 | 756 | } |
| 802 | 757 | } |
| 803 | 758 | |
| 804 | 759 | logerror("z80dart_irq_reti: failed to find an interrupt to clear IEO on!\n"); |
| 805 | 760 | } |
| 761 | |
| 762 | |
| 763 | static DEVICE_START( z80dart ) |
| 764 | { |
| 765 | const z80dart_interface *intf = device->static_config; |
| 766 | z80dart *dart = get_safe_token(device); |
| 767 | |
| 768 | dart->chan[0].receive_timer = timer_alloc(serial_callback, (void *)device); |
| 769 | dart->chan[1].receive_timer = timer_alloc(serial_callback, (void *)device); |
| 770 | |
| 771 | dart->irq_cb = intf->irq_cb; |
| 772 | dart->dtr_changed_cb = intf->dtr_changed_cb; |
| 773 | dart->rts_changed_cb = intf->rts_changed_cb; |
| 774 | dart->break_changed_cb = intf->break_changed_cb; |
| 775 | dart->transmit_cb = intf->transmit_cb; |
| 776 | dart->receive_poll_cb = intf->receive_poll_cb; |
| 777 | |
| 778 | return DEVICE_START_OK; |
| 779 | } |
| 780 | |
| 781 | |
| 782 | static DEVICE_RESET( z80dart ) |
| 783 | { |
| 784 | int ch; |
| 785 | |
| 786 | /* set up defaults */ |
| 787 | for (ch = 0; ch < 2; ch++) |
| 788 | { |
| 789 | reset_channel( device, ch ); |
| 790 | } |
| 791 | interrupt_check(device); |
| 792 | } |
| 793 | |
| 794 | |
| 795 | static DEVICE_SET_INFO( z80dart ) |
| 796 | { |
| 797 | switch (state) |
| 798 | { |
| 799 | /* no parameters to set */ |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | |
| 804 | DEVICE_GET_INFO( z80dart ) |
| 805 | { |
| 806 | switch (state) |
| 807 | { |
| 808 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 809 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(z80dart); break; |
| 810 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 811 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 812 | |
| 813 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 814 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(z80dart); break; |
| 815 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(z80dart); break; |
| 816 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 817 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(z80dart); break; |
| 818 | case DEVINFO_FCT_IRQ_STATE: info->f = (genf *)z80dart_irq_state; break; |
| 819 | case DEVINFO_FCT_IRQ_ACK: info->f = (genf *)z80dart_irq_ack; break; |
| 820 | case DEVINFO_FCT_IRQ_RETI: info->f = (genf *)z80dart_irq_reti; break; |
| 821 | |
| 822 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 823 | case DEVINFO_STR_NAME: info->s = "Zilog Z80 DART"; break; |
| 824 | case DEVINFO_STR_FAMILY: info->s = "Z80"; break; |
| 825 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 826 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 827 | case DEVINFO_STR_CREDITS: info->s = "Copyright the MESS Team"; break; |
| 828 | } |
| 829 | } |
| 830 | |
src/mess/machine/z80dart.h
| r3353 | r3354 | |
| 7 | 7 | |
| 8 | 8 | ***************************************************************************/ |
| 9 | 9 | |
| 10 | | /*************************************************************************** |
| 11 | | CONSTANTS |
| 12 | | ***************************************************************************/ |
| 10 | #ifndef __Z80DART_H_ |
| 11 | #define __Z80DART_H_ |
| 13 | 12 | |
| 14 | | #define MAX_DART 2 |
| 15 | 13 | |
| 16 | | |
| 17 | | |
| 18 | 14 | /*************************************************************************** |
| 19 | 15 | TYPE DEFINITIONS |
| 20 | 16 | ***************************************************************************/ |
| r3353 | r3354 | |
| 22 | 18 | typedef struct _z80dart_interface z80dart_interface; |
| 23 | 19 | struct _z80dart_interface |
| 24 | 20 | { |
| 21 | const char *cpu; |
| 25 | 22 | int baseclock; |
| 26 | | void (*irq_cb)(int state); |
| 27 | | write8_machine_func dtr_changed_cb; |
| 28 | | write8_machine_func rts_changed_cb; |
| 29 | | write8_machine_func break_changed_cb; |
| 30 | | write8_machine_func transmit_cb; |
| 31 | | int (*receive_poll_cb)(int which); |
| 23 | void (*irq_cb)(const device_config *device, int state); |
| 24 | write8_device_func dtr_changed_cb; |
| 25 | write8_device_func rts_changed_cb; |
| 26 | write8_device_func break_changed_cb; |
| 27 | write8_device_func transmit_cb; |
| 28 | int (*receive_poll_cb)(const device_config *device, int ch); |
| 32 | 29 | }; |
| 33 | 30 | |
| 34 | 31 | |
| 35 | 32 | |
| 36 | 33 | /*************************************************************************** |
| 37 | | INITIALIZATION/CONFIGURATION |
| 34 | DEVICE CONFIGURATION MACROS |
| 38 | 35 | ***************************************************************************/ |
| 39 | 36 | |
| 40 | | void z80dart_init(int which, const z80dart_interface *intf); |
| 41 | | void z80dart_reset(int which); |
| 37 | #define MDRV_Z80DART_ADD(_tag, _intrf) \ |
| 38 | MDRV_DEVICE_ADD(_tag, Z80DART) \ |
| 39 | MDRV_DEVICE_CONFIG(_intrf) |
| 42 | 40 | |
| 41 | #define MDRV_Z80DART_REMOVE(_tag) \ |
| 42 | MDRV_DEVICE_REMOVE(_tag, Z80DART) |
| 43 | 43 | |
| 44 | 44 | |
| 45 | |
| 45 | 46 | /*************************************************************************** |
| 46 | 47 | CONTROL REGISTER READ/WRITE |
| 47 | 48 | ***************************************************************************/ |
| 48 | 49 | |
| 49 | | void z80dart_c_w(running_machine *machine, int which, int ch, UINT8 data); |
| 50 | | UINT8 z80dart_c_r(int which, int ch); |
| 50 | WRITE8_DEVICE_HANDLER( z80dart_c_w ); |
| 51 | READ8_DEVICE_HANDLER( z80dart_c_r ); |
| 51 | 52 | |
| 52 | 53 | |
| 53 | 54 | |
| r3353 | r3354 | |
| 55 | 56 | DATA REGISTER READ/WRITE |
| 56 | 57 | ***************************************************************************/ |
| 57 | 58 | |
| 58 | | void z80dart_d_w(int which, int ch, UINT8 data); |
| 59 | | UINT8 z80dart_d_r(int which, int ch); |
| 59 | WRITE8_DEVICE_HANDLER( z80dart_d_w ); |
| 60 | READ8_DEVICE_HANDLER( z80dart_d_r ); |
| 60 | 61 | |
| 61 | 62 | |
| 62 | 63 | |
| r3353 | r3354 | |
| 64 | 65 | CONTROL LINE READ/WRITE |
| 65 | 66 | ***************************************************************************/ |
| 66 | 67 | |
| 67 | | int z80dart_get_dtr(int which, int ch); |
| 68 | | int z80dart_get_rts(int which, int ch); |
| 69 | | void z80dart_set_cts(int which, int ch, int state); |
| 70 | | void z80dart_set_dcd(int which, int ch, int state); |
| 71 | | void z80dart_set_ri(int which, int state); |
| 72 | | void z80dart_receive_data(int which, int ch, UINT8 data); |
| 68 | int z80dart_get_dtr(const device_config *device, int ch); |
| 69 | int z80dart_get_rts(const device_config *device, int ch); |
| 70 | void z80dart_set_cts(const device_config *device, int ch, int state); |
| 71 | void z80dart_set_dcd(const device_config *device, int ch, int state); |
| 72 | void z80dart_set_ri(const device_config *device, int state); |
| 73 | void z80dart_receive_data(const device_config *device, int ch, UINT8 data); |
| 73 | 74 | |
| 74 | 75 | |
| 76 | /* ----- device interface ----- */ |
| 75 | 77 | |
| 76 | | /*************************************************************************** |
| 77 | | DAISY CHAIN INTERFACE |
| 78 | | ***************************************************************************/ |
| 78 | #define Z80DART DEVICE_GET_INFO_NAME(z80dart) |
| 79 | DEVICE_GET_INFO( z80dart ); |
| 79 | 80 | |
| 80 | | int z80dart_irq_state(int which); |
| 81 | | int z80dart_irq_ack(int which); |
| 82 | | void z80dart_irq_reti(int which); |
| 81 | #endif |