b964be191cf894ced3b1ea5286d2dfa28de38340
3 #define VIDMEM_BASE 0xa0000
4 char* vidmem
= (char *)(VIDMEM_BASE
);
6 div_t div(int num
, int denom
)
9 if (num
> 0 && denom
< 0) {
15 if (num
< 0 && denom
> 0)
26 int mod(int num
, int denom
)
28 div_t dvt
= div(num
, denom
);
85 void vgaSetWriteMode(char mode
)
87 VideoPortWritePortUchar((PUCHAR
)0x03ce, 0x03);
88 VideoPortWritePortUchar((PUCHAR
)0x03cf, mode
);
91 void vgaSetColor(int cindex
, int red
, int green
, int blue
)
93 VideoPortWritePortUchar((PUCHAR
)0x03c8, cindex
);
94 VideoPortWritePortUchar((PUCHAR
)0x03c9, red
);
95 VideoPortWritePortUchar((PUCHAR
)0x03c9, green
);
96 VideoPortWritePortUchar((PUCHAR
)0x03c9, blue
);
99 void vgaPutPixel(int x
, int y
, unsigned char c
)
104 offset
= xconv
[x
]+y80
[y
];
106 VideoPortWritePortUchar((PUCHAR
)0x3ce,0x08); // Set
107 VideoPortWritePortUchar((PUCHAR
)0x3cf,maskbit
[x
]); // the MASK
108 VideoPortWritePortUshort((PUSHORT
)0x3ce,0x0205); // write mode = 2 (bits 0,1)
109 // read mode = 0 (bit 3
110 a
= vidmem
[offset
]; // Update bit buffer
111 vidmem
[offset
] = c
; // Write the pixel
114 void vgaPutByte(int x
, int y
, unsigned char c
)
118 offset
= xconv
[x
]+y80
[y
];
120 // Set mask to all pixels in byte
121 VideoPortWritePortUchar((PUCHAR
)0x3ce,0x08);
122 VideoPortWritePortUchar((PUCHAR
)0x3cf,0xff);
127 void vgaGetByte(unsigned offset
,
128 unsigned char *b
, unsigned char *g
,
129 unsigned char *r
, unsigned char *i
)
131 VideoPortWritePortUshort((PUSHORT
)0x03ce, 0x0304);
133 VideoPortWritePortUshort((PUSHORT
)0x03ce, 0x0204);
135 VideoPortWritePortUshort((PUSHORT
)0x03ce, 0x0104);
137 VideoPortWritePortUshort((PUSHORT
)0x03ce, 0x0004);
141 int vgaGetPixel(int x
, int y
)
143 unsigned char mask
, b
, g
, r
, i
;
146 offset
= xconv
[x
]+y80
[y
];
148 vgaGetByte(offset
, &b
, &g
, &r
, &i
);
160 return(b
+2*g
+4*r
+8*i
);
163 BOOL
vgaHLine(int x
, int y
, int len
, unsigned char c
)
166 unsigned int pre1
, i
;
167 unsigned int orgpre1
, orgx
, midpre1
;
168 unsigned long leftpixs
, midpixs
, rightpixs
, temp
;
174 for (i
=x
; i
<x
+len
; i
++)
175 vgaPutPixel(i
, y
, c
);
179 while(leftpixs
>8) leftpixs
-=8;
188 if((temp
>=0) && (midpixs
>0)) midpixs
--;
190 pre1
=xconv
[x
]+y80
[y
];
195 // Left edge should be an entire middle bar
201 VideoPortWritePortUchar((PUCHAR
)0x3ce,0x08); // Set
202 VideoPortWritePortUchar((PUCHAR
)0x3cf,startmasks
[leftpixs
]); // the MASK
203 VideoPortWritePortUshort((PUSHORT
)0x3ce,0x0205); // write mode = 2 (bits 0,1)
204 // read mode = 0 (bit 3
205 a
= vidmem
[pre1
]; // Update bit buffer
206 vidmem
[pre1
] = c
; // Write the pixel
209 x
=orgx
+(8-leftpixs
)+leftpixs
;
218 midpre1
=xconv
[x
]+y80
[y
];
220 // Set mask to all pixels in byte
221 VideoPortWritePortUchar((PUCHAR
)0x3ce, 0x08);
222 VideoPortWritePortUchar((PUCHAR
)0x3cf, 0xff);
223 memset(vidmem
+midpre1
, c
, midpixs
);
226 rightpixs
= len
- ((midpixs
*8) + leftpixs
);
230 x
=(orgx
+len
)-rightpixs
;
232 // Go backwards till we reach the 8-byte boundary
233 while(mod(x
, 8)!=0) { x
--; rightpixs
++; }
237 // This is a BAD case as this should have been a midpixs
244 pre1
=xconv
[x
]+y80
[y
];
245 VideoPortWritePortUchar((PUCHAR
)0x3ce,0x08); // Set
246 VideoPortWritePortUchar((PUCHAR
)0x3cf,endmasks
[rightpixs
]); // the MASK
247 VideoPortWritePortUshort((PUSHORT
)0x3ce,0x0205); // write mode = 2 (bits 0,1)
248 // read mode = 0 (bit 3
249 a
= vidmem
[pre1
]; // Update bit buffer
250 vidmem
[pre1
] = c
; // Write the pixel
257 BOOL
vgaVLine(int x
, int y
, int len
, unsigned char c
)
262 offset
= xconv
[x
]+y80
[y
];
264 VideoPortWritePortUchar((PUCHAR
)0x3ce,0x08); // Set
265 VideoPortWritePortUchar((PUCHAR
)0x3cf,maskbit
[x
]); // the MASK
266 VideoPortWritePortUshort((PUSHORT
)0x3ce,0x0205); // write mode = 2 (bits 0,1)
267 // read mode = 0 (bit 3)
270 for(i
=y
; i
<y
+len
; i
++)
272 a
= vidmem
[offset
]; // Update bit buffer
273 vidmem
[offset
] = c
; // Write the pixel