66 lines
808 B
NASM
66 lines
808 B
NASM
|
console_input:
|
||
|
xor ax, ax
|
||
|
int 0x16
|
||
|
; loop until we got >0
|
||
|
test al, al
|
||
|
jz console_input
|
||
|
push ax
|
||
|
push bx
|
||
|
jmp console_output.shortcut
|
||
|
console_output:
|
||
|
push ax
|
||
|
push bx
|
||
|
mov al, dl
|
||
|
.shortcut:
|
||
|
mov ah, 0x0e
|
||
|
xor bx, bx
|
||
|
int 0x10
|
||
|
pop bx
|
||
|
pop ax
|
||
|
ret
|
||
|
|
||
|
print_string:
|
||
|
push si
|
||
|
mov si, dx
|
||
|
.loop:
|
||
|
mov dl, BYTE [si]
|
||
|
cmp dl, '$'
|
||
|
jz .end
|
||
|
call console_output
|
||
|
inc si
|
||
|
jmp .loop
|
||
|
.end:
|
||
|
pop si
|
||
|
ret
|
||
|
|
||
|
read_buffer:
|
||
|
push bx
|
||
|
push si
|
||
|
xor bx, bx
|
||
|
mov si, dx
|
||
|
.loop:
|
||
|
call console_input
|
||
|
cmp al, 0x0D
|
||
|
je .end
|
||
|
cmp al, 8
|
||
|
je .bs
|
||
|
mov [si+bx+2], al
|
||
|
inc bx
|
||
|
cmp bl, [si]
|
||
|
jc .loop
|
||
|
.end:
|
||
|
mov byte [si+bx+2], 0x0D
|
||
|
mov [si+1], bl
|
||
|
pop si
|
||
|
pop bx
|
||
|
ret
|
||
|
.bs:
|
||
|
test bx, bx
|
||
|
jz .loop
|
||
|
mov dl, 0x20
|
||
|
call console_output
|
||
|
mov dl, 8
|
||
|
call console_output
|
||
|
dec bx
|
||
|
jmp .loop
|