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

@@ -15,7 +15,7 @@ $(BUILD_DIR)/crawos.iso: floppy_image
# Floppy image # Floppy image
# Fat12 # Fat12
floppy_image: $(BUILD_DIR)/crawos.img floppy_image: $(BUILD_DIR)/crawos.img
$(BUILD_DIR)/crawos.img: bootloader kernel $(BUILD_DIR)/crawos.img: bootloader kernel check-fat83
mkdir -p disk_images mkdir -p disk_images
dd if=/dev/zero of=$(BUILD_DIR)/crawos.img bs=512 count=2880 # Use dd to make a disk image dd if=/dev/zero of=$(BUILD_DIR)/crawos.img bs=512 count=2880 # Use dd to make a disk image
mkfs.fat -F 12 -n "CRAWOS" $(BUILD_DIR)/crawos.img # Format the disk image with fat12 mkfs.fat -F 12 -n "CRAWOS" $(BUILD_DIR)/crawos.img # Format the disk image with fat12
@@ -36,6 +36,11 @@ $(BUILD_DIR)/kernel.bin:
mkdir -p disk_images mkdir -p disk_images
$(ASM) $(SRC_DIR)/kernel/kernel.asm -f bin -o $ $(BUILD_DIR)/kernel.bin $(ASM) $(SRC_DIR)/kernel/kernel.asm -f bin -o $ $(BUILD_DIR)/kernel.bin
check-fat83:
@echo "Checking filenames for FAT 8.3 compliance..."
@find ./data -type f | awk -F/ '{print $$NF}' | \
awk -F. 'length($$1)>8 || length($$2)>3 || NF>2 {print "Invalid FAT 8.3 filename:", $$0; bad=1} END{exit bad}'
# Clean # Clean
clean: clean:
rm -f disk_images/* rm -f disk_images/*

View File

@@ -1,9 +1,14 @@
Kernel written in Assmebly # What is this?
I'm using a modified JazzOS Bootloader This is a simple implementation of a computer kernel
written in pure x86 assembly with features including
- Read/Write disk operations
- The ability to boot from the BIOS using the JazzOS Bootloader
- A modified MikeOS BASIC interpreter
- A functional POSIX inspired CLI
Commands: # Commands
CAT - CAT <filename>: outputs the contents of the file.
HELP - LS: outputs a list of files on the system .
CLEAR - CLEAR: clears the screen.
REBOOT - REBOOT: or esc reboots the system
PONG - BAS <filename>: runs a basic script.

View File

@@ -1,2 +1,2 @@
PORT OUT 80 5 PRINT "Hello World"
END END

View File

@@ -1 +0,0 @@
x = 5

View File

@@ -34,6 +34,7 @@ reboot_string: db 'REBOOT', 0
basic_string: db 'BAS', 0 basic_string: db 'BAS', 0
cat_string: db 'CAT', 0 cat_string: db 'CAT', 0
ls_string: db 'LS', 0 ls_string: db 'LS', 0
ed_string: db 'ED', 0
help_text: db 'This is for Cowards:\n"LS" to list the directory,\n"CAT" to output the contents of a file,\n"BAS" to run a basic script,\n"HELP" for this helpful text,\n"CLEAR" to clear the screen,\n"REBOOT" or esc to reboot\n', 0 help_text: db 'This is for Cowards:\n"LS" to list the directory,\n"CAT" to output the contents of a file,\n"BAS" to run a basic script,\n"HELP" for this helpful text,\n"CLEAR" to clear the screen,\n"REBOOT" or esc to reboot\n', 0
basic_text: db 'BASIC PROGRAM BEGUN:\n', 0 basic_text: db 'BASIC PROGRAM BEGUN:\n', 0
command_result_text: db 'You typed: ', 0 command_result_text: db 'You typed: ', 0

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -33,13 +33,19 @@ halt:
%INCLUDE "source/kernel/features/sound.asm" %INCLUDE "source/kernel/features/sound.asm"
%INCLUDE "source/kernel/features/disk.asm" %INCLUDE "source/kernel/features/disk.asm"
%INCLUDE "source/kernel/features/math.asm" %INCLUDE "source/kernel/features/math.asm"
%INCLUDE "source/kernel/features/check.asm"
%INCLUDE "source/kernel/features/time.asm" %INCLUDE "source/kernel/features/time.asm"
%INCLUDE "source/kernel/features/utils.asm" %INCLUDE "source/kernel/features/utils.asm"
%INCLUDE "source/kernel/features/cli.asm" %INCLUDE "source/kernel/features/cli.asm"
%INCLUDE "source/kernel/features/misc.asm" %INCLUDE "source/kernel/features/misc.asm"
%INCLUDE "source/kernel/features/basic.asm" %INCLUDE "source/kernel/features/basic.asm"
; PROGRAMS
%INCLUDE "source/kernel/programs/ed.asm"
; DATA/VARIABLES ; DATA/VARIABLES
%INCLUDE "source/kernel/data.asm" %INCLUDE "source/kernel/data.asm"

View File

@@ -0,0 +1,35 @@
; Planned commands:
; i insert
; a append
; l prints lines
; w save to disk
; q quit
ed:
pusha
mov si, ed_welcome
call os_print_string
.main_loop:
mov ax, ed_prompt
mov bx, 40
call keyboard_display_input ; AX = string location, BX = max prompt length
mov si, ed_prompt
jmp .get_token
; Types of tokens:
; Number: eg 123
; Doller (refers to the last line) $
; Comma ,
; Command: eg i
; 123
.get_token:
xor ax,ax
lodsb
call check_is_number
jmp .exit
.exit:
popa
ret
ed_prompt: times 40 db 0
ed_welcome: db "This is ED\n", 0