1 /* ----------------------------------------------------------------------- *
3 * Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
4 * Copyright 2013 Intel Corporation
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 * ----------------------------------------------------------------------- */
18 * VGA font handling code
22 #include <syslinux/firmware.h>
31 __export
uint8_t UserFont
= 0; /* Using a user-specified font */
33 __export __lowmem
char fontbuf
[8192];
35 uint16_t GXPixCols
= 1; /* Graphics mode pixel columns */
36 uint16_t GXPixRows
= 1; /* Graphics mode pixel rows */
39 * loadfont: Load a .psf font file and install it onto the VGA console
40 * (if we're not on a VGA screen then ignore.)
42 __export
void loadfont(const char *filename
)
51 f
= fopen(filename
, "r");
56 if (_fread(&hdr
, sizeof hdr
, f
) != sizeof hdr
)
60 if (hdr
.magic
!= 0x0436)
63 /* File mode: font modes 0-5 supported */
67 /* VGA minimum/maximum */
68 if (hdr
.height
< 2 || hdr
.height
> 32)
71 /* Load the actual font into the font buffer. */
72 memset(fontbuf
, 0, 256*32);
73 if (_fread(fontbuf
, 256*hdr
.height
, f
) != 256*hdr
.height
)
77 VGAFontSize
= hdr
.height
;
78 UserFont
= 1; /* Set font flag */
87 * This routine activates whatever font happens to be in the
88 * vgafontbuf, and updates the bios_adjust_screen data.
89 * Must be called with CS = DS
93 com32sys_t ireg
, oreg
;
94 uint8_t bytes
= VGAFontSize
;
96 /* Nonstandard mode? */
98 syslinux_force_text_mode();
100 memset(&ireg
, 0, sizeof(ireg
));
102 ireg
.es
= SEG(fontbuf
);
103 ireg
.ebp
.w
[0] = OFFS(fontbuf
); /* ES:BP -> font */
105 /* Are we using a user-specified font? */
106 if (UserFont
& 0x1) {
107 /* Are we in graphics mode? */
108 if (UsingVGA
& 0x1) {
111 rows
= GXPixRows
/ bytes
;
114 /* Set user character table */
115 ireg
.eax
.w
[0] = 0x1121;
117 ireg
.ecx
.b
[0] = bytes
; /* bytes/character */
118 ireg
.edx
.b
[0] = rows
;
120 __intcall(0x10, &ireg
, &oreg
);
122 /* 8 pixels/character */
123 VidCols
= ((GXPixCols
>> 3) - 1);
125 /* No need to call bios_adjust_screen */
128 ireg
.eax
.w
[0] = 0x1110; /* Load into VGA RAM */
130 ireg
.ebx
.b
[1] = bytes
; /* bytes/character */
134 __intcall(0x10, &ireg
, &oreg
);
137 ireg
.eax
.w
[0] = 0x1103; /* Select page 0 */
138 __intcall(0x10, &ireg
, NULL
);
143 bios_adjust_screen();
147 * bios_adjust_screen: Set the internal variables associated with the screen size.
148 * This is a subroutine in case we're loading a custom font.
150 void bios_adjust_screen(void)
152 com32sys_t ireg
, oreg
;
153 volatile uint8_t *vidrows
= (volatile uint8_t *)BIOS_vidrows
;
159 * No vidrows in BIOS, assume 25.
160 * (Remember: vidrows == rows-1)
167 ireg
.eax
.b
[1] = 0x0f; /* Read video state */
168 __intcall(0x10, &ireg
, &oreg
);
169 cols
= oreg
.eax
.b
[1];
171 VidCols
= --cols
; /* Store count-1 (same as rows) */
174 void adjust_screen(void)
176 if (firmware
->adjust_screen
)
177 firmware
->adjust_screen();
180 void pm_adjust_screen(com32sys_t
*regs __unused
)
185 void pm_userfont(com32sys_t
*regs
)
187 regs
->es
= SEG(fontbuf
);
188 regs
->ebx
.w
[0] = OFFS(fontbuf
);