forked from TCShenanigans/symphony_stdlib
One instruction less by using another register
This commit is contained in:
+10
-12
@@ -6,41 +6,39 @@
|
|||||||
pub read_line:
|
pub read_line:
|
||||||
|
|
||||||
mov r4, 0 ; Storing the last key here, so we don't repeat the same key
|
mov r4, 0 ; Storing the last key here, so we don't repeat the same key
|
||||||
mov r2, r1 ; Saving the buffer pointer for return
|
|
||||||
mov r3, r1 ; The pointer to after the last character
|
mov r3, r1 ; The pointer to after the last character
|
||||||
|
|
||||||
read_line_keyloop:
|
read_line_keyloop:
|
||||||
keyboard r1
|
keyboard r2
|
||||||
|
|
||||||
cmp r1, r4
|
cmp r2, r4
|
||||||
je read_line_keyloop ; If the current key is same as previous, we loop
|
je read_line_keyloop ; If the current key is same as previous, we loop
|
||||||
mov r4, r1 ; Storing current key as previous
|
mov r4, r2 ; Storing current key as previous
|
||||||
|
|
||||||
cmp r1, 0x100 ; Is the key down or up?
|
cmp r2, 0x100 ; Is the key down or up?
|
||||||
jbe read_line_keyloop ; If the key was up, we loop
|
jbe read_line_keyloop ; If the key was up, we loop
|
||||||
xor r1, r1, 0x100 ; We remove the "down" bit
|
xor r2, r2, 0x100 ; We remove the "down" bit
|
||||||
|
|
||||||
cmp r1, 10 ; Was the key Enter?
|
cmp r2, 10 ; Was the key Enter?
|
||||||
je read_line_finished ; If so, we're finished
|
je read_line_finished ; If so, we're finished
|
||||||
|
|
||||||
cmp r1, 32 ; Was the key under Space? i.e. non-renderable
|
cmp r2, 32 ; Was the key under Space? i.e. non-renderable
|
||||||
jb read_line_keyloop ; If so, we loop
|
jb read_line_keyloop ; If so, we loop
|
||||||
|
|
||||||
cmp r1, 127 ; Was the key Backspace?
|
cmp r2, 127 ; Was the key Backspace?
|
||||||
je read_line_backspace ; If yes we need to move one character back
|
je read_line_backspace ; If yes we need to move one character back
|
||||||
|
|
||||||
read_line_store:
|
read_line_store:
|
||||||
store_8 [r3], r1 ; Else, we store the key in the buffer
|
store_8 [r3], r2 ; Else, we store the key in the buffer
|
||||||
add r3, r3, 1 ; We advance forward
|
add r3, r3, 1 ; We advance forward
|
||||||
jmp read_line_keyloop
|
jmp read_line_keyloop
|
||||||
|
|
||||||
read_line_backspace:
|
read_line_backspace:
|
||||||
cmp r3, r2
|
cmp r3, r1 ; Compare the current pointer to start of buffer
|
||||||
je read_line_keyloop ; If we are at the start, we loop
|
je read_line_keyloop ; If we are at the start, we loop
|
||||||
sub r3, r3, 1 ; We move back one character
|
sub r3, r3, 1 ; We move back one character
|
||||||
jmp read_line_keyloop
|
jmp read_line_keyloop
|
||||||
|
|
||||||
read_line_finished:
|
read_line_finished:
|
||||||
store_8 [r3], zr ; We store null at the end so the string is finished
|
store_8 [r3], zr ; We store null at the end so the string is finished
|
||||||
mov r1, r2 ; Recovering the buffer pointer
|
|
||||||
jmp r13
|
jmp r13
|
||||||
|
|||||||
Reference in New Issue
Block a user