2 * -----------------------------------------------------------------------
4 * Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 * Boston MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * -----------------------------------------------------------------------
14 * -----------------------------------------------------------------------
15 * VGA splash screen code
16 * -----------------------------------------------------------------------
27 uint16_t VGAPos
; /* Pointer into VGA memory */
28 uint16_t *VGAFilePtr
; /* Pointer into VGAFileBuf */
30 char VGAFileBuf
[VGA_FILE_BUF_SIZE
]; /* Unmangled VGA image name */
31 char VGAFileMBuf
[FILENAME_MAX
]; /* Mangled VGA image name */
33 static uint8_t VGARowBuffer
[640 + 80]; /* Decompression buffer */
34 static uint8_t VGAPlaneBuffer
[(640/8) * 4]; /* Plane buffers */
36 extern uint16_t GXPixCols
;
37 extern uint16_t GXPixRows
;
39 /* Maps colors to consecutive DAC registers */
40 static uint8_t linear_color
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
41 9, 10, 11, 12, 13, 14, 15, 0 };
46 uint32_t LSSMagic
; /* Magic number */
47 uint16_t GraphXSize
; /* Width of splash screen file */
48 uint16_t GraphYSize
; /* Height of splash screen file */
49 uint8_t GraphColorMap
[3*16];
52 static lssheader_t LSSHeader
;
54 #define LSSMagic LSSHeader.LSSMagic
55 #define GraphXSize LSSHeader.GraphXSize
56 #define GraphYSize LSSHeader.GraphYSize
59 * Enable VGA graphics, if possible. Return 0 on success.
61 static int vgasetmode(void)
63 com32sys_t ireg
, oreg
;
66 return 0; /* Nothing to do... */
68 memset(&ireg
, 0, sizeof(ireg
));
69 memset(&oreg
, 0, sizeof(oreg
));
73 * We're in VESA mode, which means VGA; use VESA call
74 * to revert the mode, and then call the conventional
75 * mode-setting for good measure...
77 ireg
.eax
.w
[0] = 0x4F02;
78 ireg
.ebx
.w
[0] = 0x0012;
79 __intcall(0x10, &ireg
, &oreg
);
81 /* Get video card and monitor */
82 ireg
.eax
.w
[0] = 0x1A00;
83 __intcall(0x10, &ireg
, &oreg
);
84 oreg
.ebx
.b
[0] -= 7; /* BL=07h and BL=08h OK */
86 if (oreg
.ebx
.b
[0] > 1)
93 ireg
.eax
.w
[0] = 0x0012; /* Set mode = 640x480 VGA 16 colors */
94 __intcall(0x10, &ireg
, &oreg
);
96 ireg
.edx
.w
[0] = (uint32_t)linear_color
;
97 ireg
.eax
.w
[0] = 0x1002; /* Write color registers */
98 __intcall(0x10, &ireg
, &oreg
);
102 /* Set GXPixCols and GXPixRows */
112 static inline char getnybble(void)
114 char data
= getc(fd
);
122 return (data
& 0x0F);
127 * Decode a pixel row in RLE16 format.
129 * 'in': input (RLE16 encoded) buffer
130 * 'out': output (decoded) buffer
131 * 'count': pixel count
133 static void rledecode(uint8_t *out
, size_t count
)
135 uint8_t prev_pixel
= 0;
141 for (i
= 0; i
< size
; i
++) {
144 if (data
== prev_pixel
)
155 /* Start of run sequence */
169 for (i
= 0; i
< data
; i
++)
179 * Convert packed-pixel to VGA bitplanes
181 * 'in': packed pixel string (640 pixels)
182 * 'out': output (four planes @ 640/8 = 80 bytes)
183 * 'count': pixel count (multiple of 8)
185 static void packedpixel2vga(const uint8_t *in
, uint8_t *out
)
189 for (i
= 0; i
< 4; i
++) {
190 const uint8_t *ip
= in
;
192 for (j
= 0; j
< 640/8; j
++) {
195 for (k
= 0; k
< 8; k
++) {
197 ob
= (ob
<< 1) | ((px
>> i
) & 1);
207 * Output four subsequent lines of VGA data
209 * 'in': four planes @ 640/8=80 bytes
210 * 'out': pointer into VGA memory
212 static void outputvga(const void *in
, void *out
)
216 /* Select the sequencer mask */
217 outb(VGA_SEQ_IX_MAP_MASK
, VGA_SEQ_ADDR
);
219 for (i
= 1; i
<= 8; i
<<= 1) {
220 /* Select the bit plane to write */
221 outb(i
, VGA_SEQ_DATA
);
222 memcpy(out
, in
, 640/8);
223 in
= (const char *)in
+ 640/8;
228 * Display a graphical splash screen.
230 void vgadisplayfile(FILE *_fd
)
238 * This is a cheap and easy way to make sure the screen is
239 * cleared in case we were in graphics mode aready.
245 p
= (char *)&LSSHeader
;
247 /* Load the header */
252 com32sys_t ireg
, oreg
;
256 /* The header WILL be in the first chunk. */
257 if (LSSMagic
!= 0x1413f33d)
260 memset(&ireg
, 0, sizeof(ireg
));
262 /* Color map offset */
263 ireg
.edx
.w
[0] = offsetof(lssheader_t
, GraphColorMap
);
265 ireg
.eax
.w
[0] = 0x1012; /* Set RGB registers */
266 ireg
.ebx
.w
[0] = 0; /* First register number */
267 ireg
.ecx
.w
[0] = 16; /* 16 registers */
268 __intcall(0x10, &ireg
, &oreg
);
270 /* Number of pixel rows */
271 rows
= (GraphYSize
+ VGAFontSize
) - 1;
272 rows
= rows
/ VGAFontSize
;
276 memset(&ireg
, 0, sizeof(ireg
));
278 ireg
.edx
.b
[1] = rows
;
282 /* Set cursor below image */
283 __intcall(0x10, &ireg
, &oreg
);
285 rows
= GraphYSize
; /* Number of graphics rows */
288 for (i
= 0; i
< rows
; i
++) {
289 /* Pre-clear the row buffer */
290 memset(VGARowBuffer
, 0, 640);
293 rledecode(VGARowBuffer
, GraphXSize
);
295 packedpixel2vga(VGARowBuffer
, VGAPlaneBuffer
);
296 outputvga(VGAPlaneBuffer
, MK_PTR(0xA000, VGAPos
));
303 * Disable VGA graphics.
305 void vgaclearmode(void)
307 com32sys_t ireg
, oreg
;
309 /* Already in text mode? */
313 if (UsingVGA
& 0x4) {
314 /* VESA return to normal video mode */
315 memset(&ireg
, 0, sizeof(ireg
));
317 ireg
.eax
.w
[0] = 0x4F02; /* Set SuperVGA video mode */
318 ireg
.ebx
.w
[0] = 0x0003;
319 __intcall(0x10, &ireg
, &oreg
);
322 /* Return to normal video mode */
323 memset(&ireg
, 0, sizeof(ireg
));
324 ireg
.eax
.w
[0] = 0x0003;
325 __intcall(0x10, &ireg
, &oreg
);
329 ScrollAttribute
= 0x7;
330 /* Restore text font/data */
334 static void vgacursorcommon(char data
)
339 ireg
.eax
.b
[0] = data
;
340 ireg
.eax
.b
[1] = 0x09;
341 ireg
.ebx
.w
[0] = 0x0007;
343 __intcall(0x10, &ireg
, NULL
);
347 void vgahidecursor(void)
349 vgacursorcommon(' ');
352 void vgashowcursor(void)
354 vgacursorcommon('_');
357 void using_vga(uint8_t vga
, uint16_t pix_cols
, uint16_t pix_rows
)
360 GXPixCols
= pix_cols
;
361 GXPixRows
= pix_rows
;
363 if (!(UsingVGA
& 0x08))
367 void pm_using_vga(com32sys_t
*regs
)
369 using_vga(regs
->eax
.b
[0], regs
->ecx
.w
[0], regs
->edx
.w
[0]);