blob: 70c6b93b30b5111b4bad61a9fdb781f74c94b681 [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'Connordeb9cb92009-05-25 09:06:50 -040010// * remove recursion from biosfn_write_teletype()
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040011// * review correctness of converted asm by comparing with RBIL
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040012// * refactor redundant code into sub-functions
13// * See if there is a method to the in/out stuff that can be encapsulated.
14// * remove "biosfn" prefixes
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040015// * verify all funcs static
16//
Kevin O'Connor6ace78f2009-05-14 19:24:49 -040017// * convert vbe/clext code
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040018
19#include "bregs.h" // struct bregs
20#include "biosvar.h" // GET_BDA
21#include "util.h" // memset
Kevin O'Connorc0c7df62009-05-17 18:11:33 -040022#include "vgatables.h" // find_vga_entry
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040023
24// XXX
25#define CONFIG_VBE 0
26#define CONFIG_CIRRUS 0
27
28// XXX
29#define DEBUG_VGA_POST 1
30#define DEBUG_VGA_10 3
31
Kevin O'Connord113a992009-05-16 21:05:02 -040032#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040033
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040034inline void
35call16_vgaint(u32 eax, u32 ebx)
36{
37 asm volatile(
38 "int $0x10\n"
39 "cli\n"
40 "cld"
41 :
42 : "a"(eax), "b"(ebx)
43 : "cc", "memory");
44}
45
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040046static void
47biosfn_perform_gray_scale_summing(u16 start, u16 count)
48{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040049 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040050 int i;
51 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040052 u8 rgb[3];
53 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040054
55 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040056 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040057 if (intensity > 0x3f)
58 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040059
Kevin O'Connora0ecb052009-05-18 23:34:00 -040060 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040061 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040062 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040063}
64
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040065static void
66biosfn_set_cursor_shape(u8 CH, u8 CL)
67{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040068 CH &= 0x3f;
69 CL &= 0x1f;
70
Kevin O'Connordd2be772009-05-16 15:41:23 -040071 u16 curs = (CH << 8) + CL;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040072 SET_BDA(cursor_type, curs);
73
Kevin O'Connordd2be772009-05-16 15:41:23 -040074 u8 modeset_ctl = GET_BDA(modeset_ctl);
75 u16 cheight = GET_BDA(char_height);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040076 if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -040077 if (CL != (CH + 1))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040078 CH = ((CH + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040079 else
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040080 CH = ((CL + 1) * cheight / 8) - 2;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040081 CL = ((CL + 1) * cheight / 8) - 1;
82 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040083 vgahw_set_cursor_shape(CH, CL);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040084}
85
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040086static u16
87biosfn_get_cursor_shape(u8 page)
88{
89 if (page > 7)
90 return 0;
91 // FIXME should handle VGA 14/16 lines
92 return GET_BDA(cursor_type);
93}
94
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040095static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040096set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040097{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040098 // Should not happen...
Kevin O'Connor918b1562009-05-25 11:05:18 -040099 if (cp.page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400100 return;
101
102 // Bios cursor pos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400103 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400104
105 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400106 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400107 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400108 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400109
Kevin O'Connordd2be772009-05-16 15:41:23 -0400110 // Get the dimensions
111 u16 nbcols = GET_BDA(video_cols);
112 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400113
Kevin O'Connordd2be772009-05-16 15:41:23 -0400114 // Calculate the address knowing nbcols nbrows and page num
Kevin O'Connor918b1562009-05-25 11:05:18 -0400115 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
116 + cp.x + cp.y * nbcols);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400117
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400118 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400119}
120
Kevin O'Connor918b1562009-05-25 11:05:18 -0400121struct cursorpos
122get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400123{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400124 if (page == 0xff)
125 // special case - use current page
126 page = GET_BDA(video_page);
127 if (page > 7) {
128 struct cursorpos cp = { 0, 0, 0xfe };
129 return cp;
130 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400131 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400132 u16 xy = GET_BDA(cursor_pos[page]);
133 struct cursorpos cp = {xy, xy>>8, page};
134 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400135}
136
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400137static void
138biosfn_set_active_page(u8 page)
139{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400140 if (page > 7)
141 return;
142
143 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400144 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
145 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400146 return;
147
148 // Get pos curs pos for the right page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400149 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400150
Kevin O'Connordd2be772009-05-16 15:41:23 -0400151 u16 address;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400152 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400153 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400154 u16 nbcols = GET_BDA(video_cols);
155 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400156
157 // Calculate the address knowing nbcols nbrows and page num
158 address = SCREEN_MEM_START(nbcols, nbrows, page);
159 SET_BDA(video_pagestart, address);
160
161 // Start address
162 address = SCREEN_IO_START(nbcols, nbrows, page);
163 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400164 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
165 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400166 }
167
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400168 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400169
170 // And change the BIOS page
171 SET_BDA(video_page, page);
172
Kevin O'Connora12c2152009-05-13 22:06:16 -0400173 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400174
175 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400176 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400177}
178
179static void
Kevin O'Connor09262412009-05-25 11:44:11 -0400180biosfn_write_teletype(u8 page, struct carattr ca)
181{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400182 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400183 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
184 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400185 return;
186
187 // Get the cursor pos for the page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400188 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400189
190 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400191 u16 nbrows = GET_BDA(video_rows) + 1;
192 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400193
Kevin O'Connor09262412009-05-25 11:44:11 -0400194 switch (ca.car) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400195 case 7:
196 //FIXME should beep
197 break;
198
199 case 8:
Kevin O'Connor918b1562009-05-25 11:05:18 -0400200 if (cp.x > 0)
201 cp.x--;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400202 break;
203
204 case '\r':
Kevin O'Connor918b1562009-05-25 11:05:18 -0400205 cp.x = 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400206 break;
207
208 case '\n':
Kevin O'Connor918b1562009-05-25 11:05:18 -0400209 cp.y++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400210 break;
211
212 case '\t':
213 do {
Kevin O'Connor09262412009-05-25 11:44:11 -0400214 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
215 biosfn_write_teletype(page, dummyca);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400216 cp = get_cursor_pos(page);
217 } while (cp.x % 8 == 0);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400218 break;
219
220 default:
Kevin O'Connor09262412009-05-25 11:44:11 -0400221 vgafb_write_char(cp.page, ca, 1);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400222 cp.x++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400223 }
224
225 // Do we need to wrap ?
Kevin O'Connor918b1562009-05-25 11:05:18 -0400226 if (cp.x == nbcols) {
227 cp.x = 0;
228 cp.y++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400229 }
230 // Do we need to scroll ?
Kevin O'Connor918b1562009-05-25 11:05:18 -0400231 if (cp.y == nbrows) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400232 if (GET_GLOBAL(vmode_g->class) == TEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400233 biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page,
234 SCROLL_UP);
235 else
236 biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page,
237 SCROLL_UP);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400238 cp.y--;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400239 }
240 // Set the cursor for the page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400241 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400242}
243
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400244static void
Kevin O'Connor918b1562009-05-25 11:05:18 -0400245biosfn_write_string(struct cursorpos cp, u8 flag, u8 attr, u16 count,
Kevin O'Connordd2be772009-05-16 15:41:23 -0400246 u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400247{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400248 // Read curs info for the page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400249 struct cursorpos oldcp = get_cursor_pos(cp.page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400250
251 // if row=0xff special case : use current cursor position
Kevin O'Connor918b1562009-05-25 11:05:18 -0400252 if (cp.y == 0xff)
253 cp = oldcp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400254
Kevin O'Connor918b1562009-05-25 11:05:18 -0400255 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400256
257 while (count-- != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400258 u8 car = GET_FARVAR(seg, *offset_far);
259 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400260 if ((flag & 0x02) != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400261 attr = GET_FARVAR(seg, *offset_far);
262 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400263 }
264
Kevin O'Connor09262412009-05-25 11:44:11 -0400265 struct carattr ca = {car, attr, 1};
266 biosfn_write_teletype(cp.page, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400267 }
268
269 // Set back curs pos
270 if ((flag & 0x01) == 0)
Kevin O'Connor918b1562009-05-25 11:05:18 -0400271 set_cursor_pos(oldcp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400272}
273
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400274static void
Kevin O'Connore7132042009-05-25 00:10:35 -0400275set_scan_lines(u8 lines)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400276{
Kevin O'Connore7132042009-05-25 00:10:35 -0400277 vgahw_set_scan_lines(lines);
278 if (lines == 8)
279 biosfn_set_cursor_shape(0x06, 0x07);
280 else
281 biosfn_set_cursor_shape(lines - 4, lines - 3);
282 SET_BDA(char_height, lines);
283 u16 vde = vgahw_get_vde();
284 u8 rows = vde / lines;
285 SET_BDA(video_rows, rows - 1);
286 u16 cols = GET_BDA(video_cols);
287 SET_BDA(video_pagesize, rows * cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400288}
289
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400290static void
Kevin O'Connorca668642009-05-21 23:06:08 -0400291biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400292{
Kevin O'Connorca668642009-05-21 23:06:08 -0400293 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
294 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
295 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
296 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
297 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
298 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
299 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
300 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
301 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
302 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
303 u16 i;
304 for (i=0; i<8; i++)
305 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
306 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
307 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
308 /* current font */
309 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
310 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400311}
312
Kevin O'Connorca668642009-05-21 23:06:08 -0400313static void
314biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400315{
Kevin O'Connorca668642009-05-21 23:06:08 -0400316 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
317 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
318 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
319 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
320 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
321 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
322 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
323 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
324 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
325 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
326 u16 i;
327 for (i = 0; i < 8; i++)
328 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
329 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
330 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
331 /* current font */
332 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
333 , GET_FARVAR(seg, info->font0_off));
334 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
335 , GET_FARVAR(seg, info->font1_off));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400336}
337
338
339/****************************************************************
340 * VGA int 10 handler
341 ****************************************************************/
342
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400343// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400344static void
345handle_1000(struct bregs *regs)
346{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400347 u8 noclearmem = regs->al & 0x80;
348 u8 mode = regs->al & 0x7f;
349
Kevin O'Connor918b1562009-05-25 11:05:18 -0400350 // Set regs->al
351 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400352 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400353 else if (mode == 6)
354 regs->al = 0x3f;
355 else
356 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400357
358 if (CONFIG_CIRRUS)
359 cirrus_set_video_mode(mode);
360
361 if (CONFIG_VBE)
362 if (vbe_has_vbe_display())
363 dispi_set_enable(VBE_DISPI_DISABLED);
364
365 // find the entry in the video modes
366 struct vgamode_s *vmode_g = find_vga_entry(mode);
367 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
368 if (!vmode_g)
369 return;
370
371 // Read the bios mode set control
372 u8 modeset_ctl = GET_BDA(modeset_ctl);
373
374 // Then we know the number of lines
375// FIXME
376
377 // if palette loading (bit 3 of modeset ctl = 0)
378 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
379 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
380
381 // From which palette
382 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
383 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
384
385 // Always 256*3 values
386 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
387 u16 i;
388 for (i = palsize; i < 0x0100; i++) {
389 static u8 rgb[3] VAR16;
390 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
391 }
392
393 if ((modeset_ctl & 0x02) == 0x02)
394 biosfn_perform_gray_scale_summing(0x00, 0x100);
395 }
396
397 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
398 vgahw_set_mode(vparam_g);
399
400 if (noclearmem == 0x00)
401 clear_screen(vmode_g);
402
403 // Set CRTC address VGA or MDA
404 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
405 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
406 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
407
408 // Set the BIOS mem
409 u16 cheight = GET_GLOBAL(vparam_g->cheight);
410 SET_BDA(video_mode, mode);
411 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
412 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
413 SET_BDA(crtc_address, crtc_addr);
414 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
415 SET_BDA(char_height, cheight);
416 SET_BDA(video_ctl, (0x60 | noclearmem));
417 SET_BDA(video_switches, 0xF9);
418 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
419
420 // FIXME We nearly have the good tables. to be reworked
421 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
422 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
423 SET_BDA(video_savetable_seg, get_global_seg());
424
425 // FIXME
426 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
427 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
428
429 // Set cursor shape
430 if (GET_GLOBAL(vmode_g->class) == TEXT)
431 biosfn_set_cursor_shape(0x06, 0x07);
432 // Set cursor pos for page 0..7
433 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400434 for (i = 0; i < 8; i++) {
435 struct cursorpos cp = {0, 0, i};
436 set_cursor_pos(cp);
437 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400438
439 // Set active page 0
440 biosfn_set_active_page(0x00);
441
442 // Write the fonts in memory
443 if (GET_GLOBAL(vmode_g->class) == TEXT) {
444 call16_vgaint(0x1104, 0);
445 call16_vgaint(0x1103, 0);
446 }
447 // Set the ints 0x1F and 0x43
448 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
449
450 switch (cheight) {
451 case 8:
452 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
453 break;
454 case 14:
455 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
456 break;
457 case 16:
458 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
459 break;
460 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400461}
462
463static void
464handle_1001(struct bregs *regs)
465{
466 biosfn_set_cursor_shape(regs->ch, regs->cl);
467}
468
469static void
470handle_1002(struct bregs *regs)
471{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400472 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
473 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400474}
475
476static void
477handle_1003(struct bregs *regs)
478{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400479 regs->cx = biosfn_get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400480 struct cursorpos cp = get_cursor_pos(regs->bh);
481 regs->dl = cp.x;
482 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400483}
484
485// Read light pen pos (unimplemented)
486static void
487handle_1004(struct bregs *regs)
488{
489 debug_stub(regs);
490 regs->ax = regs->bx = regs->cx = regs->dx = 0;
491}
492
493static void
494handle_1005(struct bregs *regs)
495{
496 biosfn_set_active_page(regs->al);
497}
498
499static void
500handle_1006(struct bregs *regs)
501{
502 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
503 , 0xFF, SCROLL_UP);
504}
505
506static void
507handle_1007(struct bregs *regs)
508{
509 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
510 , 0xFF, SCROLL_DOWN);
511}
512
513static void
514handle_1008(struct bregs *regs)
515{
Kevin O'Connor09262412009-05-25 11:44:11 -0400516 struct carattr ca = vgafb_read_char(regs->bh);
517 regs->al = ca.car;
518 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400519}
520
521static void
522handle_1009(struct bregs *regs)
523{
Kevin O'Connor09262412009-05-25 11:44:11 -0400524 struct carattr ca = {regs->al, regs->bl, 1};
525 vgafb_write_char(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400526}
527
528static void
529handle_100a(struct bregs *regs)
530{
Kevin O'Connor09262412009-05-25 11:44:11 -0400531 struct carattr ca = {regs->al, regs->bl, 0};
532 vgafb_write_char(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400533}
534
535
536static void
537handle_100b00(struct bregs *regs)
538{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400539 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400540}
541
542static void
543handle_100b01(struct bregs *regs)
544{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400545 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400546}
547
548static void
549handle_100bXX(struct bregs *regs)
550{
551 debug_stub(regs);
552}
553
554static void
555handle_100b(struct bregs *regs)
556{
557 switch (regs->bh) {
558 case 0x00: handle_100b00(regs); break;
559 case 0x01: handle_100b01(regs); break;
560 default: handle_100bXX(regs); break;
561 }
562}
563
564
565static void
566handle_100c(struct bregs *regs)
567{
568 // XXX - inline
569 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
570}
571
572static void
573handle_100d(struct bregs *regs)
574{
575 // XXX - inline
576 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
577}
578
579static void
580handle_100e(struct bregs *regs)
581{
582 // Ralf Brown Interrupt list is WRONG on bh(page)
583 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400584 struct carattr ca = {regs->al, regs->bl, 0};
585 biosfn_write_teletype(0xff, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400586}
587
588static void
589handle_100f(struct bregs *regs)
590{
Kevin O'Connore7132042009-05-25 00:10:35 -0400591 regs->bh = GET_BDA(video_page);
592 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
593 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400594}
595
596
597static void
598handle_101000(struct bregs *regs)
599{
600 if (regs->bl > 0x14)
601 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400602 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400603}
604
605static void
606handle_101001(struct bregs *regs)
607{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400608 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400609}
610
611static void
612handle_101002(struct bregs *regs)
613{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400614 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400615}
616
617static void
618handle_101003(struct bregs *regs)
619{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400620 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400621}
622
623static void
624handle_101007(struct bregs *regs)
625{
626 if (regs->bl > 0x14)
627 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400628 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400629}
630
631static void
632handle_101008(struct bregs *regs)
633{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400634 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400635}
636
637static void
638handle_101009(struct bregs *regs)
639{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400640 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400641}
642
643static void
644handle_101010(struct bregs *regs)
645{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400646 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
647 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400648}
649
650static void
651handle_101012(struct bregs *regs)
652{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400653 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400654}
655
656static void
657handle_101013(struct bregs *regs)
658{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400659 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400660}
661
662static void
663handle_101015(struct bregs *regs)
664{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400665 u8 rgb[3];
666 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
667 regs->dh = rgb[0];
668 regs->ch = rgb[1];
669 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400670}
671
672static void
673handle_101017(struct bregs *regs)
674{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400675 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400676}
677
678static void
679handle_101018(struct bregs *regs)
680{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400681 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400682}
683
684static void
685handle_101019(struct bregs *regs)
686{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400687 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400688}
689
690static void
691handle_10101a(struct bregs *regs)
692{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400693 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400694}
695
696static void
697handle_10101b(struct bregs *regs)
698{
699 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
700}
701
702static void
703handle_1010XX(struct bregs *regs)
704{
705 debug_stub(regs);
706}
707
708static void
709handle_1010(struct bregs *regs)
710{
711 switch (regs->al) {
712 case 0x00: handle_101000(regs); break;
713 case 0x01: handle_101001(regs); break;
714 case 0x02: handle_101002(regs); break;
715 case 0x03: handle_101003(regs); break;
716 case 0x07: handle_101007(regs); break;
717 case 0x08: handle_101008(regs); break;
718 case 0x09: handle_101009(regs); break;
719 case 0x10: handle_101010(regs); break;
720 case 0x12: handle_101012(regs); break;
721 case 0x13: handle_101013(regs); break;
722 case 0x15: handle_101015(regs); break;
723 case 0x17: handle_101017(regs); break;
724 case 0x18: handle_101018(regs); break;
725 case 0x19: handle_101019(regs); break;
726 case 0x1a: handle_10101a(regs); break;
727 case 0x1b: handle_10101b(regs); break;
728 default: handle_1010XX(regs); break;
729 }
730}
731
732
733static void
734handle_101100(struct bregs *regs)
735{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400736 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
737 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400738}
739
740static void
741handle_101101(struct bregs *regs)
742{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400743 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400744}
745
746static void
747handle_101102(struct bregs *regs)
748{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400749 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400750}
751
752static void
753handle_101103(struct bregs *regs)
754{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400755 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400756}
757
758static void
759handle_101104(struct bregs *regs)
760{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400761 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400762}
763
764static void
765handle_101110(struct bregs *regs)
766{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400767 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
768 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400769 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400770}
771
772static void
773handle_101111(struct bregs *regs)
774{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400775 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400776 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400777}
778
779static void
780handle_101112(struct bregs *regs)
781{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400782 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400783 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400784}
785
786static void
787handle_101114(struct bregs *regs)
788{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400789 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400790 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400791}
792
793static void
794handle_101130(struct bregs *regs)
795{
Kevin O'Connore7132042009-05-25 00:10:35 -0400796 switch (regs->bh) {
797 case 0x00: {
798 u32 segoff = GET_IVT(0x1f).segoff;
799 regs->es = segoff >> 16;
800 regs->bp = segoff;
801 break;
802 }
803 case 0x01: {
804 u32 segoff = GET_IVT(0x43).segoff;
805 regs->es = segoff >> 16;
806 regs->bp = segoff;
807 break;
808 }
809 case 0x02:
810 regs->es = get_global_seg();
811 regs->bp = (u32)vgafont14;
812 break;
813 case 0x03:
814 regs->es = get_global_seg();
815 regs->bp = (u32)vgafont8;
816 break;
817 case 0x04:
818 regs->es = get_global_seg();
819 regs->bp = (u32)vgafont8 + 128 * 8;
820 break;
821 case 0x05:
822 regs->es = get_global_seg();
823 regs->bp = (u32)vgafont14alt;
824 break;
825 case 0x06:
826 regs->es = get_global_seg();
827 regs->bp = (u32)vgafont16;
828 break;
829 case 0x07:
830 regs->es = get_global_seg();
831 regs->bp = (u32)vgafont16alt;
832 break;
833 default:
834 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
835 return;
836 }
837 // Set byte/char of on screen font
838 regs->cx = GET_BDA(char_height) & 0xff;
839
840 // Set Highest char row
841 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400842}
843
844static void
845handle_1011XX(struct bregs *regs)
846{
847 debug_stub(regs);
848}
849
850static void
851handle_1011(struct bregs *regs)
852{
853 switch (regs->al) {
854 case 0x00: handle_101100(regs); break;
855 case 0x01: handle_101101(regs); break;
856 case 0x02: handle_101102(regs); break;
857 case 0x03: handle_101103(regs); break;
858 case 0x04: handle_101104(regs); break;
859 case 0x10: handle_101110(regs); break;
860 case 0x11: handle_101111(regs); break;
861 case 0x12: handle_101112(regs); break;
862 case 0x14: handle_101114(regs); break;
863 case 0x30: handle_101130(regs); break;
864 default: handle_1011XX(regs); break;
865 }
866}
867
868
869static void
870handle_101210(struct bregs *regs)
871{
Kevin O'Connore7132042009-05-25 00:10:35 -0400872 u16 crtc_addr = GET_BDA(crtc_address);
873 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
874 regs->bx = 0x0103;
875 else
876 regs->bx = 0x0003;
877 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400878}
879
880static void
881handle_101230(struct bregs *regs)
882{
Kevin O'Connore7132042009-05-25 00:10:35 -0400883 u8 mctl = GET_BDA(modeset_ctl);
884 u8 vswt = GET_BDA(video_switches);
885 switch (regs->al) {
886 case 0x00:
887 // 200 lines
888 mctl = (mctl & ~0x10) | 0x80;
889 vswt = (vswt & ~0x0f) | 0x08;
890 break;
891 case 0x01:
892 // 350 lines
893 mctl &= ~0x90;
894 vswt = (vswt & ~0x0f) | 0x09;
895 break;
896 case 0x02:
897 // 400 lines
898 mctl = (mctl & ~0x80) | 0x10;
899 vswt = (vswt & ~0x0f) | 0x09;
900 break;
901 default:
902 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
903 break;
904 }
905 SET_BDA(modeset_ctl, mctl);
906 SET_BDA(video_switches, vswt);
907 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400908}
909
910static void
911handle_101231(struct bregs *regs)
912{
Kevin O'Connore7132042009-05-25 00:10:35 -0400913 u8 v = (regs->al & 0x01) << 3;
914 u8 mctl = GET_BDA(video_ctl) & ~0x08;
915 SET_BDA(video_ctl, mctl | v);
916 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400917}
918
919static void
920handle_101232(struct bregs *regs)
921{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400922 vgahw_enable_video_addressing(regs->al);
923 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400924}
925
926static void
927handle_101233(struct bregs *regs)
928{
Kevin O'Connore7132042009-05-25 00:10:35 -0400929 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
930 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
931 SET_BDA(modeset_ctl, v | v2);
932 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400933}
934
935static void
936handle_101234(struct bregs *regs)
937{
Kevin O'Connore7132042009-05-25 00:10:35 -0400938 u8 v = (regs->al & 0x01) ^ 0x01;
939 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
940 SET_BDA(modeset_ctl, v | v2);
941 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400942}
943
944static void
945handle_101235(struct bregs *regs)
946{
947 debug_stub(regs);
948 regs->al = 0x12;
949}
950
951static void
952handle_101236(struct bregs *regs)
953{
954 debug_stub(regs);
955 regs->al = 0x12;
956}
957
958static void
959handle_1012XX(struct bregs *regs)
960{
961 debug_stub(regs);
962}
963
964static void
965handle_1012(struct bregs *regs)
966{
967 switch (regs->bl) {
968 case 0x10: handle_101210(regs); break;
969 case 0x30: handle_101230(regs); break;
970 case 0x31: handle_101231(regs); break;
971 case 0x32: handle_101232(regs); break;
972 case 0x33: handle_101233(regs); break;
973 case 0x34: handle_101234(regs); break;
974 case 0x35: handle_101235(regs); break;
975 case 0x36: handle_101236(regs); break;
976 default: handle_1012XX(regs); break;
977 }
978
979 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
980}
981
982
983static void
984handle_1013(struct bregs *regs)
985{
986 // XXX - inline
Kevin O'Connor918b1562009-05-25 11:05:18 -0400987 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
988 biosfn_write_string(cp, regs->al, regs->bl, regs->cx
989 , regs->es, (void*)(regs->bp + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400990}
991
992
993static void
994handle_101a00(struct bregs *regs)
995{
Kevin O'Connore7132042009-05-25 00:10:35 -0400996 regs->bx = GET_BDA(dcc_index);
997 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400998}
999
1000static void
1001handle_101a01(struct bregs *regs)
1002{
Kevin O'Connore7132042009-05-25 00:10:35 -04001003 SET_BDA(dcc_index, regs->bl);
1004 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1005 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001006}
1007
1008static void
1009handle_101aXX(struct bregs *regs)
1010{
1011 debug_stub(regs);
1012}
1013
1014static void
1015handle_101a(struct bregs *regs)
1016{
1017 switch (regs->al) {
1018 case 0x00: handle_101a00(regs); break;
1019 case 0x01: handle_101a01(regs); break;
1020 default: handle_101aXX(regs); break;
1021 }
1022}
1023
1024
Kevin O'Connorca668642009-05-21 23:06:08 -04001025struct funcInfo {
1026 u16 static_functionality_off;
1027 u16 static_functionality_seg;
1028 u8 bda_0x49[30];
1029 u8 bda_0x84[3];
1030 u8 dcc_index;
1031 u8 dcc_alt;
1032 u16 colors;
1033 u8 pages;
1034 u8 scan_lines;
1035 u8 primary_char;
1036 u8 secondar_char;
1037 u8 misc;
1038 u8 non_vga_mode;
1039 u8 reserved_2f[2];
1040 u8 video_mem;
1041 u8 save_flags;
1042 u8 disp_info;
1043 u8 reserved_34[12];
1044};
1045
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001046static void
1047handle_101b(struct bregs *regs)
1048{
Kevin O'Connorca668642009-05-21 23:06:08 -04001049 u16 seg = regs->es;
1050 struct funcInfo *info = (void*)(regs->di+0);
1051 memset_far(seg, info, 0, sizeof(*info));
1052 // Address of static functionality table
1053 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1054 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1055
1056 // Hard coded copy from BIOS area. Should it be cleaner ?
1057 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1058 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1059
1060 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1061 SET_FARVAR(seg, info->colors, 16);
1062 SET_FARVAR(seg, info->pages, 8);
1063 SET_FARVAR(seg, info->scan_lines, 2);
1064 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001065 regs->al = 0x1B;
1066}
1067
1068
1069static void
1070handle_101c00(struct bregs *regs)
1071{
Kevin O'Connorca668642009-05-21 23:06:08 -04001072 u16 flags = regs->cx;
1073 u16 size = 0;
1074 if (flags & 1)
1075 size += sizeof(struct saveVideoHardware);
1076 if (flags & 2)
1077 size += sizeof(struct saveBDAstate);
1078 if (flags & 4)
1079 size += sizeof(struct saveDACcolors);
1080 regs->bx = size;
1081 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001082}
1083
1084static void
1085handle_101c01(struct bregs *regs)
1086{
Kevin O'Connorca668642009-05-21 23:06:08 -04001087 u16 flags = regs->cx;
1088 u16 seg = regs->es;
1089 void *data = (void*)(regs->bx+0);
1090 if (flags & 1) {
1091 vgahw_save_state(seg, data);
1092 data += sizeof(struct saveVideoHardware);
1093 }
1094 if (flags & 2) {
1095 biosfn_save_bda_state(seg, data);
1096 data += sizeof(struct saveBDAstate);
1097 }
1098 if (flags & 4)
1099 vgahw_save_dac_state(seg, data);
1100 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001101}
1102
1103static void
1104handle_101c02(struct bregs *regs)
1105{
Kevin O'Connorca668642009-05-21 23:06:08 -04001106 u16 flags = regs->cx;
1107 u16 seg = regs->es;
1108 void *data = (void*)(regs->bx+0);
1109 if (flags & 1) {
1110 vgahw_restore_state(seg, data);
1111 data += sizeof(struct saveVideoHardware);
1112 }
1113 if (flags & 2) {
1114 biosfn_restore_bda_state(seg, data);
1115 data += sizeof(struct saveBDAstate);
1116 }
1117 if (flags & 4)
1118 vgahw_restore_dac_state(seg, data);
1119 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001120}
1121
1122static void
1123handle_101cXX(struct bregs *regs)
1124{
1125 debug_stub(regs);
1126}
1127
1128static void
1129handle_101c(struct bregs *regs)
1130{
1131 switch (regs->al) {
1132 case 0x00: handle_101c00(regs); break;
1133 case 0x01: handle_101c01(regs); break;
1134 case 0x02: handle_101c02(regs); break;
1135 default: handle_101cXX(regs); break;
1136 }
1137}
1138
1139
1140static void
1141handle_104f00(struct bregs *regs)
1142{
1143 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1144 // XXX - OR cirrus_vesa_00h
1145}
1146
1147static void
1148handle_104f01(struct bregs *regs)
1149{
1150 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1151 // XXX - OR cirrus_vesa_01h
1152}
1153
1154static void
1155handle_104f02(struct bregs *regs)
1156{
1157 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1158 // XXX - OR cirrus_vesa_02h
1159}
1160
1161static void
1162handle_104f03(struct bregs *regs)
1163{
1164 // XXX - vbe_biosfn_return_current_mode
1165 // XXX - OR cirrus_vesa_03h
1166}
1167
1168static void
1169handle_104f04(struct bregs *regs)
1170{
1171 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1172}
1173
1174static void
1175handle_104f05(struct bregs *regs)
1176{
1177 // XXX - vbe_biosfn_display_window_control
1178 // XXX - OR cirrus_vesa_05h
1179}
1180
1181static void
1182handle_104f06(struct bregs *regs)
1183{
1184 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1185 // XXX - OR cirrus_vesa_06h
1186}
1187
1188static void
1189handle_104f07(struct bregs *regs)
1190{
1191 // XXX - vbe_biosfn_set_get_display_start
1192 // XXX - OR cirrus_vesa_07h
1193}
1194
1195static void
1196handle_104f08(struct bregs *regs)
1197{
1198 // XXX - vbe_biosfn_set_get_dac_palette_format
1199}
1200
1201static void
1202handle_104f0a(struct bregs *regs)
1203{
1204 // XXX - vbe_biosfn_return_protected_mode_interface
1205}
1206
1207static void
1208handle_104fXX(struct bregs *regs)
1209{
1210 debug_stub(regs);
1211 regs->ax = 0x0100;
1212}
1213
1214static void
1215handle_104f(struct bregs *regs)
1216{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001217 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001218 handle_104fXX(regs);
1219 return;
1220 }
1221
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001222 switch (regs->al) {
1223 case 0x00: handle_104f00(regs); break;
1224 case 0x01: handle_104f01(regs); break;
1225 case 0x02: handle_104f02(regs); break;
1226 case 0x03: handle_104f03(regs); break;
1227 case 0x04: handle_104f04(regs); break;
1228 case 0x05: handle_104f05(regs); break;
1229 case 0x06: handle_104f06(regs); break;
1230 case 0x07: handle_104f07(regs); break;
1231 case 0x08: handle_104f08(regs); break;
1232 case 0x0a: handle_104f0a(regs); break;
1233 default: handle_104fXX(regs); break;
1234 }
1235}
1236
1237
1238static void
1239handle_10XX(struct bregs *regs)
1240{
1241 debug_stub(regs);
1242}
1243
1244// INT 10h Video Support Service Entry Point
1245void VISIBLE16
1246handle_10(struct bregs *regs)
1247{
1248 debug_enter(regs, DEBUG_VGA_10);
1249 switch (regs->ah) {
1250 case 0x00: handle_1000(regs); break;
1251 case 0x01: handle_1001(regs); break;
1252 case 0x02: handle_1002(regs); break;
1253 case 0x03: handle_1003(regs); break;
1254 case 0x04: handle_1004(regs); break;
1255 case 0x05: handle_1005(regs); break;
1256 case 0x06: handle_1006(regs); break;
1257 case 0x07: handle_1007(regs); break;
1258 case 0x08: handle_1008(regs); break;
1259 case 0x09: handle_1009(regs); break;
1260 case 0x0a: handle_100a(regs); break;
1261 case 0x0b: handle_100b(regs); break;
1262 case 0x0c: handle_100c(regs); break;
1263 case 0x0d: handle_100d(regs); break;
1264 case 0x0e: handle_100e(regs); break;
1265 case 0x0f: handle_100f(regs); break;
1266 case 0x10: handle_1010(regs); break;
1267 case 0x11: handle_1011(regs); break;
1268 case 0x12: handle_1012(regs); break;
1269 case 0x13: handle_1013(regs); break;
1270 case 0x1a: handle_101a(regs); break;
1271 case 0x1b: handle_101b(regs); break;
1272 case 0x1c: handle_101c(regs); break;
1273 case 0x4f: handle_104f(regs); break;
1274 default: handle_10XX(regs); break;
1275 }
1276}
1277
1278
1279/****************************************************************
1280 * VGA post
1281 ****************************************************************/
1282
1283static void
1284init_bios_area()
1285{
1286 // init detected hardware BIOS Area
1287 // set 80x25 color (not clear from RBIL but usual)
1288 u16 eqf = GET_BDA(equipment_list_flags);
1289 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1290
1291 // Just for the first int10 find its children
1292
1293 // the default char height
1294 SET_BDA(char_height, 0x10);
1295
1296 // Clear the screen
1297 SET_BDA(video_ctl, 0x60);
1298
1299 // Set the basic screen we have
1300 SET_BDA(video_switches, 0xf9);
1301
1302 // Set the basic modeset options
1303 SET_BDA(modeset_ctl, 0x51);
1304
1305 // Set the default MSR
1306 SET_BDA(video_msr, 0x09);
1307}
1308
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001309void VISIBLE16
1310vga_post(struct bregs *regs)
1311{
1312 debug_enter(regs, DEBUG_VGA_POST);
1313
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001314 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001315
1316 init_bios_area();
1317
Kevin O'Connor21079f42009-05-16 21:30:10 -04001318 if (CONFIG_VBE)
1319 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001320
1321 extern void entry_10(void);
Kevin O'Connord113a992009-05-16 21:05:02 -04001322 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001323
1324 if (CONFIG_CIRRUS)
1325 cirrus_init();
1326
1327 // XXX - clear screen and display info
1328
1329 // XXX: fill it
1330 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001331 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001332
1333 // Fixup checksum
1334 extern u8 _rom_header_size, _rom_header_checksum;
1335 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001336 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001337 SET_VGA(_rom_header_checksum, sum);
1338}