From d1a9e1a0cb60804b9aef3e5df3d2ff96561c2d3a Mon Sep 17 00:00:00 2001 From: Kazutaka YOKOTA Date: Mon, 29 Mar 1999 15:10:56 +0000 Subject: [PATCH] Another round of fix for palette loading. - Don't try to change DAC width when unnecessary. - Convert 8 bit DAC data to 6 bit DAC data before unloading the vesa KLD module. --- sys/i386/isa/vesa.c | 47 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/sys/i386/isa/vesa.c b/sys/i386/isa/vesa.c index 08ca06411e58..5f303ed96cb1 100644 --- a/sys/i386/isa/vesa.c +++ b/sys/i386/isa/vesa.c @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: vesa.c,v 1.19 1999/03/18 04:38:16 jlemon Exp $ + * $Id: vesa.c,v 1.20 1999/03/18 20:13:20 jlemon Exp $ */ #include "vga.h" @@ -152,6 +152,7 @@ static char *vesa_revstr = NULL; static int int10_set_mode(int mode); static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode); static int vesa_bios_set_mode(int mode); +static int vesa_bios_get_dac(void); static int vesa_bios_set_dac(int bits); static int vesa_bios_save_palette(int start, int colors, u_char *palette, int bits); @@ -234,6 +235,21 @@ vesa_bios_set_mode(int mode) return ((err != 0) || (vmf.vmf_eax != 0x4f)); } +static int +vesa_bios_get_dac(void) +{ + struct vm86frame vmf; + int err; + + bzero(&vmf, sizeof(vmf)); + vmf.vmf_eax = 0x4f08; + vmf.vmf_ebx = 1; /* get DAC width */ + err = vm86_intcall(0x10, &vmf); + if ((err != 0) || (vmf.vmf_eax != 0x4f)) + return 6; /* XXX */ + return ((vmf.vmf_ebx >> 8) & 0x00ff); +} + static int vesa_bios_set_dac(int bits) { @@ -841,12 +857,14 @@ vesa_save_palette(video_adapter_t *adp, u_char *palette) int bits; int error; - if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) - && ((bits = vesa_bios_set_dac(8)) > 6)) { + if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) + && VESA_MODE(adp->va_mode)) { + bits = vesa_bios_get_dac(); error = vesa_bios_save_palette(0, 256, palette, bits); - vesa_bios_set_dac(6); if (error == 0) return 0; + if (bits != 6) + return error; } return (*prevvidsw->save_palette)(adp, palette); @@ -855,16 +873,19 @@ vesa_save_palette(video_adapter_t *adp, u_char *palette) static int vesa_load_palette(video_adapter_t *adp, u_char *palette) { +#if notyet int bits; int error; if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) - && ((bits = vesa_bios_set_dac(8)) > 6)) { + && VESA_MODE(adp->va_mode) && ((bits = vesa_bios_set_dac(8)) > 6)) { error = vesa_bios_load_palette(0, 256, palette, bits); - vesa_bios_set_dac(6); if (error == 0) return 0; + if (vesa_bios_set_dac(6) != 6) + return 1; } +#endif /* notyet */ return (*prevvidsw->load_palette)(adp, palette); } @@ -1075,7 +1096,9 @@ vesa_load(void) static int vesa_unload(void) { + u_char palette[256*3]; int error; + int bits; int s; /* if the adapter is currently in a VESA mode, don't unload */ @@ -1089,8 +1112,16 @@ vesa_unload(void) s = spltty(); if ((error = vesa_unload_ioctl()) == 0) { if (vesa_adp != NULL) { - if (vesa_adp_info->v_flags & V_DAC8) - vesa_bios_set_dac(6); + if (vesa_adp_info->v_flags & V_DAC8) { + bits = vesa_bios_get_dac(); + if (bits > 6) { + vesa_bios_save_palette(0, 256, + palette, bits); + vesa_bios_set_dac(6); + vesa_bios_load_palette(0, 256, + palette, 6); + } + } vesa_adp->va_flags &= ~V_ADP_VESA; vidsw[vesa_adp->va_index] = prevvidsw; }