Debian Codegraph @

src/ints/int10_put_pixel.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: int10_put_pixel.cpp,v 1.23 2009-05-27 09:15:42 qbix79 Exp $ */
20
21 #include "dosbox.h"
22 #include "mem.h"
23 #include "inout.h"
24 #include "int10.h"
25
26 static Bit8u cga_masks[4]={0x3f,0xcf,0xf3,0xfc};
27 static Bit8u cga_masks2[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
28
29 void INT10_PutPixel(Bit16u x,Bit16u y,Bit8u page,Bit8u color) {
30 static bool putpixelwarned = false;
31
32 switch (CurMode->type) {
33 case M_CGA4:
34 {
35 if (real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE)<=5) {
36 Bit16u off=(y>>1)*80+(x>>2);
37 if (y&1) off+=8*1024;
38
39 Bit8u old=real_readb(0xb800,off);
40 if (color & 0x80) {
41 color&=3;
42 old^=color << (2*(3-(x&3)));
43 } else {
44 old=(old&cga_masks[x&3])|((color&3) << (2*(3-(x&3))));
45 }
46 real_writeb(0xb800,off,old);
47 } else {
48 Bit16u off=(y>>2)*160+((x>>2)&(~1));
49 off+=(8*1024) * (y & 3);
50
51 Bit16u old=real_readw(0xb800,off);
52 if (color & 0x80) {
53 old^=(color&1) << (7-(x&7));
54 old^=((color&2)>>1) << ((7-(x&7))+8);
55 } else {
56 old=(old&(~(0x101<<(7-(x&7))))) | ((color&1) << (7-(x&7))) | (((color&2)>>1) << ((7-(x&7))+8));
57 }
58 real_writew(0xb800,off,old);
59 }
60 }
61 break;
62 case M_CGA2:
63 {
64 Bit16u off=(y>>1)*80+(x>>3);
65 if (y&1) off+=8*1024;
66 Bit8u old=real_readb(0xb800,off);
67 if (color & 0x80) {
68 color&=1;
69 old^=color << ((7-(x&7)));
70 } else {
71 old=(old&cga_masks2[x&7])|((color&1) << ((7-(x&7))));
72 }
73 real_writeb(0xb800,off,old);
74 }
75 break;
76 case M_TANDY16:
77 {
78 IO_Write(0x3d4,0x09);
79 Bit8u scanlines_m1=IO_Read(0x3d5);
80 Bit16u off=(y>>((scanlines_m1==1)?1:2))*(CurMode->swidth>>1)+(x>>1);
81 off+=(8*1024) * (y & scanlines_m1);
82 Bit8u old=real_readb(0xb800,off);
83 Bit8u p[2];
84 p[1] = (old >> 4) & 0xf;
85 p[0] = old & 0xf;
86 Bitu ind = 1-(x & 0x1);
87
88 if (color & 0x80) {
89 p[ind]^=(color & 0x7f);
90 } else {
91 p[ind]=color;
92 }
93 old = (p[1] << 4) | p[0];
94 real_writeb(0xb800,off,old);
95 }
96 break;
97 case M_LIN4:
98 if ((machine!=MCH_VGA) || (svgaCard!=SVGA_TsengET4K) ||
99 (CurMode->swidth>800)) {
100 // the ET4000 BIOS supports text output in 800x600 SVGA (Gateway 2)
101 // putpixel warining?
102 break;
103 }
104 case M_EGA:
105 {
106 /* Set the correct bitmask for the pixel position */
107 IO_Write(0x3ce,0x8);Bit8u mask=128>>(x&7);IO_Write(0x3cf,mask);
108 /* Set the color to set/reset register */
109 IO_Write(0x3ce,0x0);IO_Write(0x3cf,color);
110 /* Enable all the set/resets */
111 IO_Write(0x3ce,0x1);IO_Write(0x3cf,0xf);
112 /* test for xorring */
113 if (color & 0x80) { IO_Write(0x3ce,0x3);IO_Write(0x3cf,0x18); }
114 //Perhaps also set mode 1
115 /* Calculate where the pixel is in video memory */
116 if (CurMode->plength!=(Bitu)real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE))
117 LOG(LOG_INT10,LOG_ERROR)("PutPixel_EGA_p: %x!=%x",CurMode->plength,real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE));
118 if (CurMode->swidth!=(Bitu)real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8)
119 LOG(LOG_INT10,LOG_ERROR)("PutPixel_EGA_w: %x!=%x",CurMode->swidth,real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
120 PhysPt off=0xa0000+real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE)*page+
121 ((y*real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8+x)>>3);
122 /* Bitmask and set/reset should do the rest */
123 mem_readb(off);
124 mem_writeb(off,0xff);
125 /* Restore bitmask */
126 IO_Write(0x3ce,0x8);IO_Write(0x3cf,0xff);
127 IO_Write(0x3ce,0x1);IO_Write(0x3cf,0);
128 /* Restore write operating if changed */
129 if (color & 0x80) { IO_Write(0x3ce,0x3);IO_Write(0x3cf,0x0); }
130 break;
131 }
132
133 case M_VGA:
134 mem_writeb(PhysMake(0xa000,y*320+x),color);
135 break;
136 case M_LIN8: {
137 if (CurMode->swidth!=(Bitu)real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8)
138 LOG(LOG_INT10,LOG_ERROR)("PutPixel_VGA_w: %x!=%x",CurMode->swidth,real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
139 PhysPt off=S3_LFB_BASE+y*real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8+x;
140 mem_writeb(off,color);
141 break;
142 }
143 default:
144 if(GCC_UNLIKELY(!putpixelwarned)) {
145 putpixelwarned = true;
146 LOG(LOG_INT10,LOG_ERROR)("PutPixel unhandled mode type %d",CurMode->type);
147 }
148 break;
149 }
150 }
151
152 void INT10_GetPixel(Bit16u x,Bit16u y,Bit8u page,Bit8u * color) {
153 switch (CurMode->type) {
154 case M_CGA4:
155 {
156 Bit16u off=(y>>1)*80+(x>>2);
157 if (y&1) off+=8*1024;
158 Bit8u val=real_readb(0xb800,off);
159 *color=(val>>(((3-(x&3)))*2)) & 3 ;
160 }
161 break;
162 case M_CGA2:
163 {
164 Bit16u off=(y>>1)*80+(x>>3);
165 if (y&1) off+=8*1024;
166 Bit8u val=real_readb(0xb800,off);
167 *color=(val>>(((7-(x&7))))) & 1 ;
168 }
169 break;
170 case M_EGA:
171 {
172 /* Calculate where the pixel is in video memory */
173 if (CurMode->plength!=(Bitu)real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE))
174 LOG(LOG_INT10,LOG_ERROR)("GetPixel_EGA_p: %x!=%x",CurMode->plength,real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE));
175 if (CurMode->swidth!=(Bitu)real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8)
176 LOG(LOG_INT10,LOG_ERROR)("GetPixel_EGA_w: %x!=%x",CurMode->swidth,real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
177 PhysPt off=0xa0000+real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE)*page+
178 ((y*real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8+x)>>3);
179 Bitu shift=7-(x & 7);
180 /* Set the read map */
181 *color=0;
182 IO_Write(0x3ce,0x4);IO_Write(0x3cf,0);
183 *color|=((mem_readb(off)>>shift) & 1) << 0;
184 IO_Write(0x3ce,0x4);IO_Write(0x3cf,1);
185 *color|=((mem_readb(off)>>shift) & 1) << 1;
186 IO_Write(0x3ce,0x4);IO_Write(0x3cf,2);
187 *color|=((mem_readb(off)>>shift) & 1) << 2;
188 IO_Write(0x3ce,0x4);IO_Write(0x3cf,3);
189 *color|=((mem_readb(off)>>shift) & 1) << 3;
190 break;
191 }
192 case M_VGA:
193 *color=mem_readb(PhysMake(0xa000,320*y+x));
194 break;
195 case M_LIN8: {
196 if (CurMode->swidth!=(Bitu)real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8)
197 LOG(LOG_INT10,LOG_ERROR)("GetPixel_VGA_w: %x!=%x",CurMode->swidth,real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
198 PhysPt off=S3_LFB_BASE+y*real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8+x;
199 *color = mem_readb(off);
200 break;
201 }
202 default:
203 LOG(LOG_INT10,LOG_ERROR)("GetPixel unhandled mode type %d",CurMode->type);
204 break;
205 }
206 }
207