vgabios: Merge support for GeodeLX vga bios.
[seabios.git] / vgasrc / vga.c
index fd4ae28997779f58b97637bd5fc5b6f88a2fb84b..37f227c078598fb2141fa54ba8cf1b005c6e3bc5 100644 (file)
@@ -8,39 +8,44 @@
 
 // TODO:
 //  * review correctness of converted asm by comparing with RBIL
-//  * refactor redundant code into sub-functions
-//  * See if there is a method to the in/out stuff that can be encapsulated.
-//  * remove "biosfn" prefixes
-//  * verify all funcs static
 //
 //  * convert vbe/clext code
-//
-//  * extract hw code from bios interfaces
 
 #include "bregs.h" // struct bregs
 #include "biosvar.h" // GET_BDA
 #include "util.h" // memset
 #include "vgatables.h" // find_vga_entry
-
-// XXX
-#define CONFIG_VBE 0
-#define CONFIG_CIRRUS 0
+#include "optionroms.h" // struct pci_data
+#include "config.h" // CONFIG_*
+#include "vbe.h" // vbe_*
+#include "geodelx.h" // geodelx_init
 
 // XXX
 #define DEBUG_VGA_POST 1
 #define DEBUG_VGA_10 3
 
-#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
 
+/****************************************************************
+ * PCI Data
+ ****************************************************************/
+#if CONFIG_VGA_PCI == 1
+struct pci_data rom_pci_data VAR16VISIBLE = {
+    .signature = PCI_ROM_SIGNATURE,
+    .vendor = CONFIG_VGA_VID,
+    .device = CONFIG_VGA_DID,
+    .dlen = 0x18,
+    .class_hi = 0x300,
+    .irevision = 1,
+    .type = PCIROM_CODETYPE_X86,
+    .indicator = 0x80,
+};
+#endif
 
-// ===================================================================
-//
-// Video Utils
-//
-// ===================================================================
+/****************************************************************
+ * Helper functions
+ ****************************************************************/
 
-// -------------------------------------------------------------------
-inline void
+static inline void
 call16_vgaint(u32 eax, u32 ebx)
 {
     asm volatile(
@@ -52,16 +57,8 @@ call16_vgaint(u32 eax, u32 ebx)
         : "cc", "memory");
 }
 
-
-// ===================================================================
-//
-// BIOS functions
-//
-// ===================================================================
-
-// -------------------------------------------------------------------
 static void
-biosfn_perform_gray_scale_summing(u16 start, u16 count)
+perform_gray_scale_summing(u16 start, u16 count)
 {
     vgahw_screen_disable();
     int i;
@@ -79,30 +76,29 @@ biosfn_perform_gray_scale_summing(u16 start, u16 count)
     vgahw_screen_enable();
 }
 
-// -------------------------------------------------------------------
 static void
-biosfn_set_cursor_shape(u8 CH, u8 CL)
+set_cursor_shape(u8 start, u8 end)
 {
-    CH &= 0x3f;
-    CL &= 0x1f;
+    start &= 0x3f;
+    end &= 0x1f;
 
-    u16 curs = (CH << 8) + CL;
+    u16 curs = (start << 8) + end;
     SET_BDA(cursor_type, curs);
 
     u8 modeset_ctl = GET_BDA(modeset_ctl);
     u16 cheight = GET_BDA(char_height);
-    if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
-        if (CL != (CH + 1))
-            CH = ((CH + 1) * cheight / 8) - 1;
+    if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
+        if (end != (start + 1))
+            start = ((start + 1) * cheight / 8) - 1;
         else
-            CH = ((CL + 1) * cheight / 8) - 2;
-        CL = ((CL + 1) * cheight / 8) - 1;
+            start = ((end + 1) * cheight / 8) - 2;
+        end = ((end + 1) * cheight / 8) - 1;
     }
-    vgahw_set_cursor_shape(CH, CL);
+    vgahw_set_cursor_shape(start, end);
 }
 
 static u16
-biosfn_get_cursor_shape(u8 page)
+get_cursor_shape(u8 page)
 {
     if (page > 7)
         return 0;
@@ -110,47 +106,50 @@ biosfn_get_cursor_shape(u8 page)
     return GET_BDA(cursor_type);
 }
 
-// -------------------------------------------------------------------
 static void
-biosfn_set_cursor_pos(u8 page, u16 cursor)
+set_cursor_pos(struct cursorpos cp)
 {
     // Should not happen...
-    if (page > 7)
+    if (cp.page > 7)
         return;
 
     // Bios cursor pos
-    SET_BDA(cursor_pos[page], cursor);
+    SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
 
     // Set the hardware cursor
     u8 current = GET_BDA(video_page);
-    if (page != current)
+    if (cp.page != current)
         return;
 
     // Get the dimensions
     u16 nbcols = GET_BDA(video_cols);
     u16 nbrows = GET_BDA(video_rows) + 1;
 
-    u8 xcurs = cursor & 0x00ff;
-    u8 ycurs = (cursor & 0xff00) >> 8;
-
     // Calculate the address knowing nbcols nbrows and page num
-    u16 address = SCREEN_IO_START(nbcols, nbrows, page) + xcurs + ycurs * nbcols;
+    u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
+                   + cp.x + cp.y * nbcols);
 
     vgahw_set_cursor_pos(address);
 }
 
