PCem

view src/video.c @ 120:47132154ffe7

Added emulation of Phoenix Trio32. Based on patch from Battler. Paradise Bahamas 64, Number Nine 9FX and Phoenix Trio32 now have configurable memory sizes.
author TomW
date Wed Jul 09 21:45:42 2014 +0100
parents f749363ad763
children 84742b645324
line source
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <math.h>
4 #include "ibm.h"
5 #include "device.h"
6 #include "mem.h"
7 #include "video.h"
8 #include "vid_svga.h"
9 #include "io.h"
10 #include "cpu.h"
11 #include "rom.h"
12 #include "timer.h"
14 #include "vid_ati18800.h"
15 #include "vid_ati28800.h"
16 #include "vid_ati_mach64.h"
17 #include "vid_cga.h"
18 #include "vid_cl5429.h"
19 #include "vid_ega.h"
20 #include "vid_et4000.h"
21 #include "vid_et4000w32.h"
22 #include "vid_hercules.h"
23 #include "vid_mda.h"
24 #include "vid_olivetti_m24.h"
25 #include "vid_oti067.h"
26 #include "vid_paradise.h"
27 #include "vid_pc1512.h"
28 #include "vid_pc1640.h"
29 #include "vid_pc200.h"
30 #include "vid_pcjr.h"
31 #include "vid_s3.h"
32 #include "vid_s3_virge.h"
33 #include "vid_tandy.h"
34 #include "vid_tgui9440.h"
35 #include "vid_tvga.h"
36 #include "vid_vga.h"
38 typedef struct
39 {
40 char name[64];
41 device_t *device;
42 int legacy_id;
43 } VIDEO_CARD;
45 static VIDEO_CARD video_cards[] =
46 {
47 {"ATI Graphics Pro Turbo (Mach64 GX)", &mach64gx_device, GFX_MACH64GX},
48 {"ATI VGA Charger (ATI-28800)", &ati28800_device, GFX_VGACHARGER},
49 {"ATI VGA Edge-16 (ATI-18800)", &ati18800_device, GFX_VGAEDGE16},
50 {"CGA", &cga_device, GFX_CGA},
51 {"Cirrus Logic CL-GD5429", &gd5429_device, GFX_CL_GD5429},
52 {"Diamond Stealth 32 (Tseng ET4000/w32p)", &et4000w32p_device, GFX_ET4000W32},
53 {"Diamond Stealth 3D 2000 (S3 ViRGE)", &s3_virge_device, GFX_VIRGE},
54 {"EGA", &ega_device, GFX_EGA},
55 {"Hercules", &hercules_device, GFX_HERCULES},
56 {"MDA", &mda_device, GFX_MDA},
57 {"Number Nine 9FX (S3 Trio64)", &s3_9fx_device, GFX_N9_9FX},
58 {"OAK OTI-067", &oti067_device, GFX_OTI067},
59 {"Paradise Bahamas 64 (S3 Vision864)", &s3_bahamas64_device, GFX_BAHAMAS64},
60 {"Phoenix S3 Trio32", &s3_phoenix_trio32_device, GFX_PHOENIX_TRIO32},
61 {"S3 ViRGE/DX", &s3_virge_375_device, GFX_VIRGEDX},
62 {"Trident TVGA8900D", &tvga8900d_device, GFX_TVGA},
63 {"Tseng ET4000AX", &et4000_device, GFX_ET4000},
64 {"Trident TGUI9440", &tgui9440_device, GFX_TGUI9440},
65 {"VGA", &vga_device, GFX_VGA},
66 {"", NULL, 0}
67 };
69 int video_card_available(int card)
70 {
71 if (video_cards[card].device)
72 return device_available(video_cards[card].device);
74 return 1;
75 }
77 char *video_card_getname(int card)
78 {
79 return video_cards[card].name;
80 }
82 device_t *video_card_getdevice(int card)
83 {
84 return video_cards[card].device;
85 }
87 int video_card_has_config(int card)
88 {
89 return video_cards[card].device->config ? 1 : 0;
90 }
92 int video_card_getid(char *s)
93 {
94 int c = 0;
96 while (video_cards[c].device)
97 {
98 if (!strcmp(video_cards[c].name, s))
99 return c;
100 c++;
101 }
103 return 0;
104 }
106 int video_old_to_new(int card)
107 {
108 int c = 0;
110 while (video_cards[c].device)
111 {
112 if (video_cards[c].legacy_id == card)
113 return c;
114 c++;
115 }
117 return 0;
118 }
120 int video_new_to_old(int card)
121 {
122 return video_cards[card].legacy_id;
123 }
125 int video_fullscreen = 0, video_fullscreen_scale, video_fullscreen_first;
126 uint32_t *video_15to32, *video_16to32;
128 int egareads=0,egawrites=0;
129 int changeframecount=2;
131 uint8_t rotatevga[8][256];
133 int frames = 0;
135 int fullchange;
137 uint8_t edatlookup[4][4];
139 /*Video timing settings -
141 8-bit - 1mb/sec
142 B = 8 ISA clocks
143 W = 16 ISA clocks
144 L = 32 ISA clocks
146 Slow 16-bit - 2mb/sec
147 B = 6 ISA clocks
148 W = 8 ISA clocks
149 L = 16 ISA clocks
151 Fast 16-bit - 4mb/sec
152 B = 3 ISA clocks
153 W = 3 ISA clocks
154 L = 6 ISA clocks
156 Slow VLB/PCI - 8mb/sec (ish)
157 B = 4 bus clocks
158 W = 8 bus clocks
159 L = 16 bus clocks
161 Mid VLB/PCI -
162 B = 4 bus clocks
163 W = 5 bus clocks
164 L = 10 bus clocks
166 Fast VLB/PCI -
167 B = 3 bus clocks
168 W = 3 bus clocks
169 L = 4 bus clocks
170 */
172 enum
173 {
174 VIDEO_ISA = 0,
175 VIDEO_BUS
176 };
178 int video_speed = 0;
179 int video_timing[6][4] =
180 {
181 {VIDEO_ISA, 8, 16, 32},
182 {VIDEO_ISA, 6, 8, 16},
183 {VIDEO_ISA, 3, 3, 6},
184 {VIDEO_BUS, 4, 8, 16},
185 {VIDEO_BUS, 4, 5, 10},
186 {VIDEO_BUS, 3, 3, 4}
187 };
189 void video_updatetiming()
190 {
191 if (video_timing[video_speed][0] == VIDEO_ISA)
192 {
193 video_timing_b = (int)(isa_timing * video_timing[video_speed][1]);
194 video_timing_w = (int)(isa_timing * video_timing[video_speed][2]);
195 video_timing_l = (int)(isa_timing * video_timing[video_speed][3]);
196 }
197 else
198 {
199 video_timing_b = (int)(bus_timing * video_timing[video_speed][1]);
200 video_timing_w = (int)(bus_timing * video_timing[video_speed][2]);
201 video_timing_l = (int)(bus_timing * video_timing[video_speed][3]);
202 }
203 if (cpu_16bitbus)
204 video_timing_l = video_timing_w * 2;
205 }
207 int video_timing_b, video_timing_w, video_timing_l;
209 int video_res_x, video_res_y, video_bpp;
211 void (*video_blit_memtoscreen)(int x, int y, int y1, int y2, int w, int h);
212 void (*video_blit_memtoscreen_8)(int x, int y, int w, int h);
214 void video_init()
215 {
216 pclog("Video_init %i %i\n",romset,gfxcard);
218 switch (romset)
219 {
220 case ROM_IBMPCJR:
221 device_add(&pcjr_video_device);
222 return;
224 case ROM_TANDY:
225 device_add(&tandy_device);
226 return;
228 case ROM_PC1512:
229 device_add(&pc1512_device);
230 return;
232 case ROM_PC1640:
233 device_add(&pc1640_device);
234 return;
236 case ROM_PC200:
237 device_add(&pc200_device);
238 return;
240 case ROM_OLIM24:
241 device_add(&m24_device);
242 return;
244 case ROM_PC2086:
245 device_add(&paradise_pvga1a_pc2086_device);
246 return;
248 case ROM_PC3086:
249 device_add(&paradise_pvga1a_pc3086_device);
250 return;
252 case ROM_MEGAPC:
253 device_add(&paradise_wd90c11_megapc_device);
254 return;
256 case ROM_ACER386:
257 device_add(&oti067_device);
258 return;
259 }
260 device_add(video_cards[video_old_to_new(gfxcard)].device);
261 }
264 BITMAP *buffer, *buffer32;
266 uint8_t fontdat[256][8];
267 uint8_t fontdatm[256][16];
269 int xsize=1,ysize=1;
271 PALETTE cgapal;
273 void loadfont(char *s, int format)
274 {
275 FILE *f=romfopen(s,"rb");
276 int c,d;
277 if (!f)
278 return;
280 if (!format)
281 {
282 for (c=0;c<256;c++)
283 {
284 for (d=0;d<8;d++)
285 {
286 fontdatm[c][d]=getc(f);
287 }
288 }
289 for (c=0;c<256;c++)
290 {
291 for (d=0;d<8;d++)
292 {
293 fontdatm[c][d+8]=getc(f);
294 }
295 }
296 fseek(f,4096+2048,SEEK_SET);
297 for (c=0;c<256;c++)
298 {
299 for (d=0;d<8;d++)
300 {
301 fontdat[c][d]=getc(f);
302 }
303 }
304 }
305 else if (format == 1)
306 {
307 for (c=0;c<256;c++)
308 {
309 for (d=0;d<8;d++)
310 {
311 fontdatm[c][d]=getc(f);
312 }
313 }
314 for (c=0;c<256;c++)
315 {
316 for (d=0;d<8;d++)
317 {
318 fontdatm[c][d+8]=getc(f);
319 }
320 }
321 fseek(f, 4096, SEEK_SET);
322 for (c=0;c<256;c++)
323 {
324 for (d=0;d<8;d++)
325 {
326 fontdat[c][d]=getc(f);
327 }
328 for (d=0;d<8;d++) getc(f);
329 }
330 }
331 else
332 {
333 for (c=0;c<256;c++)
334 {
335 for (d=0;d<8;d++)
336 {
337 fontdat[c][d]=getc(f);
338 }
339 }
340 }
341 fclose(f);
342 }
345 void initvideo()
346 {
347 int c, d, e;
349 buffer32 = create_bitmap(2048, 2048);
351 buffer = create_bitmap(2048, 2048);
353 for (c = 0; c < 64; c++)
354 {
355 cgapal[c + 64].r = (((c & 4) ? 2 : 0) | ((c & 0x10) ? 1 : 0)) * 21;
356 cgapal[c + 64].g = (((c & 2) ? 2 : 0) | ((c & 0x10) ? 1 : 0)) * 21;
357 cgapal[c + 64].b = (((c & 1) ? 2 : 0) | ((c & 0x10) ? 1 : 0)) * 21;
358 if ((c & 0x17) == 6)
359 cgapal[c + 64].g >>= 1;
360 }
361 for (c = 0; c < 64; c++)
362 {
363 cgapal[c + 128].r = (((c & 4) ? 2 : 0) | ((c & 0x20) ? 1 : 0)) * 21;
364 cgapal[c + 128].g = (((c & 2) ? 2 : 0) | ((c & 0x10) ? 1 : 0)) * 21;
365 cgapal[c + 128].b = (((c & 1) ? 2 : 0) | ((c & 0x08) ? 1 : 0)) * 21;
366 }
368 for (c = 0; c < 256; c++)
369 {
370 e = c;
371 for (d = 0; d < 8; d++)
372 {
373 rotatevga[d][c] = e;
374 e = (e >> 1) | ((e & 1) ? 0x80 : 0);
375 }
376 }
377 for (c = 0; c < 4; c++)
378 {
379 for (d = 0; d < 4; d++)
380 {
381 edatlookup[c][d] = 0;
382 if (c & 1) edatlookup[c][d] |= 1;
383 if (d & 1) edatlookup[c][d] |= 2;
384 if (c & 2) edatlookup[c][d] |= 0x10;
385 if (d & 2) edatlookup[c][d] |= 0x20;
386 // printf("Edat %i,%i now %02X\n",c,d,edatlookup[c][d]);
387 }
388 }
390 video_15to32 = malloc(4 * 65536);
391 for (c = 0; c < 65536; c++)
392 video_15to32[c] = ((c & 31) << 3) | (((c >> 5) & 31) << 11) | (((c >> 10) & 31) << 19);
394 video_16to32 = malloc(4 * 65536);
395 for (c = 0; c < 65536; c++)
396 video_16to32[c] = ((c & 31) << 3) | (((c >> 5) & 63) << 10) | (((c >> 11) & 31) << 19);
398 }
400 void closevideo()
401 {
402 free(video_15to32);
403 free(video_16to32);
404 destroy_bitmap(buffer);
405 destroy_bitmap(buffer32);
406 }