Fixed some bugs with inputs

This commit is contained in:
deadvey
2026-03-08 22:07:21 +00:00
parent 7a9b82d57c
commit 88716c0b64
10 changed files with 199 additions and 32 deletions

View File

@@ -1950,8 +1950,9 @@ do_input:
.number_var:
mov ax, .tmpstring ; Get input from the user
mov bx, 6
mov bx, 20
call keyboard_display_input
jc .end
mov ax, .tmpstring
call string_length
@@ -1973,8 +1974,6 @@ do_input:
call os_print_newline
jmp mainloop
.string_var:
mov ax, 128
mul bx
@@ -1987,8 +1986,9 @@ do_input:
jmp mainloop
.tmpstring times 6 db 0
.tmpstring times 20 db 0
.end
ret
; -----------------------------------------------------------

View File

@@ -0,0 +1,29 @@
check_is_number:
cmp al, 48
jl .not_number
cmp al, 57
jg .not_number
stc
ret
.not_number:
clc
ret
check_is_letter:
cmp al, 65
jl .not_letter
cmp al, 122
jg .not_letter
cmp al, 90
jg .maybe_not_letter
stc
ret
.maybe_not_letter:
cmp al, 97
jl .not_letter
stc
ret
.not_letter:
clc
ret

View File

@@ -11,6 +11,7 @@ os_start_cli:
mov ax, user_input
call keyboard_display_input
jc power_reboot
jmp os_read_cli

View File

@@ -171,6 +171,7 @@ disk_clear_output_buffer:
; OUT
; data_buffer: file contents
; TODO use predefined data for calculations
; carry flag: set if failed to load file
disk_load_file:
pusha
call string_length ; cl = string length
@@ -227,11 +228,15 @@ disk_load_file:
.file_not_found:
mov si, file_not_found
call os_print_string
jmp .done
jmp .done_fail
.filename_too_long:
mov si, too_long_filename
call os_print_string
jmp .done
jmp .done_fail
.done_fail:
popa
stc
ret
.done:
popa
ret

View File

@@ -15,6 +15,7 @@ os_read_input:
; AX = key pressed
; Returns straight away
; carry flag is set when escape is pressed and data is returned straight away
keyboard_check_key:
xor ax,ax
mov ah, 11h ; BIOS call to check for key
@@ -27,11 +28,11 @@ keyboard_check_key:
; IN:
; AX = output address
; BX = max length
keyboard_display_input:
pusha
mov di, ax
mov ax, bx
xor ax,ax
mov [prompt_length], bx
.check_key_pressed:
call os_read_input
@@ -54,7 +55,9 @@ keyboard_display_input:
jmp .check_key_pressed
.esc_key:
call power_reboot
stc
popa
ret
.enter_key:
mov al, 0
@@ -63,7 +66,7 @@ keyboard_display_input:
ret ; Return to the parent function (whatever that may be)
.backspace:
cmp bx, 20 ; Cannot backspace if the cursor is at the start
cmp bx, [prompt_length] ; Cannot backspace if the cursor is at the start
jb .move_cursor_back ; then .move_cursor_back
jmp .check_key_pressed ; Else check the next key
@@ -86,6 +89,7 @@ keyboard_display_input:
mov ah, 0Eh
int 10h
jmp .check_key_pressed
.input_length db 0
keyboard_get_cursor_pos:
ret

View File

@@ -107,7 +107,7 @@ string_join:
; ------------------------------------------------------------------------
; TODO
; Converts a null terminated string to an integer
; Converts a string to an integer
; IN: SI = string location (max 5 chars, up to '65536')
; OUT: AX = number
string_cast_to_int:
@@ -116,8 +116,12 @@ string_cast_to_int:
.loop:
xor ax,ax
lodsb
cmp al, 0
je .finish
cmp al, 30h
jl .finish
cmp al, 39h
jg .finish
sub al, 30h
mov bx, ax
mov ax, 10

View File

@@ -7,10 +7,12 @@ util_cat:
add si, 4 ; Move si to after 'CAT'
call disk_load_file
jc .done ; if file failed to load, just quit
mov si, file_buffer
mov cx, [file_length]
call text_print_raw
.done
popa
ret
@@ -34,6 +36,7 @@ util_basic:
; TODO make this more consistent to account for double spaces
;add si, 3 ; Move si to after 'BAS'
call disk_load_file
jc .done
mov si, file_buffer
@@ -41,6 +44,7 @@ util_basic:
mov si, 0
call basic_run_basic
.done
popa
ret