-u16
-biosfn_get_cursor_pos(u8 page)
+static struct cursorpos
+get_cursor_pos(u8 page)
 {
-    if (page > 7)
-        return 0;
+    if (page == 0xff)
+        // special case - use current page
+        page = GET_BDA(video_page);
+    if (page > 7) {
+        struct cursorpos cp = { 0, 0, 0xfe };
+        return cp;
+    }
     // FIXME should handle VGA 14/16 lines
-    return GET_BDA(cursor_pos[page]);
+    u16 xy = GET_BDA(cursor_pos[page]);
+    struct cursorpos cp = {xy, xy>>8, page};
+    return cp;
 }
 
-// -------------------------------------------------------------------
 static void
-biosfn_set_active_page(u8 page)
+set_active_page(u8 page)
 {
     if (page > 7)
         return;
@@ -161,10 +160,10 @@ biosfn_set_active_page(u8 page)
         return;
 
     // Get pos curs pos for the right page
-    u16 cursor = biosfn_get_cursor_pos(page);
+    struct cursorpos cp = get_cursor_pos(page);
 
     u16 address;
-    if (GET_GLOBAL(vmode_g->class) == TEXT) {
+    if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
         // Get the dimensions
         u16 nbcols = GET_BDA(video_cols);
         u16 nbrows = GET_BDA(video_rows) + 1;
@@ -176,8 +175,7 @@ biosfn_set_active_page(u8 page)
         // Start address
         address = SCREEN_IO_START(nbcols, nbrows, page);
     } else {
-        struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
-        address = page * GET_GLOBAL(vparam_g->slength);
+        address = page * GET_GLOBAL(vmode_g->slength);
     }
 
     vgahw_set_active_page(address);
@@ -188,250 +186,128 @@ biosfn_set_active_page(u8 page)
     dprintf(1, "Set active page %02x address %04x\n", page, address);
 
     // Display the cursor, now the page is active
-    biosfn_set_cursor_pos(page, cursor);
+    set_cursor_pos(cp);
 }
 
 static void
