blob: 74c5680e1791e990f1be216d49a21e50d416db85 [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'Connor1f2c3072009-05-06 23:35:59 -0400180biosfn_write_teletype(u8 car, u8 page, u8 attr, u8 flag)
181{ // flag = WITH_ATTR / NO_ATTR
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
194 switch (car) {
195 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 {
214 biosfn_write_teletype(' ', page, attr, flag);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400215 cp = get_cursor_pos(page);
216 } while (cp.x % 8 == 0);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400217 break;
218
219 default:
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400220 if (flag == WITH_ATTR)
Kevin O'Connor918b1562009-05-25 11:05:18 -0400221 biosfn_write_char_attr(car, cp.page, attr, 1);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400222 else
Kevin O'Connor918b1562009-05-25 11:05:18 -0400223 biosfn_write_char_only(car, cp.page, attr, 1);
224 cp.x++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400225 }
226
227 // Do we need to wrap ?
Kevin O'Connor918b1562009-05-25 11:05:18 -0400228 if (cp.x == nbcols) {
229 cp.x = 0;
230 cp.y++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400231 }
232 // Do we need to scroll ?
Kevin O'Connor918b1562009-05-25 11:05:18 -0400233 if (cp.y == nbrows) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400234 if (GET_GLOBAL(vmode_g->class) == TEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400235 biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page,
236 SCROLL_UP);
237 else
238 biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page,
239 SCROLL_UP);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400240 cp.y--;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400241 }
242 // Set the cursor for the page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400243 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400244}
245
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400246static void
Kevin O'Connor918b1562009-05-25 11:05:18 -0400247biosfn_write_string(struct cursorpos cp, u8 flag, u8 attr, u16 count,
Kevin O'Connordd2be772009-05-16 15:41:23 -0400248 u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400249{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400250 // Read curs info for the page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400251 struct cursorpos oldcp = get_cursor_pos(cp.page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400252
253 // if row=0xff special case : use current cursor position
Kevin O'Connor918b1562009-05-25 11:05:18 -0400254 if (cp.y == 0xff)
255 cp = oldcp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400256
Kevin O'Connor918b1562009-05-25 11:05:18 -0400257 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400258
259 while (count-- != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400260 u8 car = GET_FARVAR(seg, *offset_far);
261 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400262 if ((flag & 0x02) != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400263 attr = GET_FARVAR(seg, *offset_far);
264 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400265 }
266
Kevin O'Connor918b1562009-05-25 11:05:18 -0400267 biosfn_write_teletype(car, cp.page, attr, WITH_ATTR);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400268 }
269
270 // Set back curs pos
271 if ((flag & 0x01) == 0)
Kevin O'Connor918b1562009-05-25 11:05:18 -0400272 set_cursor_pos(oldcp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400273}
274
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400275static void
Kevin O'Connore7132042009-05-25 00:10:35 -0400276set_scan_lines(u8 lines)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400277{
Kevin O'Connore7132042009-05-25 00:10:35 -0400278 vgahw_set_scan_lines(lines);
279 if (lines == 8)
280 biosfn_set_cursor_shape(0x06, 0x07);
281 else
282 biosfn_set_cursor_shape(lines - 4, lines - 3);
283 SET_BDA(char_height, lines);
284 u16 vde = vgahw_get_vde();
285 u8 rows = vde / lines;
286 SET_BDA(video_rows, rows - 1);
287 u16 cols = GET_BDA(video_cols);
288 SET_BDA(video_pagesize, rows * cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400289}
290
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400291static void
Kevin O'Connorca668642009-05-21 23:06:08 -0400292biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400293{
Kevin O'Connorca668642009-05-21 23:06:08 -0400294 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
295 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
296 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
297 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
298 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
299 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
300 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
301 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
302 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
303 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
304 u16 i;
305 for (i=0; i<8; i++)
306 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
307 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
308 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
309 /* current font */
310 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
311 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400312}
313
Kevin O'Connorca668642009-05-21 23:06:08 -0400314static void
315biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400316{
Kevin O'Connorca668642009-05-21 23:06:08 -0400317 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
318 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
319 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
320 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
321 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
322 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
323 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
324 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
325 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
326 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
327 u16 i;
328 for (i = 0; i < 8; i++)
329 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
330 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
331 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
332 /* current font */
333 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
334 , GET_FARVAR(seg, info->font0_off));
335 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
336 , GET_FARVAR(seg, info->font1_off));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400337}
338
339
340/****************************************************************
341 * VGA int 10 handler
342 ****************************************************************/
343
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400344// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400345static void
346handle_1000(struct bregs *regs)
347{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400348 u8 noclearmem = regs->al & 0x80;
349 u8 mode = regs->al & 0x7f;
350
Kevin O'Connor918b1562009-05-25 11:05:18 -0400351 // Set regs->al
352 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400353 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400354 else if (mode == 6)
355 regs->al = 0x3f;
356 else
357 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400358
359 if (CONFIG_CIRRUS)
360 cirrus_set_video_mode(mode);
361
362 if (CONFIG_VBE)
363 if (vbe_has_vbe_display())
364 dispi_set_enable(VBE_DISPI_DISABLED);
365
366 // find the entry in the video modes
367 struct vgamode_s *vmode_g = find_vga_entry(mode);
368 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
369 if (!vmode_g)
370 return;
371
372 // Read the bios mode set control
373 u8 modeset_ctl = GET_BDA(modeset_ctl);
374
375 // Then we know the number of lines
376// FIXME
377
378 // if palette loading (bit 3 of modeset ctl = 0)
379 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
380 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
381
382 // From which palette
383 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
384 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
385
386 // Always 256*3 values
387 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
388 u16 i;
389 for (i = palsize; i < 0x0100; i++) {
390 static u8 rgb[3] VAR16;
391 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
392 }
393
394 if ((modeset_ctl & 0x02) == 0x02)
395 biosfn_perform_gray_scale_summing(0x00, 0x100);
396 }
397
398 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
399 vgahw_set_mode(vparam_g);
400
401 if (noclearmem == 0x00)
402 clear_screen(vmode_g);
403
404 // Set CRTC address VGA or MDA
405 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
406 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
407 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
408
409 // Set the BIOS mem
410 u16 cheight = GET_GLOBAL(vparam_g->cheight);
411 SET_BDA(video_mode, mode);
412 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
413 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
414 SET_BDA(crtc_address, crtc_addr);
415 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
416 SET_BDA(char_height, cheight);
417 SET_BDA(video_ctl, (0x60 | noclearmem));
418 SET_BDA(video_switches, 0xF9);
419 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
420
421 // FIXME We nearly have the good tables. to be reworked
422 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
423 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
424 SET_BDA(video_savetable_seg, get_global_seg());
425
426 // FIXME
427 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
428 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
429
430 // Set cursor shape
431 if (GET_GLOBAL(vmode_g->class) == TEXT)
432 biosfn_set_cursor_shape(0x06, 0x07);
433 // Set cursor pos for page 0..7
434 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400435 for (i = 0; i < 8; i++) {
436 struct cursorpos cp = {0, 0, i};
437 set_cursor_pos(cp);
438 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400439
440 // Set active page 0
441 biosfn_set_active_page(0x00);
442
443 // Write the fonts in memory
444 if (GET_GLOBAL(vmode_g->class) == TEXT) {
445 call16_vgaint(0x1104, 0);
446 call16_vgaint(0x1103, 0);
447 }
448 // Set the ints 0x1F and 0x43
449 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
450
451 switch (cheight) {
452 case 8:
453 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
454 break;
455 case 14:
456 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
457 break;
458 case 16:
459 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
460 break;
461 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400462}
463
464static void
465handle_1001(struct bregs *regs)
466{
467 biosfn_set_cursor_shape(regs->ch, regs->cl);
468}
469
470static void
471handle_1002(struct bregs *regs)
472{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400473 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
474 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400475}
476
477static void
478handle_1003(struct bregs *regs)
479{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400480 regs->cx = biosfn_get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400481 struct cursorpos cp = get_cursor_pos(regs->bh);
482 regs->dl = cp.x;
483 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400484}
485
486// Read light pen pos (unimplemented)
487static void
488handle_1004(struct bregs *regs)
489{
490 debug_stub(regs);
491 regs->ax = regs->bx = regs->cx = regs->dx = 0;
492}
493
494static void
495handle_1005(struct bregs *regs)
496{
497 biosfn_set_active_page(regs->al);
498}
499
500static void
501handle_1006(struct bregs *regs)
502{
503 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
504 , 0xFF, SCROLL_UP);
505}
506
507static void
508handle_1007(struct bregs *regs)
509{
510 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
511 , 0xFF, SCROLL_DOWN);
512}
513
514static void
515handle_1008(struct bregs *regs)
516{
517 // XXX - inline
518 biosfn_read_char_attr(regs->bh, &regs->ax);
519}
520
521static void
522handle_1009(struct bregs *regs)
523{
524 // XXX - inline
525 biosfn_write_char_attr(regs->al, regs->bh, regs->bl, regs->cx);
526}
527
528static void
529handle_100a(struct bregs *regs)
530{
531 // XXX - inline
532 biosfn_write_char_only(regs->al, regs->bh, regs->bl, regs->cx);
533}
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 !
584 biosfn_write_teletype(regs->al, 0xff, regs->bl, NO_ATTR);
585}
586
587static void
588handle_100f(struct bregs *regs)
589{
Kevin O'Connore7132042009-05-25 00:10:35 -0400590 regs->bh = GET_BDA(video_page);
591 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
592 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400593}
594
595
596static void
597handle_101000(struct bregs *regs)
598{
599 if (regs->bl > 0x14)
600 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400601 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400602}
603
604static void
605handle_101001(struct bregs *regs)
606{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400607 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400608}
609
610static void
611handle_101002(struct bregs *regs)
612{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400613 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400614}
615
616static void
617handle_101003(struct bregs *regs)
618{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400619 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400620}
621
622static void
623handle_101007(struct bregs *regs)
624{
625 if (regs->bl > 0x14)
626 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400627 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400628}
629
630static void
631handle_101008(struct bregs *regs)
632{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400633 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400634}
635
636static void
637handle_101009(struct bregs *regs)
638{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400639 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400640}
641
642static void
643handle_101010(struct bregs *regs)
644{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400645 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
646 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400647}
648
649static void
650handle_101012(struct bregs *regs)
651{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400652 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400653}
654
655static void
656handle_101013(struct bregs *regs)
657{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400658 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400659}
660
661static void
662handle_101015(struct bregs *regs)
663{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400664 u8 rgb[3];
665 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
666 regs->dh = rgb[0];
667 regs->ch = rgb[1];
668 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400669}
670
671static void
672handle_101017(struct bregs *regs)
673{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400674 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400675}
676
677static void
678handle_101018(struct bregs *regs)
679{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400680 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400681}
682
683static void
684handle_101019(struct bregs *regs)
685{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400686 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400687}
688
689static void
690handle_10101a(struct bregs *regs)
691{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400692 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400693}
694
695static void
696handle_10101b(struct bregs *regs)
697{
698 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
699}
700
701static void
702handle_1010XX(struct bregs *regs)
703{
704 debug_stub(regs);
705}
706
707static void
708handle_1010(struct bregs *regs)
709{
710 switch (regs->al) {
711 case 0x00: handle_101000(regs); break;
712 case 0x01: handle_101001(regs); break;
713 case 0x02: handle_101002(regs); break;
714 case 0x03: handle_101003(regs); break;
715 case 0x07: handle_101007(regs); break;
716 case 0x08: handle_101008(regs); break;
717 case 0x09: handle_101009(regs); break;
718 case 0x10: handle_101010(regs); break;
719 case 0x12: handle_101012(regs); break;
720 case 0x13: handle_101013(regs); break;
721 case 0x15: handle_101015(regs); break;
722 case 0x17: handle_101017(regs); break;
723 case 0x18: handle_101018(regs); break;
724 case 0x19: handle_101019(regs); break;
725 case 0x1a: handle_10101a(regs); break;
726 case 0x1b: handle_10101b(regs); break;
727 default: handle_1010XX(regs); break;
728 }
729}
730
731
732static void
733handle_101100(struct bregs *regs)
734{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400735 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
736 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400737}
738
739static void
740handle_101101(struct bregs *regs)
741{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400742 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400743}
744
745static void
746handle_101102(struct bregs *regs)
747{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400748 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400749}
750
751static void
752handle_101103(struct bregs *regs)
753{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400754 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400755}
756
757static void
758handle_101104(struct bregs *regs)
759{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400760 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400761}
762
763static void
764handle_101110(struct bregs *regs)
765{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400766 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
767 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400768 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400769}
770
771static void
772handle_101111(struct bregs *regs)
773{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400774 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400775 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400776}
777
778static void
779handle_101112(struct bregs *regs)
780{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400781 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400782 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400783}
784
785static void
786handle_101114(struct bregs *regs)
787{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400788 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400789 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400790}
791
792static void
793handle_101130(struct bregs *regs)
794{
Kevin O'Connore7132042009-05-25 00:10:35 -0400795 switch (regs->bh) {
796 case 0x00: {
797 u32 segoff = GET_IVT(0x1f).segoff;
798 regs->es = segoff >> 16;
799 regs->bp = segoff;
800 break;
801 }
802 case 0x01: {
803 u32 segoff = GET_IVT(0x43).segoff;
804 regs->es = segoff >> 16;
805 regs->bp = segoff;
806 break;
807 }
808 case 0x02:
809 regs->es = get_global_seg();
810 regs->bp = (u32)vgafont14;
811 break;
812 case 0x03:
813 regs->es = get_global_seg();
814 regs->bp = (u32)vgafont8;
815 break;
816 case 0x04:
817 regs->es = get_global_seg();
818 regs->bp = (u32)vgafont8 + 128 * 8;
819 break;
820 case 0x05:
821 regs->es = get_global_seg();
822 regs->bp = (u32)vgafont14alt;
823 break;
824 case 0x06:
825 regs->es = get_global_seg();
826 regs->bp = (u32)vgafont16;
827 break;
828 case 0x07:
829 regs->es = get_global_seg();
830 regs->bp = (u32)vgafont16alt;
831 break;
832 default:
833 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
834 return;
835 }
836 // Set byte/char of on screen font
837 regs->cx = GET_BDA(char_height) & 0xff;
838
839 // Set Highest char row
840 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400841}
842
843static void
844handle_1011XX(struct bregs *regs)
845{
846 debug_stub(regs);
847}
848
849static void
850handle_1011(struct bregs *regs)
851{
852 switch (regs->al) {
853 case 0x00: handle_101100(regs); break;
854 case 0x01: handle_101101(regs); break;
855 case 0x02: handle_101102(regs); break;
856 case 0x03: handle_101103(regs); break;
857 case 0x04: handle_101104(regs); break;
858 case 0x10: handle_101110(regs); break;
859 case 0x11: handle_101111(regs); break;
860 case 0x12: handle_101112(regs); break;
861 case 0x14: handle_101114(regs); break;
862 case 0x30: handle_101130(regs); break;
863 default: handle_1011XX(regs); break;
864 }
865}
866
867
868static void
869handle_101210(struct bregs *regs)
870{
Kevin O'Connore7132042009-05-25 00:10:35 -0400871 u16 crtc_addr = GET_BDA(crtc_address);
872 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
873 regs->bx = 0x0103;
874 else
875 regs->bx = 0x0003;
876 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400877}
878
879static void
880handle_101230(struct bregs *regs)
881{
Kevin O'Connore7132042009-05-25 00:10:35 -0400882 u8 mctl = GET_BDA(modeset_ctl);
883 u8 vswt = GET_BDA(video_switches);
884 switch (regs->al) {
885 case 0x00:
886 // 200 lines
887 mctl = (mctl & ~0x10) | 0x80;
888 vswt = (vswt & ~0x0f) | 0x08;
889 break;
890 case 0x01:
891 // 350 lines
892 mctl &= ~0x90;
893 vswt = (vswt & ~0x0f) | 0x09;
894 break;
895 case 0x02:
896 // 400 lines
897 mctl = (mctl & ~0x80) | 0x10;
898 vswt = (vswt & ~0x0f) | 0x09;
899 break;
900 default:
901 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
902 break;
903 }
904 SET_BDA(modeset_ctl, mctl);
905 SET_BDA(video_switches, vswt);
906 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400907}
908
909static void
910handle_101231(struct bregs *regs)
911{
Kevin O'Connore7132042009-05-25 00:10:35 -0400912 u8 v = (regs->al & 0x01) << 3;
913 u8 mctl = GET_BDA(video_ctl) & ~0x08;
914 SET_BDA(video_ctl, mctl | v);
915 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400916}
917
918static void
919handle_101232(struct bregs *regs)
920{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400921 vgahw_enable_video_addressing(regs->al);
922 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400923}
924
925static void
926handle_101233(struct bregs *regs)
927{
Kevin O'Connore7132042009-05-25 00:10:35 -0400928 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
929 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
930 SET_BDA(modeset_ctl, v | v2);
931 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400932}
933
934static void
935handle_101234(struct bregs *regs)
936{
Kevin O'Connore7132042009-05-25 00:10:35 -0400937 u8 v = (regs->al & 0x01) ^ 0x01;
938 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
939 SET_BDA(modeset_ctl, v | v2);
940 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400941}
942
943static void
944handle_101235(struct bregs *regs)
945{
946 debug_stub(regs);
947 regs->al = 0x12;
948}
949
950static void
951handle_101236(struct bregs *regs)
952{
953 debug_stub(regs);
954 regs->al = 0x12;
955}
956
957static void
958handle_1012XX(struct bregs *regs)
959{
960 debug_stub(regs);
961}
962
963static void
964handle_1012(struct bregs *regs)
965{
966 switch (regs->bl) {
967 case 0x10: handle_101210(regs); break;
968 case 0x30: handle_101230(regs); break;
969 case 0x31: handle_101231(regs); break;
970 case 0x32: handle_101232(regs); break;
971 case 0x33: handle_101233(regs); break;
972 case 0x34: handle_101234(regs); break;
973 case 0x35: handle_101235(regs); break;
974 case 0x36: handle_101236(regs); break;
975 default: handle_1012XX(regs); break;
976 }
977
978 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
979}
980
981
982static void
983handle_1013(struct bregs *regs)
984{
985 // XXX - inline
Kevin O'Connor918b1562009-05-25 11:05:18 -0400986 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
987 biosfn_write_string(cp, regs->al, regs->bl, regs->cx
988 , regs->es, (void*)(regs->bp + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400989}
990
991
992static void
993handle_101a00(struct bregs *regs)
994{
Kevin O'Connore7132042009-05-25 00:10:35 -0400995 regs->bx = GET_BDA(dcc_index);
996 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400997}
998
999static void
1000handle_101a01(struct bregs *regs)
1001{
Kevin O'Connore7132042009-05-25 00:10:35 -04001002 SET_BDA(dcc_index, regs->bl);
1003 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1004 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001005}
1006
1007static void
1008handle_101aXX(struct bregs *regs)
1009{
1010 debug_stub(regs);
1011}
1012
1013static void
1014handle_101a(struct bregs *regs)
1015{
1016 switch (regs->al) {
1017 case 0x00: handle_101a00(regs); break;
1018 case 0x01: handle_101a01(regs); break;
1019 default: handle_101aXX(regs); break;
1020 }
1021}
1022
1023
Kevin O'Connorca668642009-05-21 23:06:08 -04001024struct funcInfo {
1025 u16 static_functionality_off;
1026 u16 static_functionality_seg;
1027 u8 bda_0x49[30];
1028 u8 bda_0x84[3];
1029 u8 dcc_index;
1030 u8 dcc_alt;
1031 u16 colors;
1032 u8 pages;
1033 u8 scan_lines;
1034 u8 primary_char;
1035 u8 secondar_char;
1036 u8 misc;
1037 u8 non_vga_mode;
1038 u8 reserved_2f[2];
1039 u8 video_mem;
1040 u8 save_flags;
1041 u8 disp_info;
1042 u8 reserved_34[12];
1043};
1044
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001045static void
1046handle_101b(struct bregs *regs)
1047{
Kevin O'Connorca668642009-05-21 23:06:08 -04001048 u16 seg = regs->es;
1049 struct funcInfo *info = (void*)(regs->di+0);
1050 memset_far(seg, info, 0, sizeof(*info));
1051 // Address of static functionality table
1052 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1053 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1054
1055 // Hard coded copy from BIOS area. Should it be cleaner ?
1056 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1057 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1058
1059 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1060 SET_FARVAR(seg, info->colors, 16);
1061 SET_FARVAR(seg, info->pages, 8);
1062 SET_FARVAR(seg, info->scan_lines, 2);
1063 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001064 regs->al = 0x1B;
1065}
1066
1067
1068static void
1069handle_101c00(struct bregs *regs)
1070{
Kevin O'Connorca668642009-05-21 23:06:08 -04001071 u16 flags = regs->cx;
1072 u16 size = 0;
1073 if (flags & 1)
1074 size += sizeof(struct saveVideoHardware);
1075 if (flags & 2)
1076 size += sizeof(struct saveBDAstate);
1077 if (flags & 4)
1078 size += sizeof(struct saveDACcolors);
1079 regs->bx = size;
1080 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001081}
1082
1083static void
1084handle_101c01(struct bregs *regs)
1085{
Kevin O'Connorca668642009-05-21 23:06:08 -04001086 u16 flags = regs->cx;
1087 u16 seg = regs->es;
1088 void *data = (void*)(regs->bx+0);
1089 if (flags & 1) {
1090 vgahw_save_state(seg, data);
1091 data += sizeof(struct saveVideoHardware);
1092 }
1093 if (flags & 2) {
1094 biosfn_save_bda_state(seg, data);
1095 data += sizeof(struct saveBDAstate);
1096 }
1097 if (flags & 4)
1098 vgahw_save_dac_state(seg, data);
1099 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001100}
1101
1102static void
1103handle_101c02(struct bregs *regs)
1104{
Kevin O'Connorca668642009-05-21 23:06:08 -04001105 u16 flags = regs->cx;
1106 u16 seg = regs->es;
1107 void *data = (void*)(regs->bx+0);
1108 if (flags & 1) {
1109 vgahw_restore_state(seg, data);
1110 data += sizeof(struct saveVideoHardware);
1111 }
1112 if (flags & 2) {
1113 biosfn_restore_bda_state(seg, data);
1114 data += sizeof(struct saveBDAstate);
1115 }
1116 if (flags & 4)
1117 vgahw_restore_dac_state(seg, data);
1118 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001119}
1120
1121static void
1122handle_101cXX(struct bregs *regs)
1123{
1124 debug_stub(regs);
1125}
1126
1127static void
1128handle_101c(struct bregs *regs)
1129{
1130 switch (regs->al) {
1131 case 0x00: handle_101c00(regs); break;
1132 case 0x01: handle_101c01(regs); break;
1133 case 0x02: handle_101c02(regs); break;
1134 default: handle_101cXX(regs); break;
1135 }
1136}
1137
1138
1139static void
1140handle_104f00(struct bregs *regs)
1141{
1142 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1143 // XXX - OR cirrus_vesa_00h
1144}
1145
1146static void
1147handle_104f01(struct bregs *regs)
1148{
1149 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1150 // XXX - OR cirrus_vesa_01h
1151}
1152
1153static void
1154handle_104f02(struct bregs *regs)
1155{
1156 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1157 // XXX - OR cirrus_vesa_02h
1158}
1159
1160static void
1161handle_104f03(struct bregs *regs)
1162{
1163 // XXX - vbe_biosfn_return_current_mode
1164 // XXX - OR cirrus_vesa_03h
1165}
1166
1167static void
1168handle_104f04(struct bregs *regs)
1169{
1170 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1171}
1172
1173static void
1174handle_104f05(struct bregs *regs)
1175{
1176 // XXX - vbe_biosfn_display_window_control
1177 // XXX - OR cirrus_vesa_05h
1178}
1179
1180static void
1181handle_104f06(struct bregs *regs)
1182{
1183 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1184 // XXX - OR cirrus_vesa_06h
1185}
1186
1187static void
1188handle_104f07(struct bregs *regs)
1189{
1190 // XXX - vbe_biosfn_set_get_display_start
1191 // XXX - OR cirrus_vesa_07h
1192}
1193
1194static void
1195handle_104f08(struct bregs *regs)
1196{
1197 // XXX - vbe_biosfn_set_get_dac_palette_format
1198}
1199
1200static void
1201handle_104f0a(struct bregs *regs)
1202{
1203 // XXX - vbe_biosfn_return_protected_mode_interface
1204}
1205
1206static void
1207handle_104fXX(struct bregs *regs)
1208{
1209 debug_stub(regs);
1210 regs->ax = 0x0100;
1211}
1212
1213static void
1214handle_104f(struct bregs *regs)
1215{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001216 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001217 handle_104fXX(regs);
1218 return;
1219 }
1220
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001221 switch (regs->al) {
1222 case 0x00: handle_104f00(regs); break;
1223 case 0x01: handle_104f01(regs); break;
1224 case 0x02: handle_104f02(regs); break;
1225 case 0x03: handle_104f03(regs); break;
1226 case 0x04: handle_104f04(regs); break;
1227 case 0x05: handle_104f05(regs); break;
1228 case 0x06: handle_104f06(regs); break;
1229 case 0x07: handle_104f07(regs); break;
1230 case 0x08: handle_104f08(regs); break;
1231 case 0x0a: handle_104f0a(regs); break;
1232 default: handle_104fXX(regs); break;
1233 }
1234}
1235
1236
1237static void
1238handle_10XX(struct bregs *regs)
1239{
1240 debug_stub(regs);
1241}
1242
1243// INT 10h Video Support Service Entry Point
1244void VISIBLE16
1245handle_10(struct bregs *regs)
1246{
1247 debug_enter(regs, DEBUG_VGA_10);
1248 switch (regs->ah) {
1249 case 0x00: handle_1000(regs); break;
1250 case 0x01: handle_1001(regs); break;
1251 case 0x02: handle_1002(regs); break;
1252 case 0x03: handle_1003(regs); break;
1253 case 0x04: handle_1004(regs); break;
1254 case 0x05: handle_1005(regs); break;
1255 case 0x06: handle_1006(regs); break;
1256 case 0x07: handle_1007(regs); break;
1257 case 0x08: handle_1008(regs); break;
1258 case 0x09: handle_1009(regs); break;
1259 case 0x0a: handle_100a(regs); break;
1260 case 0x0b: handle_100b(regs); break;
1261 case 0x0c: handle_100c(regs); break;
1262 case 0x0d: handle_100d(regs); break;
1263 case 0x0e: handle_100e(regs); break;
1264 case 0x0f: handle_100f(regs); break;
1265 case 0x10: handle_1010(regs); break;
1266 case 0x11: handle_1011(regs); break;
1267 case 0x12: handle_1012(regs); break;
1268 case 0x13: handle_1013(regs); break;
1269 case 0x1a: handle_101a(regs); break;
1270 case 0x1b: handle_101b(regs); break;
1271 case 0x1c: handle_101c(regs); break;
1272 case 0x4f: handle_104f(regs); break;
1273 default: handle_10XX(regs); break;
1274 }
1275}
1276
1277
1278/****************************************************************
1279 * VGA post
1280 ****************************************************************/
1281
1282static void
1283init_bios_area()
1284{
1285 // init detected hardware BIOS Area
1286 // set 80x25 color (not clear from RBIL but usual)
1287 u16 eqf = GET_BDA(equipment_list_flags);
1288 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1289
1290 // Just for the first int10 find its children
1291
1292 // the default char height
1293 SET_BDA(char_height, 0x10);
1294
1295 // Clear the screen
1296 SET_BDA(video_ctl, 0x60);
1297
1298 // Set the basic screen we have
1299 SET_BDA(video_switches, 0xf9);
1300
1301 // Set the basic modeset options
1302 SET_BDA(modeset_ctl, 0x51);
1303
1304 // Set the default MSR
1305 SET_BDA(video_msr, 0x09);
1306}
1307
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001308void VISIBLE16
1309vga_post(struct bregs *regs)
1310{
1311 debug_enter(regs, DEBUG_VGA_POST);
1312
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001313 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001314
1315 init_bios_area();
1316
Kevin O'Connor21079f42009-05-16 21:30:10 -04001317 if (CONFIG_VBE)
1318 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001319
1320 extern void entry_10(void);
Kevin O'Connord113a992009-05-16 21:05:02 -04001321 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001322
1323 if (CONFIG_CIRRUS)
1324 cirrus_init();
1325
1326 // XXX - clear screen and display info
1327
1328 // XXX: fill it
1329 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001330 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001331
1332 // Fixup checksum
1333 extern u8 _rom_header_size, _rom_header_checksum;
1334 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001335 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001336 SET_VGA(_rom_header_checksum, sum);
1337}