~ubuntu-branches/ubuntu/karmic/xmame/karmic

« back to all changes in this revision

Viewing changes to mess/vidhrdw/pc_cga.c

  • Committer: Bazaar Package Importer
  • Author(s): Bruno Barrera C.
  • Date: 2007-02-16 10:06:54 UTC
  • mfrom: (2.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20070216100654-iztas2cl47k5j039
Tags: 0.106-2
* Added Italian debconf templates translation. (closes: #382672)
* Added German debconf templates translation. (closes: #396610)
* Added Japanese debconf templates translation. (closes: #400011)
* Added Portuguese debconf templates translation. (closes: #409960)

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include "state.h"
53
53
 
54
54
#include "includes/crtc6845.h"
55
 
#include "includes/pc_cga.h"
56
 
#include "includes/pc_video.h"
 
55
#include "vidhrdw/pc_cga.h"
 
56
#include "vidhrdw/pc_video.h"
57
57
#include "mscommon.h"
 
58
#include "memconv.h"
58
59
 
59
60
#define VERBOSE_CGA 0           /* CGA (Color Graphics Adapter) */
60
61
 
89
90
 
90
91
***************************************************************************/
91
92
 
92
 
unsigned char cga_palette[16 * CGA_PALETTE_SETS][3] =
93
 
{
94
 
/*  normal colors */
95
 
    { 0x00,0x00,0x00 },
96
 
    { 0x00,0x00,0xaa },
97
 
    { 0x00,0xaa,0x00 },
98
 
    { 0x00,0xaa,0xaa },
99
 
    { 0xaa,0x00,0x00 },
100
 
    { 0xaa,0x00,0xaa },
101
 
    { 0xaa,0x55,0x00 },
102
 
    { 0xaa,0xaa,0xaa },
103
 
/*  light colors */
104
 
    { 0x55,0x55,0x55 },
105
 
    { 0x55,0x55,0xff },
106
 
    { 0x55,0xff,0x55 },
107
 
    { 0x55,0xff,0xff },
108
 
    { 0xff,0x55,0x55 },
109
 
    { 0xff,0x55,0xff },
110
 
    { 0xff,0xff,0x55 },
111
 
        { 0xff,0xff,0xff },
112
 
/*  normal greys */
113
 
    { 0x00,0x00,0x00 },
114
 
        { 0x11,0x11,0x11 }, 
115
 
        { 0x44,0x44,0x44 }, 
116
 
        { 0x55,0x55,0x55 },
117
 
    { 0x22,0x22,0x22 }, 
118
 
        { 0x33,0x33,0x33 }, 
119
 
        { 0x66,0x66,0x66 }, 
120
 
        { 0x77,0x77,0x77 },
121
 
/*  light greys */
122
 
    { 0x88,0x88,0x88 }, 
123
 
        { 0x99,0x99,0x99 }, 
124
 
        { 0xcc,0xcc,0xcc }, 
125
 
        { 0xdd,0xdd,0xdd },
126
 
    { 0xaa,0xaa,0xaa }, 
127
 
        { 0xbb,0xbb,0xbb }, 
128
 
        { 0xee,0xee,0xee }, 
129
 
        { 0xff,0xff,0xff }
130
 
};
 
93
/* In cgapal.c; it's quite big */
 
94
extern unsigned char cga_palette[16 * CGA_PALETTE_SETS][3];
131
95
 
132
96
 
133
97
unsigned short cga_colortable[] =
134
98
{
 
99
/* Text modes */
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,
184
149
};
185
150
 
186
 
struct GfxLayout CGA_charlayout =
 
151
gfx_layout CGA_charlayout =
187
152
{
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 */
192
 
    /* x offsets */
193
 
    { 0,1,2,3,4,5,6,7 },
194
 
    /* y offsets */
 
154
        256,                    /* 256 characters */
 
155
        1,                      /* 1 bits per pixel */
 
156
        { 0 },                  /* no bitplanes; 1 bit per pixel */
 
157
        /* x offsets */
 
158
        { 0,1,2,3,4,5,6,7 },
 
159
        /* y offsets */
195
160
        { 0*8,1*8,2*8,3*8,
196
 
          4*8,5*8,6*8,7*8,
197
 
          0*8,1*8,2*8,3*8,
198
 
          4*8,5*8,6*8,7*8 },
199
 
    8*8                     /* every char takes 8 bytes */
 
161
                4*8,5*8,6*8,7*8,
 
162
                0*8,1*8,2*8,3*8,
 
163
                4*8,5*8,6*8,7*8 },
 
164
        8*8                     /* every char takes 8 bytes */
200
165
};
201
166
 
202
 
static struct GfxDecodeInfo CGA_gfxdecodeinfo[] =
 
167
static gfx_decode CGA_gfxdecodeinfo[] =
203
168
{
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 */
210
175
};
211
176
 
307
272
        if (!pc_video_start(&config, pc_cga_choosevideomode, 0x8000))
308
273
                return 1;
309
274
 
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);
314
279
 
315
280
        timer_pulse(TIME_IN_SEC(32.0/240.0), 0, cga_timerproc);
316
281
        return 0;
323
288
        int buswidth;
324
289
 
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 
 
293
         * BC000h */
327
294
        buswidth = cputype_databus_width(Machine->drv->cpu[0].cpu_type, ADDRESS_SPACE_PROGRAM);
328
 
        switch(buswidth) {
329
 
        case 8:
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 );
334
 
                break;
335
 
 
336
 
        case 32:
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 );
341
 
                break;
342
 
 
343
 
        default:
344
 
                osd_die("CGA:  Bus width %d not supported\n", buswidth);
345
 
                break;
 
295
        switch(buswidth)
 
296
        {
 
297
                case 8:
 
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 );
 
302
                        break;
 
303
 
 
304
                case 32:
 
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 );
 
309
                        break;
 
310
 
 
311
                default:
 
312
                        fatalerror("CGA:  Bus width %d not supported\n", buswidth);
 
313
                        break;
346
314
        }