-biosfn_set_video_mode(u8 mode)
-{                               // mode: Bit 7 is 1 if no clear screen
-    if (CONFIG_CIRRUS)
-        cirrus_set_video_mode(mode);
-
-    if (CONFIG_VBE)
-        if (vbe_has_vbe_display())
-            dispi_set_enable(VBE_DISPI_DISABLED);
-
-    // The real mode
-    u8 noclearmem = mode & 0x80;
-    mode = mode & 0x7f;
-
-    // find the entry in the video modes
-    struct vgamode_s *vmode_g = find_vga_entry(mode);
-    dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
-    if (!vmode_g)
-        return;
-
-    // Read the bios mode set control
-    u8 modeset_ctl = GET_BDA(modeset_ctl);
-
-    // Then we know the number of lines
-// FIXME
-
-    // if palette loading (bit 3 of modeset ctl = 0)
-    if ((modeset_ctl & 0x08) == 0) {    // Set the PEL mask
-        vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
-
-        // From which palette
-        u8 *palette_g = GET_GLOBAL(vmode_g->dac);
-        u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
-
-        // Always 256*3 values
-        vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
-        u16 i;
-        for (i = palsize; i < 0x0100; i++) {
-            static u8 rgb[3] VAR16;
-            vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
-        }
-
-        if ((modeset_ctl & 0x02) == 0x02)
-            biosfn_perform_gray_scale_summing(0x00, 0x100);
-    }
-
-    struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
-    vgahw_set_mode(vparam_g);
-
-    if (noclearmem == 0x00)
-        clear_screen(vmode_g);
-
-    // Set CRTC address VGA or MDA
-    u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
-    if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
-        crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
-
-    // Set the BIOS mem
-    u16 cheight = GET_GLOBAL(vparam_g->cheight);
-    SET_BDA(video_mode, mode);
-    SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
-    SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
-    SET_BDA(crtc_address, crtc_addr);
-    SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
-    SET_BDA(char_height, cheight);
-    SET_BDA(video_ctl, (0x60 | noclearmem));
-    SET_BDA(video_switches, 0xF9);
-    SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
-
-    // FIXME We nearly have the good tables. to be reworked
-    SET_BDA(dcc_index, 0x08);   // 8 is VGA should be ok for now
-    SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
-    SET_BDA(video_savetable_seg, get_global_seg());
-
-    // FIXME
-    SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
-    SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
-
-    // Set cursor shape
-    if (GET_GLOBAL(vmode_g->class) == TEXT)
-        biosfn_set_cursor_shape(0x06, 0x07);
-    // Set cursor pos for page 0..7
-    int i;
-    for (i = 0; i < 8; i++)
-        biosfn_set_cursor_pos(i, 0x0000);
+set_scan_lines(u8 lines)
+{
+    vgahw_set_scan_lines(lines);
+    if (lines == 8)
+        set_cursor_shape(0x06, 0x07);
+    else
+        set_cursor_shape(lines - 4, lines - 3);
+    SET_BDA(char_height, lines);
+    u16 vde = vgahw_get_vde();
+    u8 rows = vde / lines;
+    SET_BDA(video_rows, rows - 1);
+    u16 cols = GET_BDA(video_cols);
+    SET_BDA(video_pagesize, rows * cols * 2);
+}
 
-    // Set active page 0
-    biosfn_set_active_page(0x00);
 
-    // Write the fonts in memory
-    if (GET_GLOBAL(vmode_g->class) == TEXT) {
-        call16_vgaint(0x1104, 0);
-        call16_vgaint(0x1103, 0);
-    }
-    // Set the ints 0x1F and 0x43
-    SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
+/****************************************************************
+ * Character writing
+ ****************************************************************/
 
-    switch (cheight) {
-    case 8:
-        SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
-        break;
-    case 14:
-        SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
-        break;
-    case 16:
-        SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
-        break;
-    }
+// Scroll the screen one line.  This function is designed to be called
+// tail-recursive to reduce stack usage.
+static void noinline
+scroll_one(u16 nbrows, u16 nbcols, u8 page)
+{
+    struct cursorpos ul = {0, 0, page};
+    struct cursorpos lr = {nbcols-1, nbrows-1, page};
+    vgafb_scroll(1, -1, ul, lr);
 }
 
-// -------------------------------------------------------------------
+// Write a character to the screen at a given position.  Implement
+// special characters and scroll the screen if necessary.
 static void
-biosfn_write_teletype(u8 car, u8 page, u8 attr, u8 flag)
-{                               // flag = WITH_ATTR / NO_ATTR
-    // special case if page is 0xff, use current page
-    if (page == 0xff)
-        page = GET_BDA(video_page);
-
-    // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
-    if (!vmode_g)
-        return;
-
-    // Get the cursor pos for the page
-    u16 cursor = biosfn_get_cursor_pos(page);
-    u8 xcurs = cursor & 0x00ff;
-    u8 ycurs = (cursor & 0xff00) >> 8;
+write_teletype(struct cursorpos *pcp, struct carattr ca)
+{
+    struct cursorpos cp = *pcp;
 
     // Get the dimensions
     u16 nbrows = GET_BDA(video_rows) + 1;
     u16 nbcols = GET_BDA(video_cols);
 
-    switch (car) {
+    switch (ca.car) {
     case 7:
         //FIXME should beep
         break;
-
     case 8:
-        if (xcurs > 0)
-            xcurs--;
+        if (cp.x > 0)
+            cp.x--;
         break;
-
     case '\r':
-        xcurs = 0;
+        cp.x = 0;
         break;
-
     case '\n':
-        ycurs++;
+        cp.y++;
         break;
-
     case '\t':
         do {
-            biosfn_write_teletype(' ', page, attr, flag);
-            cursor = biosfn_get_cursor_pos(page);
-            xcurs = cursor & 0x00ff;
-            ycurs = (cursor & 0xff00) >> 8;
-        } while (xcurs % 8 == 0);
+            struct carattr dummyca = {' ', ca.attr, ca.use_attr};
+            vgafb_write_char(cp, dummyca);
+            cp.x++;
+        } while (cp.x < nbcols && cp.x % 8);
         break;
-
     default:
-        if (flag == WITH_ATTR)
-            biosfn_write_char_attr(car, page, attr, 1);
-        else
-            biosfn_write_char_only(car, page, attr, 1);
-        xcurs++;
+        vgafb_write_char(cp, ca);
+        cp.x++;
     }
 
     // Do we need to wrap ?
-    if (xcurs == nbcols) {
-        xcurs = 0;
-        ycurs++;
+    if (cp.x == nbcols) {
+        cp.x = 0;
+        cp.y++;
     }
     // Do we need to scroll ?
-    if (ycurs == nbrows) {
-        if (GET_GLOBAL(vmode_g->class) == TEXT)
-            biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page,
-                          SCROLL_UP);
-        else
-            biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page,
-                          SCROLL_UP);
-        ycurs -= 1;
+    if (cp.y < nbrows) {
+        *pcp = cp;
+        return;
     }
-    // Set the cursor for the page
-    cursor = ycurs;
-    cursor <<= 8;
-    cursor += xcurs;
-    biosfn_set_cursor_pos(page, cursor);
+    // Scroll screen
+    cp.y--;
+    *pcp = cp;
+    scroll_one(nbrows, nbcols, cp.page);
 }
 
+// Write out a buffer of alternating characters and attributes.
 static void
-biosfn_write_string(u8 flag, u8 page, u8 attr, u16 count, u8 row, u8 col,
-                    u16 seg, u8 *offset_far)
+write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
 {
-    // Read curs info for the page
-    u16 oldcurs = biosfn_get_cursor_pos(page);
-
-    // if row=0xff special case : use current cursor position
-    if (row == 0xff) {
-        col = oldcurs & 0x00ff;
-        row = (oldcurs & 0xff00) >> 8;
-    }
-
-    u16 newcurs = row;
-    newcurs <<= 8;
-    newcurs += col;
-    biosfn_set_cursor_pos(page, newcurs);
-
-    while (count-- != 0) {
+    while (count--) {
         u8 car = GET_FARVAR(seg, *offset_far);
         offset_far++;
-        if ((flag & 0x02) != 0) {
-            attr = GET_FARVAR(seg, *offset_far);
-            offset_far++;
-        }
+        u8 attr = GET_FARVAR(seg, *offset_far);
+        offset_far++;
 
-        biosfn_write_teletype(car, page, attr, WITH_ATTR);
+        struct carattr ca = {car, attr, 1};
+        write_teletype(pcp, ca);
     }
-
-    // Set back curs pos
-    if ((flag & 0x01) == 0)
-        biosfn_set_cursor_pos(page, oldcurs);
 }
 
+// Write out a buffer of characters.
 static void
-set_scan_lines(u8 lines)
+write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
 {
-    vgahw_set_scan_lines(lines);
-    if (lines == 8)
-        biosfn_set_cursor_shape(0x06, 0x07);
-    else
-        biosfn_set_cursor_shape(lines - 4, lines - 3);
-    SET_BDA(char_height, lines);
-    u16 vde = vgahw_get_vde();
-    u8 rows = vde / lines;
-    SET_BDA(video_rows, rows - 1);
-    u16 cols = GET_BDA(video_cols);
-    SET_BDA(video_pagesize, rows * cols * 2);
+    while (count--) {
+        u8 car = GET_FARVAR(seg, *offset_far);
+        offset_far++;
+
+        struct carattr ca = {car, attr, 1};
+        write_teletype(pcp, ca);
+    }
 }
 
+
+/****************************************************************
+ * Save and restore bda state
+ ****************************************************************/
+
 static void
-biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
+save_bda_state(u16 seg, struct saveBDAstate *info)
 {
     SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
     SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
@@ -449,12 +325,12 @@ biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
     SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
     SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
     /* current font */
-    SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
-    SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
+    SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
+    SET_FARVAR(seg, info->font1, GET_IVT(0x43));
 }
 
 static void
-biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
+restore_bda_state(u16 seg, struct saveBDAstate *info)
 {
     SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
     SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
@@ -472,10 +348,8 @@ biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
     SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
     SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
     /* current font */
-    SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
-            , GET_FARVAR(seg, info->font0_off));
-    SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
-            , GET_FARVAR(seg, info->font1_off));
+    SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
+    SET_IVT(0x43, GET_FARVAR(seg, info->font1));
 }
 
 
@@ -483,46 +357,153 @@ biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
  * VGA int 10 handler
  ****************************************************************/
 
-static void
-handle_1000(struct bregs *regs)
+// set video mode
+void
+vga_set_mode(u8 mode, u8 noclearmem)
 {
-    // XXX - inline
-    biosfn_set_video_mode(regs->al);
-    switch(regs->al & 0x7F) {
-    case 6:
-        regs->al = 0x3F;
+    // find the entry in the video modes
+    struct vgamode_s *vmode_g = find_vga_entry(mode);
+    dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
+    if (!vmode_g)
+        return;
+
+    // Read the bios mode set control
+    u8 modeset_ctl = GET_BDA(modeset_ctl);
+
+    // Then we know the number of lines
+// FIXME
+
+    // if palette loading (bit 3 of modeset ctl = 0)
+    if ((modeset_ctl & 0x08) == 0) {    // Set the PEL mask
+        vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
+
+        // From which palette
+        u8 *palette_g = GET_GLOBAL(vmode_g->dac);
+        u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
+
+        // Always 256*3 values
+        vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
+        u16 i;
+        for (i = palsize; i < 0x0100; i++) {
+            static u8 rgb[3] VAR16;
+            vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
+        }
+
+        if ((modeset_ctl & 0x02) == 0x02)
+            perform_gray_scale_summing(0x00, 0x100);
+    }
+
+    vgahw_set_mode(vmode_g);
+
+    if (noclearmem == 0x00)
+        clear_screen(vmode_g);
+
+    // Set CRTC address VGA or MDA
+    u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
+    if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
+        crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
+
+    // Set the BIOS mem
+    u16 cheight = GET_GLOBAL(vmode_g->cheight);
+    SET_BDA(video_mode, mode);
+    SET_BDA(video_cols, GET_GLOBAL(vmode_g->twidth));
+    SET_BDA(video_pagesize, GET_GLOBAL(vmode_g->slength));
+    SET_BDA(crtc_address, crtc_addr);
+    SET_BDA(video_rows, GET_GLOBAL(vmode_g->theight)-1);
+    SET_BDA(char_height, cheight);
+    SET_BDA(video_ctl, (0x60 | noclearmem));
+    SET_BDA(video_switches, 0xF9);
+    SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
+
+    // FIXME We nearly have the good tables. to be reworked
+    SET_BDA(dcc_index, 0x08);   // 8 is VGA should be ok for now
+    SET_BDA(video_savetable
+            , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
+
+    // FIXME
+    SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
+    SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
+
+    // Set cursor shape
+    if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
+        set_cursor_shape(0x06, 0x07);
+    // Set cursor pos for page 0..7
+    int i;
+    for (i = 0; i < 8; i++) {
+        struct cursorpos cp = {0, 0, i};
+        set_cursor_pos(cp);
+    }
+
+    // Set active page 0
+    set_active_page(0x00);
+
+    // Write the fonts in memory
+    if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
+        call16_vgaint(0x1104, 0);
+        call16_vgaint(0x1103, 0);
+    }
+    // Set the ints 0x1F and 0x43
+    SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
+
+    switch (cheight) {
+    case 8:
+        SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
         break;
-    case 0:
-    case 1:
-    case 2:
-    case 3:
-    case 4:
-    case 5:
-    case 7:
-        regs->al = 0x30;
+    case 14:
+        SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
         break;
-    default:
+    case 16:
+        SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
+        break;
+    }
+}
+
+static void
+handle_1000(struct bregs *regs)
+{
+    u8 noclearmem = regs->al & 0x80;
+    u8 mode = regs->al & 0x7f;
+
+    // Set regs->al
+    if (mode > 7)
         regs->al = 0x20;
+    else if (mode == 6)
+        regs->al = 0x3f;
+    else
+        regs->al = 0x30;
+
+    if (CONFIG_VGA_CIRRUS) {
+        int ret = cirrus_set_video_mode(mode, noclearmem);
+        if (ret)
+            return;
     }
+
+    if (vbe_enabled())
+        vbe_hires_enable(0);
+
+    vga_set_mode(mode, noclearmem);
 }
 
 static void
 handle_1001(struct bregs *regs)
 {
-    biosfn_set_cursor_shape(regs->ch, regs->cl);
+    set_cursor_shape(regs->ch, regs->cl);
 }
 
 static void
 handle_1002(struct bregs *regs)
 {
-    biosfn_set_cursor_pos(regs->bh, regs->dx);
+    struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
+    set_cursor_pos(cp);
 }
 
 static void
 handle_1003(struct bregs *regs)
 {
-    regs->cx = biosfn_get_cursor_shape(regs->bh);
-    regs->dx = biosfn_get_cursor_pos(regs->bh);
+    regs->cx = get_cursor_shape(regs->bh);
+    struct cursorpos cp = get_cursor_pos(regs->bh);
+    regs->dl = cp.x;
+    regs->dh = cp.y;
 }
 
 // Read light pen pos (unimplemented)
@@ -536,42 +517,75 @@ handle_1004(struct bregs *regs)
 static void
 handle_1005(struct bregs *regs)
 {
-    biosfn_set_active_page(regs->al);
+    set_active_page(regs->al);
+}
+
+static void
+verify_scroll(struct bregs *regs, int dir)
+{
+    u8 page = GET_BDA(video_page);
+    struct cursorpos ul = {regs->cl, regs->ch, page};
+    struct cursorpos lr = {regs->dl, regs->dh, page};
+
+    u16 nbrows = GET_BDA(video_rows) + 1;
+    if (lr.y >= nbrows)
+        lr.y = nbrows - 1;
+    u16 nbcols = GET_BDA(video_cols);
+    if (lr.x >= nbcols)
+        lr.x = nbcols - 1;
+
+    if (ul.x > lr.x || ul.y > lr.y)
+        return;
+
+    u16 nblines = regs->al;
+    if (!nblines || nblines > lr.y - ul.y + 1)
+        nblines = lr.y - ul.y + 1;
+
+    vgafb_scroll(dir * nblines, regs->bh, ul, lr);
 }
 
 static void
 handle_1006(struct bregs *regs)
 {
-    biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
-                  , 0xFF, SCROLL_UP);
+    verify_scroll(regs, 1);
 }
 
 static void
 handle_1007(struct bregs *regs)
 {
-    biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
-                  , 0xFF, SCROLL_DOWN);
+    verify_scroll(regs, -1);
 }
 
 static void
 handle_1008(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_read_char_attr(regs->bh, &regs->ax);
+    struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
+    regs->al = ca.car;
+    regs->ah = ca.attr;
+}
+
+static void noinline
+write_chars(u8 page, struct carattr ca, u16 count)
+{
+    struct cursorpos cp = get_cursor_pos(page);
+    while (count--) {
+        vgafb_write_char(cp, ca);
+        cp.x++;
+    }
 }
 
 static void
 handle_1009(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_write_char_attr(regs->al, regs->bh, regs->bl, regs->cx);
+    struct carattr ca = {regs->al, regs->bl, 1};
+    write_chars(regs->bh, ca, regs->cx);
 }
 
 static void
 handle_100a(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_write_char_only(regs->al, regs->bh, regs->bl, regs->cx);
+    struct carattr ca = {regs->al, regs->bl, 0};
+    write_chars(regs->bh, ca, regs->cx);
 }
 
 
