blob: d0efc1168ec0d7ae250f0b80f2532dff1889b87d [file] [log] [blame]
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001// VGA bios implementation
2//
Kevin O'Connordab0a742013-12-03 11:50:49 -05003// Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04004// 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
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04008#include "biosvar.h" // GET_BDA
Kevin O'Connor2d2fa312013-09-14 21:55:26 -04009#include "bregs.h" // struct bregs
Kevin O'Connore91ec7c2012-01-14 16:30:49 -050010#include "clext.h" // clext_1012
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040011#include "config.h" // CONFIG_*
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040012#include "output.h" // dprintf
Kevin O'Connor2e57c812013-09-14 22:29:32 -040013#include "std/vbe.h" // VBE_RETURN_STATUS_FAILED
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040014#include "stdvga.h" // stdvga_set_cursor_shape
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040015#include "string.h" // memset_far
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040016#include "vgabios.h" // calc_page_size
17#include "vgahw.h" // vgahw_set_mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040018
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040019
20/****************************************************************
21 * Helper functions
22 ****************************************************************/
23
Kevin O'Connor3876b532012-01-24 00:07:44 -050024// Return the bits per pixel in system memory for a given mode.
25int
26vga_bpp(struct vgamode_s *vmode_g)
27{
28 switch (GET_GLOBAL(vmode_g->memmodel)) {
29 case MM_TEXT:
30 return 16;
31 case MM_PLANAR:
32 return 1;
33 }
34 u8 depth = GET_GLOBAL(vmode_g->depth);
35 if (depth > 8)
36 return ALIGN(depth, 8);
37 return depth;
38}
39
Kevin O'Connor83047be2012-01-07 18:27:19 -050040u16
41calc_page_size(u8 memmodel, u16 width, u16 height)
42{
43 switch (memmodel) {
44 case MM_TEXT:
45 return ALIGN(width * height * 2, 2*1024);
46 case MM_CGA:
47 return 16*1024;
48 default:
49 return ALIGN(width * height / 8, 8*1024);
50 }
51}
52
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040053static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040054set_cursor_shape(u8 start, u8 end)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040055{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040056 start &= 0x3f;
57 end &= 0x1f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040058
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040059 u16 curs = (start << 8) + end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040060 SET_BDA(cursor_type, curs);
61
Kevin O'Connorefbf4d62014-02-09 11:50:21 -050062 if (!CONFIG_VGA_STDVGA_PORTS)
63 return;
64
Kevin O'Connordd2be772009-05-16 15:41:23 -040065 u8 modeset_ctl = GET_BDA(modeset_ctl);
66 u16 cheight = GET_BDA(char_height);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040067 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
68 if (end != (start + 1))
69 start = ((start + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040070 else
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040071 start = ((end + 1) * cheight / 8) - 2;
72 end = ((end + 1) * cheight / 8) - 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040073 }
Kevin O'Connor88ca7412011-12-31 04:24:20 -050074 stdvga_set_cursor_shape(start, end);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040075}
76
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040077static u16
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040078get_cursor_shape(u8 page)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040079{
80 if (page > 7)
81 return 0;
82 // FIXME should handle VGA 14/16 lines
83 return GET_BDA(cursor_type);
84}
85
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040086static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040087set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040088{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050089 u8 page = cp.page, x = cp.x, y = cp.y;
90
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040091 // Should not happen...
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050092 if (page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040093 return;
94
95 // Bios cursor pos
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050096 SET_BDA(cursor_pos[page], (y << 8) | x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040097
Kevin O'Connorefbf4d62014-02-09 11:50:21 -050098 if (!CONFIG_VGA_STDVGA_PORTS)
99 return;
100
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400101 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400102 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400103 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400104 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400105
Kevin O'Connor83047be2012-01-07 18:27:19 -0500106 // Calculate the memory address
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500107 int address = (GET_BDA(video_pagesize) * page
108 + (x + y * GET_BDA(video_cols)) * 2);
Kevin O'Connor16920072012-01-27 22:59:46 -0500109 stdvga_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400110}
111
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400112static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400113get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400114{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400115 if (page == 0xff)
116 // special case - use current page
117 page = GET_BDA(video_page);
118 if (page > 7) {
119 struct cursorpos cp = { 0, 0, 0xfe };
120 return cp;
121 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400122 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400123 u16 xy = GET_BDA(cursor_pos[page]);
124 struct cursorpos cp = {xy, xy>>8, page};
125 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400126}
127
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400128static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400129set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400130{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400131 if (page > 7)
132 return;
133
134 // Get the mode
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500135 struct vgamode_s *vmode_g = get_current_mode();
Kevin O'Connor5727c292009-05-16 17:29:32 -0400136 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400137 return;
138
Kevin O'Connor4c85a262012-02-12 11:50:52 -0500139 // Get cursor pos for the given page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400140 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400141
Kevin O'Connor83047be2012-01-07 18:27:19 -0500142 // Calculate memory address of start of page
Kevin O'Connord61fc532012-01-27 20:37:45 -0500143 int address = GET_BDA(video_pagesize) * page;
144 vgahw_set_displaystart(vmode_g, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400145
146 // And change the BIOS page
Kevin O'Connor83047be2012-01-07 18:27:19 -0500147 SET_BDA(video_pagestart, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400148 SET_BDA(video_page, page);
149
Kevin O'Connora12c2152009-05-13 22:06:16 -0400150 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400151
152 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400153 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400154}
155
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400156static void
157set_scan_lines(u8 lines)
158{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500159 stdvga_set_scan_lines(lines);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400160 if (lines == 8)
161 set_cursor_shape(0x06, 0x07);
162 else
163 set_cursor_shape(lines - 4, lines - 3);
164 SET_BDA(char_height, lines);
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500165 u16 vde = stdvga_get_vde();
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400166 u8 rows = vde / lines;
167 SET_BDA(video_rows, rows - 1);
168 u16 cols = GET_BDA(video_cols);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500169 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400170}
171
172
173/****************************************************************
174 * Character writing
175 ****************************************************************/
176
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500177// Write a character to the screen and calculate new cursor position.
178static void
179write_char(struct cursorpos *pcp, struct carattr ca)
Kevin O'Connor09262412009-05-25 11:44:11 -0400180{
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500181 vgafb_write_char(*pcp, ca);
182 pcp->x++;
183 // Do we need to wrap ?
184 if (pcp->x == GET_BDA(video_cols)) {
185 pcp->x = 0;
186 pcp->y++;
187 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400188}
189
190// Write a character to the screen at a given position. Implement
191// special characters and scroll the screen if necessary.
192static void
193write_teletype(struct cursorpos *pcp, struct carattr ca)
194{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400195 switch (ca.car) {
196 case 7:
197 //FIXME should beep
198 break;
199 case 8:
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500200 if (pcp->x > 0)
201 pcp->x--;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400202 break;
203 case '\r':
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500204 pcp->x = 0;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400205 break;
206 case '\n':
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500207 pcp->y++;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400208 break;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400209 default:
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500210 write_char(pcp, ca);
211 break;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400212 }
213
Kevin O'Connor82221b22009-05-26 00:20:40 -0400214 // Do we need to scroll ?
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500215 u16 nbrows = GET_BDA(video_rows);
216 if (pcp->y > nbrows) {
217 pcp->y--;
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400218
219 struct vgamode_s *vmode_g = get_current_mode();
220 if (!vmode_g)
221 return;
222
223 struct cursorpos dest = {0, 0, pcp->page};
224 struct cursorpos src = {0, 1, pcp->page};
225 struct cursorpos size = {GET_BDA(video_cols), nbrows};
226 vgafb_move_chars(vmode_g, dest, src, size);
227
228 struct cursorpos clr = {0, nbrows, pcp->page};
229 struct carattr attr = {' ', 0, 0};
230 struct cursorpos clrsize = {GET_BDA(video_cols), 1};
231 vgafb_clear_chars(vmode_g, clr, attr, clrsize);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400232 }
Kevin O'Connor82221b22009-05-26 00:20:40 -0400233}
234
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400235
236/****************************************************************
237 * Save and restore bda state
238 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400239
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500240struct saveBDAstate {
241 u8 bda_0x49[28];
242 u8 bda_0x84[6];
243 u16 vbe_mode;
244 struct segoff_s font0;
245 struct segoff_s font1;
246};
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400247
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500248int
249bda_save_restore(int cmd, u16 seg, void *data)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400250{
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500251 if (!(cmd & SR_BDA))
252 return 0;
253 struct saveBDAstate *info = data;
254 if (cmd & SR_SAVE) {
255 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
256 , sizeof(info->bda_0x49));
257 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
258 , sizeof(info->bda_0x84));
259 SET_FARVAR(seg, info->vbe_mode, GET_BDA(vbe_mode));
260 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
261 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
262 }
263 if (cmd & SR_RESTORE) {
264 memcpy_far(SEG_BDA, (void*)0x49, seg, info->bda_0x49
265 , sizeof(info->bda_0x49));
266 memcpy_far(SEG_BDA, (void*)0x84, seg, info->bda_0x84
267 , sizeof(info->bda_0x84));
268 SET_BDA(vbe_mode, GET_FARVAR(seg, info->vbe_mode));
269 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
270 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
271 }
272 return sizeof(*info);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400273}
274
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500275
276/****************************************************************
277 * Mode setting
278 ****************************************************************/
279
280struct vgamode_s *
281get_current_mode(void)
282{
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500283 return vgahw_find_mode(GET_BDA(vbe_mode) & ~MF_VBEFLAGS);
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500284}
285
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500286// Setup BDA after a mode switch.
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500287int
288vga_set_mode(int mode, int flags)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400289{
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500290 dprintf(1, "set VGA mode %x\n", mode);
291 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
292 if (!vmode_g)
293 return VBE_RETURN_STATUS_FAILED;
294
295 int ret = vgahw_set_mode(vmode_g, flags);
296 if (ret)
297 return ret;
298
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400299 // Set the BIOS mem
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500300 int width = GET_GLOBAL(vmode_g->width);
301 int height = GET_GLOBAL(vmode_g->height);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500302 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500303 int cheight = GET_GLOBAL(vmode_g->cheight);
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500304 if (mode < 0x100)
305 SET_BDA(video_mode, mode);
306 else
307 SET_BDA(video_mode, 0xff);
308 SET_BDA(vbe_mode, mode | (flags & MF_VBEFLAGS));
Kevin O'Connor83047be2012-01-07 18:27:19 -0500309 if (memmodel == MM_TEXT) {
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500310 SET_BDA(video_cols, width);
311 SET_BDA(video_rows, height-1);
312 SET_BDA(cursor_type, 0x0607);
313 } else {
314 int cwidth = GET_GLOBAL(vmode_g->cwidth);
315 SET_BDA(video_cols, width / cwidth);
316 SET_BDA(video_rows, (height / cheight) - 1);
317 SET_BDA(cursor_type, 0x0000);
318 }
Kevin O'Connor83047be2012-01-07 18:27:19 -0500319 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500320 SET_BDA(crtc_address, CONFIG_VGA_STDVGA_PORTS ? stdvga_get_crtc() : 0);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400321 SET_BDA(char_height, cheight);
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500322 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400323 SET_BDA(video_switches, 0xF9);
324 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
Kevin O'Connorcecbc5d2011-12-31 17:24:11 -0500325 int i;
326 for (i=0; i<8; i++)
327 SET_BDA(cursor_pos[i], 0x0000);
328 SET_BDA(video_pagestart, 0x0000);
329 SET_BDA(video_page, 0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400330
331 // FIXME We nearly have the good tables. to be reworked
332 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
Kevin O'Connor9f985422009-09-09 11:34:39 -0400333 SET_BDA(video_savetable
Kevin O'Connor815e4472011-12-21 09:05:32 -0500334 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400335
336 // FIXME
337 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
338 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
339
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400340 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400341 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400342
343 switch (cheight) {
344 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400345 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400346 break;
347 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400348 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400349 break;
350 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400351 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400352 break;
353 }
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500354
355 return 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400356}
357
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500358
359/****************************************************************
360 * VGA int 10 handler
361 ****************************************************************/
362
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400363static void
Julian Pidancet87879e22011-12-19 05:08:00 +0000364handle_1000(struct bregs *regs)
365{
Kevin O'Connor5108c692011-12-31 19:13:45 -0500366 int mode = regs->al & 0x7f;
Julian Pidancet87879e22011-12-19 05:08:00 +0000367
368 // Set regs->al
369 if (mode > 7)
370 regs->al = 0x20;
371 else if (mode == 6)
372 regs->al = 0x3f;
373 else
374 regs->al = 0x30;
375
Kevin O'Connorb7b92932013-03-09 13:04:47 -0500376 int flags = MF_LEGACY | (GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM));
Kevin O'Connor5108c692011-12-31 19:13:45 -0500377 if (regs->al & 0x80)
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500378 flags |= MF_NOCLEARMEM;
379
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500380 vga_set_mode(mode, flags);
Julian Pidancet87879e22011-12-19 05:08:00 +0000381}
382
383static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400384handle_1001(struct bregs *regs)
385{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400386 set_cursor_shape(regs->ch, regs->cl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400387}
388
389static void
390handle_1002(struct bregs *regs)
391{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400392 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
393 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400394}
395
396static void
397handle_1003(struct bregs *regs)
398{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400399 regs->cx = get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400400 struct cursorpos cp = get_cursor_pos(regs->bh);
401 regs->dl = cp.x;
402 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400403}
404
405// Read light pen pos (unimplemented)
406static void
407handle_1004(struct bregs *regs)
408{
409 debug_stub(regs);
410 regs->ax = regs->bx = regs->cx = regs->dx = 0;
411}
412
413static void
414handle_1005(struct bregs *regs)
415{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400416 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400417}
418
419static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400420verify_scroll(struct bregs *regs, int dir)
421{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500422 u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400423 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500424 if (lry >= nbrows)
425 lry = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400426 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500427 if (lrx >= nbcols)
428 lrx = nbcols - 1;
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400429 int wincols = lrx - ulx + 1, winrows = lry - uly + 1;
430 if (wincols <= 0 || winrows <= 0)
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400431 return;
432
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400433 struct vgamode_s *vmode_g = get_current_mode();
434 if (!vmode_g)
435 return;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400436
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500437 u8 page = GET_BDA(video_page);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400438 int clearlines = regs->al, movelines = winrows - clearlines;
439 if (!clearlines || movelines <= 0) {
440 // Clear whole area.
441 struct cursorpos clr = {ulx, uly, page};
442 struct carattr attr = {' ', regs->bh, 1};
443 struct cursorpos clrsize = {wincols, winrows};
444 vgafb_clear_chars(vmode_g, clr, attr, clrsize);
445 return;
446 }
447
448 if (dir > 0) {
449 // Normal scroll
450 struct cursorpos dest = {ulx, uly, page};
451 struct cursorpos src = {ulx, uly + clearlines, page};
452 struct cursorpos size = {wincols, movelines};
453 vgafb_move_chars(vmode_g, dest, src, size);
454
455 struct cursorpos clr = {ulx, uly + movelines, page};
456 struct carattr attr = {' ', regs->bh, 1};
457 struct cursorpos clrsize = {wincols, clearlines};
458 vgafb_clear_chars(vmode_g, clr, attr, clrsize);
459 } else {
460 // Scroll down
461 struct cursorpos dest = {ulx, uly + clearlines, page};
462 struct cursorpos src = {ulx, uly, page};
463 struct cursorpos size = {wincols, movelines};
464 vgafb_move_chars(vmode_g, dest, src, size);
465
466 struct cursorpos clr = {ulx, uly, page};
467 struct carattr attr = {' ', regs->bh, 1};
468 struct cursorpos clrsize = {wincols, clearlines};
469 vgafb_clear_chars(vmode_g, clr, attr, clrsize);
470 }
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400471}
472
473static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400474handle_1006(struct bregs *regs)
475{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400476 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400477}
478
479static void
480handle_1007(struct bregs *regs)
481{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400482 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400483}
484
485static void
486handle_1008(struct bregs *regs)
487{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400488 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400489 regs->al = ca.car;
490 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400491}
492
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400493static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400494handle_1009(struct bregs *regs)
495{
Kevin O'Connor09262412009-05-25 11:44:11 -0400496 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500497 struct cursorpos cp = get_cursor_pos(regs->bh);
498 int count = regs->cx;
499 while (count--)
500 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400501}
502
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500503static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400504handle_100a(struct bregs *regs)
505{
Kevin O'Connor09262412009-05-25 11:44:11 -0400506 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500507 struct cursorpos cp = get_cursor_pos(regs->bh);
508 int count = regs->cx;
509 while (count--)
510 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400511}
512
513
514static void
515handle_100b00(struct bregs *regs)
516{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500517 stdvga_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400518}
519
520static void
521handle_100b01(struct bregs *regs)
522{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500523 stdvga_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400524}
525
526static void
527handle_100bXX(struct bregs *regs)
528{
529 debug_stub(regs);
530}
531
532static void
533handle_100b(struct bregs *regs)
534{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500535 if (!CONFIG_VGA_STDVGA_PORTS) {
536 handle_100bXX(regs);
537 return;
538 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400539 switch (regs->bh) {
540 case 0x00: handle_100b00(regs); break;
541 case 0x01: handle_100b01(regs); break;
542 default: handle_100bXX(regs); break;
543 }
544}
545
546
547static void
548handle_100c(struct bregs *regs)
549{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400550 // XXX - page (regs->bh) is unused
551 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400552}
553
554static void
555handle_100d(struct bregs *regs)
556{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400557 // XXX - page (regs->bh) is unused
558 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400559}
560
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400561static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400562handle_100e(struct bregs *regs)
563{
564 // Ralf Brown Interrupt list is WRONG on bh(page)
565 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400566 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400567 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400568 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400569 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400570}
571
572static void
573handle_100f(struct bregs *regs)
574{
Kevin O'Connore7132042009-05-25 00:10:35 -0400575 regs->bh = GET_BDA(video_page);
576 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
577 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400578}
579
580
581static void
582handle_101000(struct bregs *regs)
583{
584 if (regs->bl > 0x14)
585 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500586 stdvga_attr_write(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400587}
588
589static void
590handle_101001(struct bregs *regs)
591{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500592 stdvga_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400593}
594
595static void
596handle_101002(struct bregs *regs)
597{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500598 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400599}
600
601static void
602handle_101003(struct bregs *regs)
603{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500604 stdvga_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400605}
606
607static void
608handle_101007(struct bregs *regs)
609{
610 if (regs->bl > 0x14)
611 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500612 regs->bh = stdvga_attr_read(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400613}
614
615static void
616handle_101008(struct bregs *regs)
617{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500618 regs->bh = stdvga_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400619}
620
621static void
622handle_101009(struct bregs *regs)
623{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500624 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400625}
626
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400627static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400628handle_101010(struct bregs *regs)
629{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400630 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500631 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400632}
633
634static void
635handle_101012(struct bregs *regs)
636{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500637 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400638}
639
640static void
641handle_101013(struct bregs *regs)
642{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500643 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400644}
645
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400646static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400647handle_101015(struct bregs *regs)
648{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400649 u8 rgb[3];
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500650 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400651 regs->dh = rgb[0];
652 regs->ch = rgb[1];
653 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400654}
655
656static void
657handle_101017(struct bregs *regs)
658{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500659 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400660}
661
662static void
663handle_101018(struct bregs *regs)
664{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500665 stdvga_pelmask_write(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400666}
667
668static void
669handle_101019(struct bregs *regs)
670{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500671 regs->bl = stdvga_pelmask_read();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400672}
673
674static void
675handle_10101a(struct bregs *regs)
676{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500677 stdvga_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400678}
679
680static void
681handle_10101b(struct bregs *regs)
682{
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500683 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400684}
685
686static void
687handle_1010XX(struct bregs *regs)
688{
689 debug_stub(regs);
690}
691
692static void
693handle_1010(struct bregs *regs)
694{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500695 if (!CONFIG_VGA_STDVGA_PORTS) {
696 handle_1010XX(regs);
697 return;
698 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400699 switch (regs->al) {
700 case 0x00: handle_101000(regs); break;
701 case 0x01: handle_101001(regs); break;
702 case 0x02: handle_101002(regs); break;
703 case 0x03: handle_101003(regs); break;
704 case 0x07: handle_101007(regs); break;
705 case 0x08: handle_101008(regs); break;
706 case 0x09: handle_101009(regs); break;
707 case 0x10: handle_101010(regs); break;
708 case 0x12: handle_101012(regs); break;
709 case 0x13: handle_101013(regs); break;
710 case 0x15: handle_101015(regs); break;
711 case 0x17: handle_101017(regs); break;
712 case 0x18: handle_101018(regs); break;
713 case 0x19: handle_101019(regs); break;
714 case 0x1a: handle_10101a(regs); break;
715 case 0x1b: handle_10101b(regs); break;
716 default: handle_1010XX(regs); break;
717 }
718}
719
720
721static void
722handle_101100(struct bregs *regs)
723{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500724 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
725 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400726}
727
728static void
729handle_101101(struct bregs *regs)
730{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500731 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400732}
733
734static void
735handle_101102(struct bregs *regs)
736{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500737 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400738}
739
740static void
741handle_101103(struct bregs *regs)
742{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500743 stdvga_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400744}
745
746static void
747handle_101104(struct bregs *regs)
748{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500749 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400750}
751
752static void
753handle_101110(struct bregs *regs)
754{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500755 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
756 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400757 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400758}
759
760static void
761handle_101111(struct bregs *regs)
762{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500763 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400764 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400765}
766
767static void
768handle_101112(struct bregs *regs)
769{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500770 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400771 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400772}
773
774static void
775handle_101114(struct bregs *regs)
776{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500777 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400778 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400779}
780
781static void
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100782handle_101120(struct bregs *regs)
783{
784 SET_IVT(0x1f, SEGOFF(regs->es, regs->bp));
785}
786
787void
788load_gfx_font(u16 seg, u16 off, u8 height, u8 bl, u8 dl)
789{
790 u8 rows;
791
792 SET_IVT(0x43, SEGOFF(seg, off));
793 switch(bl) {
794 case 0:
795 rows = dl;
796 break;
797 case 1:
798 rows = 14;
799 break;
800 case 3:
801 rows = 43;
802 break;
803 case 2:
804 default:
805 rows = 25;
806 break;
807 }
808 SET_BDA(video_rows, rows - 1);
809 SET_BDA(char_height, height);
810}
811
812static void
813handle_101121(struct bregs *regs)
814{
815 load_gfx_font(regs->es, regs->bp, regs->cx, regs->bl, regs->dl);
816}
817
818static void
819handle_101122(struct bregs *regs)
820{
821 load_gfx_font(get_global_seg(), (u32)vgafont14, 14, regs->bl, regs->dl);
822}
823
824static void
825handle_101123(struct bregs *regs)
826{
827 load_gfx_font(get_global_seg(), (u32)vgafont8, 8, regs->bl, regs->dl);
828}
829
830static void
831handle_101124(struct bregs *regs)
832{
833 load_gfx_font(get_global_seg(), (u32)vgafont16, 16, regs->bl, regs->dl);
834}
835
836static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400837handle_101130(struct bregs *regs)
838{
Kevin O'Connore7132042009-05-25 00:10:35 -0400839 switch (regs->bh) {
840 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500841 struct segoff_s so = GET_IVT(0x1f);
842 regs->es = so.seg;
843 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400844 break;
845 }
846 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500847 struct segoff_s so = GET_IVT(0x43);
848 regs->es = so.seg;
849 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400850 break;
851 }
852 case 0x02:
853 regs->es = get_global_seg();
854 regs->bp = (u32)vgafont14;
855 break;
856 case 0x03:
857 regs->es = get_global_seg();
858 regs->bp = (u32)vgafont8;
859 break;
860 case 0x04:
861 regs->es = get_global_seg();
862 regs->bp = (u32)vgafont8 + 128 * 8;
863 break;
864 case 0x05:
865 regs->es = get_global_seg();
866 regs->bp = (u32)vgafont14alt;
867 break;
868 case 0x06:
869 regs->es = get_global_seg();
870 regs->bp = (u32)vgafont16;
871 break;
872 case 0x07:
873 regs->es = get_global_seg();
874 regs->bp = (u32)vgafont16alt;
875 break;
876 default:
877 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
878 return;
879 }
880 // Set byte/char of on screen font
881 regs->cx = GET_BDA(char_height) & 0xff;
882
883 // Set Highest char row
Kevin O'Connor4c85a262012-02-12 11:50:52 -0500884 regs->dl = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400885}
886
887static void
888handle_1011XX(struct bregs *regs)
889{
890 debug_stub(regs);
891}
892
893static void
894handle_1011(struct bregs *regs)
895{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500896 if (CONFIG_VGA_STDVGA_PORTS) {
897 switch (regs->al) {
898 case 0x00: handle_101100(regs); break;
899 case 0x01: handle_101101(regs); break;
900 case 0x02: handle_101102(regs); break;
901 case 0x03: handle_101103(regs); break;
902 case 0x04: handle_101104(regs); break;
903 case 0x10: handle_101110(regs); break;
904 case 0x11: handle_101111(regs); break;
905 case 0x12: handle_101112(regs); break;
906 case 0x14: handle_101114(regs); break;
907 }
908 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400909 switch (regs->al) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400910 case 0x30: handle_101130(regs); break;
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100911 case 0x20: handle_101120(regs); break;
912 case 0x21: handle_101121(regs); break;
913 case 0x22: handle_101122(regs); break;
914 case 0x23: handle_101123(regs); break;
915 case 0x24: handle_101124(regs); break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400916 default: handle_1011XX(regs); break;
917 }
918}
919
920
921static void
922handle_101210(struct bregs *regs)
923{
Kevin O'Connore7132042009-05-25 00:10:35 -0400924 u16 crtc_addr = GET_BDA(crtc_address);
925 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
926 regs->bx = 0x0103;
927 else
928 regs->bx = 0x0003;
929 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400930}
931
932static void
933handle_101230(struct bregs *regs)
934{
Kevin O'Connore7132042009-05-25 00:10:35 -0400935 u8 mctl = GET_BDA(modeset_ctl);
936 u8 vswt = GET_BDA(video_switches);
937 switch (regs->al) {
938 case 0x00:
939 // 200 lines
940 mctl = (mctl & ~0x10) | 0x80;
941 vswt = (vswt & ~0x0f) | 0x08;
942 break;
943 case 0x01:
944 // 350 lines
945 mctl &= ~0x90;
946 vswt = (vswt & ~0x0f) | 0x09;
947 break;
948 case 0x02:
949 // 400 lines
950 mctl = (mctl & ~0x80) | 0x10;
951 vswt = (vswt & ~0x0f) | 0x09;
952 break;
953 default:
954 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
955 break;
956 }
957 SET_BDA(modeset_ctl, mctl);
958 SET_BDA(video_switches, vswt);
959 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400960}
961
962static void
963handle_101231(struct bregs *regs)
964{
Kevin O'Connore7132042009-05-25 00:10:35 -0400965 u8 v = (regs->al & 0x01) << 3;
966 u8 mctl = GET_BDA(video_ctl) & ~0x08;
967 SET_BDA(video_ctl, mctl | v);
968 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400969}
970
971static void
972handle_101232(struct bregs *regs)
973{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500974 if (CONFIG_VGA_STDVGA_PORTS) {
975 stdvga_enable_video_addressing(regs->al);
976 regs->al = 0x12;
977 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400978}
979
980static void
981handle_101233(struct bregs *regs)
982{
Kevin O'Connore7132042009-05-25 00:10:35 -0400983 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
984 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
985 SET_BDA(modeset_ctl, v | v2);
986 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400987}
988
989static void
990handle_101234(struct bregs *regs)
991{
Kevin O'Connore7132042009-05-25 00:10:35 -0400992 u8 v = (regs->al & 0x01) ^ 0x01;
993 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
994 SET_BDA(modeset_ctl, v | v2);
995 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400996}
997
998static void
999handle_101235(struct bregs *regs)
1000{
1001 debug_stub(regs);
1002 regs->al = 0x12;
1003}
1004
1005static void
1006handle_101236(struct bregs *regs)
1007{
1008 debug_stub(regs);
1009 regs->al = 0x12;
1010}
1011
1012static void
1013handle_1012XX(struct bregs *regs)
1014{
1015 debug_stub(regs);
1016}
1017
1018static void
1019handle_1012(struct bregs *regs)
1020{
Kevin O'Connore91ec7c2012-01-14 16:30:49 -05001021 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
1022 clext_1012(regs);
1023 return;
1024 }
1025
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001026 switch (regs->bl) {
1027 case 0x10: handle_101210(regs); break;
1028 case 0x30: handle_101230(regs); break;
1029 case 0x31: handle_101231(regs); break;
1030 case 0x32: handle_101232(regs); break;
1031 case 0x33: handle_101233(regs); break;
1032 case 0x34: handle_101234(regs); break;
1033 case 0x35: handle_101235(regs); break;
1034 case 0x36: handle_101236(regs); break;
1035 default: handle_1012XX(regs); break;
1036 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001037}
1038
1039
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001040// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -04001041static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001042handle_1013(struct bregs *regs)
1043{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001044 struct cursorpos cp;
1045 if (regs->dh == 0xff)
1046 // if row=0xff special case : use current cursor position
1047 cp = get_cursor_pos(regs->bh);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001048 else
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001049 cp = (struct cursorpos) {regs->dl, regs->dh, regs->bh};
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001050
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001051 u16 count = regs->cx;
1052 u8 *offset_far = (void*)(regs->bp + 0);
1053 u8 attr = regs->bl;
1054 while (count--) {
1055 u8 car = GET_FARVAR(regs->es, *offset_far);
1056 offset_far++;
1057 if (regs->al & 2) {
1058 attr = GET_FARVAR(regs->es, *offset_far);
1059 offset_far++;
1060 }
1061
1062 struct carattr ca = {car, attr, 1};
1063 write_teletype(&cp, ca);
1064 }
1065
1066 if (regs->al & 1)
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001067 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001068}
1069
1070
1071static void
1072handle_101a00(struct bregs *regs)
1073{
Kevin O'Connore7132042009-05-25 00:10:35 -04001074 regs->bx = GET_BDA(dcc_index);
1075 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001076}
1077
1078static void
1079handle_101a01(struct bregs *regs)
1080{
Kevin O'Connore7132042009-05-25 00:10:35 -04001081 SET_BDA(dcc_index, regs->bl);
1082 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1083 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001084}
1085
1086static void
1087handle_101aXX(struct bregs *regs)
1088{
1089 debug_stub(regs);
1090}
1091
1092static void
1093handle_101a(struct bregs *regs)
1094{
1095 switch (regs->al) {
1096 case 0x00: handle_101a00(regs); break;
1097 case 0x01: handle_101a01(regs); break;
1098 default: handle_101aXX(regs); break;
1099 }
1100}
1101
1102
Kevin O'Connorefb45232012-01-14 22:55:11 -05001103static u8 static_functionality[0x10] VAR16 = {
1104 /* 0 */ 0xff, // All modes supported #1
1105 /* 1 */ 0xe0, // All modes supported #2
1106 /* 2 */ 0x0f, // All modes supported #3
1107 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1108 /* 7 */ 0x07, // 200, 350, 400 scan lines
1109 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1110 /* 9 */ 0x08, // total number of charset blocks in text mode
1111 /* a */ 0xe7, // Change to add new functions
1112 /* b */ 0x0c, // Change to add new functions
1113 /* c */ 0x00, // reserved
1114 /* d */ 0x00, // reserved
1115 /* e */ 0x00, // Change to add new functions
1116 /* f */ 0x00 // reserved
1117};
1118
Kevin O'Connorca668642009-05-21 23:06:08 -04001119struct funcInfo {
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001120 struct segoff_s static_functionality;
Kevin O'Connorca668642009-05-21 23:06:08 -04001121 u8 bda_0x49[30];
1122 u8 bda_0x84[3];
1123 u8 dcc_index;
1124 u8 dcc_alt;
1125 u16 colors;
1126 u8 pages;
1127 u8 scan_lines;
1128 u8 primary_char;
1129 u8 secondar_char;
1130 u8 misc;
1131 u8 non_vga_mode;
1132 u8 reserved_2f[2];
1133 u8 video_mem;
1134 u8 save_flags;
1135 u8 disp_info;
1136 u8 reserved_34[12];
Kevin O'Connorf5ec1e02014-02-05 18:49:44 -05001137} PACKED;
Kevin O'Connorca668642009-05-21 23:06:08 -04001138
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001139static void
1140handle_101b(struct bregs *regs)
1141{
Kevin O'Connorca668642009-05-21 23:06:08 -04001142 u16 seg = regs->es;
1143 struct funcInfo *info = (void*)(regs->di+0);
1144 memset_far(seg, info, 0, sizeof(*info));
1145 // Address of static functionality table
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001146 SET_FARVAR(seg, info->static_functionality
1147 , SEGOFF(get_global_seg(), (u32)static_functionality));
Kevin O'Connorca668642009-05-21 23:06:08 -04001148
1149 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001150 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1151 , sizeof(info->bda_0x49));
1152 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1153 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001154
1155 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1156 SET_FARVAR(seg, info->colors, 16);
1157 SET_FARVAR(seg, info->pages, 8);
1158 SET_FARVAR(seg, info->scan_lines, 2);
1159 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001160 regs->al = 0x1B;
1161}
1162
1163
1164static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001165handle_101c(struct bregs *regs)
1166{
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001167 u16 seg = regs->es;
1168 void *data = (void*)(regs->bx+0);
1169 u16 states = regs->cx;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001170 u8 cmd = regs->al;
1171 if (states & ~0x07 || cmd > 2)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001172 goto fail;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001173 int ret = vgahw_save_restore(states | (cmd<<8), seg, data);
1174 if (ret < 0)
1175 goto fail;
1176 if (cmd == 0)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001177 regs->bx = ret / 64;
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001178 regs->al = 0x1c;
1179fail:
1180 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001181}
1182
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001183static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001184handle_10XX(struct bregs *regs)
1185{
1186 debug_stub(regs);
1187}
1188
1189// INT 10h Video Support Service Entry Point
1190void VISIBLE16
1191handle_10(struct bregs *regs)
1192{
1193 debug_enter(regs, DEBUG_VGA_10);
1194 switch (regs->ah) {
1195 case 0x00: handle_1000(regs); break;
1196 case 0x01: handle_1001(regs); break;
1197 case 0x02: handle_1002(regs); break;
1198 case 0x03: handle_1003(regs); break;
1199 case 0x04: handle_1004(regs); break;
1200 case 0x05: handle_1005(regs); break;
1201 case 0x06: handle_1006(regs); break;
1202 case 0x07: handle_1007(regs); break;
1203 case 0x08: handle_1008(regs); break;
1204 case 0x09: handle_1009(regs); break;
1205 case 0x0a: handle_100a(regs); break;
1206 case 0x0b: handle_100b(regs); break;
1207 case 0x0c: handle_100c(regs); break;
1208 case 0x0d: handle_100d(regs); break;
1209 case 0x0e: handle_100e(regs); break;
1210 case 0x0f: handle_100f(regs); break;
1211 case 0x10: handle_1010(regs); break;
1212 case 0x11: handle_1011(regs); break;
1213 case 0x12: handle_1012(regs); break;
1214 case 0x13: handle_1013(regs); break;
1215 case 0x1a: handle_101a(regs); break;
1216 case 0x1b: handle_101b(regs); break;
1217 case 0x1c: handle_101c(regs); break;
1218 case 0x4f: handle_104f(regs); break;
1219 default: handle_10XX(regs); break;
1220 }
1221}