1
0
Fork 0

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 je loop
execute: execute:
.help:
mov si, input
mov di, command.help
call compare
jnc .hello
call help
jmp loop
.hello: .hello:
mov si, input mov si, input
mov di, command.hello mov di, command.hello
@ -25,9 +32,16 @@ jmp loop
mov si, input mov si, input
mov di, command.echo mov di, command.echo
call compare call compare
jnc .unknown jnc .keycode
call echo call echo
jmp loop jmp loop
.keycode:
mov si, input
mov di, command.keycode
call compare
jnc .unknown
call keycode
jmp loop
.unknown: .unknown:
mov si, command.unknown mov si, command.unknown
call print call print
@ -45,11 +59,15 @@ jmp print
.done: .done:
ret ret
read: clear:
mov di, input mov di, input
mov cx, 0x80 mov cx, 0x80
mov al, 0 mov al, 0
rep stosb rep stosb
ret
read:
call clear
mov di, input mov di, input
mov cl, 0 mov cl, 0
.loop: .loop:
@ -130,6 +148,36 @@ ret
stc stc
ret 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: hello:
mov si, .msg mov si, .msg
call print call print
@ -140,12 +188,38 @@ db "Hello world!", 0xd, 0xa, 0
echo: echo:
call read call read
cmp byte [input], 0 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 mov si, input
call print call print
mov si, newline mov si, newline
call print call print
ret ret
.prefix:
db "0x", 0
.scan:
db 0
.ascii:
db 0
;Data ;Data
@ -156,10 +230,14 @@ prompt:
db "> ", 0 db "> ", 0
command: command:
.help:
db "help", 0
.hello: .hello:
db "hello", 0 db "hello", 0
.echo: .echo:
db "echo", 0 db "echo", 0
.keycode:
db "keycode", 0
.unknown: .unknown:
db "Unknown command", 0xd, 0xa, 0 db "Unknown command", 0xd, 0xa, 0