Debian Codegraph @

src/hardware/vga_tseng.cpp

raw
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: vga_tseng.cpp,v 1.5 2009-05-27 09:15:41 qbix79 Exp $ */
20
21
22 #include "dosbox.h"
23 #include "setup.h"
24 #include "vga.h"
25 #include "inout.h"
26 #include "mem.h"
27 #include <cstdlib>
28 // Tseng ET4K data
29 typedef struct {
30 Bit8u extensionsEnabled;
31
32 // Stored exact values of some registers. Documentation only specifies some bits but hardware checks may
33 // expect other bits to be preserved.
34 Bitu store_3d4_31;
35 Bitu store_3d4_32;
36 Bitu store_3d4_33;
37 Bitu store_3d4_34;
38 Bitu store_3d4_35;
39 Bitu store_3d4_36;
40 Bitu store_3d4_37;
41 Bitu store_3d4_3f;
42
43 Bitu store_3c0_16;
44 Bitu store_3c0_17;
45
46 Bitu store_3c4_06;
47 Bitu store_3c4_07;
48
49 Bitu clockFreq[16];
50 Bitu biosMode;
51 } SVGA_ET4K_DATA;
52
53 static SVGA_ET4K_DATA et4k = { 1,0,0,0,0,0,0,0,0, 0,0, 0,0,
54 { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 0 };
55
56 #define STORE_ET4K(port, index) \
57 case 0x##index: \
58 et4k.store_##port##_##index = val; \
59 break;
60
61 #define RESTORE_ET4K(port, index) \
62 case 0x##index: \
63 return et4k.store_##port##_##index;
64
65 // Tseng ET4K implementation
66 void write_p3d5_et4k(Bitu reg,Bitu val,Bitu iolen) {
67 if(!et4k.extensionsEnabled && reg!=0x33)
68 return;
69
70 switch(reg) {
71 /*
72 3d4h index 31h (R/W): General Purpose
73 bit 0-3 Scratch pad
74 6-7 Clock Select bits 3-4. Bits 0-1 are in 3C2h/3CCh bits 2-3.
75 */
76 STORE_ET4K(3d4, 31);
77
78 // 3d4h index 32h - RAS/CAS Configuration (R/W)
79 // No effect on emulation. Should not be written by software.
80 STORE_ET4K(3d4, 32);
81
82 case 0x33:
83 // 3d4 index 33h (R/W): Extended start Address
84 // 0-1 Display Start Address bits 16-17
85 // 2-3 Cursor start address bits 16-17
86 // Used by standard Tseng ID scheme
87 et4k.store_3d4_33 = val;
88 vga.config.display_start = (vga.config.display_start & 0xffff) | ((val & 0x03)<<16);
89 vga.config.cursor_start = (vga.config.cursor_start & 0xffff) | ((val & 0x0c)<<14);
90 break;
91
92 /*
93 3d4h index 34h (R/W): 6845 Compatibility Control Register
94 bit 0 Enable CS0 (alternate clock timing)
95 1 Clock Select bit 2. Bits 0-1 in 3C2h bits 2-3, bits 3-4 are in 3d4h
96 index 31h bits 6-7
97 2 Tristate ET4000 bus and color outputs if set
98 3 Video Subsystem Enable Register at 46E8h if set, at 3C3h if clear.
99 4 Enable Translation ROM for reading CRTC and MISCOUT if set
100 5 Enable Translation ROM for writing CRTC and MISCOUT if set
101 6 Enable double scan in AT&T compatibility mode if set
102 7 Enable 6845 compatibility if set
103 */
104 // TODO: Bit 6 may have effect on emulation
105 STORE_ET4K(3d4, 34);
106
107 case 0x35:
108 /*
109 3d4h index 35h (R/W): Overflow High
110 bit 0 Vertical Blank Start Bit 10 (3d4h index 15h).
111 1 Vertical Total Bit 10 (3d4h index 6).
112 2 Vertical Display End Bit 10 (3d4h index 12h).
113 3 Vertical Sync Start Bit 10 (3d4h index 10h).
114 4 Line Compare Bit 10 (3d4h index 18h).
115 5 Gen-Lock Enabled if set (External sync)
116 6 (4000) Read/Modify/Write Enabled if set. Currently not implemented.
117 7 Vertical interlace if set. The Vertical timing registers are
118 programmed as if the mode was non-interlaced!!
119 */
120 et4k.store_3d4_35 = val;
121 vga.config.line_compare = (vga.config.line_compare & 0x3ff) | ((val&0x10)<<6);
122 // Abusing s3 ex_ver_overflow field. This is to be cleaned up later.
123 {
124 Bit8u s3val =
125 ((val & 0x01) << 2) | // vbstart
126 ((val & 0x02) >> 1) | // vtotal
127 ((val & 0x04) >> 1) | // vdispend
128 ((val & 0x08) << 1) | // vsyncstart (?)
129 ((val & 0x10) << 2); // linecomp
130 if ((s3val ^ vga.s3.ex_ver_overflow) & 0x3) {
131 vga.s3.ex_ver_overflow=s3val;
132 VGA_StartResize();
133 } else vga.s3.ex_ver_overflow=s3val;
134 }
135 break;
136
137 // 3d4h index 36h - Video System Configuration 1 (R/W)
138 // VGADOC provides a lot of info on this register, Ferraro has significantly less detail.
139 // This is unlikely to be used by any games. Bit 4 switches chipset into linear mode -
140 // that may be useful in some cases if there is any software actually using it.
141 // TODO (not near future): support linear addressing
142 STORE_ET4K(3d4, 36);
143
144 // 3d4h index 37 - Video System Configuration 2 (R/W)
145 // Bits 0,1, and 3 provides information about memory size:
146 // 0-1 Bus width (1: 8 bit, 2: 16 bit, 3: 32 bit)
147 // 3 Size of RAM chips (0: 64Kx, 1: 256Kx)
148 // Other bits have no effect on emulation.
149 case 0x37:
150 if (val != et4k.store_3d4_37) {
151 et4k.store_3d4_37 = val;
152 vga.vmemwrap = ((64*1024)<<((val&8)>>2))<<((val&3)-1);
153 VGA_SetupHandlers();
154 }
155 break;
156
157 case 0x3f:
158 /*
159 3d4h index 3Fh (R/W):
160 bit 0 Bit 8 of the Horizontal Total (3d4h index 0)
161 2 Bit 8 of the Horizontal Blank Start (3d4h index 3)
162 4 Bit 8 of the Horizontal Retrace Start (3d4h index 4)
163 7 Bit 8 of the CRTC offset register (3d4h index 13h).
164 */
165 // The only unimplemented one is bit 7
166 et4k.store_3d4_3f = val;
167 // Abusing s3 ex_hor_overflow field which very similar. This is
168 // to be cleaned up later
169 if ((val ^ vga.s3.ex_hor_overflow) & 3) {
170 vga.s3.ex_hor_overflow=(val&0x15);
171 VGA_StartResize();
172 } else vga.s3.ex_hor_overflow=(val&0x15);
173 break;
174 default:
175 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET4K:Write to illegal index %2X", reg);
176 break;
177 }
178 }
179
180 Bitu read_p3d5_et4k(Bitu reg,Bitu iolen) {
181 if (!et4k.extensionsEnabled && reg!=0x33)
182 return 0x0;
183 switch(reg) {
184 RESTORE_ET4K(3d4, 31);
185 RESTORE_ET4K(3d4, 32);
186 RESTORE_ET4K(3d4, 33);
187 RESTORE_ET4K(3d4, 34);
188 RESTORE_ET4K(3d4, 35);
189 RESTORE_ET4K(3d4, 36);
190 RESTORE_ET4K(3d4, 37);
191 RESTORE_ET4K(3d4, 3f);
192 default:
193 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET4K:Read from illegal index %2X", reg);
194 break;
195 }
196 return 0x0;
197 }
198
199 void write_p3c5_et4k(Bitu reg,Bitu val,Bitu iolen) {
200 switch(reg) {
201 /*
202 3C4h index 6 (R/W): TS State Control
203 bit 1-2 Font Width Select in dots/character
204 If 3C4h index 4 bit 0 clear:
205 0: 9 dots, 1: 10 dots, 2: 12 dots, 3: 6 dots
206 If 3C4h index 5 bit 0 set:
207 0: 8 dots, 1: 11 dots, 2: 7 dots, 3: 16 dots
208 Only valid if 3d4h index 34h bit 3 set.
209 */
210 // TODO: Figure out if this has any practical use
211 STORE_ET4K(3c4, 06);
212 // 3C4h index 7 (R/W): TS Auxiliary Mode
213 // Unlikely to be used by games (things like ROM enable/disable and emulation of VGA vs EGA)
214 STORE_ET4K(3c4, 07);
215 default:
216 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET4K:Write to illegal index %2X", reg);
217 break;
218 }
219 }
220
221 Bitu read_p3c5_et4k(Bitu reg,Bitu iolen) {
222 switch(reg) {
223 RESTORE_ET4K(3c4, 06);
224 RESTORE_ET4K(3c4, 07);
225 default:
226 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET4K:Read from illegal index %2X", reg);
227 break;
228 }
229 return 0x0;
230 }
231
232 /*
233 3CDh (R/W): Segment Select
234 bit 0-3 64k Write bank number (0..15)
235 4-7 64k Read bank number (0..15)
236 */
237 void write_p3cd_et4k(Bitu port,Bitu val,Bitu iolen) {
238 vga.svga.bank_write = val & 0x0f;
239 vga.svga.bank_read = (val>>4) & 0x0f;
240 VGA_SetupHandlers();
241 }
242
243 Bitu read_p3cd_et4k(Bitu port,Bitu iolen) {
244 return (vga.svga.bank_read<<4)|vga.svga.bank_write;
245 }
246
247 void write_p3c0_et4k(Bitu reg,Bitu val,Bitu iolen) {
248 switch(reg) {
249 // 3c0 index 16h: ATC Miscellaneous
250 // VGADOC provides a lot of information, Ferarro documents only two bits
251 // and even those incompletely. The register is used as part of identification
252 // scheme.
253 // Unlikely to be used by any games but double timing may be useful.
254 // TODO: Figure out if this has any practical use
255 STORE_ET4K(3c0, 16);
256 /*
257 3C0h index 17h (R/W): Miscellaneous 1
258 bit 7 If set protects the internal palette ram and redefines the attribute
259 bits as follows:
260 Monochrome:
261 bit 0-2 Select font 0-7
262 3 If set selects blinking
263 4 If set selects underline
264 5 If set prevents the character from being displayed
265 6 If set displays the character at half intensity
266 7 If set selects reverse video
267 Color:
268 bit 0-1 Selects font 0-3
269 2 Foreground Blue
270 3 Foreground Green
271 4 Foreground Red
272 5 Background Blue
273 6 Background Green
274 7 Background Red
275 */
276 // TODO: Figure out if this has any practical use
277 STORE_ET4K(3c0, 17);
278 default:
279 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET4K:Write to illegal index %2X", reg);
280 break;
281 }
282 }
283
284 Bitu read_p3c1_et4k(Bitu reg,Bitu iolen) {
285 switch(reg) {
286 RESTORE_ET4K(3c0, 16);
287 RESTORE_ET4K(3c0, 17);
288 default:
289 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET4K:Read from illegal index %2X", reg);
290 break;
291 }
292 return 0x0;
293 }
294
295 /*
296 These ports are used but have little if any effect on emulation:
297 3BFh (R/W): Hercules Compatibility Mode
298 3CBh (R/W): PEL Address/Data Wd
299 3CEh index 0Dh (R/W): Microsequencer Mode
300 3CEh index 0Eh (R/W): Microsequencer Reset
301 3d8h (R/W): Display Mode Control
302 3DEh (W); AT&T Mode Control Register
303 */
304
305 static Bitu get_clock_index_et4k() {
306 // Ignoring bit 4, using "only" 16 frequencies. Looks like most implementations had only that
307 return ((vga.misc_output>>2)&3) | ((et4k.store_3d4_34<<1)&4) | ((et4k.store_3d4_31>>3)&8);
308 }
309
310 static void set_clock_index_et4k(Bitu index) {
311 // Shortwiring register reads/writes for simplicity
312 IO_Write(0x3c2, (vga.misc_output&~0x0c)|((index&3)<<2));
313 et4k.store_3d4_34 = (et4k.store_3d4_34&~0x02)|((index&4)>>1);
314 et4k.store_3d4_31 = (et4k.store_3d4_31&~0xc0)|((index&8)<<3); // (index&0x18) if 32 clock frequencies are to be supported
315 }
316
317 void FinishSetMode_ET4K(Bitu crtc_base, VGA_ModeExtraData* modeData) {
318 et4k.biosMode = modeData->modeNo;
319
320 IO_Write(0x3cd, 0x00); // both banks to 0
321
322 // Reinterpret hor_overflow. Curiously, three bits out of four are
323 // in the same places. Input has hdispend (not supported), output
324 // has CRTC offset (also not supported)
325 Bit8u et4k_hor_overflow =
326 (modeData->hor_overflow & 0x01) |
327 (modeData->hor_overflow & 0x04) |
328 (modeData->hor_overflow & 0x10);
329 IO_Write(crtc_base,0x3f);IO_Write(crtc_base+1,et4k_hor_overflow);
330
331 // Reinterpret ver_overflow
332 Bit8u et4k_ver_overflow =
333 ((modeData->ver_overflow & 0x01) << 1) | // vtotal10
334 ((modeData->ver_overflow & 0x02) << 1) | // vdispend10
335 ((modeData->ver_overflow & 0x04) >> 2) | // vbstart10
336 ((modeData->ver_overflow & 0x10) >> 1) | // vretrace10 (tseng has vsync start?)
337 ((modeData->ver_overflow & 0x40) >> 2); // line_compare
338 IO_Write(crtc_base,0x35);IO_Write(crtc_base+1,et4k_ver_overflow);
339
340 // Clear remaining ext CRTC registers
341 IO_Write(crtc_base,0x31);IO_Write(crtc_base+1,0);
342 IO_Write(crtc_base,0x32);IO_Write(crtc_base+1,0);
343 IO_Write(crtc_base,0x33);IO_Write(crtc_base+1,0);
344 IO_Write(crtc_base,0x34);IO_Write(crtc_base+1,0);
345 IO_Write(crtc_base,0x36);IO_Write(crtc_base+1,0);
346 IO_Write(crtc_base,0x37);IO_Write(crtc_base+1,0x0c|(vga.vmemsize==1024*1024?3:vga.vmemsize==512*1024?2:1));
347 // Clear ext SEQ
348 IO_Write(0x3c4,0x06);IO_Write(0x3c5,0);
349 IO_Write(0x3c4,0x07);IO_Write(0x3c5,0);
350 // Clear ext ATTR
351 IO_Write(0x3c0,0x16);IO_Write(0x3c0,0);
352 IO_Write(0x3c0,0x17);IO_Write(0x3c0,0);
353
354 // Select SVGA clock to get close to 60Hz (not particularly clean implementation)
355 if (modeData->modeNo > 0x13) {
356 Bitu target = modeData->vtotal*8*modeData->htotal*60;
357 Bitu best = 1;
358 Bits dist = 100000000;
359 for (Bitu i=0; i<16; i++) {
360 Bits cdiff=abs((Bits)(target-et4k.clockFreq[i]));
361 if (cdiff < dist) {
362 best = i;
363 dist = cdiff;
364 }
365 }
366 set_clock_index_et4k(best);
367 }
368
369 if(svga.determine_mode)
370 svga.determine_mode();
371
372 // Verified (on real hardware and in a few games): Tseng ET4000 used chain4 implementation
373 // different from standard VGA. It was also not limited to 64K in regular mode 13h.
374 vga.config.compatible_chain4 = false;
375 vga.vmemwrap = vga.vmemsize;
376
377 VGA_SetupHandlers();
378 }
379
380 void DetermineMode_ET4K() {
381 // Close replica from the base implementation. It will stay here
382 // until I figure a way to either distinguish M_VGA and M_LIN8 or
383 // merge them.
384 if (vga.attr.mode_control & 1) {
385 if (vga.gfx.mode & 0x40) VGA_SetMode((et4k.biosMode<=0x13)?M_VGA:M_LIN8); // Ugly...
386 else if (vga.gfx.mode & 0x20) VGA_SetMode(M_CGA4);
387 else if ((vga.gfx.miscellaneous & 0x0c)==0x0c) VGA_SetMode(M_CGA2);
388 else VGA_SetMode((et4k.biosMode<=0x13)?M_EGA:M_LIN4);
389 } else {
390 VGA_SetMode(M_TEXT);
391 }
392 }
393
394 void SetClock_ET4K(Bitu which,Bitu target) {
395 et4k.clockFreq[which]=1000*target;
396 VGA_StartResize();
397 }
398
399 Bitu GetClock_ET4K() {
400 return et4k.clockFreq[get_clock_index_et4k()];
401 }
402
403 bool AcceptsMode_ET4K(Bitu mode) {
404 return VideoModeMemSize(mode) < vga.vmemsize;
405 // return mode != 0x3d;
406 }
407
408 void SVGA_Setup_TsengET4K(void) {
409 svga.write_p3d5 = &write_p3d5_et4k;
410 svga.read_p3d5 = &read_p3d5_et4k;
411 svga.write_p3c5 = &write_p3c5_et4k;
412 svga.read_p3c5 = &read_p3c5_et4k;
413 svga.write_p3c0 = &write_p3c0_et4k;
414 svga.read_p3c1 = &read_p3c1_et4k;
415
416 svga.set_video_mode = &FinishSetMode_ET4K;
417 svga.determine_mode = &DetermineMode_ET4K;
418 svga.set_clock = &SetClock_ET4K;
419 svga.get_clock = &GetClock_ET4K;
420 svga.accepts_mode = &AcceptsMode_ET4K;
421
422 // From the depths of X86Config, probably inexact
423 VGA_SetClock(0,CLK_25);
424 VGA_SetClock(1,CLK_28);
425 VGA_SetClock(2,32400);
426 VGA_SetClock(3,35900);
427 VGA_SetClock(4,39900);
428 VGA_SetClock(5,44700);
429 VGA_SetClock(6,31400);
430 VGA_SetClock(7,37500);
431 VGA_SetClock(8,50000);
432 VGA_SetClock(9,56500);
433 VGA_SetClock(10,64900);
434 VGA_SetClock(11,71900);
435 VGA_SetClock(12,79900);
436 VGA_SetClock(13,89600);
437 VGA_SetClock(14,62800);
438 VGA_SetClock(15,74800);
439
440 IO_RegisterReadHandler(0x3cd,read_p3cd_et4k,IO_MB);
441 IO_RegisterWriteHandler(0x3cd,write_p3cd_et4k,IO_MB);
442
443 // Default to 1M of VRAM
444 if (vga.vmemsize == 0)
445 vga.vmemsize = 1024*1024;
446
447 if (vga.vmemsize < 512*1024)
448 vga.vmemsize = 256*1024;
449 else if (vga.vmemsize < 1024*1024)
450 vga.vmemsize = 512*1024;
451 else
452 vga.vmemsize = 1024*1024;
453
454 // Tseng ROM signature
455 PhysPt rom_base=PhysMake(0xc000,0);
456 phys_writeb(rom_base+0x0075,' ');
457 phys_writeb(rom_base+0x0076,'T');
458 phys_writeb(rom_base+0x0077,'s');
459 phys_writeb(rom_base+0x0078,'e');
460 phys_writeb(rom_base+0x0079,'n');
461 phys_writeb(rom_base+0x007a,'g');
462 phys_writeb(rom_base+0x007b,' ');
463 }
464
465
466 // Tseng ET3K implementation
467 typedef struct {
468 // Stored exact values of some registers. Documentation only specifies some bits but hardware checks may
469 // expect other bits to be preserved.
470 Bitu store_3d4_1b;
471 Bitu store_3d4_1c;
472 Bitu store_3d4_1d;
473 Bitu store_3d4_1e;
474 Bitu store_3d4_1f;
475 Bitu store_3d4_20;
476 Bitu store_3d4_21;
477 Bitu store_3d4_23; // note that 22 is missing
478 Bitu store_3d4_24;
479 Bitu store_3d4_25;
480
481 Bitu store_3c0_16;
482 Bitu store_3c0_17;
483
484 Bitu store_3c4_06;
485 Bitu store_3c4_07;
486
487 Bitu clockFreq[8];
488 Bitu biosMode;
489 } SVGA_ET3K_DATA;
490
491 static SVGA_ET3K_DATA et3k = { 0,0,0,0,0,0,0,0,0,0, 0,0, 0,0, {0,0,0,0,0,0,0,0}, 0 };
492
493 #define STORE_ET3K(port, index) \
494 case 0x##index: \
495 et3k.store_##port##_##index = val; \
496 break;
497
498 #define RESTORE_ET3K(port, index) \
499 case 0x##index: \
500 return et3k.store_##port##_##index;
501
502
503 void write_p3d5_et3k(Bitu reg,Bitu val,Bitu iolen) {
504 switch(reg) {
505 // 3d4 index 1bh-21h: Hardware zoom control registers
506 // I am not sure if there was a piece of software that used these.
507 // Not implemented and will probably stay this way.
508 STORE_ET3K(3d4, 1b);
509 STORE_ET3K(3d4, 1c);
510 STORE_ET3K(3d4, 1d);
511 STORE_ET3K(3d4, 1e);
512 STORE_ET3K(3d4, 1f);
513 STORE_ET3K(3d4, 20);
514 STORE_ET3K(3d4, 21);
515
516 case 0x23:
517 /*
518 3d4h index 23h (R/W): Extended start ET3000
519 bit 0 Cursor start address bit 16
520 1 Display start address bit 16
521 2 Zoom start address bit 16
522 7 If set memory address 8 is output on the MBSL pin (allowing access to
523 1MB), if clear the blanking signal is output.
524 */
525 // Only bits 1 and 2 are supported. Bit 2 is related to hardware zoom, bit 7 is too obscure to be useful
526 et3k.store_3d4_23 = val;
527 vga.config.display_start = (vga.config.display_start & 0xffff) | ((val & 0x02)<<15);
528 vga.config.cursor_start = (vga.config.cursor_start & 0xffff) | ((val & 0x01)<<16);
529 break;
530
531
532 /*
533 3d4h index 24h (R/W): Compatibility Control
534 bit 0 Enable Clock Translate if set
535 1 Clock Select bit 2. Bits 0-1 are in 3C2h/3CCh.
536 2 Enable tri-state for all output pins if set
537 3 Enable input A8 of 1MB DRAMs from the INTL output if set
538 4 Reserved
539 5 Enable external ROM CRTC translation if set
540 6 Enable Double Scan and Underline Attribute if set
541 7 Enable 6845 compatibility if set.
542 */
543 // TODO: Some of these may be worth implementing.
544 STORE_ET3K(3d4, 24);
545
546
547 case 0x25:
548 /*
549 3d4h index 25h (R/W): Overflow High
550 bit 0 Vertical Blank Start bit 10
551 1 Vertical Total Start bit 10
552 2 Vertical Display End bit 10
553 3 Vertical Sync Start bit 10
554 4 Line Compare bit 10
555 5-6 Reserved
556 7 Vertical Interlace if set
557 */
558 et3k.store_3d4_25 = val;
559 vga.config.line_compare = (vga.config.line_compare & 0x3ff) | ((val&0x10)<<6);
560 // Abusing s3 ex_ver_overflow field. This is to be cleaned up later.
561 {
562 Bit8u s3val =
563 ((val & 0x01) << 2) | // vbstart
564 ((val & 0x02) >> 1) | // vtotal
565 ((val & 0x04) >> 1) | // vdispend
566 ((val & 0x08) << 1) | // vsyncstart (?)
567 ((val & 0x10) << 2); // linecomp
568 if ((s3val ^ vga.s3.ex_ver_overflow) & 0x3) {
569 vga.s3.ex_ver_overflow=s3val;
570 VGA_StartResize();
571 } else vga.s3.ex_ver_overflow=s3val;
572 }
573 break;
574
575 default:
576 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET3K:Write to illegal index %2X", reg);
577 break;
578 }
579 }
580
581 Bitu read_p3d5_et3k(Bitu reg,Bitu iolen) {
582 switch(reg) {
583 RESTORE_ET3K(3d4, 1b);
584 RESTORE_ET3K(3d4, 1c);
585 RESTORE_ET3K(3d4, 1d);
586 RESTORE_ET3K(3d4, 1e);
587 RESTORE_ET3K(3d4, 1f);
588 RESTORE_ET3K(3d4, 20);
589 RESTORE_ET3K(3d4, 21);
590 RESTORE_ET3K(3d4, 23);
591 RESTORE_ET3K(3d4, 24);
592 RESTORE_ET3K(3d4, 25);
593 default:
594 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET3K:Read from illegal index %2X", reg);
595 break;
596 }
597 return 0x0;
598 }
599
600 void write_p3c5_et3k(Bitu reg,Bitu val,Bitu iolen) {
601 switch(reg) {
602 // Both registers deal mostly with hardware zoom which is not implemented. Other bits
603 // seem to be useless for emulation with the exception of index 7 bit 4 (font select)
604 STORE_ET3K(3c4, 06);
605 STORE_ET3K(3c4, 07);
606 default:
607 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET3K:Write to illegal index %2X", reg);
608 break;
609 }
610 }
611
612 Bitu read_p3c5_et3k(Bitu reg,Bitu iolen) {
613 switch(reg) {
614 RESTORE_ET3K(3c4, 06);
615 RESTORE_ET3K(3c4, 07);
616 default:
617 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET3K:Read from illegal index %2X", reg);
618 break;
619 }
620 return 0x0;
621 }
622
623 /*
624 3CDh (R/W): Segment Select
625 bit 0-2 64k Write bank number
626 3-5 64k Read bank number
627 6-7 Segment Configuration.
628 0 128K segments
629 1 64K segments
630 2 1M linear memory
631 NOTES: 1M linear memory is not supported
632 */
633 void write_p3cd_et3k(Bitu port,Bitu val,Bitu iolen) {
634 vga.svga.bank_write = val & 0x07;
635 vga.svga.bank_read = (val>>3) & 0x07;
636 vga.svga.bank_size = (val&0x40)?64*1024:128*1024;
637 VGA_SetupHandlers();
638 }
639
640 Bitu read_p3cd_et3k(Bitu port,Bitu iolen) {
641 return (vga.svga.bank_read<<3)|vga.svga.bank_write|((vga.svga.bank_size==128*1024)?0:0x40);
642 }
643
644 void write_p3c0_et3k(Bitu reg,Bitu val,Bitu iolen) {
645 // See ET4K notes.
646 switch(reg) {
647 STORE_ET3K(3c0, 16);
648 STORE_ET3K(3c0, 17);
649 default:
650 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET3K:Write to illegal index %2X", reg);
651 break;
652 }
653 }
654
655 Bitu read_p3c1_et3k(Bitu reg,Bitu iolen) {
656 switch(reg) {
657 RESTORE_ET3K(3c0, 16);
658 RESTORE_ET3K(3c0, 17);
659 default:
660 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET3K:Read from illegal index %2X", reg);
661 break;
662 }
663 return 0x0;
664 }
665
666 /*
667 These ports are used but have little if any effect on emulation:
668 3B8h (W): Display Mode Control Register
669 3BFh (R/W): Hercules Compatibility Mode
670 3CBh (R/W): PEL Address/Data Wd
671 3CEh index 0Dh (R/W): Microsequencer Mode
672 3CEh index 0Eh (R/W): Microsequencer Reset
673 3d8h (R/W): Display Mode Control
674 3D9h (W): Color Select Register
675 3dAh (W): Feature Control Register
676 3DEh (W); AT&T Mode Control Register
677 */
678
679 static Bitu get_clock_index_et3k() {
680 return ((vga.misc_output>>2)&3) | ((et3k.store_3d4_24<<1)&4);
681 }
682
683 static void set_clock_index_et3k(Bitu index) {
684 // Shortwiring register reads/writes for simplicity
685 IO_Write(0x3c2, (vga.misc_output&~0x0c)|((index&3)<<2));
686 et3k.store_3d4_24 = (et3k.store_3d4_24&~0x02)|((index&4)>>1);
687 }
688
689 void FinishSetMode_ET3K(Bitu crtc_base, VGA_ModeExtraData* modeData) {
690 et3k.biosMode = modeData->modeNo;
691
692 IO_Write(0x3cd, 0x40); // both banks to 0, 64K bank size
693
694 // Tseng ET3K does not have horizontal overflow bits
695 // Reinterpret ver_overflow
696 Bit8u et4k_ver_overflow =
697 ((modeData->ver_overflow & 0x01) << 1) | // vtotal10
698 ((modeData->ver_overflow & 0x02) << 1) | // vdispend10
699 ((modeData->ver_overflow & 0x04) >> 2) | // vbstart10
700 ((modeData->ver_overflow & 0x10) >> 1) | // vretrace10 (tseng has vsync start?)
701 ((modeData->ver_overflow & 0x40) >> 2); // line_compare
702 IO_Write(crtc_base,0x25);IO_Write(crtc_base+1,et4k_ver_overflow);
703
704 // Clear remaining ext CRTC registers
705 for (Bitu i=0x16; i<=0x21; i++)
706 IO_Write(crtc_base,i);IO_Write(crtc_base+1,0);
707 IO_Write(crtc_base,0x23);IO_Write(crtc_base+1,0);
708 IO_Write(crtc_base,0x24);IO_Write(crtc_base+1,0);
709 // Clear ext SEQ
710 IO_Write(0x3c4,0x06);IO_Write(0x3c5,0);
711 IO_Write(0x3c4,0x07);IO_Write(0x3c5,0x40); // 0 in this register breaks WHATVGA
712 // Clear ext ATTR
713 IO_Write(0x3c0,0x16);IO_Write(0x3c0,0);
714 IO_Write(0x3c0,0x17);IO_Write(0x3c0,0);
715
716 // Select SVGA clock to get close to 60Hz (not particularly clean implementation)
717 if (modeData->modeNo > 0x13) {
718 Bitu target = modeData->vtotal*8*modeData->htotal*60;
719 Bitu best = 1;
720 Bits dist = 100000000;
721 for (Bitu i=0; i<8; i++) {
722 Bits cdiff = abs((Bits)(target-et3k.clockFreq[i]));
723 if (cdiff < dist) {
724 best = i;
725 dist = cdiff;
726 }
727 }
728 set_clock_index_et3k(best);
729 }
730
731 if (svga.determine_mode)
732 svga.determine_mode();
733
734 // Verified on functioning (at last!) hardware: Tseng ET3000 is the same as ET4000 when
735 // it comes to chain4 architecture
736 vga.config.compatible_chain4 = false;
737 vga.vmemwrap = vga.vmemsize;
738
739 VGA_SetupHandlers();
740 }
741
742 void DetermineMode_ET3K() {
743 // Close replica from the base implementation. It will stay here
744 // until I figure a way to either distinguish M_VGA and M_LIN8 or
745 // merge them.
746 if (vga.attr.mode_control & 1) {
747 if (vga.gfx.mode & 0x40) VGA_SetMode((et3k.biosMode<=0x13)?M_VGA:M_LIN8); // Ugly...
748 else if (vga.gfx.mode & 0x20) VGA_SetMode(M_CGA4);
749 else if ((vga.gfx.miscellaneous & 0x0c)==0x0c) VGA_SetMode(M_CGA2);
750 else VGA_SetMode((et3k.biosMode<=0x13)?M_EGA:M_LIN4);
751 } else {
752 VGA_SetMode(M_TEXT);
753 }
754 }
755
756 void SetClock_ET3K(Bitu which,Bitu target) {
757 et3k.clockFreq[which]=1000*target;
758 VGA_StartResize();
759 }
760
761 Bitu GetClock_ET3K() {
762 return et3k.clockFreq[get_clock_index_et3k()];
763 }
764
765 bool AcceptsMode_ET3K(Bitu mode) {
766 return mode <= 0x37 && mode != 0x2f && VideoModeMemSize(mode) < vga.vmemsize;
767 }
768
769 void SVGA_Setup_TsengET3K(void) {
770 svga.write_p3d5 = &write_p3d5_et3k;
771 svga.read_p3d5 = &read_p3d5_et3k;
772 svga.write_p3c5 = &write_p3c5_et3k;
773 svga.read_p3c5 = &read_p3c5_et3k;
774 svga.write_p3c0 = &write_p3c0_et3k;
775 svga.read_p3c1 = &read_p3c1_et3k;
776
777 svga.set_video_mode = &FinishSetMode_ET3K;
778 svga.determine_mode = &DetermineMode_ET3K;
779 svga.set_clock = &SetClock_ET3K;
780 svga.get_clock = &GetClock_ET3K;
781 svga.accepts_mode = &AcceptsMode_ET3K;
782
783 VGA_SetClock(0,CLK_25);
784 VGA_SetClock(1,CLK_28);
785 VGA_SetClock(2,32400);
786 VGA_SetClock(3,35900);
787 VGA_SetClock(4,39900);
788 VGA_SetClock(5,44700);
789 VGA_SetClock(6,31400);
790 VGA_SetClock(7,37500);
791
792 IO_RegisterReadHandler(0x3cd,read_p3cd_et3k,IO_MB);
793 IO_RegisterWriteHandler(0x3cd,write_p3cd_et3k,IO_MB);
794
795 vga.vmemsize = 512*1024; // Cannot figure how this was supposed to work on the real card
796
797 // Tseng ROM signature
798 PhysPt rom_base=PhysMake(0xc000,0);
799 phys_writeb(rom_base+0x0075,' ');
800 phys_writeb(rom_base+0x0076,'T');
801 phys_writeb(rom_base+0x0077,'s');
802 phys_writeb(rom_base+0x0078,'e');
803 phys_writeb(rom_base+0x0079,'n');
804 phys_writeb(rom_base+0x007a,'g');
805 phys_writeb(rom_base+0x007b,' ');
806 }