src/mess/video/pc_cga.c
| r2547 | r2548 | |
| 45 | 45 | |
| 46 | 46 | (source John Elliott http://www.seasip.info/AmstradXT/pc1512disp.html) |
| 47 | 47 | |
| 48 | |
| 49 | Cursor signal handling: |
| 50 | |
| 51 | The alpha dots signal is set when a character pixel should be set. This signal is |
| 52 | also set when the cursor should be displayed. The following formula for alpha |
| 53 | dots is derived from the schematics: |
| 54 | ALPHA DOTS = ( ( CURSOR DLY ) AND ( CURSOR BLINK ) ) OR ( ( ( NOT AT7 ) OR CURSOR DLY OR -BLINK OR NOT ENABLE BLINK ) AND ( CHG DOTS ) ) |
| 55 | |
| 56 | -CURSOR BLINK = VSYNC DLY (LS393) (changes every 8 vsyncs) |
| 57 | -BLINK = -CURSOR BLINK (LS393) (changes every 16 vsyncs) |
| 58 | -CURSOR DLY = -CURSOR signal from mc6845 and LS174 |
| 59 | CHG DOTS = character pixel (from character rom) |
| 60 | |
| 61 | For non-blinking modes this formula reduces to: |
| 62 | ALPHA DOTS = ( ( CURSOR DLY ) AND ( CURSOR BLINK ) ) OR ( CHG DOTS ) |
| 63 | |
| 64 | This means the cursor switches on/off state every 8 vsyncs. |
| 65 | |
| 66 | |
| 67 | For blinking modes this formula reduces to: |
| 68 | ALPHA DOTS = ( ( CURSOR DLY ) AND ( CURSOR BLINK ) ) OR ( ( ( NOT AT7 ) OR CURSOR DLY OR -BLINK ) AND ( CHG DOTS ) ) |
| 69 | |
| 70 | So, at the cursor location the attribute blinking is ignored and only regular |
| 71 | cursor blinking takes place (state switches every 8 vsyncs). On non-cursor |
| 72 | locations with the highest attribute bits set the character will switch |
| 73 | on/off every 16 vsyncs. In all other cases the character is displayed as |
| 74 | usual. |
| 75 | |
| 48 | 76 | ***************************************************************************/ |
| 49 | 77 | |
| 50 | 78 | #include "driver.h" |
| r2547 | r2548 | |
| 160 | 188 | static VIDEO_UPDATE( mc6845_pc1512 ); |
| 161 | 189 | |
| 162 | 190 | |
| 163 | | static const mc6845_interface mc6845_cga_intf = { |
| 191 | static const mc6845_interface mc6845_cga_intf = |
| 192 | { |
| 164 | 193 | CGA_SCREEN_NAME, /* screen number */ |
| 165 | 194 | XTAL_14_31818MHz/8, /* clock */ |
| 166 | 195 | 8, /* numbers of pixels per video memory address */ |
| r2547 | r2548 | |
| 231 | 260 | * |
| 232 | 261 | ***************************************************************************/ |
| 233 | 262 | |
| 234 | | struct ntsc_decoder { |
| 263 | struct ntsc_decoder |
| 264 | { |
| 235 | 265 | int period; |
| 236 | 266 | |
| 237 | 267 | int *I_filter; |
| r2547 | r2548 | |
| 248 | 278 | |
| 249 | 279 | |
| 250 | 280 | /* Clear NTSC buffers and running totals. Call this before the beginning of each new line. */ |
| 251 | | static void ntsc_clear(struct ntsc_decoder *ntsc) { |
| 281 | static void ntsc_clear(struct ntsc_decoder *ntsc) |
| 282 | { |
| 252 | 283 | int j; |
| 253 | | for (j=0;j<ntsc->period;++j) { |
| 284 | for (j=0;j<ntsc->period;++j) |
| 285 | { |
| 254 | 286 | ntsc->Y_buffer[j] = 0; |
| 255 | 287 | ntsc->I_buffer[j] = 0; |
| 256 | 288 | ntsc->Q_buffer[j] = 0; |
| r2547 | r2548 | |
| 274 | 306 | |
| 275 | 307 | The correct value for hue will usually be a multiple of 128. |
| 276 | 308 | */ |
| 277 | | static void ntsc_decoder_init(struct ntsc_decoder *ntsc, int period, int hue) { |
| 309 | static void ntsc_decoder_init(struct ntsc_decoder *ntsc, int period, int hue) |
| 310 | { |
| 278 | 311 | int j; |
| 279 | 312 | |
| 280 | 313 | ntsc->period = period; |
| r2547 | r2548 | |
| 284 | 317 | ntsc->I_buffer = auto_malloc(period * sizeof(int)); |
| 285 | 318 | ntsc->Q_buffer = auto_malloc(period * sizeof(int)); |
| 286 | 319 | ntsc_clear(ntsc); |
| 287 | | for (j=0;j<period;++j) { |
| 320 | for (j=0;j<period;++j) |
| 321 | { |
| 288 | 322 | double angle = M_PI*((hue+(j<<8))/(period*128.0)-33.0/180); |
| 289 | 323 | ntsc->I_filter[j] = (int)(512.0*cos(angle)); |
| 290 | 324 | ntsc->Q_filter[j] = (int)(512.0*sin(angle)); |
| r2547 | r2548 | |
| 302 | 336 | first call ntsc_decode(ntsc, input, NULL, 1) with "input" containing the |
| 303 | 337 | samples directly before the samples you will subsequently be using. |
| 304 | 338 | */ |
| 305 | | static void ntsc_decode(struct ntsc_decoder *ntsc, UINT8 *input, UINT8 *output, int periods) { |
| 339 | static void ntsc_decode(struct ntsc_decoder *ntsc, UINT8 *input, UINT8 *output, int periods) |
| 340 | { |
| 306 | 341 | int j; |
| 307 | 342 | |
| 308 | 343 | int *I_filter; |
| r2547 | r2548 | |
| 317 | 352 | int R,G,B; |
| 318 | 353 | int period = ntsc->period; |
| 319 | 354 | |
| 320 | | while ((--periods)>=0) { |
| 355 | while ((--periods)>=0) |
| 356 | { |
| 321 | 357 | I_filter = ntsc->I_filter; |
| 322 | 358 | Q_filter = ntsc->Q_filter; |
| 323 | 359 | Y_buffer = ntsc->Y_buffer; |
| 324 | 360 | I_buffer = ntsc->I_buffer; |
| 325 | 361 | Q_buffer = ntsc->Q_buffer; |
| 326 | 362 | |
| 327 | | for (j=0;j<period;++j) { |
| 363 | for (j=0;j<period;++j) |
| 364 | { |
| 328 | 365 | |
| 329 | 366 | /* Get next point */ |
| 330 | 367 | Y = *(input++); |
| r2547 | r2548 | |
| 385 | 422 | { |
| 386 | 423 | int i, r, g, b; |
| 387 | 424 | |
| 388 | | for ( i = 0; i < CGA_PALETTE_SETS * 16; i++ ) { |
| 425 | for ( i = 0; i < CGA_PALETTE_SETS * 16; i++ ) |
| 426 | { |
| 389 | 427 | palette_set_color_rgb( machine, i, cga_palette[i][0], cga_palette[i][1], cga_palette[i][2] ); |
| 390 | 428 | } |
| 391 | 429 | |
| 392 | 430 | i = 0x8000; |
| 393 | | for ( r = 0; r < 32; r++ ) { |
| 394 | | for ( g = 0; g < 32; g++ ) { |
| 395 | | for ( b = 0; b < 32; b++ ) { |
| 431 | for ( r = 0; r < 32; r++ ) |
| 432 | { |
| 433 | for ( g = 0; g < 32; g++ ) |
| 434 | { |
| 435 | for ( b = 0; b < 32; b++ ) |
| 436 | { |
| 396 | 437 | palette_set_color_rgb( machine, i, r << 3, g << 3, b << 3 ); |
| 397 | 438 | i++; |
| 398 | 439 | } |
| r2547 | r2548 | |
| 477 | 518 | mc6845_update( devconf, bitmap, cliprect); |
| 478 | 519 | |
| 479 | 520 | /* Check for changes in font dipsetting */ |
| 480 | | switch ( CGA_FONT & 0x01 ) { |
| 521 | switch ( CGA_FONT & 0x01 ) |
| 522 | { |
| 481 | 523 | case 0: |
| 482 | 524 | cga.chr_gen = memory_region(REGION_GFX1) + 0x1800; |
| 483 | 525 | break; |
| r2547 | r2548 | |
| 494 | 536 | The character cell size is 16x8 |
| 495 | 537 | ***************************************************************************/ |
| 496 | 538 | |
| 497 | | static MC6845_UPDATE_ROW( cga_text_inten_update_row ) { |
| 539 | static MC6845_UPDATE_ROW( cga_text_inten_update_row ) |
| 540 | { |
| 498 | 541 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 499 | 542 | int i; |
| 500 | 543 | |
| 501 | 544 | if ( y == 0 ) CGA_LOG(1,"cga_text_inten_update_row",("\n")); |
| 502 | | for ( i = 0; i < x_count; i++ ) { |
| 545 | for ( i = 0; i < x_count; i++ ) |
| 546 | { |
| 503 | 547 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x3fff; |
| 504 | 548 | UINT8 chr = videoram[ offset ]; |
| 505 | 549 | UINT8 attr = videoram[ offset +1 ]; |
| r2547 | r2548 | |
| 507 | 551 | UINT16 fg = attr & 0x0F; |
| 508 | 552 | UINT16 bg = attr >> 4; |
| 509 | 553 | |
| 510 | | if ( i == cursor_x ) { |
| 554 | if ( i == cursor_x && ( cga.frame & 0x08 ) ) |
| 555 | { |
| 511 | 556 | data = 0xFF; |
| 512 | 557 | } |
| 513 | 558 | |
| r2547 | r2548 | |
| 528 | 573 | The character cell size is 16x8. Composite monitor, greyscale. |
| 529 | 574 | ***************************************************************************/ |
| 530 | 575 | |
| 531 | | static MC6845_UPDATE_ROW( cga_text_inten_comp_grey_update_row ) { |
| 576 | static MC6845_UPDATE_ROW( cga_text_inten_comp_grey_update_row ) |
| 577 | { |
| 532 | 578 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 533 | 579 | int i; |
| 534 | 580 | |
| 535 | 581 | if ( y == 0 ) CGA_LOG(1,"cga_text_inten_update_row",("\n")); |
| 536 | | for ( i = 0; i < x_count; i++ ) { |
| 582 | for ( i = 0; i < x_count; i++ ) |
| 583 | { |
| 537 | 584 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x3fff; |
| 538 | 585 | UINT8 chr = videoram[ offset ]; |
| 539 | 586 | UINT8 attr = videoram[ offset +1 ]; |
| r2547 | r2548 | |
| 541 | 588 | UINT16 fg = 0x10 + ( attr & 0x0F ); |
| 542 | 589 | UINT16 bg = 0x10 + ( ( attr >> 4 ) & 0x07 ); |
| 543 | 590 | |
| 544 | | if ( i == cursor_x ) { |
| 591 | if ( i == cursor_x && ( cga.frame & 0x08 ) ) |
| 592 | { |
| 545 | 593 | data = 0xFF; |
| 546 | 594 | } |
| 547 | 595 | |
| r2547 | r2548 | |
| 561 | 609 | The character cell size is 16x8 |
| 562 | 610 | ***************************************************************************/ |
| 563 | 611 | |
| 564 | | static MC6845_UPDATE_ROW( cga_text_inten_alt_update_row ) { |
| 612 | static MC6845_UPDATE_ROW( cga_text_inten_alt_update_row ) |
| 613 | { |
| 565 | 614 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 566 | 615 | int i; |
| 567 | 616 | |
| 568 | 617 | if ( y == 0 ) CGA_LOG(1,"cga_text_inten_alt_update_row",("\n")); |
| 569 | | for ( i = 0; i < x_count; i++ ) { |
| 618 | for ( i = 0; i < x_count; i++ ) |
| 619 | { |
| 570 | 620 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x3fff; |
| 571 | 621 | UINT8 chr = videoram[ offset ]; |
| 572 | 622 | UINT8 attr = videoram[ offset +1 ]; |
| 573 | 623 | UINT8 data = cga.chr_gen[ chr * 8 + ra ]; |
| 574 | 624 | UINT16 fg = attr & 0x0F; |
| 575 | 625 | |
| 576 | | if ( i == cursor_x ) { |
| 626 | if ( i == cursor_x && ( cga.frame & 0x08 ) ) |
| 627 | { |
| 577 | 628 | data = 0xFF; |
| 578 | 629 | } |
| 579 | 630 | |
| r2547 | r2548 | |
| 594 | 645 | The character cell size is 16x8 |
| 595 | 646 | ***************************************************************************/ |
| 596 | 647 | |
| 597 | | static MC6845_UPDATE_ROW( cga_text_blink_update_row ) { |
| 648 | static MC6845_UPDATE_ROW( cga_text_blink_update_row ) |
| 649 | { |
| 598 | 650 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 599 | 651 | int i; |
| 600 | 652 | |
| 601 | 653 | if ( y == 0 ) CGA_LOG(1,"cga_text_blink_update_row",("\n")); |
| 602 | | for ( i = 0; i < x_count; i++ ) { |
| 654 | for ( i = 0; i < x_count; i++ ) |
| 655 | { |
| 603 | 656 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x3fff; |
| 604 | 657 | UINT8 chr = videoram[ offset ]; |
| 605 | 658 | UINT8 attr = videoram[ offset +1 ]; |
| r2547 | r2548 | |
| 607 | 660 | UINT16 fg = attr & 0x0F; |
| 608 | 661 | UINT16 bg = attr >> 4; |
| 609 | 662 | |
| 610 | | if ( i == cursor_x ) { |
| 611 | | data = 0xFF; |
| 612 | | } else { |
| 613 | | if ( ( attr & 0x80 ) && ( cga.frame & 0x10 ) ) { |
| 663 | if ( i == cursor_x ) |
| 664 | { |
| 665 | if ( cga.frame & 0x08 ) |
| 666 | { |
| 667 | data = 0xFF; |
| 668 | } |
| 669 | } |
| 670 | else |
| 671 | { |
| 672 | if ( ( attr & 0x80 ) && ( cga.frame & 0x10 ) ) |
| 673 | { |
| 614 | 674 | data = 0x00; |
| 615 | 675 | } |
| 616 | 676 | } |
| r2547 | r2548 | |
| 632 | 692 | The character cell size is 16x8 |
| 633 | 693 | ***************************************************************************/ |
| 634 | 694 | |
| 635 | | static MC6845_UPDATE_ROW( cga_text_blink_alt_update_row ) { |
| 695 | static MC6845_UPDATE_ROW( cga_text_blink_alt_update_row ) |
| 696 | { |
| 636 | 697 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 637 | 698 | int i; |
| 638 | 699 | |
| 639 | 700 | if ( y == 0 ) CGA_LOG(1,"cga_text_blink_alt_update_row",("\n")); |
| 640 | | for ( i = 0; i < x_count; i++ ) { |
| 701 | for ( i = 0; i < x_count; i++ ) |
| 702 | { |
| 641 | 703 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x3fff; |
| 642 | 704 | UINT8 chr = videoram[ offset ]; |
| 643 | 705 | UINT8 attr = videoram[ offset +1 ]; |
| r2547 | r2548 | |
| 645 | 707 | UINT16 fg = attr & 0x07; |
| 646 | 708 | UINT16 bg = 0; |
| 647 | 709 | |
| 648 | | if ( i == cursor_x ) { |
| 649 | | data = 0xFF; |
| 650 | | } else { |
| 651 | | if ( ( attr & 0x80 ) && ( cga.frame & 0x10 ) ) { |
| 710 | if ( i == cursor_x ) |
| 711 | { |
| 712 | if ( cga.frame & 0x08 ) |
| 713 | { |
| 714 | data = 0xFF; |
| 715 | } |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | if ( ( attr & 0x80 ) && ( cga.frame & 0x10 ) ) |
| 720 | { |
| 652 | 721 | data = 0x00; |
| 653 | 722 | bg = ( attr >> 4 ) & 0x07; |
| 654 | 723 | } |
| r2547 | r2548 | |
| 668 | 737 | |
| 669 | 738 | /* The lo-res (320x200) graphics mode on a colour composite monitor */ |
| 670 | 739 | |
| 671 | | static MC6845_UPDATE_ROW( cga_gfx_4bppl_update_row ) { |
| 740 | static MC6845_UPDATE_ROW( cga_gfx_4bppl_update_row ) |
| 741 | { |
| 672 | 742 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 673 | 743 | int i; |
| 674 | 744 | |
| 675 | 745 | if ( y == 0 ) CGA_LOG(1,"cga_gfx_4bppl_update_row",("\n")); |
| 676 | | for ( i = 0; i < x_count; i++ ) { |
| 746 | for ( i = 0; i < x_count; i++ ) |
| 747 | { |
| 677 | 748 | UINT16 offset = ( ( ( ma + i ) << 1 ) & 0x1fff ) | ( ( y & 1 ) << 13 ); |
| 678 | 749 | UINT8 data = videoram[ offset ]; |
| 679 | 750 | |
| r2547 | r2548 | |
| 700 | 771 | |
| 701 | 772 | static const UINT8 yc_lut2[4] = { 0, 182, 71, 255 }; |
| 702 | 773 | |
| 703 | | static const UINT8 yc_lut[16][8] = { |
| 774 | static const UINT8 yc_lut[16][8] = |
| 775 | { |
| 704 | 776 | { 0, 0, 0, 0, 0, 0, 0, 0 }, /* black */ |
| 705 | 777 | { 0, 0, 0, 0, 1, 1, 1, 1 }, /* blue */ |
| 706 | 778 | { 0, 1, 1, 1, 1, 0, 0, 0 }, /* green */ |
| r2547 | r2548 | |
| 720 | 792 | { 3, 3, 3, 3, 3, 3, 3, 3 }, /* white */ |
| 721 | 793 | }; |
| 722 | 794 | |
| 723 | | static MC6845_UPDATE_ROW( cga_gfx_4bpph_update_row ) { |
| 795 | static MC6845_UPDATE_ROW( cga_gfx_4bpph_update_row ) |
| 796 | { |
| 724 | 797 | UINT8 samples[1280]; |
| 725 | 798 | UINT8 ntsc_decoded[3*1280]; |
| 726 | 799 | int samp_index = 0; |
| r2547 | r2548 | |
| 728 | 801 | int i; |
| 729 | 802 | |
| 730 | 803 | if ( y == 0 ) CGA_LOG(1,"cga_gfx_4bpph_update_row",("\n")); |
| 731 | | if ( NTSC_FILTER ) { |
| 804 | if ( NTSC_FILTER ) |
| 805 | { |
| 732 | 806 | ntsc_clear( &ntsc ); |
| 733 | 807 | memset( ntsc_decoded, 0, sizeof(ntsc_decoded)); |
| 734 | 808 | } |
| 735 | | for ( i = 0; i < x_count; i++ ) { |
| 809 | for ( i = 0; i < x_count; i++ ) |
| 810 | { |
| 736 | 811 | UINT16 offset = ( ( ( ma + i ) << 1 ) & 0x1fff ) | ( ( y & 1 ) << 13 ); |
| 737 | 812 | UINT8 data = videoram[ offset ]; |
| 738 | 813 | |
| 739 | | if ( NTSC_FILTER ) { |
| 814 | if ( NTSC_FILTER ) |
| 815 | { |
| 740 | 816 | samples[samp_index] = yc_lut2[yc_lut[data>>4][0]]; samp_index++; |
| 741 | 817 | samples[samp_index] = yc_lut2[yc_lut[data>>4][1]]; samp_index++; |
| 742 | 818 | samples[samp_index] = yc_lut2[yc_lut[data>>4][2]]; samp_index++; |
| r2547 | r2548 | |
| 767 | 843 | |
| 768 | 844 | data = videoram[ offset + 1 ]; |
| 769 | 845 | |
| 770 | | if ( NTSC_FILTER ) { |
| 846 | if ( NTSC_FILTER ) |
| 847 | { |
| 771 | 848 | samples[samp_index] = yc_lut2[yc_lut[data>>4][0]]; samp_index++; |
| 772 | 849 | samples[samp_index] = yc_lut2[yc_lut[data>>4][1]]; samp_index++; |
| 773 | 850 | samples[samp_index] = yc_lut2[yc_lut[data>>4][2]]; samp_index++; |
| r2547 | r2548 | |
| 796 | 873 | *p = data & 0x0F; p++; |
| 797 | 874 | *p = data & 0x0F; p++; |
| 798 | 875 | } |
| 799 | | if (NTSC_FILTER) { |
| 876 | if (NTSC_FILTER) |
| 877 | { |
| 800 | 878 | ntsc_decode( &ntsc, samples, ntsc_decoded, 160 ); |
| 801 | 879 | p = BITMAP_ADDR16(bitmap, y, 0); |
| 802 | 880 | samp_index = 0; |
| 803 | | for ( i = 0; i < ( 8 * x_count ); i++ ) { |
| 881 | for ( i = 0; i < ( 8 * x_count ); i++ ) |
| 882 | { |
| 804 | 883 | int r = ( ntsc_decoded[samp_index] + ntsc_decoded[samp_index+3] ) / 2; |
| 805 | 884 | int g = ( ntsc_decoded[samp_index+1] + ntsc_decoded[samp_index+4] ) / 2; |
| 806 | 885 | int b = ( ntsc_decoded[samp_index+2] + ntsc_decoded[samp_index+5] ) / 2; |
| r2547 | r2548 | |
| 818 | 897 | cga fetches 2 byte per mc6845 access. |
| 819 | 898 | ***************************************************************************/ |
| 820 | 899 | |
| 821 | | static MC6845_UPDATE_ROW( cga_gfx_2bpp_update_row ) { |
| 900 | static MC6845_UPDATE_ROW( cga_gfx_2bpp_update_row ) |
| 901 | { |
| 822 | 902 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 823 | 903 | int i; |
| 824 | 904 | |
| 825 | 905 | if ( y == 0 ) CGA_LOG(1,"cga_gfx_2bpp_update_row",("\n")); |
| 826 | | for ( i = 0; i < x_count; i++ ) { |
| 906 | for ( i = 0; i < x_count; i++ ) |
| 907 | { |
| 827 | 908 | UINT16 offset = ( ( ( ma + i ) << 1 ) & 0x1fff ) | ( ( y & 1 ) << 13 ); |
| 828 | 909 | UINT8 data = videoram[ offset ]; |
| 829 | 910 | |
| r2547 | r2548 | |
| 849 | 930 | Even scanlines are from CGA_base + 0x0000, odd from CGA_base + 0x2000 |
| 850 | 931 | ***************************************************************************/ |
| 851 | 932 | |
| 852 | | static MC6845_UPDATE_ROW( cga_gfx_1bpp_update_row ) { |
| 933 | static MC6845_UPDATE_ROW( cga_gfx_1bpp_update_row ) |
| 934 | { |
| 853 | 935 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 854 | 936 | UINT8 fg = cga.color_select & 0x0F; |
| 855 | 937 | int i; |
| 856 | 938 | |
| 857 | 939 | if ( y == 0 ) CGA_LOG(1,"cga_gfx_1bpp_update_row",("\n")); |
| 858 | | for ( i = 0; i < x_count; i++ ) { |
| 940 | for ( i = 0; i < x_count; i++ ) |
| 941 | { |
| 859 | 942 | UINT16 offset = ( ( ( ma + i ) << 1 ) & 0x1fff ) | ( ( ra & 1 ) << 13 ); |
| 860 | 943 | UINT8 data = videoram[ offset ]; |
| 861 | 944 | |
| r2547 | r2548 | |
| 882 | 965 | } |
| 883 | 966 | |
| 884 | 967 | |
| 885 | | static MC6845_UPDATE_ROW( cga_update_row ) { |
| 886 | | if ( cga.update_row ) { |
| 968 | static MC6845_UPDATE_ROW( cga_update_row ) |
| 969 | { |
| 970 | if ( cga.update_row ) |
| 971 | { |
| 887 | 972 | cga.update_row( device, bitmap, cliprect, ma, ra, y, x_count, cursor_x, param ); |
| 888 | 973 | } |
| 889 | 974 | } |
| 890 | 975 | |
| 891 | 976 | |
| 892 | | static MC6845_ON_HSYNC_CHANGED( cga_hsync_changed ) { |
| 977 | static MC6845_ON_HSYNC_CHANGED( cga_hsync_changed ) |
| 978 | { |
| 893 | 979 | cga.hsync = hsync ? 1 : 0; |
| 894 | 980 | } |
| 895 | 981 | |
| 896 | 982 | |
| 897 | | static MC6845_ON_VSYNC_CHANGED( cga_vsync_changed ) { |
| 983 | static MC6845_ON_VSYNC_CHANGED( cga_vsync_changed ) |
| 984 | { |
| 898 | 985 | cga.vsync = vsync ? 8 : 0; |
| 899 | | if ( vsync ) { |
| 986 | if ( vsync ) |
| 987 | { |
| 900 | 988 | cga.frame++; |
| 901 | 989 | } |
| 902 | 990 | } |
| 903 | 991 | |
| 904 | 992 | |
| 905 | | static void pc_cga_set_palette_luts(void) { |
| 993 | static void pc_cga_set_palette_luts(void) |
| 994 | { |
| 906 | 995 | /* Setup 2bpp palette lookup table */ |
| 907 | | if ( cga.mode_control & 0x10 ) { |
| 996 | if ( cga.mode_control & 0x10 ) |
| 997 | { |
| 908 | 998 | cga.palette_lut_2bpp[0] = 0; |
| 909 | | } else { |
| 999 | } |
| 1000 | else |
| 1001 | { |
| 910 | 1002 | cga.palette_lut_2bpp[0] = cga.color_select & 0x0F; |
| 911 | 1003 | } |
| 912 | | if ( cga.mode_control & 0x04 ) { |
| 1004 | if ( cga.mode_control & 0x04 ) |
| 1005 | { |
| 913 | 1006 | cga.palette_lut_2bpp[1] = ( ( cga.color_select & 0x10 ) >> 1 ) | 3; |
| 914 | 1007 | cga.palette_lut_2bpp[2] = ( ( cga.color_select & 0x10 ) >> 1 ) | 4; |
| 915 | 1008 | cga.palette_lut_2bpp[3] = ( ( cga.color_select & 0x10 ) >> 1 ) | 7; |
| 916 | | } else { |
| 917 | | if ( cga.color_select & 0x20 ) { |
| 1009 | } |
| 1010 | else |
| 1011 | { |
| 1012 | if ( cga.color_select & 0x20 ) |
| 1013 | { |
| 918 | 1014 | cga.palette_lut_2bpp[1] = ( ( cga.color_select & 0x10 ) >> 1 ) | 3; |
| 919 | 1015 | cga.palette_lut_2bpp[2] = ( ( cga.color_select & 0x10 ) >> 1 ) | 5; |
| 920 | 1016 | cga.palette_lut_2bpp[3] = ( ( cga.color_select & 0x10 ) >> 1 ) | 7; |
| 921 | | } else { |
| 1017 | } |
| 1018 | else |
| 1019 | { |
| 922 | 1020 | cga.palette_lut_2bpp[1] = ( ( cga.color_select & 0x10 ) >> 1 ) | 2; |
| 923 | 1021 | cga.palette_lut_2bpp[2] = ( ( cga.color_select & 0x10 ) >> 1 ) | 4; |
| 924 | 1022 | cga.palette_lut_2bpp[3] = ( ( cga.color_select & 0x10 ) >> 1 ) | 6; |
| r2547 | r2548 | |
| 957 | 1055 | cga.mode_control = data; |
| 958 | 1056 | |
| 959 | 1057 | //logerror("mode set to %02X\n", cga.mode_control & 0x3F ); |
| 960 | | switch ( cga.mode_control & 0x3F ) { |
| 1058 | switch ( cga.mode_control & 0x3F ) |
| 1059 | { |
| 961 | 1060 | case 0x08: case 0x09: case 0x0C: case 0x0D: |
| 962 | 1061 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 963 | | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 964 | | if ( cga.mode_control & 0x04 ) { |
| 1062 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) |
| 1063 | { |
| 1064 | if ( cga.mode_control & 0x04 ) |
| 1065 | { |
| 965 | 1066 | /* Composite greyscale */ |
| 966 | 1067 | cga.update_row = cga_text_inten_comp_grey_update_row; |
| 967 | | } else { |
| 1068 | } |
| 1069 | else |
| 1070 | { |
| 968 | 1071 | /* Composite colour */ |
| 969 | 1072 | cga.update_row = cga_text_inten_update_row; |
| 970 | 1073 | } |
| 971 | | } else { |
| 1074 | } |
| 1075 | else |
| 1076 | { |
| 972 | 1077 | /* RGB colour */ |
| 973 | 1078 | cga.update_row = cga_text_inten_update_row; |
| 974 | 1079 | } |
| 975 | 1080 | break; |
| 976 | 1081 | case 0x0A: case 0x0B: case 0x2A: case 0x2B: |
| 977 | 1082 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 978 | | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 1083 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) |
| 1084 | { |
| 979 | 1085 | cga.update_row = cga_gfx_4bppl_update_row; |
| 980 | | } else { |
| 1086 | } |
| 1087 | else |
| 1088 | { |
| 981 | 1089 | cga.update_row = cga_gfx_2bpp_update_row; |
| 982 | 1090 | } |
| 983 | 1091 | break; |
| r2547 | r2548 | |
| 991 | 1099 | break; |
| 992 | 1100 | case 0x1A: case 0x1B: case 0x3A: case 0x3B: |
| 993 | 1101 | mc6845_set_hpixels_per_column( devconf, 16 ); |
| 994 | | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 1102 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) |
| 1103 | { |
| 995 | 1104 | cga.update_row = cga_gfx_4bpph_update_row; |
| 996 | | } else { |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 997 | 1108 | cga.update_row = cga_gfx_1bpp_update_row; |
| 998 | 1109 | } |
| 999 | 1110 | break; |
| r2547 | r2548 | |
| 1003 | 1114 | break; |
| 1004 | 1115 | case 0x28: case 0x29: case 0x2C: case 0x2D: |
| 1005 | 1116 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1006 | | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 1007 | | if ( cga.mode_control & 0x04 ) { |
| 1117 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) |
| 1118 | { |
| 1119 | if ( cga.mode_control & 0x04 ) |
| 1120 | { |
| 1008 | 1121 | /* Composite greyscale */ |
| 1009 | 1122 | cga.update_row = cga_text_blink_update_row; |
| 1010 | | } else { |
| 1123 | } |
| 1124 | else |
| 1125 | { |
| 1011 | 1126 | /* Composite colour */ |
| 1012 | 1127 | cga.update_row = cga_text_blink_update_row; |
| 1013 | 1128 | } |
| 1014 | | } else { |
| 1129 | } |
| 1130 | else |
| 1131 | { |
| 1015 | 1132 | /* RGB colour */ |
| 1016 | 1133 | cga.update_row = cga_text_blink_update_row; |
| 1017 | 1134 | } |
| r2547 | r2548 | |
| 1316 | 1433 | static const int videoram_offset[4]= { 0x0000, 0x4000, 0x8000, 0xC000 }; |
| 1317 | 1434 | |
| 1318 | 1435 | |
| 1319 | | static const UINT8 mc6845_writeonce_register[31] = { |
| 1436 | static const UINT8 mc6845_writeonce_register[31] = |
| 1437 | { |
| 1320 | 1438 | 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 1321 | 1439 | }; |
| 1322 | 1440 | |
| r2547 | r2548 | |
| 1330 | 1448 | } pc1512; |
| 1331 | 1449 | |
| 1332 | 1450 | |
| 1333 | | static MC6845_UPDATE_ROW( pc1512_gfx_4bpp_update_row ) { |
| 1451 | static MC6845_UPDATE_ROW( pc1512_gfx_4bpp_update_row ) |
| 1452 | { |
| 1334 | 1453 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 1335 | 1454 | UINT16 offset_base = ra << 13; |
| 1336 | 1455 | int i; |
| 1337 | 1456 | |
| 1338 | 1457 | if ( y == 0 ) CGA_LOG(1,"pc1512_gfx_4bpp_update_row",("\n")); |
| 1339 | | for ( i = 0; i < x_count; i++ ) { |
| 1458 | for ( i = 0; i < x_count; i++ ) |
| 1459 | { |
| 1340 | 1460 | UINT16 offset = offset_base | ( ( ma + i ) & 0x1FFF ); |
| 1341 | 1461 | UINT16 i = ( cga.color_select & 8 ) ? videoram[ videoram_offset[3] | offset ] << 3 : 0; |
| 1342 | 1462 | UINT16 r = ( cga.color_select & 4 ) ? videoram[ videoram_offset[2] | offset ] << 2 : 0; |
| r2547 | r2548 | |
| 1359 | 1479 | { |
| 1360 | 1480 | device_config *devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, CGA_MC6845_NAME); |
| 1361 | 1481 | |
| 1362 | | switch (offset) { |
| 1482 | switch (offset) |
| 1483 | { |
| 1363 | 1484 | case 0: case 2: case 4: case 6: |
| 1364 | 1485 | data &= 0x1F; |
| 1365 | 1486 | mc6845_address_w( devconf, offset, data ); |
| r2547 | r2548 | |
| 1367 | 1488 | break; |
| 1368 | 1489 | |
| 1369 | 1490 | case 1: case 3: case 5: case 7: |
| 1370 | | if ( ! pc1512.mc6845_locked_register[pc1512.mc6845_address] ) { |
| 1491 | if ( ! pc1512.mc6845_locked_register[pc1512.mc6845_address] ) |
| 1492 | { |
| 1371 | 1493 | mc6845_register_w( devconf, offset, data ); |
| 1372 | | if ( mc6845_writeonce_register[pc1512.mc6845_address] ) { |
| 1494 | if ( mc6845_writeonce_register[pc1512.mc6845_address] ) |
| 1495 | { |
| 1373 | 1496 | pc1512.mc6845_locked_register[pc1512.mc6845_address] = 1; |
| 1374 | 1497 | } |
| 1375 | 1498 | } |
| r2547 | r2548 | |
| 1377 | 1500 | |
| 1378 | 1501 | case 0x8: |
| 1379 | 1502 | /* Check if we're changing to graphics mode 2 */ |
| 1380 | | if ( ( cga.mode_control & 0x12 ) != 0x12 && ( data & 0x12 ) == 0x12 ) { |
| 1503 | if ( ( cga.mode_control & 0x12 ) != 0x12 && ( data & 0x12 ) == 0x12 ) |
| 1504 | { |
| 1381 | 1505 | pc1512.write = 0x0F; |
| 1382 | | } else { |
| 1506 | } |
| 1507 | else |
| 1508 | { |
| 1383 | 1509 | memory_set_bankptr(1, videoram + videoram_offset[0]); |
| 1384 | 1510 | } |
| 1385 | 1511 | cga.mode_control = data; |
| 1386 | | switch( cga.mode_control & 0x3F ) { |
| 1512 | switch( cga.mode_control & 0x3F ) |
| 1513 | { |
| 1387 | 1514 | case 0x08: case 0x09: case 0x0C: case 0x0D: |
| 1388 | 1515 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1389 | 1516 | cga.update_row = cga_text_inten_update_row; |
| 1390 | 1517 | break; |
| 1391 | 1518 | case 0x0A: case 0x0B: case 0x2A: case 0x2B: |
| 1392 | 1519 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1393 | | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 1520 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) |
| 1521 | { |
| 1394 | 1522 | cga.update_row = cga_gfx_4bppl_update_row; |
| 1395 | | } else { |
| 1523 | } |
| 1524 | else |
| 1525 | { |
| 1396 | 1526 | cga.update_row = cga_gfx_2bpp_update_row; |
| 1397 | 1527 | } |
| 1398 | 1528 | break; |
| r2547 | r2548 | |
| 1432 | 1562 | |
| 1433 | 1563 | case 0xe: |
| 1434 | 1564 | pc1512.read = data; |
| 1435 | | if ( ( cga.mode_control & 0x12 ) == 0x12 ) { |
| 1565 | if ( ( cga.mode_control & 0x12 ) == 0x12 ) |
| 1566 | { |
| 1436 | 1567 | memory_set_bankptr(1, videoram + videoram_offset[data & 3]); |
| 1437 | 1568 | } |
| 1438 | 1569 | break; |
| r2547 | r2548 | |
| 1447 | 1578 | { |
| 1448 | 1579 | UINT8 data; |
| 1449 | 1580 | |
| 1450 | | switch (offset) { |
| 1581 | switch (offset) |
| 1582 | { |
| 1451 | 1583 | case 0xd: |
| 1452 | 1584 | data = pc1512.write; |
| 1453 | 1585 | break; |
| r2547 | r2548 | |
| 1466 | 1598 | |
| 1467 | 1599 | static WRITE8_HANDLER ( pc1512_videoram_w ) |
| 1468 | 1600 | { |
| 1469 | | if ( ( cga.mode_control & 0x12 ) == 0x12 ) { |
| 1601 | if ( ( cga.mode_control & 0x12 ) == 0x12 ) |
| 1602 | { |
| 1470 | 1603 | if (pc1512.write & 1) |
| 1471 | 1604 | videoram[offset+videoram_offset[0]] = data; /* blue plane */ |
| 1472 | 1605 | if (pc1512.write & 2) |
| r2547 | r2548 | |
| 1475 | 1608 | videoram[offset+videoram_offset[2]] = data; /* red */ |
| 1476 | 1609 | if (pc1512.write & 8) |
| 1477 | 1610 | videoram[offset+videoram_offset[3]] = data; /* intensity (text, 4color) */ |
| 1478 | | } else { |
| 1611 | } |
| 1612 | else |
| 1613 | { |
| 1479 | 1614 | videoram[offset + videoram_offset[0]] = data; |
| 1480 | 1615 | } |
| 1481 | 1616 | } |
| r2547 | r2548 | |
| 1510 | 1645 | mc6845_update( devconf, bitmap, cliprect); |
| 1511 | 1646 | |
| 1512 | 1647 | /* Check for changes in font dipsetting */ |
| 1513 | | switch ( CGA_FONT & 0x03 ) { |
| 1648 | switch ( CGA_FONT & 0x03 ) |
| 1649 | { |
| 1514 | 1650 | case 0: |
| 1515 | 1651 | cga.chr_gen = memory_region(REGION_GFX1) + 0x0000; |
| 1516 | 1652 | break; |