Skip to content

Commit 59c96fe

Browse files
author
Ian Seyler
committed
Add cursor support from kernel
1 parent 78bca2c commit 59c96fe

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/monitor.asm

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,21 +1068,22 @@ string_to_int_invalid:
10681068
ui_input:
10691069
push rdi
10701070
push rdx ; Counter to keep track of max accepted characters
1071+
push rbx
10711072
push rax
10721073

10731074
mov rdx, rcx ; Max chars to accept
1075+
xor ebx, ebx ; Cursor position
10741076
xor ecx, ecx ; Offset from start
10751077

10761078
ui_input_more:
1077-
mov al, '_' ; Cursor character
1078-
call output_char ; Output the cursor
1079-
mov al, 0x03 ; Decrement cursor
1080-
call output_char ; Output the cursor
1081-
ui_input_halt:
10821079
hlt ; Halt until an interrupt is received
10831080
call [b_input] ; Returns the character entered. 0 if there was none
1084-
jz ui_input_halt ; If there was no character then halt until an interrupt is received
1081+
jz ui_input_more ; If there was no character then halt until an interrupt is received
10851082
ui_input_process:
1083+
cmp al, 0x02
1084+
je ui_input_inc_cursor
1085+
cmp al, 0x03
1086+
je ui_input_dec_cursor
10861087
cmp al, 0x1C ; If Enter key pressed, finish
10871088
je ui_input_done
10881089
cmp al, 0x0E ; Backspace
@@ -1094,31 +1095,47 @@ ui_input_process:
10941095
cmp rcx, rdx ; Check if we have reached the max number of chars
10951096
je ui_input_more ; Jump if we have (should beep as well)
10961097
stosb ; Store AL at RDI and increment RDI by 1
1098+
inc ebx
10971099
inc rcx ; Increment the counter
10981100
call output_char ; Display char
10991101
jmp ui_input_more
11001102

11011103
ui_input_backspace:
1102-
test rcx, rcx ; backspace at the beginning? get a new char
1104+
test ecx, ecx ; backspace at the beginning? get a new char
11031105
jz ui_input_more
1104-
mov al, ' '
1105-
call output_char ; Output backspace as a character
11061106
mov al, 0x03 ; Decrement cursor
11071107
call output_char ; Output the cursor
1108+
mov al, ' '
1109+
call output_char ; Output backspace as a character
11081110
mov al, 0x03 ; Decrement cursor
11091111
call output_char ; Output the cursor
11101112
dec rdi ; go back one in the string
11111113
mov byte [rdi], 0x00 ; NULL out the char
11121114
dec rcx ; decrement the counter by one
11131115
jmp ui_input_more
11141116

1117+
ui_input_inc_cursor:
1118+
cmp ebx, ecx
1119+
je ui_input_more
1120+
call output_char ; Output the cursor
1121+
inc ebx
1122+
jmp ui_input_more
1123+
1124+
ui_input_dec_cursor:
1125+
test ebx, ebx ; backspace at the beginning? get a new char
1126+
jz ui_input_more
1127+
call output_char ; Output the cursor
1128+
dec ebx
1129+
jmp ui_input_more
1130+
11151131
ui_input_done:
11161132
xor al, al
11171133
stosb ; We NULL terminate the string
11181134
mov al, ' '
11191135
call output_char ; Overwrite the cursor
11201136

11211137
pop rax
1138+
pop rbx
11221139
pop rdx
11231140
pop rdi
11241141
ret

0 commit comments

Comments
 (0)