@@ -607,23 +621,26 @@ handle_100b(struct bregs *regs)
 static void
 handle_100c(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
+    // XXX - page (regs->bh) is unused
+    vgafb_write_pixel(regs->al, regs->cx, regs->dx);
 }
 
 static void
 handle_100d(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
+    // XXX - page (regs->bh) is unused
+    regs->al = vgafb_read_pixel(regs->cx, regs->dx);
 }
 
-static void
+static void noinline
 handle_100e(struct bregs *regs)
 {
     // Ralf Brown Interrupt list is WRONG on bh(page)
     // We do output only on the current page !
-    biosfn_write_teletype(regs->al, 0xff, regs->bl, NO_ATTR);
+    struct carattr ca = {regs->al, regs->bl, 0};
+    struct cursorpos cp = get_cursor_pos(0xff);
+    write_teletype(&cp, ca);
+    set_cursor_pos(cp);
 }
 
 static void
@@ -672,7 +689,7 @@ handle_101007(struct bregs *regs)
 static void
 handle_101008(struct bregs *regs)
 {
-    regs->bh = vgahw_get_overscan_border_color(regs);
+    regs->bh = vgahw_get_overscan_border_color();
 }
 
 static void
@@ -681,7 +698,7 @@ handle_101009(struct bregs *regs)
     vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
 }
 
