2020-05-18 20:05:06 +02:00
|
|
|
; IN DS:SI remaining unparsed string
|
|
|
|
; CS:DI error message
|
|
|
|
parse_error:
|
|
|
|
push si
|
2020-05-18 22:35:41 +02:00
|
|
|
mov si, .str1
|
|
|
|
call putcs
|
2020-05-18 20:05:06 +02:00
|
|
|
mov si, di
|
|
|
|
call putcs
|
2020-05-18 22:35:41 +02:00
|
|
|
mov si, .str2
|
|
|
|
call putcs
|
2020-05-18 20:05:06 +02:00
|
|
|
pop si
|
|
|
|
call putds
|
|
|
|
jmp crlf
|
2020-05-18 22:35:41 +02:00
|
|
|
.str1: db "Not a ", 0
|
|
|
|
.str2: db ": ", 0
|
2020-05-18 20:05:06 +02:00
|
|
|
|
2020-05-18 22:35:41 +02:00
|
|
|
; Advance over whitespace
|
|
|
|
; IN DS:SI
|
2020-05-18 20:05:06 +02:00
|
|
|
eat_whitespace:
|
2020-05-18 23:43:54 +02:00
|
|
|
.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
|
2020-05-18 20:05:06 +02:00
|
|
|
|
2020-05-18 22:35:41 +02:00
|
|
|
; Parse a register name
|
|
|
|
; IN DS:SI string to read
|
|
|
|
; OUT CF set if no match
|
2020-05-18 20:05:06 +02:00
|
|
|
; 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
|
2020-05-18 22:35:41 +02:00
|
|
|
.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
|