blob: c28d8915f3dee27c592f66a9993e5a097522f95d [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// * review correctness of converted asm by comparing with RBIL
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040011// * refactor redundant code into sub-functions
12// * See if there is a method to the in/out stuff that can be encapsulated.
13// * remove "biosfn" prefixes
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040014// * verify all funcs static
15//
Kevin O'Connor6ace78f2009-05-14 19:24:49 -040016// * convert vbe/clext code
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040017
18#include "bregs.h" // struct bregs
19#include "biosvar.h" // GET_BDA
20#include "util.h" // memset
Kevin O'Connorc0c7df62009-05-17 18:11:33 -040021#include "vgatables.h" // find_vga_entry
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040022
23// XXX
24#define CONFIG_VBE 0
25#define CONFIG_CIRRUS 0
26
27// XXX
28#define DEBUG_VGA_POST 1
29#define DEBUG_VGA_10 3
30
Kevin O'Connord113a992009-05-16 21:05:02 -040031#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040032
Kevin O'Connor217f2bc2009-05-31 00:46:47 -040033static inline void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040034call16_vgaint(u32 eax, u32 ebx)
35{
36 asm volatile(
37 "int $0x10\n"
38 "cli\n"
39 "cld"
40 :
41 : "a"(eax), "b"(ebx)
42 : "cc", "memory");
43}
44
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040045static void
46biosfn_perform_gray_scale_summing(u16 start, u16 count)
47{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040048 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040049 int i;
50 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040051 u8 rgb[3];
52 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040053
54 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040055 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040056 if (intensity > 0x3f)
57 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040058
Kevin O'Connora0ecb052009-05-18 23:34:00 -040059 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040060 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040061 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040062}
63
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040064static void
65biosfn_set_cursor_shape(u8 CH, u8 CL)
66{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040067 CH &= 0x3f;
68 CL &= 0x1f;
69
Kevin O'Connordd2be772009-05-16 15:41:23 -040070 u16 curs = (CH << 8) + CL;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040071 SET_BDA(cursor_type, curs);
72
Kevin O'Connordd2be772009-05-16 15:41:23 -040073 u8 modeset_ctl = GET_BDA(modeset_ctl);
74 u16 cheight = GET_BDA(char_height);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040075 if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -040076 if (CL != (CH + 1))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040077 CH = ((CH + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040078 else
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040079 CH = ((CL + 1) * cheight / 8) - 2;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040080 CL = ((CL + 1) * cheight / 8) - 1;
81 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040082 vgahw_set_cursor_shape(CH, CL);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040083}
84
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040085static u16
86biosfn_get_cursor_shape(u8 page)
87{
88 if (page > 7)
89 return 0;
90 // FIXME should handle VGA 14/16 lines
91 return GET_BDA(cursor_type);
92}
93
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040094static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040095set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040096{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040097 // Should not happen...
Kevin O'Connor918b1562009-05-25 11:05:18 -040098 if (cp.page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040099 return;
100
101 // Bios cursor pos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400102 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400103
104 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400105 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400106 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400107 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400108
Kevin O'Connordd2be772009-05-16 15:41:23 -0400109 // Get the dimensions
110 u16 nbcols = GET_BDA(video_cols);
111 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400112
Kevin O'Connordd2be772009-05-16 15:41:23 -0400113 // Calculate the address knowing nbcols nbrows and page num
Kevin O'Connor918b1562009-05-25 11:05:18 -0400114 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
115 + cp.x + cp.y * nbcols);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400116
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400117 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400118}
119
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400120static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400121get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400122{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400123 if (page == 0xff)
124 // special case - use current page
125 page = GET_BDA(video_page);
126 if (page > 7) {
127 struct cursorpos cp = { 0, 0, 0xfe };
128 return cp;
129 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400130 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400131 u16 xy = GET_BDA(cursor_pos[page]);
132 struct cursorpos cp = {xy, xy>>8, page};
133 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400134}
135
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400136static void
137biosfn_set_active_page(u8 page)
138{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400139 if (page > 7)
140 return;
141
142 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400143 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
144 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400145 return;
146
147 // Get pos curs pos for the right page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400148 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400149
Kevin O'Connordd2be772009-05-16 15:41:23 -0400150 u16 address;
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400151 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400152 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400153 u16 nbcols = GET_BDA(video_cols);
154 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400155
156 // Calculate the address knowing nbcols nbrows and page num
157 address = SCREEN_MEM_START(nbcols, nbrows, page);
158 SET_BDA(video_pagestart, address);
159
160 // Start address
161 address = SCREEN_IO_START(nbcols, nbrows, page);
162 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400163 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
164 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400165 }
166
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400167 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400168
169 // And change the BIOS page
170 SET_BDA(video_page, page);
171
Kevin O'Connora12c2152009-05-13 22:06:16 -0400172 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400173
174 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400175 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400176}
177
Kevin O'Connor82221b22009-05-26 00:20:40 -0400178static struct cursorpos
179check_scroll(struct cursorpos cp)
Kevin O'Connor09262412009-05-25 11:44:11 -0400180{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400181 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400182 u16 nbrows = GET_BDA(video_rows) + 1;
183 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400184
Kevin O'Connor82221b22009-05-26 00:20:40 -0400185 // Do we need to wrap ?
186 if (cp.x == nbcols) {
187 cp.x = 0;
188 cp.y++;
189 }
190 // Do we need to scroll ?
191 if (cp.y == nbrows) {
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400192 struct cursorpos ul = {0, 0, cp.page};
193 struct cursorpos lr = {nbcols-1, nbrows-1, cp.page};
194 vgafb_scroll(1, -1, ul, lr);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400195 cp.y--;
196 }
197
198 return cp;
199}
200
Kevin O'Connor116a0442009-05-26 00:47:32 -0400201static struct cursorpos
202write_teletype(struct cursorpos cp, struct carattr ca)
Kevin O'Connor82221b22009-05-26 00:20:40 -0400203{
Kevin O'Connor09262412009-05-25 11:44:11 -0400204 switch (ca.car) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400205 case 7:
206 //FIXME should beep
207 break;
208
209 case 8:
Kevin O'Connor918b1562009-05-25 11:05:18 -0400210 if (cp.x > 0)
211 cp.x--;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400212 break;
213
214 case '\r':
Kevin O'Connor918b1562009-05-25 11:05:18 -0400215 cp.x = 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400216 break;
217
218 case '\n':
Kevin O'Connor918b1562009-05-25 11:05:18 -0400219 cp.y++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400220 break;
221
222 case '\t':
223 do {
Kevin O'Connor09262412009-05-25 11:44:11 -0400224 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
Kevin O'Connor82221b22009-05-26 00:20:40 -0400225 vgafb_write_char(cp, dummyca);
226 cp.x++;
227 cp = check_scroll(cp);
228 } while (cp.x % 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400229 break;
230
231 default:
Kevin O'Connord3b38152009-05-26 00:05:37 -0400232 vgafb_write_char(cp, ca);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400233 cp.x++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400234 }
235
Kevin O'Connor116a0442009-05-26 00:47:32 -0400236 return check_scroll(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400237}
238
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400239static void
Kevin O'Connor116a0442009-05-26 00:47:32 -0400240write_string(struct cursorpos cp, u8 flag, u8 attr, u16 count,
241 u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400242{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400243 // if row=0xff special case : use current cursor position
Kevin O'Connor918b1562009-05-25 11:05:18 -0400244 if (cp.y == 0xff)
Kevin O'Connor116a0442009-05-26 00:47:32 -0400245 cp = get_cursor_pos(cp.page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400246
247 while (count-- != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400248 u8 car = GET_FARVAR(seg, *offset_far);
249 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400250 if ((flag & 0x02) != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400251 attr = GET_FARVAR(seg, *offset_far);
252 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400253 }
254
Kevin O'Connor09262412009-05-25 11:44:11 -0400255 struct carattr ca = {car, attr, 1};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400256 cp = write_teletype(cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400257 }
258
Kevin O'Connor116a0442009-05-26 00:47:32 -0400259 if (flag & 0x01)
260 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400261}
262
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400263static void
Kevin O'Connore7132042009-05-25 00:10:35 -0400264set_scan_lines(u8 lines)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400265{
Kevin O'Connore7132042009-05-25 00:10:35 -0400266 vgahw_set_scan_lines(lines);
267 if (lines == 8)
268 biosfn_set_cursor_shape(0x06, 0x07);
269 else
270 biosfn_set_cursor_shape(lines - 4, lines - 3);
271 SET_BDA(char_height, lines);
272 u16 vde = vgahw_get_vde();
273 u8 rows = vde / lines;
274 SET_BDA(video_rows, rows - 1);
275 u16 cols = GET_BDA(video_cols);
276 SET_BDA(video_pagesize, rows * cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400277}
278
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400279static void
Kevin O'Connorca668642009-05-21 23:06:08 -0400280biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400281{
Kevin O'Connorca668642009-05-21 23:06:08 -0400282 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
283 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
284 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
285 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
286 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
287 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
288 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
289 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
290 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
291 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
292 u16 i;
293 for (i=0; i<8; i++)
294 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
295 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
296 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
297 /* current font */
298 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
299 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400300}
301
Kevin O'Connorca668642009-05-21 23:06:08 -0400302static void
303biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400304{
Kevin O'Connorca668642009-05-21 23:06:08 -0400305 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
306 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
307 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
308 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
309 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
310 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
311 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
312 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
313 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
314 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
315 u16 i;
316 for (i = 0; i < 8; i++)
317 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
318 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
319 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
320 /* current font */
321 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
322 , GET_FARVAR(seg, info->font0_off));
323 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
324 , GET_FARVAR(seg, info->font1_off));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400325}
326
327
328/****************************************************************
329 * VGA int 10 handler
330 ****************************************************************/
331
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400332// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400333static void
334handle_1000(struct bregs *regs)
335{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400336 u8 noclearmem = regs->al & 0x80;
337 u8 mode = regs->al & 0x7f;
338
Kevin O'Connor918b1562009-05-25 11:05:18 -0400339 // Set regs->al
340 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400341 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400342 else if (mode == 6)
343 regs->al = 0x3f;
344 else
345 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400346
347 if (CONFIG_CIRRUS)
348 cirrus_set_video_mode(mode);
349
350 if (CONFIG_VBE)
351 if (vbe_has_vbe_display())
352 dispi_set_enable(VBE_DISPI_DISABLED);
353
354 // find the entry in the video modes
355 struct vgamode_s *vmode_g = find_vga_entry(mode);
356 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
357 if (!vmode_g)
358 return;
359
360 // Read the bios mode set control
361 u8 modeset_ctl = GET_BDA(modeset_ctl);
362
363 // Then we know the number of lines
364// FIXME
365
366 // if palette loading (bit 3 of modeset ctl = 0)
367 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
368 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
369
370 // From which palette
371 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
372 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
373
374 // Always 256*3 values
375 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
376 u16 i;
377 for (i = palsize; i < 0x0100; i++) {
378 static u8 rgb[3] VAR16;
379 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
380 }
381
382 if ((modeset_ctl & 0x02) == 0x02)
383 biosfn_perform_gray_scale_summing(0x00, 0x100);
384 }
385
386 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
387 vgahw_set_mode(vparam_g);
388
389 if (noclearmem == 0x00)
390 clear_screen(vmode_g);
391
392 // Set CRTC address VGA or MDA
393 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
394 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
395 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
396
397 // Set the BIOS mem
398 u16 cheight = GET_GLOBAL(vparam_g->cheight);
399 SET_BDA(video_mode, mode);
400 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
401 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
402 SET_BDA(crtc_address, crtc_addr);
403 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
404 SET_BDA(char_height, cheight);
405 SET_BDA(video_ctl, (0x60 | noclearmem));
406 SET_BDA(video_switches, 0xF9);
407 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
408
409 // FIXME We nearly have the good tables. to be reworked
410 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
411 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
412 SET_BDA(video_savetable_seg, get_global_seg());
413
414 // FIXME
415 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
416 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
417
418 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400419 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400420 biosfn_set_cursor_shape(0x06, 0x07);
421 // Set cursor pos for page 0..7
422 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400423 for (i = 0; i < 8; i++) {
424 struct cursorpos cp = {0, 0, i};
425 set_cursor_pos(cp);
426 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400427
428 // Set active page 0
429 biosfn_set_active_page(0x00);
430
431 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400432 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400433 call16_vgaint(0x1104, 0);
434 call16_vgaint(0x1103, 0);
435 }
436 // Set the ints 0x1F and 0x43
437 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
438
439 switch (cheight) {
440 case 8:
441 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
442 break;
443 case 14:
444 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
445 break;
446 case 16:
447 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
448 break;
449 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400450}
451
452static void
453handle_1001(struct bregs *regs)
454{
455 biosfn_set_cursor_shape(regs->ch, regs->cl);
456}
457
458static void
459handle_1002(struct bregs *regs)
460{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400461 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
462 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400463}
464
465static void
466handle_1003(struct bregs *regs)
467{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400468 regs->cx = biosfn_get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400469 struct cursorpos cp = get_cursor_pos(regs->bh);
470 regs->dl = cp.x;
471 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400472}
473
474// Read light pen pos (unimplemented)
475static void
476handle_1004(struct bregs *regs)
477{
478 debug_stub(regs);
479 regs->ax = regs->bx = regs->cx = regs->dx = 0;
480}
481
482static void
483handle_1005(struct bregs *regs)
484{
485 biosfn_set_active_page(regs->al);
486}
487
488static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400489verify_scroll(struct bregs *regs, int dir)
490{
491 u8 page = GET_BDA(video_page);
492 struct cursorpos ul = {regs->cl, regs->ch, page};
493 struct cursorpos lr = {regs->dl, regs->dh, page};
494
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400495 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400496 if (lr.y >= nbrows)
497 lr.y = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400498 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400499 if (lr.x >= nbcols)
500 lr.x = nbcols - 1;
501
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400502 if (ul.x > lr.x || ul.y > lr.y)
503 return;
504
505 u16 nblines = regs->al;
506 if (!nblines || nblines > lr.y - ul.y + 1)
507 nblines = lr.y - ul.y + 1;
508
509 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400510}
511
512static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400513handle_1006(struct bregs *regs)
514{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400515 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400516}
517
518static void
519handle_1007(struct bregs *regs)
520{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400521 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400522}
523
524static void
525handle_1008(struct bregs *regs)
526{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400527 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400528 regs->al = ca.car;
529 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400530}
531
532static void
Kevin O'Connord3b38152009-05-26 00:05:37 -0400533write_chars(u8 page, struct carattr ca, u16 count)
534{
535 struct cursorpos cp = get_cursor_pos(page);
536 while (count--) {
537 vgafb_write_char(cp, ca);
538 cp.x++;
539 }
540}
541
542static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400543handle_1009(struct bregs *regs)
544{
Kevin O'Connor09262412009-05-25 11:44:11 -0400545 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400546 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400547}
548
549static void
550handle_100a(struct bregs *regs)
551{
Kevin O'Connor09262412009-05-25 11:44:11 -0400552 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400553 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400554}
555
556
557static void
558handle_100b00(struct bregs *regs)
559{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400560 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400561}
562
563static void
564handle_100b01(struct bregs *regs)
565{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400566 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400567}
568
569static void
570handle_100bXX(struct bregs *regs)
571{
572 debug_stub(regs);
573}
574
575static void
576handle_100b(struct bregs *regs)
577{
578 switch (regs->bh) {
579 case 0x00: handle_100b00(regs); break;
580 case 0x01: handle_100b01(regs); break;
581 default: handle_100bXX(regs); break;
582 }
583}
584
585
586static void
587handle_100c(struct bregs *regs)
588{
589 // XXX - inline
590 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
591}
592
593static void
594handle_100d(struct bregs *regs)
595{
596 // XXX - inline
597 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
598}
599
600static void
601handle_100e(struct bregs *regs)
602{
603 // Ralf Brown Interrupt list is WRONG on bh(page)
604 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400605 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400606 struct cursorpos cp = get_cursor_pos(0xff);
607 cp = write_teletype(cp, ca);
608 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400609}
610
611static void
612handle_100f(struct bregs *regs)
613{
Kevin O'Connore7132042009-05-25 00:10:35 -0400614 regs->bh = GET_BDA(video_page);
615 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
616 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400617}
618
619
620static void
621handle_101000(struct bregs *regs)
622{
623 if (regs->bl > 0x14)
624 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400625 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400626}
627
628static void
629handle_101001(struct bregs *regs)
630{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400631 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400632}
633
634static void
635handle_101002(struct bregs *regs)
636{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400637 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400638}
639
640static void
641handle_101003(struct bregs *regs)
642{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400643 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400644}
645
646static void
647handle_101007(struct bregs *regs)
648{
649 if (regs->bl > 0x14)
650 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400651 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400652}
653
654static void
655handle_101008(struct bregs *regs)
656{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400657 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400658}
659
660static void
661handle_101009(struct bregs *regs)
662{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400663 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400664}
665
666static void
667handle_101010(struct bregs *regs)
668{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400669 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
670 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400671}
672
673static void
674handle_101012(struct bregs *regs)
675{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400676 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400677}
678
679static void
680handle_101013(struct bregs *regs)
681{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400682 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400683}
684
685static void
686handle_101015(struct bregs *regs)
687{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400688 u8 rgb[3];
689 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
690 regs->dh = rgb[0];
691 regs->ch = rgb[1];
692 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400693}
694
695static void
696handle_101017(struct bregs *regs)
697{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400698 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400699}
700
701static void
702handle_101018(struct bregs *regs)
703{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400704 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400705}
706
707static void
708handle_101019(struct bregs *regs)
709{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400710 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400711}
712
713static void
714handle_10101a(struct bregs *regs)
715{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400716 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400717}
718
719static void
720handle_10101b(struct bregs *regs)
721{
722 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
723}
724
725static void
726handle_1010XX(struct bregs *regs)
727{
728 debug_stub(regs);
729}
730
731static void
732handle_1010(struct bregs *regs)
733{
734 switch (regs->al) {
735 case 0x00: handle_101000(regs); break;
736 case 0x01: handle_101001(regs); break;
737 case 0x02: handle_101002(regs); break;
738 case 0x03: handle_101003(regs); break;
739 case 0x07: handle_101007(regs); break;
740 case 0x08: handle_101008(regs); break;
741 case 0x09: handle_101009(regs); break;
742 case 0x10: handle_101010(regs); break;
743 case 0x12: handle_101012(regs); break;
744 case 0x13: handle_101013(regs); break;
745 case 0x15: handle_101015(regs); break;
746 case 0x17: handle_101017(regs); break;
747 case 0x18: handle_101018(regs); break;
748 case 0x19: handle_101019(regs); break;
749 case 0x1a: handle_10101a(regs); break;
750 case 0x1b: handle_10101b(regs); break;
751 default: handle_1010XX(regs); break;
752 }
753}
754
755
756static void
757handle_101100(struct bregs *regs)
758{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400759 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
760 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400761}
762
763static void
764handle_101101(struct bregs *regs)
765{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400766 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400767}
768
769static void
770handle_101102(struct bregs *regs)
771{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400772 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400773}
774
775static void
776handle_101103(struct bregs *regs)
777{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400778 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400779}
780
781static void
782handle_101104(struct bregs *regs)
783{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400784 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400785}
786
787static void
788handle_101110(struct bregs *regs)
789{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400790 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
791 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400792 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400793}
794
795static void
796handle_101111(struct bregs *regs)
797{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400798 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400799 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400800}
801
802static void
803handle_101112(struct bregs *regs)
804{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400805 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400806 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400807}
808
809static void
810handle_101114(struct bregs *regs)
811{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400812 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400813 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400814}
815
816static void
817handle_101130(struct bregs *regs)
818{
Kevin O'Connore7132042009-05-25 00:10:35 -0400819 switch (regs->bh) {
820 case 0x00: {
821 u32 segoff = GET_IVT(0x1f).segoff;
822 regs->es = segoff >> 16;
823 regs->bp = segoff;
824 break;
825 }
826 case 0x01: {
827 u32 segoff = GET_IVT(0x43).segoff;
828 regs->es = segoff >> 16;
829 regs->bp = segoff;
830 break;
831 }
832 case 0x02:
833 regs->es = get_global_seg();
834 regs->bp = (u32)vgafont14;
835 break;
836 case 0x03:
837 regs->es = get_global_seg();
838 regs->bp = (u32)vgafont8;
839 break;
840 case 0x04:
841 regs->es = get_global_seg();
842 regs->bp = (u32)vgafont8 + 128 * 8;
843 break;
844 case 0x05:
845 regs->es = get_global_seg();
846 regs->bp = (u32)vgafont14alt;
847 break;
848 case 0x06:
849 regs->es = get_global_seg();
850 regs->bp = (u32)vgafont16;
851 break;
852 case 0x07:
853 regs->es = get_global_seg();
854 regs->bp = (u32)vgafont16alt;
855 break;
856 default:
857 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
858 return;
859 }
860 // Set byte/char of on screen font
861 regs->cx = GET_BDA(char_height) & 0xff;
862
863 // Set Highest char row
864 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400865}
866
867static void
868handle_1011XX(struct bregs *regs)
869{
870 debug_stub(regs);
871}
872
873static void
874handle_1011(struct bregs *regs)
875{
876 switch (regs->al) {
877 case 0x00: handle_101100(regs); break;
878 case 0x01: handle_101101(regs); break;
879 case 0x02: handle_101102(regs); break;
880 case 0x03: handle_101103(regs); break;
881 case 0x04: handle_101104(regs); break;
882 case 0x10: handle_101110(regs); break;
883 case 0x11: handle_101111(regs); break;
884 case 0x12: handle_101112(regs); break;
885 case 0x14: handle_101114(regs); break;
886 case 0x30: handle_101130(regs); break;
887 default: handle_1011XX(regs); break;
888 }
889}
890
891
892static void
893handle_101210(struct bregs *regs)
894{
Kevin O'Connore7132042009-05-25 00:10:35 -0400895 u16 crtc_addr = GET_BDA(crtc_address);
896 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
897 regs->bx = 0x0103;
898 else
899 regs->bx = 0x0003;
900 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400901}
902
903static void
904handle_101230(struct bregs *regs)
905{
Kevin O'Connore7132042009-05-25 00:10:35 -0400906 u8 mctl = GET_BDA(modeset_ctl);
907 u8 vswt = GET_BDA(video_switches);
908 switch (regs->al) {
909 case 0x00:
910 // 200 lines
911 mctl = (mctl & ~0x10) | 0x80;
912 vswt = (vswt & ~0x0f) | 0x08;
913 break;
914 case 0x01:
915 // 350 lines
916 mctl &= ~0x90;
917 vswt = (vswt & ~0x0f) | 0x09;
918 break;
919 case 0x02:
920 // 400 lines
921 mctl = (mctl & ~0x80) | 0x10;
922 vswt = (vswt & ~0x0f) | 0x09;
923 break;
924 default:
925 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
926 break;
927 }
928 SET_BDA(modeset_ctl, mctl);
929 SET_BDA(video_switches, vswt);
930 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400931}
932
933static void
934handle_101231(struct bregs *regs)
935{
Kevin O'Connore7132042009-05-25 00:10:35 -0400936 u8 v = (regs->al & 0x01) << 3;
937 u8 mctl = GET_BDA(video_ctl) & ~0x08;
938 SET_BDA(video_ctl, mctl | v);
939 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400940}
941
942static void
943handle_101232(struct bregs *regs)
944{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400945 vgahw_enable_video_addressing(regs->al);
946 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400947}
948
949static void
950handle_101233(struct bregs *regs)
951{
Kevin O'Connore7132042009-05-25 00:10:35 -0400952 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
953 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
954 SET_BDA(modeset_ctl, v | v2);
955 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400956}
957
958static void
959handle_101234(struct bregs *regs)
960{
Kevin O'Connore7132042009-05-25 00:10:35 -0400961 u8 v = (regs->al & 0x01) ^ 0x01;
962 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
963 SET_BDA(modeset_ctl, v | v2);
964 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400965}
966
967static void
968handle_101235(struct bregs *regs)
969{
970 debug_stub(regs);
971 regs->al = 0x12;
972}
973
974static void
975handle_101236(struct bregs *regs)
976{
977 debug_stub(regs);
978 regs->al = 0x12;
979}
980
981static void
982handle_1012XX(struct bregs *regs)
983{
984 debug_stub(regs);
985}
986
987static void
988handle_1012(struct bregs *regs)
989{
990 switch (regs->bl) {
991 case 0x10: handle_101210(regs); break;
992 case 0x30: handle_101230(regs); break;
993 case 0x31: handle_101231(regs); break;
994 case 0x32: handle_101232(regs); break;
995 case 0x33: handle_101233(regs); break;
996 case 0x34: handle_101234(regs); break;
997 case 0x35: handle_101235(regs); break;
998 case 0x36: handle_101236(regs); break;
999 default: handle_1012XX(regs); break;
1000 }
1001
1002 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1003}
1004
1005
1006static void
1007handle_1013(struct bregs *regs)
1008{
1009 // XXX - inline
Kevin O'Connor918b1562009-05-25 11:05:18 -04001010 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor116a0442009-05-26 00:47:32 -04001011 write_string(cp, regs->al, regs->bl, regs->cx
1012 , regs->es, (void*)(regs->bp + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001013}
1014
1015
1016static void
1017handle_101a00(struct bregs *regs)
1018{
Kevin O'Connore7132042009-05-25 00:10:35 -04001019 regs->bx = GET_BDA(dcc_index);
1020 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001021}
1022
1023static void
1024handle_101a01(struct bregs *regs)
1025{
Kevin O'Connore7132042009-05-25 00:10:35 -04001026 SET_BDA(dcc_index, regs->bl);
1027 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1028 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001029}
1030
1031static void
1032handle_101aXX(struct bregs *regs)
1033{
1034 debug_stub(regs);
1035}
1036
1037static void
1038handle_101a(struct bregs *regs)
1039{
1040 switch (regs->al) {
1041 case 0x00: handle_101a00(regs); break;
1042 case 0x01: handle_101a01(regs); break;
1043 default: handle_101aXX(regs); break;
1044 }
1045}
1046
1047
Kevin O'Connorca668642009-05-21 23:06:08 -04001048struct funcInfo {
1049 u16 static_functionality_off;
1050 u16 static_functionality_seg;
1051 u8 bda_0x49[30];
1052 u8 bda_0x84[3];
1053 u8 dcc_index;
1054 u8 dcc_alt;
1055 u16 colors;
1056 u8 pages;
1057 u8 scan_lines;
1058 u8 primary_char;
1059 u8 secondar_char;
1060 u8 misc;
1061 u8 non_vga_mode;
1062 u8 reserved_2f[2];
1063 u8 video_mem;
1064 u8 save_flags;
1065 u8 disp_info;
1066 u8 reserved_34[12];
1067};
1068
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001069static void
1070handle_101b(struct bregs *regs)
1071{
Kevin O'Connorca668642009-05-21 23:06:08 -04001072 u16 seg = regs->es;
1073 struct funcInfo *info = (void*)(regs->di+0);
1074 memset_far(seg, info, 0, sizeof(*info));
1075 // Address of static functionality table
1076 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1077 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1078
1079 // Hard coded copy from BIOS area. Should it be cleaner ?
1080 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1081 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1082
1083 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1084 SET_FARVAR(seg, info->colors, 16);
1085 SET_FARVAR(seg, info->pages, 8);
1086 SET_FARVAR(seg, info->scan_lines, 2);
1087 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001088 regs->al = 0x1B;
1089}
1090
1091
1092static void
1093handle_101c00(struct bregs *regs)
1094{
Kevin O'Connorca668642009-05-21 23:06:08 -04001095 u16 flags = regs->cx;
1096 u16 size = 0;
1097 if (flags & 1)
1098 size += sizeof(struct saveVideoHardware);
1099 if (flags & 2)
1100 size += sizeof(struct saveBDAstate);
1101 if (flags & 4)
1102 size += sizeof(struct saveDACcolors);
1103 regs->bx = size;
1104 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001105}
1106
1107static void
1108handle_101c01(struct bregs *regs)
1109{
Kevin O'Connorca668642009-05-21 23:06:08 -04001110 u16 flags = regs->cx;
1111 u16 seg = regs->es;
1112 void *data = (void*)(regs->bx+0);
1113 if (flags & 1) {
1114 vgahw_save_state(seg, data);
1115 data += sizeof(struct saveVideoHardware);
1116 }
1117 if (flags & 2) {
1118 biosfn_save_bda_state(seg, data);
1119 data += sizeof(struct saveBDAstate);
1120 }
1121 if (flags & 4)
1122 vgahw_save_dac_state(seg, data);
1123 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001124}
1125
1126static void
1127handle_101c02(struct bregs *regs)
1128{
Kevin O'Connorca668642009-05-21 23:06:08 -04001129 u16 flags = regs->cx;
1130 u16 seg = regs->es;
1131 void *data = (void*)(regs->bx+0);
1132 if (flags & 1) {
1133 vgahw_restore_state(seg, data);
1134 data += sizeof(struct saveVideoHardware);
1135 }
1136 if (flags & 2) {
1137 biosfn_restore_bda_state(seg, data);
1138 data += sizeof(struct saveBDAstate);
1139 }
1140 if (flags & 4)
1141 vgahw_restore_dac_state(seg, data);
1142 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001143}
1144
1145static void
1146handle_101cXX(struct bregs *regs)
1147{
1148 debug_stub(regs);
1149}
1150
1151static void
1152handle_101c(struct bregs *regs)
1153{
1154 switch (regs->al) {
1155 case 0x00: handle_101c00(regs); break;
1156 case 0x01: handle_101c01(regs); break;
1157 case 0x02: handle_101c02(regs); break;
1158 default: handle_101cXX(regs); break;
1159 }
1160}
1161
1162
1163static void
1164handle_104f00(struct bregs *regs)
1165{
1166 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1167 // XXX - OR cirrus_vesa_00h
1168}
1169
1170static void
1171handle_104f01(struct bregs *regs)
1172{
1173 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1174 // XXX - OR cirrus_vesa_01h
1175}
1176
1177static void
1178handle_104f02(struct bregs *regs)
1179{
1180 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1181 // XXX - OR cirrus_vesa_02h
1182}
1183
1184static void
1185handle_104f03(struct bregs *regs)
1186{
1187 // XXX - vbe_biosfn_return_current_mode
1188 // XXX - OR cirrus_vesa_03h
1189}
1190
1191static void
1192handle_104f04(struct bregs *regs)
1193{
1194 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1195}
1196
1197static void
1198handle_104f05(struct bregs *regs)
1199{
1200 // XXX - vbe_biosfn_display_window_control
1201 // XXX - OR cirrus_vesa_05h
1202}
1203
1204static void
1205handle_104f06(struct bregs *regs)
1206{
1207 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1208 // XXX - OR cirrus_vesa_06h
1209}
1210
1211static void
1212handle_104f07(struct bregs *regs)
1213{
1214 // XXX - vbe_biosfn_set_get_display_start
1215 // XXX - OR cirrus_vesa_07h
1216}
1217
1218static void
1219handle_104f08(struct bregs *regs)
1220{
1221 // XXX - vbe_biosfn_set_get_dac_palette_format
1222}
1223
1224static void
1225handle_104f0a(struct bregs *regs)
1226{
1227 // XXX - vbe_biosfn_return_protected_mode_interface
1228}
1229
1230static void
1231handle_104fXX(struct bregs *regs)
1232{
1233 debug_stub(regs);
1234 regs->ax = 0x0100;
1235}
1236
1237static void
1238handle_104f(struct bregs *regs)
1239{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001240 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001241 handle_104fXX(regs);
1242 return;
1243 }
1244
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001245 switch (regs->al) {
1246 case 0x00: handle_104f00(regs); break;
1247 case 0x01: handle_104f01(regs); break;
1248 case 0x02: handle_104f02(regs); break;
1249 case 0x03: handle_104f03(regs); break;
1250 case 0x04: handle_104f04(regs); break;
1251 case 0x05: handle_104f05(regs); break;
1252 case 0x06: handle_104f06(regs); break;
1253 case 0x07: handle_104f07(regs); break;
1254 case 0x08: handle_104f08(regs); break;
1255 case 0x0a: handle_104f0a(regs); break;
1256 default: handle_104fXX(regs); break;
1257 }
1258}
1259
1260
1261static void
1262handle_10XX(struct bregs *regs)
1263{
1264 debug_stub(regs);
1265}
1266
1267// INT 10h Video Support Service Entry Point
1268void VISIBLE16
1269handle_10(struct bregs *regs)
1270{
1271 debug_enter(regs, DEBUG_VGA_10);
1272 switch (regs->ah) {
1273 case 0x00: handle_1000(regs); break;
1274 case 0x01: handle_1001(regs); break;
1275 case 0x02: handle_1002(regs); break;
1276 case 0x03: handle_1003(regs); break;
1277 case 0x04: handle_1004(regs); break;
1278 case 0x05: handle_1005(regs); break;
1279 case 0x06: handle_1006(regs); break;
1280 case 0x07: handle_1007(regs); break;
1281 case 0x08: handle_1008(regs); break;
1282 case 0x09: handle_1009(regs); break;
1283 case 0x0a: handle_100a(regs); break;
1284 case 0x0b: handle_100b(regs); break;
1285 case 0x0c: handle_100c(regs); break;
1286 case 0x0d: handle_100d(regs); break;
1287 case 0x0e: handle_100e(regs); break;
1288 case 0x0f: handle_100f(regs); break;
1289 case 0x10: handle_1010(regs); break;
1290 case 0x11: handle_1011(regs); break;
1291 case 0x12: handle_1012(regs); break;
1292 case 0x13: handle_1013(regs); break;
1293 case 0x1a: handle_101a(regs); break;
1294 case 0x1b: handle_101b(regs); break;
1295 case 0x1c: handle_101c(regs); break;
1296 case 0x4f: handle_104f(regs); break;
1297 default: handle_10XX(regs); break;
1298 }
1299}
1300
1301
1302/****************************************************************
1303 * VGA post
1304 ****************************************************************/
1305
1306static void
1307init_bios_area()
1308{
1309 // init detected hardware BIOS Area
1310 // set 80x25 color (not clear from RBIL but usual)
1311 u16 eqf = GET_BDA(equipment_list_flags);
1312 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1313
1314 // Just for the first int10 find its children
1315
1316 // the default char height
1317 SET_BDA(char_height, 0x10);
1318
1319 // Clear the screen
1320 SET_BDA(video_ctl, 0x60);
1321
1322 // Set the basic screen we have
1323 SET_BDA(video_switches, 0xf9);
1324
1325 // Set the basic modeset options
1326 SET_BDA(modeset_ctl, 0x51);
1327
1328 // Set the default MSR
1329 SET_BDA(video_msr, 0x09);
1330}
1331
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001332void VISIBLE16
1333vga_post(struct bregs *regs)
1334{
1335 debug_enter(regs, DEBUG_VGA_POST);
1336
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001337 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001338
1339 init_bios_area();
1340
Kevin O'Connor21079f42009-05-16 21:30:10 -04001341 if (CONFIG_VBE)
1342 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001343
1344 extern void entry_10(void);
Kevin O'Connord113a992009-05-16 21:05:02 -04001345 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001346
1347 if (CONFIG_CIRRUS)
1348 cirrus_init();
1349
1350 // XXX - clear screen and display info
1351
1352 // XXX: fill it
1353 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001354 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001355
1356 // Fixup checksum
1357 extern u8 _rom_header_size, _rom_header_checksum;
1358 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001359 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001360 SET_VGA(_rom_header_checksum, sum);
1361}