-static void
+static void noinline
 handle_101010(struct bregs *regs)
 {
     u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
@@ -700,7 +717,7 @@ handle_101013(struct bregs *regs)
     vgahw_select_video_dac_color_page(regs->bl, regs->bh);
 }
 
-static void
+static void noinline
 handle_101015(struct bregs *regs)
 {
     u8 rgb[3];
@@ -737,7 +754,7 @@ handle_10101a(struct bregs *regs)
 static void
 handle_10101b(struct bregs *regs)
 {
-    biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
+    perform_gray_scale_summing(regs->bx, regs->cx);
 }
 
 static void
@@ -774,20 +791,20 @@ handle_1010(struct bregs *regs)
 static void
 handle_101100(struct bregs *regs)
 {
-    biosfn_load_text_user_pat(regs->es, regs->bp
-                              , regs->cx, regs->dx, regs->bl, regs->bh);
+    vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
+                    , regs->dx, regs->bl, regs->bh);
 }
 
 static void
 handle_101101(struct bregs *regs)
 {
-    biosfn_load_text_8_14_pat(regs->bl);
+    vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
 }
 
 static void
 handle_101102(struct bregs *regs)
 {
-    biosfn_load_text_8_8_pat(regs->bl);
+    vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
 }
 
 static void
@@ -799,35 +816,35 @@ handle_101103(struct bregs *regs)
 static void
 handle_101104(struct bregs *regs)
 {
-    biosfn_load_text_8_16_pat(regs->bl);
+    vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
 }
 
 static void
 handle_101110(struct bregs *regs)
 {
-    biosfn_load_text_user_pat(regs->es, regs->bp
-                              , regs->cx, regs->dx, regs->bl, regs->bh);
+    vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
+                    , regs->dx, regs->bl, regs->bh);
     set_scan_lines(regs->bh);
 }
 
 static void
 handle_101111(struct bregs *regs)
 {
-    biosfn_load_text_8_14_pat(regs->bl);
+    vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
     set_scan_lines(14);
 }
 
 static void
 handle_101112(struct bregs *regs)
 {
-    biosfn_load_text_8_8_pat(regs->bl);
+    vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
     set_scan_lines(8);
 }
 
 static void
 handle_101114(struct bregs *regs)
 {
-    biosfn_load_text_8_16_pat(regs->bl);
+    vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
     set_scan_lines(16);
 }
 
