EttinOS/src/PRINT.ASM

102 lines
1.3 KiB
NASM

cpu 8086
org 0x3000
;Load a file and print it
;Set the stack
cli
mov sp, stack + 0x100
sti
;Check for an empty tail
;Check
cmp byte [si], 0x0
jne extract
;Print an error message and abort if the tail is empty
mov si, errormsg
mov ah, 0x2
int 0x21
je done
;Find the end of the filename and add a null if needed
;Set DI at the tail
extract:
mov di, si
findend:
;Check for the string end
cmp byte [di], 0x0
je load
;Check for a space
cmp byte [di], 0x20
je addnull
inc di
jmp findend
;Add a null
addnull:
mov al, 0x0
stosb
;Load the file
;Load
load:
mov bx, stack + 0x100
mov ah, 0x2
int 0x22
;Check for errors
cmp al, 0x0
jne done
;Print the file
;Setup
mov bh, 0x0
mov bl, 0x18
mov dl, 0x50
mov si, stack + 0x100
;Decrease the character counter
print:
dec dl
;Load the current character
lodsb
;Print the character
mov ah, 0xe
int 0x10
;Check for a hard line end
cmp al, 0xa
je linecount
;Check for a soft line end
cmp dl, 0x0
je linecount
;Check paging
contprint:
cmp bl, 0x0
jz page
;Repeat for the next character
loop print
jmp done
;Decrease the line counter and reset the character one
linecount:
dec bl
mov dl, 0x50
jmp contprint
;Page
page:
push ax
mov ah, 0x0
int 0x16
cmp al, 0x1b
je done
pop ax
mov bl, 0x18
mov dl, 0x50
loop print
;Return to the system
done:
int 0x20
;Data
errormsg db "File not found", 0x0
;Stack
stack: