diff --git a/console.asm b/console.asm new file mode 100644 index 0000000..a79c39e --- /dev/null +++ b/console.asm @@ -0,0 +1,32 @@ +; Reads a line from the keyboard and fills the specified buffer with it +; Does not support Shift or any other special keys +; Argument: r1 - pointer to the buffer +; Returns the pointer to the same buffer +; Clobbers r2, r3 and r4 +pub read_line: + + 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 + + read_line_keyloop: + keyboard r1 + + cmp r1, r4 + je read_line_keyloop ; If the current key is same as previous, we loop + mov r4, r1 ; Storing current key as previous + + cmp r1, 0x100 + jbe read_line_keyloop ; If the key was up, we loop + xor r1, r1, 0x100 ; We remove the "down" bit + + cmp r1, 10 ; Was the key Enter? + je read_line_finished ; If so, we're finished + + store_8 [r3], r1 ; Else, we store the key in the buffer + add r3, r3, 1 ; We advance forward + jmp read_line_keyloop + read_line_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 diff --git a/stdlib.asm b/stdlib.asm index 2374dc5..ff7a916 100644 --- a/stdlib.asm +++ b/stdlib.asm @@ -1,3 +1,3 @@ pub include bit pub include imath -pub include array +pub include console