rdos/debug/parse.asm

120 lines
1.4 KiB
NASM

; IN DS:SI remaining unparsed string
; CS:DI error message
parse_error:
push si
mov si, .str1
call putcs
mov si, di
call putcs
mov si, .str2
call putcs
pop si
call putds
jmp crlf
.str1: db "Not a ", 0
.str2: db ": ", 0
; Advance over whitespace
; IN DS:SI
eat_whitespace:
.loop: lodsb
cmp al, 0x20
je .loop
cmp al, 0x0A
je .loop
cmp al, 0x0D
je .loop
cmp al, 0x09
je .loop
dec si
ret
; Parse a register name
; IN DS:SI string to read
; OUT CF set if no match
; BX register number * 2 if CF clear
eat_register:
push si
push es
lodsw
and ax, 0xDFDF
; ES := CS
push cs
pop es
mov di, rnames
mov cx, 14
repne scasw
pop es
jne .fail
pop bx
mov bx, di
sub bx, (rnames+2)
clc
ret
.fail: pop si
stc
ret
.emsg: db "register name", 0
; Parse hex digit
; IN DS:SI
; OUT AL
eat_hex_digit:
push si
lodsb
sub al, '0'
jc .err
cmp al, 9
jna .ret
sub al, 7
cmp al, 0xF
ja .err
.ret: add sp, 2
ret
.err: pop si
stc
ret
.emsg: db "hex digit", 0
; Parse hexadecimal byte
; IN DS:SI
; OUT DL or carry set
eat_hex_byte:
push si
mov cl, 4
xor dl, dl
call eat_hex_digit
jc .err
or dl, al
shl dl, cl
call eat_hex_digit
jc .err
or dl, al
add sp, 2
ret
.err: pop si
stc
ret
.emsg: db "hex byte", 0
; Parse hexadecimal word
; OUT DX or carry set
eat_hex_word:
push si
xor dx, dx
call eat_hex_byte
jc .err
mov dh, dl
call eat_hex_byte
jc .err
add sp, 2
ret
.err: pop si
stc
ret
.emsg: db "hex word", 0