Add byte2hex call and help and keycode commands

This commit is contained in:
CrazyEttin 2021-05-27 21:00:50 +03:00
parent 0daa68f804
commit 958b64e8a3
1 changed files with 81 additions and 3 deletions

View File

@ -14,6 +14,13 @@ cmp byte [input], 0
je loop
execute:
.help:
mov si, input
mov di, command.help
call compare
jnc .hello
call help
jmp loop
.hello:
mov si, input
mov di, command.hello
@ -25,9 +32,16 @@ jmp loop
mov si, input
mov di, command.echo
call compare
jnc .unknown
jnc .keycode
call echo
jmp loop
.keycode:
mov si, input
mov di, command.keycode
call compare
jnc .unknown
call keycode
jmp loop
.unknown:
mov si, command.unknown
call print
@ -45,11 +59,15 @@ jmp print
.done:
ret
read:
clear:
mov di, input
mov cx, 0x80
mov al, 0
rep stosb
ret
read:
call clear
mov di, input
mov cl, 0
.loop:
@ -130,6 +148,36 @@ ret
stc
ret
byte2hex:
call clear
mov di, input
mov si, .hex
mov cx, 0x2
.loop:
rol ax, 0x4
mov bx, ax
and bx, 0xf
mov bl, [si + bx]
mov [di], bl
inc di
dec cx
jnz .loop
; mov si, input
ret
.hex:
db "0123456789abcdef"
help:
mov si, .input
call print
mov si, .commands
call print
ret
.input:
db "Input:", 0xd, 0xa, "* Typing a character overwrites the cursor location.", 0xd, 0xa, "* The tab key erases the cursor location.", 0xd, 0xa, "* The space and backspace keys move the cursor.", 0xd, 0xa, 0
.commands:
db "Commands:", 0xd, 0xa, "* help: you are reading it.", 0xd, 0xa, "* hello: a hello world program.", 0xd, 0xa, "* echo: echoes its input.", 0xd, 0xa, "* keycode: echoes the BIOS scancode of a key.", 0xd, 0xa, 0
hello:
mov si, .msg
call print
@ -140,12 +188,38 @@ db "Hello world!", 0xd, 0xa, 0
echo:
call read
cmp byte [input], 0
je loop
je .done
mov si, input
call print
mov si, newline
call print
.done:
ret
keycode:
mov ah, 0
int 0x16
mov byte [.scan], ah
mov byte [.ascii], al
mov si, .prefix
call print
mov ah, [.scan]
call byte2hex
mov si, input
call print
mov ah, [.ascii]
call byte2hex
mov si, input
call print
mov si, newline
call print
ret
.prefix:
db "0x", 0
.scan:
db 0
.ascii:
db 0
;Data
@ -156,10 +230,14 @@ prompt:
db "> ", 0
command:
.help:
db "help", 0
.hello:
db "hello", 0
.echo:
db "echo", 0
.keycode:
db "keycode", 0
.unknown:
db "Unknown command", 0xd, 0xa, 0