@@ -836,15 +853,15 @@ handle_101130(struct bregs *regs)
 {
     switch (regs->bh) {
     case 0x00: {
-        u32 segoff = GET_IVT(0x1f).segoff;
-        regs->es = segoff >> 16;
-        regs->bp = segoff;
+        struct segoff_s so = GET_IVT(0x1f);
+        regs->es = so.seg;
+        regs->bp = so.offset;
         break;
     }
     case 0x01: {
-        u32 segoff = GET_IVT(0x43).segoff;
-        regs->es = segoff >> 16;
-        regs->bp = segoff;
+        struct segoff_s so = GET_IVT(0x43);
+        regs->es = so.seg;
+        regs->bp = so.offset;
         break;
     }
     case 0x02:
@@ -1021,12 +1038,22 @@ handle_1012(struct bregs *regs)
 }
 
 
-static void
+// Write string
+static void noinline
 handle_1013(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_write_string(regs->al, regs->bh, regs->bl, regs->cx
-                        , regs->dh, regs->dl, regs->es, (void*)(regs->bp + 0));
+    struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
+    // if row=0xff special case : use current cursor position
+    if (cp.y == 0xff)
+        cp = get_cursor_pos(cp.page);
+    u8 flag = regs->al;
+    if (flag & 2)
+        write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
+    else
+        write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
+
+    if (flag & 1)
+        set_cursor_pos(cp);
 }
 
 
@@ -1063,8 +1090,7 @@ handle_101a(struct bregs *regs)
 
 
 struct funcInfo {
-    u16 static_functionality_off;
-    u16 static_functionality_seg;
+    struct segoff_s static_functionality;
     u8 bda_0x49[30];
     u8 bda_0x84[3];
     u8 dcc_index;
@@ -1090,12 +1116,14 @@ handle_101b(struct bregs *regs)
     struct funcInfo *info = (void*)(regs->di+0);
     memset_far(seg, info, 0, sizeof(*info));
     // Address of static functionality table
-    SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
-    SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
+    SET_FARVAR(seg, info->static_functionality
+               , SEGOFF(get_global_seg(), (u32)static_functionality));
 
     // Hard coded copy from BIOS area. Should it be cleaner ?
-    memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
-    memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
+    memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
+               , sizeof(info->bda_0x49));
+    memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
+               , sizeof(info->bda_0x84));
 
     SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
     SET_FARVAR(seg, info->colors, 16);
@@ -1132,7 +1160,7 @@ handle_101c01(struct bregs *regs)
         data += sizeof(struct saveVideoHardware);
     }
     if (flags & 2) {
-        biosfn_save_bda_state(seg, data);
+        save_bda_state(seg, data);
         data += sizeof(struct saveBDAstate);
     }
     if (flags & 4)
@@ -1151,7 +1179,7 @@ handle_101c02(struct bregs *regs)
         data += sizeof(struct saveVideoHardware);
     }
     if (flags & 2) {
-        biosfn_restore_bda_state(seg, data);
+        restore_bda_state(seg, data);
         data += sizeof(struct saveBDAstate);
     }
     if (flags & 4)
@@ -1176,72 +1204,261 @@ handle_101c(struct bregs *regs)
     }
 }
 
