version: Update to 4.08, update year to 2014
[syslinux/sherbszt.git] / core / font.inc
blob12236358f38da816571e852df9b0be7f4d776b1e
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
4 ;;
5 ;;   This program is free software; you can redistribute it and/or modify
6 ;;   it under the terms of the GNU General Public License as published by
7 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;;   (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
14 ;; font.inc
16 ;; VGA font handling code
19                 section .text16
22 ; loadfont:     Load a .psf font file and install it onto the VGA console
23 ;               (if we're not on a VGA screen then ignore.)
24 ;               The font is on top of the getc stack.
26 loadfont.err:   jmp close                       ; Tailcall the close routine
28 loadfont:
29                 mov di,trackbuf
30                 mov cx,4
31                 call readc                      ; Read header
32                 jc .err
34                 mov ax,[trackbuf]               ; Magic number
35                 cmp ax,0436h
36                 jne .err
38                 mov al,[trackbuf+2]             ; File mode
39                 cmp al,5                        ; Font modes 0-5 supported
40                 ja .err
42                 xor bx,bx
43                 mov bh,[trackbuf+3]             ; Height of font
44                 cmp bh,2                        ; VGA minimum
45                 jb .err
46                 cmp bh,32                       ; VGA maximum
47                 ja .err
49                 ; Load the actual font
50                 mov di,trackbuf
51                 mov cx,bx                       ; Bytes = font height * 256
52                 call readc
53                 jc .err
55                 call close
57                 ; Copy to font buffer
58                 mov si,trackbuf                 ; Start of font data
59                 mov [VGAFontSize],bh
60                 push es
61                 mov cx,aux_seg
62                 mov es,cx
63                 mov di,aux.fontbuf
64                 mov cx,bx
65                 shr cx,2
66                 rep movsd
67                 pop es
69                 mov [UserFont], byte 1          ; Set font flag
72 ; use_font:
73 ;       This routine activates whatever font happens to be in the
74 ;       vgafontbuf, and updates the adjust_screen data.
75 ;       Must be called with CS = DS
77 use_font:
78                 test byte [UsingVGA], ~03h      ; Nonstandard mode?
79                 jz .modeok
80                 call vgaclearmode
82 .modeok:
83                 test [UserFont], byte 1         ; Are we using a user-specified font?
84                 jz adjust_screen                ; If not, just do the normal stuff
86                 push es
87                 mov bp,aux_seg
88                 mov es,bp
90                 mov bp,aux.fontbuf              ; ES:BP -> font
91                 mov bh,[VGAFontSize]
92                 xor bl,bl                       ; Needed by both INT 10h calls
94                 test byte [UsingVGA], 01h       ; Are we in graphics mode?
95                 jz .text
97 .graphics:
98                 xor cx,cx
99                 mov cl,bh                       ; CX = bytes/character
100                 mov ax,[GXPixRows]
101                 div cl                          ; Compute char rows per screen
102                 mov dl,al
103                 dec ax
104                 mov [VidRows],al
105                 mov ax,1121h                    ; Set user character table
106                 int 10h
107                 mov ax,[GXPixCols]
108                 shr ax,3                        ; 8 pixels/character
109                 dec ax
110                 mov [VidCols],al
111                 pop es
112                 ret                             ; No need to call adjust_screen
114 .text:
115                 mov cx,256
116                 xor dx,dx
117                 mov ax,1110h
118                 int 10h                         ; Load into VGA RAM
119                 pop es
121                 xor bl,bl
122                 mov ax,1103h                    ; Select page 0
123                 int 10h
126 ; adjust_screen: Set the internal variables associated with the screen size.
127 ;               This is a subroutine in case we're loading a custom font.
129 adjust_screen:
130                 pusha
131                 mov al,[BIOS_vidrows]
132                 and al,al
133                 jnz vidrows_ok
134                 mov al,24                       ; No vidrows in BIOS, assume 25
135                                                 ; (Remember: vidrows == rows-1)
136 vidrows_ok:     mov [VidRows],al
137                 mov ah,0fh
138                 int 10h                         ; Read video state
139                 dec ah                          ; Store count-1 (same as rows)
140                 mov [VidCols],ah
141                 popa
142                 ret
144                 section .data16
145                 alignz 2
146 VGAFontSize     dw 16                   ; Defaults to 16 byte font
147 UserFont        db 0                    ; Using a user-specified font
149                 section .bss16
150                 alignb 4
151 GXPixCols       resw 1                  ; Graphics mode pixel columns
152 GXPixRows       resw 1                  ; Graphics mode pixel rows