Previous 15994 Revisions Next

r13995 Thursday 12th January, 2012 at 20:42:55 UTC by Angelo Salese
Part 1 of VGA refactoring
[src/emu/video]pc_vga.c

src/emu/video/pc_vga.c
r13994r13995
4545
4646***************************************************************************/
4747
48static pc_video_update_proc (*pc_choosevideomode)(running_machine &machine, int *width, int *height);
49
50static int pc_current_height;
51static int pc_current_width;
52/***************************************************************************
53
54    Static declarations
55
56***************************************************************************/
57
58#define LOG_ACCESSES   0
59#define LOG_REGISTERS   0
60
61static PALETTE_INIT( vga );
62static VIDEO_START( vga );
63static VIDEO_RESET( vga );
64
65static pc_video_update_proc pc_vga_choosevideomode(running_machine &machine, int *width, int *height);
66
67/***************************************************************************
68
69    MachineDriver stuff
70
71***************************************************************************/
72
73void pc_video_start(running_machine &machine, pc_video_update_proc (*choosevideomode)(running_machine &machine, int *width, int *height))
74{
75   pc_choosevideomode = choosevideomode;
76   pc_current_height = -1;
77   pc_current_width = -1;
78}
79
80
81
82SCREEN_UPDATE( pc_video )
83{
84   UINT32 rc = 0;
85   int w = 0, h = 0;
86   pc_video_update_proc video_update = pc_choosevideomode(screen.machine(), &w, &h);
87
88   if (video_update)
89   {
90      if ((pc_current_width != w) || (pc_current_height != h))
91      {
92         int width = screen.width();
93         int height = screen.height();
94
95         pc_current_width = w;
96         pc_current_height = h;
97
98         if (pc_current_width > width)
99            pc_current_width = width;
100         if (pc_current_height > height)
101            pc_current_height = height;
102
103         if ((pc_current_width > 100) && (pc_current_height > 100))
104            screen.set_visible_area(0, pc_current_width-1, 0, pc_current_height-1);
105
106         bitmap.fill(0, cliprect);
107      }
108
109      video_update(bitmap);
110   }
111   return rc;
112}
113/***************************************************************************/
114
115static PALETTE_INIT( vga )
116{
117   int i;
118   for (i = 0; i < 0x100; i++)
119      palette_set_color_rgb(machine, i, 0, 0, 0);
120}
121
12248static UINT8 color_bitplane_to_packed[4/*plane*/][8/*pixel*/][256];
12349
12450static struct
r13994r13995
229155#define FONT1 (  ((vga.sequencer.data[3]&0x3)    |((vga.sequencer.data[3]&0x10)<<2))*0x2000 )
230156#define FONT2 ( (((vga.sequencer.data[3]&0xc)>>2)|((vga.sequencer.data[3]&0x20)<<3))*0x2000 )
231157
158static int pc_current_height;
159static int pc_current_width;
232160
161/***************************************************************************
162
163    Static declarations
164
165***************************************************************************/
166
167#define LOG_ACCESSES   0
168#define LOG_REGISTERS   0
169
170static PALETTE_INIT( vga );
171static VIDEO_START( vga );
172static VIDEO_RESET( vga );
173
174/***************************************************************************
175
176    MachineDriver stuff
177
178***************************************************************************/
179
180void pc_video_start(running_machine &machine)
181{
182//   pc_choosevideomode = choosevideomode;
183   pc_current_height = -1;
184   pc_current_width = -1;
185}
186
187static void vga_vh_text(bitmap_t &bitmap, const rectangle &cliprect)
188{
189   UINT8 ch, attr;
190   UINT8 bits;
191   UINT8 *font;
192   UINT16 *bitmapline;
193   int width=CHAR_WIDTH, height=CRTC_CHAR_HEIGHT;
194   int pos, line, column, mask, w, h, addr;
195   pen_t pen;
196
197   if (CRTC_CURSOR_MODE!=CRTC_CURSOR_OFF)
198   {
199      if (++vga.cursor.time>=0x10)
200      {
201         vga.cursor.visible^=1;
202         vga.cursor.time=0;
203      }
204   }
205
206   for (addr = TEXT_START_ADDRESS, line = -CRTC_SKEW; line < TEXT_LINES;
207       line += height, addr += TEXT_LINE_LENGTH)
208   {
209      for (pos = addr, column=0; column<TEXT_COLUMNS; column++, pos++)
210      {
211         ch   = vga.memory[(pos<<2) + 0];
212         attr = vga.memory[(pos<<2) + 1];
213         font = vga.memory+2+(ch<<(5+2))+FONT1;
214
215         for (h = MAX(-line, 0); (h < height) && (line+h < MIN(TEXT_LINES, bitmap.height())); h++)
216         {
217            bitmapline = &bitmap.pix16(line+h);
218            bits = font[h<<2];
219
220            assert(bitmapline);
221
222            for (mask=0x80, w=0; (w<width)&&(w<8); w++, mask>>=1)
223            {
224               if (bits&mask)
225                  pen = vga.pens[attr & 0x0f];
226               else
227                  pen = vga.pens[attr >> 4];
228               bitmapline[column*width+w] = pen;
229            }
230            if (w<width)
231            {
232               /* 9 column */
233               if (TEXT_COPY_9COLUMN(ch)&&(bits&1))
234                  pen = vga.pens[attr & 0x0f];
235               else
236                  pen = vga.pens[attr >> 4];
237               bitmapline[column*width+w] = pen;
238            }
239         }
240         if ((CRTC_CURSOR_MODE!=CRTC_CURSOR_OFF)
241            &&vga.cursor.visible&&(pos==CRTC_CURSOR_POS))
242         {
243            for (h=CRTC_CURSOR_TOP;
244                (h<=CRTC_CURSOR_BOTTOM)&&(h<height)&&(line+h<TEXT_LINES);
245                h++)
246            {
247               bitmap.plot_box(column*width, line+h, width, 1, vga.pens[attr&0xf]);
248            }
249         }
250      }
251   }
252}
253
254static void vga_vh_ega(bitmap_t &bitmap,  const rectangle &cliprect)
255{
256   int pos, line, column, c, addr, i;
257   int height = CRTC_CHAR_HEIGHT;
258   UINT16 *bitmapline;
259   UINT16 *newbitmapline;
260   pen_t pen;
261
262   for (addr=EGA_START_ADDRESS, pos=0, line=0; line<LINES;
263       line += height, addr=(addr+EGA_LINE_LENGTH)&0x3ffff)
264   {
265      bitmapline = &bitmap.pix16(line);
266
267      for (pos=addr, c=0, column=0; column<EGA_COLUMNS; column++, c+=8, pos=(pos+4)&0x3ffff)
268      {
269         int data[4];
270
271         data[0]=vga.memory[pos];
272         data[1]=vga.memory[pos+1]<<1;
273         data[2]=vga.memory[pos+2]<<2;
274         data[3]=vga.memory[pos+3]<<3;
275
276         for (i = 7; i >= 0; i--)
277         {
278            pen = vga.pens[(data[0]&1) | (data[1]&2) | (data[2]&4) | (data[3]&8)];
279            bitmapline[c+i] = pen;
280
281            data[0]>>=1;
282            data[1]>>=1;
283            data[2]>>=1;
284            data[3]>>=1;
285         }
286      }
287
288      for (i = 1; i < height; i++)
289      {
290         if (line + i >= LINES)
291            break;
292
293         newbitmapline = &bitmap.pix16(line+i);
294         memcpy(newbitmapline, bitmapline, EGA_COLUMNS * 8 * sizeof(UINT16));
295      }
296   }
297}
298
299static void vga_vh_vga(bitmap_t &bitmap, const rectangle &cliprect)
300{
301   int pos, line, column, c, addr, curr_addr;
302   UINT16 *bitmapline;
303   UINT16 mask_comp;
304
305   /* line compare is screen sensitive */
306   mask_comp = 0xff | (LINES & 0x300);
307
308   curr_addr = 0;
309   if(vga.sequencer.data[4] & 0x08)
310   {
311      for (addr = VGA_START_ADDRESS, line=0; line<LINES; line++, addr+=VGA_LINE_LENGTH, curr_addr+=VGA_LINE_LENGTH)
312      {
313         if(line < (vga.line_compare & mask_comp))
314            curr_addr = addr;
315         if(line == (vga.line_compare & mask_comp))
316            curr_addr = 0;
317         bitmapline = &bitmap.pix16(line);
318         addr %= vga.svga_intf.vram_size;
319         for (pos=curr_addr, c=0, column=0; column<VGA_COLUMNS; column++, c+=8, pos+=0x20)
320         {
321            if(pos + 0x20 > vga.svga_intf.vram_size)
322               return;
323            bitmapline[c+0] = vga.memory[pos+0];
324            bitmapline[c+1] = vga.memory[pos+1];
325            bitmapline[c+2] = vga.memory[pos+2];
326            bitmapline[c+3] = vga.memory[pos+3];
327            bitmapline[c+4] = vga.memory[pos+0x10];
328            bitmapline[c+5] = vga.memory[pos+0x11];
329            bitmapline[c+6] = vga.memory[pos+0x12];
330            bitmapline[c+7] = vga.memory[pos+0x13];
331         }
332      }
333   }
334   else
335   {
336      for (addr = VGA_START_ADDRESS, line=0; line<LINES; line++, addr+=VGA_LINE_LENGTH/4, curr_addr+=VGA_LINE_LENGTH/4)
337      {
338         if(line < (vga.line_compare & mask_comp))
339            curr_addr = addr;
340         if(line == (vga.line_compare & mask_comp))
341            curr_addr = 0;
342         bitmapline = &bitmap.pix16(line);
343         addr %= vga.svga_intf.vram_size;
344         for (pos=curr_addr, c=0, column=0; column<VGA_COLUMNS; column++, c+=8, pos+=0x08)
345         {
346            if(pos + 0x08 > vga.svga_intf.vram_size)
347               return;
348            bitmapline[c+0] = vga.memory[pos+0];
349            bitmapline[c+1] = vga.memory[pos+1];
350            bitmapline[c+2] = vga.memory[pos+2];
351            bitmapline[c+3] = vga.memory[pos+3];
352            bitmapline[c+4] = vga.memory[pos+4];
353            bitmapline[c+5] = vga.memory[pos+5];
354            bitmapline[c+6] = vga.memory[pos+6];
355            bitmapline[c+7] = vga.memory[pos+7];
356         }
357      }
358   }
359}
360
361static UINT8 pc_vga_choosevideomode(running_machine &machine, int *width, int *height)
362{
363   int i;
364
365   if (CRTC_ON)
366   {
367      if (vga.dac.dirty)
368      {
369         for (i=0; i<256;i++)
370         {
371            palette_set_color_rgb(machine, i,(vga.dac.color[i].red & 0x3f) << 2,
372                            (vga.dac.color[i].green & 0x3f) << 2,
373                            (vga.dac.color[i].blue & 0x3f) << 2);
374         }
375         vga.dac.dirty = 0;
376      }
377
378      if (vga.attribute.data[0x10] & 0x80)
379      {
380         for (i=0; i<16;i++)
381         {
382            vga.pens[i] = machine.pens[(vga.attribute.data[i]&0x0f)
383                               |((vga.attribute.data[0x14]&0xf)<<4)];
384         }
385      }
386      else
387      {
388         for (i=0; i<16;i++)
389         {
390            vga.pens[i]=machine.pens[(vga.attribute.data[i]&0x3f)
391                               |((vga.attribute.data[0x14]&0xc)<<4)];
392         }
393      }
394
395      if (vga.svga_intf.choosevideomode)
396      {
397         return 4;
398      }
399      else if (!GRAPHIC_MODE)
400      {
401         //proc = vga_vh_text;
402         *height = TEXT_LINES;
403         *width = TEXT_COLUMNS * CHAR_WIDTH;
404         return 1;
405      }
406      else if (vga.gc.data[5]&0x40)
407      {
408         //proc = vga_vh_vga;
409         *height = LINES;
410         *width = VGA_COLUMNS * 8;
411         return 2;
412      }
413      else
414      {
415         //proc = vga_vh_ega;
416         *height = LINES;
417         *width = EGA_COLUMNS * 8;
418         return 3;
419      }
420   }
421
422   return 0;
423}
424
425SCREEN_UPDATE( pc_video )
426{
427   UINT8 cur_mode = 0;
428   int w = 0, h = 0;
429
430   cur_mode = pc_vga_choosevideomode(screen.machine(), &w, &h);
431
432   if ((pc_current_width != w) || (pc_current_height != h))
433   {
434      int width = screen.width();
435      int height = screen.height();
436
437      pc_current_width = w;
438      pc_current_height = h;
439
440      if (pc_current_width > width)
441         pc_current_width = width;
442      if (pc_current_height > height)
443         pc_current_height = height;
444
445      if ((pc_current_width > 100) && (pc_current_height > 100))
446         screen.set_visible_area(0, pc_current_width-1, 0, pc_current_height-1);
447
448      bitmap.fill(0, cliprect);
449   }
450
451   switch(cur_mode)
452   {
453      case 0: bitmap.fill(get_black_pen(screen.machine()), cliprect);break;
454      case 1: vga_vh_text(bitmap,cliprect); break;
455      case 2: vga_vh_vga(bitmap,cliprect); break;
456      case 3: vga_vh_ega(bitmap,cliprect); break;
457      /* Nothing uses this so far, to be nuked */
458      case 4: vga.svga_intf.choosevideomode(vga.sequencer.data, vga.crtc.data, vga.gc.data, &w, &h); break;
459   }
460
461   return 0;
462}
463/***************************************************************************/
464
465static PALETTE_INIT( vga )
466{
467   int i;
468   for (i = 0; i < 0x100; i++)
469      palette_set_color_rgb(machine, i, 0, 0, 0);
470}
471
233472INLINE UINT8 rotate_right(UINT8 val, UINT8 rot)
234473{
235474   return (val >> rot) | (val << (8 - rot));
r13994r13995
9831222   vga.monitor.get_columns=vga_get_crtc_columns;
9841223   vga.monitor.get_sync_lines=vga_get_crtc_sync_lines;
9851224   vga.monitor.get_sync_columns=vga_get_crtc_sync_columns;
986   pc_video_start(machine, pc_vga_choosevideomode);
1225   pc_video_start(machine);
9871226}
9881227
9891228static VIDEO_RESET( vga )
r13994r13995
9911230   pc_vga_reset(machine);
9921231}
9931232
994static void vga_vh_text(bitmap_t &bitmap)
995{
996   UINT8 ch, attr;
997   UINT8 bits;
998   UINT8 *font;
999   UINT16 *bitmapline;
1000   int width=CHAR_WIDTH, height=CRTC_CHAR_HEIGHT;
1001   int pos, line, column, mask, w, h, addr;
1002   pen_t pen;
10031233
1004   if (CRTC_CURSOR_MODE!=CRTC_CURSOR_OFF)
1005   {
1006      if (++vga.cursor.time>=0x10)
1007      {
1008         vga.cursor.visible^=1;
1009         vga.cursor.time=0;
1010      }
1011   }
10121234
1013   for (addr = TEXT_START_ADDRESS, line = -CRTC_SKEW; line < TEXT_LINES;
1014       line += height, addr += TEXT_LINE_LENGTH)
1015   {
1016      for (pos = addr, column=0; column<TEXT_COLUMNS; column++, pos++)
1017      {
1018         ch   = vga.memory[(pos<<2) + 0];
1019         attr = vga.memory[(pos<<2) + 1];
1020         font = vga.memory+2+(ch<<(5+2))+FONT1;
1021
1022         for (h = MAX(-line, 0); (h < height) && (line+h < MIN(TEXT_LINES, bitmap.height())); h++)
1023         {
1024            bitmapline = &bitmap.pix16(line+h);
1025            bits = font[h<<2];
1026
1027            assert(bitmapline);
1028
1029            for (mask=0x80, w=0; (w<width)&&(w<8); w++, mask>>=1)
1030            {
1031               if (bits&mask)
1032                  pen = vga.pens[attr & 0x0f];
1033               else
1034                  pen = vga.pens[attr >> 4];
1035               bitmapline[column*width+w] = pen;
1036            }
1037            if (w<width)
1038            {
1039               /* 9 column */
1040               if (TEXT_COPY_9COLUMN(ch)&&(bits&1))
1041                  pen = vga.pens[attr & 0x0f];
1042               else
1043                  pen = vga.pens[attr >> 4];
1044               bitmapline[column*width+w] = pen;
1045            }
1046         }
1047         if ((CRTC_CURSOR_MODE!=CRTC_CURSOR_OFF)
1048            &&vga.cursor.visible&&(pos==CRTC_CURSOR_POS))
1049         {
1050            for (h=CRTC_CURSOR_TOP;
1051                (h<=CRTC_CURSOR_BOTTOM)&&(h<height)&&(line+h<TEXT_LINES);
1052                h++)
1053            {
1054               bitmap.plot_box(column*width, line+h, width, 1, vga.pens[attr&0xf]);
1055            }
1056         }
1057      }
1058   }
1059}
1060
1061static void vga_vh_ega(bitmap_t &bitmap)
1062{
1063   int pos, line, column, c, addr, i;
1064   int height = CRTC_CHAR_HEIGHT;
1065   UINT16 *bitmapline;
1066   UINT16 *newbitmapline;
1067   pen_t pen;
1068
1069   for (addr=EGA_START_ADDRESS, pos=0, line=0; line<LINES;
1070       line += height, addr=(addr+EGA_LINE_LENGTH)&0x3ffff)
1071   {
1072      bitmapline = &bitmap.pix16(line);
1073
1074      for (pos=addr, c=0, column=0; column<EGA_COLUMNS; column++, c+=8, pos=(pos+4)&0x3ffff)
1075      {
1076         int data[4];
1077
1078         data[0]=vga.memory[pos];
1079         data[1]=vga.memory[pos+1]<<1;
1080         data[2]=vga.memory[pos+2]<<2;
1081         data[3]=vga.memory[pos+3]<<3;
1082
1083         for (i = 7; i >= 0; i--)
1084         {
1085            pen = vga.pens[(data[0]&1) | (data[1]&2) | (data[2]&4) | (data[3]&8)];
1086            bitmapline[c+i] = pen;
1087
1088            data[0]>>=1;
1089            data[1]>>=1;
1090            data[2]>>=1;
1091            data[3]>>=1;
1092         }
1093      }
1094
1095      for (i = 1; i < height; i++)
1096      {
1097         if (line + i >= LINES)
1098            break;
1099
1100         newbitmapline = &bitmap.pix16(line+i);
1101         memcpy(newbitmapline, bitmapline, EGA_COLUMNS * 8 * sizeof(UINT16));
1102      }
1103   }
1104}
1105
1106static void vga_vh_vga(bitmap_t &bitmap)
1107{
1108   int pos, line, column, c, addr, curr_addr;
1109   UINT16 *bitmapline;
1110   UINT16 mask_comp;
1111
1112   /* line compare is screen sensitive */
1113   mask_comp = 0xff | (LINES & 0x300);
1114
1115   curr_addr = 0;
1116   if(vga.sequencer.data[4] & 0x08)
1117   {
1118      for (addr = VGA_START_ADDRESS, line=0; line<LINES; line++, addr+=VGA_LINE_LENGTH, curr_addr+=VGA_LINE_LENGTH)
1119      {
1120         if(line < (vga.line_compare & mask_comp))
1121            curr_addr = addr;
1122         if(line == (vga.line_compare & mask_comp))
1123            curr_addr = 0;
1124         bitmapline = &bitmap.pix16(line);
1125         addr %= vga.svga_intf.vram_size;
1126         for (pos=curr_addr, c=0, column=0; column<VGA_COLUMNS; column++, c+=8, pos+=0x20)
1127         {
1128            if(pos + 0x20 > vga.svga_intf.vram_size)
1129               return;
1130            bitmapline[c+0] = vga.memory[pos+0];
1131            bitmapline[c+1] = vga.memory[pos+1];
1132            bitmapline[c+2] = vga.memory[pos+2];
1133            bitmapline[c+3] = vga.memory[pos+3];
1134            bitmapline[c+4] = vga.memory[pos+0x10];
1135            bitmapline[c+5] = vga.memory[pos+0x11];
1136            bitmapline[c+6] = vga.memory[pos+0x12];
1137            bitmapline[c+7] = vga.memory[pos+0x13];
1138         }
1139      }
1140   }
1141   else
1142   {
1143      for (addr = VGA_START_ADDRESS, line=0; line<LINES; line++, addr+=VGA_LINE_LENGTH/4, curr_addr+=VGA_LINE_LENGTH/4)
1144      {
1145         if(line < (vga.line_compare & mask_comp))
1146            curr_addr = addr;
1147         if(line == (vga.line_compare & mask_comp))
1148            curr_addr = 0;
1149         bitmapline = &bitmap.pix16(line);
1150         addr %= vga.svga_intf.vram_size;
1151         for (pos=curr_addr, c=0, column=0; column<VGA_COLUMNS; column++, c+=8, pos+=0x08)
1152         {
1153            if(pos + 0x08 > vga.svga_intf.vram_size)
1154               return;
1155            bitmapline[c+0] = vga.memory[pos+0];
1156            bitmapline[c+1] = vga.memory[pos+1];
1157            bitmapline[c+2] = vga.memory[pos+2];
1158            bitmapline[c+3] = vga.memory[pos+3];
1159            bitmapline[c+4] = vga.memory[pos+4];
1160            bitmapline[c+5] = vga.memory[pos+5];
1161            bitmapline[c+6] = vga.memory[pos+6];
1162            bitmapline[c+7] = vga.memory[pos+7];
1163         }
1164      }
1165   }
1166}
1167
1168static pc_video_update_proc pc_vga_choosevideomode(running_machine &machine, int *width, int *height)
1169{
1170   pc_video_update_proc proc = NULL;
1171   int i;
1172
1173   if (CRTC_ON)
1174   {
1175      if (vga.dac.dirty)
1176      {
1177         for (i=0; i<256;i++)
1178         {
1179            palette_set_color_rgb(machine, i,(vga.dac.color[i].red & 0x3f) << 2,
1180                            (vga.dac.color[i].green & 0x3f) << 2,
1181                            (vga.dac.color[i].blue & 0x3f) << 2);
1182         }
1183         vga.dac.dirty = 0;
1184      }
1185
1186      if (vga.attribute.data[0x10] & 0x80)
1187      {
1188         for (i=0; i<16;i++)
1189         {
1190            vga.pens[i] = machine.pens[(vga.attribute.data[i]&0x0f)
1191                               |((vga.attribute.data[0x14]&0xf)<<4)];
1192         }
1193      }
1194      else
1195      {
1196         for (i=0; i<16;i++)
1197         {
1198            vga.pens[i]=machine.pens[(vga.attribute.data[i]&0x3f)
1199                               |((vga.attribute.data[0x14]&0xc)<<4)];
1200         }
1201      }
1202
1203      if (vga.svga_intf.choosevideomode)
1204         proc = vga.svga_intf.choosevideomode(vga.sequencer.data, vga.crtc.data, vga.gc.data, width, height);
1205
1206      if (!proc)
1207      {
1208         if (!GRAPHIC_MODE)
1209         {
1210            proc = vga_vh_text;
1211            *height = TEXT_LINES;
1212            *width = TEXT_COLUMNS * CHAR_WIDTH;
1213         }
1214         else if (vga.gc.data[5]&0x40)
1215         {
1216            proc = vga_vh_vga;
1217            *height = LINES;
1218            *width = VGA_COLUMNS * 8;
1219         }
1220         else
1221         {
1222            proc = vga_vh_ega;
1223            *height = LINES;
1224            *width = EGA_COLUMNS * 8;
1225         }
1226      }
1227   }
1228   return proc;
1229}
1230
1231
1232
12331235void *pc_vga_memory(void)
12341236{
12351237   return vga.memory;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team