| 1932 | } |
| 1933 | |
| 1934 | static boolean |
| 1935 | vesa_SetHardPalette(const struct Pixel *palette) |
| 1936 | { |
| 1937 | int palette_sel = -1; /* custodial */ |
| 1938 | int palette_seg; |
| 1939 | unsigned char p2[1024]; |
| 1940 | unsigned i, shift; |
| 1941 | __dpmi_regs regs; |
| 1942 | |
| 1943 | palette_seg = __dpmi_allocate_dos_memory( 1024 / 16, &palette_sel); |
| 1944 | if (palette_seg < 0) goto error; |
| 1945 | |
| 1946 | /* Use 8 bit DACs if we have them */ |
| 1947 | memset(®s, 0, sizeof(regs)); |
| 1948 | regs.x.ax = 0x4F08; |
| 1949 | regs.h.bl = 0; |
| 1950 | regs.h.bh = 8; |
| 1951 | (void) __dpmi_int(VIDEO_BIOS, ®s); |
| 1952 | if (regs.x.ax != 0x004F) { |
| 1953 | shift = 2; |
| 1954 | } else if (regs.h.bh > 8) { |
| 1955 | shift = 0; |
| 1956 | } else { |
| 1957 | shift = 8 - regs.h.bh; |
| 1958 | } |
| 1959 | |
| 1960 | /* First, try the VESA palette function */ |
| 1961 | /* Set the tile set and text colors */ |
| 1962 | #ifdef TILES_IN_GLYPHMAP |
| 1963 | for (i = 0; i < FIRST_TEXT_COLOR; ++i) { |
| 1964 | p2[i*4 + 0] = palette[i].b >> shift; |
| 1965 | p2[i*4 + 1] = palette[i].g >> shift; |
| 1966 | p2[i*4 + 2] = palette[i].r >> shift; |
| 1967 | } |
| 1968 | #endif |
| 1969 | for (i = FIRST_TEXT_COLOR; i < 256; ++i) { |
| 1970 | p2[i*4 + 0] = defpalette[i-FIRST_TEXT_COLOR].b >> shift; |
| 1971 | p2[i*4 + 1] = defpalette[i-FIRST_TEXT_COLOR].g >> shift; |
| 1972 | p2[i*4 + 2] = defpalette[i-FIRST_TEXT_COLOR].r >> shift; |
| 1973 | } |
| 1974 | |
| 1975 | /* Call the BIOS */ |
| 1976 | dosmemput(p2, 256*4, palette_seg*16L); |
| 1977 | memset(®s, 0, sizeof(regs)); |
| 1978 | regs.x.ax = 0x4F09; |
| 1979 | regs.h.bl = 0; |
| 1980 | regs.x.cx = 256; |
| 1981 | regs.x.dx = 0; |
| 1982 | regs.x.di = 0; |
| 1983 | regs.x.es = palette_seg; |
| 1984 | (void) __dpmi_int(VIDEO_BIOS, ®s); |
| 1985 | |
| 1986 | /* If that didn't work, use the original BIOS function */ |
| 1987 | if (regs.x.ax != 0x004F) { |
| 1988 | /* Set the tile set and text colors */ |
| 1989 | #ifdef TILES_IN_GLYPHMAP |
| 1990 | for (i = 0; i < FIRST_TEXT_COLOR; ++i) { |
| 1991 | p2[i*3 + 0] = palette[i].r >> shift; |