src/mess/video/pc_cga.c
| r2103 | r2104 | |
| 54 | 54 | #include "memconv.h" |
| 55 | 55 | |
| 56 | 56 | #define VERBOSE_CGA 0 /* CGA (Color Graphics Adapter) */ |
| 57 | #define NTSC_FILTER 0 |
| 57 | 58 | |
| 58 | 59 | #define CGA_LOG(N,M,A) \ |
| 59 | 60 | if(VERBOSE_CGA>=N){ if( M )logerror("%11.6f: %-24s",attotime_to_double(timer_get_time()),(char*)M ); logerror A; } |
| r2103 | r2104 | |
| 103 | 104 | MDRV_SCREEN_ADD(CGA_SCREEN_NAME, RASTER) |
| 104 | 105 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 105 | 106 | MDRV_SCREEN_RAW_PARAMS(XTAL_14_31818MHz,912,0,640,262,0,200) |
| 106 | | MDRV_PALETTE_LENGTH( CGA_PALETTE_SETS * 16 ) |
| 107 | MDRV_PALETTE_LENGTH(/* CGA_PALETTE_SETS * 16*/ 65536 ) |
| 107 | 108 | |
| 108 | 109 | MDRV_PALETTE_INIT(pc_cga) |
| 109 | 110 | |
| r2103 | r2104 | |
| 170 | 171 | |
| 171 | 172 | |
| 172 | 173 | /*************************************************************************** |
| 174 | * |
| 175 | * NTSC filter |
| 176 | * |
| 177 | * Code taken from http://www.reenigne.org/crtc.html |
| 178 | * |
| 179 | ***************************************************************************/ |
| 173 | 180 | |
| 181 | struct ntsc_decoder { |
| 182 | int period; |
| 183 | |
| 184 | int *I_filter; |
| 185 | int *Q_filter; |
| 186 | |
| 187 | int *Y_buffer; |
| 188 | int *I_buffer; |
| 189 | int *Q_buffer; |
| 190 | |
| 191 | int Y_total; |
| 192 | int I_total; |
| 193 | int Q_total; |
| 194 | } ntsc; |
| 195 | |
| 196 | |
| 197 | /* Clear NTSC buffers and running totals. Call this before the beginning of each new line. */ |
| 198 | static void ntsc_clear(struct ntsc_decoder *ntsc) { |
| 199 | int j; |
| 200 | for (j=0;j<ntsc->period;++j) { |
| 201 | ntsc->Y_buffer[j] = 0; |
| 202 | ntsc->I_buffer[j] = 0; |
| 203 | ntsc->Q_buffer[j] = 0; |
| 204 | } |
| 205 | ntsc->Y_total = 0; |
| 206 | ntsc->I_total = 0; |
| 207 | ntsc->Q_total = 0; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /* Create an NTSC decoder object. |
| 212 | |
| 213 | period is the number of times the NTSC signal is sampled per cycle of the color subcarrier clock (3.579545 MHz). |
| 214 | e.g. CGA is 8 because you need to sample the chroma signal at 28.6MHz to retain all color information. |
| 215 | For 4-color composite systems such as CoCo, 2 samples may suffice. |
| 216 | |
| 217 | samples is also the number of data points whose values are used to determine the color of a given point. |
| 218 | |
| 219 | Points here do not necessarily correspond to pixels - points are samples of the RGB color decoded output and pixels |
| 220 | are CPU addressable points in the input composite data. |
| 221 | |
| 222 | The correct value for hue will usually be a multiple of 128. |
| 223 | */ |
| 224 | static void ntsc_decoder_init(struct ntsc_decoder *ntsc, int period, int hue) { |
| 225 | int j; |
| 226 | |
| 227 | ntsc->period = period; |
| 228 | ntsc->I_filter = auto_malloc(period * sizeof(int)); |
| 229 | ntsc->Q_filter = auto_malloc(period * sizeof(int)); |
| 230 | ntsc->Y_buffer = auto_malloc(period * sizeof(int)); |
| 231 | ntsc->I_buffer = auto_malloc(period * sizeof(int)); |
| 232 | ntsc->Q_buffer = auto_malloc(period * sizeof(int)); |
| 233 | ntsc_clear(ntsc); |
| 234 | for (j=0;j<period;++j) { |
| 235 | double angle = M_PI*((hue+(j<<8))/(period*128.0)-33.0/180); |
| 236 | ntsc->I_filter[j] = (int)(512.0*cos(angle)); |
| 237 | ntsc->Q_filter[j] = (int)(512.0*sin(angle)); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | |
| 242 | /* Decode some NTSC data, working from left to right. |
| 243 | |
| 244 | The composite (luma+chroma) values are in "input", scaled to 0-255 values. |
| 245 | Red, green and blue bytes (in that order) are placed in "output". |
| 246 | |
| 247 | Note that consecutive calls to ntsc_decode() should be on consecutive input data, |
| 248 | or the first ntsc->samples points will be inaccurate. To avoid this inaccuracy, |
| 249 | first call ntsc_decode(ntsc, input, NULL, 1) with "input" containing the |
| 250 | samples directly before the samples you will subsequently be using. |
| 251 | */ |
| 252 | static void ntsc_decode(struct ntsc_decoder *ntsc, UINT8 *input, UINT8 *output, int periods) { |
| 253 | int j; |
| 254 | |
| 255 | int *I_filter; |
| 256 | int *Q_filter; |
| 257 | int *Y_buffer; |
| 258 | int *I_buffer; |
| 259 | int *Q_buffer; |
| 260 | int Y_total = ntsc->Y_total; |
| 261 | int I_total = ntsc->I_total; |
| 262 | int Q_total = ntsc->Q_total; |
| 263 | int Y,I,Q; |
| 264 | int R,G,B; |
| 265 | int period = ntsc->period; |
| 266 | |
| 267 | while ((--periods)>=0) { |
| 268 | I_filter = ntsc->I_filter; |
| 269 | Q_filter = ntsc->Q_filter; |
| 270 | Y_buffer = ntsc->Y_buffer; |
| 271 | I_buffer = ntsc->I_buffer; |
| 272 | Q_buffer = ntsc->Q_buffer; |
| 273 | |
| 274 | for (j=0;j<period;++j) { |
| 275 | |
| 276 | /* Get next point */ |
| 277 | Y = *(input++); |
| 278 | I = Y * *(I_filter++); |
| 279 | Q = Y * *(Q_filter++); |
| 280 | |
| 281 | /* Update running totals */ |
| 282 | Y_total += Y - *Y_buffer; |
| 283 | I_total += I - *I_buffer; |
| 284 | Q_total += Q - *Q_buffer; |
| 285 | |
| 286 | /* Save point in buffer */ |
| 287 | *(Y_buffer++) = Y; |
| 288 | *(I_buffer++) = I; |
| 289 | *(Q_buffer++) = Q; |
| 290 | |
| 291 | /* Compute averages over entire period */ |
| 292 | Y = Y_total/period; |
| 293 | I = I_total/period; |
| 294 | Q = Q_total/period; |
| 295 | |
| 296 | /* Clamp YIQ values to avoid hue drift of oversaturated colors */ |
| 297 | if (Y>256) Y=256; if (Y<0) Y=0; |
| 298 | if (I>39041) I=39041; if (I<-39041) I=-39041; |
| 299 | if (Q>34249) Q=34249; if (Q<-34249) Q=-34249; |
| 300 | |
| 301 | /* Convert YIQ to RGB */ |
| 302 | Y<<=16; |
| 303 | R = (Y + 249*I + 159*Q)>>16; |
| 304 | G = (Y - 70*I - 166*Q)>>16; |
| 305 | B = (Y - 283*I + 436*Q)>>16; |
| 306 | |
| 307 | /* Clamp the RGB values */ |
| 308 | if (R>255) R=255; if (R<0) R=0; |
| 309 | if (G>255) G=255; if (G<0) G=0; |
| 310 | if (B>255) B=255; if (B<0) B=0; |
| 311 | |
| 312 | /* Emit the RGB values to the output buffer */ |
| 313 | *output = R; output++; |
| 314 | *output = G; output++; |
| 315 | *output = B; output++; |
| 316 | } |
| 317 | } |
| 318 | ntsc->Y_total = Y_total; |
| 319 | ntsc->I_total = I_total; |
| 320 | ntsc->Q_total = Q_total; |
| 321 | } |
| 322 | |
| 323 | |
| 324 | /*************************************************************************** |
| 325 | |
| 174 | 326 | Methods |
| 175 | 327 | |
| 176 | 328 | ***************************************************************************/ |
| r2103 | r2104 | |
| 178 | 330 | /* Initialise the cga palette */ |
| 179 | 331 | static PALETTE_INIT( pc_cga ) |
| 180 | 332 | { |
| 181 | | int i; |
| 333 | int i, r, g, b; |
| 182 | 334 | |
| 183 | 335 | for ( i = 0; i < CGA_PALETTE_SETS * 16; i++ ) { |
| 184 | 336 | palette_set_color_rgb( machine, i, cga_palette[i][0], cga_palette[i][1], cga_palette[i][2] ); |
| 185 | 337 | } |
| 338 | |
| 339 | i = 0x8000; |
| 340 | for ( r = 0; r < 32; r++ ) { |
| 341 | for ( g = 0; g < 32; g++ ) { |
| 342 | for ( b = 0; b < 32; b++ ) { |
| 343 | palette_set_color_rgb( machine, i, r << 3, g << 3, b << 3 ); |
| 344 | i++; |
| 345 | } |
| 346 | } |
| 347 | } |
| 186 | 348 | } |
| 187 | 349 | |
| 188 | 350 | |
| r2103 | r2104 | |
| 247 | 409 | memory_set_bankptr(11, videoram); |
| 248 | 410 | |
| 249 | 411 | internal_pc_cga_video_start(M6845_PERSONALITY_GENUINE); |
| 412 | |
| 413 | ntsc_decoder_init( &ntsc, 8, 256 ); |
| 250 | 414 | } |
| 251 | 415 | |
| 252 | 416 | |
| r2103 | r2104 | |
| 284 | 448 | UINT8 attr = videoram[ offset +1 ]; |
| 285 | 449 | UINT8 data = cga.chr_gen[ chr * 8 + ra ]; |
| 286 | 450 | UINT16 fg = attr & 0x0F; |
| 287 | | UINT16 bg = ( attr >> 4 ) & 0x07; |
| 451 | UINT16 bg = attr >> 4; |
| 288 | 452 | |
| 289 | 453 | if ( i == cursor_x ) { |
| 290 | 454 | data = 0xFF; |
| r2103 | r2104 | |
| 304 | 468 | |
| 305 | 469 | /*************************************************************************** |
| 306 | 470 | Draw text mode with 40x25 characters (default) with high intensity bg. |
| 471 | The character cell size is 16x8. Composite monitor, greyscale. |
| 472 | ***************************************************************************/ |
| 473 | |
| 474 | static MC6845_UPDATE_ROW( cga_text_inten_comp_grey_update_row ) { |
| 475 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 476 | int i; |
| 477 | |
| 478 | if ( y == 0 ) logerror("cga_text_inten_update_row\n"); |
| 479 | for ( i = 0; i < x_count; i++ ) { |
| 480 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x3fff; |
| 481 | UINT8 chr = videoram[ offset ]; |
| 482 | UINT8 attr = videoram[ offset +1 ]; |
| 483 | UINT8 data = cga.chr_gen[ chr * 8 + ra ]; |
| 484 | UINT16 fg = 0x10 + ( attr & 0x0F ); |
| 485 | UINT16 bg = 0x10 + ( ( attr >> 4 ) & 0x07 ); |
| 486 | |
| 487 | if ( i == cursor_x ) { |
| 488 | data = 0xFF; |
| 489 | } |
| 490 | |
| 491 | *p = ( data & 0x80 ) ? fg : bg; p++; |
| 492 | *p = ( data & 0x40 ) ? fg : bg; p++; |
| 493 | *p = ( data & 0x20 ) ? fg : bg; p++; |
| 494 | *p = ( data & 0x10 ) ? fg : bg; p++; |
| 495 | *p = ( data & 0x08 ) ? fg : bg; p++; |
| 496 | *p = ( data & 0x04 ) ? fg : bg; p++; |
| 497 | *p = ( data & 0x02 ) ? fg : bg; p++; |
| 498 | *p = ( data & 0x01 ) ? fg : bg; p++; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | /*************************************************************************** |
| 503 | Draw text mode with 40x25 characters (default) with high intensity bg. |
| 307 | 504 | The character cell size is 16x8 |
| 308 | 505 | ***************************************************************************/ |
| 309 | 506 | |
| r2103 | r2104 | |
| 411 | 608 | } |
| 412 | 609 | |
| 413 | 610 | |
| 414 | | /* The lo-res graphics mode on a colour composite monitor */ |
| 611 | /* The lo-res (320x200) graphics mode on a colour composite monitor */ |
| 415 | 612 | |
| 416 | 613 | static MC6845_UPDATE_ROW( cga_gfx_4bppl_update_row ) { |
| 417 | 614 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| r2103 | r2104 | |
| 443 | 640 | * are the same size as the normal colour ones. |
| 444 | 641 | */ |
| 445 | 642 | |
| 643 | static const UINT8 yc_lut2[4] = { 0, 182, 71, 255 }; |
| 644 | |
| 645 | static const UINT8 yc_lut[16][8] = { |
| 646 | { 0, 0, 0, 0, 0, 0, 0, 0 }, /* black */ |
| 647 | { 0, 0, 0, 0, 1, 1, 1, 1 }, /* blue */ |
| 648 | { 0, 1, 1, 1, 1, 0, 0, 0 }, /* green */ |
| 649 | { 0, 0, 1, 1, 1, 1, 0, 0 }, /* cyan */ |
| 650 | { 1, 1, 0, 0, 0, 0, 1, 1 }, /* red */ |
| 651 | { 1, 0, 0, 0, 0, 1, 1, 1 }, /* magenta */ |
| 652 | { 1, 1, 1, 1, 0, 0, 0, 0 }, /* yellow */ |
| 653 | { 1, 1, 1, 1, 1, 1, 1, 1 }, /* white */ |
| 654 | /* Intensity set */ |
| 655 | { 2, 2, 2, 2, 2, 2, 2, 2 }, /* black */ |
| 656 | { 2, 2, 2, 2, 3, 3, 3, 3 }, /* blue */ |
| 657 | { 2, 3, 3, 3, 3, 2, 2, 2 }, /* green */ |
| 658 | { 2, 2, 3, 3, 3, 3, 2, 2 }, /* cyan */ |
| 659 | { 3, 3, 2, 2, 2, 2, 3, 3 }, /* red */ |
| 660 | { 3, 2, 2, 2, 2, 3, 3, 3 }, /* magenta */ |
| 661 | { 3, 3, 3, 3, 2, 2, 2, 2 }, /* yellow */ |
| 662 | { 3, 3, 3, 3, 3, 3, 3, 3 }, /* white */ |
| 663 | }; |
| 664 | |
| 446 | 665 | static MC6845_UPDATE_ROW( cga_gfx_4bpph_update_row ) { |
| 666 | UINT8 samples[1280]; |
| 667 | UINT8 ntsc_decoded[3*1280]; |
| 668 | int samp_index = 0; |
| 447 | 669 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 448 | 670 | int i; |
| 449 | 671 | |
| 450 | 672 | if ( y == 0 ) logerror("cga_gfx_4bpph_update_row\n"); |
| 673 | if ( NTSC_FILTER ) { |
| 674 | ntsc_clear( &ntsc ); |
| 675 | memset( ntsc_decoded, 0, sizeof(ntsc_decoded)); |
| 676 | } |
| 451 | 677 | for ( i = 0; i < x_count; i++ ) { |
| 452 | 678 | UINT16 offset = ( ( ( ma + i ) << 1 ) & 0x1fff ) | ( ( y & 1 ) << 13 ); |
| 453 | 679 | UINT8 data = videoram[ offset ]; |
| 454 | 680 | |
| 681 | if ( NTSC_FILTER ) { |
| 682 | samples[samp_index] = yc_lut2[yc_lut[data>>4][0]]; samp_index++; |
| 683 | samples[samp_index] = yc_lut2[yc_lut[data>>4][1]]; samp_index++; |
| 684 | samples[samp_index] = yc_lut2[yc_lut[data>>4][2]]; samp_index++; |
| 685 | samples[samp_index] = yc_lut2[yc_lut[data>>4][3]]; samp_index++; |
| 686 | samples[samp_index] = yc_lut2[yc_lut[data>>4][4]]; samp_index++; |
| 687 | samples[samp_index] = yc_lut2[yc_lut[data>>4][5]]; samp_index++; |
| 688 | samples[samp_index] = yc_lut2[yc_lut[data>>4][6]]; samp_index++; |
| 689 | samples[samp_index] = yc_lut2[yc_lut[data>>4][7]]; samp_index++; |
| 690 | |
| 691 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][0]]; samp_index++; |
| 692 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][1]]; samp_index++; |
| 693 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][2]]; samp_index++; |
| 694 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][3]]; samp_index++; |
| 695 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][4]]; samp_index++; |
| 696 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][5]]; samp_index++; |
| 697 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][6]]; samp_index++; |
| 698 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][7]]; samp_index++; |
| 699 | } |
| 700 | |
| 455 | 701 | *p = data >> 4; p++; |
| 456 | 702 | *p = data >> 4; p++; |
| 703 | *p = data >> 4; p++; |
| 704 | *p = data >> 4; p++; |
| 457 | 705 | *p = data & 0x0F; p++; |
| 458 | 706 | *p = data & 0x0F; p++; |
| 707 | *p = data & 0x0F; p++; |
| 708 | *p = data & 0x0F; p++; |
| 459 | 709 | |
| 460 | 710 | data = videoram[ offset + 1 ]; |
| 461 | 711 | |
| 712 | if ( NTSC_FILTER ) { |
| 713 | samples[samp_index] = yc_lut2[yc_lut[data>>4][0]]; samp_index++; |
| 714 | samples[samp_index] = yc_lut2[yc_lut[data>>4][1]]; samp_index++; |
| 715 | samples[samp_index] = yc_lut2[yc_lut[data>>4][2]]; samp_index++; |
| 716 | samples[samp_index] = yc_lut2[yc_lut[data>>4][3]]; samp_index++; |
| 717 | samples[samp_index] = yc_lut2[yc_lut[data>>4][4]]; samp_index++; |
| 718 | samples[samp_index] = yc_lut2[yc_lut[data>>4][5]]; samp_index++; |
| 719 | samples[samp_index] = yc_lut2[yc_lut[data>>4][6]]; samp_index++; |
| 720 | samples[samp_index] = yc_lut2[yc_lut[data>>4][7]]; samp_index++; |
| 721 | |
| 722 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][0]]; samp_index++; |
| 723 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][1]]; samp_index++; |
| 724 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][2]]; samp_index++; |
| 725 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][3]]; samp_index++; |
| 726 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][4]]; samp_index++; |
| 727 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][5]]; samp_index++; |
| 728 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][6]]; samp_index++; |
| 729 | samples[samp_index] = yc_lut2[yc_lut[data & 0x0F][7]]; samp_index++; |
| 730 | } |
| 731 | |
| 462 | 732 | *p = data >> 4; p++; |
| 463 | 733 | *p = data >> 4; p++; |
| 734 | *p = data >> 4; p++; |
| 735 | *p = data >> 4; p++; |
| 464 | 736 | *p = data & 0x0F; p++; |
| 465 | 737 | *p = data & 0x0F; p++; |
| 738 | *p = data & 0x0F; p++; |
| 739 | *p = data & 0x0F; p++; |
| 466 | 740 | } |
| 741 | if (NTSC_FILTER) { |
| 742 | ntsc_decode( &ntsc, samples, ntsc_decoded, 160 ); |
| 743 | p = BITMAP_ADDR16(bitmap, y, 0); |
| 744 | samp_index = 0; |
| 745 | for ( i = 0; i < ( 8 * x_count ); i++ ) { |
| 746 | int r = ( ntsc_decoded[samp_index] + ntsc_decoded[samp_index+3] ) / 2; |
| 747 | int g = ( ntsc_decoded[samp_index+1] + ntsc_decoded[samp_index+4] ) / 2; |
| 748 | int b = ( ntsc_decoded[samp_index+2] + ntsc_decoded[samp_index+5] ) / 2; |
| 749 | *p = 0x8000 + ( ( ( r & 0xF8 ) << 7 ) | ( ( g & 0xF8 ) << 2 ) | ( ( b & 0xF8 ) >> 3 ) ); |
| 750 | p++; |
| 751 | samp_index +=6; |
| 752 | } |
| 467 | 753 | } |
| 754 | } |
| 468 | 755 | |
| 469 | 756 | |
| 470 | 757 | /*************************************************************************** |
| r2103 | r2104 | |
| 498 | 785 | |
| 499 | 786 | |
| 500 | 787 | /*************************************************************************** |
| 788 | Draw graphics mode with 320x200 pixels (default) with 2 bits/pixel. |
| 789 | Even scanlines are from CGA_base + 0x0000, odd from CGA_base + 0x2000 |
| 790 | cga fetches 2 byte per mscrtc6845 access. |
| 791 | ***************************************************************************/ |
| 792 | |
| 793 | static MC6845_UPDATE_ROW( cga_gfx_2bpph_update_row ) { |
| 794 | UINT16 *p = BITMAP_ADDR16(bitmap, y, 0); |
| 795 | int i; |
| 796 | |
| 797 | // if ( y == 0 ) logerror("cga_gfx_2bpph_update_row\n"); |
| 798 | for ( i = 0; i < x_count; i++ ) { |
| 799 | UINT16 offset = ( ( ( ma + i ) << 1 ) & 0x1fff ) | ( ( y & 1 ) << 13 ); |
| 800 | UINT8 data = videoram[ offset ]; |
| 801 | |
| 802 | *p = cga.palette_lut_2bpp[ ( data >> 6 ) & 0x03 ]; p++; |
| 803 | *p = cga.palette_lut_2bpp[ ( data >> 6 ) & 0x03 ]; p++; |
| 804 | *p = cga.palette_lut_2bpp[ ( data >> 4 ) & 0x03 ]; p++; |
| 805 | *p = cga.palette_lut_2bpp[ ( data >> 4 ) & 0x03 ]; p++; |
| 806 | *p = cga.palette_lut_2bpp[ ( data >> 2 ) & 0x03 ]; p++; |
| 807 | *p = cga.palette_lut_2bpp[ ( data >> 2 ) & 0x03 ]; p++; |
| 808 | *p = cga.palette_lut_2bpp[ data & 0x03 ]; p++; |
| 809 | *p = cga.palette_lut_2bpp[ data & 0x03 ]; p++; |
| 810 | |
| 811 | data = videoram[ offset+1 ]; |
| 812 | |
| 813 | *p = cga.palette_lut_2bpp[ ( data >> 6 ) & 0x03 ]; p++; |
| 814 | *p = cga.palette_lut_2bpp[ ( data >> 6 ) & 0x03 ]; p++; |
| 815 | *p = cga.palette_lut_2bpp[ ( data >> 4 ) & 0x03 ]; p++; |
| 816 | *p = cga.palette_lut_2bpp[ ( data >> 4 ) & 0x03 ]; p++; |
| 817 | *p = cga.palette_lut_2bpp[ ( data >> 2 ) & 0x03 ]; p++; |
| 818 | *p = cga.palette_lut_2bpp[ ( data >> 2 ) & 0x03 ]; p++; |
| 819 | *p = cga.palette_lut_2bpp[ data & 0x03 ]; p++; |
| 820 | *p = cga.palette_lut_2bpp[ data & 0x03 ]; p++; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /*************************************************************************** |
| 501 | 825 | Draw graphics mode with 640x200 pixels (default). |
| 502 | 826 | The cell size is 1x1 (1 scanline is the real default) |
| 503 | 827 | Even scanlines are from CGA_base + 0x0000, odd from CGA_base + 0x2000 |
| r2103 | r2104 | |
| 594 | 918 | * x x x 0 1 1 1 1 - unknown/invalid. |
| 595 | 919 | * x x x 1 1 0 0 0 - unknown/invalid. |
| 596 | 920 | * x x x 1 1 0 0 1 - unknown/invalid. |
| 597 | | * x x x 1 1 0 1 0 - 160x200/640x200 graphics. 640x200 on RGB monitor, 160x200 on composite monitor. |
| 921 | * x x x 1 1 0 1 0 - 160x200/640x200 graphics. 640x200 ?? on RGB monitor, 160x200 on composite monitor. |
| 598 | 922 | * x x x 1 1 0 1 1 - unknown/invalid. |
| 599 | 923 | * x x x 1 1 1 0 0 - unknown/invalid. |
| 600 | 924 | * x x x 1 1 1 0 1 - unknown/invalid. |
| r2103 | r2104 | |
| 604 | 928 | static void pc_cga_mode_control_w(running_machine *machine, int data) |
| 605 | 929 | { |
| 606 | 930 | device_config *devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, CGA_MC6845_NAME); |
| 607 | | unsigned char mask = 0x3B; |
| 608 | 931 | |
| 609 | 932 | CGA_LOG(1,"CGA_mode_control_w",("$%02x: columns %d, gfx %d, hires %d, blink %d\n", |
| 610 | 933 | data, (data&1)?80:40, (data>>1)&1, (data>>4)&1, (data>>5)&1)); |
| 611 | 934 | |
| 612 | | /* CGA composite: Switching between mono & colour behaves like a |
| 613 | | * mode change */ |
| 614 | | if(CGA_MONITOR == CGA_MONITOR_COMPOSITE) mask = 0x3F; |
| 615 | 935 | cga.mode_control = data; |
| 616 | 936 | |
| 617 | 937 | //logerror("mode set to %02X\n", cga.mode_control & 0x3F ); |
| 618 | 938 | switch ( cga.mode_control & 0x3F ) { |
| 619 | 939 | case 0x08: case 0x09: case 0x0C: case 0x0D: |
| 620 | 940 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 621 | | cga.update_row = cga_text_inten_update_row; |
| 941 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 942 | if ( cga.mode_control & 0x04 ) { |
| 943 | /* Composite greyscale */ |
| 944 | cga.update_row = cga_text_inten_comp_grey_update_row; |
| 945 | } else { |
| 946 | /* Composite colour */ |
| 947 | cga.update_row = cga_text_inten_update_row; |
| 948 | } |
| 949 | } else { |
| 950 | /* RGB colour */ |
| 951 | cga.update_row = cga_text_inten_update_row; |
| 952 | } |
| 622 | 953 | break; |
| 623 | 954 | case 0x0A: case 0x0B: case 0x2A: case 0x2B: |
| 624 | 955 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| r2103 | r2104 | |
| 637 | 968 | cga.update_row = cga_text_inten_alt_update_row; |
| 638 | 969 | break; |
| 639 | 970 | case 0x1A: case 0x1B: case 0x3A: case 0x3B: |
| 640 | | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 971 | mc6845_set_hpixels_per_column( devconf, 16 ); |
| 641 | 972 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 642 | 973 | cga.update_row = cga_gfx_4bpph_update_row; |
| 643 | 974 | } else { |
| 644 | | cga.update_row = cga_gfx_2bpp_update_row; |
| 975 | cga.update_row = cga_gfx_2bpph_update_row; |
| 645 | 976 | } |
| 646 | 977 | break; |
| 647 | 978 | case 0x1E: case 0x1F: case 0x3E: case 0x3F: |
| r2103 | r2104 | |
| 650 | 981 | break; |
| 651 | 982 | case 0x28: case 0x29: case 0x2C: case 0x2D: |
| 652 | 983 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 653 | | cga.update_row = cga_text_blink_update_row; |
| 984 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 985 | if ( cga.mode_control & 0x04 ) { |
| 986 | /* Composite greyscale */ |
| 987 | cga.update_row = cga_text_blink_update_row; |
| 988 | } else { |
| 989 | /* Composite colour */ |
| 990 | cga.update_row = cga_text_blink_update_row; |
| 991 | } |
| 992 | } else { |
| 993 | /* RGB colour */ |
| 994 | cga.update_row = cga_text_blink_update_row; |
| 995 | } |
| 654 | 996 | break; |
| 655 | 997 | case 0x38: case 0x39: case 0x3C: case 0x3D: |
| 656 | 998 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| r2103 | r2104 | |
| 991 | 1333 | |
| 992 | 1334 | static WRITE8_HANDLER ( pc1512_w ) |
| 993 | 1335 | { |
| 994 | | device_config *devconf; |
| 1336 | device_config *devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, CGA_MC6845_NAME); |
| 995 | 1337 | |
| 996 | 1338 | switch (offset) { |
| 997 | 1339 | case 0: case 2: case 4: case 6: |
| 998 | | devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, CGA_MC6845_NAME); |
| 999 | 1340 | data &= 0x1F; |
| 1000 | 1341 | mc6845_address_w( devconf, offset, data ); |
| 1001 | 1342 | pc1512.mc6845_address = data; |
| 1002 | 1343 | break; |
| 1003 | 1344 | |
| 1004 | 1345 | case 1: case 3: case 5: case 7: |
| 1005 | | devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, CGA_MC6845_NAME); |
| 1006 | 1346 | if ( ! pc1512.mc6845_locked_register[pc1512.mc6845_address] ) { |
| 1007 | 1347 | mc6845_register_w( devconf, offset, data ); |
| 1008 | 1348 | if ( mc6845_writeonce_register[pc1512.mc6845_address] ) { |
| r2103 | r2104 | |
| 1021 | 1361 | cga.mode_control = data; |
| 1022 | 1362 | switch( cga.mode_control & 0x3F ) { |
| 1023 | 1363 | case 0x08: case 0x09: case 0x0C: case 0x0D: |
| 1364 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1024 | 1365 | cga.update_row = cga_text_inten_update_row; |
| 1025 | 1366 | break; |
| 1026 | 1367 | case 0x0A: case 0x0B: case 0x2A: case 0x2B: |
| 1368 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1027 | 1369 | if ( CGA_MONITOR == CGA_MONITOR_COMPOSITE ) { |
| 1028 | 1370 | cga.update_row = cga_gfx_4bppl_update_row; |
| 1029 | 1371 | } else { |
| r2103 | r2104 | |
| 1031 | 1373 | } |
| 1032 | 1374 | break; |
| 1033 | 1375 | case 0x0E: case 0x0F: case 0x2E: case 0x2F: |
| 1376 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1034 | 1377 | cga.update_row = cga_gfx_2bpp_update_row; |
| 1035 | 1378 | break; |
| 1036 | 1379 | case 0x18: case 0x19: case 0x1C: case 0x1D: |
| 1380 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1037 | 1381 | cga.update_row = cga_text_inten_alt_update_row; |
| 1038 | 1382 | break; |
| 1039 | 1383 | case 0x1A: case 0x1B: case 0x3A: case 0x3B: |
| 1384 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1040 | 1385 | cga.update_row = pc1512_gfx_4bpp_update_row; |
| 1041 | 1386 | break; |
| 1042 | 1387 | case 0x1E: case 0x1F: case 0x3E: case 0x3F: |
| 1388 | mc6845_set_hpixels_per_column( devconf, 16 ); |
| 1043 | 1389 | cga.update_row = cga_gfx_1bpp_update_row; |
| 1044 | 1390 | break; |
| 1045 | 1391 | case 0x28: case 0x29: case 0x2C: case 0x2D: |
| 1392 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1046 | 1393 | cga.update_row = cga_text_blink_update_row; |
| 1047 | 1394 | break; |
| 1048 | 1395 | case 0x38: case 0x39: case 0x3C: case 0x3D: |
| 1396 | mc6845_set_hpixels_per_column( devconf, 8 ); |
| 1049 | 1397 | cga.update_row = cga_text_blink_alt_update_row; |
| 1050 | 1398 | break; |
| 1051 | 1399 | default: |