Debian Codegraph @

src/hardware/vga_attr.cpp

raw ◀ ▶
1 Debian patch touch this file
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_attr.cpp,v 1.31 2009-06-28 14:56:13 c2woody Exp $ */
20
21 #include "dosbox.h"
22 #include "inout.h"
23 #include "vga.h"
24
25 #define attr(blah) vga.attr.blah
26
27 void VGA_ATTR_SetPalette(Bit8u index,Bit8u val) {
28 vga.attr.palette[index] = val;
29 if (vga.attr.mode_control & 0x80) val = (val&0xf) | (vga.attr.color_select << 4);
30 val &= 63;
31 val |= (vga.attr.color_select & 0xc) << 4;
32 if (GCC_UNLIKELY(machine==MCH_EGA)) {
33 if ((vga.crtc.vertical_total | ((vga.crtc.overflow & 1) << 8)) == 260) {
34 // check for intensity bit
35 if (val&0x10) val|=0x38;
36 else {
37 val&=0x7;
38 // check for special brown
39 if (val==6) val=0x14;
40 }
41 }
42 }
43 VGA_DAC_CombineColor(index,val);
44 }
45
46 Bitu read_p3c0(Bitu /*port*/,Bitu /*iolen*/) {
47 // Wcharts, Win 3.11 & 95 SVGA
48 Bitu retval = attr(index) & 0x1f;
49 if (!(attr(disabled) & 0x1)) retval |= 0x20;
50 return retval;
51 }
52
53 void write_p3c0(Bitu /*port*/,Bitu val,Bitu iolen) {
54 if (!vga.internal.attrindex) {
55 attr(index)=val & 0x1F;
56 vga.internal.attrindex=true;
57 if (val & 0x20) attr(disabled) &= ~1;
58 else attr(disabled) |= 1;
59 /*
60 0-4 Address of data register to write to port 3C0h or read from port 3C1h
61 5 If set screen output is enabled and the palette can not be modified,
62 if clear screen output is disabled and the palette can be modified.
63 */
64 return;
65 } else {
66 vga.internal.attrindex=false;
67 switch (attr(index)) {
68 /* Palette */
69 case 0x00: case 0x01: case 0x02: case 0x03:
70 case 0x04: case 0x05: case 0x06: case 0x07:
71 case 0x08: case 0x09: case 0x0a: case 0x0b:
72 case 0x0c: case 0x0d: case 0x0e: case 0x0f:
73 if (attr(disabled) & 0x1) VGA_ATTR_SetPalette(attr(index),(Bit8u)val);
74 /*
75 0-5 Index into the 256 color DAC table. May be modified by 3C0h index
76 10h and 14h.
77 */
78 break;
79 case 0x10: /* Mode Control Register */
80 if (!IS_VGA_ARCH) val&=0x1f; // not really correct, but should do it
81 if ((attr(mode_control) ^ val) & 0x80) {
82 attr(mode_control)^=0x80;
83 for (Bit8u i=0;i<0x10;i++) {
84 VGA_ATTR_SetPalette(i,vga.attr.palette[i]);
85 }
86 }
87 if ((attr(mode_control) ^ val) & 0x08) {
88 VGA_SetBlinking(val & 0x8);
89 }
90 if ((attr(mode_control) ^ val) & 0x04) {
91 attr(mode_control)=(Bit8u)val;
92 VGA_DetermineMode();
93 if ((IS_VGA_ARCH) && (svgaCard==SVGA_None)) VGA_StartResize();
94 } else {
95 attr(mode_control)=(Bit8u)val;
96 VGA_DetermineMode();
97 }
98
99 /*
100 0 Graphics mode if set, Alphanumeric mode else.
101 1 Monochrome mode if set, color mode else.
102 2 9-bit wide characters if set.
103 The 9th bit of characters C0h-DFh will be the same as
104 the 8th bit. Otherwise it will be the background color.
105 3 If set Attribute bit 7 is blinking, else high intensity.
106 5 If set the PEL panning register (3C0h index 13h) is temporarily set
107 to 0 from when the line compare causes a wrap around until the next
108 vertical retrace when the register is automatically reloaded with
109 the old value, else the PEL panning register ignores line compares.
110 6 If set pixels are 8 bits wide. Used in 256 color modes.
111 7 If set bit 4-5 of the index into the DAC table are taken from port
112 3C0h index 14h bit 0-1, else the bits in the palette register are
113 used.
114 */
115 break;
116 case 0x11: /* Overscan Color Register */
117 attr(overscan_color)=(Bit8u)val;
118 /* 0-5 Color of screen border. Color is defined as in the palette registers. */
119 break;
120 case 0x12: /* Color Plane Enable Register */
121 /* Why disable colour planes? */
122 attr(color_plane_enable)=(Bit8u)val;
123 /*
124 0 Bit plane 0 is enabled if set.
125 1 Bit plane 1 is enabled if set.
126 2 Bit plane 2 is enabled if set.
127 3 Bit plane 3 is enabled if set.
128 4-5 Video Status MUX. Diagnostics use only.
129 Two attribute bits appear on bits 4 and 5 of the Input Status
130 Register 1 (3dAh). 0: Bit 2/0, 1: Bit 5/4, 2: bit 3/1, 3: bit 7/6
131 */
132 break;
133 case 0x13: /* Horizontal PEL Panning Register */
134 attr(horizontal_pel_panning)=val & 0xF;
135 switch (vga.mode) {
136 case M_TEXT:
137 if ((val==0x7) && (svgaCard==SVGA_None)) vga.config.pel_panning=7;
138 if (val>0x7) vga.config.pel_panning=0;
139 else vga.config.pel_panning=(Bit8u)(val+1);
140 break;
141 case M_VGA:
142 case M_LIN8:
143 vga.config.pel_panning=(val & 0x7)/2;
144 break;
145 case M_LIN16:
146 default:
147 vga.config.pel_panning=(val & 0x7);
148 }
149 /*
150 0-3 Indicates number of pixels to shift the display left
151 Value 9bit textmode 256color mode Other modes
152 0 1 0 0
153 1 2 n/a 1
154 2 3 1 2
155 3 4 n/a 3
156 4 5 2 4
157 5 6 n/a 5
158 6 7 3 6
159 7 8 n/a 7
160 8 0 n/a n/a
161 */
162 break;
163 case 0x14: /* Color Select Register */
164 if (!IS_VGA_ARCH) {
165 attr(color_select)=0;
166 break;
167 }
168 if (attr(color_select) ^ val) {
169 attr(color_select)=(Bit8u)val;
170 for (Bit8u i=0;i<0x10;i++) {
171 VGA_ATTR_SetPalette(i,vga.attr.palette[i]);
172 }
173 }
174 /*
175 0-1 If 3C0h index 10h bit 7 is set these 2 bits are used as bits 4-5 of
176 the index into the DAC table.
177 2-3 These 2 bits are used as bit 6-7 of the index into the DAC table
178 except in 256 color mode.
179 Note: this register does not affect 256 color modes.
180 */
181 break;
182 default:
183 if (svga.write_p3c0) {
184 svga.write_p3c0(attr(index), val, iolen);
185 break;
186 }
•187 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:Write to unknown Index %2X",attr(index));
188 break;
189 }
190 }
191 }
192
193 Bitu read_p3c1(Bitu /*port*/,Bitu iolen) {
194 // vga.internal.attrindex=false;
195 switch (attr(index)) {
196 /* Palette */
197 case 0x00: case 0x01: case 0x02: case 0x03:
198 case 0x04: case 0x05: case 0x06: case 0x07:
199 case 0x08: case 0x09: case 0x0a: case 0x0b:
200 case 0x0c: case 0x0d: case 0x0e: case 0x0f:
201 return attr(palette[attr(index)]);
202 case 0x10: /* Mode Control Register */
203 return attr(mode_control);
204 case 0x11: /* Overscan Color Register */
205 return attr(overscan_color);
206 case 0x12: /* Color Plane Enable Register */
207 return attr(color_plane_enable);
208 case 0x13: /* Horizontal PEL Panning Register */
209 return attr(horizontal_pel_panning);
210 case 0x14: /* Color Select Register */
211 return attr(color_select);
212 default:
213 if (svga.read_p3c1)
214 return svga.read_p3c1(attr(index), iolen);
•215 LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:Read from unknown Index %2X",attr(index));
216 }
217 return 0;
218 }
219
220
221 void VGA_SetupAttr(void) {
222 if (IS_EGAVGA_ARCH) {
223 IO_RegisterWriteHandler(0x3c0,write_p3c0,IO_MB);
224 if (IS_VGA_ARCH) {
225 IO_RegisterReadHandler(0x3c0,read_p3c0,IO_MB);
226 IO_RegisterReadHandler(0x3c1,read_p3c1,IO_MB);
227 }
228 }
229 }