return 0;
}
+int
+bochsvga_get_linelength(struct vgamode_s *vmode_g)
+{
+ return dispi_read(VBE_DISPI_INDEX_VIRT_WIDTH) * vga_bpp(vmode_g) / 8;
+}
+
+int
+bochsvga_set_linelength(struct vgamode_s *vmode_g, int val)
+{
+ stdvga_set_linelength(vmode_g, val);
+ int pixels = (val * 8) / vga_bpp(vmode_g);
+ dispi_write(VBE_DISPI_INDEX_VIRT_WIDTH, pixels);
+ return 0;
+}
+
static void
bochsvga_clear_scr(void)
{
struct vgamode_s *bochsvga_find_mode(int mode);
int bochsvga_get_window(struct vgamode_s *vmode_g, int window);
int bochsvga_set_window(struct vgamode_s *vmode_g, int window, int val);
+int bochsvga_get_linelength(struct vgamode_s *vmode_g);
+int bochsvga_set_linelength(struct vgamode_s *vmode_g, int val);
int bochsvga_set_mode(struct vgamode_s *vmode_g, int flags);
#endif // bochsvga.h
return 0;
}
+int
+clext_get_linelength(struct vgamode_s *vmode_g)
+{
+ u16 crtc_addr = stdvga_get_crtc();
+ u8 reg13 = stdvga_crtc_read(crtc_addr, 0x13);
+ u8 reg1b = stdvga_crtc_read(crtc_addr, 0x1b);
+ return (((reg1b & 0x10) << 4) + reg13) * stdvga_bpp_factor(vmode_g) * 2;
+}
+
+int
+clext_set_linelength(struct vgamode_s *vmode_g, int val)
+{
+ u16 crtc_addr = stdvga_get_crtc();
+ int factor = stdvga_bpp_factor(vmode_g) * 2;
+ int new_line_offset = DIV_ROUND_UP(val, factor);
+ stdvga_crtc_write(crtc_addr, 0x13, new_line_offset);
+ stdvga_crtc_mask(crtc_addr, 0x1b, 0x10, (new_line_offset & 0x100) >> 4);
+ return 0;
+}
+
static void
cirrus_enable_16k_granularity(void)
{
return v;
}
-static void
-cirrus_set_line_offset(u16 new_line_offset)
-{
- new_line_offset /= 8;
- u16 crtc_addr = stdvga_get_crtc();
- stdvga_crtc_write(crtc_addr, 0x13, new_line_offset);
- stdvga_crtc_mask(crtc_addr, 0x1b, 0x10, (new_line_offset & 0x100) >> 4);
-}
-
static u16
cirrus_get_line_offset(void)
{
| ((b4 & 0x80) << 12));
}
-static void
-cirrus_vesa_06h(struct bregs *regs)
-{
- if (regs->bl > 2) {
- regs->ax = 0x0100;
- return;
- }
-
- if (regs->bl == 0x00) {
- cirrus_set_line_offset(cirrus_get_bpp_bytes() * regs->cx);
- } else if (regs->bl == 0x02) {
- cirrus_set_line_offset(regs->cx);
- }
-
- u32 v = cirrus_get_line_offset();
- regs->cx = v / cirrus_get_bpp_bytes();
- regs->bx = v;
- regs->dx = GET_GLOBAL(VBE_total_memory) / v;
- regs->ax = 0x004f;
-}
-
static void
cirrus_vesa_07h(struct bregs *regs)
{
cirrus_vesa(struct bregs *regs)
{
switch (regs->al) {
- case 0x06: cirrus_vesa_06h(regs); break;
case 0x07: cirrus_vesa_07h(regs); break;
case 0x10: cirrus_vesa_10h(regs); break;
default: cirrus_vesa_not_handled(regs); break;
struct vgamode_s *clext_find_mode(int mode);
int clext_get_window(struct vgamode_s *vmode_g, int window);
int clext_set_window(struct vgamode_s *vmode_g, int window, int val);
+int clext_get_linelength(struct vgamode_s *vmode_g);
+int clext_set_linelength(struct vgamode_s *vmode_g, int val);
int clext_set_mode(struct vgamode_s *vmode_g, int flags);
void clext_list_modes(u16 seg, u16 *dest, u16 *last);
int clext_init(void);
return VGAREG_MDA_CRTC_ADDRESS;
}
+// Return the multiplication factor needed for the vga offset register.
+int
+stdvga_bpp_factor(struct vgamode_s *vmode_g)
+{
+ switch (GET_GLOBAL(vmode_g->memmodel)) {
+ case MM_TEXT:
+ return 2;
+ case MM_CGA:
+ return GET_GLOBAL(vmode_g->depth);
+ case MM_PLANAR:
+ return 1;
+ default:
+ return 4;
+ }
+}
+
void
stdvga_set_cursor_shape(u8 start, u8 end)
{
return -1;
}
+int
+stdvga_get_linelength(struct vgamode_s *vmode_g)
+{
+ u8 val = stdvga_crtc_read(stdvga_get_crtc(), 0x13);
+ return val * stdvga_bpp_factor(vmode_g) * 2;
+}
+
+int
+stdvga_set_linelength(struct vgamode_s *vmode_g, int val)
+{
+ int factor = stdvga_bpp_factor(vmode_g) * 2;
+ stdvga_crtc_write(stdvga_get_crtc(), 0x13, DIV_ROUND_UP(val, factor));
+ return 0;
+}
+
/****************************************************************
* Save/Restore/Set state
void stdvga_load_font(u16 seg, void *src_far, u16 count
, u16 start, u8 destflags, u8 fontsize);
u16 stdvga_get_crtc(void);
+int stdvga_bpp_factor(struct vgamode_s *vmode_g);
void stdvga_set_cursor_shape(u8 start, u8 end);
void stdvga_set_active_page(u16 address);
void stdvga_set_cursor_pos(u16 address);
u16 stdvga_get_vde(void);
int stdvga_get_window(struct vgamode_s *vmode_g, int window);
int stdvga_set_window(struct vgamode_s *vmode_g, int window, int val);
+int stdvga_get_linelength(struct vgamode_s *vmode_g);
+int stdvga_set_linelength(struct vgamode_s *vmode_g, int val);
void stdvga_save_state(u16 seg, struct saveVideoHardware *info);
void stdvga_restore_state(u16 seg, struct saveVideoHardware *info);
int stdvga_set_mode(struct vgamode_s *vmode_g, int flags);
static void
vbe_104f06(struct bregs *regs)
{
- debug_stub(regs);
- regs->ax = 0x0100;
+ if (regs->bl > 0x02)
+ goto fail;
+ struct vgamode_s *vmode_g = get_current_mode();
+ if (! vmode_g)
+ goto fail;
+ int bpp = vga_bpp(vmode_g);
+
+ if (regs->bl == 0x00) {
+ int ret = vgahw_set_linelength(vmode_g, DIV_ROUND_UP(regs->cx * bpp, 8));
+ if (ret)
+ goto fail;
+ } else if (regs->bl == 0x02) {
+ int ret = vgahw_set_linelength(vmode_g, regs->cx);
+ if (ret)
+ goto fail;
+ }
+ int linelength = vgahw_get_linelength(vmode_g);
+ if (linelength < 0)
+ goto fail;
+
+ regs->bx = linelength;
+ regs->cx = (linelength * 8) / bpp;
+ regs->dx = GET_GLOBAL(VBE_total_memory) / linelength;
+ regs->ax = 0x004f;
+ return;
+fail:
+ regs->ax = 0x014f;
}
static void
* Helper functions
****************************************************************/
+// Return the bits per pixel in system memory for a given mode.
+int
+vga_bpp(struct vgamode_s *vmode_g)
+{
+ switch (GET_GLOBAL(vmode_g->memmodel)) {
+ case MM_TEXT:
+ return 16;
+ case MM_PLANAR:
+ return 1;
+ }
+ u8 depth = GET_GLOBAL(vmode_g->depth);
+ if (depth > 8)
+ return ALIGN(depth, 8);
+ return depth;
+}
+
u16
calc_page_size(u8 memmodel, u16 width, u16 height)
{
struct cursorpos {
u8 x, y, page;
};
+int vga_bpp(struct vgamode_s *vmode_g);
u16 calc_page_size(u8 memmodel, u16 width, u16 height);
struct vgamode_s *get_current_mode(void);
int vga_set_mode(int mode, int flags);
return stdvga_set_window(vmode_g, window, val);
}
+static inline int vgahw_get_linelength(struct vgamode_s *vmode_g) {
+ if (CONFIG_VGA_CIRRUS)
+ return clext_get_linelength(vmode_g);
+ if (CONFIG_VGA_BOCHS)
+ return bochsvga_get_linelength(vmode_g);
+ return stdvga_get_linelength(vmode_g);
+}
+
+static inline int vgahw_set_linelength(struct vgamode_s *vmode_g, int val) {
+ if (CONFIG_VGA_CIRRUS)
+ return clext_set_linelength(vmode_g, val);
+ if (CONFIG_VGA_BOCHS)
+ return bochsvga_set_linelength(vmode_g, val);
+ return stdvga_set_linelength(vmode_g, val);
+}
+
#endif // vgahw.h