-
 static void
 handle_104f00(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
-    // XXX - OR cirrus_vesa_00h
+    u16 seg = regs->es;
+    struct vbe_info *info = (void*)(regs->di+0);
+
+    if (GET_FARVAR(seg, info->signature) == VBE2_SIGNATURE) {
+        dprintf(4, "Get VBE Controller: VBE2 Signature found\n");
+    } else if (GET_FARVAR(seg, info->signature) == VESA_SIGNATURE) {
+        dprintf(4, "Get VBE Controller: VESA Signature found\n");
+    } else {
+        dprintf(4, "Get VBE Controller: Invalid Signature\n");
+    }
+
+    memset_far(seg, info, 0, sizeof(*info));
+
+    SET_FARVAR(seg, info->signature, VESA_SIGNATURE);
+
+    SET_FARVAR(seg, info->version, 0x0200);
+
+    SET_FARVAR(seg, info->oem_string,
+            SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING));
+    SET_FARVAR(seg, info->capabilities[0], 0x1); /* 8BIT DAC */
+
+    /* We generate our mode list in the reserved field of the info block */
+    SET_FARVAR(seg, info->video_mode, SEGOFF(seg, regs->di + 34));
+
+    /* Total memory (in 64 blocks) */
+    SET_FARVAR(seg, info->total_memory, vbe_total_mem());
+
+    SET_FARVAR(seg, info->oem_vendor_string,
+            SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING));
+    SET_FARVAR(seg, info->oem_product_string,
+            SEGOFF(get_global_seg(), (u32)VBE_PRODUCT_STRING));
+    SET_FARVAR(seg, info->oem_revision_string,
+            SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING));
+
+    /* Fill list of modes */
+    vbe_list_modes(seg, regs->di + 32);
+
+    regs->al = regs->ah; /* 0x4F, Function supported */
+    regs->ah = 0x0; /* 0x0, Function call successful */
 }
 
 static void
 handle_104f01(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
-    // XXX - OR cirrus_vesa_01h
+    u16 seg = regs->es;
+    struct vbe_mode_info *info = (void*)(regs->di+0);
+    u16 mode = regs->cx;
+    struct vbe_modeinfo modeinfo;
+    int rc;
+
+    dprintf(1, "VBE mode info request: %x\n", mode);
+
+    rc = vbe_mode_info(mode, &modeinfo);
+    if (rc) {
+        dprintf(1, "VBE mode %x not found\n", mode);
+        regs->ax = 0x100;
+        return;
+    }
+
+    u16 mode_attr = VBE_MODE_ATTRIBUTE_SUPPORTED |
+                    VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE |
+                    VBE_MODE_ATTRIBUTE_COLOR_MODE |
+                    VBE_MODE_ATTRIBUTE_GRAPHICS_MODE;
+    if (modeinfo.depth == 4)
+        mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT;
+    else
+        mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE;
+    SET_FARVAR(seg, info->mode_attributes, mode_attr);
+    SET_FARVAR(seg, info->winA_attributes,
+               VBE_WINDOW_ATTRIBUTE_RELOCATABLE |
+               VBE_WINDOW_ATTRIBUTE_READABLE |
+               VBE_WINDOW_ATTRIBUTE_WRITEABLE);
+    SET_FARVAR(seg, info->winB_attributes, 0);
+    SET_FARVAR(seg, info->win_granularity, 64); /* Bank size 64K */
+    SET_FARVAR(seg, info->win_size, 64); /* Bank size 64K */
+    SET_FARVAR(seg, info->winA_seg, 0xA000);
+    SET_FARVAR(seg, info->winB_seg, 0x0);
+    SET_FARVAR(seg, info->win_func_ptr, 0x0);
+    SET_FARVAR(seg, info->bytes_per_scanline, modeinfo.linesize);
+    SET_FARVAR(seg, info->xres, modeinfo.width);
+    SET_FARVAR(seg, info->yres, modeinfo.height);
+    SET_FARVAR(seg, info->xcharsize, 8);
+    SET_FARVAR(seg, info->ycharsize, 16);
+    if (modeinfo.depth == 4)
+        SET_FARVAR(seg, info->planes, 4);
+    else
+        SET_FARVAR(seg, info->planes, 1);
+    SET_FARVAR(seg, info->bits_per_pixel, modeinfo.depth);
+    SET_FARVAR(seg, info->banks,
+            (modeinfo.linesize * modeinfo.height + 65535) / 65536);
+    if (modeinfo.depth == 4)
+        SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PLANAR);
+    else if (modeinfo.depth == 8)
+        SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PACKED_PIXEL);
+    else
+        SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_DIRECT_COLOR);
+    SET_FARVAR(seg, info->bank_size, 0);
+    u32 pages = modeinfo.vram_size / (modeinfo.height * modeinfo.linesize);
+    if (modeinfo.depth == 4)
+        SET_FARVAR(seg, info->pages, (pages / 4) - 1);
+    else
+        SET_FARVAR(seg, info->pages, pages - 1);
+    SET_FARVAR(seg, info->reserved0, 1);
+
+    u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
+
+    switch (modeinfo.depth) {
+    case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5;
+             b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break;
+    case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5;
+             b_size = 5; b_pos = 0; a_size = 0; a_pos = 0; break;
+    case 24: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
+             b_size = 8; b_pos = 0; a_size = 0; a_pos = 0; break;
+    case 32: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
+             b_size = 8; b_pos = 0; a_size = 8; a_pos = 24; break;
+    default: r_size = 0; r_pos = 0; g_size = 0; g_pos = 0;
+             b_size = 0; b_pos = 0; a_size = 0; a_pos = 0; break;
+    }
+
+    SET_FARVAR(seg, info->red_size, r_size);
+    SET_FARVAR(seg, info->red_pos, r_pos);
+    SET_FARVAR(seg, info->green_size, g_size);
+    SET_FARVAR(seg, info->green_pos, g_pos);
+    SET_FARVAR(seg, info->blue_size, b_size);
+    SET_FARVAR(seg, info->blue_pos, b_pos);
+    SET_FARVAR(seg, info->alpha_size, a_size);
+    SET_FARVAR(seg, info->alpha_pos, a_pos);
+
+    if (modeinfo.depth == 32)
+        SET_FARVAR(seg, info->directcolor_info,
+                   VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE);
+    else
+        SET_FARVAR(seg, info->directcolor_info, 0);
+
+    if (modeinfo.depth > 4)
+        SET_FARVAR(seg, info->phys_base, modeinfo.phys_base);
+    else
+        SET_FARVAR(seg, info->phys_base, 0);
+
+    SET_FARVAR(seg, info->reserved1, 0);
+    SET_FARVAR(seg, info->reserved2, 0);
+    SET_FARVAR(seg, info->linear_bytes_per_scanline, modeinfo.linesize);
+    SET_FARVAR(seg, info->bank_pages, 0);
+    SET_FARVAR(seg, info->linear_pages, 0);
+    SET_FARVAR(seg, info->linear_red_size, r_size);
+    SET_FARVAR(seg, info->linear_red_pos, r_pos);
+    SET_FARVAR(seg, info->linear_green_size, g_size);
+    SET_FARVAR(seg, info->linear_green_pos, g_pos);
+    SET_FARVAR(seg, info->linear_blue_size, b_size);
+    SET_FARVAR(seg, info->linear_blue_pos, b_pos);
+    SET_FARVAR(seg, info->linear_alpha_size, a_size);
+    SET_FARVAR(seg, info->linear_alpha_pos, a_pos);
+    SET_FARVAR(seg, info->pixclock_max, 0);
+
+    regs->al = regs->ah; /* 0x4F, Function supported */
+    regs->ah = 0x0; /* 0x0, Function call successful */
 }
 
 static void
 handle_104f02(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
-    // XXX - OR cirrus_vesa_02h
+    //u16 seg = regs->es;
+    //struct vbe_crtc_info *crtc_info = (void*)(regs->di+0);
+    u16 mode = regs->bx;
+    struct vbe_modeinfo modeinfo;
+    int rc;
+
+    dprintf(1, "VBE mode set: %x\n", mode);
+
+    if (mode < 0x100) { /* VGA */
+        dprintf(1, "set VGA mode %x\n", mode);
+
+        vbe_hires_enable(0);
+        vga_set_mode(mode, 0);
+    } else { /* VBE */
+        rc = vbe_mode_info(mode & 0x1ff, &modeinfo);
+        if (rc) {
+            dprintf(1, "VBE mode %x not found\n", mode & 0x1ff);
+            regs->ax = 0x100;
+            return;
+        }
+        vbe_hires_enable(1);
+        vbe_set_mode(mode & 0x1ff, &modeinfo);
+
+        if (mode & 0x4000) {
+            /* Linear frame buffer */
+            /* XXX: ??? */
+        }
+        if (!(mode & 0x8000)) {
+            vbe_clear_scr();
+        }
+    }
+
+    regs->al = regs->ah; /* 0x4F, Function supported */
+    regs->ah = 0x0; /* 0x0, Function call successful */
 }
 
 static void
 handle_104f03(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_return_current_mode
-    // XXX - OR cirrus_vesa_03h
+    if (!vbe_hires_enabled()) {
+        regs->bx = GET_BDA(video_mode);
+    } else {
+        regs->bx = vbe_curr_mode();
+    }
+
+    dprintf(1, "VBE current mode=%x\n", regs->bx);
+
+    regs->al = regs->ah; /* 0x4F, Function supported */
+    regs->ah = 0x0; /* 0x0, Function call successful */
 }
 
 static void
 handle_104f04(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
+    debug_enter(regs, DEBUG_VGA_10);
+    regs->ax = 0x0100;
 }
 
 static void
 handle_104f05(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_display_window_control
-    // XXX - OR cirrus_vesa_05h
+    debug_enter(regs, DEBUG_VGA_10);
+    regs->ax = 0x0100;
 }
 
 static void
 handle_104f06(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_set_get_logical_scan_line_length
-    // XXX - OR cirrus_vesa_06h
+    debug_enter(regs, DEBUG_VGA_10);
+    regs->ax = 0x0100;
 }
 
 static void
 handle_104f07(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_set_get_display_start
-    // XXX - OR cirrus_vesa_07h
+    debug_enter(regs, DEBUG_VGA_10);
+    regs->ax = 0x0100;
 }
 
 static void
 handle_104f08(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_set_get_dac_palette_format
+    debug_enter(regs, DEBUG_VGA_10);
+    regs->ax = 0x0100;
 }
 
 static void
 handle_104f0a(struct bregs *regs)
 {
-    // XXX - vbe_biosfn_return_protected_mode_interface
+    debug_enter(regs, DEBUG_VGA_10);
+    regs->ax = 0x0100;
 }
 
 static void
