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