90
91
***************************************************************************/
92
unsigned char cga_palette[16 * CGA_PALETTE_SETS][3] =
93
/* In cgapal.c; it's quite big */
94
extern unsigned char cga_palette[16 * CGA_PALETTE_SETS][3];
133
97
unsigned short cga_colortable[] =
135
100
0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0,10, 0,11, 0,12, 0,13, 0,14, 0,15,
136
101
1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1,10, 1,11, 1,12, 1,13, 1,14, 1,15,
137
102
2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2,10, 2,11, 2,12, 2,13, 2,14, 2,15,
153
118
0,0, 0,1, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7,
154
119
0,8, 0,9, 0,10, 0,11, 0,12, 0,13, 0,14, 0,15,
155
120
/* the color sets for 2bpp graphics mode. There are 32*3 = 96 of these,
156
* though only the first 64 apply on a real CGA. */
121
* though only the first 64 are documented. */
157
122
/* Red/Green/Yellow set */
158
123
0, 2, 4, 6, 1, 2, 4, 6, 2, 2, 4, 6, 3, 2, 4, 6,
159
124
4, 2, 4, 6, 5, 2, 4, 6, 6, 2, 4, 6, 7, 2, 4, 6,
172
137
4,11,13,15, 5,11,13,15, 6,11,13,15, 7,11,13,15,
173
138
8,11,13,15, 9,11,13,15, 10,11,13,15, 11,11,13,15,
174
139
12,11,13,15, 13,11,13,15, 14,11,13,15, 15,11,13,15,
175
/* Red/Cyan/White set (PC1512 only) */
140
/* Red/Cyan/White set (undocumented) */
176
141
0, 3, 4, 7, 1, 3, 4, 7, 2, 3, 4, 7, 3, 3, 4, 7,
177
142
4, 3, 4, 7, 5, 3, 4, 7, 6, 3, 4, 7, 7, 3, 4, 7,
178
143
8, 3, 4, 7, 9, 3, 4, 7, 10, 3, 4, 7, 11, 3, 4, 7,
183
148
12,11,12,15, 13,11,12,15, 14,11,12,15, 15,11,12,15,
186
struct GfxLayout CGA_charlayout =
151
gfx_layout CGA_charlayout =
188
153
8,16, /* 8 x 16 characters */
189
256, /* 256 characters */
190
1, /* 1 bits per pixel */
191
{ 0 }, /* no bitplanes; 1 bit per pixel */
154
256, /* 256 characters */
155
1, /* 1 bits per pixel */
156
{ 0 }, /* no bitplanes; 1 bit per pixel */
195
160
{ 0*8,1*8,2*8,3*8,
199
8*8 /* every char takes 8 bytes */
164
8*8 /* every char takes 8 bytes */
202
static struct GfxDecodeInfo CGA_gfxdecodeinfo[] =
167
static gfx_decode CGA_gfxdecodeinfo[] =
204
169
/* Support up to four CGA fonts */
205
{ 1, 0x0000, &CGA_charlayout, 0, 256 }, /* Font 0 */
206
{ 1, 0x0800, &CGA_charlayout, 0, 256 }, /* Font 1 */
207
{ 1, 0x1000, &CGA_charlayout, 0, 256 }, /* Font 2 */
208
{ 1, 0x1800, &CGA_charlayout, 0, 256 }, /* Font 3*/
170
{ REGION_GFX1, 0x0000, &CGA_charlayout, 0, 256 }, /* Font 0 */
171
{ REGION_GFX1, 0x0800, &CGA_charlayout, 0, 256 }, /* Font 1 */
172
{ REGION_GFX1, 0x1000, &CGA_charlayout, 0, 256 }, /* Font 2 */
173
{ REGION_GFX1, 0x1800, &CGA_charlayout, 0, 256 }, /* Font 3*/
209
174
{ -1 } /* end of array */
307
272
if (!pc_video_start(&config, pc_cga_choosevideomode, 0x8000))
310
state_save_register_UINT8("pccga", 0, "mode_control", &cga.mode_control, 1);
311
state_save_register_UINT8("pccga", 0, "color_select", &cga.color_select, 1);
312
state_save_register_UINT8("pccga", 0, "status", &cga.status, 1);
313
state_save_register_UINT8("pccga", 0, "plantronics", &cga.plantronics, 1);
275
state_save_register_item("pccga", 0, cga.mode_control);
276
state_save_register_item("pccga", 0, cga.color_select);
277
state_save_register_item("pccga", 0, cga.status);
278
state_save_register_item("pccga", 0, cga.plantronics);
315
280
timer_pulse(TIME_IN_SEC(32.0/240.0), 0, cga_timerproc);
325
290
/* Changed video RAM size to full 32k, for cards which support the
326
* Plantronics chipset */
291
* Plantronics chipset.
292
* TODO: Cards which don't support Plantronics should repeat at
327
294
buswidth = cputype_databus_width(Machine->drv->cpu[0].cpu_type, ADDRESS_SPACE_PROGRAM);
330
memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, MRA8_RAM );
331
memory_install_write8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, pc_video_videoram_w );
332
memory_install_read8_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga8_r );
333
memory_install_write8_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga8_w );
337
memory_install_read32_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, MRA32_RAM );
338
memory_install_write32_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, pc_video_videoram32_w );
339
memory_install_read32_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga32_r );
340
memory_install_write32_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga32_w );
344
osd_die("CGA: Bus width %d not supported\n", buswidth);
298
memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, MRA8_BANK11 );
299
memory_install_write8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, pc_video_videoram_w );
300
memory_install_read8_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga8_r );
301
memory_install_write8_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga8_w );
305
memory_install_read32_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, MRA32_BANK11 );
306
memory_install_write32_handler(0, ADDRESS_SPACE_PROGRAM, 0xb8000, 0xbffff, 0, 0, pc_video_videoram32_w );
307
memory_install_read32_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga32_r );
308
memory_install_write32_handler(0, ADDRESS_SPACE_IO, 0x3d0, 0x3df, 0, 0, pc_cga32_w );
312
fatalerror("CGA: Bus width %d not supported\n", buswidth);
348
videoram = memory_region(REGION_CPU1)+0xb8000;
349
videoram_size = 0x4000;
316
if (videoram_size == 0)
317
videoram_size = 0x8000;
319
videoram = auto_malloc(videoram_size);
320
memory_set_bankptr(11, videoram);
350
322
return internal_pc_cga_video_start(M6845_PERSONALITY_GENUINE);
355
327
static void pc_cga_check_palette(void)
329
int i, p = 0; /* RGB palette */
359
331
switch(CGA_MONITOR)
361
333
case CGA_MONITOR_COMPOSITE:
362
334
if (cga.mode_control & 4)
336
p = 1; /* Greyscale palette */
338
else if (cga.mode_control & 2) /* Graphics mode */
340
if (cga.mode_control & 0x10) /* Hi-Res */
342
p = (cga.color_select & 0x0F) + 0x03;
346
p = (cga.color_select & 0x3F) + 0x13;
352
p = 2; /* Text-mode colour palette */
365
355
case CGA_MONITOR_MONO:
366
356
case CGA_MONITOR_LCD:
357
p = 1; /* Greyscale palette */
370
362
if (p != cga.palette)
372
364
for(i = 0; i < (sizeof(cga_palette) / (3 * CGA_PALETTE_SETS)); i++)
387
379
static void pc_cga_mode_control_w(int data)
381
unsigned char mask = 0x3B;
389
383
CGA_LOG(1,"CGA_mode_control_w",(errorlog, "$%02x: columns %d, gfx %d, hires %d, blink %d\n",
390
384
data, (data&1)?80:40, (data>>1)&1, (data>>4)&1, (data>>5)&1));
392
if ((cga.mode_control ^ data) & 0x3b) /* text/gfx/width change */
386
/* CGA composite: Switching between mono & colour behaves like a
388
if(CGA_MONITOR == CGA_MONITOR_COMPOSITE) mask = 0x3F;
390
if ((cga.mode_control ^ data) & mask) /* text/gfx/width change */
394
392
schedule_full_refresh();
395
393
if (dirtybuffer) memset(dirtybuffer, 1, videoram_size);
587
585
The character cell size is 16x8
588
586
***************************************************************************/
590
static void cga_text_inten_alt(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
588
static void cga_text_inten_alt(mame_bitmap *bitmap, struct crtc6845 *crtc)
593
591
int offs = crtc6845_get_start(crtc) * 2;
594
592
int lines = crtc6845_get_char_lines(crtc);
595
593
int height = crtc6845_get_char_height(crtc);
596
594
int columns = crtc6845_get_char_columns(crtc);
598
596
struct crtc6845_cursor cursor;
600
598
if (CGA_CHIPSET != CGA_CHIPSET_PC200)
642
640
Draw text mode with 40x25 characters (default) and blinking colors.
643
641
The character cell size is 16x8
644
642
***************************************************************************/
645
static void cga_text_blink(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
643
static void cga_text_blink(mame_bitmap *bitmap, struct crtc6845 *crtc)
648
646
int offs = crtc6845_get_start(crtc)*2;
649
647
int lines = crtc6845_get_char_lines(crtc);
650
648
int height = crtc6845_get_char_height(crtc);
651
649
int columns = crtc6845_get_char_columns(crtc);
653
651
struct crtc6845_cursor cursor;
655
653
crtc6845_time(crtc);
714
712
The character cell size is 16x8
715
713
***************************************************************************/
717
static void cga_text_blink_alt(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
715
static void cga_text_blink_alt(mame_bitmap *bitmap, struct crtc6845 *crtc)
720
718
int offs = crtc6845_get_start(crtc)*2;
721
719
int lines = crtc6845_get_char_lines(crtc);
722
720
int height = crtc6845_get_char_height(crtc);
723
721
int columns = crtc6845_get_char_columns(crtc);
725
723
struct crtc6845_cursor cursor;
727
725
if (CGA_CHIPSET != CGA_CHIPSET_PC200)
783
781
cga fetches 2 byte per crtc6845 access (not modeled here)!
784
782
***************************************************************************/
786
static void cga_gfx_2bpp(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
784
static void cga_gfx_2bpp(mame_bitmap *bitmap, struct crtc6845 *crtc)
788
786
const UINT16 *palette;
789
787
int colorset = cga.color_select & 0x3F;
791
/* Many clone chipsets use bit 2 of the mode control register to
792
* access a third palette */
789
/* Most chipsets use bit 2 of the mode control register to
790
* access a third palette. But not consistently. */
793
791
pc_cga_check_palette();
794
792
switch(CGA_CHIPSET)
794
/* The IBM Professional Graphics Controller behaves like
795
* the PC1512, btw. */
796
796
case CGA_CHIPSET_PC1512:
797
797
if ((colorset < 32) && (cga.mode_control & 4)) colorset += 64;
800
case CGA_CHIPSET_IBM:
800
801
case CGA_CHIPSET_PC200:
801
802
case CGA_CHIPSET_ATI:
802
803
case CGA_CHIPSET_PARADISE:
841
INLINE void pgfx_plot_unit_4bpp(struct mame_bitmap *bitmap,
842
INLINE void cga_plot_unit_4bpp(mame_bitmap *bitmap,
843
int x, int y, int offs, int scale)
848
color = (videoram[offs] & 0xF0) >> 4;
849
for (i = 0; i < scale; i++) plot_pixel(bitmap, x++, y, Machine->pens[color]);
850
color = videoram[offs] & 0x0F;
851
for (i = 0; i < scale; i++) plot_pixel(bitmap, x++, y, Machine->pens[color]);
855
static void cga_gfx_4bpp(mame_bitmap *bitmap, struct crtc6845 *crtc, int scale)
858
int offs = crtc6845_get_start(crtc)*2;
859
int lines = crtc6845_get_char_lines(crtc);
860
int height = crtc6845_get_char_height(crtc);
861
int columns = crtc6845_get_char_columns(crtc)*2;
863
pc_cga_check_palette();
865
for (sy=0; sy<lines; sy++,offs=(offs+columns)&0x1fff)
867
for (sh=0; sh<height; sh++, offs|=0x2000)
869
/* char line 0 used as a12 line in graphic mode */
872
for (i=offs, sx=0; sx<columns; sx++, i=(i+1)&0x1fff)
874
if (!dirtybuffer || dirtybuffer[i])
876
cga_plot_unit_4bpp(bitmap, sx*scale, sy*height+sh, i, scale/2);
884
for (i=offs|0x2000, sx=0; sx<columns; sx++, i=((i+1)&0x1fff)|0x2000)
886
if (!dirtybuffer || dirtybuffer[i])
888
cga_plot_unit_4bpp(bitmap, sx*scale, sy*height+sh, i, scale/2);
899
/* The hi-res graphics mode on a colour composite monitor
901
* The different scaling factors mean that the '160x200' versions of screens
902
* are the same size as the normal colour ones.
904
static void cga_gfx_4bpph(mame_bitmap *bitmap, struct crtc6845 *crtc)
906
pc_cga_check_palette();
907
cga_gfx_4bpp(bitmap, crtc, 8);
911
/* The lo-res graphics mode on a colour composite monitor */
912
static void cga_gfx_4bppl(mame_bitmap *bitmap, struct crtc6845 *crtc)
914
pc_cga_check_palette();
915
cga_gfx_4bpp(bitmap, crtc, 4);
921
INLINE void pgfx_plot_unit_4bpp(mame_bitmap *bitmap,
842
922
int x, int y, int offs)
844
924
int color, values[2];
1166
1249
static const pc_video_update_proc videoprocs_cga[] =
1168
1251
/* 0x08 - 0x0f */
1169
cga_text_inten, cga_text_inten, cga_gfx_2bpp, cga_gfx_2bpp,
1252
cga_text_inten, cga_text_inten, cga_gfx_4bppl, cga_gfx_4bppl,
1170
1253
cga_text_inten, cga_text_inten, cga_gfx_2bpp, cga_gfx_2bpp,
1172
1255
/* 0x18 - 0x1f */
1173
cga_text_inten_alt, cga_text_inten_alt, cga_gfx_1bpp, cga_gfx_1bpp,
1256
cga_text_inten_alt, cga_text_inten_alt, cga_gfx_4bpph, cga_gfx_4bpph,
1174
1257
cga_text_inten_alt, cga_text_inten_alt, cga_gfx_1bpp, cga_gfx_1bpp,
1176
1259
/* 0x28 - 0x2f */
1177
cga_text_blink, cga_text_blink, cga_gfx_2bpp, cga_gfx_2bpp,
1260
cga_text_blink, cga_text_blink, cga_gfx_4bppl, cga_gfx_4bppl,
1178
1261
cga_text_blink, cga_text_blink, cga_gfx_2bpp, cga_gfx_2bpp,
1180
1263
/* 0x38 - 0x3f */
1181
cga_text_blink_alt, cga_text_blink_alt, cga_gfx_1bpp, cga_gfx_1bpp,
1264
cga_text_blink_alt, cga_text_blink_alt, cga_gfx_4bpph, cga_gfx_4bpph,
1182
1265
cga_text_blink_alt, cga_text_blink_alt, cga_gfx_1bpp, cga_gfx_1bpp,