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 * -----------------------------------------------------------------------
17 * VGA font handling code
29 static __lowmem
char fontbuf
[8192];
31 extern uint8_t UserFont
;
33 uint16_t GXPixCols
= 1; /* Graphics mode pixel columns */
34 uint16_t GXPixRows
= 1; /* Graphics mode pixel rows */
37 * loadfont: Load a .psf font file and install it onto the VGA console
38 * (if we're not on a VGA screen then ignore.)
40 void loadfont(const char *filename
)
51 f
= fopen(filename
, "r");
57 if (_fread(&hdr
, sizeof hdr
, f
) != sizeof hdr
)
61 if (hdr
.magic
!= 0x0436)
64 /* File mode: font modes 0-5 supported */
68 /* VGA minimum/maximum */
69 if (hdr
.height
< 2 || hdr
.height
> 32)
72 /* Load the actual font into the font buffer. */
73 memset(fontbuf
, 0, 256*32);
76 for (i
= 0; i
< 256; i
++) {
77 if (_fread(p
, hdr
.height
, f
) != hdr
.height
)
83 VGAFontSize
= hdr
.height
;
84 UserFont
= 1; /* Set font flag */
93 * This routine activates whatever font happens to be in the
94 * vgafontbuf, and updates the adjust_screen data.
95 * Must be called with CS = DS
99 com32sys_t ireg
, oreg
;
100 uint8_t bytes
= VGAFontSize
;
102 /* Nonstandard mode? */
104 syslinux_force_text_mode();
106 memset(&ireg
, 0, sizeof(ireg
));
108 ireg
.es
= SEG(fontbuf
);
109 ireg
.ebp
.w
[0] = OFFS(fontbuf
); /* ES:BP -> font */
111 /* Are we using a user-specified font? */
112 if (UserFont
& 0x1) {
113 /* Are we in graphics mode? */
114 if (UsingVGA
& 0x1) {
117 rows
= GXPixRows
/ bytes
;
120 /* Set user character table */
121 ireg
.eax
.w
[0] = 0x1121;
123 ireg
.ecx
.b
[0] = bytes
; /* bytes/character */
124 ireg
.edx
.b
[0] = rows
;
126 __intcall(0x10, &ireg
, &oreg
);
128 /* 8 pixels/character */
129 VidCols
= ((GXPixCols
>> 3) - 1);
131 /* No need to call adjust_screen */
134 ireg
.eax
.w
[0] = 0x1110; /* Load into VGA RAM */
136 ireg
.ebx
.b
[1] = bytes
; /* bytes/character */
140 __intcall(0x10, &ireg
, &oreg
);
143 ireg
.eax
.w
[0] = 0x1103; /* Select page 0 */
144 __intcall(0x10, &ireg
, NULL
);
152 * adjust_screen: Set the internal variables associated with the screen size.
153 * This is a subroutine in case we're loading a custom font.
155 void adjust_screen(void)
157 com32sys_t ireg
, oreg
;
158 volatile uint8_t *vidrows
= (volatile uint8_t *)BIOS_vidrows
;
164 * No vidrows in BIOS, assume 25.
165 * (Remember: vidrows == rows-1)
172 ireg
.eax
.b
[1] = 0x0f; /* Read video state */
173 __intcall(0x10, &ireg
, &oreg
);
174 cols
= oreg
.eax
.b
[1];
176 VidCols
= --cols
; /* Store count-1 (same as rows) */
179 void pm_adjust_screen(com32sys_t
*regs __unused
)
184 void pm_userfont(com32sys_t
*regs
)
186 regs
->es
= SEG(fontbuf
);
187 regs
->ebx
.w
[0] = OFFS(fontbuf
);