347
315
 
348
 
        videoram = memory_region(REGION_CPU1)+0xb8000;
349
 
        videoram_size = 0x4000;
 
316
        if (videoram_size == 0)
 
317
                videoram_size = 0x8000;
 
318
        if (!videoram)
 
319
                videoram = auto_malloc(videoram_size);
 
320
        memory_set_bankptr(11, videoram);
 
321
 
350
322
        return internal_pc_cga_video_start(M6845_PERSONALITY_GENUINE);
351
323
}
352
324
 
354
326
 
355
327
static void pc_cga_check_palette(void)
356
328
{
357
 
        int i, p = 0;
 
329
        int i, p = 0;   /* RGB palette */
358
330
 
359
331
        switch(CGA_MONITOR)
360
332
        {
361
333
                case CGA_MONITOR_COMPOSITE: 
362
334
                        if (cga.mode_control & 4)
363
 
                                p = 16;
 
335
                        {
 
336
                                p = 1;  /* Greyscale palette */
 
337
                        }
 
338
                        else if (cga.mode_control & 2) /* Graphics mode */
 
339
                        {
 
340
                                if (cga.mode_control & 0x10) /* Hi-Res */
 
341
                                {
 
342
                                        p = (cga.color_select & 0x0F) + 0x03;
 
343
                                }
 
344
                                else    /* Lo-Res */
 
345
                                {
 
346
                                        p = (cga.color_select & 0x3F) + 0x13;
 
347
                                }
 
348
 
 
349
                        }
 
350
                        else
 
351
                        {
 
352
                                p = 2;  /* Text-mode colour palette */
 
353
                        }
364
354
                        break;
365
355
                case CGA_MONITOR_MONO:
366
356
                case CGA_MONITOR_LCD:
367
 
                        p = 16;
 
357
                        p = 1;          /* Greyscale palette */
368
358
                        break;
369
359
        }
 
360
        p *= 16;
 
361
 
370
362
        if (p != cga.palette)
371
363
        {
372
364
                for(i = 0; i < (sizeof(cga_palette) / (3 * CGA_PALETTE_SETS)); i++)
386
378
 */
387
379
static void pc_cga_mode_control_w(int data)
388
380
{
 
381
        unsigned char mask = 0x3B;
 
382
 
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));
391
385
 
392
 
        if ((cga.mode_control ^ data) & 0x3b)    /* text/gfx/width change */
 
386
        /* CGA composite: Switching between mono & colour behaves like a 
 
387
         * mode change */
 
388
        if(CGA_MONITOR == CGA_MONITOR_COMPOSITE) mask = 0x3F;
 
389
 
 
390
        if ((cga.mode_control ^ data) & mask)    /* text/gfx/width change */
393
391
        {
394
392
                schedule_full_refresh();
395
393
                if (dirtybuffer) memset(dirtybuffer, 1, videoram_size);
510
508
 
511
509
READ32_HANDLER( pc_cga32_r )
512
510
{
513
 
        return read32_with_read8_handler(pc_cga8_r, offset, mem_mask);
 
511
        return read32le_with_read8_handler(pc_cga8_r, offset, mem_mask);
514
512
}
515
513
 
516
514
 
517
515
 
518
516
WRITE32_HANDLER( pc_cga32_w )
519
517
{
520
 
        write32_with_write8_handler(pc_cga8_w, offset, data, mem_mask);
 
518
        write32le_with_write8_handler(pc_cga8_w, offset, data, mem_mask);
521
519
}
522
520
 
523
521
 
527
525
  The character cell size is 16x8
528
526
***************************************************************************/
529
527
 
530
 
static void cga_text_inten(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
 
528
static void cga_text_inten(mame_bitmap *bitmap, struct crtc6845 *crtc)
531
529
{
532
530
        int sx, sy;
533
531
        int     offs = crtc6845_get_start(crtc) * 2;
534
532
        int lines = crtc6845_get_char_lines(crtc);
535
533
        int height = crtc6845_get_char_height(crtc);
536
534
        int columns = crtc6845_get_char_columns(crtc);
537
 
        struct rectangle r;
 
535
        rectangle r;
538
536
        struct crtc6845_cursor cursor;
539
537
 
540
538
        crtc6845_time(crtc);
543
541
 
544
542
        for (sy=0, r.min_y=0, r.max_y=height-1; sy<lines; sy++, r.min_y+=height,r.max_y+=height)
545
543
        {
546
 
                if (r.min_y >= Machine->scrbitmap->height)
 
544
                if (r.min_y >= Machine->drv->screen_height)
547
545
                        break;
548
546
                for (sx=0, r.min_x=0, r.max_x=7; sx<columns; 
549
547
                         sx++, offs=(offs+2)&0x3fff, r.min_x+=8, r.max_x+=8)
587
585
  The character cell size is 16x8
588
586
***************************************************************************/
589
587
 
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)
591
589
{
592
590
        int sx, sy;
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);
597
 
        struct rectangle r;
 
595
        rectangle r;
598
596
        struct crtc6845_cursor cursor;
599
597
 
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)
646
644
{
647
645
        int sx, sy;
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);
652
 
        struct rectangle r;
 
650
        rectangle r;
653
651
        struct crtc6845_cursor cursor;
654
652
 
655
653
        crtc6845_time(crtc);
658
656
 
659
657
        for (sy=0, r.min_y=0, r.max_y=height-1; sy<lines; sy++, r.min_y+=height,r.max_y+=height)
660
658
        {
661
 
                if (r.min_y >= Machine->scrbitmap->height)
 
659
                if (r.min_y >= Machine->drv->screen_height)
662
660
                        break;
663
661
 
664
662
                for (sx=0, r.min_x=0, r.max_x=7; sx<columns; 
714
712
  The character cell size is 16x8
715
713
***************************************************************************/
716
714
 
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)
718
716
{
719
717
        int sx, sy;
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);
724
 
        struct rectangle r;
 
722
        rectangle r;
725
723
        struct crtc6845_cursor cursor;
726
724
        
727
725
        if (CGA_CHIPSET != CGA_CHIPSET_PC200) 
736
734
 
737
735
        for (sy=0, r.min_y=0, r.max_y=height-1; sy<lines; sy++, r.min_y+=height,r.max_y+=height)
738
736
        {
739
 
                if (r.min_y >= Machine->scrbitmap->height)
 
737
                if (r.min_y >= Machine->drv->screen_height)
740
738
                        break;
741
739
 
742
740
                for (sx=0, r.min_x=0, r.max_x=7; sx<columns; 
783
781
  cga fetches 2 byte per crtc6845 access (not modeled here)!
784
782
***************************************************************************/
785
783
 
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)
787
785
{
788
786
        const UINT16 *palette;
789
787
        int colorset = cga.color_select & 0x3F;
790
788
 
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)
795
793
        {
 
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;
798
798
                break;
799
799
 
 
800
                case CGA_CHIPSET_IBM:
800
801
                case CGA_CHIPSET_PC200:
801
802
                case CGA_CHIPSET_ATI:
802
803
                case CGA_CHIPSET_PARADISE:
822
823
  Even scanlines are from CGA_base + 0x0000, odd from CGA_base + 0x2000
823
824
***************************************************************************/
824
825
 
825
 
static void cga_gfx_1bpp(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
 
826
static void cga_gfx_1bpp(mame_bitmap *bitmap, struct crtc6845 *crtc)
826
827
{
827
828
        const UINT16 *palette;
828
829
 
838
839
 
839
840
 
840
841
 
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)
 
844
{
 
845
        int color;
 
846
        int i;
 
847
 
 
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]);
 
852
}
 
853
 
 
854
 
 
855
static void cga_gfx_4bpp(mame_bitmap *bitmap, struct crtc6845 *crtc, int scale)
 
856
{
 
857
        int i, sx, sy, sh;
 
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;
 
862
 
 
863
        pc_cga_check_palette();
 
864
 
 
865
        for (sy=0; sy<lines; sy++,offs=(offs+columns)&0x1fff) 
 
866
        {
 
867
                for (sh=0; sh<height; sh++, offs|=0x2000) 
 
868
                { 
 
869
                        /* char line 0 used as a12 line in graphic mode */
 
870
                        if (!(sh & 1))
 
871
                        {
 
872
                                for (i=offs, sx=0; sx<columns; sx++, i=(i+1)&0x1fff) 
 
873
                                {
 
874
                                        if (!dirtybuffer || dirtybuffer[i]) 
 
875
                                        {
 
876
                                                cga_plot_unit_4bpp(bitmap, sx*scale, sy*height+sh, i, scale/2);
 
877
                                                if (dirtybuffer)
 
878
                                                        dirtybuffer[i]=0;
 
879
                                        }
 
880
                                }
 
881
                        }
 
882
                        else
 
883
                        {
 
884
                                for (i=offs|0x2000, sx=0; sx<columns; sx++, i=((i+1)&0x1fff)|0x2000) 
 
885
                                {
 
886
                                        if (!dirtybuffer || dirtybuffer[i]) 
 
887
                                        {
 
888
                                                cga_plot_unit_4bpp(bitmap, sx*scale, sy*height+sh, i, scale/2);
 
889
                                                if (dirtybuffer)
 
890
                                                        dirtybuffer[i]=0;
 
891
                                        }
 
892
                                }
 
893
                        }
 
894
                }
 
895
        }
 
896
}
 
897
 
 
898
 
 
899
/* The hi-res graphics mode on a colour composite monitor 
 
900
 *
 
901
 * The different scaling factors mean that the '160x200' versions of screens
 
902
 * are the same size as the normal colour ones.
 
903
 */ 
 
904
static void cga_gfx_4bpph(mame_bitmap *bitmap, struct crtc6845 *crtc)
 
905
{
 
906
        pc_cga_check_palette();
 
907
        cga_gfx_4bpp(bitmap, crtc, 8);
 
908
}
 
909
 
 
910
        
 
911
/* The lo-res graphics mode on a colour composite monitor */
 
912
static void cga_gfx_4bppl(mame_bitmap *bitmap, struct crtc6845 *crtc)
 
913
{
 
914
        pc_cga_check_palette();
 
915
        cga_gfx_4bpp(bitmap, crtc, 4);
 
916
}
 
917
        
 
918
 
 
919
 
 
920
 
 
921
INLINE void pgfx_plot_unit_4bpp(mame_bitmap *bitmap, 
842
922
                                                         int x, int y, int offs)
843
923
{
844
924
        int color, values[2];
873
953
  Second plane at CGA_base + 0x4000 / 0x6000 
874
954
***************************************************************************/
875
955
 
876
 
static void cga_pgfx_4bpp(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
 
956
static void cga_pgfx_4bpp(mame_bitmap *bitmap, struct crtc6845 *crtc)
877
957
{
878
958
        int i, sx, sy, sh;
879
959
        int     offs = crtc6845_get_start(crtc)*2;
916
996
 
917
997
 
918
998
 
919
 
INLINE void pgfx_plot_unit_2bpp(struct mame_bitmap *bitmap, 
 
999
INLINE void pgfx_plot_unit_2bpp(mame_bitmap *bitmap, 
920
1000
                                         int x, int y, const UINT16 *palette, int offs)
921
1001
{
922
1002
        int i;
963
1043
  cga fetches 2 byte per crtc6845 access (not modeled here)!
964
1044
***************************************************************************/
965
1045
 
966
 
static void cga_pgfx_2bpp(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
 
1046
static void cga_pgfx_2bpp(mame_bitmap *bitmap, struct crtc6845 *crtc)
967
1047
{
968
1048
        int i, sx, sy, sh;
969
1049
        int     offs = crtc6845_get_start(crtc)*2;
973
1053
        int colorset = cga.color_select & 0x3F;
974
1054
        const UINT16 *palette;
975
1055
 
976
 
        /* Many clone chipsets use bit 2 of the mode control register to 
977
 
         * access a third palette */
 
1056
        /* Most chipsets use bit 2 of the mode control register to 
 
1057
         * access a third palette. But not consistently. */
978
1058
        pc_cga_check_palette();
979
1059
        switch(CGA_CHIPSET)
980
1060
        {
 
1061
                /* The IBM Professional Graphics Controller behaves like
 
1062
                 * the PC1512, btw. */
981
1063
                case CGA_CHIPSET_PC1512:
982
1064
                if ((colorset < 32) && (cga.mode_control & 4)) colorset += 64;
983
1065
                break;
984
1066
 
 
1067
                case CGA_CHIPSET_IBM:
985
1068
                case CGA_CHIPSET_PC200:
986
1069
                case CGA_CHIPSET_ATI:
987
1070
                case CGA_CHIPSET_PARADISE:
1034
1117
/* mapping of the 4 planes into videoram */
1035
1118
/* (text data should be readable at videoram+0) */
1036
1119
static const int videoram_offset[4]= { 0xc000, 0x8000, 0x4000, 0 };
1037
 
INLINE void pc1512_plot_unit(struct mame_bitmap *bitmap, 
 
1120
INLINE void pc1512_plot_unit(mame_bitmap *bitmap, 
1038
1121
                                                         int x, int y, int offs)
1039
1122
{
1040
1123
        int color, values[4];
1066
1149
  Even scanlines are from CGA_base + 0x0000, odd from CGA_base + 0x2000
1067
1150
***************************************************************************/
1068
1151
 
1069
 
static void pc1512_gfx_4bpp(struct mame_bitmap *bitmap, struct crtc6845 *crtc)
 
1152
static void pc1512_gfx_4bpp(mame_bitmap *bitmap, struct crtc6845 *crtc)
1070
1153
{
1071
1154
        int i, sx, sy, sh;
1072
1155
        int     offs = crtc6845_get_start(crtc)*2;
1166
1249
        static const pc_video_update_proc videoprocs_cga[] =
1167
1250
        {
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,
1171
1254
 
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,
1175
1258
 
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,
1179
1262
 
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,
1183
1266
        };
1184
1267
 
1221
1304
                if ((cga.mode_control & 2) && (cga.plantronics & 0x10))
1222
1305
                        proc = cga_pgfx_4bpp;
1223
1306
 
1224
 
                if (proc == cga_gfx_1bpp || proc == pc1512_gfx_4bpp || proc == cga_pgfx_2bpp)
 
1307
                /* The 160x200 modes are only available on a composite 
 
1308
                 * monitor */   
 
1309
                if (proc == cga_gfx_4bppl && 
 
1310
                    CGA_MONITOR != CGA_MONITOR_COMPOSITE) proc = cga_gfx_2bpp;
 
1311
                if (proc == cga_gfx_4bpph && 
 
1312
                    CGA_MONITOR != CGA_MONITOR_COMPOSITE) proc = cga_gfx_1bpp;
 
1313
 
 
1314
                /* Modes that are 640 pixels wide */
 
1315
                if (proc == cga_gfx_1bpp    || 
 
1316
                    proc == cga_gfx_4bpph   ||
 
1317
                    proc == pc1512_gfx_4bpp || 
 
1318
                    proc == cga_pgfx_2bpp)
 
1319
                {
1225
1320
                        *width *= 16;
 
1321
                }
1226
1322
                else
 
1323
                {
1227
1324
                        *width *= 8;
1228
 
 
 
1325
                }
1229
1326
        }
1230
1327
        return proc;
1231
1328
}
1247
1344
 
1248
1345
        case 0xe:
1249
1346
                pc1512.read = data;
1250
 
                cpu_setbank(1, videoram + videoram_offset[data & 3]);
 
1347
                memory_set_bankptr(1, videoram + videoram_offset[data & 3]);
1251
1348
                break;
1252
1349
 
1253
1350
        /* The PC1512 doesn't have a full 6845; writes to the first 9 6845
1284
1381
 
1285
1382
 READ8_HANDLER ( pc1512_r )
1286
1383
{
1287
 
        data8_t data;
 
1384
        UINT8 data;
1288
1385
 
1289
1386
        switch (offset) {
1290
1387
        case 0xd:
1323
1420
VIDEO_START( pc1512 )
1324
1421
{
1325
1422
        videoram = (UINT8*) auto_malloc(0x10000);
1326
 
        if (videoram == 0)
1327
 
                return 1;
1328
 
 
1329
1423
        videoram_size = 0x4000; /*! used in cga this way, size of plain memory in 1 bank */
1330
 
        cpu_setbank(1,videoram + videoram_offset[0]);
 
1424
        memory_set_bankptr(1,videoram + videoram_offset[0]);
1331
1425
        pc1512.write = 0xf;
1332
1426
        pc1512.read = 0;
1333
1427