summaryrefslogtreecommitdiff
path: root/ldlinux.asm
diff options
context:
space:
mode:
authorhpa <hpa>2002-04-26 22:17:52 +0000
committerhpa <hpa>2002-04-26 22:17:52 +0000
commitc423d62e97df05b5ebdf2dbba2ac15349b78c51c (patch)
tree794fafb372db04940305be2522954c670c6a9dee /ldlinux.asm
parent62ca92287e71450514018da90a00da6392ec25b2 (diff)
downloadsyslinux-c423d62e97df05b5ebdf2dbba2ac15349b78c51c.tar.gz
More common code factoring: getc library, font handling code
Diffstat (limited to 'ldlinux.asm')
-rw-r--r--ldlinux.asm358
1 files changed, 2 insertions, 356 deletions
diff --git a/ldlinux.asm b/ldlinux.asm
index 33339379..dde41035 100644
--- a/ldlinux.asm
+++ b/ldlinux.asm
@@ -2881,102 +2881,6 @@ dir_success:
mov bx,ax
or bx,dx ; Sets ZF iff DX:AX is zero
dir_return:
-lf_ret: ret
-
-;
-; loadfont: Load a .psf font file and install it onto the VGA console
-; (if we're not on a VGA screen then ignore.) It is called with
-; SI and DX:AX set by routine searchdir
-;
-loadfont:
- mov bx,trackbuf ; The trackbuf is >= 16K; the part
- mov cx,[BufSafe] ; of a PSF file we care about is no
- call getfssec ; more than 8K+4 bytes
-
- mov ax,[trackbuf] ; Magic number
- cmp ax,0436h
- jne lf_ret
-
- mov al,[trackbuf+2] ; File mode
- cmp al,5 ; Font modes 0-5 supported
- ja lf_ret
-
- mov bh,byte [trackbuf+3] ; Height of font
- cmp bh,2 ; VGA minimum
- jb lf_ret
- cmp bh,32 ; VGA maximum
- ja lf_ret
-
- ; Copy to font buffer
- mov si,trackbuf+4 ; Start of font data
- mov [VGAFontSize],bh
- mov di,vgafontbuf
- mov cx,(32*256) >> 2 ; Maximum size
- rep movsd
-
- mov [UserFont], byte 1 ; Set font flag
-
- ; Fall through to use_font
-
-;
-; use_font:
-; This routine activates whatever font happens to be in the
-; vgafontbuf, and updates the adjust_screen data.
-; Must be called with CS = DS = ES
-;
-use_font:
- test [UserFont], byte 1 ; Are we using a user-specified font?
- jz adjust_screen ; If not, just do the normal stuff
-
- mov bp,vgafontbuf
- mov bh,[VGAFontSize]
-
- xor bl,bl ; Needed by both INT 10h calls
- cmp [UsingVGA], byte 1 ; Are we in graphics mode?
- jne .text
-
-.graphics:
- xor cx,cx
- mov cl,bh ; CX = bytes/character
- mov ax,480
- div cl ; Compute char rows per screen
- mov dl,al
- dec al
- mov [VidRows],al
- mov ax,1121h ; Set user character table
- int 10h
- mov [VidCols], byte 79 ; Always 80 bytes/line
- mov [TextPage], byte 0 ; Always page 0
- ret ; No need to call adjust_screen
-
-.text:
- mov cx,256
- xor dx,dx
- mov ax,1110h
- int 10h ; Load into VGA RAM
-
- xor bl,bl
- mov ax,1103h ; Select page 0
- int 10h
-
- ; Fall through to adjust_screen
-
-;
-; adjust_screen: Set the internal variables associated with the screen size.
-; This is a subroutine in case we're loading a custom font.
-;
-adjust_screen:
- mov al,[BIOS_vidrows]
- and al,al
- jnz vidrows_ok
- mov al,24 ; No vidrows in BIOS, assume 25
- ; (Remember: vidrows == rows-1)
-vidrows_ok: mov [VidRows],al
- mov ah,0fh
- int 10h ; Read video state
- mov [TextPage],bh
- dec ah ; Store count-1 (same as rows)
- mov [VidCols],ah
ret
;
@@ -3407,102 +3311,6 @@ kaboom2:
.norge: jmp short .norge ; If int 19h returned; this is the end
;
-; open,getc: Load a file a character at a time for parsing in a manner
-; similar to the C library getc routine. Only one simultaneous
-; use is supported. Note: "open" trashes the trackbuf.
-;
-; open: Input: mangled filename in DS:DI
-; Output: ZF set on file not found or zero length
-;
-; getc: Output: CF set on end of file
-; Character loaded in AL
-;
-open:
- call searchdir
- jz open_return
- pushf
- mov [FBytes1],ax
- mov [FBytes2],dx
- add ax,[ClustSize]
- adc dx,byte 0
- sub ax,byte 1
- sbb dx,byte 0
- div word [ClustSize]
- mov [FClust],ax ; Number of clusters
- mov [FNextClust],si ; Cluster pointer
- mov ax,[EndOfGetCBuf] ; Pointer at end of buffer ->
- mov [FPtr],ax ; nothing loaded yet
- popf ; Restore no ZF
-open_return: ret
-
-getc:
- stc ; If we exit here -> EOF
- mov ecx,[FBytes]
- jecxz getc_ret
- mov si,[FPtr]
- cmp si,[EndOfGetCBuf]
- jb getc_loaded
- ; Buffer empty -- load another set
- mov cx,[FClust]
- cmp cx,[BufSafe]
- jna getc_oksize
- mov cx,[BufSafe]
-getc_oksize: sub [FClust],cx ; Reduce remaining clusters
- mov si,[FNextClust]
- push es ; ES may be != DS, save old ES
- push ds
- pop es
- mov bx,getcbuf
- push bx
- call getfssec ; Load a trackbuf full of data
- mov [FNextClust],si ; Store new next pointer
- pop si ; SI -> newly loaded data
- pop es ; Restore ES
-getc_loaded: lodsb ; Load a byte
- mov [FPtr],si ; Update next byte pointer
- dec dword [FBytes] ; Update bytes left counter
- clc ; Not EOF
-getc_ret: ret
-
-;
-; ungetc: Push a character (in AL) back into the getc buffer
-; Note: if more than one byte is pushed back, this may cause
-; bytes to be written below the getc buffer boundary. If there
-; is a risk for this to occur, the getcbuf base address should
-; be moved up.
-;
-ungetc:
- mov si,[FPtr]
- dec si
- mov [si],al
- mov [FPtr],si
- inc dword [FBytes]
- ret
-
-;
-; skipspace: Skip leading whitespace using "getc". If we hit end-of-line
-; or end-of-file, return with carry set; ZF = true of EOF
-; ZF = false for EOLN; otherwise CF = ZF = 0.
-;
-; Otherwise AL = first character after whitespace
-;
-skipspace:
-skipspace_loop: call getc
- jc skipspace_eof
- cmp al,1Ah ; DOS EOF
- je skipspace_eof
- cmp al,0Ah
- je skipspace_eoln
- cmp al,' '
- jbe skipspace_loop
- ret ; CF = ZF = 0
-skipspace_eof: cmp al,al ; Set ZF
- stc ; Set CF
- ret
-skipspace_eoln: add al,0FFh ; Set CF, clear ZF
- ret
-
-;
; getkeyword: Get a keyword from the current "getc" file; only the two
; first characters are considered significant.
;
@@ -3561,170 +3369,6 @@ gkw_skipline: cmp al,10 ; Scan for LF
jmp short gkw_skipline
;
-; getint: Load an integer from the getc file.
-; Return CF if error; otherwise return integer in EBX
-;
-getint:
- mov di,NumBuf
-gi_getnum: cmp di,NumBufEnd ; Last byte in NumBuf
- jae gi_loaded
- push di
- call getc
- pop di
- jc gi_loaded
- stosb
- cmp al,'-'
- jnb gi_getnum
- call ungetc ; Unget non-numeric
-gi_loaded: mov byte [di],0
- mov si,NumBuf
- ; Fall through to parseint
-
-;
-; parseint: Convert an integer to a number in EBX
-; Get characters from string in DS:SI
-; Return CF on error
-; DS:SI points to first character after number
-;
-; Syntaxes accepted: [-]dec, [-]0+oct, [-]0x+hex, val+K, val+M
-;
-parseint:
- push eax
- push ecx
- push bp
- xor eax,eax ; Current digit (keep eax == al)
- mov ebx,eax ; Accumulator
- mov ecx,ebx ; Base
- xor bp,bp ; Used for negative flag
-pi_begin: lodsb
- cmp al,'-'
- jne pi_not_minus
- xor bp,1 ; Set unary minus flag
- jmp short pi_begin
-pi_not_minus:
- cmp al,'0'
- jb pi_err
- je pi_octhex
- cmp al,'9'
- ja pi_err
- mov cl,10 ; Base = decimal
- jmp short pi_foundbase
-pi_octhex:
- lodsb
- cmp al,'0'
- jb pi_km ; Value is zero
- or al,20h ; Downcase
- cmp al,'x'
- je pi_ishex
- cmp al,'7'
- ja pi_err
- mov cl,8 ; Base = octal
- jmp short pi_foundbase
-pi_ishex:
- mov al,'0' ; No numeric value accrued yet
- mov cl,16 ; Base = hex
-pi_foundbase:
- call unhexchar
- jc pi_km ; Not a (hex) digit
- cmp al,cl
- jae pi_km ; Invalid for base
- imul ebx,ecx ; Multiply accumulated by base
- add ebx,eax ; Add current digit
- lodsb
- jmp short pi_foundbase
-pi_km:
- dec si ; Back up to last non-numeric
- lodsb
- or al,20h
- cmp al,'k'
- je pi_isk
- cmp al,'m'
- je pi_ism
- dec si ; Back up
-pi_fini: and bp,bp
- jz pi_ret ; CF=0!
- neg ebx ; Value was negative
-pi_done: clc
-pi_ret: pop bp
- pop ecx
- pop eax
- ret
-pi_err: stc
- jmp short pi_ret
-pi_isk: shl ebx,10 ; x 2^10
- jmp short pi_done
-pi_ism: shl ebx,20 ; x 2^20
- jmp short pi_done
-
-;
-; unhexchar: Convert a hexadecimal digit in AL to the equivalent number;
-; return CF=1 if not a hex digit
-;
-unhexchar:
- cmp al,'0'
- jb uxc_ret ; If failure, CF == 1 already
- cmp al,'9'
- ja uxc_1
- sub al,'0' ; CF <- 0
- ret
-uxc_1: or al,20h ; upper case -> lower case
- cmp al,'a'
- jb uxc_ret ; If failure, CF == 1 already
- cmp al,'f'
- ja uxc_err
- sub al,'a'-10 ; CF <- 0
- ret
-uxc_err: stc
-uxc_ret: ret
-
-;
-;
-; getline: Get a command line, converting control characters to spaces
-; and collapsing streches to one; a space is appended to the
-; end of the string, unless the line is empty.
-; The line is terminated by ^J, ^Z or EOF and is written
-; to ES:DI. On return, DI points to first char after string.
-; CF is set if we hit EOF.
-;
-getline:
- call skipspace
- mov dl,1 ; Empty line -> empty string.
- jz gl_eof ; eof
- jc gl_eoln ; eoln
- call ungetc
-gl_fillloop: push dx
- push di
- call getc
- pop di
- pop dx
- jc gl_ret ; CF set!
- cmp al,' '
- jna gl_ctrl
- xor dx,dx
-gl_store: stosb
- jmp short gl_fillloop
-gl_ctrl: cmp al,10
- je gl_ret ; CF clear!
- cmp al,26
- je gl_eof
- and dl,dl
- jnz gl_fillloop ; Ignore multiple spaces
- mov al,' ' ; Ctrl -> space
- inc dx
- jmp short gl_store
-gl_eoln: clc ; End of line is not end of file
- jmp short gl_ret
-gl_eof: stc
-gl_ret: pushf ; We want the last char to be space!
- and dl,dl
- jnz gl_xret
- mov al,' '
- stosb
-gl_xret: popf
- ret
-
-
-;
; mangle_name: Mangle a DOS filename pointed to by DS:SI into a buffer pointed
; to by ES:DI; ends on encountering any whitespace
;
@@ -3838,6 +3482,8 @@ lc_ret: ret
; Common modules
; -----------------------------------------------------------------------------
+%include "getc.inc" ; getc et al
+%include "font.inc" ; VGA font stuff
%include "graphics.inc" ; VGA graphics
; -----------------------------------------------------------------------------