This series adds comments to vgasrc/stdvga.c along with some variable and function renaming. The goal is to make it a little easier to understand this legacy code.
There should be no functionality changes with this patch series.
-Kevin
Kevin O'Connor (9): stdvgamodes: No need to store pelmask in vga_modes[] stdvgamodes: Improve naming of dac palette tables stdvga: Rename CGA palette functions stdvga: Add comments to interface functions in stdvga.c stdvga: Rename stdvga_toggle_intensity() to stdvga_set_palette_blinking() stdvga: Rework stdvga palette index paging interface functions stdvga: Rename stdvga_set_text_block_specifier() to stdvga_set_font_location() stdvga: Rename stdvga_set_scan_lines() to stdvga_set_character_height() stdvga: Rename stdvga_get_vde() to stdvga_get_vertical_size()
vgasrc/stdvga.c | 103 ++++++++++++++++++++++++++++--------------- vgasrc/stdvga.h | 17 +++---- vgasrc/stdvgamodes.c | 95 +++++++++++++++++++++------------------ vgasrc/vgabios.c | 31 +++++++------ 4 files changed, 144 insertions(+), 102 deletions(-)
The pelmask is always 0xff so no need to store in a static table.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvgamodes.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/vgasrc/stdvgamodes.c b/vgasrc/stdvgamodes.c index 3e6b575..ed1d983 100644 --- a/vgasrc/stdvgamodes.c +++ b/vgasrc/stdvgamodes.c @@ -263,7 +263,6 @@ struct stdvga_mode_s { u16 mode; struct vgamode_s info;
- u8 pelmask; u8 *dac; u16 dacsize; u8 *sequ_regs; @@ -275,39 +274,39 @@ struct stdvga_mode_s {
static struct stdvga_mode_s vga_modes[] VAR16 = { //mode { model tx ty bpp cw ch sstart } - // pelm dac sequ misc crtc actl grdc + // dac sequ misc crtc actl grdc {0x00, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT } - , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01}, + , PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01}, {0x01, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT } - , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01}, + , PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01}, {0x02, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT } - , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01}, + , PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01}, {0x03, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT } - , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01}, + , PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01}, {0x04, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT } - , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04}, + , PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04}, {0x05, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT } - , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04}, + , PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04}, {0x06, { MM_CGA, 640, 200, 1, 8, 8, SEG_CTEXT } - , 0xFF, PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06}, + , PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06}, {0x07, { MM_TEXT, 80, 25, 4, 9, 16, SEG_MTEXT } - , 0xFF, PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07}, + , PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07}, {0x0D, { MM_PLANAR, 320, 200, 4, 8, 8, SEG_GRAPH } - , 0xFF, PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d}, + , PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d}, {0x0E, { MM_PLANAR, 640, 200, 4, 8, 8, SEG_GRAPH } - , 0xFF, PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d}, + , PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d}, {0x0F, { MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH } - , 0xFF, PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d}, + , PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d}, {0x10, { MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH } - , 0xFF, PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d}, + , PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d}, {0x11, { MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH } - , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d}, + , PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d}, {0x12, { MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH } - , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d}, + , PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d}, {0x13, { MM_PACKED, 320, 200, 8, 8, 8, SEG_GRAPH } - , 0xFF, PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13}, + , PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13}, {0x6A, { MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH } - , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d}, + , PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d}, };
@@ -457,7 +456,7 @@ stdvga_set_mode(struct vgamode_s *vmode_g, int flags)
// if palette loading (bit 3 of modeset ctl = 0) if (!(flags & MF_NOPALETTE)) { // Set the PEL mask - stdvga_pelmask_write(GET_GLOBAL(stdmode_g->pelmask)); + stdvga_pelmask_write(0xff);
// From which palette u8 *palette_g = GET_GLOBAL(stdmode_g->dac);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvgamodes.c | 92 ++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 42 deletions(-)
diff --git a/vgasrc/stdvgamodes.c b/vgasrc/stdvgamodes.c index ed1d983..c1d9722 100644 --- a/vgasrc/stdvgamodes.c +++ b/vgasrc/stdvgamodes.c @@ -15,11 +15,11 @@
/**************************************************************** - * Video mode register definitions + * Default color palettes (stored in DAC registers) ****************************************************************/
-/* Mono */ -static u8 palette0[] VAR16 = { +// 4 grey palette used for MDA card compatibility +static u8 pal_mda[] VAR16 = { 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, @@ -38,7 +38,8 @@ static u8 palette0[] VAR16 = { 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f };
-static u8 palette1[] VAR16 = { +// 16 colors used for CGA mode compatibility +static u8 pal_cga[] VAR16 = { 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a, 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a, 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a, @@ -57,7 +58,8 @@ static u8 palette1[] VAR16 = { 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f };
-static u8 palette2[] VAR16 = { +// 64 colors used for EGA mode compatibility +static u8 pal_ega[] VAR16 = { 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a, 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x2a,0x00, 0x2a,0x2a,0x2a, 0x00,0x00,0x15, 0x00,0x00,0x3f, 0x00,0x2a,0x15, 0x00,0x2a,0x3f, @@ -76,7 +78,8 @@ static u8 palette2[] VAR16 = { 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f };
-static u8 palette3[] VAR16 = { +// Default 256 colors used in VGA "packed" mode +static u8 pal_vga[] VAR16 = { 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a, 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a, 0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f, @@ -146,6 +149,11 @@ static u8 palette3[] VAR16 = { 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00 };
+ +/**************************************************************** + * Video mode register definitions + ****************************************************************/ + static u8 sequ_01[] VAR16 = { 0x08, 0x03, 0x00, 0x02 }; static u8 crtc_01[] VAR16 = { 0x2d, 0x27, 0x28, 0x90, 0x2b, 0xa0, 0xbf, 0x1f, @@ -262,9 +270,9 @@ static u8 crtc_6A[] VAR16 = { struct stdvga_mode_s { u16 mode; struct vgamode_s info; - u8 *dac; u16 dacsize; + u8 *sequ_regs; u8 miscreg; u8 *crtc_regs; @@ -273,40 +281,40 @@ struct stdvga_mode_s { };
static struct stdvga_mode_s vga_modes[] VAR16 = { - //mode { model tx ty bpp cw ch sstart } - // dac sequ misc crtc actl grdc - {0x00, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT } - , PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01}, - {0x01, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT } - , PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01}, - {0x02, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT } - , PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01}, - {0x03, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT } - , PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01}, - {0x04, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT } - , PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04}, - {0x05, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT } - , PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04}, - {0x06, { MM_CGA, 640, 200, 1, 8, 8, SEG_CTEXT } - , PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06}, - {0x07, { MM_TEXT, 80, 25, 4, 9, 16, SEG_MTEXT } - , PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07}, - {0x0D, { MM_PLANAR, 320, 200, 4, 8, 8, SEG_GRAPH } - , PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d}, - {0x0E, { MM_PLANAR, 640, 200, 4, 8, 8, SEG_GRAPH } - , PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d}, - {0x0F, { MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH } - , PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d}, - {0x10, { MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH } - , PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d}, - {0x11, { MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH } - , PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d}, - {0x12, { MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH } - , PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d}, - {0x13, { MM_PACKED, 320, 200, 8, 8, 8, SEG_GRAPH } - , PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13}, - {0x6A, { MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH } - , PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d}, + //mode { model tx ty bpp cw ch sstart } dac + // sequ misc crtc actl grdc + {0x00, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT }, PAL(pal_ega) + , sequ_01, 0x67, crtc_01, actl_01, grdc_01}, + {0x01, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT }, PAL(pal_ega) + , sequ_01, 0x67, crtc_01, actl_01, grdc_01}, + {0x02, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT }, PAL(pal_ega) + , sequ_03, 0x67, crtc_03, actl_01, grdc_01}, + {0x03, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT }, PAL(pal_ega) + , sequ_03, 0x67, crtc_03, actl_01, grdc_01}, + {0x04, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT }, PAL(pal_cga) + , sequ_04, 0x63, crtc_04, actl_04, grdc_04}, + {0x05, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT }, PAL(pal_cga) + , sequ_04, 0x63, crtc_04, actl_04, grdc_04}, + {0x06, { MM_CGA, 640, 200, 1, 8, 8, SEG_CTEXT }, PAL(pal_cga) + , sequ_06, 0x63, crtc_06, actl_06, grdc_06}, + {0x07, { MM_TEXT, 80, 25, 4, 9, 16, SEG_MTEXT }, PAL(pal_mda) + , sequ_03, 0x66, crtc_07, actl_07, grdc_07}, + {0x0D, { MM_PLANAR, 320, 200, 4, 8, 8, SEG_GRAPH }, PAL(pal_cga) + , sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d}, + {0x0E, { MM_PLANAR, 640, 200, 4, 8, 8, SEG_GRAPH }, PAL(pal_cga) + , sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d}, + {0x0F, { MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH }, PAL(pal_mda) + , sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d}, + {0x10, { MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH }, PAL(pal_ega) + , sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d}, + {0x11, { MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH }, PAL(pal_ega) + , sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d}, + {0x12, { MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH }, PAL(pal_ega) + , sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d}, + {0x13, { MM_PACKED, 320, 200, 8, 8, 8, SEG_GRAPH }, PAL(pal_vga) + , sequ_13, 0x63, crtc_13, actl_13, grdc_13}, + {0x6A, { MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH }, PAL(pal_ega) + , sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d}, };
@@ -527,5 +535,5 @@ stdvga_set_mode(struct vgamode_s *vmode_g, int flags) void stdvga_set_packed_palette(void) { - stdvga_dac_write(get_global_seg(), palette3, 0, sizeof(palette3) / 3); + stdvga_dac_write(get_global_seg(), pal_vga, 0, sizeof(pal_vga) / 3); }
Rename stdvga_set_border_color() to stdvga_set_cga_background_color() and stdvga_set_palette() to stdvga_set_cga_palette(). These functions implement compatibility for old CGA cards - rename them so they are not confused with the functions that manipulte the VGA palette.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvga.c | 23 ++++++++++++++--------- vgasrc/stdvga.h | 4 ++-- vgasrc/vgabios.c | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index da67af4..eac0357 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -18,19 +18,32 @@ * Attribute control ****************************************************************/
+// Emulate CGA background setting via VGA palette index registers void -stdvga_set_border_color(u8 color) +stdvga_set_cga_background_color(u8 color) { + // Set the background color (via palette index 0) u8 v1 = color & 0x0f; if (v1 & 0x08) v1 += 0x08; stdvga_attr_write(0x00, v1);
+ // Dim/brighten foreground (see pal_cga[] in stdvgamodes.c) int i; for (i = 1; i < 4; i++) stdvga_attr_mask(i, 0x10, color & 0x10); }
+// Emulate CGA palette setting by altering VGA palette index registers +void +stdvga_set_cga_palette(u8 palid) +{ + // Switch foreground colors (see pal_cga[] in stdvgamodes.c) + int i; + for (i = 1; i < 4; i++) + stdvga_attr_mask(i, 0x01, palid & 0x01); +} + void stdvga_set_overscan_border_color(u8 color) { @@ -43,14 +56,6 @@ stdvga_get_overscan_border_color(void) return stdvga_attr_read(0x11); }
-void -stdvga_set_palette(u8 palid) -{ - int i; - for (i = 1; i < 4; i++) - stdvga_attr_mask(i, 0x01, palid & 0x01); -} - void stdvga_set_all_palette_reg(u16 seg, u8 *data_far) { diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index ce79783..a2375c7 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -45,10 +45,10 @@ #define SEG_MTEXT 0xB000
// stdvga.c -void stdvga_set_border_color(u8 color); +void stdvga_set_cga_background_color(u8 color); +void stdvga_set_cga_palette(u8 palid); void stdvga_set_overscan_border_color(u8 color); u8 stdvga_get_overscan_border_color(void); -void stdvga_set_palette(u8 palid); void stdvga_set_all_palette_reg(u16 seg, u8 *data_far); void stdvga_get_all_palette_reg(u16 seg, u8 *data_far); void stdvga_toggle_intensity(u8 flag); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 2ca8c3d..d522f83 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -457,13 +457,13 @@ handle_100a(struct bregs *regs) static void handle_100b00(struct bregs *regs) { - stdvga_set_border_color(regs->bl); + stdvga_set_cga_background_color(regs->bl); }
static void handle_100b01(struct bregs *regs) { - stdvga_set_palette(regs->bl); + stdvga_set_cga_palette(regs->bl); }
static void
On 1/4/24 17:51, Kevin O'Connor wrote:
Rename stdvga_set_border_color() to stdvga_set_cga_background_color() and stdvga_set_palette() to stdvga_set_cga_palette(). These functions implement compatibility for old CGA cards - rename them so they are not confused with the functions that manipulte the VGA palette.
Signed-off-by: Kevin O'Connor kevin@koconnor.net
vgasrc/stdvga.c | 23 ++++++++++++++--------- vgasrc/stdvga.h | 4 ++-- vgasrc/vgabios.c | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé philmd@linaro.org
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvga.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index eac0357..149c88a 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -1,6 +1,6 @@ // Standard VGA driver code // -// Copyright (C) 2009 Kevin O'Connor kevin@koconnor.net +// Copyright (C) 2009-2024 Kevin O'Connor kevin@koconnor.net // Copyright (C) 2001-2008 the LGPL VGABios developers Team // // This file may be distributed under the terms of the GNU LGPLv3 license. @@ -44,29 +44,35 @@ stdvga_set_cga_palette(u8 palid) stdvga_attr_mask(i, 0x01, palid & 0x01); }
+// Set the VGA palette index register for the "overscan" area void stdvga_set_overscan_border_color(u8 color) { stdvga_attr_write(0x11, color); }
+// Get the VGA palette index register for the "overscan" area u8 stdvga_get_overscan_border_color(void) { return stdvga_attr_read(0x11); }
+// Set the VGA palette index registers void stdvga_set_all_palette_reg(u16 seg, u8 *data_far) { + // Set palette indexes (offset into DAC colors) int i; for (i = 0; i < 0x10; i++) { stdvga_attr_write(i, GET_FARVAR(seg, *data_far)); data_far++; } + // Set "overscan" palette index (offset into DAC colors) stdvga_attr_write(0x11, GET_FARVAR(seg, *data_far)); }
+// Get the VGA palette index registers void stdvga_get_all_palette_reg(u16 seg, u8 *data_far) { @@ -78,6 +84,7 @@ stdvga_get_all_palette_reg(u16 seg, u8 *data_far) SET_FARVAR(seg, *data_far, stdvga_attr_read(0x11)); }
+// Set blinking mode (when enabled, palette index bit 0x08 indicates blinking) void stdvga_toggle_intensity(u8 flag) { @@ -116,6 +123,7 @@ stdvga_read_video_dac_state(u8 *pmode, u8 *curpage) * DAC control ****************************************************************/
+// Convert all loaded colors to shades of gray void stdvga_perform_gray_scale_summing(u16 start, u16 count) { @@ -141,6 +149,7 @@ stdvga_perform_gray_scale_summing(u16 start, u16 count) * Memory control ****************************************************************/
+// Set the video memory location of the start of character fonts void stdvga_set_text_block_specifier(u8 spec) { @@ -210,6 +219,7 @@ stdvga_load_font(u16 seg, void *src_far, u16 count * CRTC registers ****************************************************************/
+// Return the IO port used to access the CRTC register u16 stdvga_get_crtc(void) { @@ -234,6 +244,7 @@ stdvga_vram_ratio(struct vgamode_s *vmode_g) } }
+// Set cursor shape (when in text mode) void stdvga_set_cursor_shape(u16 cursor_type) { @@ -242,6 +253,7 @@ stdvga_set_cursor_shape(u16 cursor_type) stdvga_crtc_write(crtc_addr, 0x0b, cursor_type); }
+// Set the position of the text cursor (as offset into system framebuffer) void stdvga_set_cursor_pos(int address) { @@ -251,6 +263,7 @@ stdvga_set_cursor_pos(int address) stdvga_crtc_write(crtc_addr, 0x0f, address); }
+// Set the character height (when in text mode) void stdvga_set_scan_lines(u8 lines) { @@ -268,15 +281,19 @@ stdvga_get_vde(void) return vde; }
+// Get offset into framebuffer accessible from real-mode 64K segment int stdvga_get_window(struct vgamode_s *curmode_g, int window) { return -1; }
+// Set offset into framebuffer that is accessible from real-mode 64K +// segment (in units of VBE_win_granularity windows) int stdvga_set_window(struct vgamode_s *curmode_g, int window, int val) { + // Stdvga does not support changing window offset return -1; }
@@ -325,15 +342,18 @@ stdvga_set_displaystart(struct vgamode_s *curmode_g, int val) return 0; }
+// Report if using 8bit per rgb (24bit total) or 6bit per rgb (18bit total) int stdvga_get_dacformat(struct vgamode_s *curmode_g) { return -1; }
+// Set 8bit per rgb (24bit total) or 6bit per rgb (18bit total) int stdvga_set_dacformat(struct vgamode_s *curmode_g, int val) { + // Stdvga only supports 6bits for each color channel return -1; }
@@ -477,6 +497,7 @@ stdvga_save_restore(int cmd, u16 seg, void *data) * Misc ****************************************************************/
+// Enable/disable system access to the video memory void stdvga_enable_video_addressing(u8 disable) {
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvga.c | 4 ++-- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index 149c88a..63700d4 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -86,9 +86,9 @@ stdvga_get_all_palette_reg(u16 seg, u8 *data_far)
// Set blinking mode (when enabled, palette index bit 0x08 indicates blinking) void -stdvga_toggle_intensity(u8 flag) +stdvga_set_palette_blinking(u8 enable_blink) { - stdvga_attr_mask(0x10, 0x08, (flag & 0x01) << 3); + stdvga_attr_mask(0x10, 0x08, (enable_blink & 0x01) << 3); }
void diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index a2375c7..6ce6a90 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -51,7 +51,7 @@ void stdvga_set_overscan_border_color(u8 color); u8 stdvga_get_overscan_border_color(void); void stdvga_set_all_palette_reg(u16 seg, u8 *data_far); void stdvga_get_all_palette_reg(u16 seg, u8 *data_far); -void stdvga_toggle_intensity(u8 flag); +void stdvga_set_palette_blinking(u8 enable_blink); void stdvga_select_video_dac_color_page(u8 flag, u8 data); void stdvga_read_video_dac_state(u8 *pmode, u8 *curpage); void stdvga_perform_gray_scale_summing(u16 start, u16 count); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index d522f83..b55a4db 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -544,7 +544,7 @@ handle_101002(struct bregs *regs) static void handle_101003(struct bregs *regs) { - stdvga_toggle_intensity(regs->bl); + stdvga_set_palette_blinking(regs->bl); }
static void
Rename the functions to make them a little easier to understand.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvga.c | 31 ++++++++++++++++++------------- vgasrc/stdvga.h | 5 +++-- vgasrc/vgabios.c | 7 +++++-- 3 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index 63700d4..2edd6d7 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -91,31 +91,36 @@ stdvga_set_palette_blinking(u8 enable_blink) stdvga_attr_mask(0x10, 0x08, (enable_blink & 0x01) << 3); }
+// Select 4-bit or 6-bit palette indexes (for "page" switching of colors) void -stdvga_select_video_dac_color_page(u8 flag, u8 data) +stdvga_set_palette_pagesize(u8 pal_pagesize) { - if (!(flag & 0x01)) { - // select paging mode - stdvga_attr_mask(0x10, 0x80, data << 7); - return; - } - // select page + stdvga_attr_mask(0x10, 0x80, pal_pagesize << 7); +} + +// Set palette index offset (enables color switching via "pages") +void +stdvga_set_palette_page(u8 pal_page) +{ + // Check if using 4-bit or 6-bit "palette index pages" u8 val = stdvga_attr_read(0x10); if (!(val & 0x80)) - data <<= 2; - data &= 0x0f; - stdvga_attr_write(0x14, data); + pal_page <<= 2; + // select page + pal_page &= 0x0f; + stdvga_attr_write(0x14, pal_page); }
+// Report current pallete index pagesize and current page void -stdvga_read_video_dac_state(u8 *pmode, u8 *curpage) +stdvga_get_palette_page(u8 *pal_pagesize, u8 *pal_page) { u8 val1 = stdvga_attr_read(0x10) >> 7; u8 val2 = stdvga_attr_read(0x14) & 0x0f; if (!(val1 & 0x01)) val2 >>= 2; - *pmode = val1; - *curpage = val2; + *pal_pagesize = val1; + *pal_page = val2; }
diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index 6ce6a90..e9cd2f0 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -52,8 +52,9 @@ u8 stdvga_get_overscan_border_color(void); void stdvga_set_all_palette_reg(u16 seg, u8 *data_far); void stdvga_get_all_palette_reg(u16 seg, u8 *data_far); void stdvga_set_palette_blinking(u8 enable_blink); -void stdvga_select_video_dac_color_page(u8 flag, u8 data); -void stdvga_read_video_dac_state(u8 *pmode, u8 *curpage); +void stdvga_set_palette_pagesize(u8 pal_pagesize); +void stdvga_set_palette_page(u8 pal_page); +void stdvga_get_palette_page(u8 *pal_pagesize, u8 *pal_page); void stdvga_perform_gray_scale_summing(u16 start, u16 count); void stdvga_set_text_block_specifier(u8 spec); void stdvga_planar4_plane(int plane); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index b55a4db..00325f5 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -583,7 +583,10 @@ handle_101012(struct bregs *regs) static void handle_101013(struct bregs *regs) { - stdvga_select_video_dac_color_page(regs->bl, regs->bh); + if (!(regs->bl & 0x01)) + stdvga_set_palette_pagesize(regs->bh); + else + stdvga_set_palette_page(regs->bh); }
static void noinline @@ -617,7 +620,7 @@ handle_101019(struct bregs *regs) static void handle_10101a(struct bregs *regs) { - stdvga_read_video_dac_state(®s->bl, ®s->bh); + stdvga_get_palette_page(®s->bl, ®s->bh); }
static void
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvga.c | 14 +++++++------- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index 2edd6d7..060e866 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -154,13 +154,6 @@ stdvga_perform_gray_scale_summing(u16 start, u16 count) * Memory control ****************************************************************/
-// Set the video memory location of the start of character fonts -void -stdvga_set_text_block_specifier(u8 spec) -{ - stdvga_sequ_write(0x03, spec); -} - // Enable reads and writes to the given "plane" when in planar4 mode. void stdvga_planar4_plane(int plane) @@ -180,6 +173,13 @@ stdvga_planar4_plane(int plane) * Font loading ****************************************************************/
+// Set the video memory location of the start of character fonts +void +stdvga_set_font_location(u8 spec) +{ + stdvga_sequ_write(0x03, spec); +} + static void get_font_access(void) { diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index e9cd2f0..8760486 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -56,8 +56,8 @@ void stdvga_set_palette_pagesize(u8 pal_pagesize); void stdvga_set_palette_page(u8 pal_page); void stdvga_get_palette_page(u8 *pal_pagesize, u8 *pal_page); void stdvga_perform_gray_scale_summing(u16 start, u16 count); -void stdvga_set_text_block_specifier(u8 spec); void stdvga_planar4_plane(int plane); +void stdvga_set_font_location(u8 spec); void stdvga_load_font(u16 seg, void *src_far, u16 count , u16 start, u8 destflags, u8 fontsize); u16 stdvga_get_crtc(void); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 00325f5..22c0261 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -686,7 +686,7 @@ handle_101102(struct bregs *regs) static void handle_101103(struct bregs *regs) { - stdvga_set_text_block_specifier(regs->bl); + stdvga_set_font_location(regs->bl); }
static void
On 1/4/24 17:51, Kevin O'Connor wrote:
Signed-off-by: Kevin O'Connor kevin@koconnor.net
vgasrc/stdvga.c | 14 +++++++------- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé philmd@linaro.org
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvga.c | 2 +- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index 060e866..839bd06 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -270,7 +270,7 @@ stdvga_set_cursor_pos(int address)
// Set the character height (when in text mode) void -stdvga_set_scan_lines(u8 lines) +stdvga_set_character_height(u8 lines) { stdvga_crtc_mask(stdvga_get_crtc(), 0x09, 0x1f, lines - 1); } diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index 8760486..439930a 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -65,7 +65,7 @@ struct vgamode_s; int stdvga_vram_ratio(struct vgamode_s *vmode_g); void stdvga_set_cursor_shape(u16 cursor_type); void stdvga_set_cursor_pos(int address); -void stdvga_set_scan_lines(u8 lines); +void stdvga_set_character_height(u8 lines); u16 stdvga_get_vde(void); int stdvga_get_window(struct vgamode_s *curmode_g, int window); int stdvga_set_window(struct vgamode_s *curmode_g, int window, int val); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 22c0261..a68cae1 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -134,9 +134,9 @@ set_active_page(u8 page) }
static void -set_scan_lines(u8 lines) +set_character_height(u8 lines) { - stdvga_set_scan_lines(lines); + stdvga_set_character_height(lines); SET_BDA(char_height, lines); u16 vde = stdvga_get_vde(); u8 rows = vde / lines; @@ -700,28 +700,28 @@ handle_101110(struct bregs *regs) { stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx , regs->dx, regs->bl, regs->bh); - set_scan_lines(regs->bh); + set_character_height(regs->bh); }
static void handle_101111(struct bregs *regs) { stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14); - set_scan_lines(14); + set_character_height(14); }
static void handle_101112(struct bregs *regs) { stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8); - set_scan_lines(8); + set_character_height(8); }
static void handle_101114(struct bregs *regs) { stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16); - set_scan_lines(16); + set_character_height(16); }
static void
On 1/4/24 17:51, Kevin O'Connor wrote:
Signed-off-by: Kevin O'Connor kevin@koconnor.net
vgasrc/stdvga.c | 2 +- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé philmd@linaro.org
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/stdvga.c | 8 ++++---- vgasrc/stdvga.h | 2 +- vgasrc/vgabios.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index 839bd06..991c791 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -275,15 +275,15 @@ stdvga_set_character_height(u8 lines) stdvga_crtc_mask(stdvga_get_crtc(), 0x09, 0x1f, lines - 1); }
-// Get vertical display end +// Get vertical screen size (number of horizontal lines in the display) u16 -stdvga_get_vde(void) +stdvga_get_vertical_size(void) { u16 crtc_addr = stdvga_get_crtc(); u16 vde = stdvga_crtc_read(crtc_addr, 0x12); u8 ovl = stdvga_crtc_read(crtc_addr, 0x07); - vde += (((ovl & 0x02) << 7) + ((ovl & 0x40) << 3) + 1); - return vde; + vde += ((ovl & 0x02) << 7) + ((ovl & 0x40) << 3); + return vde + 1; }
// Get offset into framebuffer accessible from real-mode 64K segment diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h index 439930a..1828585 100644 --- a/vgasrc/stdvga.h +++ b/vgasrc/stdvga.h @@ -66,7 +66,7 @@ int stdvga_vram_ratio(struct vgamode_s *vmode_g); void stdvga_set_cursor_shape(u16 cursor_type); void stdvga_set_cursor_pos(int address); void stdvga_set_character_height(u8 lines); -u16 stdvga_get_vde(void); +u16 stdvga_get_vertical_size(void); int stdvga_get_window(struct vgamode_s *curmode_g, int window); int stdvga_set_window(struct vgamode_s *curmode_g, int window, int val); int stdvga_minimum_linelength(struct vgamode_s *vmode_g); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index a68cae1..3659f01 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -138,8 +138,8 @@ set_character_height(u8 lines) { stdvga_set_character_height(lines); SET_BDA(char_height, lines); - u16 vde = stdvga_get_vde(); - u8 rows = vde / lines; + u16 vertical_size = stdvga_get_vertical_size(); + u8 rows = vertical_size / lines; SET_BDA(video_rows, rows - 1); u16 cols = GET_BDA(video_cols); SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
On Mon, Apr 01, 2024 at 11:51:22AM -0400, Kevin O'Connor wrote:
This series adds comments to vgasrc/stdvga.c along with some variable and function renaming. The goal is to make it a little easier to understand this legacy code.
There should be no functionality changes with this patch series.
-Kevin
I committed this patch series. (During merge I also fixed a minor comment spelling error in patch 6.)
-Kevin