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 * -----------------------------------------------------------------------
28 __export
uint8_t UsingVGA
= 0;
29 uint16_t VGAPos
; /* Pointer into VGA memory */
30 __export
uint16_t *VGAFilePtr
; /* Pointer into VGAFileBuf */
31 __export
uint16_t VGAFontSize
= 16; /* Defaults to 16 byte font */
33 __export
char VGAFileBuf
[VGA_FILE_BUF_SIZE
]; /* Unmangled VGA image name */
34 __export
char VGAFileMBuf
[FILENAME_MAX
]; /* Mangled VGA image name */
36 static uint8_t VGARowBuffer
[640 + 80]; /* Decompression buffer */
37 static uint8_t VGAPlaneBuffer
[(640/8) * 4]; /* Plane buffers */
39 extern uint16_t GXPixCols
;
40 extern uint16_t GXPixRows
;
42 /* Maps colors to consecutive DAC registers */
43 static uint8_t linear_color
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
44 9, 10, 11, 12, 13, 14, 15, 0 };
49 uint32_t LSSMagic
; /* Magic number */
50 uint16_t GraphXSize
; /* Width of splash screen file */
51 uint16_t GraphYSize
; /* Height of splash screen file */
52 uint8_t GraphColorMap
[3*16];
55 static lssheader_t LSSHeader
;
57 #define LSSMagic LSSHeader.LSSMagic
58 #define GraphXSize LSSHeader.GraphXSize
59 #define GraphYSize LSSHeader.GraphYSize
62 * Enable VGA graphics, if possible. Return 0 on success.
64 static int vgasetmode(void)
66 com32sys_t ireg
, oreg
;
69 return 0; /* Nothing to do... */
71 memset(&ireg
, 0, sizeof(ireg
));
72 memset(&oreg
, 0, sizeof(oreg
));
76 * We're in VESA mode, which means VGA; use VESA call
77 * to revert the mode, and then call the conventional
78 * mode-setting for good measure...
80 ireg
.eax
.w
[0] = 0x4F02;
81 ireg
.ebx
.w
[0] = 0x0012;
82 __intcall(0x10, &ireg
, &oreg
);
84 /* Get video card and monitor */
85 ireg
.eax
.w
[0] = 0x1A00;
86 __intcall(0x10, &ireg
, &oreg
);
87 oreg
.ebx
.b
[0] -= 7; /* BL=07h and BL=08h OK */
89 if (oreg
.ebx
.b
[0] > 1)
96 ireg
.eax
.w
[0] = 0x0012; /* Set mode = 640x480 VGA 16 colors */
97 __intcall(0x10, &ireg
, &oreg
);
99 ireg
.edx
.w
[0] = (uint32_t)linear_color
;
100 ireg
.eax
.w
[0] = 0x1002; /* Write color registers */
101 __intcall(0x10, &ireg
, &oreg
);
105 /* Set GXPixCols and GXPixRows */
115 static inline char getnybble(void)
117 char data
= getc(fd
);
125 return (data
& 0x0F);
130 * Decode a pixel row in RLE16 format.
132 * 'in': input (RLE16 encoded) buffer
133 * 'out': output (decoded) buffer
134 * 'count': pixel count
136 static void rledecode(uint8_t *out
, size_t count
)
138 uint8_t prev_pixel
= 0;
144 for (i
= 0; i
< size
; i
++) {
147 if (data
== prev_pixel
)
158 /* Start of run sequence */
172 for (i
= 0; i
< data
; i
++)
182 * Convert packed-pixel to VGA bitplanes
184 * 'in': packed pixel string (640 pixels)
185 * 'out': output (four planes @ 640/8 = 80 bytes)
186 * 'count': pixel count (multiple of 8)
188 static void packedpixel2vga(const uint8_t *in
, uint8_t *out
)
192 for (i
= 0; i
< 4; i
++) {
193 const uint8_t *ip
= in
;
195 for (j
= 0; j
< 640/8; j
++) {
198 for (k
= 0; k
< 8; k
++) {
200 ob
= (ob
<< 1) | ((px
>> i
) & 1);
210 * Output four subsequent lines of VGA data
212 * 'in': four planes @ 640/8=80 bytes
213 * 'out': pointer into VGA memory
215 static void outputvga(const void *in
, void *out
)
219 /* Select the sequencer mask */
220 outb(VGA_SEQ_IX_MAP_MASK
, VGA_SEQ_ADDR
);
222 for (i
= 1; i
<= 8; i
<<= 1) {
223 /* Select the bit plane to write */
224 outb(i
, VGA_SEQ_DATA
);
225 memcpy(out
, in
, 640/8);
226 in
= (const char *)in
+ 640/8;
231 * Display a graphical splash screen.
233 __export
void vgadisplayfile(FILE *_fd
)
241 * This is a cheap and easy way to make sure the screen is
242 * cleared in case we were in graphics mode aready.
244 syslinux_force_text_mode();
248 p
= (char *)&LSSHeader
;
250 /* Load the header */
255 com32sys_t ireg
, oreg
;
259 /* The header WILL be in the first chunk. */
260 if (LSSMagic
!= 0x1413f33d)
263 memset(&ireg
, 0, sizeof(ireg
));
265 /* Color map offset */
266 ireg
.edx
.w
[0] = offsetof(lssheader_t
, GraphColorMap
);
268 ireg
.eax
.w
[0] = 0x1012; /* Set RGB registers */
269 ireg
.ebx
.w
[0] = 0; /* First register number */
270 ireg
.ecx
.w
[0] = 16; /* 16 registers */
271 __intcall(0x10, &ireg
, &oreg
);
273 /* Number of pixel rows */
274 rows
= (GraphYSize
+ VGAFontSize
) - 1;
275 rows
= rows
/ VGAFontSize
;
279 memset(&ireg
, 0, sizeof(ireg
));
281 ireg
.edx
.b
[1] = rows
;
285 /* Set cursor below image */
286 __intcall(0x10, &ireg
, &oreg
);
288 rows
= GraphYSize
; /* Number of graphics rows */
291 for (i
= 0; i
< rows
; i
++) {
292 /* Pre-clear the row buffer */
293 memset(VGARowBuffer
, 0, 640);
296 rledecode(VGARowBuffer
, GraphXSize
);
298 packedpixel2vga(VGARowBuffer
, VGAPlaneBuffer
);
299 outputvga(VGAPlaneBuffer
, MK_PTR(0xA000, VGAPos
));
306 * Disable VGA graphics.
308 __export
void syslinux_force_text_mode(void)
310 com32sys_t ireg
, oreg
;
312 /* Already in text mode? */
316 if (UsingVGA
& 0x4) {
317 /* VESA return to normal video mode */
318 memset(&ireg
, 0, sizeof(ireg
));
320 ireg
.eax
.w
[0] = 0x4F02; /* Set SuperVGA video mode */
321 ireg
.ebx
.w
[0] = 0x0003;
322 __intcall(0x10, &ireg
, &oreg
);
325 /* Return to normal video mode */
326 memset(&ireg
, 0, sizeof(ireg
));
327 ireg
.eax
.w
[0] = 0x0003;
328 __intcall(0x10, &ireg
, &oreg
);
332 ScrollAttribute
= 0x7;
333 /* Restore text font/data */
337 static void vgacursorcommon(char data
)
342 ireg
.eax
.b
[0] = data
;
343 ireg
.eax
.b
[1] = 0x09;
344 ireg
.ebx
.w
[0] = 0x0007;
346 __intcall(0x10, &ireg
, NULL
);
350 void vgahidecursor(void)
352 vgacursorcommon(' ');
355 void vgashowcursor(void)
357 vgacursorcommon('_');
360 __export
void using_vga(uint8_t vga
, uint16_t pix_cols
, uint16_t pix_rows
)
363 GXPixCols
= pix_cols
;
364 GXPixRows
= pix_rows
;
366 if (!(UsingVGA
& 0x08))
370 void pm_using_vga(com32sys_t
*regs
)
372 using_vga(regs
->eax
.b
[0], regs
->ecx
.w
[0], regs
->edx
.w
[0]);