Debian Codegraph @

src/hardware/vga_dac.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 "inout.h"
21 #include "render.h"
22 #include "vga.h"
23
24 /*
25 3C6h (R/W): PEL Mask
26 bit 0-7 This register is anded with the palette index sent for each dot.
27 Should be set to FFh.
28
29 3C7h (R): DAC State Register
30 bit 0-1 0 indicates the DAC is in Write Mode and 3 indicates Read mode.
31
32 3C7h (W): PEL Address Read Mode
33 bit 0-7 The PEL data register (0..255) to be read from 3C9h.
34 Note: After reading the 3 bytes at 3C9h this register will increment,
35 pointing to the next data register.
36
37 3C8h (R/W): PEL Address Write Mode
38 bit 0-7 The PEL data register (0..255) to be written to 3C9h.
39 Note: After writing the 3 bytes at 3C9h this register will increment, pointing
40 to the next data register.
41
42 3C9h (R/W): PEL Data Register
43 bit 0-5 Color value
44 Note: Each read or write of this register will cycle through first the
45 registers for Red, Blue and Green, then increment the appropriate
46 address register, thus the entire palette can be loaded by writing 0 to
47 the PEL Address Write Mode register 3C8h and then writing all 768 bytes
48 of the palette to this register.
49 */
50
51 enum {DAC_READ,DAC_WRITE};
52
53 static void VGA_DAC_SendColor( Bitu index, Bitu src ) {
54 const Bit8u red = vga.dac.rgb[src].red;
55 const Bit8u green = vga.dac.rgb[src].green;
56 const Bit8u blue = vga.dac.rgb[src].blue;
57 //Set entry in 16bit output lookup table
58 vga.dac.xlat16[index] = ((blue>>1)&0x1f) | (((green)&0x3f)<<5) | (((red>>1)&0x1f) << 11);
59
60 RENDER_SetPal( index, (red << 2) | ( red >> 4 ), (green << 2) | ( green >> 4 ), (blue << 2) | ( blue >> 4 ) );
61 }
62
63 static void VGA_DAC_UpdateColor( Bitu index ) {
64 Bitu maskIndex = index & vga.dac.pel_mask;
65 VGA_DAC_SendColor( index, maskIndex );
66 }
67
68 static void write_p3c6(Bitu port,Bitu val,Bitu iolen) {
69 if ( vga.dac.pel_mask != val ) {
70 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:DCA:Pel Mask set to %X", val);
71 vga.dac.pel_mask = val;
72 for ( Bitu i = 0;i<256;i++)
73 VGA_DAC_UpdateColor( i );
74 }
75 }
76
77
78 static Bitu read_p3c6(Bitu port,Bitu iolen) {
79 return vga.dac.pel_mask;
80 }
81
82
83 static void write_p3c7(Bitu port,Bitu val,Bitu iolen) {
84 vga.dac.read_index=val;
85 vga.dac.pel_index=0;
86 vga.dac.state=DAC_READ;
87 vga.dac.write_index= val + 1;
88 }
89
90 static Bitu read_p3c7(Bitu port,Bitu iolen) {
91 if (vga.dac.state==DAC_READ) return 0x3;
92 else return 0x0;
93 }
94
95 static void write_p3c8(Bitu port,Bitu val,Bitu iolen) {
96 vga.dac.write_index=val;
97 vga.dac.pel_index=0;
98 vga.dac.state=DAC_WRITE;
99 }
100
101 static Bitu read_p3c8(Bitu port, Bitu iolen){
102 return vga.dac.write_index;
103 }
104
105 static void write_p3c9(Bitu port,Bitu val,Bitu iolen) {
106 val&=0x3f;
107 switch (vga.dac.pel_index) {
108 case 0:
109 vga.dac.rgb[vga.dac.write_index].red=val;
110 vga.dac.pel_index=1;
111 break;
112 case 1:
113 vga.dac.rgb[vga.dac.write_index].green=val;
114 vga.dac.pel_index=2;
115 break;
116 case 2:
117 vga.dac.rgb[vga.dac.write_index].blue=val;
118 switch (vga.mode) {
119 case M_VGA:
120 case M_LIN8:
121 VGA_DAC_UpdateColor( vga.dac.write_index );
122 if ( GCC_UNLIKELY( vga.dac.pel_mask != 0xff)) {
123 Bitu index = vga.dac.write_index;
124 if ( (index & vga.dac.pel_mask) == index ) {
125 for ( Bitu i = index+1;i<256;i++)
126 if ( (i & vga.dac.pel_mask) == index )
127 VGA_DAC_UpdateColor( i );
128 }
129 }
130 break;
131 default:
132 /* Check for attributes and DAC entry link */
133 for (Bitu i=0;i<16;i++) {
134 if (vga.dac.combine[i]==vga.dac.write_index) {
135 VGA_DAC_SendColor( i, vga.dac.write_index );
136 }
137 }
138 }
139 vga.dac.write_index++;
140 // vga.dac.read_index = vga.dac.write_index - 1;//disabled as it breaks Wari
141 vga.dac.pel_index=0;
142 break;
143 default:
144 LOG(LOG_VGAGFX,LOG_NORMAL)("VGA:DAC:Illegal Pel Index"); //If this can actually happen that will be the day
145 break;
146 };
147 }
148
149 static Bitu read_p3c9(Bitu port,Bitu iolen) {
150 Bit8u ret;
151 switch (vga.dac.pel_index) {
152 case 0:
153 ret=vga.dac.rgb[vga.dac.read_index].red;
154 vga.dac.pel_index=1;
155 break;
156 case 1:
157 ret=vga.dac.rgb[vga.dac.read_index].green;
158 vga.dac.pel_index=2;
159 break;
160 case 2:
161 ret=vga.dac.rgb[vga.dac.read_index].blue;
162 vga.dac.read_index++;
163 vga.dac.pel_index=0;
164 // vga.dac.write_index=vga.dac.read_index+1;//disabled as it breaks wari
165 break;
166 default:
167 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:DAC:Illegal Pel Index"); //If this can actually happen that will be the day
168 ret=0;
169 break;
170 }
171 return ret;
172 }
173
174 void VGA_DAC_CombineColor(Bit8u attr,Bit8u pal) {
175 /* Check if this is a new color */
176 vga.dac.combine[attr]=pal;
177 switch (vga.mode) {
178 case M_LIN8:
179 break;
180 case M_VGA:
181 // used by copper demo; almost no video card seems to suport it
182 if(!IS_VGA_ARCH || (svgaCard!=SVGA_None)) break;
183 default:
184 VGA_DAC_SendColor( attr, pal );
185 }
186 }
187
188 void VGA_DAC_SetEntry(Bitu entry,Bit8u red,Bit8u green,Bit8u blue) {
189 //Should only be called in machine != vga
190 vga.dac.rgb[entry].red=red;
191 vga.dac.rgb[entry].green=green;
192 vga.dac.rgb[entry].blue=blue;
193 for (Bitu i=0;i<16;i++)
194 if (vga.dac.combine[i]==entry)
195 VGA_DAC_SendColor( i, i );
196 }
197
198 void VGA_SetupDAC(void) {
199 vga.dac.first_changed=256;
200 vga.dac.bits=6;
201 vga.dac.pel_mask=0xff;
202 vga.dac.pel_index=0;
203 vga.dac.state=DAC_READ;
204 vga.dac.read_index=0;
205 vga.dac.write_index=0;
206 if (IS_VGA_ARCH) {
207 /* Setup the DAC IO port Handlers */
208 IO_RegisterWriteHandler(0x3c6,write_p3c6,IO_MB);
209 IO_RegisterReadHandler(0x3c6,read_p3c6,IO_MB);
210 IO_RegisterWriteHandler(0x3c7,write_p3c7,IO_MB);
211 IO_RegisterReadHandler(0x3c7,read_p3c7,IO_MB);
212 IO_RegisterWriteHandler(0x3c8,write_p3c8,IO_MB);
213 IO_RegisterReadHandler(0x3c8,read_p3c8,IO_MB);
214 IO_RegisterWriteHandler(0x3c9,write_p3c9,IO_MB);
215 IO_RegisterReadHandler(0x3c9,read_p3c9,IO_MB);
216 } else if (machine==MCH_EGA) {
217 for (Bitu i=0;i<64;i++) {
218 if ((i&4)>0) vga.dac.rgb[i].red=0x2a;
219 else vga.dac.rgb[i].red=0;
220 if ((i&32)>0) vga.dac.rgb[i].red+=0x15;
221
222 if ((i&2)>0) vga.dac.rgb[i].green=0x2a;
223 else vga.dac.rgb[i].green=0;
224 if ((i&16)>0) vga.dac.rgb[i].green+=0x15;
225
226 if ((i&1)>0) vga.dac.rgb[i].blue=0x2a;
227 else vga.dac.rgb[i].blue=0;
228 if ((i&8)>0) vga.dac.rgb[i].blue+=0x15;
229 }
230 }
231 }