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 #include <syslinux/video.h>
29 __export
uint8_t UsingVGA
= 0;
30 uint16_t VGAPos
; /* Pointer into VGA memory */
31 __export
uint16_t *VGAFilePtr
; /* Pointer into VGAFileBuf */
32 __export
uint16_t VGAFontSize
= 16; /* Defaults to 16 byte font */
34 __export
char VGAFileBuf
[VGA_FILE_BUF_SIZE
]; /* Unmangled VGA image name */
35 __export
char VGAFileMBuf
[FILENAME_MAX
]; /* Mangled VGA image name */
37 static uint8_t VGARowBuffer
[640 + 80]; /* Decompression buffer */
38 static uint8_t VGAPlaneBuffer
[(640/8) * 4]; /* Plane buffers */
40 extern uint16_t GXPixCols
;
41 extern uint16_t GXPixRows
;
43 /* Maps colors to consecutive DAC registers */
44 static uint8_t linear_color
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
45 9, 10, 11, 12, 13, 14, 15, 0 };
50 uint32_t LSSMagic
; /* Magic number */
51 uint16_t GraphXSize
; /* Width of splash screen file */
52 uint16_t GraphYSize
; /* Height of splash screen file */
53 uint8_t GraphColorMap
[3*16];
56 static lssheader_t LSSHeader
;
58 #define LSSMagic LSSHeader.LSSMagic
59 #define GraphXSize LSSHeader.GraphXSize
60 #define GraphYSize LSSHeader.GraphYSize
63 * Enable VGA graphics, if possible. Return 0 on success.
65 static int vgasetmode(void)
67 com32sys_t ireg
, oreg
;
70 return 0; /* Nothing to do... */
72 memset(&ireg
, 0, sizeof(ireg
));
73 memset(&oreg
, 0, sizeof(oreg
));
77 * We're in VESA mode, which means VGA; use VESA call
78 * to revert the mode, and then call the conventional
79 * mode-setting for good measure...
81 ireg
.eax
.w
[0] = 0x4F02;
82 ireg
.ebx
.w
[0] = 0x0012;
83 __intcall(0x10, &ireg
, &oreg
);
85 /* Get video card and monitor */
86 ireg
.eax
.w
[0] = 0x1A00;
87 __intcall(0x10, &ireg
, &oreg
);
88 oreg
.ebx
.b
[0] -= 7; /* BL=07h and BL=08h OK */
90 if (oreg
.ebx
.b
[0] > 1)
97 memset(&ireg
, 0, sizeof(ireg
));
98 ireg
.eax
.w
[0] = 0x0012; /* Set mode = 640x480 VGA 16 colors */
99 __intcall(0x10, &ireg
, &oreg
);
101 memset(&ireg
, 0, sizeof(ireg
));
102 ireg
.edx
.w
[0] = (uint32_t)linear_color
;
103 ireg
.eax
.w
[0] = 0x1002; /* Write color registers */
104 __intcall(0x10, &ireg
, &oreg
);
108 /* Set GXPixCols and GXPixRows */
118 static inline char getnybble(void)
120 char data
= getc(fd
);
128 return (data
& 0x0F);
133 * Decode a pixel row in RLE16 format.
135 * 'in': input (RLE16 encoded) buffer
136 * 'out': output (decoded) buffer
137 * 'count': pixel count
139 static void rledecode(uint8_t *out
, size_t count
)
141 uint8_t prev_pixel
= 0;
147 for (i
= 0; i
< size
; i
++) {
150 if (data
== prev_pixel
)
161 /* Start of run sequence */
175 for (i
= 0; i
< data
; i
++)
185 * Convert packed-pixel to VGA bitplanes
187 * 'in': packed pixel string (640 pixels)
188 * 'out': output (four planes @ 640/8 = 80 bytes)
189 * 'count': pixel count (multiple of 8)
191 static void packedpixel2vga(const uint8_t *in
, uint8_t *out
)
195 for (i
= 0; i
< 4; i
++) {
196 const uint8_t *ip
= in
;
198 for (j
= 0; j
< 640/8; j
++) {
201 for (k
= 0; k
< 8; k
++) {
203 ob
= (ob
<< 1) | ((px
>> i
) & 1);
213 * Output four subsequent lines of VGA data
215 * 'in': four planes @ 640/8=80 bytes
216 * 'out': pointer into VGA memory
218 static void outputvga(const void *in
, void *out
)
222 /* Select the sequencer mask */
223 outb(VGA_SEQ_IX_MAP_MASK
, VGA_SEQ_ADDR
);
225 for (i
= 1; i
<= 8; i
<<= 1) {
226 /* Select the bit plane to write */
227 outb(i
, VGA_SEQ_DATA
);
228 memcpy(out
, in
, 640/8);
229 in
= (const char *)in
+ 640/8;
234 * Display a graphical splash screen.
236 __export
void vgadisplayfile(FILE *_fd
)
244 * This is a cheap and easy way to make sure the screen is
245 * cleared in case we were in graphics mode aready.
247 syslinux_force_text_mode();
251 p
= (char *)&LSSHeader
;
253 /* Load the header */
258 com32sys_t ireg
, oreg
;
262 /* The header WILL be in the first chunk. */
263 if (LSSMagic
!= 0x1413f33d)
266 memset(&ireg
, 0, sizeof(ireg
));
268 /* Color map offset */
269 ireg
.edx
.w
[0] = offsetof(lssheader_t
, GraphColorMap
);
271 ireg
.eax
.w
[0] = 0x1012; /* Set RGB registers */
272 ireg
.ebx
.w
[0] = 0; /* First register number */
273 ireg
.ecx
.w
[0] = 16; /* 16 registers */
274 __intcall(0x10, &ireg
, &oreg
);
276 /* Number of pixel rows */
277 rows
= (GraphYSize
+ VGAFontSize
) - 1;
278 rows
= rows
/ VGAFontSize
;
282 memset(&ireg
, 0, sizeof(ireg
));
284 ireg
.edx
.b
[1] = rows
;
288 /* Set cursor below image */
289 __intcall(0x10, &ireg
, &oreg
);
291 rows
= GraphYSize
; /* Number of graphics rows */
294 for (i
= 0; i
< rows
; i
++) {
295 /* Pre-clear the row buffer */
296 memset(VGARowBuffer
, 0, 640);
299 rledecode(VGARowBuffer
, GraphXSize
);
301 packedpixel2vga(VGARowBuffer
, VGAPlaneBuffer
);
302 outputvga(VGAPlaneBuffer
, MK_PTR(0xA000, VGAPos
));
309 * Disable VGA graphics.
311 __export
void syslinux_force_text_mode(void)
313 com32sys_t ireg
, oreg
;
315 /* Already in text mode? */
319 if (UsingVGA
& 0x4) {
320 /* VESA return to normal video mode */
321 memset(&ireg
, 0, sizeof(ireg
));
323 ireg
.eax
.w
[0] = 0x4F02; /* Set SuperVGA video mode */
324 ireg
.ebx
.w
[0] = 0x0003;
325 __intcall(0x10, &ireg
, &oreg
);
328 /* Return to normal video mode */
329 memset(&ireg
, 0, sizeof(ireg
));
330 ireg
.eax
.w
[0] = 0x0003;
331 __intcall(0x10, &ireg
, &oreg
);
335 ScrollAttribute
= 0x7;
336 /* Restore text font/data */
340 static void vgacursorcommon(char data
)
344 memset(&ireg
, 0, sizeof(ireg
));
346 ireg
.eax
.b
[0] = data
;
347 ireg
.eax
.b
[1] = 0x09;
348 ireg
.ebx
.w
[0] = 0x0007;
350 __intcall(0x10, &ireg
, NULL
);
354 void vgahidecursor(void)
356 vgacursorcommon(' ');
359 void vgashowcursor(void)
361 vgacursorcommon('_');
364 __export
void using_vga(uint8_t vga
, uint16_t pix_cols
, uint16_t pix_rows
)
367 GXPixCols
= pix_cols
;
368 GXPixRows
= pix_rows
;
370 if (!(UsingVGA
& 0x08))
374 void pm_using_vga(com32sys_t
*regs
)
376 using_vga(regs
->eax
.b
[0], regs
->ecx
.w
[0], regs
->edx
.w
[0]);