blob: a01b0fc3545098f9d7ed6a8d93e8029e9ef4c9a6 [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
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400179write_teletype(struct cursorpos cp, struct carattr ca)
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'Connor2e86c6a2009-05-31 20:43:06 -0400185 switch (ca.car) {
186 case 7:
187 //FIXME should beep
188 break;
189 case 8:
190 if (cp.x > 0)
191 cp.x--;
192 break;
193 case '\r':
194 cp.x = 0;
195 break;
196 case '\n':
197 cp.y++;
198 break;
199 case '\t':
200 do {
201 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
202 vgafb_write_char(cp, dummyca);
203 cp.x++;
204 } while (cp.x < nbcols && cp.x % 8);
205 break;
206 default:
207 vgafb_write_char(cp, ca);
208 cp.x++;
209 }
210
Kevin O'Connor82221b22009-05-26 00:20:40 -0400211 // Do we need to wrap ?
212 if (cp.x == nbcols) {
213 cp.x = 0;
214 cp.y++;
215 }
216 // Do we need to scroll ?
217 if (cp.y == nbrows) {
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400218 struct cursorpos ul = {0, 0, cp.page};
219 struct cursorpos lr = {nbcols-1, nbrows-1, cp.page};
220 vgafb_scroll(1, -1, ul, lr);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400221 cp.y--;
222 }
223
224 return cp;
225}
226
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400227static void
Kevin O'Connor116a0442009-05-26 00:47:32 -0400228write_string(struct cursorpos cp, u8 flag, u8 attr, u16 count,
229 u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400230{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400231 while (count--) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400232 u8 car = GET_FARVAR(seg, *offset_far);
233 offset_far++;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400234 if (flag & 0x02) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400235 attr = GET_FARVAR(seg, *offset_far);
236 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400237 }
238
Kevin O'Connor09262412009-05-25 11:44:11 -0400239 struct carattr ca = {car, attr, 1};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400240 cp = write_teletype(cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400241 }
242
Kevin O'Connor116a0442009-05-26 00:47:32 -0400243 if (flag & 0x01)
244 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400245}
246
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400247static void
Kevin O'Connore7132042009-05-25 00:10:35 -0400248set_scan_lines(u8 lines)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400249{
Kevin O'Connore7132042009-05-25 00:10:35 -0400250 vgahw_set_scan_lines(lines);
251 if (lines == 8)
252 biosfn_set_cursor_shape(0x06, 0x07);
253 else
254 biosfn_set_cursor_shape(lines - 4, lines - 3);
255 SET_BDA(char_height, lines);
256 u16 vde = vgahw_get_vde();
257 u8 rows = vde / lines;
258 SET_BDA(video_rows, rows - 1);
259 u16 cols = GET_BDA(video_cols);
260 SET_BDA(video_pagesize, rows * cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400261}
262
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400263static void
Kevin O'Connorca668642009-05-21 23:06:08 -0400264biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400265{
Kevin O'Connorca668642009-05-21 23:06:08 -0400266 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
267 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
268 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
269 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
270 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
271 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
272 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
273 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
274 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
275 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
276 u16 i;
277 for (i=0; i<8; i++)
278 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
279 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
280 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
281 /* current font */
282 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
283 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400284}
285
Kevin O'Connorca668642009-05-21 23:06:08 -0400286static void
287biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400288{
Kevin O'Connorca668642009-05-21 23:06:08 -0400289 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
290 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
291 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
292 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
293 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
294 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
295 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
296 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
297 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
298 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
299 u16 i;
300 for (i = 0; i < 8; i++)
301 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
302 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
303 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
304 /* current font */
305 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
306 , GET_FARVAR(seg, info->font0_off));
307 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
308 , GET_FARVAR(seg, info->font1_off));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400309}
310
311
312/****************************************************************
313 * VGA int 10 handler
314 ****************************************************************/
315
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400316// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400317static void
318handle_1000(struct bregs *regs)
319{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400320 u8 noclearmem = regs->al & 0x80;
321 u8 mode = regs->al & 0x7f;
322
Kevin O'Connor918b1562009-05-25 11:05:18 -0400323 // Set regs->al
324 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400325 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400326 else if (mode == 6)
327 regs->al = 0x3f;
328 else
329 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400330
331 if (CONFIG_CIRRUS)
332 cirrus_set_video_mode(mode);
333
334 if (CONFIG_VBE)
335 if (vbe_has_vbe_display())
336 dispi_set_enable(VBE_DISPI_DISABLED);
337
338 // find the entry in the video modes
339 struct vgamode_s *vmode_g = find_vga_entry(mode);
340 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
341 if (!vmode_g)
342 return;
343
344 // Read the bios mode set control
345 u8 modeset_ctl = GET_BDA(modeset_ctl);
346
347 // Then we know the number of lines
348// FIXME
349
350 // if palette loading (bit 3 of modeset ctl = 0)
351 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
352 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
353
354 // From which palette
355 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
356 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
357
358 // Always 256*3 values
359 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
360 u16 i;
361 for (i = palsize; i < 0x0100; i++) {
362 static u8 rgb[3] VAR16;
363 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
364 }
365
366 if ((modeset_ctl & 0x02) == 0x02)
367 biosfn_perform_gray_scale_summing(0x00, 0x100);
368 }
369
370 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
371 vgahw_set_mode(vparam_g);
372
373 if (noclearmem == 0x00)
374 clear_screen(vmode_g);
375
376 // Set CRTC address VGA or MDA
377 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
378 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
379 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
380
381 // Set the BIOS mem
382 u16 cheight = GET_GLOBAL(vparam_g->cheight);
383 SET_BDA(video_mode, mode);
384 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
385 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
386 SET_BDA(crtc_address, crtc_addr);
387 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
388 SET_BDA(char_height, cheight);
389 SET_BDA(video_ctl, (0x60 | noclearmem));
390 SET_BDA(video_switches, 0xF9);
391 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
392
393 // FIXME We nearly have the good tables. to be reworked
394 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
395 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
396 SET_BDA(video_savetable_seg, get_global_seg());
397
398 // FIXME
399 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
400 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
401
402 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400403 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400404 biosfn_set_cursor_shape(0x06, 0x07);
405 // Set cursor pos for page 0..7
406 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400407 for (i = 0; i < 8; i++) {
408 struct cursorpos cp = {0, 0, i};
409 set_cursor_pos(cp);
410 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400411
412 // Set active page 0
413 biosfn_set_active_page(0x00);
414
415 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400416 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400417 call16_vgaint(0x1104, 0);
418 call16_vgaint(0x1103, 0);
419 }
420 // Set the ints 0x1F and 0x43
421 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
422
423 switch (cheight) {
424 case 8:
425 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
426 break;
427 case 14:
428 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
429 break;
430 case 16:
431 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
432 break;
433 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400434}
435
436static void
437handle_1001(struct bregs *regs)
438{
439 biosfn_set_cursor_shape(regs->ch, regs->cl);
440}
441
442static void
443handle_1002(struct bregs *regs)
444{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400445 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
446 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400447}
448
449static void
450handle_1003(struct bregs *regs)
451{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400452 regs->cx = biosfn_get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400453 struct cursorpos cp = get_cursor_pos(regs->bh);
454 regs->dl = cp.x;
455 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400456}
457
458// Read light pen pos (unimplemented)
459static void
460handle_1004(struct bregs *regs)
461{
462 debug_stub(regs);
463 regs->ax = regs->bx = regs->cx = regs->dx = 0;
464}
465
466static void
467handle_1005(struct bregs *regs)
468{
469 biosfn_set_active_page(regs->al);
470}
471
472static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400473verify_scroll(struct bregs *regs, int dir)
474{
475 u8 page = GET_BDA(video_page);
476 struct cursorpos ul = {regs->cl, regs->ch, page};
477 struct cursorpos lr = {regs->dl, regs->dh, page};
478
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400479 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400480 if (lr.y >= nbrows)
481 lr.y = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400482 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400483 if (lr.x >= nbcols)
484 lr.x = nbcols - 1;
485
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400486 if (ul.x > lr.x || ul.y > lr.y)
487 return;
488
489 u16 nblines = regs->al;
490 if (!nblines || nblines > lr.y - ul.y + 1)
491 nblines = lr.y - ul.y + 1;
492
493 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400494}
495
496static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400497handle_1006(struct bregs *regs)
498{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400499 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400500}
501
502static void
503handle_1007(struct bregs *regs)
504{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400505 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400506}
507
508static void
509handle_1008(struct bregs *regs)
510{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400511 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400512 regs->al = ca.car;
513 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400514}
515
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400516static void noinline
Kevin O'Connord3b38152009-05-26 00:05:37 -0400517write_chars(u8 page, struct carattr ca, u16 count)
518{
519 struct cursorpos cp = get_cursor_pos(page);
520 while (count--) {
521 vgafb_write_char(cp, ca);
522 cp.x++;
523 }
524}
525
526static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400527handle_1009(struct bregs *regs)
528{
Kevin O'Connor09262412009-05-25 11:44:11 -0400529 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400530 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400531}
532
533static void
534handle_100a(struct bregs *regs)
535{
Kevin O'Connor09262412009-05-25 11:44:11 -0400536 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400537 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400538}
539
540
541static void
542handle_100b00(struct bregs *regs)
543{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400544 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400545}
546
547static void
548handle_100b01(struct bregs *regs)
549{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400550 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400551}
552
553static void
554handle_100bXX(struct bregs *regs)
555{
556 debug_stub(regs);
557}
558
559static void
560handle_100b(struct bregs *regs)
561{
562 switch (regs->bh) {
563 case 0x00: handle_100b00(regs); break;
564 case 0x01: handle_100b01(regs); break;
565 default: handle_100bXX(regs); break;
566 }
567}
568
569
570static void
571handle_100c(struct bregs *regs)
572{
573 // XXX - inline
574 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
575}
576
577static void
578handle_100d(struct bregs *regs)
579{
580 // XXX - inline
581 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
582}
583
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400584static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400585handle_100e(struct bregs *regs)
586{
587 // Ralf Brown Interrupt list is WRONG on bh(page)
588 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400589 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400590 struct cursorpos cp = get_cursor_pos(0xff);
591 cp = write_teletype(cp, ca);
592 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400593}
594
595static void
596handle_100f(struct bregs *regs)
597{
Kevin O'Connore7132042009-05-25 00:10:35 -0400598 regs->bh = GET_BDA(video_page);
599 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
600 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400601}
602
603
604static void
605handle_101000(struct bregs *regs)
606{
607 if (regs->bl > 0x14)
608 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400609 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400610}
611
612static void
613handle_101001(struct bregs *regs)
614{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400615 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400616}
617
618static void
619handle_101002(struct bregs *regs)
620{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400621 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400622}
623
624static void
625handle_101003(struct bregs *regs)
626{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400627 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400628}
629
630static void
631handle_101007(struct bregs *regs)
632{
633 if (regs->bl > 0x14)
634 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400635 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400636}
637
638static void
639handle_101008(struct bregs *regs)
640{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400641 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400642}
643
644static void
645handle_101009(struct bregs *regs)
646{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400647 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400648}
649
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400650static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400651handle_101010(struct bregs *regs)
652{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400653 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
654 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400655}
656
657static void
658handle_101012(struct bregs *regs)
659{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400660 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400661}
662
663static void
664handle_101013(struct bregs *regs)
665{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400666 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400667}
668
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400669static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400670handle_101015(struct bregs *regs)
671{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400672 u8 rgb[3];
673 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
674 regs->dh = rgb[0];
675 regs->ch = rgb[1];
676 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400677}
678
679static void
680handle_101017(struct bregs *regs)
681{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400682 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400683}
684
685static void
686handle_101018(struct bregs *regs)
687{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400688 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400689}
690
691static void
692handle_101019(struct bregs *regs)
693{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400694 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400695}
696
697static void
698handle_10101a(struct bregs *regs)
699{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400700 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400701}
702
703static void
704handle_10101b(struct bregs *regs)
705{
706 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
707}
708
709static void
710handle_1010XX(struct bregs *regs)
711{
712 debug_stub(regs);
713}
714
715static void
716handle_1010(struct bregs *regs)
717{
718 switch (regs->al) {
719 case 0x00: handle_101000(regs); break;
720 case 0x01: handle_101001(regs); break;
721 case 0x02: handle_101002(regs); break;
722 case 0x03: handle_101003(regs); break;
723 case 0x07: handle_101007(regs); break;
724 case 0x08: handle_101008(regs); break;
725 case 0x09: handle_101009(regs); break;
726 case 0x10: handle_101010(regs); break;
727 case 0x12: handle_101012(regs); break;
728 case 0x13: handle_101013(regs); break;
729 case 0x15: handle_101015(regs); break;
730 case 0x17: handle_101017(regs); break;
731 case 0x18: handle_101018(regs); break;
732 case 0x19: handle_101019(regs); break;
733 case 0x1a: handle_10101a(regs); break;
734 case 0x1b: handle_10101b(regs); break;
735 default: handle_1010XX(regs); break;
736 }
737}
738
739
740static void
741handle_101100(struct bregs *regs)
742{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400743 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
744 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400745}
746
747static void
748handle_101101(struct bregs *regs)
749{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400750 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400751}
752
753static void
754handle_101102(struct bregs *regs)
755{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400756 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400757}
758
759static void
760handle_101103(struct bregs *regs)
761{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400762 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400763}
764
765static void
766handle_101104(struct bregs *regs)
767{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400768 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400769}
770
771static void
772handle_101110(struct bregs *regs)
773{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400774 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
775 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400776 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400777}
778
779static void
780handle_101111(struct bregs *regs)
781{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400782 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400783 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400784}
785
786static void
787handle_101112(struct bregs *regs)
788{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400789 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400790 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400791}
792
793static void
794handle_101114(struct bregs *regs)
795{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400796 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400797 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400798}
799
800static void
801handle_101130(struct bregs *regs)
802{
Kevin O'Connore7132042009-05-25 00:10:35 -0400803 switch (regs->bh) {
804 case 0x00: {
805 u32 segoff = GET_IVT(0x1f).segoff;
806 regs->es = segoff >> 16;
807 regs->bp = segoff;
808 break;
809 }
810 case 0x01: {
811 u32 segoff = GET_IVT(0x43).segoff;
812 regs->es = segoff >> 16;
813 regs->bp = segoff;
814 break;
815 }
816 case 0x02:
817 regs->es = get_global_seg();
818 regs->bp = (u32)vgafont14;
819 break;
820 case 0x03:
821 regs->es = get_global_seg();
822 regs->bp = (u32)vgafont8;
823 break;
824 case 0x04:
825 regs->es = get_global_seg();
826 regs->bp = (u32)vgafont8 + 128 * 8;
827 break;
828 case 0x05:
829 regs->es = get_global_seg();
830 regs->bp = (u32)vgafont14alt;
831 break;
832 case 0x06:
833 regs->es = get_global_seg();
834 regs->bp = (u32)vgafont16;
835 break;
836 case 0x07:
837 regs->es = get_global_seg();
838 regs->bp = (u32)vgafont16alt;
839 break;
840 default:
841 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
842 return;
843 }
844 // Set byte/char of on screen font
845 regs->cx = GET_BDA(char_height) & 0xff;
846
847 // Set Highest char row
848 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400849}
850
851static void
852handle_1011XX(struct bregs *regs)
853{
854 debug_stub(regs);
855}
856
857static void
858handle_1011(struct bregs *regs)
859{
860 switch (regs->al) {
861 case 0x00: handle_101100(regs); break;
862 case 0x01: handle_101101(regs); break;
863 case 0x02: handle_101102(regs); break;
864 case 0x03: handle_101103(regs); break;
865 case 0x04: handle_101104(regs); break;
866 case 0x10: handle_101110(regs); break;
867 case 0x11: handle_101111(regs); break;
868 case 0x12: handle_101112(regs); break;
869 case 0x14: handle_101114(regs); break;
870 case 0x30: handle_101130(regs); break;
871 default: handle_1011XX(regs); break;
872 }
873}
874
875
876static void
877handle_101210(struct bregs *regs)
878{
Kevin O'Connore7132042009-05-25 00:10:35 -0400879 u16 crtc_addr = GET_BDA(crtc_address);
880 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
881 regs->bx = 0x0103;
882 else
883 regs->bx = 0x0003;
884 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400885}
886
887static void
888handle_101230(struct bregs *regs)
889{
Kevin O'Connore7132042009-05-25 00:10:35 -0400890 u8 mctl = GET_BDA(modeset_ctl);
891 u8 vswt = GET_BDA(video_switches);
892 switch (regs->al) {
893 case 0x00:
894 // 200 lines
895 mctl = (mctl & ~0x10) | 0x80;
896 vswt = (vswt & ~0x0f) | 0x08;
897 break;
898 case 0x01:
899 // 350 lines
900 mctl &= ~0x90;
901 vswt = (vswt & ~0x0f) | 0x09;
902 break;
903 case 0x02:
904 // 400 lines
905 mctl = (mctl & ~0x80) | 0x10;
906 vswt = (vswt & ~0x0f) | 0x09;
907 break;
908 default:
909 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
910 break;
911 }
912 SET_BDA(modeset_ctl, mctl);
913 SET_BDA(video_switches, vswt);
914 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400915}
916
917static void
918handle_101231(struct bregs *regs)
919{
Kevin O'Connore7132042009-05-25 00:10:35 -0400920 u8 v = (regs->al & 0x01) << 3;
921 u8 mctl = GET_BDA(video_ctl) & ~0x08;
922 SET_BDA(video_ctl, mctl | v);
923 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400924}
925
926static void
927handle_101232(struct bregs *regs)
928{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400929 vgahw_enable_video_addressing(regs->al);
930 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400931}
932
933static void
934handle_101233(struct bregs *regs)
935{
Kevin O'Connore7132042009-05-25 00:10:35 -0400936 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
937 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
938 SET_BDA(modeset_ctl, v | v2);
939 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400940}
941
942static void
943handle_101234(struct bregs *regs)
944{
Kevin O'Connore7132042009-05-25 00:10:35 -0400945 u8 v = (regs->al & 0x01) ^ 0x01;
946 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
947 SET_BDA(modeset_ctl, v | v2);
948 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400949}
950
951static void
952handle_101235(struct bregs *regs)
953{
954 debug_stub(regs);
955 regs->al = 0x12;
956}
957
958static void
959handle_101236(struct bregs *regs)
960{
961 debug_stub(regs);
962 regs->al = 0x12;
963}
964
965static void
966handle_1012XX(struct bregs *regs)
967{
968 debug_stub(regs);
969}
970
971static void
972handle_1012(struct bregs *regs)
973{
974 switch (regs->bl) {
975 case 0x10: handle_101210(regs); break;
976 case 0x30: handle_101230(regs); break;
977 case 0x31: handle_101231(regs); break;
978 case 0x32: handle_101232(regs); break;
979 case 0x33: handle_101233(regs); break;
980 case 0x34: handle_101234(regs); break;
981 case 0x35: handle_101235(regs); break;
982 case 0x36: handle_101236(regs); break;
983 default: handle_1012XX(regs); break;
984 }
985
986 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
987}
988
989
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400990static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400991handle_1013(struct bregs *regs)
992{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400993 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400994 // if row=0xff special case : use current cursor position
995 if (cp.y == 0xff)
996 cp = get_cursor_pos(cp.page);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400997 write_string(cp, regs->al, regs->bl, regs->cx
998 , regs->es, (void*)(regs->bp + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400999}
1000
1001
1002static void
1003handle_101a00(struct bregs *regs)
1004{
Kevin O'Connore7132042009-05-25 00:10:35 -04001005 regs->bx = GET_BDA(dcc_index);
1006 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001007}
1008
1009static void
1010handle_101a01(struct bregs *regs)
1011{
Kevin O'Connore7132042009-05-25 00:10:35 -04001012 SET_BDA(dcc_index, regs->bl);
1013 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1014 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001015}
1016
1017static void
1018handle_101aXX(struct bregs *regs)
1019{
1020 debug_stub(regs);
1021}
1022
1023static void
1024handle_101a(struct bregs *regs)
1025{
1026 switch (regs->al) {
1027 case 0x00: handle_101a00(regs); break;
1028 case 0x01: handle_101a01(regs); break;
1029 default: handle_101aXX(regs); break;
1030 }
1031}
1032
1033
Kevin O'Connorca668642009-05-21 23:06:08 -04001034struct funcInfo {
1035 u16 static_functionality_off;
1036 u16 static_functionality_seg;
1037 u8 bda_0x49[30];
1038 u8 bda_0x84[3];
1039 u8 dcc_index;
1040 u8 dcc_alt;
1041 u16 colors;
1042 u8 pages;
1043 u8 scan_lines;
1044 u8 primary_char;
1045 u8 secondar_char;
1046 u8 misc;
1047 u8 non_vga_mode;
1048 u8 reserved_2f[2];
1049 u8 video_mem;
1050 u8 save_flags;
1051 u8 disp_info;
1052 u8 reserved_34[12];
1053};
1054
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001055static void
1056handle_101b(struct bregs *regs)
1057{
Kevin O'Connorca668642009-05-21 23:06:08 -04001058 u16 seg = regs->es;
1059 struct funcInfo *info = (void*)(regs->di+0);
1060 memset_far(seg, info, 0, sizeof(*info));
1061 // Address of static functionality table
1062 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1063 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1064
1065 // Hard coded copy from BIOS area. Should it be cleaner ?
1066 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1067 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1068
1069 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1070 SET_FARVAR(seg, info->colors, 16);
1071 SET_FARVAR(seg, info->pages, 8);
1072 SET_FARVAR(seg, info->scan_lines, 2);
1073 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001074 regs->al = 0x1B;
1075}
1076
1077
1078static void
1079handle_101c00(struct bregs *regs)
1080{
Kevin O'Connorca668642009-05-21 23:06:08 -04001081 u16 flags = regs->cx;
1082 u16 size = 0;
1083 if (flags & 1)
1084 size += sizeof(struct saveVideoHardware);
1085 if (flags & 2)
1086 size += sizeof(struct saveBDAstate);
1087 if (flags & 4)
1088 size += sizeof(struct saveDACcolors);
1089 regs->bx = size;
1090 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001091}
1092
1093static void
1094handle_101c01(struct bregs *regs)
1095{
Kevin O'Connorca668642009-05-21 23:06:08 -04001096 u16 flags = regs->cx;
1097 u16 seg = regs->es;
1098 void *data = (void*)(regs->bx+0);
1099 if (flags & 1) {
1100 vgahw_save_state(seg, data);
1101 data += sizeof(struct saveVideoHardware);
1102 }
1103 if (flags & 2) {
1104 biosfn_save_bda_state(seg, data);
1105 data += sizeof(struct saveBDAstate);
1106 }
1107 if (flags & 4)
1108 vgahw_save_dac_state(seg, data);
1109 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001110}
1111
1112static void
1113handle_101c02(struct bregs *regs)
1114{
Kevin O'Connorca668642009-05-21 23:06:08 -04001115 u16 flags = regs->cx;
1116 u16 seg = regs->es;
1117 void *data = (void*)(regs->bx+0);
1118 if (flags & 1) {
1119 vgahw_restore_state(seg, data);
1120 data += sizeof(struct saveVideoHardware);
1121 }
1122 if (flags & 2) {
1123 biosfn_restore_bda_state(seg, data);
1124 data += sizeof(struct saveBDAstate);
1125 }
1126 if (flags & 4)
1127 vgahw_restore_dac_state(seg, data);
1128 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001129}
1130
1131static void
1132handle_101cXX(struct bregs *regs)
1133{
1134 debug_stub(regs);
1135}
1136
1137static void
1138handle_101c(struct bregs *regs)
1139{
1140 switch (regs->al) {
1141 case 0x00: handle_101c00(regs); break;
1142 case 0x01: handle_101c01(regs); break;
1143 case 0x02: handle_101c02(regs); break;
1144 default: handle_101cXX(regs); break;
1145 }
1146}
1147
1148
1149static void
1150handle_104f00(struct bregs *regs)
1151{
1152 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1153 // XXX - OR cirrus_vesa_00h
1154}
1155
1156static void
1157handle_104f01(struct bregs *regs)
1158{
1159 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1160 // XXX - OR cirrus_vesa_01h
1161}
1162
1163static void
1164handle_104f02(struct bregs *regs)
1165{
1166 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1167 // XXX - OR cirrus_vesa_02h
1168}
1169
1170static void
1171handle_104f03(struct bregs *regs)
1172{
1173 // XXX - vbe_biosfn_return_current_mode
1174 // XXX - OR cirrus_vesa_03h
1175}
1176
1177static void
1178handle_104f04(struct bregs *regs)
1179{
1180 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1181}
1182
1183static void
1184handle_104f05(struct bregs *regs)
1185{
1186 // XXX - vbe_biosfn_display_window_control
1187 // XXX - OR cirrus_vesa_05h
1188}
1189
1190static void
1191handle_104f06(struct bregs *regs)
1192{
1193 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1194 // XXX - OR cirrus_vesa_06h
1195}
1196
1197static void
1198handle_104f07(struct bregs *regs)
1199{
1200 // XXX - vbe_biosfn_set_get_display_start
1201 // XXX - OR cirrus_vesa_07h
1202}
1203
1204static void
1205handle_104f08(struct bregs *regs)
1206{
1207 // XXX - vbe_biosfn_set_get_dac_palette_format
1208}
1209
1210static void
1211handle_104f0a(struct bregs *regs)
1212{
1213 // XXX - vbe_biosfn_return_protected_mode_interface
1214}
1215
1216static void
1217handle_104fXX(struct bregs *regs)
1218{
1219 debug_stub(regs);
1220 regs->ax = 0x0100;
1221}
1222
1223static void
1224handle_104f(struct bregs *regs)
1225{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001226 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001227 handle_104fXX(regs);
1228 return;
1229 }
1230
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001231 switch (regs->al) {
1232 case 0x00: handle_104f00(regs); break;
1233 case 0x01: handle_104f01(regs); break;
1234 case 0x02: handle_104f02(regs); break;
1235 case 0x03: handle_104f03(regs); break;
1236 case 0x04: handle_104f04(regs); break;
1237 case 0x05: handle_104f05(regs); break;
1238 case 0x06: handle_104f06(regs); break;
1239 case 0x07: handle_104f07(regs); break;
1240 case 0x08: handle_104f08(regs); break;
1241 case 0x0a: handle_104f0a(regs); break;
1242 default: handle_104fXX(regs); break;
1243 }
1244}
1245
1246
1247static void
1248handle_10XX(struct bregs *regs)
1249{
1250 debug_stub(regs);
1251}
1252
1253// INT 10h Video Support Service Entry Point
1254void VISIBLE16
1255handle_10(struct bregs *regs)
1256{
1257 debug_enter(regs, DEBUG_VGA_10);
1258 switch (regs->ah) {
1259 case 0x00: handle_1000(regs); break;
1260 case 0x01: handle_1001(regs); break;
1261 case 0x02: handle_1002(regs); break;
1262 case 0x03: handle_1003(regs); break;
1263 case 0x04: handle_1004(regs); break;
1264 case 0x05: handle_1005(regs); break;
1265 case 0x06: handle_1006(regs); break;
1266 case 0x07: handle_1007(regs); break;
1267 case 0x08: handle_1008(regs); break;
1268 case 0x09: handle_1009(regs); break;
1269 case 0x0a: handle_100a(regs); break;
1270 case 0x0b: handle_100b(regs); break;
1271 case 0x0c: handle_100c(regs); break;
1272 case 0x0d: handle_100d(regs); break;
1273 case 0x0e: handle_100e(regs); break;
1274 case 0x0f: handle_100f(regs); break;
1275 case 0x10: handle_1010(regs); break;
1276 case 0x11: handle_1011(regs); break;
1277 case 0x12: handle_1012(regs); break;
1278 case 0x13: handle_1013(regs); break;
1279 case 0x1a: handle_101a(regs); break;
1280 case 0x1b: handle_101b(regs); break;
1281 case 0x1c: handle_101c(regs); break;
1282 case 0x4f: handle_104f(regs); break;
1283 default: handle_10XX(regs); break;
1284 }
1285}
1286
1287
1288/****************************************************************
1289 * VGA post
1290 ****************************************************************/
1291
1292static void
1293init_bios_area()
1294{
1295 // init detected hardware BIOS Area
1296 // set 80x25 color (not clear from RBIL but usual)
1297 u16 eqf = GET_BDA(equipment_list_flags);
1298 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1299
1300 // Just for the first int10 find its children
1301
1302 // the default char height
1303 SET_BDA(char_height, 0x10);
1304
1305 // Clear the screen
1306 SET_BDA(video_ctl, 0x60);
1307
1308 // Set the basic screen we have
1309 SET_BDA(video_switches, 0xf9);
1310
1311 // Set the basic modeset options
1312 SET_BDA(modeset_ctl, 0x51);
1313
1314 // Set the default MSR
1315 SET_BDA(video_msr, 0x09);
1316}
1317
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001318void VISIBLE16
1319vga_post(struct bregs *regs)
1320{
1321 debug_enter(regs, DEBUG_VGA_POST);
1322
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001323 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001324
1325 init_bios_area();
1326
Kevin O'Connor21079f42009-05-16 21:30:10 -04001327 if (CONFIG_VBE)
1328 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001329
1330 extern void entry_10(void);
Kevin O'Connord113a992009-05-16 21:05:02 -04001331 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001332
1333 if (CONFIG_CIRRUS)
1334 cirrus_init();
1335
1336 // XXX - clear screen and display info
1337
1338 // XXX: fill it
1339 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001340 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001341
1342 // Fixup checksum
1343 extern u8 _rom_header_size, _rom_header_checksum;
1344 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001345 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001346 SET_VGA(_rom_header_checksum, sum);
1347}