rdos/com/a86.asm

145 lines
2.1 KiB
NASM

org 0x100
jmp init
fcb1 equ 0x5C
eof equ 0x1A
stack equ 0x10 ; stack size
dumpax push ax
push cx
push dx
mov dx, ax
call dmpdx0
mov al, 0x0A
call dmpdx3
mov al, 0x0D
call dmpdx3
pop dx
pop cx
pop ax
ret
dmpdx0 mov ah, 0xe
mov cl, 4
; this double-call is essentially a 4 times repeating loop
call dmpdx1
dmpdx1: call dmpdx2
dmpdx2: ; grab highest nibble from dx
mov al, dh
; remove highest nibble from dx
shl dx, cl
; shift away second-highest nibble that we accidentally copied
shr al, cl
; map 0-9 to ascii codes for '0' to '9'
add al, 0x30
; if result is larger than '9', ...
cmp al, 0x3a
jl dmpdx3
; ... add 7 so we continue at 'A'
add al, 7
dmpdx3: int 0x10
ret
free dw 0 ; free ram size
lncnt dw 0 ; line count
rdptr dw 0xFFFF ; infile blk ptr
getc mov bx, [rdptr]
cmp bx, 0x80
jc l01
mov ah, 0x14
mov dx, fcb1
int 0x21
cmp al, 1
je l02
mov bx, 0
l01 mov al, [0x80+bx]
cmp al, eof
je l02
cmp al, 0
je l02
cmp al, 0x0A
jne l01b
inc word [lncnt]
l01b inc bx
mov [rdptr], bx
jmp l03
l02 mov al, 0x1A
l03 cmp al, eof
ret
newlin mov dl, 0x0A
mov ah, 2
int 0x21
mov dl, 0x0D
int 0x21
ret
error mov dl, [bx]
mov ah, 2
int 0x21
inc bx
cmp dl, 0x20
jne error
mov ax, [lncnt]
call dumpax
call newlin
int 0x20
e_eof db "EOF "
e_dup db "DUPSYM "
tok1:
s_ws db " " ; also used for tabs
s_com db ","
s_obr db "["
s_cbr db "]"
s_plu db "+"
s_min db "-"
align 2
tok2:
reg8 db "AL","CL","DL","BL","AH","CH","DH","BH"
reg16 db "AX","CX","DX","BX","SP","BP","SI","DI"
sreg db "ES","CS","SS","DS"
s_db db "DB"
s_dw db "DW"
tok3:
s_org db "ORG"
s_equ db "EQU"
; TODO: parse a line into wordlist of tokens and ptrs to strings
rline: ret
; clear symbol table
main mov byte [init], 0
call rline
int 0x20
align 16
; stuff behind here gets overwritten
; by symbol table and program data
init mov ax, [6]
mov dx, sp
sub dx, stack
cmp ax, dx
jc il01
mov ax, dx
il01 sub ax, init
shr ax, 1
and ax, 0xFFF0
mov [free], ax
; open input file
mov ah, 0x0F
mov dx, fcb1
int 0x21
mov bx, e_op
test al, al
jnz error
jmp main
e_op db "NOFILE "