Fix backspace not working at linebreak.

This commit is contained in:
CrazyEttin 2021-05-28 00:53:34 +03:00
parent 958b64e8a3
commit 3045519bd4
1 changed files with 50 additions and 18 deletions

View File

@ -3,6 +3,10 @@
mov ax, 0x1000
mov ds, ax
mov ah, 0xf
int 0x10
mov byte [cpl], ah
mov si, welcome
call print
@ -68,30 +72,33 @@ ret
read:
call clear
mov bl, 0
mov ah, 0x3
int 0x10
mov byte [.lastline], dh
mov di, input
mov cl, 0
.loop:
mov ah, 0
int 0x16
cmp al, 0
je .loop
cmp al, 0xd
je .return
cmp al, 0x8
je .backspace
cmp cl, 0x80
cmp bl, 0x80
je .loop
cmp al, 0x20
je .space
cmp al, 0x9
je .erase
cmp al, 0
je .loop
cmp al, 0x20
je .space
.character:
mov byte [di], 0
mov ah, 0xe
int 0x10
stosb
inc cl
jmp .loop
inc bl
jmp .linecheck
.erase:
mov al, 0x20
jmp .character
@ -102,34 +109,57 @@ mov al, byte [di]
mov ah, 0xe
int 0x10
inc di
inc cl
inc bl
.linecheck:
mov ah, 0x3
int 0x10
cmp dh, [.lastline]
jle .loop
mov byte [.lastline], dh
jmp .loop
.backspace:
cmp cl, 0
cmp bl, 0
je .loop
mov ah, 0x3
int 0x10
cmp dl, 1
je .prevline
mov ah, 0xe
int 0x10
dec di
dec cl
dec bl
jmp .loop
.prevline:
mov ah, 0x2
dec dh
mov dl, [cpl]
int 0x10
dec di
dec bl
jmp .loop
.return:
mov di, input.end
.tspfind:
.findtrailingspace:
dec di
cmp byte [di], 0
je .tspfind
je .findtrailingspace
cmp byte [di], 0x20
je .tsperase
je .erasetrailingspace
jmp .done
.tsperase:
.erasetrailingspace:
mov al, 0
stosb
dec di
jmp .tspfind
jmp .findtrailingspace
.done:
mov ah, 0x2
mov dh, [.lastline]
int 0x10
mov si, newline
call print
ret
.lastline:
db 0
compare:
mov al, [si]
@ -162,7 +192,6 @@ mov [di], bl
inc di
dec cx
jnz .loop
; mov si, input
ret
.hex:
db "0123456789abcdef"
@ -176,7 +205,7 @@ 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
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 code of a key.", 0xd, 0xa, 0
hello:
mov si, .msg
@ -223,6 +252,9 @@ db 0
;Data
cpl:
db 0
welcome:
db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0xd, 0xa, 0