EttinOS/src/PRINT.ASM

100 lines
1.3 KiB
NASM
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 start
;Print an error message and abort if the tail is empty
mov si, errormsg
mov ah, 0x2
int 0x21
je done
start:
;Find the end of the filename and add a null if needed
;Set DI at the tail
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
addnull:
mov al, 0x0
stosb
;Load the file
load:
;Load
mov bx, stack + 0x100
mov ah, 0x0
int 0x22
;Check for errors
cmp al, 0x1
je done
;Print the file
;Setup
mov bh, 0x0
mov bl, 0x18
mov cl, 0x50
mov si, stack + 0x100
print:
;Decrease the character counter
dec cl
;Load the current character
lodsb
;Check for the string end
cmp al, 0x0
je done
;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 cl, 0x0
je linecount
contprint:
;Check paging
cmp bl, 0x0
jz page
;Repeat for the next character
jmp print
;Decrease the line counter and reset the character one
linecount:
dec bl
mov cl, 0x50
jmp contprint
;Page
page:
push ax
mov ah, 0x0
int 0x16
pop ax
mov bl, 0x18
mov cl, 0x50
jmp print
done:
int 0x20
;Data
errormsg db "File not found", 0x0
stack: