6 #define CRTC_ADDR_PORT (iobase | 4)
7 #define CRTC_DATA_PORT (iobase | 5)
10 #define CRTC_START_H 0x0c
11 #define CRTC_START_L 0x0d
12 #define CRTC_CURPOS_H 0x0e
13 #define CRTC_CURPOS_L 0x0f
15 static void detect_video(void);
16 static int detect_vgainfo(void);
17 static int detect_egainfo(void);
18 static void detect_eqlist(void);
19 static void crtc_write(int reg, unsigned char val);
21 static uint16_t __far *vmem;
24 static uint16_t cur_attr;
25 static int cur_x, cur_y;
26 static int cur_scroll;
36 vmem = MK_FP(0xb000, 0);
39 vmem = MK_FP(0xb800, 0);
46 static void detect_video(void)
52 if(detect_vgainfo() == 0) {
55 if(detect_egainfo() == 0) {
61 static int detect_vgainfo(void)
66 int86(0x10, ®s, ®s);
67 if(regs.h.al != 0x1a) {
110 static int detect_egainfo(void)
116 int86(0x10, ®s, ®s);
117 if(regs.h.bh == 0xff) {
126 static void detect_eqlist(void)
130 int86(0x11, ®s, ®s);
131 switch(regs.w.ax & 0x30) {
154 fmemset(vmem, 0, 80 * 25 * 2);
157 void vid_clearline(int row)
164 ptr = vmem + row * 80;
165 for(i=0; i<80; i++) {
170 /* write a copy to wrap-around future scrolling */
172 for(i=0; i<80; i++) {
181 for(i=0; i<25; i++) {
186 void vid_scroll(int line)
189 cur_scroll = line & 0x1f;
190 offs = cur_scroll * 80;
191 crtc_write(CRTC_START_H, offs >> 8);
192 crtc_write(CRTC_START_L, offs);
195 void vid_setcursor(int x, int y)
197 int loc = (y + cur_scroll) * 80 + x;
200 crtc_write(CRTC_CURPOS_H, loc >> 8);
201 crtc_write(CRTC_CURPOS_L, loc);
204 void vid_fgcolor(int color)
206 cur_attr = (cur_attr & 0xf0) | color;
209 void vid_bgcolor(int color)
211 cur_attr = (cur_attr & 0x0f) | (color << 4);
214 void vid_char(int x, int y, int c, int attr)
217 uint16_t val = c | (attr << 8);
221 ptr = vmem + y * 80 + x;
225 /* write a copy to wrap-around future scrolling */
231 void vid_text(int x, int y, const char *s, int attr)
238 ptr = vmem + y * 80 + x;
240 *ptr++ = *s++ | (attr << 8);
245 /* write a copy to wrap-around future scrolling */
246 ptr -= 80 * 32 + len;
249 *ptr++ = *s++ | (attr << 8);
254 void vid_putchar(int c)
260 vid_setcursor(0, cur_y);
264 if(cur_y >= cur_scroll + 25) {
265 vid_scroll(cur_scroll + 1);
266 vid_setcursor(0, cur_y);
268 vid_setcursor(0, cur_y + 1);
273 x = (cur_x + 8) & 0xf8;
277 vid_setcursor(x, cur_y);
282 vid_char(cur_x, cur_y, c, cur_attr);
283 if(cur_x + 1 >= 80) {
286 vid_setcursor(cur_x + 1, cur_y);
291 static void crtc_write(int reg, unsigned char val)
293 outp(CRTC_ADDR_PORT, reg);
294 outp(CRTC_DATA_PORT, val);