Debian Codegraph @

src/ints/int10_pal.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 #include "dosbox.h"
20 #include "mem.h"
21 #include "inout.h"
22 #include "int10.h"
23
24 #define ACTL_MAX_REG 0x14
25
26 static INLINE void ResetACTL(void) {
27 IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6);
28 }
29
30 static INLINE void WriteTandyACTL(Bit8u creg,Bit8u val) {
31 IO_Write(VGAREG_TDY_ADDRESS,creg);
32 if (machine==MCH_TANDY) IO_Write(VGAREG_TDY_DATA,val);
33 else IO_Write(VGAREG_PCJR_DATA,val);
34 }
35
36 void INT10_SetSinglePaletteRegister(Bit8u reg,Bit8u val) {
37 switch (machine) {
38 case TANDY_ARCH_CASE:
39 IO_Read(VGAREG_TDY_RESET);
40 WriteTandyACTL(reg+0x10,val);
41 break;
42 case EGAVGA_ARCH_CASE:
43 if (!IS_VGA_ARCH) reg&=0x1f;
44 if(reg<=ACTL_MAX_REG) {
45 ResetACTL();
46 IO_Write(VGAREG_ACTL_ADDRESS,reg);
47 IO_Write(VGAREG_ACTL_WRITE_DATA,val);
48 }
49 IO_Write(VGAREG_ACTL_ADDRESS,32); //Enable output and protect palette
50 break;
51 }
52 }
53
54
55 void INT10_SetOverscanBorderColor(Bit8u val) {
56 switch (machine) {
57 case TANDY_ARCH_CASE:
58 IO_Read(VGAREG_TDY_RESET);
59 WriteTandyACTL(0x02,val);
60 break;
61 case EGAVGA_ARCH_CASE:
62 ResetACTL();
63 IO_Write(VGAREG_ACTL_ADDRESS,0x11);
64 IO_Write(VGAREG_ACTL_WRITE_DATA,val);
65 IO_Write(VGAREG_ACTL_ADDRESS,32); //Enable output and protect palette
66 break;
67 }
68 }
69
70 void INT10_SetAllPaletteRegisters(PhysPt data) {
71 switch (machine) {
72 case TANDY_ARCH_CASE:
73 IO_Read(VGAREG_TDY_RESET);
74 // First the colors
75 for(Bit8u i=0;i<0x10;i++) {
76 WriteTandyACTL(i+0x10,mem_readb(data));
77 data++;
78 }
79 // Then the border
80 WriteTandyACTL(0x02,mem_readb(data));
81 break;
82 case EGAVGA_ARCH_CASE:
83 ResetACTL();
84 // First the colors
85 for(Bit8u i=0;i<0x10;i++) {
86 IO_Write(VGAREG_ACTL_ADDRESS,i);
87 IO_Write(VGAREG_ACTL_WRITE_DATA,mem_readb(data));
88 data++;
89 }
90 // Then the border
91 IO_Write(VGAREG_ACTL_ADDRESS,0x11);
92 IO_Write(VGAREG_ACTL_WRITE_DATA,mem_readb(data));
93 IO_Write(VGAREG_ACTL_ADDRESS,32); //Enable output and protect palette
94 break;
95 }
96 }
97
98 void INT10_ToggleBlinkingBit(Bit8u state) {
99 Bit8u value;
100 // state&=0x01;
101 if ((state>1) && (svgaCard==SVGA_S3Trio)) return;
102 ResetACTL();
103
104 IO_Write(VGAREG_ACTL_ADDRESS,0x10);
105 value=IO_Read(VGAREG_ACTL_READ_DATA);
106 if (state<=1) {
107 value&=0xf7;
108 value|=state<<3;
109 }
110
111 ResetACTL();
112 IO_Write(VGAREG_ACTL_ADDRESS,0x10);
113 IO_Write(VGAREG_ACTL_WRITE_DATA,value);
114 IO_Write(VGAREG_ACTL_ADDRESS,32); //Enable output and protect palette
115
116 if (state<=1) {
117 Bit8u msrval=real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_MSR)&0xdf;
118 if (state) msrval|=0x20;
119 real_writeb(BIOSMEM_SEG,BIOSMEM_CURRENT_MSR,msrval);
120 }
121 }
122
123 void INT10_GetSinglePaletteRegister(Bit8u reg,Bit8u * val) {
124 if(reg<=ACTL_MAX_REG) {
125 ResetACTL();
126 IO_Write(VGAREG_ACTL_ADDRESS,reg+32);
127 *val=IO_Read(VGAREG_ACTL_READ_DATA);
128 IO_Write(VGAREG_ACTL_WRITE_DATA,*val);
129 }
130 }
131
132 void INT10_GetOverscanBorderColor(Bit8u * val) {
133 ResetACTL();
134 IO_Write(VGAREG_ACTL_ADDRESS,0x11+32);
135 *val=IO_Read(VGAREG_ACTL_READ_DATA);
136 IO_Write(VGAREG_ACTL_WRITE_DATA,*val);
137 }
138
139 void INT10_GetAllPaletteRegisters(PhysPt data) {
140 ResetACTL();
141 // First the colors
142 for(Bit8u i=0;i<0x10;i++) {
143 IO_Write(VGAREG_ACTL_ADDRESS,i);
144 mem_writeb(data,IO_Read(VGAREG_ACTL_READ_DATA));
145 ResetACTL();
146 data++;
147 }
148 // Then the border
149 IO_Write(VGAREG_ACTL_ADDRESS,0x11+32);
150 mem_writeb(data,IO_Read(VGAREG_ACTL_READ_DATA));
151 ResetACTL();
152 }
153
154 void INT10_SetSingleDacRegister(Bit8u index,Bit8u red,Bit8u green,Bit8u blue) {
155 IO_Write(VGAREG_DAC_WRITE_ADDRESS,(Bit8u)index);
156 IO_Write(VGAREG_DAC_DATA,red);
157 IO_Write(VGAREG_DAC_DATA,green);
158 IO_Write(VGAREG_DAC_DATA,blue);
159 }
160
161 void INT10_GetSingleDacRegister(Bit8u index,Bit8u * red,Bit8u * green,Bit8u * blue) {
162 IO_Write(VGAREG_DAC_READ_ADDRESS,index);
163 *red=IO_Read(VGAREG_DAC_DATA);
164 *green=IO_Read(VGAREG_DAC_DATA);
165 *blue=IO_Read(VGAREG_DAC_DATA);
166 }
167
168 void INT10_SetDACBlock(Bit16u index,Bit16u count,PhysPt data) {
169 IO_Write(VGAREG_DAC_WRITE_ADDRESS,(Bit8u)index);
170 for (;count>0;count--) {
171 IO_Write(VGAREG_DAC_DATA,mem_readb(data++));
172 IO_Write(VGAREG_DAC_DATA,mem_readb(data++));
173 IO_Write(VGAREG_DAC_DATA,mem_readb(data++));
174 }
175 }
176
177 void INT10_GetDACBlock(Bit16u index,Bit16u count,PhysPt data) {
178 IO_Write(VGAREG_DAC_READ_ADDRESS,(Bit8u)index);
179 for (;count>0;count--) {
180 mem_writeb(data++,IO_Read(VGAREG_DAC_DATA));
181 mem_writeb(data++,IO_Read(VGAREG_DAC_DATA));
182 mem_writeb(data++,IO_Read(VGAREG_DAC_DATA));
183 }
184 }
185
186 void INT10_SelectDACPage(Bit8u function,Bit8u mode) {
187 ResetACTL();
188 IO_Write(VGAREG_ACTL_ADDRESS,0x10);
189 Bit8u old10=IO_Read(VGAREG_ACTL_READ_DATA);
190 if (!function) { //Select paging mode
191 if (mode) old10|=0x80;
192 else old10&=0x7f;
193 //IO_Write(VGAREG_ACTL_ADDRESS,0x10);
194 IO_Write(VGAREG_ACTL_WRITE_DATA,old10);
195 } else { //Select page
196 IO_Write(VGAREG_ACTL_WRITE_DATA,old10);
197 if (!(old10 & 0x80)) mode<<=2;
198 mode&=0xf;
199 IO_Write(VGAREG_ACTL_ADDRESS,0x14);
200 IO_Write(VGAREG_ACTL_WRITE_DATA,mode);
201 }
202 IO_Write(VGAREG_ACTL_ADDRESS,32); //Enable output and protect palette
203 }
204
205 void INT10_GetDACPage(Bit8u* mode,Bit8u* page) {
206 ResetACTL();
207 IO_Write(VGAREG_ACTL_ADDRESS,0x10);
208 Bit8u reg10=IO_Read(VGAREG_ACTL_READ_DATA);
209 IO_Write(VGAREG_ACTL_WRITE_DATA,reg10);
210 *mode=(reg10&0x80)?0x01:0x00;
211 IO_Write(VGAREG_ACTL_ADDRESS,0x14);
212 *page=IO_Read(VGAREG_ACTL_READ_DATA);
213 IO_Write(VGAREG_ACTL_WRITE_DATA,*page);
214 if(*mode) {
215 *page&=0xf;
216 } else {
217 *page&=0xc;
218 *page>>=2;
219 }
220 }
221
222 void INT10_SetPelMask(Bit8u mask) {
223 IO_Write(VGAREG_PEL_MASK,mask);
224 }
225
226 void INT10_GetPelMask(Bit8u & mask) {
227 mask=IO_Read(VGAREG_PEL_MASK);
228 }
229
230 void INT10_SetBackgroundBorder(Bit8u val) {
231 Bit8u temp=real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAL);
232 temp=(temp & 0xe0) | (val & 0x1f);
233 real_writeb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAL,temp);
234 if (machine == MCH_CGA || IS_TANDY_ARCH)
235 IO_Write(0x3d9,temp);
236 else if (IS_EGAVGA_ARCH) {
237 val = ((val << 1) & 0x10) | (val & 0x7);
238 /* Aways set the overscan color */
239 INT10_SetSinglePaletteRegister( 0x11, val );
240 /* Don't set any extra colors when in text mode */
241 if (CurMode->mode <= 3)
242 return;
243 INT10_SetSinglePaletteRegister( 0, val );
244 val = (temp & 0x10) | 2 | ((temp & 0x20) >> 5);
245 INT10_SetSinglePaletteRegister( 1, val );
246 val+=2;
247 INT10_SetSinglePaletteRegister( 2, val );
248 val+=2;
249 INT10_SetSinglePaletteRegister( 3, val );
250 }
251 }
252
253 void INT10_SetColorSelect(Bit8u val) {
254 Bit8u temp=real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAL);
255 temp=(temp & 0xdf) | ((val & 1) ? 0x20 : 0x0);
256 real_writeb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAL,temp);
257 if (machine == MCH_CGA || IS_TANDY_ARCH)
258 IO_Write(0x3d9,temp);
259 else if (IS_EGAVGA_ARCH) {
260 if (CurMode->mode <= 3) //Maybe even skip the total function!
261 return;
262 val = (temp & 0x10) | 2 | val;
263 INT10_SetSinglePaletteRegister( 1, val );
264 val+=2;
265 INT10_SetSinglePaletteRegister( 2, val );
266 val+=2;
267 INT10_SetSinglePaletteRegister( 3, val );
268 }
269 }
270
271 void INT10_PerformGrayScaleSumming(Bit16u start_reg,Bit16u count) {
272 if (count>0x100) count=0x100;
273 for (Bitu ct=0; ct<count; ct++) {
274 IO_Write(VGAREG_DAC_READ_ADDRESS,start_reg+ct);
275 Bit8u red=IO_Read(VGAREG_DAC_DATA);
276 Bit8u green=IO_Read(VGAREG_DAC_DATA);
277 Bit8u blue=IO_Read(VGAREG_DAC_DATA);
278
279 /* calculate clamped intensity, taken from VGABIOS */
280 Bit32u i=(( 77*red + 151*green + 28*blue ) + 0x80) >> 8;
281 Bit8u ic=(i>0x3f) ? 0x3f : ((Bit8u)(i & 0xff));
282 INT10_SetSingleDacRegister(start_reg+ct,ic,ic,ic);
283 }
284 }