debug: Rework repl loop and implement help command '?'

This commit is contained in:
Nero 2020-05-17 22:46:11 +02:00
parent 31a72d594a
commit 9ce6ec5476

View File

@ -58,18 +58,30 @@ init: push ds
pop ds
retf
crlf: xor bx, bx
mov ax, 0x0e0a
int 0x10
mov al, 0x0d
; Print AL
space: mov al, ' '
putc: xor bx, bx
mov ah, 0x0e
int 0x10
ret
space: xor bx, bx
mov ax, 0x0e20
int 0x10
; Print CS:SI
puts: push ds
push cs
pop ds
.loop: lodsb
test al, al
jz .ret
call putc
jmp .loop
.ret: pop ds
ret
crlf: mov al, 0x0A
call putc
mov al, 0x0D
jmp putc
print16:
; setup bx and ah for int 10h call
xor bx, bx
@ -94,42 +106,6 @@ print16:
.noadj: int 0x10
ret
printregs:
mov cx, 13
xor bx, bx
mov ah, 0x0e
mov si, reg_ax
.loop: push cx
mov dx, [cs:si+names]
mov al, dl
int 0x10
mov al, dh
int 0x10
mov al, '='
int 0x10
lodsw
mov dx, ax
call print16
call space
pop cx
loop .loop
mov dx, [reg_fl]
mov si, fnames
mov cx, 16
.floop: mov al, [cs:si]
inc si
cmp al, '+'
je .fskip
test dx, 0x8000
jnz .fprnt
mov al, '-'
.fprnt: int 0x10
.fskip: shl dx, 1
loop .floop
call space
ret
int3entry:
; save DS and AX
push ds
@ -168,42 +144,21 @@ int3entry:
mov ss, ax
mov sp, stack
call crlf
call printregs
mov dx, ds
call print16
loop: ; new line & show prompt
call crlf
loop: ; show prompt
mov al, '-'
int 0x10
; read data
call read
pushf
call crlf
popf
jc loop
; execute
call crlf
mov al, [cmdbuf]
call runcmd
jmp loop
runcmd: cmp al, 'r'
je printregs
cmp al, 'g'
je go
cmp al, 't'
je step
; print a question mark
xor bx, bx
mov ax, 0x0e3F
int 0x10
ret
go: and word [reg_fl+1], 0xfe
jmp return
step: or word [reg_fl+1], 0x03
return: ; restore stack pointer
mov ss, [reg_ss]
mov sp, [reg_sp]
@ -276,6 +231,75 @@ read: mov di, cmdbuf
.can: stc
.enter: ret
runcmd: mov al, [cmdbuf]
cmp al, 'g'
je cmd_g
cmp al, 'r'
je cmd_r
cmp al, 't'
je cmd_t
cmp al, '?'
je cmd_?
mov al, '?'
call putc
jmp crlf
cmd_?: mov si, .txt
jmp puts
.txt: db "g Go", 0x0A, 0x0D
db "r Print register values", 0x0A, 0x0D
db "t Single-Step", 0x0A, 0x0D
db 0
cmd_g: and word [reg_fl+1], 0xfe
jmp return
cmd_r: jmp printregs
cmd_t: or word [reg_fl+1], 0x03
jmp return
printregs:
mov cx, 13
xor bx, bx
mov ah, 0x0e
mov si, reg_ax
.loop: push cx
mov dx, [cs:si+names]
lodsw
call printreg
pop cx
loop .loop
mov dx, [reg_fl]
mov si, fnames
mov cx, 16
.floop: mov al, [cs:si]
inc si
cmp al, '+'
je .fskip
test dx, 0x8000
jnz .fprnt
mov al, '-'
.fprnt: int 0x10
.fskip: shl dx, 1
loop .floop
call crlf
ret
printreg:
push ax
mov al, dl
call putc
mov al, dh
call putc
mov al, '='
call putc
pop dx
call print16
call space
ret
align 512
absolute 0