rdos/com/a86.asm

89 lines
1.4 KiB
NASM
Raw Normal View History

org 0x100
mov ax, 0x3D00
mov dx, infile
int 0x21
jc err
mov [fd], ax
2020-09-15 20:38:34 +02:00
call getline
mov dx, [line_length]
call dumpdx
mov si, line_buffer
mov cx, [line_length]
mov ah, 2
2020-09-15 20:38:34 +02:00
l03: lodsb
mov dl, al
int 0x21
2020-09-15 20:38:34 +02:00
loop l03
end: ret
2020-09-15 20:38:34 +02:00
line_num: dw 1
err: mov dx, ax
dumpdx: ; setup bx and ah for int 10h call
xor bx, bx
mov ah, 0x0e
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
; read a character from the input file into DL
getc: mov dl, 26
push dx
mov ah, 0x3f
mov bx, [fd]
mov cx, 1
mov dx, sp
int 0x21
pop dx
ret
2020-09-15 20:38:34 +02:00
getline: mov word [line_length], 0
mov di, line_buffer
mov cx, line_buflen
l02: push cx
call getc
pop cx
mov al, dl
cmp al, 0x0A
je l01
cmp al, 0x0D
je l01
cmp al, 0x1A
je l01
inc word [line_length]
loop l02
l01: ret
infile: db "com/a86.asm", 0
2020-09-15 20:38:34 +02:00
line_buflen: equ 0x100
line_length: dw 0 ; valid bytes in buffer
line_prefix: times 16 db " "
line_buffer: times line_buflen db 0
fd: dw 0