Debian Codegraph @

src/hardware/vga_s3.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_s3.cpp,v 1.18 2009-03-15 11:28:35 c2woody Exp $ */
20
21 #include "dosbox.h"
22 #include "inout.h"
23 #include "vga.h"
24 #include "mem.h"
25
26 void SVGA_S3_WriteCRTC(Bitu reg,Bitu val,Bitu iolen) {
27 switch (reg) {
28 case 0x31: /* CR31 Memory Configuration */
29 //TODO Base address
30 vga.s3.reg_31 = val;
31 vga.config.compatible_chain4 = !(val&0x08);
32 if (vga.config.compatible_chain4) vga.vmemwrap = 256*1024;
33 else vga.vmemwrap = vga.vmemsize;
34 vga.config.display_start = (vga.config.display_start&~0x30000)|((val&0x30)<<12);
35 VGA_DetermineMode();
36 VGA_SetupHandlers();
37 break;
38 /*
39 0 Enable Base Address Offset (CPUA BASE). Enables bank operation if
40 set, disables if clear.
41 1 Two Page Screen Image. If set enables 2048 pixel wide screen setup
42 2 VGA 16bit Memory Bus Width. Set for 16bit, clear for 8bit
43 3 Use Enhanced Mode Memory Mapping (ENH MAP). Set to enable access to
44 video memory above 256k.
45 4-5 Bit 16-17 of the Display Start Address. For the 801/5,928 see index
46 51h, for the 864/964 see index 69h.
47 6 High Speed Text Display Font Fetch Mode. If set enables Page Mode
48 for Alpha Mode Font Access.
49 7 (not 864/964) Extended BIOS ROM Space Mapped out. If clear the area
50 C6800h-C7FFFh is mapped out, if set it is accessible.
51 */
52 case 0x35: /* CR35 CRT Register Lock */
53 if (vga.s3.reg_lock1 != 0x48) return; //Needed for uvconfig detection
54 vga.s3.reg_35=val & 0xf0;
55 if ((vga.svga.bank_read & 0xf) ^ (val & 0xf)) {
56 vga.svga.bank_read&=0xf0;
57 vga.svga.bank_read|=val & 0xf;
58 vga.svga.bank_write = vga.svga.bank_read;
59 VGA_SetupHandlers();
60 }
61 break;
62 /*
63 0-3 CPU Base Address. 64k bank number. For the 801/5 and 928 see 3d4h
64 index 51h bits 2-3. For the 864/964 see index 6Ah.
65 4 Lock Vertical Timing Registers (LOCK VTMG). Locks 3d4h index 6, 7
66 (bits 0,2,3,5,7), 9 bit 5, 10h, 11h bits 0-3, 15h, 16h if set
67 5 Lock Horizontal Timing Registers (LOCK HTMG). Locks 3d4h index
68 0,1,2,3,4,5,17h bit 2 if set
69 6 (911/924) Lock VSync Polarity.
70 7 (911/924) Lock HSync Polarity.
71 */
72 case 0x38: /* CR38 Register Lock 1 */
73 vga.s3.reg_lock1=val;
74 break;
75 case 0x39: /* CR39 Register Lock 2 */
76 vga.s3.reg_lock2=val;
77 break;
78 case 0x3a:
79 vga.s3.reg_3a = val;
80 break;
81 case 0x40: /* CR40 System Config */
82 vga.s3.reg_40 = val;
83 break;
84 case 0x41: /* CR41 BIOS flags */
85 vga.s3.reg_41 = val;
86 break;
87 case 0x43: /* CR43 Extended Mode */
88 vga.s3.reg_43=val & ~0x4;
89 if (((val & 0x4) ^ (vga.config.scan_len >> 6)) & 0x4) {
90 vga.config.scan_len&=0x2ff;
91 vga.config.scan_len|=(val & 0x4) << 6;
92 VGA_CheckScanLength();
93 }
94 break;
95 /*
96 2 Logical Screen Width bit 8. Bit 8 of the Display Offset Register/
97 (3d4h index 13h). (801/5,928) Only active if 3d4h index 51h bits 4-5
98 are 0
99 */
100 case 0x45: /* Hardware cursor mode */
101 vga.s3.hgc.curmode = val;
102 // Activate hardware cursor code if needed
103 VGA_ActivateHardwareCursor();
104 break;
105 case 0x46:
106 vga.s3.hgc.originx = (vga.s3.hgc.originx & 0x00ff) | (val << 8);
107 break;
108 case 0x47: /* HGC orgX */
109 vga.s3.hgc.originx = (vga.s3.hgc.originx & 0xff00) | val;
110 break;
111 case 0x48:
112 vga.s3.hgc.originy = (vga.s3.hgc.originy & 0x00ff) | (val << 8);
113 break;
114 case 0x49: /* HGC orgY */
115 vga.s3.hgc.originy = (vga.s3.hgc.originy & 0xff00) | val;
116 break;
117 case 0x4A: /* HGC foreground stack */
118 if (vga.s3.hgc.fstackpos > 2) vga.s3.hgc.fstackpos = 0;
119 vga.s3.hgc.forestack[vga.s3.hgc.fstackpos] = val;
120 vga.s3.hgc.fstackpos++;
121 break;
122 case 0x4B: /* HGC background stack */
123 if (vga.s3.hgc.bstackpos > 2) vga.s3.hgc.bstackpos = 0;
124 vga.s3.hgc.backstack[vga.s3.hgc.bstackpos] = val;
125 vga.s3.hgc.bstackpos++;
126 break;
127 case 0x4c: /* HGC start address high byte*/
128 vga.s3.hgc.startaddr &=0xff;
129 vga.s3.hgc.startaddr |= ((val & 0xf) << 8);
130 if ((((Bitu)vga.s3.hgc.startaddr)<<10)+((64*64*2)/8) > vga.vmemsize) {
131 vga.s3.hgc.startaddr &= 0xff; // put it back to some sane area;
132 // if read back of this address is ever implemented this needs to change
133 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:S3:CRTC: HGC pattern address beyond video memory" );
134 }
135 break;
136 case 0x4d: /* HGC start address low byte*/
137 vga.s3.hgc.startaddr &=0xff00;
138 vga.s3.hgc.startaddr |= (val & 0xff);
139 break;
140 case 0x4e: /* HGC pattern start X */
141 vga.s3.hgc.posx = val & 0x3f; // bits 0-5
142 break;
143 case 0x4f: /* HGC pattern start Y */
144 vga.s3.hgc.posy = val & 0x3f; // bits 0-5
145 break;
146 case 0x50: // Extended System Control 1
147 vga.s3.reg_50 = val;
148 switch (val & S3_XGA_CMASK) {
149 case S3_XGA_32BPP: vga.s3.xga_color_mode = M_LIN32; break;
150 case S3_XGA_16BPP: vga.s3.xga_color_mode = M_LIN16; break;
151 case S3_XGA_8BPP: vga.s3.xga_color_mode = M_LIN8; break;
152 }
153 switch (val & S3_XGA_WMASK) {
154 case S3_XGA_1024: vga.s3.xga_screen_width = 1024; break;
155 case S3_XGA_1152: vga.s3.xga_screen_width = 1152; break;
156 case S3_XGA_640: vga.s3.xga_screen_width = 640; break;
157 case S3_XGA_800: vga.s3.xga_screen_width = 800; break;
158 case S3_XGA_1280: vga.s3.xga_screen_width = 1280; break;
159 default: vga.s3.xga_screen_width = 1024; break;
160 }
161 break;
162 case 0x51: /* Extended System Control 2 */
163 vga.s3.reg_51=val & 0xc0; //Only store bits 6,7
164 vga.config.display_start&=0xF3FFFF;
165 vga.config.display_start|=(val & 3) << 18;
166 if ((vga.svga.bank_read&0x30) ^ ((val&0xc)<<2)) {
167 vga.svga.bank_read&=0xcf;
168 vga.svga.bank_read|=(val&0xc)<<2;
169 vga.svga.bank_write = vga.svga.bank_read;
170 VGA_SetupHandlers();
171 }
172 if (((val & 0x30) ^ (vga.config.scan_len >> 4)) & 0x30) {
173 vga.config.scan_len&=0xff;
174 vga.config.scan_len|=(val & 0x30) << 4;
175 VGA_CheckScanLength();
176 }
177 break;
178 /*
179 0 (80x) Display Start Address bit 18
180 0-1 (928 +) Display Start Address bit 18-19
181 Bits 16-17 are in index 31h bits 4-5, Bits 0-15 are in 3d4h index
182 0Ch,0Dh. For the 864/964 see 3d4h index 69h
183 2 (80x) CPU BASE. CPU Base Address Bit 18.
184 2-3 (928 +) Old CPU Base Address Bits 19-18.
185 64K Bank register bits 4-5. Bits 0-3 are in 3d4h index 35h.
186 For the 864/964 see 3d4h index 6Ah
187 4-5 Logical Screen Width Bit [8-9]. Bits 8-9 of the CRTC Offset register
188 (3d4h index 13h). If this field is 0, 3d4h index 43h bit 2 is active
189 6 (928,964) DIS SPXF. Disable Split Transfers if set. Spilt Transfers
190 allows transferring one half of the VRAM shift register data while
191 the other half is being output. For the 964 Split Transfers
192 must be enabled in enhanced modes (4AE8h bit 0 set). Guess: They
193 probably can't time the VRAM load cycle closely enough while the
194 graphics engine is running.
195 7 (not 864/964) Enable EPROM Write. If set enables flash memory write
196 control to the BIOS ROM address
197 */
198 case 0x52: // Extended System Control 1
199 vga.s3.reg_52 = val;
200 break;
201 case 0x53:
202 // Map or unmap MMIO
203 // bit 4 = MMIO at A0000
204 // bit 3 = MMIO at LFB + 16M (should be fine if its always enabled for now)
205 if(vga.s3.ext_mem_ctrl!=val) {
206 vga.s3.ext_mem_ctrl = val;
207 VGA_SetupHandlers();
208 }
209 break;
210 case 0x55: /* Extended Video DAC Control */
211 vga.s3.reg_55=val;
212 break;
213 /*
214 0-1 DAC Register Select Bits. Passed to the RS2 and RS3 pins on the
215 RAMDAC, allowing access to all 8 or 16 registers on advanced RAMDACs.
216 If this field is 0, 3d4h index 43h bit 1 is active.
217 2 Enable General Input Port Read. If set DAC reads are disabled and the
218 STRD strobe for reading the General Input Port is enabled for reading
219 while DACRD is active, if clear DAC reads are enabled.
220 3 (928) Enable External SID Operation if set. If set video data is
221 passed directly from the VRAMs to the DAC rather than through the
222 VGA chip
223 4 Hardware Cursor MS/X11 Mode. If set the Hardware Cursor is in X11
224 mode, if clear in MS-Windows mode
225 5 (80x,928) Hardware Cursor External Operation Mode. If set the two
226 bits of cursor data ,is output on the HC[0-1] pins for the video DAC
227 The SENS pin becomes HC1 and the MID2 pin becomes HC0.
228 6 ??
229 7 (80x,928) Disable PA Output. If set PA[0-7] and VCLK are tristated.
230 (864/964) TOFF VCLK. Tri-State Off VCLK Output. VCLK output tri
231 -stated if set
232 */
233 case 0x58: /* Linear Address Window Control */
234 vga.s3.reg_58=val;
235 break;
236 /*
237 0-1 Linear Address Window Size. Must be less than or equal to video
238 memory size. 0: 64K, 1: 1MB, 2: 2MB, 3: 4MB (928)/8Mb (864/964)
239 2 (not 864/964) Enable Read Ahead Cache if set
240 3 (80x,928) ISA Latch Address. If set latches address during every ISA
241 cycle, unlatches during every ISA cycle if clear.
242 (864/964) LAT DEL. Address Latch Delay Control (VL-Bus only). If set
243 address latching occours in the T1 cycle, if clear in the T2 cycle
244 (I.e. one clock cycle delayed).
245 4 ENB LA. Enable Linear Addressing if set.
246 5 (not 864/964) Limit Entry Depth for Write-Post. If set limits Write
247 -Post Entry Depth to avoid ISA bus timeout due to wait cycle limit.
248 6 (928,964) Serial Access Mode (SAM) 256 Words Control. If set SAM
249 control is 256 words, if clear 512 words.
250 7 (928) RAS 6-MCLK. If set the random read/write cycle time is 6MCLKs,
251 if clear 7MCLKs
252 */
253 case 0x59: /* Linear Address Window Position High */
254 if ((vga.s3.la_window&0xff00) ^ (val << 8)) {
255 vga.s3.la_window=(vga.s3.la_window&0x00ff) | (val << 8);
256 VGA_StartUpdateLFB();
257 }
258 break;
259 case 0x5a: /* Linear Address Window Position Low */
260 if ((vga.s3.la_window&0x00ff) ^ val) {
261 vga.s3.la_window=(vga.s3.la_window&0xff00) | val;
262 VGA_StartUpdateLFB();
263 }
264 break;
265 case 0x5D: /* Extended Horizontal Overflow */
266 if ((val ^ vga.s3.ex_hor_overflow) & 3) {
267 vga.s3.ex_hor_overflow=val;
268 VGA_StartResize();
269 } else vga.s3.ex_hor_overflow=val;
270 break;
271 /*
272 0 Horizontal Total bit 8. Bit 8 of the Horizontal Total register (3d4h
273 index 0)
274 1 Horizontal Display End bit 8. Bit 8 of the Horizontal Display End
275 register (3d4h index 1)
276 2 Start Horizontal Blank bit 8. Bit 8 of the Horizontal Start Blanking
277 register (3d4h index 2).
278 3 (864,964) EHB+64. End Horizontal Blank +64. If set the /BLANK pulse
279 is extended by 64 DCLKs. Note: Is this bit 6 of 3d4h index 3 or
280 does it really extend by 64 ?
281 4 Start Horizontal Sync Position bit 8. Bit 8 of the Horizontal Start
282 Retrace register (3d4h index 4).
283 5 (864,964) EHS+32. End Horizontal Sync +32. If set the HSYNC pulse
284 is extended by 32 DCLKs. Note: Is this bit 5 of 3d4h index 5 or
285 does it really extend by 32 ?
286 6 (928,964) Data Transfer Position bit 8. Bit 8 of the Data Transfer
287 Position register (3d4h index 3Bh)
288 7 (928,964) Bus-Grant Terminate Position bit 8. Bit 8 of the Bus Grant
289 Termination register (3d4h index 5Fh).
290 */
291 case 0x5e: /* Extended Vertical Overflow */
292 vga.config.line_compare=(vga.config.line_compare & 0x3ff) | (val & 0x40) << 4;
293 if ((val ^ vga.s3.ex_ver_overflow) & 0x3) {
294 vga.s3.ex_ver_overflow=val;
295 VGA_StartResize();
296 } else vga.s3.ex_ver_overflow=val;
297 break;
298 /*
299 0 Vertical Total bit 10. Bit 10 of the Vertical Total register (3d4h
300 index 6). Bits 8 and 9 are in 3d4h index 7 bit 0 and 5.
301 1 Vertical Display End bit 10. Bit 10 of the Vertical Display End
302 register (3d4h index 12h). Bits 8 and 9 are in 3d4h index 7 bit 1
303 and 6
304 2 Start Vertical Blank bit 10. Bit 10 of the Vertical Start Blanking
305 register (3d4h index 15h). Bit 8 is in 3d4h index 7 bit 3 and bit 9
306 in 3d4h index 9 bit 5
307 4 Vertical Retrace Start bit 10. Bit 10 of the Vertical Start Retrace
308 register (3d4h index 10h). Bits 8 and 9 are in 3d4h index 7 bit 2
309 and 7.
310 6 Line Compare Position bit 10. Bit 10 of the Line Compare register
311 (3d4h index 18h). Bit 8 is in 3d4h index 7 bit 4 and bit 9 in 3d4h
312 index 9 bit 6.
313 */
314 case 0x67: /* Extended Miscellaneous Control 2 */
315 /*
316 0 VCLK PHS. VCLK Phase With Respect to DCLK. If clear VLKC is inverted
317 DCLK, if set VCLK = DCLK.
318 2-3 (Trio64V+) streams mode
319 00 disable Streams Processor
320 01 overlay secondary stream on VGA-mode background
321 10 reserved
322 11 full Streams Processor operation
323 4-7 Pixel format.
324 0 Mode 0: 8bit (1 pixel/VCLK)
325 1 Mode 8: 8bit (2 pixels/VCLK)
326 3 Mode 9: 15bit (1 pixel/VCLK)
327 5 Mode 10: 16bit (1 pixel/VCLK)
328 7 Mode 11: 24/32bit (2 VCLKs/pixel)
329 13 (732/764) 32bit (1 pixel/VCLK)
330 */
331 vga.s3.misc_control_2=val;
332 VGA_DetermineMode();
333 break;
334 case 0x69: /* Extended System Control 3 */
335 if (((vga.config.display_start & 0x1f0000)>>16) ^ (val & 0x1f)) {
336 vga.config.display_start&=0xffff;
337 vga.config.display_start|=(val & 0x1f) << 16;
338 }
339 break;
340 case 0x6a: /* Extended System Control 4 */
341 vga.svga.bank_read=val & 0x7f;
342 vga.svga.bank_write = vga.svga.bank_read;
343 VGA_SetupHandlers();
344 break;
345 case 0x6b: // BIOS scratchpad: LFB adress
346 vga.s3.reg_6b=(Bit8u)val;
347 break;
348 default:
349 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:S3:CRTC:Write to illegal index %2X", reg );
350 break;
351 }
352 }
353
354 Bitu SVGA_S3_ReadCRTC( Bitu reg, Bitu iolen) {
355 switch (reg) {
356 case 0x24: /* attribute controller index (read only) */
357 case 0x26:
358 return ((vga.attr.disabled & 1)?0x00:0x20) | (vga.attr.index & 0x1f);
359 case 0x2d: /* Extended Chip ID (high byte of PCI device ID) */
360 return 0x88;
361 case 0x2e: /* New Chip ID (low byte of PCI device ID) */
362 return 0x11; // Trio64
363 case 0x2f: /* Revision */
364 return 0x00; // Trio64 (exact value?)
365 // return 0x44; // Trio64 V+
366 case 0x30: /* CR30 Chip ID/REV register */
367 return 0xe1; // Trio+ dual byte
368 case 0x31: /* CR31 Memory Configuration */
369 //TODO mix in bits from baseaddress;
370 return vga.s3.reg_31;
371 case 0x35: /* CR35 CRT Register Lock */
372 return vga.s3.reg_35|(vga.svga.bank_read & 0xf);
373 case 0x36: /* CR36 Reset State Read 1 */
374 return vga.s3.reg_36;
375 case 0x37: /* Reset state read 2 */
376 return 0x2b;
377 case 0x38: /* CR38 Register Lock 1 */
378 return vga.s3.reg_lock1;
379 case 0x39: /* CR39 Register Lock 2 */
380 return vga.s3.reg_lock2;
381 case 0x3a:
382 return vga.s3.reg_3a;
383 case 0x40: /* CR40 system config */
384 return vga.s3.reg_40;
385 case 0x41: /* CR40 system config */
386 return vga.s3.reg_41;
387 case 0x42: // not interlaced
388 return 0x0d;
389 case 0x43: /* CR43 Extended Mode */
390 return vga.s3.reg_43|((vga.config.scan_len>>6)&0x4);
391 case 0x45: /* Hardware cursor mode */
392 vga.s3.hgc.bstackpos = 0;
393 vga.s3.hgc.fstackpos = 0;
394 return vga.s3.hgc.curmode|0xa0;
395 case 0x46:
396 return vga.s3.hgc.originx>>8;
397 case 0x47: /* HGC orgX */
398 return vga.s3.hgc.originx&0xff;
399 case 0x48:
400 return vga.s3.hgc.originy>>8;
401 case 0x49: /* HGC orgY */
402 return vga.s3.hgc.originy&0xff;
403 case 0x4A: /* HGC foreground stack */
404 return vga.s3.hgc.forestack[vga.s3.hgc.fstackpos];
405 case 0x4B: /* HGC background stack */
406 return vga.s3.hgc.backstack[vga.s3.hgc.bstackpos];
407 case 0x50: // CR50 Extended System Control 1
408 return vga.s3.reg_50;
409 case 0x51: /* Extended System Control 2 */
410 return ((vga.config.display_start >> 16) & 3 ) |
411 ((vga.svga.bank_read & 0x30) >> 2) |
412 ((vga.config.scan_len & 0x300) >> 4) |
413 vga.s3.reg_51;
414 case 0x52: // CR52 Extended BIOS flags 1
415 return vga.s3.reg_52;
416 case 0x53:
417 return vga.s3.ext_mem_ctrl;
418 case 0x55: /* Extended Video DAC Control */
419 return vga.s3.reg_55;
420 case 0x58: /* Linear Address Window Control */
421 return vga.s3.reg_58;
422 case 0x59: /* Linear Address Window Position High */
423 return (vga.s3.la_window >> 8);
424 case 0x5a: /* Linear Address Window Position Low */
425 return (vga.s3.la_window & 0xff);
426 case 0x5D: /* Extended Horizontal Overflow */
427 return vga.s3.ex_hor_overflow;
428 case 0x5e: /* Extended Vertical Overflow */
429 return vga.s3.ex_ver_overflow;
430 case 0x67: /* Extended Miscellaneous Control 2 */
431 return vga.s3.misc_control_2;
432 case 0x69: /* Extended System Control 3 */
433 return (Bit8u)((vga.config.display_start & 0x1f0000)>>16);
434 case 0x6a: /* Extended System Control 4 */
435 return (Bit8u)(vga.svga.bank_read & 0x7f);
436 case 0x6b: // BIOS scatchpad: LFB address
437 return vga.s3.reg_6b;
438 default:
439 return 0x00;
440 }
441 }
442
443 void SVGA_S3_WriteSEQ(Bitu reg,Bitu val,Bitu iolen) {
444 if (reg>0x8 && vga.s3.pll.lock!=0x6) return;
445 switch (reg) {
446 case 0x08:
447 vga.s3.pll.lock=val;
448 break;
449 case 0x10: /* Memory PLL Data Low */
450 vga.s3.mclk.n=val & 0x1f;
451 vga.s3.mclk.r=val >> 5;
452 break;
453 case 0x11: /* Memory PLL Data High */
454 vga.s3.mclk.m=val & 0x7f;
455 break;
456 case 0x12: /* Video PLL Data Low */
457 vga.s3.clk[3].n=val & 0x1f;
458 vga.s3.clk[3].r=val >> 5;
459 break;
460 case 0x13: /* Video PLL Data High */
461 vga.s3.clk[3].m=val & 0x7f;
462 break;
463 case 0x15:
464 vga.s3.pll.cmd=val;
465 VGA_StartResize();
466 break;
467 default:
468 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:S3:SEQ:Write to illegal index %2X", reg );
469 break;
470 }
471 }
472
473 Bitu SVGA_S3_ReadSEQ(Bitu reg,Bitu iolen) {
474 /* S3 specific group */
475 if (reg>0x8 && vga.s3.pll.lock!=0x6) {
476 if (reg<0x1b) return 0;
477 else return reg;
478 }
479 switch (reg) {
480 case 0x08: /* PLL Unlock */
481 return vga.s3.pll.lock;
482 case 0x10: /* Memory PLL Data Low */
483 return vga.s3.mclk.n || (vga.s3.mclk.r << 5);
484 case 0x11: /* Memory PLL Data High */
485 return vga.s3.mclk.m;
486 case 0x12: /* Video PLL Data Low */
487 return vga.s3.clk[3].n || (vga.s3.clk[3].r << 5);
488 case 0x13: /* Video Data High */
489 return vga.s3.clk[3].m;
490 case 0x15:
491 return vga.s3.pll.cmd;
492 default:
493 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:S3:SEQ:Read from illegal index %2X", reg);
494 return 0;
495 }
496 }
497
498 Bitu SVGA_S3_GetClock(void) {
499 Bitu clock = (vga.misc_output >> 2) & 3;
500 if (clock == 0)
501 clock = 25175000;
502 else if (clock == 1)
503 clock = 28322000;
504 else
505 clock=1000*S3_CLOCK(vga.s3.clk[clock].m,vga.s3.clk[clock].n,vga.s3.clk[clock].r);
506 /* Check for dual transfer, master clock/2 */
507 if (vga.s3.pll.cmd & 0x10) clock/=2;
508 return clock;
509 }
510
511 bool SVGA_S3_HWCursorActive(void) {
512 return (vga.s3.hgc.curmode & 0x1) != 0;
513 }
514
515 bool SVGA_S3_AcceptsMode(Bitu mode) {
516 return VideoModeMemSize(mode) < vga.vmemsize;
517 }
518
519 void SVGA_Setup_S3Trio(void) {
520 svga.write_p3d5 = &SVGA_S3_WriteCRTC;
521 svga.read_p3d5 = &SVGA_S3_ReadCRTC;
522 svga.write_p3c5 = &SVGA_S3_WriteSEQ;
523 svga.read_p3c5 = &SVGA_S3_ReadSEQ;
524 svga.write_p3c0 = 0; /* no S3-specific functionality */
525 svga.read_p3c1 = 0; /* no S3-specific functionality */
526
527 svga.set_video_mode = 0; /* implemented in core */
528 svga.determine_mode = 0; /* implemented in core */
529 svga.set_clock = 0; /* implemented in core */
530 svga.get_clock = &SVGA_S3_GetClock;
531 svga.hardware_cursor_active = &SVGA_S3_HWCursorActive;
532 svga.accepts_mode = &SVGA_S3_AcceptsMode;
533
534 if (vga.vmemsize == 0)
535 vga.vmemsize = 2*1024*1024; // the most common S3 configuration
536
537 // Set CRTC 36 to specify amount of VRAM and PCI
538 if (vga.vmemsize < 1024*1024) {
539 vga.vmemsize = 512*1024;
540 vga.s3.reg_36 = 0xfa; // less than 1mb fast page mode
541 } else if (vga.vmemsize < 2048*1024) {
542 vga.vmemsize = 1024*1024;
543 vga.s3.reg_36 = 0xda; // 1mb fast page mode
544 } else if (vga.vmemsize < 3072*1024) {
545 vga.vmemsize = 2048*1024;
546 vga.s3.reg_36 = 0x9a; // 2mb fast page mode
547 } else if (vga.vmemsize < 4096*1024) {
548 vga.vmemsize = 3072*1024;
549 vga.s3.reg_36 = 0x5a; // 3mb fast page mode
550 } else { // Trio64 supported only up to 4M
551 vga.vmemsize = 4096*1024;
552 vga.s3.reg_36 = 0x1a; // 4mb fast page mode
553 }
554
555 // S3 ROM signature
556 PhysPt rom_base=PhysMake(0xc000,0);
557 phys_writeb(rom_base+0x003f,'S');
558 phys_writeb(rom_base+0x0040,'3');
559 phys_writeb(rom_base+0x0041,' ');
560 phys_writeb(rom_base+0x0042,'8');
561 phys_writeb(rom_base+0x0043,'6');
562 phys_writeb(rom_base+0x0044,'C');
563 phys_writeb(rom_base+0x0045,'7');
564 phys_writeb(rom_base+0x0046,'6');
565 phys_writeb(rom_base+0x0047,'4');
566 }