@@ -1254,7 +1471,7 @@ handle_104fXX(struct bregs *regs)
 static void
 handle_104f(struct bregs *regs)
 {
-    if (! CONFIG_VBE || !vbe_has_vbe_display()) {
+    if (!vbe_enabled()) {
         handle_104fXX(regs);
         return;
     }
@@ -1321,7 +1538,7 @@ handle_10(struct bregs *regs)
  ****************************************************************/
 
 static void
-init_bios_area()
+init_bios_area(void)
 {
     // init detected hardware BIOS Area
     // set 80x25 color (not clear from RBIL but usual)
@@ -1353,22 +1570,22 @@ vga_post(struct bregs *regs)
 
     vgahw_init();
 
+    if (CONFIG_VGA_GEODELX)
+        geodelx_init();
+
     init_bios_area();
 
-    if (CONFIG_VBE)
-        vbe_init();
+    vbe_init(regs->ah, regs->al);
 
     extern void entry_10(void);
-    SET_IVT(0x10, get_global_seg(), (u32)entry_10);
+    SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
 
-    if (CONFIG_CIRRUS)
+    if (CONFIG_VGA_CIRRUS)
         cirrus_init();
 
     // XXX - clear screen and display info
 
-    // XXX: fill it
-    SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
-    SET_VGA(video_save_pointer_table[1], get_global_seg());
+    build_video_param();
 
     // Fixup checksum
     extern u8 _rom_header_size, _rom_header_checksum;