src/mess/video/crt9007.c
| r9663 | r9664 | |
| 11 | 11 | |
| 12 | 12 | TODO: |
| 13 | 13 | |
| 14 | - cursor timer |
| 14 | 15 | - interrupts |
| 15 | | - status register |
| 16 | | - reset |
| 16 | - light pen |
| 17 | - frame timer |
| 17 | 18 | - non-DMA mode |
| 18 | 19 | - DMA mode |
| 19 | 20 | - cursor/blank skew |
| r9663 | r9664 | |
| 82 | 83 | (((m_reg[0x08] << 3) & 0x0700) | m_reg[0x09]) |
| 83 | 84 | |
| 84 | 85 | #define DMA_BURST_COUNT \ |
| 85 | | (m_reg[0x0a] & 0x0f) |
| 86 | ((m_reg[0x0a] & 0x0f) + 1) |
| 86 | 87 | |
| 87 | 88 | #define DMA_BURST_DELAY \ |
| 88 | | ((m_reg[0x0a] >> 4) & 0x07) |
| 89 | ((((m_reg[0x0a] >> 4) & 0x07) + 1) % 8) |
| 89 | 90 | |
| 90 | 91 | #define DMA_DISABLE \ |
| 91 | 92 | BIT(m_reg[0x0a], 7) |
| r9663 | r9664 | |
| 144 | 145 | #define HORIZONTAL_CURSOR \ |
| 145 | 146 | m_reg[0x19] |
| 146 | 147 | |
| 148 | #define INTERRUPT_ENABLE \ |
| 149 | m_reg[0x1a] |
| 150 | |
| 147 | 151 | #define FRAME_TIMER \ |
| 148 | 152 | BIT(m_reg[0x1a], 0) |
| 149 | 153 | |
| r9663 | r9664 | |
| 172 | 176 | // operation modes |
| 173 | 177 | enum |
| 174 | 178 | { |
| 175 | | OPERATION_MODE_REPETITIVE_MEMORY_ADDRESSING = 0, |
| 176 | | OPERATION_MODE_DOUBLE_ROW_BUFFER, |
| 177 | | OPERATION_MODE_SINGLE_ROW_BUFFER = 4, |
| 178 | | OPERATION_MODE_ATTRIBUTE_ASSEMBLE = 7 |
| 179 | OPERATION_MODE_REPETITIVE_MEMORY_ADDRESSING = 0, // not implemented |
| 180 | OPERATION_MODE_DOUBLE_ROW_BUFFER = 1, |
| 181 | OPERATION_MODE_SINGLE_ROW_BUFFER = 4, // not implemented |
| 182 | OPERATION_MODE_ATTRIBUTE_ASSEMBLE = 7 // not implemented |
| 179 | 183 | }; |
| 180 | 184 | |
| 181 | 185 | |
| r9663 | r9664 | |
| 183 | 187 | enum |
| 184 | 188 | { |
| 185 | 189 | ADDRESS_MODE_SEQUENTIAL_ADDRESSING = 0, |
| 186 | | ADDRESS_MODE_SEQUENTIAL_ROLL_ADDRESSING, |
| 187 | | ADDRESS_MODE_CONTIGUOUS_ROW_TABLE, |
| 188 | | ADDRESS_MODE_LINKED_LIST_ROW_TABLE |
| 190 | ADDRESS_MODE_SEQUENTIAL_ROLL_ADDRESSING, // not implemented |
| 191 | ADDRESS_MODE_CONTIGUOUS_ROW_TABLE, // not implemented |
| 192 | ADDRESS_MODE_LINKED_LIST_ROW_TABLE // not implemented |
| 189 | 193 | }; |
| 190 | 194 | |
| 191 | 195 | |
| 196 | // interrupt enable register bits |
| 197 | const int IE_VERTICAL_RETRACE = 0x40; |
| 198 | const int IE_LIGHT_PEN = 0x20; |
| 199 | const int IE_FRAME_TIMER = 0x01; |
| 200 | |
| 192 | 201 | // status register bits |
| 193 | 202 | const int STATUS_INTERRUPT_PENDING = 0x80; |
| 194 | 203 | const int STATUS_VERTICAL_RETRACE = 0x40; |
| r9663 | r9664 | |
| 284 | 293 | memset(&out_vlt_func, 0, sizeof(out_vlt_func)); |
| 285 | 294 | memset(&out_curs_func, 0, sizeof(out_curs_func)); |
| 286 | 295 | memset(&out_drb_func, 0, sizeof(out_drb_func)); |
| 296 | memset(&out_cblank_func, 0, sizeof(out_cblank_func)); |
| 287 | 297 | memset(&out_slg_func, 0, sizeof(out_slg_func)); |
| 288 | 298 | memset(&out_sld_func, 0, sizeof(out_sld_func)); |
| 289 | 299 | } |
| r9663 | r9664 | |
| 306 | 316 | |
| 307 | 317 | |
| 308 | 318 | //------------------------------------------------- |
| 319 | // trigger_interrupt - |
| 320 | //------------------------------------------------- |
| 321 | |
| 322 | inline void crt9007_device::trigger_interrupt(int line) |
| 323 | { |
| 324 | if (INTERRUPT_ENABLE & line) |
| 325 | { |
| 326 | int status = m_status; |
| 327 | |
| 328 | m_status |= STATUS_INTERRUPT_PENDING | line; |
| 329 | |
| 330 | if (!(status & STATUS_INTERRUPT_PENDING)) |
| 331 | { |
| 332 | if (LOG) logerror("CRT9007 '%s' INT 1\n", tag()); |
| 333 | devcb_call_write_line(&m_out_int_func, ASSERT_LINE); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | |
| 339 | //------------------------------------------------- |
| 340 | // update_cblank_line - |
| 341 | //------------------------------------------------- |
| 342 | |
| 343 | inline void crt9007_device::update_cblank_line() |
| 344 | { |
| 345 | int x = m_screen->hpos(); |
| 346 | int y = m_screen->vpos(); |
| 347 | |
| 348 | // composite blank |
| 349 | int cblank = !(m_hs & m_vs); |
| 350 | |
| 351 | if (m_cblank != cblank) |
| 352 | { |
| 353 | m_cblank = cblank; |
| 354 | |
| 355 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CBLANK %u\n", tag(), y, x, m_cblank); |
| 356 | |
| 357 | devcb_call_write_line(&m_out_cblank_func, m_cblank); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | |
| 362 | //------------------------------------------------- |
| 309 | 363 | // update_hsync_timer - |
| 310 | 364 | //------------------------------------------------- |
| 311 | 365 | |
| r9663 | r9664 | |
| 314 | 368 | int y = m_screen->vpos(); |
| 315 | 369 | |
| 316 | 370 | int next_x = state ? m_hsync_start : m_hsync_end; |
| 317 | | int next_y = (y + 1) % SCAN_LINES_PER_FRAME; |
| 371 | int next_y = state ? (y + 1) % SCAN_LINES_PER_FRAME : y; |
| 318 | 372 | |
| 319 | 373 | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 320 | 374 | |
| r9663 | r9664 | |
| 342 | 396 | |
| 343 | 397 | inline void crt9007_device::update_vlt_timer(int state) |
| 344 | 398 | { |
| 345 | | // TODO |
| 399 | // this signal is active during all visible scan lines and during the horizontal trace at vertical retrace |
| 400 | int y = m_screen->vpos(); |
| 401 | |
| 402 | int next_x = state ? m_vlt_end : m_vlt_start; |
| 403 | int next_y = state ? y : ((y == m_vlt_bottom) ? 0 : (y + 1)); |
| 404 | |
| 405 | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 406 | |
| 407 | timer_adjust_oneshot(m_vlt_timer, duration, !state); |
| 346 | 408 | } |
| 347 | 409 | |
| 348 | 410 | |
| r9663 | r9664 | |
| 352 | 414 | |
| 353 | 415 | inline void crt9007_device::update_curs_timer(int state) |
| 354 | 416 | { |
| 417 | // this signal is active for 1 character time for all scanlines within the data row |
| 355 | 418 | // TODO |
| 356 | 419 | } |
| 357 | 420 | |
| r9663 | r9664 | |
| 362 | 425 | |
| 363 | 426 | inline void crt9007_device::update_drb_timer(int state) |
| 364 | 427 | { |
| 428 | // this signal is active for 1 full scan line (VLT edge to edge) at the top scan line of each new row |
| 429 | // there is 1 extra DRB signal during the 1st scanline of the vertical retrace interval |
| 430 | int y = m_screen->vpos(); |
| 431 | |
| 432 | int next_x = m_vlt_end; |
| 433 | int next_y = y ? y + 1 : y; |
| 434 | |
| 435 | if (state) |
| 436 | { |
| 437 | if (y == 0) |
| 438 | { |
| 439 | next_y = VERTICAL_DELAY - 1; |
| 440 | } |
| 441 | else if (y == m_drb_bottom) |
| 442 | { |
| 443 | next_x = 0; |
| 444 | next_y = 0; |
| 445 | } |
| 446 | else |
| 447 | { |
| 448 | next_y = y + SCAN_LINES_PER_DATA_ROW - 1; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 453 | |
| 454 | timer_adjust_oneshot(m_drb_timer, duration, !state); |
| 455 | } |
| 456 | |
| 457 | |
| 458 | //------------------------------------------------- |
| 459 | // update_dma_timer - |
| 460 | //------------------------------------------------- |
| 461 | |
| 462 | inline void crt9007_device::update_dma_timer() |
| 463 | { |
| 365 | 464 | // TODO |
| 366 | 465 | } |
| 367 | 466 | |
| r9663 | r9664 | |
| 375 | 474 | // check that necessary registers have been loaded |
| 376 | 475 | if (!HAS_VALID_PARAMETERS) return; |
| 377 | 476 | |
| 477 | // screen dimensions |
| 378 | 478 | int horiz_pix_total = CHARACTERS_PER_HORIZONTAL_PERIOD * m_hpixels_per_column; |
| 379 | 479 | int vert_pix_total = SCAN_LINES_PER_FRAME; |
| 380 | 480 | |
| 481 | // refresh rate |
| 381 | 482 | attoseconds_t refresh = HZ_TO_ATTOSECONDS(clock()) * horiz_pix_total * vert_pix_total; |
| 382 | 483 | |
| 383 | | m_hsync_start = (CHARACTERS_PER_HORIZONTAL_PERIOD - HORIZONTAL_SYNC_WIDTH) * m_hpixels_per_column; |
| 384 | | m_hsync_end = 0; |
| 385 | | m_hfp = (HORIZONTAL_DELAY - HORIZONTAL_SYNC_WIDTH) * m_hpixels_per_column; |
| 484 | // horizontal sync |
| 485 | m_hsync_start = 0; |
| 486 | m_hsync_end = HORIZONTAL_SYNC_WIDTH * m_hpixels_per_column; |
| 386 | 487 | |
| 387 | | m_vsync_start = SCAN_LINES_PER_FRAME - VERTICAL_SYNC_WIDTH; |
| 388 | | m_vsync_end = 0; |
| 389 | | m_vfp = VERTICAL_DELAY - VERTICAL_SYNC_WIDTH; |
| 488 | // visible line time |
| 489 | m_vlt_start = HORIZONTAL_DELAY * m_hpixels_per_column; |
| 490 | m_vlt_end = (HORIZONTAL_DELAY + CHARACTERS_PER_DATA_ROW) * m_hpixels_per_column; |
| 491 | m_vlt_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - 1; |
| 390 | 492 | |
| 493 | // data row boundary |
| 494 | m_drb_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - SCAN_LINES_PER_DATA_ROW; |
| 495 | |
| 496 | // vertical sync |
| 497 | m_vsync_start = 0; |
| 498 | m_vsync_end = VERTICAL_SYNC_WIDTH; |
| 499 | |
| 500 | // visible area |
| 391 | 501 | rectangle visarea; |
| 392 | 502 | |
| 393 | 503 | visarea.min_x = m_hsync_end; |
| 394 | | visarea.max_x = m_hsync_start - 1; |
| 504 | visarea.max_x = horiz_pix_total - 1; |
| 395 | 505 | |
| 396 | 506 | visarea.min_y = m_vsync_end; |
| 397 | | visarea.max_y = m_vsync_start - 1; |
| 507 | visarea.max_y = vert_pix_total - 1; |
| 398 | 508 | |
| 399 | 509 | if (LOG) |
| 400 | 510 | { |
| r9663 | r9664 | |
| 404 | 514 | |
| 405 | 515 | m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh); |
| 406 | 516 | |
| 407 | | update_hsync_timer(1); |
| 408 | | update_vsync_timer(1); |
| 409 | | update_vlt_timer(1); |
| 410 | | update_curs_timer(1); |
| 411 | | update_drb_timer(1); |
| 517 | timer_adjust_oneshot(m_hsync_timer, m_screen->time_until_pos(0, 0), 0); |
| 518 | timer_adjust_oneshot(m_vsync_timer, m_screen->time_until_pos(0, 0), 0); |
| 519 | timer_adjust_oneshot(m_vlt_timer, m_screen->time_until_pos(0, m_vlt_start), 1); |
| 520 | timer_adjust_oneshot(m_drb_timer, m_screen->time_until_pos(0, 0), 0); |
| 412 | 521 | } |
| 413 | 522 | |
| 414 | 523 | |
| r9663 | r9664 | |
| 442 | 551 | m_vlt_timer = device_timer_alloc(*this, TIMER_VLT); |
| 443 | 552 | m_curs_timer = device_timer_alloc(*this, TIMER_CURS); |
| 444 | 553 | m_drb_timer = device_timer_alloc(*this, TIMER_DRB); |
| 554 | m_dma_timer = device_timer_alloc(*this, TIMER_DMA); |
| 445 | 555 | |
| 446 | 556 | // resolve callbacks |
| 447 | 557 | devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this); |
| r9663 | r9664 | |
| 451 | 561 | devcb_resolve_write_line(&m_out_vlt_func, &m_config.out_vlt_func, this); |
| 452 | 562 | devcb_resolve_write_line(&m_out_curs_func, &m_config.out_curs_func, this); |
| 453 | 563 | devcb_resolve_write_line(&m_out_drb_func, &m_config.out_drb_func, this); |
| 564 | devcb_resolve_write_line(&m_out_cblank_func, &m_config.out_cblank_func, this); |
| 565 | devcb_resolve_write_line(&m_out_slg_func, &m_config.out_slg_func, this); |
| 566 | devcb_resolve_write_line(&m_out_sld_func, &m_config.out_sld_func, this); |
| 454 | 567 | |
| 455 | 568 | // get the screen device |
| 456 | 569 | m_screen = machine->device<screen_device>(m_config.screen_tag); |
| r9663 | r9664 | |
| 479 | 592 | devcb_call_write_line(&m_out_vs_func, 1); |
| 480 | 593 | |
| 481 | 594 | // CBLANK = 1 |
| 482 | | // devcb_call_write_line(&m_out_cblank_func, 0); |
| 595 | devcb_call_write_line(&m_out_cblank_func, 0); |
| 483 | 596 | |
| 484 | 597 | // CURS = 0 |
| 485 | 598 | devcb_call_write_line(&m_out_curs_func, 0); |
| r9663 | r9664 | |
| 499 | 612 | // 29 (WBEN) = 0 |
| 500 | 613 | |
| 501 | 614 | // 30 (SLG) = 0 |
| 502 | | // devcb_call_write_line(&m_out_slg_func, 0); |
| 615 | devcb_call_write_line(&m_out_slg_func, 0); |
| 503 | 616 | |
| 504 | 617 | // 31 (SLD) = 0 |
| 505 | | // devcb_call_write_line(&m_out_sld_func, 0); |
| 618 | devcb_call_write_line(&m_out_sld_func, 0); |
| 506 | 619 | |
| 507 | 620 | // 32 (LPSTB) = 0 |
| 508 | 621 | } |
| r9663 | r9664 | |
| 524 | 637 | |
| 525 | 638 | void crt9007_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 526 | 639 | { |
| 640 | int x = m_screen->hpos(); |
| 641 | int y = m_screen->vpos(); |
| 642 | |
| 527 | 643 | switch (id) |
| 528 | 644 | { |
| 529 | 645 | case TIMER_HSYNC: |
| 530 | | devcb_call_write_line(&m_out_hs_func, param); |
| 646 | m_hs = param; |
| 647 | |
| 648 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : HS %u\n", tag(), y, x, m_hs); |
| 649 | |
| 650 | devcb_call_write_line(&m_out_hs_func, m_hs); |
| 651 | |
| 652 | update_cblank_line(); |
| 653 | |
| 531 | 654 | update_hsync_timer(param); |
| 532 | 655 | break; |
| 533 | 656 | |
| 534 | 657 | case TIMER_VSYNC: |
| 658 | m_vs = param; |
| 659 | |
| 660 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VS %u\n", tag(), y, x, m_vs); |
| 661 | |
| 535 | 662 | devcb_call_write_line(&m_out_vs_func, param); |
| 663 | |
| 664 | if (m_vs) |
| 665 | { |
| 666 | // reset all other bits except Light Pen Update to logic 0 |
| 667 | m_status &= STATUS_LIGHT_PEN_UPDATE; |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | trigger_interrupt(IE_VERTICAL_RETRACE); |
| 672 | |
| 673 | update_cblank_line(); |
| 674 | } |
| 675 | |
| 536 | 676 | update_vsync_timer(param); |
| 537 | 677 | break; |
| 538 | 678 | |
| 539 | 679 | case TIMER_VLT: |
| 680 | m_vlt = param; |
| 681 | |
| 682 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VLT %u\n", tag(), y, x, m_vlt); |
| 683 | |
| 540 | 684 | devcb_call_write_line(&m_out_vlt_func, param); |
| 685 | |
| 541 | 686 | update_vlt_timer(param); |
| 542 | 687 | break; |
| 543 | 688 | |
| 544 | 689 | case TIMER_CURS: |
| 690 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CURS %u\n", tag(), y, x, param); |
| 691 | |
| 545 | 692 | devcb_call_write_line(&m_out_curs_func, param); |
| 693 | |
| 546 | 694 | update_curs_timer(param); |
| 547 | 695 | break; |
| 548 | 696 | |
| 549 | 697 | case TIMER_DRB: |
| 698 | m_drb = param; |
| 699 | |
| 700 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : DRB %u\n", tag(), y, x, m_drb); |
| 701 | |
| 550 | 702 | devcb_call_write_line(&m_out_drb_func, param); |
| 703 | |
| 704 | if (!m_drb && !DMA_DISABLE) |
| 705 | { |
| 706 | // start DMA burst sequence |
| 707 | m_dma_count = CHARACTERS_PER_DATA_ROW; |
| 708 | m_dma_burst = DMA_BURST_COUNT ? (DMA_BURST_COUNT * 4) : CHARACTERS_PER_DATA_ROW; |
| 709 | m_dma_delay = DMA_BURST_DELAY; |
| 710 | m_dmar = 1; |
| 711 | |
| 712 | if (LOG) logerror("CRT9007 '%s' DMAR 1\n", tag()); |
| 713 | devcb_call_write_line(&m_out_dmar_func, ASSERT_LINE); |
| 714 | } |
| 715 | |
| 551 | 716 | update_drb_timer(param); |
| 552 | 717 | break; |
| 718 | |
| 719 | case TIMER_DMA: |
| 720 | readbyte(AUXILIARY_ADDRESS_2); |
| 721 | |
| 722 | update_dma_timer(); |
| 723 | break; |
| 553 | 724 | } |
| 554 | 725 | } |
| 555 | 726 | |
| r9663 | r9664 | |
| 584 | 755 | |
| 585 | 756 | case 0x3a: |
| 586 | 757 | data = m_status; |
| 758 | |
| 759 | // reset interrupt pending bit |
| 760 | m_status &= ~STATUS_INTERRUPT_PENDING; |
| 761 | if (LOG) logerror("CRT9007 '%s' INT 0\n", tag()); |
| 762 | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 587 | 763 | break; |
| 588 | 764 | |
| 589 | 765 | case 0x3b: |
| r9663 | r9664 | |
| 592 | 768 | |
| 593 | 769 | case 0x3c: |
| 594 | 770 | data = HORIZONTAL_LIGHT_PEN; |
| 771 | |
| 772 | // reset light pen update bit |
| 773 | m_status &= ~STATUS_LIGHT_PEN_UPDATE; |
| 595 | 774 | break; |
| 596 | 775 | |
| 597 | 776 | default: |
| r9663 | r9664 | |
| 778 | 957 | |
| 779 | 958 | WRITE_LINE_MEMBER( crt9007_device::ack_w ) |
| 780 | 959 | { |
| 781 | | // TODO |
| 960 | if (LOG) logerror("CRT9007 '%s' ACK: %u\n", tag(), state); |
| 961 | |
| 962 | if (m_dmar && !m_ack && state) |
| 963 | { |
| 964 | // start DMA transfer |
| 965 | timer_adjust_oneshot(m_dma_timer, ATTOTIME_IN_HZ(clock()), 0); |
| 966 | } |
| 967 | |
| 968 | m_ack = state; |
| 782 | 969 | } |
| 783 | 970 | |
| 784 | 971 | |
| r9663 | r9664 | |
| 788 | 975 | |
| 789 | 976 | WRITE_LINE_MEMBER( crt9007_device::lpstb_w ) |
| 790 | 977 | { |
| 791 | | // TODO |
| 978 | if (LOG) logerror("CRT9007 '%s' LPSTB: %u\n", tag(), state); |
| 979 | |
| 980 | if (!m_lpstb && state) |
| 981 | { |
| 982 | // TODO latch current row/column position |
| 983 | } |
| 984 | |
| 985 | m_lpstb = state; |
| 792 | 986 | } |
| 793 | 987 | |
| 794 | 988 | |