11243dad0SKazutaka YOKOTA /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
41243dad0SKazutaka YOKOTA * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
51243dad0SKazutaka YOKOTA * Copyright (c) 1999 Kazutaka YOKOTA <yokota@freebsd.org>
61243dad0SKazutaka YOKOTA * All rights reserved.
71243dad0SKazutaka YOKOTA *
81243dad0SKazutaka YOKOTA * Redistribution and use in source and binary forms, with or without
91243dad0SKazutaka YOKOTA * modification, are permitted provided that the following conditions
101243dad0SKazutaka YOKOTA * are met:
111243dad0SKazutaka YOKOTA * 1. Redistributions of source code must retain the above copyright
121243dad0SKazutaka YOKOTA * notice, this list of conditions and the following disclaimer.
131243dad0SKazutaka YOKOTA * 2. Redistributions in binary form must reproduce the above copyright
141243dad0SKazutaka YOKOTA * notice, this list of conditions and the following disclaimer in the
151243dad0SKazutaka YOKOTA * documentation and/or other materials provided with the distribution.
161243dad0SKazutaka YOKOTA *
171243dad0SKazutaka YOKOTA * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
181243dad0SKazutaka YOKOTA * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191243dad0SKazutaka YOKOTA * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201243dad0SKazutaka YOKOTA * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
211243dad0SKazutaka YOKOTA * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221243dad0SKazutaka YOKOTA * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231243dad0SKazutaka YOKOTA * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241243dad0SKazutaka YOKOTA * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251243dad0SKazutaka YOKOTA * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261243dad0SKazutaka YOKOTA * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271243dad0SKazutaka YOKOTA * SUCH DAMAGE.
281243dad0SKazutaka YOKOTA */
291243dad0SKazutaka YOKOTA
301243dad0SKazutaka YOKOTA #include <sys/param.h>
311243dad0SKazutaka YOKOTA #include <sys/systm.h>
321243dad0SKazutaka YOKOTA #include <sys/kernel.h>
335dba30f1SPoul-Henning Kamp #include <sys/module.h>
341243dad0SKazutaka YOKOTA #include <sys/linker.h>
356e8394b8SKazutaka YOKOTA #include <sys/fbio.h>
361243dad0SKazutaka YOKOTA
371243dad0SKazutaka YOKOTA #include <dev/fb/fbreg.h>
381243dad0SKazutaka YOKOTA #include <dev/fb/splashreg.h>
3999feb462SKazutaka YOKOTA #include <dev/fb/vgareg.h>
4099feb462SKazutaka YOKOTA
4199feb462SKazutaka YOKOTA #include <isa/isareg.h>
421243dad0SKazutaka YOKOTA
43ccd48159SKazutaka YOKOTA #define FADE_TIMEOUT 15 /* sec */
44ccd48159SKazutaka YOKOTA #define FADE_LEVELS 10
451243dad0SKazutaka YOKOTA
461243dad0SKazutaka YOKOTA static int splash_mode = -1;
471243dad0SKazutaka YOKOTA static int splash_on = FALSE;
481243dad0SKazutaka YOKOTA
491243dad0SKazutaka YOKOTA static int bmp_start(video_adapter_t *adp);
501243dad0SKazutaka YOKOTA static int bmp_end(video_adapter_t *adp);
511243dad0SKazutaka YOKOTA static int bmp_splash(video_adapter_t *adp, int on);
5297be736aSMaxime Henrion static int bmp_Init(char *data, int swidth, int sheight, int sdepth);
531243dad0SKazutaka YOKOTA static int bmp_Draw(video_adapter_t *adp);
541243dad0SKazutaka YOKOTA
551243dad0SKazutaka YOKOTA static splash_decoder_t bmp_decoder = {
561243dad0SKazutaka YOKOTA "splash_bmp", bmp_start, bmp_end, bmp_splash, SPLASH_IMAGE,
571243dad0SKazutaka YOKOTA };
581243dad0SKazutaka YOKOTA
591243dad0SKazutaka YOKOTA SPLASH_DECODER(splash_bmp, bmp_decoder);
601243dad0SKazutaka YOKOTA
611243dad0SKazutaka YOKOTA static int
bmp_start(video_adapter_t * adp)621243dad0SKazutaka YOKOTA bmp_start(video_adapter_t *adp)
631243dad0SKazutaka YOKOTA {
64325fca90SKazutaka YOKOTA /* currently only 256-color modes are supported XXX */
651243dad0SKazutaka YOKOTA static int modes[] = {
66325fca90SKazutaka YOKOTA M_VESA_CG640x480,
67325fca90SKazutaka YOKOTA M_VESA_CG800x600,
68325fca90SKazutaka YOKOTA M_VESA_CG1024x768,
6999feb462SKazutaka YOKOTA M_CG640x480,
70325fca90SKazutaka YOKOTA /*
71325fca90SKazutaka YOKOTA * As 320x200 doesn't generally look great,
72325fca90SKazutaka YOKOTA * it's least preferred here.
73325fca90SKazutaka YOKOTA */
741243dad0SKazutaka YOKOTA M_VGA_CG320,
751243dad0SKazutaka YOKOTA -1,
761243dad0SKazutaka YOKOTA };
771243dad0SKazutaka YOKOTA video_info_t info;
781243dad0SKazutaka YOKOTA int i;
791243dad0SKazutaka YOKOTA
805c539f03SKazutaka YOKOTA if ((bmp_decoder.data == NULL) || (bmp_decoder.data_size <= 0)) {
815c539f03SKazutaka YOKOTA printf("splash_bmp: No bitmap file found\n");
821243dad0SKazutaka YOKOTA return ENODEV;
835c539f03SKazutaka YOKOTA }
841243dad0SKazutaka YOKOTA for (i = 0; modes[i] >= 0; ++i) {
859336e069SWojciech A. Koszek if ((vidd_get_info(adp, modes[i], &info) == 0) &&
869336e069SWojciech A. Koszek (bmp_Init((u_char *)bmp_decoder.data, info.vi_width,
879336e069SWojciech A. Koszek info.vi_height, info.vi_depth) == 0))
881243dad0SKazutaka YOKOTA break;
891243dad0SKazutaka YOKOTA }
901243dad0SKazutaka YOKOTA splash_mode = modes[i];
915c539f03SKazutaka YOKOTA if (splash_mode < 0)
925c539f03SKazutaka YOKOTA printf("splash_bmp: No appropriate video mode found\n");
931243dad0SKazutaka YOKOTA if (bootverbose)
941243dad0SKazutaka YOKOTA printf("bmp_start(): splash_mode:%d\n", splash_mode);
951243dad0SKazutaka YOKOTA return ((splash_mode < 0) ? ENODEV : 0);
961243dad0SKazutaka YOKOTA }
971243dad0SKazutaka YOKOTA
981243dad0SKazutaka YOKOTA static int
bmp_end(video_adapter_t * adp)991243dad0SKazutaka YOKOTA bmp_end(video_adapter_t *adp)
1001243dad0SKazutaka YOKOTA {
1011243dad0SKazutaka YOKOTA /* nothing to do */
1021243dad0SKazutaka YOKOTA return 0;
1031243dad0SKazutaka YOKOTA }
1041243dad0SKazutaka YOKOTA
1051243dad0SKazutaka YOKOTA static int
bmp_splash(video_adapter_t * adp,int on)1061243dad0SKazutaka YOKOTA bmp_splash(video_adapter_t *adp, int on)
1071243dad0SKazutaka YOKOTA {
1081243dad0SKazutaka YOKOTA static u_char pal[256*3];
1091243dad0SKazutaka YOKOTA static long time_stamp;
110ccd48159SKazutaka YOKOTA u_char tpal[256*3];
111ccd48159SKazutaka YOKOTA static int fading = TRUE, brightness = FADE_LEVELS;
1121243dad0SKazutaka YOKOTA struct timeval tv;
1131243dad0SKazutaka YOKOTA int i;
1141243dad0SKazutaka YOKOTA
1151243dad0SKazutaka YOKOTA if (on) {
1161243dad0SKazutaka YOKOTA if (!splash_on) {
1171243dad0SKazutaka YOKOTA /* set up the video mode and draw something */
1189336e069SWojciech A. Koszek if (vidd_set_mode(adp, splash_mode))
1191243dad0SKazutaka YOKOTA return 1;
1201243dad0SKazutaka YOKOTA if (bmp_Draw(adp))
1211243dad0SKazutaka YOKOTA return 1;
1229336e069SWojciech A. Koszek vidd_save_palette(adp, pal);
1231243dad0SKazutaka YOKOTA time_stamp = 0;
1241243dad0SKazutaka YOKOTA splash_on = TRUE;
1251243dad0SKazutaka YOKOTA }
1261243dad0SKazutaka YOKOTA /*
1271243dad0SKazutaka YOKOTA * This is a kludge to fade the image away. This section of the
1281243dad0SKazutaka YOKOTA * code takes effect only after the system is completely up.
129325fca90SKazutaka YOKOTA * FADE_TIMEOUT should be configurable.
1301243dad0SKazutaka YOKOTA */
1311243dad0SKazutaka YOKOTA if (!cold) {
1321243dad0SKazutaka YOKOTA getmicrotime(&tv);
1331243dad0SKazutaka YOKOTA if (time_stamp == 0)
1341243dad0SKazutaka YOKOTA time_stamp = tv.tv_sec;
1351243dad0SKazutaka YOKOTA if (tv.tv_sec > time_stamp + FADE_TIMEOUT) {
136ccd48159SKazutaka YOKOTA if (fading)
137ccd48159SKazutaka YOKOTA if (brightness == 0) {
138ccd48159SKazutaka YOKOTA fading = FALSE;
139ccd48159SKazutaka YOKOTA brightness++;
1401243dad0SKazutaka YOKOTA }
141ccd48159SKazutaka YOKOTA else brightness--;
142ccd48159SKazutaka YOKOTA else
143ccd48159SKazutaka YOKOTA if (brightness == FADE_LEVELS) {
144ccd48159SKazutaka YOKOTA fading = TRUE;
145ccd48159SKazutaka YOKOTA brightness--;
146ccd48159SKazutaka YOKOTA }
147ccd48159SKazutaka YOKOTA else brightness++;
148ccd48159SKazutaka YOKOTA for (i = 0; i < sizeof(pal); ++i) {
149ccd48159SKazutaka YOKOTA tpal[i] = pal[i] * brightness / FADE_LEVELS;
150ccd48159SKazutaka YOKOTA }
1519336e069SWojciech A. Koszek vidd_load_palette(adp, tpal);
152ccd48159SKazutaka YOKOTA time_stamp = tv.tv_sec;
1531243dad0SKazutaka YOKOTA }
1541243dad0SKazutaka YOKOTA }
1551243dad0SKazutaka YOKOTA return 0;
1561243dad0SKazutaka YOKOTA } else {
1571243dad0SKazutaka YOKOTA /* the video mode will be restored by the caller */
1581243dad0SKazutaka YOKOTA splash_on = FALSE;
1591243dad0SKazutaka YOKOTA return 0;
1601243dad0SKazutaka YOKOTA }
1611243dad0SKazutaka YOKOTA }
1621243dad0SKazutaka YOKOTA
1631243dad0SKazutaka YOKOTA /*
1641243dad0SKazutaka YOKOTA ** Code to handle Microsoft DIB (".BMP") format images.
1651243dad0SKazutaka YOKOTA **
1661243dad0SKazutaka YOKOTA ** Blame me (msmith@freebsd.org) if this is broken, not Soren.
1671243dad0SKazutaka YOKOTA */
1681243dad0SKazutaka YOKOTA
1691243dad0SKazutaka YOKOTA typedef struct tagBITMAPFILEHEADER { /* bmfh */
17006b642b5SMatt Jacob u_short bfType;
17106b642b5SMatt Jacob int bfSize;
17206b642b5SMatt Jacob u_short bfReserved1;
17306b642b5SMatt Jacob u_short bfReserved2;
17406b642b5SMatt Jacob int bfOffBits;
17506b642b5SMatt Jacob } __packed BITMAPFILEHEADER;
1761243dad0SKazutaka YOKOTA
1771243dad0SKazutaka YOKOTA typedef struct tagBITMAPINFOHEADER { /* bmih */
17806b642b5SMatt Jacob int biSize;
17906b642b5SMatt Jacob int biWidth;
18006b642b5SMatt Jacob int biHeight;
18106b642b5SMatt Jacob short biPlanes;
18206b642b5SMatt Jacob short biBitCount;
18306b642b5SMatt Jacob int biCompression;
18406b642b5SMatt Jacob int biSizeImage;
18506b642b5SMatt Jacob int biXPelsPerMeter;
18606b642b5SMatt Jacob int biYPelsPerMeter;
18706b642b5SMatt Jacob int biClrUsed;
18806b642b5SMatt Jacob int biClrImportant;
18906b642b5SMatt Jacob } __packed BITMAPINFOHEADER;
1901243dad0SKazutaka YOKOTA
1911243dad0SKazutaka YOKOTA typedef struct tagRGBQUAD { /* rgbq */
19206b642b5SMatt Jacob u_char rgbBlue;
19306b642b5SMatt Jacob u_char rgbGreen;
19406b642b5SMatt Jacob u_char rgbRed;
19506b642b5SMatt Jacob u_char rgbReserved;
19606b642b5SMatt Jacob } __packed RGBQUAD;
1971243dad0SKazutaka YOKOTA
1981243dad0SKazutaka YOKOTA typedef struct tagBITMAPINFO { /* bmi */
19906b642b5SMatt Jacob BITMAPINFOHEADER bmiHeader;
20006b642b5SMatt Jacob RGBQUAD bmiColors[256];
20106b642b5SMatt Jacob } __packed BITMAPINFO;
2021243dad0SKazutaka YOKOTA
2031243dad0SKazutaka YOKOTA typedef struct tagBITMAPF
2041243dad0SKazutaka YOKOTA {
20506b642b5SMatt Jacob BITMAPFILEHEADER bmfh;
20606b642b5SMatt Jacob BITMAPINFO bmfi;
20706b642b5SMatt Jacob } __packed BITMAPF;
2081243dad0SKazutaka YOKOTA
2091243dad0SKazutaka YOKOTA #define BI_RGB 0
2101243dad0SKazutaka YOKOTA #define BI_RLE8 1
2111243dad0SKazutaka YOKOTA #define BI_RLE4 2
2121243dad0SKazutaka YOKOTA
2131243dad0SKazutaka YOKOTA /*
2141243dad0SKazutaka YOKOTA ** all we actually care about the image
2151243dad0SKazutaka YOKOTA */
2161243dad0SKazutaka YOKOTA typedef struct
2171243dad0SKazutaka YOKOTA {
2181243dad0SKazutaka YOKOTA int width,height; /* image dimensions */
2191243dad0SKazutaka YOKOTA int swidth,sheight; /* screen dimensions for the current mode */
22099feb462SKazutaka YOKOTA u_char depth; /* image depth (1, 4, 8, 24 bits) */
2211243dad0SKazutaka YOKOTA u_char sdepth; /* screen depth (1, 4, 8 bpp) */
2221243dad0SKazutaka YOKOTA int ncols; /* number of colours */
2231243dad0SKazutaka YOKOTA u_char palette[256][3]; /* raw palette data */
2241243dad0SKazutaka YOKOTA u_char format; /* one of the BI_* constants above */
2251243dad0SKazutaka YOKOTA u_char *data; /* pointer to the raw data */
2261243dad0SKazutaka YOKOTA u_char *index; /* running pointer to the data while drawing */
2271243dad0SKazutaka YOKOTA u_char *vidmem; /* video memory allocated for drawing */
228325fca90SKazutaka YOKOTA video_adapter_t *adp;
229325fca90SKazutaka YOKOTA int bank;
2301243dad0SKazutaka YOKOTA } BMP_INFO;
2311243dad0SKazutaka YOKOTA
2321243dad0SKazutaka YOKOTA static BMP_INFO bmp_info;
2331243dad0SKazutaka YOKOTA
2341243dad0SKazutaka YOKOTA /*
2351243dad0SKazutaka YOKOTA ** bmp_SetPix
2361243dad0SKazutaka YOKOTA **
2371243dad0SKazutaka YOKOTA ** Given (info), set the pixel at (x),(y) to (val)
2381243dad0SKazutaka YOKOTA **
2391243dad0SKazutaka YOKOTA */
2401243dad0SKazutaka YOKOTA static void
bmp_SetPix(BMP_INFO * info,int x,int y,u_char val)2411243dad0SKazutaka YOKOTA bmp_SetPix(BMP_INFO *info, int x, int y, u_char val)
2421243dad0SKazutaka YOKOTA {
2431243dad0SKazutaka YOKOTA int sofs, bofs;
244325fca90SKazutaka YOKOTA int newbank;
2451243dad0SKazutaka YOKOTA
2461243dad0SKazutaka YOKOTA /*
2471243dad0SKazutaka YOKOTA * range check to avoid explosions
2481243dad0SKazutaka YOKOTA */
2491243dad0SKazutaka YOKOTA if ((x < 0) || (x >= info->swidth) || (y < 0) || (y >= info->sheight))
2501243dad0SKazutaka YOKOTA return;
2511243dad0SKazutaka YOKOTA
2521243dad0SKazutaka YOKOTA /*
2531243dad0SKazutaka YOKOTA * calculate offset into video memory;
2541243dad0SKazutaka YOKOTA * because 0,0 is bottom-left for DIB, we have to convert.
2551243dad0SKazutaka YOKOTA */
2561243dad0SKazutaka YOKOTA sofs = ((info->height - (y+1) + (info->sheight - info->height) / 2)
2571c27745fSKazutaka YOKOTA * info->adp->va_line_width);
25899feb462SKazutaka YOKOTA x += (info->swidth - info->width) / 2;
2591243dad0SKazutaka YOKOTA
2601243dad0SKazutaka YOKOTA switch(info->sdepth) {
2611243dad0SKazutaka YOKOTA case 4:
26299feb462SKazutaka YOKOTA case 1:
26399feb462SKazutaka YOKOTA /* EGA/VGA planar modes */
26499feb462SKazutaka YOKOTA sofs += (x >> 3);
26599feb462SKazutaka YOKOTA newbank = sofs/info->adp->va_window_size;
26699feb462SKazutaka YOKOTA if (info->bank != newbank) {
2679336e069SWojciech A. Koszek vidd_set_win_org(info->adp, newbank*info->adp->va_window_size);
26899feb462SKazutaka YOKOTA info->bank = newbank;
26999feb462SKazutaka YOKOTA }
27099feb462SKazutaka YOKOTA sofs %= info->adp->va_window_size;
27199feb462SKazutaka YOKOTA bofs = x & 0x7; /* offset within byte */
27299feb462SKazutaka YOKOTA outw(GDCIDX, (0x8000 >> bofs) | 0x08); /* bit mask */
27399feb462SKazutaka YOKOTA outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
27499feb462SKazutaka YOKOTA *(info->vidmem + sofs) ^= 0xff; /* read-modify-write */
2751243dad0SKazutaka YOKOTA break;
2761243dad0SKazutaka YOKOTA
2771243dad0SKazutaka YOKOTA case 8:
27899feb462SKazutaka YOKOTA sofs += x;
279325fca90SKazutaka YOKOTA newbank = sofs/info->adp->va_window_size;
280325fca90SKazutaka YOKOTA if (info->bank != newbank) {
2819336e069SWojciech A. Koszek vidd_set_win_org(info->adp, newbank*info->adp->va_window_size);
282325fca90SKazutaka YOKOTA info->bank = newbank;
283325fca90SKazutaka YOKOTA }
284325fca90SKazutaka YOKOTA sofs %= info->adp->va_window_size;
2851243dad0SKazutaka YOKOTA *(info->vidmem+sofs) = val;
2861243dad0SKazutaka YOKOTA break;
2871243dad0SKazutaka YOKOTA }
2881243dad0SKazutaka YOKOTA }
2891243dad0SKazutaka YOKOTA
2901243dad0SKazutaka YOKOTA /*
2911243dad0SKazutaka YOKOTA ** bmp_DecodeRLE4
2921243dad0SKazutaka YOKOTA **
2931243dad0SKazutaka YOKOTA ** Given (data) pointing to a line of RLE4-format data and (line) being the starting
2941243dad0SKazutaka YOKOTA ** line onscreen, decode the line.
2951243dad0SKazutaka YOKOTA */
2961243dad0SKazutaka YOKOTA static void
bmp_DecodeRLE4(BMP_INFO * info,int line)2971243dad0SKazutaka YOKOTA bmp_DecodeRLE4(BMP_INFO *info, int line)
2981243dad0SKazutaka YOKOTA {
2991243dad0SKazutaka YOKOTA int count; /* run count */
3001243dad0SKazutaka YOKOTA u_char val;
3011243dad0SKazutaka YOKOTA int x,y; /* screen position */
3021243dad0SKazutaka YOKOTA
3031243dad0SKazutaka YOKOTA x = 0; /* starting position */
3041243dad0SKazutaka YOKOTA y = line;
3051243dad0SKazutaka YOKOTA
3061243dad0SKazutaka YOKOTA /* loop reading data */
3071243dad0SKazutaka YOKOTA for (;;) {
3081243dad0SKazutaka YOKOTA /*
3091243dad0SKazutaka YOKOTA * encoded mode starts with a run length, and then a byte with
3101243dad0SKazutaka YOKOTA * two colour indexes to alternate between for the run
3111243dad0SKazutaka YOKOTA */
3121243dad0SKazutaka YOKOTA if (*info->index) {
3131243dad0SKazutaka YOKOTA for (count = 0; count < *info->index; count++, x++) {
3141243dad0SKazutaka YOKOTA if (count & 1) { /* odd count, low nybble */
3151243dad0SKazutaka YOKOTA bmp_SetPix(info, x, y, *(info->index+1) & 0x0f);
3161243dad0SKazutaka YOKOTA } else { /* even count, high nybble */
3171243dad0SKazutaka YOKOTA bmp_SetPix(info, x, y, (*(info->index+1) >>4) & 0x0f);
3181243dad0SKazutaka YOKOTA }
3191243dad0SKazutaka YOKOTA }
3201243dad0SKazutaka YOKOTA info->index += 2;
3211243dad0SKazutaka YOKOTA /*
3221243dad0SKazutaka YOKOTA * A leading zero is an escape; it may signal the end of the
3231243dad0SKazutaka YOKOTA * bitmap, a cursor move, or some absolute data.
3241243dad0SKazutaka YOKOTA */
3251243dad0SKazutaka YOKOTA } else { /* zero tag may be absolute mode or an escape */
3261243dad0SKazutaka YOKOTA switch (*(info->index+1)) {
3271243dad0SKazutaka YOKOTA case 0: /* end of line */
3281243dad0SKazutaka YOKOTA info->index += 2;
3291243dad0SKazutaka YOKOTA return;
3301243dad0SKazutaka YOKOTA case 1: /* end of bitmap */
3311243dad0SKazutaka YOKOTA info->index = NULL;
3321243dad0SKazutaka YOKOTA return;
3331243dad0SKazutaka YOKOTA case 2: /* move */
3341243dad0SKazutaka YOKOTA x += *(info->index + 2); /* new coords */
3351243dad0SKazutaka YOKOTA y += *(info->index + 3);
3361243dad0SKazutaka YOKOTA info->index += 4;
3371243dad0SKazutaka YOKOTA break;
3381243dad0SKazutaka YOKOTA default: /* literal bitmap data */
3391243dad0SKazutaka YOKOTA for (count = 0; count < *(info->index + 1); count++, x++) {
3401243dad0SKazutaka YOKOTA val = *(info->index + 2 + (count / 2)); /* byte with nybbles */
3411243dad0SKazutaka YOKOTA if (count & 1) {
3421243dad0SKazutaka YOKOTA val &= 0xf; /* get low nybble */
3431243dad0SKazutaka YOKOTA } else {
3441243dad0SKazutaka YOKOTA val = (val >> 4); /* get high nybble */
3451243dad0SKazutaka YOKOTA }
3461243dad0SKazutaka YOKOTA bmp_SetPix(info, x, y, val);
3471243dad0SKazutaka YOKOTA }
3481243dad0SKazutaka YOKOTA /* warning, this depends on integer truncation, do not hand-optimise! */
3491243dad0SKazutaka YOKOTA info->index += 2 + ((count + 3) / 4) * 2;
3501243dad0SKazutaka YOKOTA break;
3511243dad0SKazutaka YOKOTA }
3521243dad0SKazutaka YOKOTA }
3531243dad0SKazutaka YOKOTA }
3541243dad0SKazutaka YOKOTA }
3551243dad0SKazutaka YOKOTA
3561243dad0SKazutaka YOKOTA /*
3571243dad0SKazutaka YOKOTA ** bmp_DecodeRLE8
35899feb462SKazutaka YOKOTA ** Given (data) pointing to a line of RLE8-format data and (line) being the starting
3591243dad0SKazutaka YOKOTA ** line onscreen, decode the line.
3601243dad0SKazutaka YOKOTA */
3611243dad0SKazutaka YOKOTA static void
bmp_DecodeRLE8(BMP_INFO * info,int line)3621243dad0SKazutaka YOKOTA bmp_DecodeRLE8(BMP_INFO *info, int line)
3631243dad0SKazutaka YOKOTA {
3641243dad0SKazutaka YOKOTA int count; /* run count */
3651243dad0SKazutaka YOKOTA int x,y; /* screen position */
3661243dad0SKazutaka YOKOTA
3671243dad0SKazutaka YOKOTA x = 0; /* starting position */
3681243dad0SKazutaka YOKOTA y = line;
3691243dad0SKazutaka YOKOTA
3701243dad0SKazutaka YOKOTA /* loop reading data */
3711243dad0SKazutaka YOKOTA for(;;) {
3721243dad0SKazutaka YOKOTA /*
3731243dad0SKazutaka YOKOTA * encoded mode starts with a run length, and then a byte with
3741243dad0SKazutaka YOKOTA * two colour indexes to alternate between for the run
3751243dad0SKazutaka YOKOTA */
3761243dad0SKazutaka YOKOTA if (*info->index) {
3771243dad0SKazutaka YOKOTA for (count = 0; count < *info->index; count++, x++)
3781243dad0SKazutaka YOKOTA bmp_SetPix(info, x, y, *(info->index+1));
3791243dad0SKazutaka YOKOTA info->index += 2;
3801243dad0SKazutaka YOKOTA /*
3811243dad0SKazutaka YOKOTA * A leading zero is an escape; it may signal the end of the
3821243dad0SKazutaka YOKOTA * bitmap, a cursor move, or some absolute data.
3831243dad0SKazutaka YOKOTA */
3841243dad0SKazutaka YOKOTA } else { /* zero tag may be absolute mode or an escape */
3851243dad0SKazutaka YOKOTA switch(*(info->index+1)) {
3861243dad0SKazutaka YOKOTA case 0: /* end of line */
3871243dad0SKazutaka YOKOTA info->index += 2;
3881243dad0SKazutaka YOKOTA return;
3891243dad0SKazutaka YOKOTA case 1: /* end of bitmap */
3901243dad0SKazutaka YOKOTA info->index = NULL;
3911243dad0SKazutaka YOKOTA return;
3921243dad0SKazutaka YOKOTA case 2: /* move */
3931243dad0SKazutaka YOKOTA x += *(info->index + 2); /* new coords */
3941243dad0SKazutaka YOKOTA y += *(info->index + 3);
3951243dad0SKazutaka YOKOTA info->index += 4;
3961243dad0SKazutaka YOKOTA break;
3971243dad0SKazutaka YOKOTA default: /* literal bitmap data */
3981243dad0SKazutaka YOKOTA for (count = 0; count < *(info->index + 1); count++, x++)
3991243dad0SKazutaka YOKOTA bmp_SetPix(info, x, y, *(info->index + 2 + count));
4001243dad0SKazutaka YOKOTA /* must be an even count */
4011243dad0SKazutaka YOKOTA info->index += 2 + count + (count & 1);
4021243dad0SKazutaka YOKOTA break;
4031243dad0SKazutaka YOKOTA }
4041243dad0SKazutaka YOKOTA }
4051243dad0SKazutaka YOKOTA }
4061243dad0SKazutaka YOKOTA }
4071243dad0SKazutaka YOKOTA
4081243dad0SKazutaka YOKOTA /*
4091243dad0SKazutaka YOKOTA ** bmp_DecodeLine
4101243dad0SKazutaka YOKOTA **
4111243dad0SKazutaka YOKOTA ** Given (info) pointing to an image being decoded, (line) being the line currently
4121243dad0SKazutaka YOKOTA ** being displayed, decode a line of data.
4131243dad0SKazutaka YOKOTA */
4141243dad0SKazutaka YOKOTA static void
bmp_DecodeLine(BMP_INFO * info,int line)4151243dad0SKazutaka YOKOTA bmp_DecodeLine(BMP_INFO *info, int line)
4161243dad0SKazutaka YOKOTA {
4171243dad0SKazutaka YOKOTA int x;
41899feb462SKazutaka YOKOTA u_char val, mask, *p;
4191243dad0SKazutaka YOKOTA
4201243dad0SKazutaka YOKOTA switch(info->format) {
4211243dad0SKazutaka YOKOTA case BI_RGB:
42299feb462SKazutaka YOKOTA switch(info->depth) {
42399feb462SKazutaka YOKOTA case 8:
4241243dad0SKazutaka YOKOTA for (x = 0; x < info->width; x++, info->index++)
4251243dad0SKazutaka YOKOTA bmp_SetPix(info, x, line, *info->index);
42661329bceSKazutaka YOKOTA info->index += 3 - (--x % 4);
4271243dad0SKazutaka YOKOTA break;
42899feb462SKazutaka YOKOTA case 4:
42999feb462SKazutaka YOKOTA p = info->index;
43099feb462SKazutaka YOKOTA for (x = 0; x < info->width; x++) {
43199feb462SKazutaka YOKOTA if (x & 1) {
43299feb462SKazutaka YOKOTA val = *p & 0xf; /* get low nybble */
43399feb462SKazutaka YOKOTA p++;
43499feb462SKazutaka YOKOTA } else {
43599feb462SKazutaka YOKOTA val = *p >> 4; /* get high nybble */
43699feb462SKazutaka YOKOTA }
43799feb462SKazutaka YOKOTA bmp_SetPix(info, x, line, val);
43899feb462SKazutaka YOKOTA }
43999feb462SKazutaka YOKOTA /* warning, this depends on integer truncation, do not hand-optimise! */
44099feb462SKazutaka YOKOTA info->index += ((x + 7) / 8) * 4;
44199feb462SKazutaka YOKOTA break;
44299feb462SKazutaka YOKOTA case 1:
44399feb462SKazutaka YOKOTA p = info->index;
44499feb462SKazutaka YOKOTA mask = 0x80;
44599feb462SKazutaka YOKOTA for (x = 0; x < info->width; x++) {
44699feb462SKazutaka YOKOTA val = (*p & mask) ? 1 : 0;
44799feb462SKazutaka YOKOTA mask >>= 1;
44899feb462SKazutaka YOKOTA if (mask == 0) {
44999feb462SKazutaka YOKOTA mask = 0x80;
45099feb462SKazutaka YOKOTA p++;
45199feb462SKazutaka YOKOTA }
45299feb462SKazutaka YOKOTA bmp_SetPix(info, x, line, val);
45399feb462SKazutaka YOKOTA }
45499feb462SKazutaka YOKOTA /* warning, this depends on integer truncation, do not hand-optimise! */
45599feb462SKazutaka YOKOTA info->index += ((x + 31) / 32) * 4;
45699feb462SKazutaka YOKOTA break;
45799feb462SKazutaka YOKOTA }
45899feb462SKazutaka YOKOTA break;
4591243dad0SKazutaka YOKOTA case BI_RLE4:
4601243dad0SKazutaka YOKOTA bmp_DecodeRLE4(info, line);
4611243dad0SKazutaka YOKOTA break;
4621243dad0SKazutaka YOKOTA case BI_RLE8:
4631243dad0SKazutaka YOKOTA bmp_DecodeRLE8(info, line);
4641243dad0SKazutaka YOKOTA break;
4651243dad0SKazutaka YOKOTA }
4661243dad0SKazutaka YOKOTA }
4671243dad0SKazutaka YOKOTA
4681243dad0SKazutaka YOKOTA /*
4691243dad0SKazutaka YOKOTA ** bmp_Init
4701243dad0SKazutaka YOKOTA **
4711243dad0SKazutaka YOKOTA ** Given a pointer (data) to the image of a BMP file, fill in bmp_info with what
4721243dad0SKazutaka YOKOTA ** can be learnt from it. Return nonzero if the file isn't usable.
4731243dad0SKazutaka YOKOTA **
4741243dad0SKazutaka YOKOTA ** Take screen dimensions (swidth), (sheight) and (sdepth) and make sure we
4751243dad0SKazutaka YOKOTA ** can work with these.
4761243dad0SKazutaka YOKOTA */
4771243dad0SKazutaka YOKOTA static int
bmp_Init(char * data,int swidth,int sheight,int sdepth)47897be736aSMaxime Henrion bmp_Init(char *data, int swidth, int sheight, int sdepth)
4791243dad0SKazutaka YOKOTA {
4801243dad0SKazutaka YOKOTA BITMAPF *bmf = (BITMAPF *)data;
4811243dad0SKazutaka YOKOTA int pind;
4821243dad0SKazutaka YOKOTA
4831243dad0SKazutaka YOKOTA bmp_info.data = NULL; /* assume setup failed */
4841243dad0SKazutaka YOKOTA
4851243dad0SKazutaka YOKOTA /* check file ID */
4861243dad0SKazutaka YOKOTA if (bmf->bmfh.bfType != 0x4d42) {
4875c539f03SKazutaka YOKOTA printf("splash_bmp: not a BMP file\n");
4881243dad0SKazutaka YOKOTA return(1); /* XXX check word ordering for big-endian ports? */
4891243dad0SKazutaka YOKOTA }
4901243dad0SKazutaka YOKOTA
4915c539f03SKazutaka YOKOTA /* do we understand this bitmap format? */
4925c539f03SKazutaka YOKOTA if (bmf->bmfi.bmiHeader.biSize > sizeof(bmf->bmfi.bmiHeader)) {
4935c539f03SKazutaka YOKOTA printf("splash_bmp: unsupported BMP format (size=%d)\n",
4945c539f03SKazutaka YOKOTA bmf->bmfi.bmiHeader.biSize);
4955c539f03SKazutaka YOKOTA return(1);
4965c539f03SKazutaka YOKOTA }
4975c539f03SKazutaka YOKOTA
4981243dad0SKazutaka YOKOTA /* save what we know about the screen */
4991243dad0SKazutaka YOKOTA bmp_info.swidth = swidth;
5001243dad0SKazutaka YOKOTA bmp_info.sheight = sheight;
5011243dad0SKazutaka YOKOTA bmp_info.sdepth = sdepth;
5021243dad0SKazutaka YOKOTA
5031243dad0SKazutaka YOKOTA /* where's the data? */
5041243dad0SKazutaka YOKOTA bmp_info.data = (u_char *)data + bmf->bmfh.bfOffBits;
5051243dad0SKazutaka YOKOTA
5061243dad0SKazutaka YOKOTA /* image parameters */
5071243dad0SKazutaka YOKOTA bmp_info.width = bmf->bmfi.bmiHeader.biWidth;
5081243dad0SKazutaka YOKOTA bmp_info.height = bmf->bmfi.bmiHeader.biHeight;
50999feb462SKazutaka YOKOTA bmp_info.depth = bmf->bmfi.bmiHeader.biBitCount;
5101243dad0SKazutaka YOKOTA bmp_info.format = bmf->bmfi.bmiHeader.biCompression;
5111243dad0SKazutaka YOKOTA
5121243dad0SKazutaka YOKOTA switch(bmp_info.format) { /* check compression format */
5131243dad0SKazutaka YOKOTA case BI_RGB:
5141243dad0SKazutaka YOKOTA case BI_RLE4:
5151243dad0SKazutaka YOKOTA case BI_RLE8:
5161243dad0SKazutaka YOKOTA break;
5171243dad0SKazutaka YOKOTA default:
5185c539f03SKazutaka YOKOTA printf("splash_bmp: unsupported compression format\n");
5191243dad0SKazutaka YOKOTA return(1); /* unsupported compression format */
5201243dad0SKazutaka YOKOTA }
5211243dad0SKazutaka YOKOTA
5221243dad0SKazutaka YOKOTA /* palette details */
5231243dad0SKazutaka YOKOTA bmp_info.ncols = (bmf->bmfi.bmiHeader.biClrUsed);
5241243dad0SKazutaka YOKOTA bzero(bmp_info.palette,sizeof(bmp_info.palette));
5251243dad0SKazutaka YOKOTA if (bmp_info.ncols == 0) { /* uses all of them */
52615401862SKazutaka YOKOTA bmp_info.ncols = 1 << bmf->bmfi.bmiHeader.biBitCount;
5271243dad0SKazutaka YOKOTA }
5281243dad0SKazutaka YOKOTA if ((bmp_info.height > bmp_info.sheight) ||
5291243dad0SKazutaka YOKOTA (bmp_info.width > bmp_info.swidth) ||
5301243dad0SKazutaka YOKOTA (bmp_info.ncols > (1 << sdepth))) {
53199feb462SKazutaka YOKOTA if (bootverbose)
53299feb462SKazutaka YOKOTA printf("splash_bmp: beyond screen capacity (%dx%d, %d colors)\n",
53399feb462SKazutaka YOKOTA bmp_info.width, bmp_info.height, bmp_info.ncols);
53499feb462SKazutaka YOKOTA return(1);
5351243dad0SKazutaka YOKOTA }
5361243dad0SKazutaka YOKOTA
5371243dad0SKazutaka YOKOTA /* read palette */
5381243dad0SKazutaka YOKOTA for (pind = 0; pind < bmp_info.ncols; pind++) {
5391243dad0SKazutaka YOKOTA bmp_info.palette[pind][0] = bmf->bmfi.bmiColors[pind].rgbRed;
5401243dad0SKazutaka YOKOTA bmp_info.palette[pind][1] = bmf->bmfi.bmiColors[pind].rgbGreen;
5411243dad0SKazutaka YOKOTA bmp_info.palette[pind][2] = bmf->bmfi.bmiColors[pind].rgbBlue;
5421243dad0SKazutaka YOKOTA }
5431243dad0SKazutaka YOKOTA return(0);
5441243dad0SKazutaka YOKOTA }
5451243dad0SKazutaka YOKOTA
5461243dad0SKazutaka YOKOTA /*
5471243dad0SKazutaka YOKOTA ** bmp_Draw
5481243dad0SKazutaka YOKOTA **
5491243dad0SKazutaka YOKOTA ** Render the image. Return nonzero if that's not possible.
5501243dad0SKazutaka YOKOTA **
5511243dad0SKazutaka YOKOTA */
5521243dad0SKazutaka YOKOTA static int
bmp_Draw(video_adapter_t * adp)5531243dad0SKazutaka YOKOTA bmp_Draw(video_adapter_t *adp)
5541243dad0SKazutaka YOKOTA {
5551243dad0SKazutaka YOKOTA int line;
556b67cb277SJohn Baldwin #if 0
55799feb462SKazutaka YOKOTA int i;
558b67cb277SJohn Baldwin #endif
5591243dad0SKazutaka YOKOTA
5601243dad0SKazutaka YOKOTA if (bmp_info.data == NULL) { /* init failed, do nothing */
5611243dad0SKazutaka YOKOTA return(1);
5621243dad0SKazutaka YOKOTA }
5631243dad0SKazutaka YOKOTA
5641243dad0SKazutaka YOKOTA /* clear the screen */
5651243dad0SKazutaka YOKOTA bmp_info.vidmem = (u_char *)adp->va_window;
566325fca90SKazutaka YOKOTA bmp_info.adp = adp;
5679336e069SWojciech A. Koszek vidd_clear(adp);
5689336e069SWojciech A. Koszek vidd_set_win_org(adp, 0);
569325fca90SKazutaka YOKOTA bmp_info.bank = 0;
5701243dad0SKazutaka YOKOTA
5711243dad0SKazutaka YOKOTA /* initialise the info structure for drawing */
5721243dad0SKazutaka YOKOTA bmp_info.index = bmp_info.data;
5731243dad0SKazutaka YOKOTA
5741243dad0SKazutaka YOKOTA /* set the palette for our image */
5759336e069SWojciech A. Koszek vidd_load_palette(adp, (u_char *)&bmp_info.palette);
5761243dad0SKazutaka YOKOTA
577168d542eSYoshihiro Takahashi #if 0
57899feb462SKazutaka YOKOTA /* XXX: this is ugly, but necessary for EGA/VGA 1bpp/4bpp modes */
57999feb462SKazutaka YOKOTA if ((adp->va_type == KD_EGA) || (adp->va_type == KD_VGA)) {
58099feb462SKazutaka YOKOTA inb(adp->va_crtc_addr + 6); /* reset flip-flop */
58199feb462SKazutaka YOKOTA outb(ATC, 0x14);
58299feb462SKazutaka YOKOTA outb(ATC, 0);
58399feb462SKazutaka YOKOTA for (i = 0; i < 16; ++i) {
58499feb462SKazutaka YOKOTA outb(ATC, i);
58599feb462SKazutaka YOKOTA outb(ATC, i);
58699feb462SKazutaka YOKOTA }
58799feb462SKazutaka YOKOTA inb(adp->va_crtc_addr + 6); /* reset flip-flop */
58899feb462SKazutaka YOKOTA outb(ATC, 0x20); /* enable palette */
58999feb462SKazutaka YOKOTA
59099feb462SKazutaka YOKOTA outw(GDCIDX, 0x0f01); /* set/reset enable */
59199feb462SKazutaka YOKOTA
59299feb462SKazutaka YOKOTA if (bmp_info.sdepth == 1)
59399feb462SKazutaka YOKOTA outw(TSIDX, 0x0102); /* unmask plane #0 */
59499feb462SKazutaka YOKOTA }
595cb4860b7SYoshihiro Takahashi #endif
59699feb462SKazutaka YOKOTA
5971243dad0SKazutaka YOKOTA for (line = 0; (line < bmp_info.height) && bmp_info.index; line++) {
5981243dad0SKazutaka YOKOTA bmp_DecodeLine(&bmp_info, line);
5991243dad0SKazutaka YOKOTA }
6001243dad0SKazutaka YOKOTA return(0);
6011243dad0SKazutaka YOKOTA }
602