diff options
author | Greg Hartman <ghartman@google.com> | 2016-11-23 15:51:27 -0800 |
---|---|---|
committer | Greg Hartman <ghartman@google.com> | 2016-11-23 15:52:24 -0800 |
commit | 76d05dc695b06c4e987bb8078f78032441e1430c (patch) | |
tree | 7b567ae0c1fde3fd699b8839ca39b54aa1c10046 /core/font.c | |
parent | 49db3fec5f3681cf8fafd57c8987fcff2d40bc89 (diff) | |
download | syslinux-76d05dc695b06c4e987bb8078f78032441e1430c.tar.gz |
Clean checkin of the 6.03 codeandroid-wear-o-preview-4android-wear-o-preview-3android-wear-8.1.0_r1android-vts-8.1_r9android-vts-8.1_r8android-vts-8.1_r7android-vts-8.1_r6android-vts-8.1_r5android-vts-8.1_r4android-vts-8.1_r3android-vts-8.1_r14android-vts-8.1_r13android-vts-8.1_r12android-vts-8.1_r11android-vts-8.1_r10android-vts-8.0_r9android-vts-8.0_r8android-vts-8.0_r7android-vts-8.0_r6android-vts-8.0_r2android-vts-8.0_r13android-vts-8.0_r12android-vts-8.0_r11android-vts-8.0_r10android-vts-8.0_r1android-security-8.1.0_r93android-security-8.1.0_r92android-security-8.1.0_r91android-security-8.1.0_r90android-security-8.1.0_r89android-security-8.1.0_r88android-security-8.1.0_r87android-security-8.1.0_r86android-security-8.1.0_r85android-security-8.1.0_r84android-security-8.1.0_r83android-security-8.1.0_r82android-security-8.0.0_r54android-security-8.0.0_r53android-security-8.0.0_r52android-o-preview-4android-o-preview-3android-o-preview-2android-o-mr1-preview-2android-o-mr1-preview-1android-o-mr1-iot-release-smart-display-r9android-o-mr1-iot-release-smart-display-r8android-o-mr1-iot-release-smart-display-r5android-o-mr1-iot-release-smart-display-r40.1Jandroid-o-mr1-iot-release-smart-display-r4android-o-mr1-iot-release-smart-display-r39android-o-mr1-iot-release-smart-display-r30android-o-mr1-iot-release-smart-display-r3android-o-mr1-iot-release-smart-display-r22android-o-mr1-iot-release-smart-display-r14android-o-mr1-iot-release-smart-clock-r6android-o-mr1-iot-release-smart-clock-r2android-o-mr1-iot-release-smart-clock-fsiandroid-o-mr1-iot-release-smart-clock-fcsandroid-o-mr1-iot-release-cube_r2android-o-mr1-iot-release-cube-fsiandroid-o-mr1-iot-release-cube-fcsandroid-o-mr1-iot-release-1.0.8android-o-mr1-iot-release-1.0.7android-o-mr1-iot-release-1.0.5android-o-mr1-iot-release-1.0.4android-o-mr1-iot-release-1.0.3android-o-mr1-iot-release-1.0.2android-o-mr1-iot-release-1.0.14android-o-mr1-iot-release-1.0.13android-o-mr1-iot-release-1.0.12android-o-mr1-iot-release-1.0.10android-o-mr1-iot-release-1.0.1android-o-mr1-iot-release-1.0.0android-o-mr1-iot-preview-8android-o-mr1-iot-preview-7android-o-mr1-iot-preview-6android-o-iot-preview-5android-cts-8.1_r9android-cts-8.1_r8android-cts-8.1_r7android-cts-8.1_r6android-cts-8.1_r5android-cts-8.1_r4android-cts-8.1_r3android-cts-8.1_r25android-cts-8.1_r24android-cts-8.1_r23android-cts-8.1_r22android-cts-8.1_r21android-cts-8.1_r20android-cts-8.1_r2android-cts-8.1_r19android-cts-8.1_r18android-cts-8.1_r17android-cts-8.1_r16android-cts-8.1_r15android-cts-8.1_r14android-cts-8.1_r13android-cts-8.1_r12android-cts-8.1_r11android-cts-8.1_r10android-cts-8.1_r1android-cts-8.0_r9android-cts-8.0_r8android-cts-8.0_r7android-cts-8.0_r6android-cts-8.0_r5android-cts-8.0_r4android-cts-8.0_r3android-cts-8.0_r26android-cts-8.0_r25android-cts-8.0_r24android-cts-8.0_r23android-cts-8.0_r22android-cts-8.0_r21android-cts-8.0_r20android-cts-8.0_r2android-cts-8.0_r19android-cts-8.0_r18android-cts-8.0_r17android-cts-8.0_r16android-cts-8.0_r15android-cts-8.0_r14android-cts-8.0_r13android-cts-8.0_r12android-cts-8.0_r11android-cts-8.0_r10android-cts-8.0_r1android-8.1.0_r9android-8.1.0_r81android-8.1.0_r80android-8.1.0_r8android-8.1.0_r79android-8.1.0_r78android-8.1.0_r77android-8.1.0_r76android-8.1.0_r75android-8.1.0_r74android-8.1.0_r73android-8.1.0_r72android-8.1.0_r71android-8.1.0_r70android-8.1.0_r7android-8.1.0_r69android-8.1.0_r68android-8.1.0_r67android-8.1.0_r66android-8.1.0_r65android-8.1.0_r64android-8.1.0_r63android-8.1.0_r62android-8.1.0_r61android-8.1.0_r60android-8.1.0_r6android-8.1.0_r53android-8.1.0_r52android-8.1.0_r51android-8.1.0_r50android-8.1.0_r5android-8.1.0_r48android-8.1.0_r47android-8.1.0_r46android-8.1.0_r45android-8.1.0_r43android-8.1.0_r42android-8.1.0_r41android-8.1.0_r40android-8.1.0_r4android-8.1.0_r39android-8.1.0_r38android-8.1.0_r37android-8.1.0_r36android-8.1.0_r35android-8.1.0_r33android-8.1.0_r32android-8.1.0_r31android-8.1.0_r30android-8.1.0_r3android-8.1.0_r29android-8.1.0_r28android-8.1.0_r27android-8.1.0_r26android-8.1.0_r25android-8.1.0_r23android-8.1.0_r22android-8.1.0_r21android-8.1.0_r20android-8.1.0_r2android-8.1.0_r19android-8.1.0_r18android-8.1.0_r17android-8.1.0_r16android-8.1.0_r15android-8.1.0_r14android-8.1.0_r13android-8.1.0_r12android-8.1.0_r11android-8.1.0_r10android-8.1.0_r1android-8.0.0_r9android-8.0.0_r7android-8.0.0_r51android-8.0.0_r50android-8.0.0_r49android-8.0.0_r48android-8.0.0_r47android-8.0.0_r46android-8.0.0_r45android-8.0.0_r44android-8.0.0_r43android-8.0.0_r42android-8.0.0_r41android-8.0.0_r40android-8.0.0_r4android-8.0.0_r39android-8.0.0_r38android-8.0.0_r37android-8.0.0_r36android-8.0.0_r35android-8.0.0_r34android-8.0.0_r33android-8.0.0_r32android-8.0.0_r31android-8.0.0_r30android-8.0.0_r3android-8.0.0_r29android-8.0.0_r28android-8.0.0_r27android-8.0.0_r26android-8.0.0_r25android-8.0.0_r24android-8.0.0_r23android-8.0.0_r22android-8.0.0_r21android-8.0.0_r2android-8.0.0_r17android-8.0.0_r16android-8.0.0_r15android-8.0.0_r13android-8.0.0_r12android-8.0.0_r11android-8.0.0_r10android-8.0.0_r1security-oc-releasesecurity-oc-mr1-releaseoreo-vts-releaseoreo-security-releaseoreo-releaseoreo-r6-releaseoreo-r5-releaseoreo-r4-releaseoreo-r3-releaseoreo-r2-releaseoreo-mr1-wear-releaseoreo-mr1-vts-releaseoreo-mr1-security-releaseoreo-mr1-s1-releaseoreo-mr1-releaseoreo-mr1-iot-releaseoreo-mr1-devoreo-mr1-cuttlefish-testingoreo-mr1-cts-releaseoreo-mr1-1.2-iot-releaseoreo-m8-releaseoreo-m7-releaseoreo-m6-s4-releaseoreo-m6-s3-releaseoreo-m6-s2-releaseoreo-m5-releaseoreo-m4-s9-releaseoreo-m4-s8-releaseoreo-m4-s7-releaseoreo-m4-s6-releaseoreo-m4-s5-releaseoreo-m4-s4-releaseoreo-m4-s3-releaseoreo-m4-s2-releaseoreo-m4-s12-releaseoreo-m4-s11-releaseoreo-m4-s10-releaseoreo-m4-s1-releaseoreo-m3-releaseoreo-m2-s5-releaseoreo-m2-s4-releaseoreo-m2-s3-releaseoreo-m2-s2-releaseoreo-m2-s1-releaseoreo-m2-releaseoreo-dr3-releaseoreo-dr2-releaseoreo-dr1-releaseoreo-dr1-devoreo-devoreo-cts-releaseo-preview-4o-preview-3o-preview-2o-mr1-iot-preview-8o-mr1-iot-preview-7o-mr1-iot-preview-6o-iot-preview-5
BUG: 32495852
Change-Id: I5038a3bb41e217380c1188463daec07b1e9b6b48
Diffstat (limited to 'core/font.c')
-rw-r--r-- | core/font.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/core/font.c b/core/font.c new file mode 100644 index 0000000..508f705 --- /dev/null +++ b/core/font.c @@ -0,0 +1,193 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 1994-2008 H. Peter Anvin - All Rights Reserved + * Copyright 2013 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +/* + * + * font.c + * + * VGA font handling code + * + */ + +#include <syslinux/firmware.h> +#include <syslinux/video.h> +#include <sys/io.h> +#include <stdio.h> +#include <fs.h> + +#include "bios.h" +#include "graphics.h" +#include "core.h" + +__export uint8_t UserFont = 0; /* Using a user-specified font */ + +__export __lowmem char fontbuf[8192]; + +uint16_t GXPixCols = 1; /* Graphics mode pixel columns */ +uint16_t GXPixRows = 1; /* Graphics mode pixel rows */ + +/* + * loadfont: Load a .psf font file and install it onto the VGA console + * (if we're not on a VGA screen then ignore.) + */ +__export void loadfont(const char *filename) +{ + struct psfheader { + uint16_t magic; + uint8_t mode; + uint8_t height; + } hdr; + FILE *f; + + f = fopen(filename, "r"); + if (!f) + return; + + /* Read header */ + if (_fread(&hdr, sizeof hdr, f) != sizeof hdr) + goto fail; + + /* Magic number */ + if (hdr.magic != 0x0436) + goto fail; + + /* File mode: font modes 0-5 supported */ + if (hdr.mode > 5) + goto fail; + + /* VGA minimum/maximum */ + if (hdr.height < 2 || hdr.height > 32) + goto fail; + + /* Load the actual font into the font buffer. */ + memset(fontbuf, 0, 256*32); + if (_fread(fontbuf, 256*hdr.height, f) != 256*hdr.height) + goto fail; + + /* Loaded OK */ + VGAFontSize = hdr.height; + UserFont = 1; /* Set font flag */ + use_font(); + +fail: + fclose(f); +} + +/* + * use_font: + * This routine activates whatever font happens to be in the + * vgafontbuf, and updates the bios_adjust_screen data. + * Must be called with CS = DS + */ +void use_font(void) +{ + com32sys_t ireg, oreg; + uint8_t bytes = VGAFontSize; + + /* Nonstandard mode? */ + if (UsingVGA & ~0x3) + syslinux_force_text_mode(); + + memset(&ireg, 0, sizeof(ireg)); + + ireg.es = SEG(fontbuf); + ireg.ebp.w[0] = OFFS(fontbuf); /* ES:BP -> font */ + + /* Are we using a user-specified font? */ + if (UserFont & 0x1) { + /* Are we in graphics mode? */ + if (UsingVGA & 0x1) { + uint8_t rows; + + rows = GXPixRows / bytes; + VidRows = rows - 1; + + /* Set user character table */ + ireg.eax.w[0] = 0x1121; + ireg.ebx.b[0] = 0; + ireg.ecx.b[0] = bytes; /* bytes/character */ + ireg.edx.b[0] = rows; + + __intcall(0x10, &ireg, &oreg); + + /* 8 pixels/character */ + VidCols = ((GXPixCols >> 3) - 1); + + /* No need to call bios_adjust_screen */ + return; + } else { + ireg.eax.w[0] = 0x1110; /* Load into VGA RAM */ + ireg.ebx.b[0] = 0; + ireg.ebx.b[1] = bytes; /* bytes/character */ + ireg.ecx.w[0] = 256; + ireg.edx.w[0] = 0; + + __intcall(0x10, &ireg, &oreg); + + memset(&ireg, 0, sizeof(ireg)); + ireg.ebx.b[0] = 0; + ireg.eax.w[0] = 0x1103; /* Select page 0 */ + __intcall(0x10, &ireg, NULL); + } + + } + + bios_adjust_screen(); +} + +/* + * bios_adjust_screen: Set the internal variables associated with the screen size. + * This is a subroutine in case we're loading a custom font. + */ +void bios_adjust_screen(void) +{ + com32sys_t ireg, oreg; + volatile uint8_t *vidrows = (volatile uint8_t *)BIOS_vidrows; + uint8_t rows, cols; + + memset(&ireg, 0, sizeof(ireg)); + + rows = *vidrows; + if (!rows) { + /* + * No vidrows in BIOS, assume 25. + * (Remember: vidrows == rows-1) + */ + rows = 24; + } + + VidRows = rows; + + ireg.eax.b[1] = 0x0f; /* Read video state */ + __intcall(0x10, &ireg, &oreg); + cols = oreg.eax.b[1]; + + VidCols = --cols; /* Store count-1 (same as rows) */ +} + +void adjust_screen(void) +{ + if (firmware->adjust_screen) + firmware->adjust_screen(); +} + +void pm_adjust_screen(com32sys_t *regs __unused) +{ + adjust_screen(); +} + +void pm_userfont(com32sys_t *regs) +{ + regs->es = SEG(fontbuf); + regs->ebx.w[0] = OFFS(fontbuf); +} |