ibis-os/input_util.asm

58 lines
1.1 KiB
NASM

read_line:
pusha
mov bx, read_buffer
.loop:
mov ah, 0x00
int 0x16 ; Read char
cmp al, 0x0D ; Is enter?
jne .enter_end
jmp .end
.enter_end:
cmp al, 0x08 ; Is backspace?
jne .backspace_end
; Don't do anything if we're at col == 0
cmp bx, read_buffer
jle .backspace_end
sub bx, 1
mov ah, 0x0
mov [bx], ah
; Erase the character on screen
mov ah, 0x0e
mov al, 0x08 ; Back one
int 0x10
mov al, 0x20 ; Erase it
int 0x10
mov al, 0x08 ; Back one more
int 0x10
jmp .loop
.backspace_end
; Don't add any characters if over the limit
cmp bx, read_buffer + 20
jge .loop
; Add char to bx and incr
mov [bx], al
add bx, 1
; Display the character
mov ah, 0x0e
int 0x10
jmp .loop
.end:
mov al, 0x0
mov [bx], al ; Null terminater
popa
ret
read_buffer: resb 20