diff options
author | yokota <yokota@FreeBSD.org> | 1999-01-16 12:56:00 +0000 |
---|---|---|
committer | yokota <yokota@FreeBSD.org> | 1999-01-16 12:56:00 +0000 |
commit | 5126e935c06f6177fa93752feb871bf52061d007 (patch) | |
tree | 1028d7ace2aed2ffeacc5bd64382e7784a43c7a0 /sys | |
parent | 4f24cd0954a4fea4bd8ec6f13b2f451165bc1685 (diff) | |
download | FreeBSD-src-5126e935c06f6177fa93752feb871bf52061d007.zip FreeBSD-src-5126e935c06f6177fa93752feb871bf52061d007.tar.gz |
Fix palette save/load functions.
# They have been unchanged since the introduction of the VESA support.
# But, we started seeing the problem only recently ;-<
Diffstat (limited to 'sys')
-rw-r--r-- | sys/i386/isa/vesa.c | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/sys/i386/isa/vesa.c b/sys/i386/isa/vesa.c index 30ef3ac..db0a0cf 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.12 1999/01/11 03:18:24 yokota Exp $ + * $Id: vesa.c,v 1.13 1999/01/13 01:16:39 yokota Exp $ */ #include "vga.h" @@ -152,8 +152,10 @@ 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_set_dac(int bits); -static int vesa_bios_save_palette(int start, int colors, u_char *palette); -static int vesa_bios_load_palette(int start, int colors, u_char *palette); +static int vesa_bios_save_palette(int start, int colors, u_char *palette, + int bits); +static int vesa_bios_load_palette(int start, int colors, u_char *palette, + int bits); #define STATE_SIZE 0 #define STATE_SAVE 1 #define STATE_LOAD 2 @@ -239,11 +241,13 @@ vesa_bios_set_dac(int bits) vmf.vmf_eax = 0x4f08; vmf.vmf_ebx = (bits << 8); err = vm86_intcall(0x10, &vmf); - return ((err != 0) || (vmf.vmf_eax != 0x4f)); + if ((err != 0) || (vmf.vmf_eax != 0x4f)) + return 6; /* XXX */ + return ((vmf.vmf_ebx >> 8) & 0x00ff); } static int -vesa_bios_save_palette(int start, int colors, u_char *palette) +vesa_bios_save_palette(int start, int colors, u_char *palette, int bits) { struct vm86frame vmf; u_char *p; @@ -263,17 +267,18 @@ vesa_bios_save_palette(int start, int colors, u_char *palette) return 1; } + bits = 8 - bits; for (i = 0; i < colors; ++i) { - palette[i*3] = p[i*4 + 1]; - palette[i*3 + 1] = p[i*4 + 2]; - palette[i*3 + 2] = p[i*4 + 3]; + palette[i*3] = p[i*4 + 2] << bits; + palette[i*3 + 1] = p[i*4 + 1] << bits; + palette[i*3 + 2] = p[i*4] << bits; } free(p, M_DEVBUF); return 0; } static int -vesa_bios_load_palette(int start, int colors, u_char *palette) +vesa_bios_load_palette(int start, int colors, u_char *palette, int bits) { struct vm86frame vmf; u_char *p; @@ -281,11 +286,12 @@ vesa_bios_load_palette(int start, int colors, u_char *palette) int i; p = malloc(colors*4, M_DEVBUF, M_WAITOK); + bits = 8 - bits; for (i = 0; i < colors; ++i) { - p[i*4] = 0; - p[i*4 + 1] = palette[i*3]; - p[i*4 + 2] = palette[i*3 + 1]; - p[i*4 + 3] = palette[i*3 + 2]; + p[i*4] = palette[i*3 + 2] >> bits; + p[i*4 + 1] = palette[i*3 + 1] >> bits; + p[i*4 + 2] = palette[i*3] >> bits; + p[i*4 + 3] = 0; } bzero(&vmf, sizeof(vmf)); @@ -779,21 +785,35 @@ vesa_show_font(video_adapter_t *adp, int page) static int vesa_save_palette(video_adapter_t *adp, u_char *palette) { - if ((adp != vesa_adp) || !(vesa_adp_info->v_flags & V_DAC8) - || vesa_bios_set_dac(8)) - return (*prevvidsw->save_palette)(adp, palette); + int bits; + int error; + + if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) + && ((bits = vesa_bios_set_dac(8)) > 6)) { + error = vesa_bios_save_palette(0, 256, palette, bits); + if (error == 0) + return 0; + vesa_bios_set_dac(6); + } - return vesa_bios_save_palette(0, 256, palette); + return (*prevvidsw->save_palette)(adp, palette); } static int vesa_load_palette(video_adapter_t *adp, u_char *palette) { - if ((adp != vesa_adp) || !(vesa_adp_info->v_flags & V_DAC8) - || vesa_bios_set_dac(8)) - return (*prevvidsw->load_palette)(adp, palette); + int bits; + int error; + + if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) + && ((bits = vesa_bios_set_dac(8)) > 6)) { + error = vesa_bios_load_palette(0, 256, palette, bits); + if (error == 0) + return 0; + vesa_bios_set_dac(6); + } - return vesa_bios_load_palette(0, 256, palette); + return (*prevvidsw->load_palette)(adp, palette); } static int |