Starting writing an ed implementation

This commit is contained in:
deadvey
2026-03-07 20:48:34 +00:00
parent 43d0a020f7
commit 7a9b82d57c
12 changed files with 126 additions and 83 deletions

View File

@@ -842,14 +842,14 @@ do_break:
do_call:
call get_token
cmp ax, NUMBER
je .is_number
je .check_is_number
mov ax, 0
mov byte al, [token]
call get_var
jmp .execute_call
.is_number:
.check_is_number:
mov si, token
call string_cast_to_int
@@ -1325,7 +1325,7 @@ do_for:
cmp ax, NUMBER
jne .error
.second_is_number:
.second_check_is_number:
mov si, token ; Get target number
call string_cast_to_int
jmp .continue2
@@ -1625,7 +1625,7 @@ do_if:
je .equals_char
mov byte al, [token]
call is_letter
call check_is_letter
jc .equals_var
mov si, token ; Otherwise it's, eg 'X = 1' (a number)
@@ -1711,7 +1711,7 @@ do_if:
.greater:
call get_token ; Greater than a variable or number?
mov byte al, [token]
call is_letter
call check_is_letter
jc .greater_var
mov si, token ; Must be a number here...
@@ -1736,7 +1736,7 @@ do_if:
.less:
call get_token
mov byte al, [token]
call is_letter
call check_is_letter
jc .less_var
mov si, token
@@ -2636,7 +2636,7 @@ do_peekint:
cmp ax, NUMBER
jne .error
.address_is_number:
.address_check_is_number:
mov si, token
call string_cast_to_int
jmp .load_data
@@ -3770,14 +3770,14 @@ do_string:
call get_token ; Now there should be a number
cmp ax, NUMBER
je .third_is_number
je .third_check_is_number
cmp ax, VARIABLE
je .third_is_variable
jmp .error
.third_is_number:
.third_check_is_number:
mov si, token
call string_cast_to_int
jmp .got_number
@@ -3984,7 +3984,7 @@ get_token:
cmp al, ' '
je .newline
call is_number
call check_is_number
jc get_number_token
cmp al, '"'
@@ -4030,7 +4030,7 @@ get_number_token:
je .done
cmp al, ' '
je .done
call is_number
call check_is_number
jc .fine
mov si, err_char_in_num
@@ -4153,7 +4153,7 @@ get_string_token:
.is_not_string:
mov byte al, [token]
call is_letter
call check_is_letter
jc .is_var
mov ax, UNKNOWN
@@ -4164,37 +4164,6 @@ get_string_token:
ret
; ------------------------------------------------------------------
; Set carry flag if AL contains ASCII number
is_number:
cmp al, 48
jl .not_number
cmp al, 57
jg .not_number
stc
ret
.not_number:
clc
ret
; ------------------------------------------------------------------
; Set carry flag if AL contains ASCII letter
is_letter:
cmp al, 65
jl .not_letter
cmp al, 90
jg .not_letter
stc
ret
.not_letter:
clc
ret
; ------------------------------------------------------------------
; Print error message and quit out

View File

@@ -30,14 +30,14 @@ os_read_cli:
mov di, help_string
call os_compare_strings
cmp cl, 1
je help
je .help
; Clear screen
mov si, user_input
mov di, clear_string
call os_compare_strings
cmp cl, 1
je clear
je .clear
; Reboot
mov si, user_input
@@ -51,21 +51,28 @@ os_read_cli:
mov di, basic_string
call os_compare_strings
cmp cl, 1
je basic
je .basic
; Cat
mov si, user_input
mov di, cat_string
call os_compare_strings
cmp cl, 1
je cat
je .cat
; LS
mov si, user_input
mov di, ls_string
call os_compare_strings
cmp cl, 1
je ls
je .ls
; ED
mov si, user_input
mov di, ed_string
call os_compare_strings
cmp cl, 1
je .ed
jmp .unkown
@@ -80,21 +87,25 @@ os_read_cli:
popa
call os_start_cli
clear:
.clear:
call os_set_text_mode
call os_read_cli.finish
help:
.help:
mov si, help_text
call os_print_string
call os_read_cli.finish
basic:
.basic:
call util_basic
call os_read_cli.finish
cat:
.cat:
call util_cat
call os_read_cli.finish
ls:
.ls:
call util_ls
call os_read_cli.finish
.ed:
call util_ed
call os_read_cli.finish

View File

@@ -32,7 +32,6 @@ keyboard_display_input:
pusha
mov di, ax
mov ax, bx
mov bx,20
.check_key_pressed:
call os_read_input

View File

@@ -68,6 +68,9 @@ text_print_raw:
int 10h
mov al, 0Dh
int 10h
push ax
call os_read_input ; wait until key is pressed until it prints the next line
pop ax
jmp .repeat
.finish:
popa

View File

@@ -1,30 +1,30 @@
util_cat:
pusha
pusha
call disk_clear_file_buffer
mov si, user_input
; TODO make this more consistent to account for double spaces
add si, 4 ; Move si to after 'CAT'
call disk_clear_file_buffer
mov si, user_input
; TODO make this more consistent to account for double spaces
add si, 4 ; Move si to after 'CAT'
call disk_load_file
mov si, file_buffer
mov cx, [file_length]
call text_print_raw
call disk_load_file
mov si, file_buffer
mov cx, [file_length]
call text_print_raw
popa
ret
popa
ret
util_ls:
pusha
pusha
call disk_list_contents
call disk_list_contents
mov si, output_buffer
call os_print_string
call disk_clear_output_buffer
mov si, output_buffer
call os_print_string
call disk_clear_output_buffer
popa
ret
popa
ret
util_basic:
pusha
@@ -43,3 +43,13 @@ util_basic:
popa
ret
util_ed:
pusha
call disk_load_root
call disk_load_file
call ed
popa
ret