Merge commit 'origin/master' into nolen
[profile/ivi/syslinux.git] / font.inc
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.
10 ;;
11 ;; -----------------------------------------------------------------------
12
13 ;;
14 ;; font.inc
15 ;;
16 ;; VGA font handling code
17 ;;
18
19                 section .text
20
21 ;
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.)  It is called with
24 ;               SI and EAX set by routine searchdir
25 ;
26 loadfont:
27                 ; XXX: This can be 8K+4 bytes and the trackbuf is only
28                 ; guaranteed to be 8K in size...
29                 mov bx,trackbuf
30                 mov cx,[BufSafe]
31                 call getfssec
32
33                 mov ax,[trackbuf]               ; Magic number
34                 cmp ax,0436h
35                 jne lf_ret
36
37                 mov al,[trackbuf+2]             ; File mode
38                 cmp al,5                        ; Font modes 0-5 supported
39                 ja lf_ret
40
41                 mov bh,byte [trackbuf+3]        ; Height of font
42                 cmp bh,2                        ; VGA minimum
43                 jb lf_ret
44                 cmp bh,32                       ; VGA maximum
45                 ja lf_ret
46
47                 ; Copy to font buffer
48                 mov si,trackbuf+4               ; Start of font data
49                 mov [VGAFontSize],bh
50                 mov di,vgafontbuf
51                 mov cx,(32*256) >> 2            ; Maximum size
52                 rep movsd
53
54                 mov [UserFont], byte 1          ; Set font flag
55
56                 ; Fall through to use_font
57
58 ;
59 ; use_font:
60 ;       This routine activates whatever font happens to be in the
61 ;       vgafontbuf, and updates the adjust_screen data.
62 ;       Must be called with CS = DS = ES
63 ;
64 use_font:
65                 test byte [UsingVGA], ~03h      ; Nonstandard mode?
66                 jz .modeok
67                 call vgaclearmode
68
69 .modeok:
70                 test [UserFont], byte 1         ; Are we using a user-specified font?
71                 jz adjust_screen                ; If not, just do the normal stuff
72
73                 mov bp,vgafontbuf
74                 mov bh,[VGAFontSize]
75
76                 xor bl,bl                       ; Needed by both INT 10h calls
77
78                 test byte [UsingVGA], 01h       ; Are we in graphics mode?
79                 jz .text
80
81 .graphics:
82                 xor cx,cx
83                 mov cl,bh                       ; CX = bytes/character
84                 mov ax,[GXPixRows]
85                 div cl                          ; Compute char rows per screen
86                 mov dl,al
87                 dec ax
88                 mov [VidRows],al
89                 mov ax,1121h                    ; Set user character table
90                 int 10h
91                 mov ax,[GXPixCols]
92                 shr ax,3                        ; 8 pixels/character
93                 dec ax
94                 mov [VidCols],al
95 .lf_ret:        ret                             ; No need to call adjust_screen
96
97 .text:
98                 mov cx,256
99                 xor dx,dx
100                 mov ax,1110h
101                 int 10h                         ; Load into VGA RAM
102
103                 xor bl,bl
104                 mov ax,1103h                    ; Select page 0
105                 int 10h
106
107 lf_ret          equ use_font.lf_ret
108
109 ;
110 ; adjust_screen: Set the internal variables associated with the screen size.
111 ;               This is a subroutine in case we're loading a custom font.
112 ;
113 adjust_screen:
114                 pusha
115                 mov al,[BIOS_vidrows]
116                 and al,al
117                 jnz vidrows_ok
118                 mov al,24                       ; No vidrows in BIOS, assume 25
119                                                 ; (Remember: vidrows == rows-1)
120 vidrows_ok:     mov [VidRows],al
121                 mov ah,0fh
122                 int 10h                         ; Read video state
123                 dec ah                          ; Store count-1 (same as rows)
124                 mov [VidCols],ah
125                 popa
126                 ret
127
128                 section .bss
129 vgafontbuf      resb 8192
130
131                 section .data
132                 align 2, db 0
133 VGAFontSize     dw 16                   ; Defaults to 16 byte font
134 UserFont        db 0                    ; Using a user-specified font
135
136                 section .bss1
137                 alignb 4
138 GXPixCols       resw 1                  ; Graphics mode pixel columns
139 GXPixRows       resw 1                  ; Graphics mode pixel rows