blob: d389692cf2440902c7119b8d1d349158c7540598 [file] [log] [blame]
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001// VGA bios implementation
2//
3// Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2001-2008 the LGPL VGABios developers Team
5//
6// This file may be distributed under the terms of the GNU LGPLv3 license.
7
8
9// TODO:
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040010// * introduce "struct vregs", or add ebp to struct bregs.
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040011// * define structs for save/restore state
12// * review correctness of converted asm by comparing with RBIL
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040013// * refactor redundant code into sub-functions
14// * See if there is a method to the in/out stuff that can be encapsulated.
15// * remove "biosfn" prefixes
16// * don't hardcode 0xc000
17// * add defs for 0xa000/0xb800
18// * verify all funcs static
19//
Kevin O'Connor6ace78f2009-05-14 19:24:49 -040020// * convert vbe/clext code
21//
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040022// * separate code into separate files
23// * extract hw code from bios interfaces
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040024
25#include "bregs.h" // struct bregs
26#include "biosvar.h" // GET_BDA
27#include "util.h" // memset
28#include "vgatables.h" // vga_modes
29
30// XXX
31#define CONFIG_VBE 0
32#define CONFIG_CIRRUS 0
33
34// XXX
35#define DEBUG_VGA_POST 1
36#define DEBUG_VGA_10 3
37
38#define SET_VGA(var, val) SET_FARVAR(0xc000, (var), (val))
39
40
41// ===================================================================
42//
43// Video Utils
44//
45// ===================================================================
46
47// -------------------------------------------------------------------
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040048inline void
49call16_vgaint(u32 eax, u32 ebx)
50{
51 asm volatile(
52 "int $0x10\n"
53 "cli\n"
54 "cld"
55 :
56 : "a"(eax), "b"(ebx)
57 : "cc", "memory");
58}
59
60// XXX
61inline void
62memcpy16_far(u16 d_seg, void *d_far, u16 s_seg, const void *s_far, size_t len)
63{
64 memcpy_far(d_seg, d_far, s_seg, s_far, len);
65}
66
67
68// ===================================================================
69//
70// BIOS functions
71//
72// ===================================================================
73
74// -------------------------------------------------------------------
75static void
76biosfn_perform_gray_scale_summing(u16 start, u16 count)
77{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040078 inb(VGAREG_ACTL_RESET);
79 outb(0x00, VGAREG_ACTL_ADDRESS);
80
Kevin O'Connordd2be772009-05-16 15:41:23 -040081 int i;
82 for (i = start; i < start+count; i++) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040083 // set read address and switch to read mode
Kevin O'Connordd2be772009-05-16 15:41:23 -040084 outb(i, VGAREG_DAC_READ_ADDRESS);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040085 // get 6-bit wide RGB data values
Kevin O'Connordd2be772009-05-16 15:41:23 -040086 u8 r = inb(VGAREG_DAC_DATA);
87 u8 g = inb(VGAREG_DAC_DATA);
88 u8 b = inb(VGAREG_DAC_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040089
90 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connordd2be772009-05-16 15:41:23 -040091 u16 intensity = ((77 * r + 151 * g + 28 * b) + 0x80) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040092
Kevin O'Connordd2be772009-05-16 15:41:23 -040093 if (intensity > 0x3f)
94 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040095
96 // set write address and switch to write mode
Kevin O'Connordd2be772009-05-16 15:41:23 -040097 outb(i, VGAREG_DAC_WRITE_ADDRESS);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040098 // write new intensity value
Kevin O'Connordd2be772009-05-16 15:41:23 -040099 outb(intensity & 0xff, VGAREG_DAC_DATA);
100 outb(intensity & 0xff, VGAREG_DAC_DATA);
101 outb(intensity & 0xff, VGAREG_DAC_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400102 }
103 inb(VGAREG_ACTL_RESET);
104 outb(0x20, VGAREG_ACTL_ADDRESS);
105}
106
107// -------------------------------------------------------------------
108static void
109biosfn_set_cursor_shape(u8 CH, u8 CL)
110{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400111 CH &= 0x3f;
112 CL &= 0x1f;
113
Kevin O'Connordd2be772009-05-16 15:41:23 -0400114 u16 curs = (CH << 8) + CL;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400115 SET_BDA(cursor_type, curs);
116
Kevin O'Connordd2be772009-05-16 15:41:23 -0400117 u8 modeset_ctl = GET_BDA(modeset_ctl);
118 u16 cheight = GET_BDA(char_height);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400119 if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400120 if (CL != (CH + 1))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400121 CH = ((CH + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -0400122 else
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400123 CH = ((CL + 1) * cheight / 8) - 2;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400124 CL = ((CL + 1) * cheight / 8) - 1;
125 }
126 // CTRC regs 0x0a and 0x0b
Kevin O'Connordd2be772009-05-16 15:41:23 -0400127 u16 crtc_addr = GET_BDA(crtc_address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400128 outb(0x0a, crtc_addr);
129 outb(CH, crtc_addr + 1);
130 outb(0x0b, crtc_addr);
131 outb(CL, crtc_addr + 1);
132}
133
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400134static u16
135biosfn_get_cursor_shape(u8 page)
136{
137 if (page > 7)
138 return 0;
139 // FIXME should handle VGA 14/16 lines
140 return GET_BDA(cursor_type);
141}
142
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400143// -------------------------------------------------------------------
144static void
145biosfn_set_cursor_pos(u8 page, u16 cursor)
146{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400147 // Should not happen...
148 if (page > 7)
149 return;
150
151 // Bios cursor pos
152 SET_BDA(cursor_pos[page], cursor);
153
154 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400155 u8 current = GET_BDA(video_page);
156 if (page != current)
157 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400158
Kevin O'Connordd2be772009-05-16 15:41:23 -0400159 // Get the dimensions
160 u16 nbcols = GET_BDA(video_cols);
161 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400162
Kevin O'Connordd2be772009-05-16 15:41:23 -0400163 u8 xcurs = cursor & 0x00ff;
164 u8 ycurs = (cursor & 0xff00) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400165
Kevin O'Connordd2be772009-05-16 15:41:23 -0400166 // Calculate the address knowing nbcols nbrows and page num
167 u16 address = SCREEN_IO_START(nbcols, nbrows, page) + xcurs + ycurs * nbcols;
168
169 // CRTC regs 0x0e and 0x0f
170 u16 crtc_addr = GET_BDA(crtc_address);
171 outb(0x0e, crtc_addr);
172 outb((address & 0xff00) >> 8, crtc_addr + 1);
173 outb(0x0f, crtc_addr);
174 outb(address & 0x00ff, crtc_addr + 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400175}
176
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400177static u16
178biosfn_get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400179{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400180 if (page > 7)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400181 return 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400182 // FIXME should handle VGA 14/16 lines
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400183 return GET_BDA(cursor_pos[page]);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400184}
185
186// -------------------------------------------------------------------
187static void
188biosfn_set_active_page(u8 page)
189{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400190 if (page > 7)
191 return;
192
193 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400194 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
195 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400196 return;
197
198 // Get pos curs pos for the right page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400199 u16 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400200
Kevin O'Connordd2be772009-05-16 15:41:23 -0400201 u16 address;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400202 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400203 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400204 u16 nbcols = GET_BDA(video_cols);
205 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400206
207 // Calculate the address knowing nbcols nbrows and page num
208 address = SCREEN_MEM_START(nbcols, nbrows, page);
209 SET_BDA(video_pagestart, address);
210
211 // Start address
212 address = SCREEN_IO_START(nbcols, nbrows, page);
213 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400214 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
215 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400216 }
217
218 // CRTC regs 0x0c and 0x0d
Kevin O'Connordd2be772009-05-16 15:41:23 -0400219 u16 crtc_addr = GET_BDA(crtc_address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400220 outb(0x0c, crtc_addr);
221 outb((address & 0xff00) >> 8, crtc_addr + 1);
222 outb(0x0d, crtc_addr);
223 outb(address & 0x00ff, crtc_addr + 1);
224
225 // And change the BIOS page
226 SET_BDA(video_page, page);
227
Kevin O'Connora12c2152009-05-13 22:06:16 -0400228 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400229
230 // Display the cursor, now the page is active
231 biosfn_set_cursor_pos(page, cursor);
232}
233
234static void
235biosfn_set_video_mode(u8 mode)
236{ // mode: Bit 7 is 1 if no clear screen
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400237 if (CONFIG_CIRRUS)
238 cirrus_set_video_mode(mode);
239
240#ifdef VBE
241 if (vbe_has_vbe_display())
242 dispi_set_enable(VBE_DISPI_DISABLED);
243#endif
244
245 // The real mode
Kevin O'Connordd2be772009-05-16 15:41:23 -0400246 u8 noclearmem = mode & 0x80;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400247 mode = mode & 0x7f;
248
249 // find the entry in the video modes
Kevin O'Connor5727c292009-05-16 17:29:32 -0400250 struct vgamode_s *vmode_g = find_vga_entry(mode);
251 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
252 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400253 return;
254
Kevin O'Connor5727c292009-05-16 17:29:32 -0400255 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
256 u16 twidth = GET_GLOBAL(vparam_g->twidth);
257 u16 theightm1 = GET_GLOBAL(vparam_g->theightm1);
258 u16 cheight = GET_GLOBAL(vparam_g->cheight);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400259
260 // Read the bios mode set control
Kevin O'Connordd2be772009-05-16 15:41:23 -0400261 u8 modeset_ctl = GET_BDA(modeset_ctl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400262
263 // Then we know the number of lines
264// FIXME
265
266 // if palette loading (bit 3 of modeset ctl = 0)
267 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
Kevin O'Connor5727c292009-05-16 17:29:32 -0400268 outb(GET_GLOBAL(vmode_g->pelmask), VGAREG_PEL_MASK);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400269
270 // Set the whole dac always, from 0
271 outb(0x00, VGAREG_DAC_WRITE_ADDRESS);
272
273 // From which palette
Kevin O'Connor5727c292009-05-16 17:29:32 -0400274 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
275 u16 palsize = GET_GLOBAL(vmode_g->dacsize);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400276 // Always 256*3 values
Kevin O'Connordd2be772009-05-16 15:41:23 -0400277 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400278 for (i = 0; i < 0x0100; i++) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400279 if (i <= palsize) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400280 outb(GET_GLOBAL(palette_g[(i * 3) + 0]), VGAREG_DAC_DATA);
281 outb(GET_GLOBAL(palette_g[(i * 3) + 1]), VGAREG_DAC_DATA);
282 outb(GET_GLOBAL(palette_g[(i * 3) + 2]), VGAREG_DAC_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400283 } else {
284 outb(0, VGAREG_DAC_DATA);
285 outb(0, VGAREG_DAC_DATA);
286 outb(0, VGAREG_DAC_DATA);
287 }
288 }
289 if ((modeset_ctl & 0x02) == 0x02)
290 biosfn_perform_gray_scale_summing(0x00, 0x100);
291 }
292 // Reset Attribute Ctl flip-flop
293 inb(VGAREG_ACTL_RESET);
294
295 // Set Attribute Ctl
Kevin O'Connordd2be772009-05-16 15:41:23 -0400296 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400297 for (i = 0; i <= 0x13; i++) {
298 outb(i, VGAREG_ACTL_ADDRESS);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400299 outb(GET_GLOBAL(vparam_g->actl_regs[i]), VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400300 }
301 outb(0x14, VGAREG_ACTL_ADDRESS);
302 outb(0x00, VGAREG_ACTL_WRITE_DATA);
303
304 // Set Sequencer Ctl
305 outb(0, VGAREG_SEQU_ADDRESS);
306 outb(0x03, VGAREG_SEQU_DATA);
307 for (i = 1; i <= 4; i++) {
308 outb(i, VGAREG_SEQU_ADDRESS);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400309 outb(GET_GLOBAL(vparam_g->sequ_regs[i - 1]), VGAREG_SEQU_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400310 }
311
312 // Set Grafx Ctl
313 for (i = 0; i <= 8; i++) {
314 outb(i, VGAREG_GRDC_ADDRESS);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400315 outb(GET_GLOBAL(vparam_g->grdc_regs[i]), VGAREG_GRDC_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400316 }
317
318 // Set CRTC address VGA or MDA
319 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400320 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400321 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
322
323 // Disable CRTC write protection
324 outw(0x0011, crtc_addr);
325 // Set CRTC regs
326 for (i = 0; i <= 0x18; i++) {
327 outb(i, crtc_addr);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400328 outb(GET_GLOBAL(vparam_g->crtc_regs[i]), crtc_addr + 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400329 }
330
331 // Set the misc register
Kevin O'Connor5727c292009-05-16 17:29:32 -0400332 outb(GET_GLOBAL(vparam_g->miscreg), VGAREG_WRITE_MISC_OUTPUT);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400333
334 // Enable video
335 outb(0x20, VGAREG_ACTL_ADDRESS);
336 inb(VGAREG_ACTL_RESET);
337
338 if (noclearmem == 0x00) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400339 if (GET_GLOBAL(vmode_g->class) == TEXT) {
340 memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0720, 32*1024);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400341 } else {
342 if (mode < 0x0d) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400343 memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 32*1024);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400344 } else {
345 outb(0x02, VGAREG_SEQU_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400346 u8 mmask = inb(VGAREG_SEQU_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400347 outb(0x0f, VGAREG_SEQU_DATA); // all planes
Kevin O'Connor5727c292009-05-16 17:29:32 -0400348 memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 64*1024);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400349 outb(mmask, VGAREG_SEQU_DATA);
350 }
351 }
352 }
353 // Set the BIOS mem
354 SET_BDA(video_mode, mode);
355 SET_BDA(video_cols, twidth);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400356 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400357 SET_BDA(crtc_address, crtc_addr);
358 SET_BDA(video_rows, theightm1);
359 SET_BDA(char_height, cheight);
360 SET_BDA(video_ctl, (0x60 | noclearmem));
361 SET_BDA(video_switches, 0xF9);
362 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
363
364 // FIXME We nearly have the good tables. to be reworked
365 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
366 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
367 SET_BDA(video_savetable_seg, 0xc000);
368
369 // FIXME
370 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
371 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
372
373 // Set cursor shape
Kevin O'Connor5727c292009-05-16 17:29:32 -0400374 if (GET_GLOBAL(vmode_g->class) == TEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400375 biosfn_set_cursor_shape(0x06, 0x07);
376 // Set cursor pos for page 0..7
377 for (i = 0; i < 8; i++)
378 biosfn_set_cursor_pos(i, 0x0000);
379
380 // Set active page 0
381 biosfn_set_active_page(0x00);
382
383 // Write the fonts in memory
Kevin O'Connor5727c292009-05-16 17:29:32 -0400384 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400385 call16_vgaint(0x1104, 0);
386 call16_vgaint(0x1103, 0);
387 }
388 // Set the ints 0x1F and 0x43
389 SET_IVT(0x1f, 0xC000, (u32)&vgafont8[128 * 8]);
390
391 switch (cheight) {
392 case 8:
393 SET_IVT(0x43, 0xC000, (u32)vgafont8);
394 break;
395 case 14:
396 SET_IVT(0x43, 0xC000, (u32)vgafont14);
397 break;
398 case 16:
399 SET_IVT(0x43, 0xC000, (u32)vgafont16);
400 break;
401 }
402}
403
404// -------------------------------------------------------------------
405static void
406vgamem_copy_pl4(u8 xstart, u8 ysrc, u8 ydest, u8 cols, u8 nbcols,
407 u8 cheight)
408{
409 u16 src = ysrc * cheight * nbcols + xstart;
410 u16 dest = ydest * cheight * nbcols + xstart;
411 outw(0x0105, VGAREG_GRDC_ADDRESS);
412 u8 i;
413 for (i = 0; i < cheight; i++)
414 memcpy_far(0xa000, (void*)(dest + i * nbcols)
415 , 0xa000, (void*)(src + i * nbcols), cols);
416 outw(0x0005, VGAREG_GRDC_ADDRESS);
417}
418
419// -------------------------------------------------------------------
420static void
421vgamem_fill_pl4(u8 xstart, u8 ystart, u8 cols, u8 nbcols, u8 cheight,
422 u8 attr)
423{
424 u16 dest = ystart * cheight * nbcols + xstart;
425 outw(0x0205, VGAREG_GRDC_ADDRESS);
426 u8 i;
427 for (i = 0; i < cheight; i++)
428 memset_far(0xa000, (void*)(dest + i * nbcols), attr, cols);
429 outw(0x0005, VGAREG_GRDC_ADDRESS);
430}
431
432// -------------------------------------------------------------------
433static void
434vgamem_copy_cga(u8 xstart, u8 ysrc, u8 ydest, u8 cols, u8 nbcols,
435 u8 cheight)
436{
437 u16 src = ((ysrc * cheight * nbcols) >> 1) + xstart;
438 u16 dest = ((ydest * cheight * nbcols) >> 1) + xstart;
439 u8 i;
440 for (i = 0; i < cheight; i++)
441 if (i & 1)
442 memcpy_far(0xb800, (void*)(0x2000 + dest + (i >> 1) * nbcols)
443 , 0xb800, (void*)(0x2000 + src + (i >> 1) * nbcols)
444 , cols);
445 else
446 memcpy_far(0xb800, (void*)(dest + (i >> 1) * nbcols)
447 , 0xb800, (void*)(src + (i >> 1) * nbcols), cols);
448}
449
450// -------------------------------------------------------------------
451static void
452vgamem_fill_cga(u8 xstart, u8 ystart, u8 cols, u8 nbcols, u8 cheight,
453 u8 attr)
454{
455 u16 dest = ((ystart * cheight * nbcols) >> 1) + xstart;
456 u8 i;
457 for (i = 0; i < cheight; i++)
458 if (i & 1)
459 memset_far(0xb800, (void*)(0x2000 + dest + (i >> 1) * nbcols)
460 , attr, cols);
461 else
462 memset_far(0xb800, (void*)(dest + (i >> 1) * nbcols), attr, cols);
463}
464
465// -------------------------------------------------------------------
466static void
467biosfn_scroll(u8 nblines, u8 attr, u8 rul, u8 cul, u8 rlr, u8 clr, u8 page,
468 u8 dir)
469{
470 // page == 0xFF if current
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400471 if (rul > rlr)
472 return;
473 if (cul > clr)
474 return;
475
476 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400477 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
478 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400479 return;
480
481 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400482 u16 nbrows = GET_BDA(video_rows) + 1;
483 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400484
485 // Get the current page
486 if (page == 0xFF)
487 page = GET_BDA(video_page);
488
489 if (rlr >= nbrows)
490 rlr = nbrows - 1;
491 if (clr >= nbcols)
492 clr = nbcols - 1;
493 if (nblines > nbrows)
494 nblines = 0;
Kevin O'Connordd2be772009-05-16 15:41:23 -0400495 u8 cols = clr - cul + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400496
Kevin O'Connor5727c292009-05-16 17:29:32 -0400497 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400498 // Compute the address
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400499 void *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page));
Kevin O'Connora5288ff2009-05-13 22:25:24 -0400500 dprintf(3, "Scroll, address %p (%d %d %02x)\n"
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400501 , address_far, nbrows, nbcols, page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400502
503 if (nblines == 0 && rul == 0 && cul == 0 && rlr == nbrows - 1
504 && clr == nbcols - 1) {
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400505 memset16_far(GET_GLOBAL(vmode_g->sstart), address_far
Kevin O'Connora5288ff2009-05-13 22:25:24 -0400506 , (u16)attr * 0x100 + ' ', nbrows * nbcols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400507 } else { // if Scroll up
508 if (dir == SCROLL_UP) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400509 u16 i;
510 for (i = rul; i <= rlr; i++)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400511 if ((i + nblines > rlr) || (nblines == 0))
Kevin O'Connor5727c292009-05-16 17:29:32 -0400512 memset16_far(GET_GLOBAL(vmode_g->sstart)
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400513 , address_far + (i * nbcols + cul) * 2
Kevin O'Connora5288ff2009-05-13 22:25:24 -0400514 , (u16)attr * 0x100 + ' ', cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400515 else
Kevin O'Connor5727c292009-05-16 17:29:32 -0400516 memcpy16_far(GET_GLOBAL(vmode_g->sstart)
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400517 , address_far + (i * nbcols + cul) * 2
Kevin O'Connor5727c292009-05-16 17:29:32 -0400518 , GET_GLOBAL(vmode_g->sstart)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400519 , (void*)(((i + nblines) * nbcols + cul) * 2)
Kevin O'Connora5288ff2009-05-13 22:25:24 -0400520 , cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400521 } else {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400522 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400523 for (i = rlr; i >= rul; i--) {
524 if ((i < rul + nblines) || (nblines == 0))
Kevin O'Connor5727c292009-05-16 17:29:32 -0400525 memset16_far(GET_GLOBAL(vmode_g->sstart)
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400526 , address_far + (i * nbcols + cul) * 2
Kevin O'Connora5288ff2009-05-13 22:25:24 -0400527 , (u16)attr * 0x100 + ' ', cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400528 else
Kevin O'Connor5727c292009-05-16 17:29:32 -0400529 memcpy16_far(GET_GLOBAL(vmode_g->sstart)
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400530 , address_far + (i * nbcols + cul) * 2
Kevin O'Connor5727c292009-05-16 17:29:32 -0400531 , GET_GLOBAL(vmode_g->sstart)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400532 , (void*)(((i - nblines) * nbcols + cul) * 2)
Kevin O'Connora5288ff2009-05-13 22:25:24 -0400533 , cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400534 if (i > rlr)
535 break;
536 }
537 }
538 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400539 return;
540 }
541
542 // FIXME gfx mode not complete
Kevin O'Connor5727c292009-05-16 17:29:32 -0400543 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
544 u8 cheight = GET_GLOBAL(vparam_g->cheight);
545 switch (GET_GLOBAL(vmode_g->memmodel)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400546 case PLANAR4:
547 case PLANAR1:
548 if (nblines == 0 && rul == 0 && cul == 0 && rlr == nbrows - 1
549 && clr == nbcols - 1) {
550 outw(0x0205, VGAREG_GRDC_ADDRESS);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400551 memset_far(GET_GLOBAL(vmode_g->sstart), 0, attr,
Kevin O'Connordd2be772009-05-16 15:41:23 -0400552 nbrows * nbcols * cheight);
553 outw(0x0005, VGAREG_GRDC_ADDRESS);
554 } else { // if Scroll up
555 if (dir == SCROLL_UP) {
556 u16 i;
557 for (i = rul; i <= rlr; i++)
558 if ((i + nblines > rlr) || (nblines == 0))
559 vgamem_fill_pl4(cul, i, cols, nbcols, cheight,
560 attr);
561 else
562 vgamem_copy_pl4(cul, i + nblines, i, cols,
563 nbcols, cheight);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400564 } else {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400565 u16 i;
566 for (i = rlr; i >= rul; i--) {
567 if ((i < rul + nblines) || (nblines == 0))
568 vgamem_fill_pl4(cul, i, cols, nbcols, cheight,
569 attr);
570 else
571 vgamem_copy_pl4(cul, i, i - nblines, cols,
572 nbcols, cheight);
573 if (i > rlr)
574 break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400575 }
576 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400577 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400578 break;
579 case CGA: {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400580 u8 bpp = GET_GLOBAL(vmode_g->pixbits);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400581 if (nblines == 0 && rul == 0 && cul == 0 && rlr == nbrows - 1
582 && clr == nbcols - 1) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400583 memset_far(GET_GLOBAL(vmode_g->sstart), 0, attr,
Kevin O'Connordd2be772009-05-16 15:41:23 -0400584 nbrows * nbcols * cheight * bpp);
585 } else {
586 if (bpp == 2) {
587 cul <<= 1;
588 cols <<= 1;
589 nbcols <<= 1;
590 }
591 // if Scroll up
592 if (dir == SCROLL_UP) {
593 u16 i;
594 for (i = rul; i <= rlr; i++)
595 if ((i + nblines > rlr) || (nblines == 0))
596 vgamem_fill_cga(cul, i, cols, nbcols, cheight,
597 attr);
598 else
599 vgamem_copy_cga(cul, i + nblines, i, cols,
600 nbcols, cheight);
601 } else {
602 u16 i;
603 for (i = rlr; i >= rul; i--) {
604 if ((i < rul + nblines) || (nblines == 0))
605 vgamem_fill_cga(cul, i, cols, nbcols, cheight,
606 attr);
607 else
608 vgamem_copy_cga(cul, i, i - nblines, cols,
609 nbcols, cheight);
610 if (i > rlr)
611 break;
612 }
613 }
614 }
615 break;
616 }
617 default:
618 dprintf(1, "Scroll in graphics mode\n");
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400619 }
620}
621
622// -------------------------------------------------------------------
623static void
624biosfn_read_char_attr(u8 page, u16 *car)
625{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400626 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400627 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
628 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400629 return;
630
631 // Get the cursor pos for the page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400632 u16 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400633 u8 xcurs = cursor & 0x00ff;
634 u8 ycurs = (cursor & 0xff00) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400635
636 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400637 u16 nbrows = GET_BDA(video_rows) + 1;
638 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400639
Kevin O'Connor5727c292009-05-16 17:29:32 -0400640 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400641 // Compute the address
Kevin O'Connordd2be772009-05-16 15:41:23 -0400642 u16 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page)
643 + (xcurs + ycurs * nbcols) * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400644
Kevin O'Connor5727c292009-05-16 17:29:32 -0400645 *car = GET_FARVAR(GET_GLOBAL(vmode_g->sstart), *address_far);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400646 } else {
647 // FIXME gfx mode
Kevin O'Connor6ace78f2009-05-14 19:24:49 -0400648 dprintf(1, "Read char in graphics mode\n");
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400649 }
650}
651
652// -------------------------------------------------------------------
653static void
654write_gfx_char_pl4(u8 car, u8 attr, u8 xcurs, u8 ycurs, u8 nbcols,
655 u8 cheight)
656{
Kevin O'Connordd2be772009-05-16 15:41:23 -0400657 u8 *fdata_g;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400658 switch (cheight) {
659 case 14:
Kevin O'Connordd2be772009-05-16 15:41:23 -0400660 fdata_g = vgafont14;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400661 break;
662 case 16:
Kevin O'Connordd2be772009-05-16 15:41:23 -0400663 fdata_g = vgafont16;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400664 break;
665 default:
Kevin O'Connordd2be772009-05-16 15:41:23 -0400666 fdata_g = vgafont8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400667 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400668 u16 addr = xcurs + ycurs * cheight * nbcols;
669 u16 src = car * cheight;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400670 outw(0x0f02, VGAREG_SEQU_ADDRESS);
671 outw(0x0205, VGAREG_GRDC_ADDRESS);
672 if (attr & 0x80)
673 outw(0x1803, VGAREG_GRDC_ADDRESS);
674 else
675 outw(0x0003, VGAREG_GRDC_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400676 u8 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400677 for (i = 0; i < cheight; i++) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400678 u8 *dest_far = (void*)(addr + i * nbcols);
679 u8 j;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400680 for (j = 0; j < 8; j++) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400681 u8 mask = 0x80 >> j;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400682 outw((mask << 8) | 0x08, VGAREG_GRDC_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400683 GET_FARVAR(0xa000, *dest_far);
684 if (GET_GLOBAL(fdata_g[src + i]) & mask)
685 SET_FARVAR(0xa000, *dest_far, attr & 0x0f);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400686 else
Kevin O'Connordd2be772009-05-16 15:41:23 -0400687 SET_FARVAR(0xa000, *dest_far, 0x00);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400688 }
689 }
690 outw(0xff08, VGAREG_GRDC_ADDRESS);
691 outw(0x0005, VGAREG_GRDC_ADDRESS);
692 outw(0x0003, VGAREG_GRDC_ADDRESS);
693}
694
695// -------------------------------------------------------------------
696static void
697write_gfx_char_cga(u8 car, u8 attr, u8 xcurs, u8 ycurs, u8 nbcols, u8 bpp)
698{
Kevin O'Connordd2be772009-05-16 15:41:23 -0400699 u8 *fdata_g = vgafont8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400700 u16 addr = (xcurs * bpp) + ycurs * 320;
701 u16 src = car * 8;
702 u8 i;
703 for (i = 0; i < 8; i++) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400704 u8 *dest_far = (void*)(addr + (i >> 1) * 80);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400705 if (i & 1)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400706 dest_far += 0x2000;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400707 u8 mask = 0x80;
708 if (bpp == 1) {
709 u8 data = 0;
710 if (attr & 0x80)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400711 data = GET_FARVAR(0xb800, *dest_far);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400712 u8 j;
713 for (j = 0; j < 8; j++) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400714 if (GET_GLOBAL(fdata_g[src + i]) & mask) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400715 if (attr & 0x80)
716 data ^= (attr & 0x01) << (7 - j);
717 else
718 data |= (attr & 0x01) << (7 - j);
719 }
720 mask >>= 1;
721 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400722 SET_FARVAR(0xb800, *dest_far, data);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400723 } else {
724 while (mask > 0) {
725 u8 data = 0;
726 if (attr & 0x80)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400727 data = GET_FARVAR(0xb800, *dest_far);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400728 u8 j;
729 for (j = 0; j < 4; j++) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400730 if (GET_GLOBAL(fdata_g[src + i]) & mask) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400731 if (attr & 0x80)
732 data ^= (attr & 0x03) << ((3 - j) * 2);
733 else
734 data |= (attr & 0x03) << ((3 - j) * 2);
735 }
736 mask >>= 1;
737 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400738 SET_FARVAR(0xb800, *dest_far, data);
739 dest_far += 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400740 }
741 }
742 }
743}
744
745// -------------------------------------------------------------------
746static void
747write_gfx_char_lin(u8 car, u8 attr, u8 xcurs, u8 ycurs, u8 nbcols)
748{
Kevin O'Connordd2be772009-05-16 15:41:23 -0400749 u8 *fdata_g = vgafont8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400750 u16 addr = xcurs * 8 + ycurs * nbcols * 64;
751 u16 src = car * 8;
752 u8 i;
753 for (i = 0; i < 8; i++) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400754 u8 *dest_far = (void*)(addr + i * nbcols * 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400755 u8 mask = 0x80;
756 u8 j;
757 for (j = 0; j < 8; j++) {
758 u8 data = 0x00;
Kevin O'Connordd2be772009-05-16 15:41:23 -0400759 if (GET_GLOBAL(fdata_g[src + i]) & mask)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400760 data = attr;
Kevin O'Connordd2be772009-05-16 15:41:23 -0400761 SET_FARVAR(0xa000, dest_far[j], data);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400762 mask >>= 1;
763 }
764 }
765}
766
767// -------------------------------------------------------------------
768static void
769biosfn_write_char_attr(u8 car, u8 page, u8 attr, u16 count)
770{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400771 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400772 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
773 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400774 return;
775
776 // Get the cursor pos for the page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400777 u16 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400778 u8 xcurs = cursor & 0x00ff;
779 u8 ycurs = (cursor & 0xff00) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400780
781 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400782 u16 nbrows = GET_BDA(video_rows) + 1;
783 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400784
Kevin O'Connor5727c292009-05-16 17:29:32 -0400785 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400786 // Compute the address
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400787 void *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page)
788 + (xcurs + ycurs * nbcols) * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400789
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400790 u16 dummy = ((u16)attr << 8) + car;
Kevin O'Connorf94ec432009-05-16 17:37:23 -0400791 memset16_far(GET_GLOBAL(vmode_g->sstart), address_far, dummy, count * 2);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400792 return;
793 }
794
795 // FIXME gfx mode not complete
Kevin O'Connor5727c292009-05-16 17:29:32 -0400796 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
797 u8 cheight = GET_GLOBAL(vparam_g->cheight);
798 u8 bpp = GET_GLOBAL(vmode_g->pixbits);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400799 while ((count-- > 0) && (xcurs < nbcols)) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400800 switch (GET_GLOBAL(vmode_g->memmodel)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400801 case PLANAR4:
802 case PLANAR1:
803 write_gfx_char_pl4(car, attr, xcurs, ycurs, nbcols,
804 cheight);
805 break;
806 case CGA:
807 write_gfx_char_cga(car, attr, xcurs, ycurs, nbcols, bpp);
808 break;
809 case LINEAR8:
810 write_gfx_char_lin(car, attr, xcurs, ycurs, nbcols);
811 break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400812 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400813 xcurs++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400814 }
815}
816
817// -------------------------------------------------------------------
818static void
819biosfn_write_char_only(u8 car, u8 page, u8 attr, u16 count)
820{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400821 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400822 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
823 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400824 return;
825
826 // Get the cursor pos for the page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400827 u16 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400828 u8 xcurs = cursor & 0x00ff;
829 u8 ycurs = (cursor & 0xff00) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400830
831 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400832 u16 nbrows = GET_BDA(video_rows) + 1;
833 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400834
Kevin O'Connor5727c292009-05-16 17:29:32 -0400835 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400836 // Compute the address
Kevin O'Connordd2be772009-05-16 15:41:23 -0400837 u8 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page)
838 + (xcurs + ycurs * nbcols) * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400839 while (count-- > 0) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400840 SET_FARVAR(GET_GLOBAL(vmode_g->sstart), *address_far, car);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400841 address_far += 2;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400842 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400843 return;
844 }
845
846 // FIXME gfx mode not complete
Kevin O'Connor5727c292009-05-16 17:29:32 -0400847 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
848 u8 cheight = GET_GLOBAL(vparam_g->cheight);
849 u8 bpp = GET_GLOBAL(vmode_g->pixbits);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400850 while ((count-- > 0) && (xcurs < nbcols)) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400851 switch (GET_GLOBAL(vmode_g->memmodel)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400852 case PLANAR4:
853 case PLANAR1:
854 write_gfx_char_pl4(car, attr, xcurs, ycurs, nbcols,
855 cheight);
856 break;
857 case CGA:
858 write_gfx_char_cga(car, attr, xcurs, ycurs, nbcols, bpp);
859 break;
860 case LINEAR8:
861 write_gfx_char_lin(car, attr, xcurs, ycurs, nbcols);
862 break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400863 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400864 xcurs++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400865 }
866}
867
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400868// -------------------------------------------------------------------
869static void
870biosfn_set_border_color(struct bregs *regs)
871{
872 inb(VGAREG_ACTL_RESET);
873 outb(0x00, VGAREG_ACTL_ADDRESS);
874 u8 al = regs->bl & 0x0f;
875 if (al & 0x08)
876 al += 0x08;
Kevin O'Connord9fc0a02009-05-07 22:00:25 -0400877 outb(al, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400878 u8 bl = regs->bl & 0x10;
879
880 int i;
881 for (i = 1; i < 4; i++) {
882 outb(i, VGAREG_ACTL_ADDRESS);
883
884 al = inb(VGAREG_ACTL_READ_DATA);
885 al &= 0xef;
886 al |= bl;
Kevin O'Connord9fc0a02009-05-07 22:00:25 -0400887 outb(al, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400888 }
889 outb(0x20, VGAREG_ACTL_ADDRESS);
890}
891
892static void
893biosfn_set_palette(struct bregs *regs)
894{
895 inb(VGAREG_ACTL_RESET);
896 u8 bl = regs->bl & 0x01;
897 int i;
898 for (i = 1; i < 4; i++) {
899 outb(i, VGAREG_ACTL_ADDRESS);
900
901 u8 al = inb(VGAREG_ACTL_READ_DATA);
902 al &= 0xfe;
903 al |= bl;
Kevin O'Connord9fc0a02009-05-07 22:00:25 -0400904 outb(al, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400905 }
906 outb(0x20, VGAREG_ACTL_ADDRESS);
907}
908
909// -------------------------------------------------------------------
910static void
911biosfn_write_pixel(u8 BH, u8 AL, u16 CX, u16 DX)
912{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400913 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400914 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
915 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400916 return;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400917 if (GET_GLOBAL(vmode_g->class) == TEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400918 return;
919
Kevin O'Connordd2be772009-05-16 15:41:23 -0400920 u8 *addr_far, mask, attr, data;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400921 switch (GET_GLOBAL(vmode_g->memmodel)) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400922 case PLANAR4:
923 case PLANAR1:
Kevin O'Connordd2be772009-05-16 15:41:23 -0400924 addr_far = (void*)(CX / 8 + DX * GET_BDA(video_cols));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400925 mask = 0x80 >> (CX & 0x07);
926 outw((mask << 8) | 0x08, VGAREG_GRDC_ADDRESS);
927 outw(0x0205, VGAREG_GRDC_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400928 data = GET_FARVAR(0xa000, *addr_far);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400929 if (AL & 0x80)
930 outw(0x1803, VGAREG_GRDC_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400931 SET_FARVAR(0xa000, *addr_far, AL);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400932 outw(0xff08, VGAREG_GRDC_ADDRESS);
933 outw(0x0005, VGAREG_GRDC_ADDRESS);
934 outw(0x0003, VGAREG_GRDC_ADDRESS);
935 break;
936 case CGA:
Kevin O'Connor5727c292009-05-16 17:29:32 -0400937 if (GET_GLOBAL(vmode_g->pixbits) == 2)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400938 addr_far = (void*)((CX >> 2) + (DX >> 1) * 80);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400939 else
Kevin O'Connordd2be772009-05-16 15:41:23 -0400940 addr_far = (void*)((CX >> 3) + (DX >> 1) * 80);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400941 if (DX & 1)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400942 addr_far += 0x2000;
943 data = GET_FARVAR(0xb800, *addr_far);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400944 if (GET_GLOBAL(vmode_g->pixbits) == 2) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400945 attr = (AL & 0x03) << ((3 - (CX & 0x03)) * 2);
946 mask = 0x03 << ((3 - (CX & 0x03)) * 2);
947 } else {
948 attr = (AL & 0x01) << (7 - (CX & 0x07));
949 mask = 0x01 << (7 - (CX & 0x07));
950 }
951 if (AL & 0x80) {
952 data ^= attr;
953 } else {
954 data &= ~mask;
955 data |= attr;
956 }
Kevin O'Connordd2be772009-05-16 15:41:23 -0400957 SET_FARVAR(0xb800, *addr_far, data);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400958 break;
959 case LINEAR8:
Kevin O'Connordd2be772009-05-16 15:41:23 -0400960 addr_far = (void*)(CX + DX * (GET_BDA(video_cols) * 8));
961 SET_FARVAR(0xa000, *addr_far, AL);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400962 break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400963 }
964}
965
966// -------------------------------------------------------------------
967static void
968biosfn_read_pixel(u8 BH, u16 CX, u16 DX, u16 *AX)
969{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400970 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400971 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
972 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400973 return;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400974 if (GET_GLOBAL(vmode_g->class) == TEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400975 return;
976
Kevin O'Connor5727c292009-05-16 17:29:32 -0400977 u8 *addr_far, mask, attr=0, data, i;
978 switch (GET_GLOBAL(vmode_g->memmodel)) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400979 case PLANAR4:
980 case PLANAR1:
Kevin O'Connordd2be772009-05-16 15:41:23 -0400981 addr_far = (void*)(CX / 8 + DX * GET_BDA(video_cols));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400982 mask = 0x80 >> (CX & 0x07);
983 attr = 0x00;
984 for (i = 0; i < 4; i++) {
985 outw((i << 8) | 0x04, VGAREG_GRDC_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400986 data = GET_FARVAR(0xa000, *addr_far) & mask;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400987 if (data > 0)
988 attr |= (0x01 << i);
989 }
990 break;
991 case CGA:
Kevin O'Connordd2be772009-05-16 15:41:23 -0400992 addr_far = (void*)((CX >> 2) + (DX >> 1) * 80);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400993 if (DX & 1)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400994 addr_far += 0x2000;
995 data = GET_FARVAR(0xb800, *addr_far);
Kevin O'Connor5727c292009-05-16 17:29:32 -0400996 if (GET_GLOBAL(vmode_g->pixbits) == 2)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400997 attr = (data >> ((3 - (CX & 0x03)) * 2)) & 0x03;
998 else
999 attr = (data >> (7 - (CX & 0x07))) & 0x01;
1000 break;
1001 case LINEAR8:
Kevin O'Connordd2be772009-05-16 15:41:23 -04001002 addr_far = (void*)(CX + DX * (GET_BDA(video_cols) * 8));
1003 attr = GET_FARVAR(0xa000, *addr_far);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001004 break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001005 }
1006 *AX = (*AX & 0xff00) | attr;
1007}
1008
1009// -------------------------------------------------------------------
1010static void
1011biosfn_write_teletype(u8 car, u8 page, u8 attr, u8 flag)
1012{ // flag = WITH_ATTR / NO_ATTR
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001013 // special case if page is 0xff, use current page
1014 if (page == 0xff)
1015 page = GET_BDA(video_page);
1016
1017 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -04001018 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
1019 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001020 return;
1021
1022 // Get the cursor pos for the page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -04001023 u16 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001024 u8 xcurs = cursor & 0x00ff;
1025 u8 ycurs = (cursor & 0xff00) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001026
1027 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -04001028 u16 nbrows = GET_BDA(video_rows) + 1;
1029 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001030
1031 switch (car) {
1032 case 7:
1033 //FIXME should beep
1034 break;
1035
1036 case 8:
1037 if (xcurs > 0)
1038 xcurs--;
1039 break;
1040
1041 case '\r':
1042 xcurs = 0;
1043 break;
1044
1045 case '\n':
1046 ycurs++;
1047 break;
1048
1049 case '\t':
1050 do {
1051 biosfn_write_teletype(' ', page, attr, flag);
Kevin O'Connor0818e1a2009-05-16 18:00:19 -04001052 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001053 xcurs = cursor & 0x00ff;
1054 ycurs = (cursor & 0xff00) >> 8;
1055 } while (xcurs % 8 == 0);
1056 break;
1057
1058 default:
1059
Kevin O'Connor5727c292009-05-16 17:29:32 -04001060 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001061 // Compute the address
Kevin O'Connordd2be772009-05-16 15:41:23 -04001062 u8 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page)
1063 + (xcurs + ycurs * nbcols) * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001064 // Write the char
Kevin O'Connor5727c292009-05-16 17:29:32 -04001065 SET_FARVAR(GET_GLOBAL(vmode_g->sstart), address_far[0], car);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001066 if (flag == WITH_ATTR)
Kevin O'Connor5727c292009-05-16 17:29:32 -04001067 SET_FARVAR(GET_GLOBAL(vmode_g->sstart), address_far[1], attr);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001068 } else {
1069 // FIXME gfx mode not complete
Kevin O'Connor5727c292009-05-16 17:29:32 -04001070 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
1071 u8 cheight = GET_GLOBAL(vparam_g->cheight);
1072 u8 bpp = GET_GLOBAL(vmode_g->pixbits);
1073 switch (GET_GLOBAL(vmode_g->memmodel)) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001074 case PLANAR4:
1075 case PLANAR1:
Kevin O'Connor5727c292009-05-16 17:29:32 -04001076 write_gfx_char_pl4(car, attr, xcurs, ycurs, nbcols, cheight);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001077 break;
1078 case CGA:
1079 write_gfx_char_cga(car, attr, xcurs, ycurs, nbcols, bpp);
1080 break;
1081 case LINEAR8:
1082 write_gfx_char_lin(car, attr, xcurs, ycurs, nbcols);
1083 break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001084 }
1085 }
1086 xcurs++;
1087 }
1088
1089 // Do we need to wrap ?
1090 if (xcurs == nbcols) {
1091 xcurs = 0;
1092 ycurs++;
1093 }
1094 // Do we need to scroll ?
1095 if (ycurs == nbrows) {
Kevin O'Connor5727c292009-05-16 17:29:32 -04001096 if (GET_GLOBAL(vmode_g->class) == TEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001097 biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page,
1098 SCROLL_UP);
1099 else
1100 biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page,
1101 SCROLL_UP);
1102 ycurs -= 1;
1103 }
1104 // Set the cursor for the page
1105 cursor = ycurs;
1106 cursor <<= 8;
1107 cursor += xcurs;
1108 biosfn_set_cursor_pos(page, cursor);
1109}
1110
1111// -------------------------------------------------------------------
1112static void
1113biosfn_get_video_mode(struct bregs *regs)
1114{
1115 regs->bh = GET_BDA(video_page);
1116 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
1117 regs->ah = GET_BDA(video_cols);
1118}
1119
1120// -------------------------------------------------------------------
1121static void
1122biosfn_set_overscan_border_color(struct bregs *regs)
1123{
1124 inb(VGAREG_ACTL_RESET);
1125 outb(0x11, VGAREG_ACTL_ADDRESS);
Kevin O'Connord9fc0a02009-05-07 22:00:25 -04001126 outb(regs->bh, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001127 outb(0x20, VGAREG_ACTL_ADDRESS);
1128}
1129
1130// -------------------------------------------------------------------
1131static void
1132biosfn_set_all_palette_reg(struct bregs *regs)
1133{
1134 inb(VGAREG_ACTL_RESET);
1135
Kevin O'Connordd2be772009-05-16 15:41:23 -04001136 u8 *data_far = (u8*)(regs->dx + 0);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001137 int i;
1138 for (i = 0; i < 0x10; i++) {
1139 outb(i, VGAREG_ACTL_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001140 u8 val = GET_FARVAR(regs->es, *data_far);
Kevin O'Connord9fc0a02009-05-07 22:00:25 -04001141 outb(val, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001142 data_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001143 }
1144 outb(0x11, VGAREG_ACTL_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001145 outb(GET_FARVAR(regs->es, *data_far), VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001146 outb(0x20, VGAREG_ACTL_ADDRESS);
1147}
1148
1149// -------------------------------------------------------------------
1150static void
1151biosfn_toggle_intensity(struct bregs *regs)
1152{
1153 inb(VGAREG_ACTL_RESET);
1154 outb(0x10, VGAREG_ACTL_ADDRESS);
1155 u8 val = (inb(VGAREG_ACTL_READ_DATA) & 0x7f) | ((regs->bl & 0x01) << 3);
Kevin O'Connord9fc0a02009-05-07 22:00:25 -04001156 outb(val, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001157 outb(0x20, VGAREG_ACTL_ADDRESS);
1158}
1159
1160// -------------------------------------------------------------------
1161void
1162biosfn_set_single_palette_reg(u8 reg, u8 val)
1163{
1164 inb(VGAREG_ACTL_RESET);
1165 outb(reg, VGAREG_ACTL_ADDRESS);
Kevin O'Connord9fc0a02009-05-07 22:00:25 -04001166 outb(val, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001167 outb(0x20, VGAREG_ACTL_ADDRESS);
1168}
1169
1170// -------------------------------------------------------------------
1171u8
1172biosfn_get_single_palette_reg(u8 reg)
1173{
1174 inb(VGAREG_ACTL_RESET);
1175 outb(reg, VGAREG_ACTL_ADDRESS);
1176 u8 v = inb(VGAREG_ACTL_READ_DATA);
1177 inb(VGAREG_ACTL_RESET);
1178 outb(0x20, VGAREG_ACTL_ADDRESS);
1179 return v;
1180}
1181
1182// -------------------------------------------------------------------
1183static void
1184biosfn_read_overscan_border_color(struct bregs *regs)
1185{
1186 inb(VGAREG_ACTL_RESET);
1187 outb(0x11, VGAREG_ACTL_ADDRESS);
1188 regs->bh = inb(VGAREG_ACTL_READ_DATA);
1189 inb(VGAREG_ACTL_RESET);
1190 outb(0x20, VGAREG_ACTL_ADDRESS);
1191}
1192
1193// -------------------------------------------------------------------
1194static void
1195biosfn_get_all_palette_reg(struct bregs *regs)
1196{
Kevin O'Connordd2be772009-05-16 15:41:23 -04001197 u8 *data_far = (u8*)(regs->dx + 0);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001198 int i;
1199 for (i = 0; i < 0x10; i++) {
1200 inb(VGAREG_ACTL_RESET);
1201 outb(i, VGAREG_ACTL_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001202 SET_FARVAR(regs->es, *data_far, inb(VGAREG_ACTL_READ_DATA));
1203 data_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001204 }
1205 inb(VGAREG_ACTL_RESET);
1206 outb(0x11, VGAREG_ACTL_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001207 SET_FARVAR(regs->es, *data_far, inb(VGAREG_ACTL_READ_DATA));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001208 inb(VGAREG_ACTL_RESET);
1209 outb(0x20, VGAREG_ACTL_ADDRESS);
1210}
1211
1212// -------------------------------------------------------------------
1213static void
1214biosfn_set_single_dac_reg(struct bregs *regs)
1215{
1216 outb(regs->bl, VGAREG_DAC_WRITE_ADDRESS);
1217 outb(regs->dh, VGAREG_DAC_DATA);
1218 outb(regs->ch, VGAREG_DAC_DATA);
1219 outb(regs->cl, VGAREG_DAC_DATA);
1220}
1221
1222// -------------------------------------------------------------------
1223static void
1224biosfn_set_all_dac_reg(struct bregs *regs)
1225{
1226 outb(regs->bl, VGAREG_DAC_WRITE_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001227 u8 *data_far = (u8*)(regs->dx + 0);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001228 int count = regs->cx;
1229 while (count) {
Kevin O'Connordd2be772009-05-16 15:41:23 -04001230 outb(GET_FARVAR(regs->es, *data_far), VGAREG_DAC_DATA);
1231 data_far++;
1232 outb(GET_FARVAR(regs->es, *data_far), VGAREG_DAC_DATA);
1233 data_far++;
1234 outb(GET_FARVAR(regs->es, *data_far), VGAREG_DAC_DATA);
1235 data_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001236 count--;
1237 }
1238}
1239
1240// -------------------------------------------------------------------
1241static void
1242biosfn_select_video_dac_color_page(struct bregs *regs)
1243{
1244 inb(VGAREG_ACTL_RESET);
1245 outb(0x10, VGAREG_ACTL_ADDRESS);
1246 u8 val = inb(VGAREG_ACTL_READ_DATA);
1247 if (!(regs->bl & 0x01)) {
1248 val = (val & 0x7f) | (regs->bh << 7);
Kevin O'Connord9fc0a02009-05-07 22:00:25 -04001249 outb(val, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001250 outb(0x20, VGAREG_ACTL_ADDRESS);
1251 return;
1252 }
1253 inb(VGAREG_ACTL_RESET);
1254 outb(0x14, VGAREG_ACTL_ADDRESS);
1255 u8 bh = regs->bh;
1256 if (!(val & 0x80))
1257 bh <<= 2;
1258 bh &= 0x0f;
Kevin O'Connord9fc0a02009-05-07 22:00:25 -04001259 outb(bh, VGAREG_ACTL_WRITE_DATA);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001260 outb(0x20, VGAREG_ACTL_ADDRESS);
1261}
1262
1263// -------------------------------------------------------------------
1264static void
1265biosfn_read_single_dac_reg(struct bregs *regs)
1266{
1267 outb(regs->bl, VGAREG_DAC_READ_ADDRESS);
1268 regs->dh = inb(VGAREG_DAC_DATA);
1269 regs->ch = inb(VGAREG_DAC_DATA);
1270 regs->cl = inb(VGAREG_DAC_DATA);
1271}
1272
1273// -------------------------------------------------------------------
1274static void
1275biosfn_read_all_dac_reg(struct bregs *regs)
1276{
1277 outb(regs->bl, VGAREG_DAC_READ_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001278 u8 *data_far = (u8*)(regs->dx + 0);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001279 int count = regs->cx;
1280 while (count) {
Kevin O'Connordd2be772009-05-16 15:41:23 -04001281 SET_FARVAR(regs->es, *data_far, inb(VGAREG_DAC_DATA));
1282 data_far++;
1283 SET_FARVAR(regs->es, *data_far, inb(VGAREG_DAC_DATA));
1284 data_far++;
1285 SET_FARVAR(regs->es, *data_far, inb(VGAREG_DAC_DATA));
1286 data_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001287 count--;
1288 }
1289}
1290
1291// -------------------------------------------------------------------
1292static void
1293biosfn_set_pel_mask(struct bregs *regs)
1294{
1295 outb(regs->bl, VGAREG_PEL_MASK);
1296}
1297
1298// -------------------------------------------------------------------
1299static void
1300biosfn_read_pel_mask(struct bregs *regs)
1301{
1302 regs->bl = inb(VGAREG_PEL_MASK);
1303}
1304
1305// -------------------------------------------------------------------
1306static void
1307biosfn_read_video_dac_state(struct bregs *regs)
1308{
1309 inb(VGAREG_ACTL_RESET);
1310 outb(0x10, VGAREG_ACTL_ADDRESS);
1311 u8 val1 = inb(VGAREG_ACTL_READ_DATA) >> 7;
1312
1313 inb(VGAREG_ACTL_RESET);
1314 outb(0x14, VGAREG_ACTL_ADDRESS);
1315 u8 val2 = inb(VGAREG_ACTL_READ_DATA) & 0x0f;
1316 if (!(val1 & 0x01))
1317 val2 >>= 2;
1318
1319 inb(VGAREG_ACTL_RESET);
1320 outb(0x20, VGAREG_ACTL_ADDRESS);
1321
1322 regs->bl = val1;
1323 regs->bh = val2;
1324}
1325
1326// -------------------------------------------------------------------
1327static void
1328get_font_access()
1329{
1330 outw(0x0100, VGAREG_SEQU_ADDRESS);
1331 outw(0x0402, VGAREG_SEQU_ADDRESS);
1332 outw(0x0704, VGAREG_SEQU_ADDRESS);
1333 outw(0x0300, VGAREG_SEQU_ADDRESS);
1334 outw(0x0204, VGAREG_GRDC_ADDRESS);
1335 outw(0x0005, VGAREG_GRDC_ADDRESS);
1336 outw(0x0406, VGAREG_GRDC_ADDRESS);
1337}
1338
1339static void
1340release_font_access()
1341{
1342 outw(0x0100, VGAREG_SEQU_ADDRESS);
1343 outw(0x0302, VGAREG_SEQU_ADDRESS);
1344 outw(0x0304, VGAREG_SEQU_ADDRESS);
1345 outw(0x0300, VGAREG_SEQU_ADDRESS);
1346 u16 v = inw(VGAREG_READ_MISC_OUTPUT);
1347 v = ((v & 0x01) << 10) | 0x0a06;
1348 outw(v, VGAREG_GRDC_ADDRESS);
1349 outw(0x0004, VGAREG_GRDC_ADDRESS);
1350 outw(0x1005, VGAREG_GRDC_ADDRESS);
1351}
1352
1353static void
1354set_scan_lines(u8 lines)
1355{
Kevin O'Connordd2be772009-05-16 15:41:23 -04001356 u16 crtc_addr = GET_BDA(crtc_address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001357 outb(0x09, crtc_addr);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001358 u8 crtc_r9 = inb(crtc_addr + 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001359 crtc_r9 = (crtc_r9 & 0xe0) | (lines - 1);
1360 outb(crtc_r9, crtc_addr + 1);
1361 if (lines == 8)
1362 biosfn_set_cursor_shape(0x06, 0x07);
1363 else
1364 biosfn_set_cursor_shape(lines - 4, lines - 3);
1365 SET_BDA(char_height, lines);
1366 outb(0x12, crtc_addr);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001367 u16 vde = inb(crtc_addr + 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001368 outb(0x07, crtc_addr);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001369 u8 ovl = inb(crtc_addr + 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001370 vde += (((ovl & 0x02) << 7) + ((ovl & 0x40) << 3) + 1);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001371 u8 rows = vde / lines;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001372 SET_BDA(video_rows, rows - 1);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001373 u16 cols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001374 SET_BDA(video_pagesize, rows * cols * 2);
1375}
1376
1377static void
1378biosfn_load_text_user_pat(u8 AL, u16 ES, u16 BP, u16 CX, u16 DX, u8 BL,
1379 u8 BH)
1380{
1381 get_font_access();
1382 u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
1383 u16 i;
1384 for (i = 0; i < CX; i++) {
Kevin O'Connorf94ec432009-05-16 17:37:23 -04001385 void *src_far = (void*)(BP + i * BH);
1386 void *dest_far = (void*)(blockaddr + (DX + i) * 32);
1387 memcpy_far(0xA000, dest_far, ES, src_far, BH);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001388 }
1389 release_font_access();
1390 if (AL >= 0x10)
1391 set_scan_lines(BH);
1392}
1393
1394static void
1395biosfn_load_text_8_14_pat(u8 AL, u8 BL)
1396{
1397 get_font_access();
1398 u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
1399 u16 i;
1400 for (i = 0; i < 0x100; i++) {
1401 u16 src = i * 14;
Kevin O'Connorf94ec432009-05-16 17:37:23 -04001402 void *dest_far = (void*)(blockaddr + i * 32);
1403 memcpy_far(0xA000, dest_far, 0xC000, &vgafont14[src], 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001404 }
1405 release_font_access();
1406 if (AL >= 0x10)
1407 set_scan_lines(14);
1408}
1409
1410static void
1411biosfn_load_text_8_8_pat(u8 AL, u8 BL)
1412{
1413 get_font_access();
1414 u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
1415 u16 i;
1416 for (i = 0; i < 0x100; i++) {
1417 u16 src = i * 8;
Kevin O'Connorf94ec432009-05-16 17:37:23 -04001418 void *dest_far = (void*)(blockaddr + i * 32);
1419 memcpy_far(0xA000, dest_far, 0xC000, &vgafont8[src], 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001420 }
1421 release_font_access();
1422 if (AL >= 0x10)
1423 set_scan_lines(8);
1424}
1425
1426// -------------------------------------------------------------------
1427static void
1428biosfn_set_text_block_specifier(struct bregs *regs)
1429{
1430 outw((regs->bl << 8) | 0x03, VGAREG_SEQU_ADDRESS);
1431}
1432
1433// -------------------------------------------------------------------
1434static void
1435biosfn_load_text_8_16_pat(u8 AL, u8 BL)
1436{
1437 get_font_access();
1438 u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
1439 u16 i;
1440 for (i = 0; i < 0x100; i++) {
1441 u16 src = i * 16;
Kevin O'Connorf94ec432009-05-16 17:37:23 -04001442 void *dest_far = (void*)(blockaddr + i * 32);
1443 memcpy_far(0xA000, dest_far, 0xC000, &vgafont16[src], 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001444 }
1445 release_font_access();
1446 if (AL >= 0x10)
1447 set_scan_lines(16);
1448}
1449
1450// -------------------------------------------------------------------
1451static void
1452biosfn_get_font_info(u8 BH, u16 *ES, u16 *BP, u16 *CX, u16 *DX)
1453{
1454 switch (BH) {
1455 case 0x00: {
1456 u32 segoff = GET_IVT(0x1f).segoff;
1457 *ES = segoff >> 16;
1458 *BP = segoff;
1459 break;
1460 }
1461 case 0x01: {
1462 u32 segoff = GET_IVT(0x43).segoff;
1463 *ES = segoff >> 16;
1464 *BP = segoff;
1465 break;
1466 }
1467 case 0x02:
1468 *ES = 0xC000;
1469 *BP = (u32)vgafont14;
1470 break;
1471 case 0x03:
1472 *ES = 0xC000;
1473 *BP = (u32)vgafont8;
1474 break;
1475 case 0x04:
1476 *ES = 0xC000;
1477 *BP = (u32)vgafont8 + 128 * 8;
1478 break;
1479 case 0x05:
1480 *ES = 0xC000;
1481 *BP = (u32)vgafont14alt;
1482 break;
1483 case 0x06:
1484 *ES = 0xC000;
1485 *BP = (u32)vgafont16;
1486 break;
1487 case 0x07:
1488 *ES = 0xC000;
1489 *BP = (u32)vgafont16alt;
1490 break;
1491 default:
Kevin O'Connora12c2152009-05-13 22:06:16 -04001492 dprintf(1, "Get font info BH(%02x) was discarded\n", BH);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001493 return;
1494 }
1495 // Set byte/char of on screen font
1496 *CX = GET_BDA(char_height) & 0xff;
1497
1498 // Set Highest char row
1499 *DX = GET_BDA(video_rows);
1500}
1501
1502// -------------------------------------------------------------------
1503static void
1504biosfn_get_ega_info(struct bregs *regs)
1505{
1506 regs->cx = GET_BDA(video_switches) & 0x0f;
1507 regs->ax = GET_BDA(crtc_address);
1508 if (regs->ax == VGAREG_MDA_CRTC_ADDRESS)
1509 regs->bx = 0x0103;
1510 else
1511 regs->bx = 0x0003;
1512}
1513
1514// -------------------------------------------------------------------
1515static void
1516biosfn_select_vert_res(struct bregs *regs)
1517{
1518 u8 mctl = GET_BDA(modeset_ctl);
1519 u8 vswt = GET_BDA(video_switches);
1520
1521 switch (regs->al) {
1522 case 0x00:
1523 // 200 lines
1524 mctl = (mctl & ~0x10) | 0x80;
1525 vswt = (vswt & ~0x0f) | 0x08;
1526 break;
1527 case 0x01:
1528 // 350 lines
1529 mctl &= ~0x90;
1530 vswt = (vswt & ~0x0f) | 0x09;
1531 break;
1532 case 0x02:
1533 // 400 lines
1534 mctl = (mctl & ~0x80) | 0x10;
1535 vswt = (vswt & ~0x0f) | 0x09;
1536 break;
1537 default:
Kevin O'Connora12c2152009-05-13 22:06:16 -04001538 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001539 break;
1540 }
1541 SET_BDA(modeset_ctl, mctl);
1542 SET_BDA(video_switches, vswt);
1543 regs->ax = 0x1212;
1544}
1545
1546static void
1547biosfn_enable_default_palette_loading(struct bregs *regs)
1548{
1549 u8 v = (regs->al & 0x01) << 3;
1550 u8 mctl = GET_BDA(video_ctl) & ~0x08;
1551 SET_BDA(video_ctl, mctl | v);
1552 regs->ax = 0x1212;
1553}
1554
1555static void
1556biosfn_enable_video_addressing(struct bregs *regs)
1557{
1558 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
1559 u8 v2 = inb(VGAREG_READ_MISC_OUTPUT) & ~0x02;
1560 outb(v | v2, VGAREG_WRITE_MISC_OUTPUT);
1561 regs->ax = 0x1212;
1562}
1563
1564
1565static void
1566biosfn_enable_grayscale_summing(struct bregs *regs)
1567{
1568 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
1569 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
1570 SET_BDA(modeset_ctl, v | v2);
1571 regs->ax = 0x1212;
1572}
1573
1574static void
1575biosfn_enable_cursor_emulation(struct bregs *regs)
1576{
1577 u8 v = (regs->al & 0x01) ^ 0x01;
1578 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
1579 SET_BDA(modeset_ctl, v | v2);
1580 regs->ax = 0x1212;
1581}
1582
1583// -------------------------------------------------------------------
1584static void
1585biosfn_write_string(u8 flag, u8 page, u8 attr, u16 count, u8 row, u8 col,
Kevin O'Connordd2be772009-05-16 15:41:23 -04001586 u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001587{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001588 // Read curs info for the page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -04001589 u16 oldcurs = biosfn_get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001590
1591 // if row=0xff special case : use current cursor position
1592 if (row == 0xff) {
1593 col = oldcurs & 0x00ff;
1594 row = (oldcurs & 0xff00) >> 8;
1595 }
1596
Kevin O'Connordd2be772009-05-16 15:41:23 -04001597 u16 newcurs = row;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001598 newcurs <<= 8;
1599 newcurs += col;
1600 biosfn_set_cursor_pos(page, newcurs);
1601
1602 while (count-- != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -04001603 u8 car = GET_FARVAR(seg, *offset_far);
1604 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001605 if ((flag & 0x02) != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -04001606 attr = GET_FARVAR(seg, *offset_far);
1607 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001608 }
1609
1610 biosfn_write_teletype(car, page, attr, WITH_ATTR);
1611 }
1612
1613 // Set back curs pos
1614 if ((flag & 0x01) == 0)
1615 biosfn_set_cursor_pos(page, oldcurs);
1616}
1617
1618// -------------------------------------------------------------------
1619static void
1620biosfn_read_display_code(struct bregs *regs)
1621{
1622 regs->bx = GET_BDA(dcc_index);
1623 regs->al = 0x1a;
1624}
1625
1626static void
1627biosfn_set_display_code(struct bregs *regs)
1628{
1629 SET_BDA(dcc_index, regs->bl);
Kevin O'Connora12c2152009-05-13 22:06:16 -04001630 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001631 regs->al = 0x1a;
1632}
1633
1634// -------------------------------------------------------------------
1635static void
1636biosfn_read_state_info(u16 BX, u16 ES, u16 DI)
1637{
1638 // Address of static functionality table
1639 SET_FARVAR(ES, *(u16*)(DI + 0x00), (u32)static_functionality);
1640 SET_FARVAR(ES, *(u16*)(DI + 0x02), 0xC000);
1641
1642 // Hard coded copy from BIOS area. Should it be cleaner ?
1643 memcpy_far(ES, (void*)(DI + 0x04), SEG_BDA, (void*)0x49, 30);
1644 memcpy_far(ES, (void*)(DI + 0x22), SEG_BDA, (void*)0x84, 3);
1645
1646 SET_FARVAR(ES, *(u8*)(DI + 0x25), GET_BDA(dcc_index));
1647 SET_FARVAR(ES, *(u8*)(DI + 0x26), 0);
1648 SET_FARVAR(ES, *(u8*)(DI + 0x27), 16);
1649 SET_FARVAR(ES, *(u8*)(DI + 0x28), 0);
1650 SET_FARVAR(ES, *(u8*)(DI + 0x29), 8);
1651 SET_FARVAR(ES, *(u8*)(DI + 0x2a), 2);
1652 SET_FARVAR(ES, *(u8*)(DI + 0x2b), 0);
1653 SET_FARVAR(ES, *(u8*)(DI + 0x2c), 0);
1654 SET_FARVAR(ES, *(u8*)(DI + 0x31), 3);
1655 SET_FARVAR(ES, *(u8*)(DI + 0x32), 0);
1656
1657 memset_far(ES, (void*)(DI + 0x33), 0, 13);
1658}
1659
1660// -------------------------------------------------------------------
1661// -------------------------------------------------------------------
1662static u16
1663biosfn_read_video_state_size(u16 CX)
1664{
1665 u16 size = 0;
1666 if (CX & 1)
1667 size += 0x46;
1668 if (CX & 2)
1669 size += (5 + 8 + 5) * 2 + 6;
1670 if (CX & 4)
1671 size += 3 + 256 * 3 + 1;
1672 return size;
1673}
1674
1675static u16
1676biosfn_save_video_state(u16 CX, u16 ES, u16 BX)
1677{
Kevin O'Connordd2be772009-05-16 15:41:23 -04001678 u16 crtc_addr = GET_BDA(crtc_address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001679 if (CX & 1) {
1680 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_SEQU_ADDRESS));
1681 BX++;
1682 SET_FARVAR(ES, *(u8*)(BX+0), inb(crtc_addr));
1683 BX++;
1684 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_GRDC_ADDRESS));
1685 BX++;
1686 inb(VGAREG_ACTL_RESET);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001687 u16 ar_index = inb(VGAREG_ACTL_ADDRESS);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001688 SET_FARVAR(ES, *(u8*)(BX+0), ar_index);
1689 BX++;
1690 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_READ_FEATURE_CTL));
1691 BX++;
1692
Kevin O'Connordd2be772009-05-16 15:41:23 -04001693 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001694 for (i = 1; i <= 4; i++) {
1695 outb(i, VGAREG_SEQU_ADDRESS);
1696 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_SEQU_DATA));
1697 BX++;
1698 }
1699 outb(0, VGAREG_SEQU_ADDRESS);
1700 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_SEQU_DATA));
1701 BX++;
1702
1703 for (i = 0; i <= 0x18; i++) {
1704 outb(i, crtc_addr);
1705 SET_FARVAR(ES, *(u8*)(BX+0), inb(crtc_addr + 1));
1706 BX++;
1707 }
1708
1709 for (i = 0; i <= 0x13; i++) {
1710 inb(VGAREG_ACTL_RESET);
1711 outb(i | (ar_index & 0x20), VGAREG_ACTL_ADDRESS);
1712 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_ACTL_READ_DATA));
1713 BX++;
1714 }
1715 inb(VGAREG_ACTL_RESET);
1716
1717 for (i = 0; i <= 8; i++) {
1718 outb(i, VGAREG_GRDC_ADDRESS);
1719 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_GRDC_DATA));
1720 BX++;
1721 }
1722
1723 SET_FARVAR(ES, *(u16*)(BX+0), crtc_addr);
1724 BX += 2;
1725
1726 /* XXX: read plane latches */
1727 SET_FARVAR(ES, *(u8*)(BX+0), 0);
1728 BX++;
1729 SET_FARVAR(ES, *(u8*)(BX+0), 0);
1730 BX++;
1731 SET_FARVAR(ES, *(u8*)(BX+0), 0);
1732 BX++;
1733 SET_FARVAR(ES, *(u8*)(BX+0), 0);
1734 BX++;
1735 }
1736 if (CX & 2) {
1737 SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_mode));
1738 BX++;
1739 SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(video_cols));
1740 BX += 2;
1741 SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(video_pagesize));
1742 BX += 2;
1743 SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(crtc_address));
1744 BX += 2;
1745 SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_rows));
1746 BX++;
1747 SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(char_height));
1748 BX += 2;
1749 SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_ctl));
1750 BX++;
1751 SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_switches));
1752 BX++;
1753 SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(modeset_ctl));
1754 BX++;
1755 SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(cursor_type));
1756 BX += 2;
Kevin O'Connordd2be772009-05-16 15:41:23 -04001757 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001758 for (i = 0; i < 8; i++) {
1759 SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(cursor_pos[i]));
1760 BX += 2;
1761 }
1762 SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(video_pagestart));
1763 BX += 2;
1764 SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_page));
1765 BX++;
1766 /* current font */
1767 SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x1f * 4)));
1768 BX += 2;
1769 SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x1f * 4 + 2)));
1770 BX += 2;
1771 SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x43 * 4)));
1772 BX += 2;
1773 SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x43 * 4 + 2)));
1774 BX += 2;
1775 }
1776 if (CX & 4) {
1777 /* XXX: check this */
1778 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_DAC_STATE));
1779 BX++; /* read/write mode dac */
1780 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_DAC_WRITE_ADDRESS));
1781 BX++; /* pix address */
1782 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_PEL_MASK));
1783 BX++;
1784 // Set the whole dac always, from 0
1785 outb(0x00, VGAREG_DAC_WRITE_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001786 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001787 for (i = 0; i < 256 * 3; i++) {
1788 SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_DAC_DATA));
1789 BX++;
1790 }
1791 SET_FARVAR(ES, *(u8*)(BX+0), 0);
1792 BX++; /* color select register */
1793 }
1794 return BX;
1795}
1796
1797static u16
1798biosfn_restore_video_state(u16 CX, u16 ES, u16 BX)
1799{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001800 if (CX & 1) {
1801 // Reset Attribute Ctl flip-flop
1802 inb(VGAREG_ACTL_RESET);
1803
Kevin O'Connordd2be772009-05-16 15:41:23 -04001804 u16 crtc_addr = GET_FARVAR(ES, *(u16*)(BX + 0x40));
1805 u16 addr1 = BX;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001806 BX += 5;
1807
Kevin O'Connordd2be772009-05-16 15:41:23 -04001808 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001809 for (i = 1; i <= 4; i++) {
1810 outb(i, VGAREG_SEQU_ADDRESS);
1811 outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_SEQU_DATA);
1812 BX++;
1813 }
1814 outb(0, VGAREG_SEQU_ADDRESS);
1815 outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_SEQU_DATA);
1816 BX++;
1817
1818 // Disable CRTC write protection
1819 outw(0x0011, crtc_addr);
1820 // Set CRTC regs
1821 for (i = 0; i <= 0x18; i++) {
1822 if (i != 0x11) {
1823 outb(i, crtc_addr);
1824 outb(GET_FARVAR(ES, *(u8*)(BX+0)), crtc_addr + 1);
1825 }
1826 BX++;
1827 }
1828 // select crtc base address
Kevin O'Connordd2be772009-05-16 15:41:23 -04001829 u16 v = inb(VGAREG_READ_MISC_OUTPUT) & ~0x01;
Kevin O'Connord9fc0a02009-05-07 22:00:25 -04001830 if (crtc_addr == VGAREG_VGA_CRTC_ADDRESS)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001831 v |= 0x01;
1832 outb(v, VGAREG_WRITE_MISC_OUTPUT);
1833
1834 // enable write protection if needed
1835 outb(0x11, crtc_addr);
1836 outb(GET_FARVAR(ES, *(u8*)(BX - 0x18 + 0x11)), crtc_addr + 1);
1837
1838 // Set Attribute Ctl
Kevin O'Connordd2be772009-05-16 15:41:23 -04001839 u16 ar_index = GET_FARVAR(ES, *(u8*)(addr1 + 0x03));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001840 inb(VGAREG_ACTL_RESET);
1841 for (i = 0; i <= 0x13; i++) {
1842 outb(i | (ar_index & 0x20), VGAREG_ACTL_ADDRESS);
1843 outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_ACTL_WRITE_DATA);
1844 BX++;
1845 }
1846 outb(ar_index, VGAREG_ACTL_ADDRESS);
1847 inb(VGAREG_ACTL_RESET);
1848
1849 for (i = 0; i <= 8; i++) {
1850 outb(i, VGAREG_GRDC_ADDRESS);
1851 outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_GRDC_DATA);
1852 BX++;
1853 }
1854 BX += 2; /* crtc_addr */
1855 BX += 4; /* plane latches */
1856
1857 outb(GET_FARVAR(ES, *(u8*)(addr1+0)), VGAREG_SEQU_ADDRESS);
1858 addr1++;
1859 outb(GET_FARVAR(ES, *(u8*)(addr1+0)), crtc_addr);
1860 addr1++;
1861 outb(GET_FARVAR(ES, *(u8*)(addr1+0)), VGAREG_GRDC_ADDRESS);
1862 addr1++;
1863 addr1++;
1864 outb(GET_FARVAR(ES, *(u8*)(addr1+0)), crtc_addr - 0x4 + 0xa);
1865 addr1++;
1866 }
1867 if (CX & 2) {
1868 SET_BDA(video_mode, GET_FARVAR(ES, *(u8*)(BX+0)));
1869 BX++;
1870 SET_BDA(video_cols, GET_FARVAR(ES, *(u16*)(BX+0)));
1871 BX += 2;
1872 SET_BDA(video_pagesize, GET_FARVAR(ES, *(u16*)(BX+0)));
1873 BX += 2;
1874 SET_BDA(crtc_address, GET_FARVAR(ES, *(u16*)(BX+0)));
1875 BX += 2;
1876 SET_BDA(video_rows, GET_FARVAR(ES, *(u8*)(BX+0)));
1877 BX++;
1878 SET_BDA(char_height, GET_FARVAR(ES, *(u16*)(BX+0)));
1879 BX += 2;
1880 SET_BDA(video_ctl, GET_FARVAR(ES, *(u8*)(BX+0)));
1881 BX++;
1882 SET_BDA(video_switches, GET_FARVAR(ES, *(u8*)(BX+0)));
1883 BX++;
1884 SET_BDA(modeset_ctl, GET_FARVAR(ES, *(u8*)(BX+0)));
1885 BX++;
1886 SET_BDA(cursor_type, GET_FARVAR(ES, *(u16*)(BX+0)));
1887 BX += 2;
Kevin O'Connordd2be772009-05-16 15:41:23 -04001888 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001889 for (i = 0; i < 8; i++) {
1890 SET_BDA(cursor_pos[i], GET_FARVAR(ES, *(u16*)(BX+0)));
1891 BX += 2;
1892 }
1893 SET_BDA(video_pagestart, GET_FARVAR(ES, *(u16*)(BX+0)));
1894 BX += 2;
1895 SET_BDA(video_page, GET_FARVAR(ES, *(u8*)(BX+0)));
1896 BX++;
1897 /* current font */
1898 SET_IVT(0x1f, GET_FARVAR(ES, *(u16*)(BX+2)), GET_FARVAR(ES, *(u16*)(BX+0)));
1899 BX += 4;
1900 SET_IVT(0x43, GET_FARVAR(ES, *(u16*)(BX+2)), GET_FARVAR(ES, *(u16*)(BX+0)));
1901 BX += 4;
1902 }
1903 if (CX & 4) {
1904 BX++;
Kevin O'Connordd2be772009-05-16 15:41:23 -04001905 u16 v = GET_FARVAR(ES, *(u8*)(BX+0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001906 BX++;
1907 outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_PEL_MASK);
1908 BX++;
1909 // Set the whole dac always, from 0
1910 outb(0x00, VGAREG_DAC_WRITE_ADDRESS);
Kevin O'Connordd2be772009-05-16 15:41:23 -04001911 u16 i;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001912 for (i = 0; i < 256 * 3; i++) {
1913 outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_DAC_DATA);
1914 BX++;
1915 }
1916 BX++;
1917 outb(v, VGAREG_DAC_WRITE_ADDRESS);
1918 }
1919 return BX;
1920}
1921
1922
1923/****************************************************************
1924 * VGA int 10 handler
1925 ****************************************************************/
1926
1927static void
1928handle_1000(struct bregs *regs)
1929{
1930 // XXX - inline
1931 biosfn_set_video_mode(regs->al);
1932 switch(regs->al & 0x7F) {
1933 case 6:
1934 regs->al = 0x3F;
1935 break;
1936 case 0:
1937 case 1:
1938 case 2:
1939 case 3:
1940 case 4:
1941 case 5:
1942 case 7:
1943 regs->al = 0x30;
1944 break;
1945 default:
1946 regs->al = 0x20;
1947 }
1948}
1949
1950static void
1951handle_1001(struct bregs *regs)
1952{
1953 biosfn_set_cursor_shape(regs->ch, regs->cl);
1954}
1955
1956static void
1957handle_1002(struct bregs *regs)
1958{
1959 biosfn_set_cursor_pos(regs->bh, regs->dx);
1960}
1961
1962static void
1963handle_1003(struct bregs *regs)
1964{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -04001965 regs->cx = biosfn_get_cursor_shape(regs->bh);
1966 regs->dx = biosfn_get_cursor_pos(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001967}
1968
1969// Read light pen pos (unimplemented)
1970static void
1971handle_1004(struct bregs *regs)
1972{
1973 debug_stub(regs);
1974 regs->ax = regs->bx = regs->cx = regs->dx = 0;
1975}
1976
1977static void
1978handle_1005(struct bregs *regs)
1979{
1980 biosfn_set_active_page(regs->al);
1981}
1982
1983static void
1984handle_1006(struct bregs *regs)
1985{
1986 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
1987 , 0xFF, SCROLL_UP);
1988}
1989
1990static void
1991handle_1007(struct bregs *regs)
1992{
1993 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
1994 , 0xFF, SCROLL_DOWN);
1995}
1996
1997static void
1998handle_1008(struct bregs *regs)
1999{
2000 // XXX - inline
2001 biosfn_read_char_attr(regs->bh, &regs->ax);
2002}
2003
2004static void
2005handle_1009(struct bregs *regs)
2006{
2007 // XXX - inline
2008 biosfn_write_char_attr(regs->al, regs->bh, regs->bl, regs->cx);
2009}
2010
2011static void
2012handle_100a(struct bregs *regs)
2013{
2014 // XXX - inline
2015 biosfn_write_char_only(regs->al, regs->bh, regs->bl, regs->cx);
2016}
2017
2018
2019static void
2020handle_100b00(struct bregs *regs)
2021{
2022 // XXX - inline
2023 biosfn_set_border_color(regs);
2024}
2025
2026static void
2027handle_100b01(struct bregs *regs)
2028{
2029 // XXX - inline
2030 biosfn_set_palette(regs);
2031}
2032
2033static void
2034handle_100bXX(struct bregs *regs)
2035{
2036 debug_stub(regs);
2037}
2038
2039static void
2040handle_100b(struct bregs *regs)
2041{
2042 switch (regs->bh) {
2043 case 0x00: handle_100b00(regs); break;
2044 case 0x01: handle_100b01(regs); break;
2045 default: handle_100bXX(regs); break;
2046 }
2047}
2048
2049
2050static void
2051handle_100c(struct bregs *regs)
2052{
2053 // XXX - inline
2054 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
2055}
2056
2057static void
2058handle_100d(struct bregs *regs)
2059{
2060 // XXX - inline
2061 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
2062}
2063
2064static void
2065handle_100e(struct bregs *regs)
2066{
2067 // Ralf Brown Interrupt list is WRONG on bh(page)
2068 // We do output only on the current page !
2069 biosfn_write_teletype(regs->al, 0xff, regs->bl, NO_ATTR);
2070}
2071
2072static void
2073handle_100f(struct bregs *regs)
2074{
2075 // XXX - inline
2076 biosfn_get_video_mode(regs);
2077}
2078
2079
2080static void
2081handle_101000(struct bregs *regs)
2082{
2083 if (regs->bl > 0x14)
2084 return;
2085 biosfn_set_single_palette_reg(regs->bl, regs->bh);
2086}
2087
2088static void
2089handle_101001(struct bregs *regs)
2090{
2091 // XXX - inline
2092 biosfn_set_overscan_border_color(regs);
2093}
2094
2095static void
2096handle_101002(struct bregs *regs)
2097{
2098 // XXX - inline
2099 biosfn_set_all_palette_reg(regs);
2100}
2101
2102static void
2103handle_101003(struct bregs *regs)
2104{
2105 // XXX - inline
2106 biosfn_toggle_intensity(regs);
2107}
2108
2109static void
2110handle_101007(struct bregs *regs)
2111{
2112 if (regs->bl > 0x14)
2113 return;
2114 regs->bh = biosfn_get_single_palette_reg(regs->bl);
2115}
2116
2117static void
2118handle_101008(struct bregs *regs)
2119{
2120 // XXX - inline
2121 biosfn_read_overscan_border_color(regs);
2122}
2123
2124static void
2125handle_101009(struct bregs *regs)
2126{
2127 // XXX - inline
2128 biosfn_get_all_palette_reg(regs);
2129}
2130
2131static void
2132handle_101010(struct bregs *regs)
2133{
2134 // XXX - inline
2135 biosfn_set_single_dac_reg(regs);
2136}
2137
2138static void
2139handle_101012(struct bregs *regs)
2140{
2141 // XXX - inline
2142 biosfn_set_all_dac_reg(regs);
2143}
2144
2145static void
2146handle_101013(struct bregs *regs)
2147{
2148 // XXX - inline
2149 biosfn_select_video_dac_color_page(regs);
2150}
2151
2152static void
2153handle_101015(struct bregs *regs)
2154{
2155 // XXX - inline
2156 biosfn_read_single_dac_reg(regs);
2157}
2158
2159static void
2160handle_101017(struct bregs *regs)
2161{
2162 // XXX - inline
2163 biosfn_read_all_dac_reg(regs);
2164}
2165
2166static void
2167handle_101018(struct bregs *regs)
2168{
2169 // XXX - inline
2170 biosfn_set_pel_mask(regs);
2171}
2172
2173static void
2174handle_101019(struct bregs *regs)
2175{
2176 // XXX - inline
2177 biosfn_read_pel_mask(regs);
2178}
2179
2180static void
2181handle_10101a(struct bregs *regs)
2182{
2183 // XXX - inline
2184 biosfn_read_video_dac_state(regs);
2185}
2186
2187static void
2188handle_10101b(struct bregs *regs)
2189{
2190 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
2191}
2192
2193static void
2194handle_1010XX(struct bregs *regs)
2195{
2196 debug_stub(regs);
2197}
2198
2199static void
2200handle_1010(struct bregs *regs)
2201{
2202 switch (regs->al) {
2203 case 0x00: handle_101000(regs); break;
2204 case 0x01: handle_101001(regs); break;
2205 case 0x02: handle_101002(regs); break;
2206 case 0x03: handle_101003(regs); break;
2207 case 0x07: handle_101007(regs); break;
2208 case 0x08: handle_101008(regs); break;
2209 case 0x09: handle_101009(regs); break;
2210 case 0x10: handle_101010(regs); break;
2211 case 0x12: handle_101012(regs); break;
2212 case 0x13: handle_101013(regs); break;
2213 case 0x15: handle_101015(regs); break;
2214 case 0x17: handle_101017(regs); break;
2215 case 0x18: handle_101018(regs); break;
2216 case 0x19: handle_101019(regs); break;
2217 case 0x1a: handle_10101a(regs); break;
2218 case 0x1b: handle_10101b(regs); break;
2219 default: handle_1010XX(regs); break;
2220 }
2221}
2222
2223
2224static void
2225handle_101100(struct bregs *regs)
2226{
2227 // XXX - inline
2228 biosfn_load_text_user_pat(regs->al, regs->es, 0 // XXX - regs->bp
2229 , regs->cx, regs->dx, regs->bl, regs->bh);
2230}
2231
2232static void
2233handle_101101(struct bregs *regs)
2234{
2235 // XXX - inline
2236 biosfn_load_text_8_14_pat(regs->al, regs->bl);
2237}
2238
2239static void
2240handle_101102(struct bregs *regs)
2241{
2242 // XXX - inline
2243 biosfn_load_text_8_8_pat(regs->al, regs->bl);
2244}
2245
2246static void
2247handle_101103(struct bregs *regs)
2248{
2249 // XXX - inline
2250 biosfn_set_text_block_specifier(regs);
2251}
2252
2253static void
2254handle_101104(struct bregs *regs)
2255{
2256 // XXX - inline
2257 biosfn_load_text_8_16_pat(regs->al, regs->bl);
2258}
2259
2260static void
2261handle_101110(struct bregs *regs)
2262{
2263 handle_101100(regs);
2264}
2265
2266static void
2267handle_101111(struct bregs *regs)
2268{
2269 handle_101101(regs);
2270}
2271
2272static void
2273handle_101112(struct bregs *regs)
2274{
2275 handle_101102(regs);
2276}
2277
2278static void
2279handle_101114(struct bregs *regs)
2280{
2281 handle_101104(regs);
2282}
2283
2284static void
2285handle_101130(struct bregs *regs)
2286{
2287 // XXX - inline
2288 biosfn_get_font_info(regs->bh, &regs->es, 0 // &regs->bp
2289 , &regs->cx, &regs->dx);
2290}
2291
2292static void
2293handle_1011XX(struct bregs *regs)
2294{
2295 debug_stub(regs);
2296}
2297
2298static void
2299handle_1011(struct bregs *regs)
2300{
2301 switch (regs->al) {
2302 case 0x00: handle_101100(regs); break;
2303 case 0x01: handle_101101(regs); break;
2304 case 0x02: handle_101102(regs); break;
2305 case 0x03: handle_101103(regs); break;
2306 case 0x04: handle_101104(regs); break;
2307 case 0x10: handle_101110(regs); break;
2308 case 0x11: handle_101111(regs); break;
2309 case 0x12: handle_101112(regs); break;
2310 case 0x14: handle_101114(regs); break;
2311 case 0x30: handle_101130(regs); break;
2312 default: handle_1011XX(regs); break;
2313 }
2314}
2315
2316
2317static void
2318handle_101210(struct bregs *regs)
2319{
2320 // XXX - inline
2321 biosfn_get_ega_info(regs);
2322}
2323
2324static void
2325handle_101230(struct bregs *regs)
2326{
2327 // XXX - inline
2328 biosfn_select_vert_res(regs);
2329}
2330
2331static void
2332handle_101231(struct bregs *regs)
2333{
2334 // XXX - inline
2335 biosfn_enable_default_palette_loading(regs);
2336}
2337
2338static void
2339handle_101232(struct bregs *regs)
2340{
2341 // XXX - inline
2342 biosfn_enable_video_addressing(regs);
2343}
2344
2345static void
2346handle_101233(struct bregs *regs)
2347{
2348 // XXX - inline
2349 biosfn_enable_grayscale_summing(regs);
2350}
2351
2352static void
2353handle_101234(struct bregs *regs)
2354{
2355 // XXX - inline
2356 biosfn_enable_cursor_emulation(regs);
2357}
2358
2359static void
2360handle_101235(struct bregs *regs)
2361{
2362 debug_stub(regs);
2363 regs->al = 0x12;
2364}
2365
2366static void
2367handle_101236(struct bregs *regs)
2368{
2369 debug_stub(regs);
2370 regs->al = 0x12;
2371}
2372
2373static void
2374handle_1012XX(struct bregs *regs)
2375{
2376 debug_stub(regs);
2377}
2378
2379static void
2380handle_1012(struct bregs *regs)
2381{
2382 switch (regs->bl) {
2383 case 0x10: handle_101210(regs); break;
2384 case 0x30: handle_101230(regs); break;
2385 case 0x31: handle_101231(regs); break;
2386 case 0x32: handle_101232(regs); break;
2387 case 0x33: handle_101233(regs); break;
2388 case 0x34: handle_101234(regs); break;
2389 case 0x35: handle_101235(regs); break;
2390 case 0x36: handle_101236(regs); break;
2391 default: handle_1012XX(regs); break;
2392 }
2393
2394 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
2395}
2396
2397
2398static void
2399handle_1013(struct bregs *regs)
2400{
2401 // XXX - inline
2402 biosfn_write_string(regs->al, regs->bh, regs->bl, regs->cx
2403 , regs->dh, regs->dl, regs->es, 0); // regs->bp);
2404}
2405
2406
2407static void
2408handle_101a00(struct bregs *regs)
2409{
2410 // XXX - inline
2411 biosfn_read_display_code(regs);
2412}
2413
2414static void
2415handle_101a01(struct bregs *regs)
2416{
2417 // XXX - inline
2418 biosfn_set_display_code(regs);
2419}
2420
2421static void
2422handle_101aXX(struct bregs *regs)
2423{
2424 debug_stub(regs);
2425}
2426
2427static void
2428handle_101a(struct bregs *regs)
2429{
2430 switch (regs->al) {
2431 case 0x00: handle_101a00(regs); break;
2432 case 0x01: handle_101a01(regs); break;
2433 default: handle_101aXX(regs); break;
2434 }
2435}
2436
2437
2438static void
2439handle_101b(struct bregs *regs)
2440{
2441 // XXX - inline
2442 biosfn_read_state_info(regs->bx, regs->es, regs->di);
2443 regs->al = 0x1B;
2444}
2445
2446
2447static void
2448handle_101c00(struct bregs *regs)
2449{
2450 // XXX - inline
2451 regs->bx = biosfn_read_video_state_size(regs->cx);
2452}
2453
2454static void
2455handle_101c01(struct bregs *regs)
2456{
2457 // XXX - inline
2458 biosfn_save_video_state(regs->cx, regs->es, regs->bx);
2459}
2460
2461static void
2462handle_101c02(struct bregs *regs)
2463{
2464 // XXX - inline
2465 biosfn_restore_video_state(regs->cx, regs->es, regs->bx);
2466}
2467
2468static void
2469handle_101cXX(struct bregs *regs)
2470{
2471 debug_stub(regs);
2472}
2473
2474static void
2475handle_101c(struct bregs *regs)
2476{
2477 switch (regs->al) {
2478 case 0x00: handle_101c00(regs); break;
2479 case 0x01: handle_101c01(regs); break;
2480 case 0x02: handle_101c02(regs); break;
2481 default: handle_101cXX(regs); break;
2482 }
2483}
2484
2485
2486static void
2487handle_104f00(struct bregs *regs)
2488{
2489 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
2490 // XXX - OR cirrus_vesa_00h
2491}
2492
2493static void
2494handle_104f01(struct bregs *regs)
2495{
2496 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
2497 // XXX - OR cirrus_vesa_01h
2498}
2499
2500static void
2501handle_104f02(struct bregs *regs)
2502{
2503 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
2504 // XXX - OR cirrus_vesa_02h
2505}
2506
2507static void
2508handle_104f03(struct bregs *regs)
2509{
2510 // XXX - vbe_biosfn_return_current_mode
2511 // XXX - OR cirrus_vesa_03h
2512}
2513
2514static void
2515handle_104f04(struct bregs *regs)
2516{
2517 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
2518}
2519
2520static void
2521handle_104f05(struct bregs *regs)
2522{
2523 // XXX - vbe_biosfn_display_window_control
2524 // XXX - OR cirrus_vesa_05h
2525}
2526
2527static void
2528handle_104f06(struct bregs *regs)
2529{
2530 // XXX - vbe_biosfn_set_get_logical_scan_line_length
2531 // XXX - OR cirrus_vesa_06h
2532}
2533
2534static void
2535handle_104f07(struct bregs *regs)
2536{
2537 // XXX - vbe_biosfn_set_get_display_start
2538 // XXX - OR cirrus_vesa_07h
2539}
2540
2541static void
2542handle_104f08(struct bregs *regs)
2543{
2544 // XXX - vbe_biosfn_set_get_dac_palette_format
2545}
2546
2547static void
2548handle_104f0a(struct bregs *regs)
2549{
2550 // XXX - vbe_biosfn_return_protected_mode_interface
2551}
2552
2553static void
2554handle_104fXX(struct bregs *regs)
2555{
2556 debug_stub(regs);
2557 regs->ax = 0x0100;
2558}
2559
2560static void
2561handle_104f(struct bregs *regs)
2562{
2563 if (! CONFIG_VBE) {
2564 handle_104fXX(regs);
2565 return;
2566 }
2567
2568 // XXX - check vbe_has_vbe_display()?
2569
2570 switch (regs->al) {
2571 case 0x00: handle_104f00(regs); break;
2572 case 0x01: handle_104f01(regs); break;
2573 case 0x02: handle_104f02(regs); break;
2574 case 0x03: handle_104f03(regs); break;
2575 case 0x04: handle_104f04(regs); break;
2576 case 0x05: handle_104f05(regs); break;
2577 case 0x06: handle_104f06(regs); break;
2578 case 0x07: handle_104f07(regs); break;
2579 case 0x08: handle_104f08(regs); break;
2580 case 0x0a: handle_104f0a(regs); break;
2581 default: handle_104fXX(regs); break;
2582 }
2583}
2584
2585
2586static void
2587handle_10XX(struct bregs *regs)
2588{
2589 debug_stub(regs);
2590}
2591
2592// INT 10h Video Support Service Entry Point
2593void VISIBLE16
2594handle_10(struct bregs *regs)
2595{
2596 debug_enter(regs, DEBUG_VGA_10);
2597 switch (regs->ah) {
2598 case 0x00: handle_1000(regs); break;
2599 case 0x01: handle_1001(regs); break;
2600 case 0x02: handle_1002(regs); break;
2601 case 0x03: handle_1003(regs); break;
2602 case 0x04: handle_1004(regs); break;
2603 case 0x05: handle_1005(regs); break;
2604 case 0x06: handle_1006(regs); break;
2605 case 0x07: handle_1007(regs); break;
2606 case 0x08: handle_1008(regs); break;
2607 case 0x09: handle_1009(regs); break;
2608 case 0x0a: handle_100a(regs); break;
2609 case 0x0b: handle_100b(regs); break;
2610 case 0x0c: handle_100c(regs); break;
2611 case 0x0d: handle_100d(regs); break;
2612 case 0x0e: handle_100e(regs); break;
2613 case 0x0f: handle_100f(regs); break;
2614 case 0x10: handle_1010(regs); break;
2615 case 0x11: handle_1011(regs); break;
2616 case 0x12: handle_1012(regs); break;
2617 case 0x13: handle_1013(regs); break;
2618 case 0x1a: handle_101a(regs); break;
2619 case 0x1b: handle_101b(regs); break;
2620 case 0x1c: handle_101c(regs); break;
2621 case 0x4f: handle_104f(regs); break;
2622 default: handle_10XX(regs); break;
2623 }
2624}
2625
2626
2627/****************************************************************
2628 * VGA post
2629 ****************************************************************/
2630
2631static void
2632init_bios_area()
2633{
2634 // init detected hardware BIOS Area
2635 // set 80x25 color (not clear from RBIL but usual)
2636 u16 eqf = GET_BDA(equipment_list_flags);
2637 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
2638
2639 // Just for the first int10 find its children
2640
2641 // the default char height
2642 SET_BDA(char_height, 0x10);
2643
2644 // Clear the screen
2645 SET_BDA(video_ctl, 0x60);
2646
2647 // Set the basic screen we have
2648 SET_BDA(video_switches, 0xf9);
2649
2650 // Set the basic modeset options
2651 SET_BDA(modeset_ctl, 0x51);
2652
2653 // Set the default MSR
2654 SET_BDA(video_msr, 0x09);
2655}
2656
2657static void
2658init_vga_card()
2659{
2660 // switch to color mode and enable CPU access 480 lines
2661 outb(0xc3, VGAREG_WRITE_MISC_OUTPUT);
2662 // more than 64k 3C4/04
2663 outb(0x04, VGAREG_SEQU_ADDRESS);
2664 outb(0x02, VGAREG_SEQU_DATA);
2665}
2666
2667void VISIBLE16
2668vga_post(struct bregs *regs)
2669{
2670 debug_enter(regs, DEBUG_VGA_POST);
2671
2672 init_vga_card();
2673
2674 init_bios_area();
2675
2676 // vbe_init();
2677
2678 extern void entry_10(void);
2679 SET_IVT(0x10, 0xC000, (u32)entry_10);
2680
2681 if (CONFIG_CIRRUS)
2682 cirrus_init();
2683
2684 // XXX - clear screen and display info
2685
2686 // XXX: fill it
2687 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
2688 SET_VGA(video_save_pointer_table[1], 0xC000);
2689
2690 // Fixup checksum
2691 extern u8 _rom_header_size, _rom_header_checksum;
2692 SET_VGA(_rom_header_checksum, 0);
2693 u8 sum = -checksum_far(0xC000, 0, _rom_header_size * 512);
2694 SET_VGA(_rom_header_checksum, sum);
2695}