Starting writing an ed implementation
This commit is contained in:
7
Makefile
7
Makefile
@@ -15,7 +15,7 @@ $(BUILD_DIR)/crawos.iso: floppy_image
|
||||
# Floppy image
|
||||
# Fat12
|
||||
floppy_image: $(BUILD_DIR)/crawos.img
|
||||
$(BUILD_DIR)/crawos.img: bootloader kernel
|
||||
$(BUILD_DIR)/crawos.img: bootloader kernel check-fat83
|
||||
mkdir -p disk_images
|
||||
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
|
||||
@@ -36,6 +36,11 @@ $(BUILD_DIR)/kernel.bin:
|
||||
mkdir -p disk_images
|
||||
$(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:
|
||||
rm -f disk_images/*
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
Kernel written in Assmebly
|
||||
I'm using a modified JazzOS Bootloader
|
||||
# What is this?
|
||||
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:
|
||||
CAT
|
||||
HELP
|
||||
CLEAR
|
||||
REBOOT
|
||||
PONG
|
||||
# Commands
|
||||
- CAT <filename>: outputs the contents of the file.
|
||||
- LS: outputs a list of files on the system .
|
||||
- CLEAR: clears the screen.
|
||||
- REBOOT: or esc reboots the system
|
||||
- BAS <filename>: runs a basic script.
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
PORT OUT 80 5
|
||||
PRINT "Hello World"
|
||||
END
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
x = 5
|
||||
@@ -34,6 +34,7 @@ reboot_string: db 'REBOOT', 0
|
||||
basic_string: db 'BAS', 0
|
||||
cat_string: db 'CAT', 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
|
||||
basic_text: db 'BASIC PROGRAM BEGUN:\n', 0
|
||||
command_result_text: db 'You typed: ', 0
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ keyboard_display_input:
|
||||
pusha
|
||||
mov di, ax
|
||||
mov ax, bx
|
||||
mov bx,20
|
||||
|
||||
.check_key_pressed:
|
||||
call os_read_input
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -43,3 +43,13 @@ util_basic:
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
util_ed:
|
||||
pusha
|
||||
call disk_load_root
|
||||
call disk_load_file
|
||||
|
||||
call ed
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
@@ -33,13 +33,19 @@ halt:
|
||||
%INCLUDE "source/kernel/features/sound.asm"
|
||||
%INCLUDE "source/kernel/features/disk.asm"
|
||||
%INCLUDE "source/kernel/features/math.asm"
|
||||
%INCLUDE "source/kernel/features/check.asm"
|
||||
%INCLUDE "source/kernel/features/time.asm"
|
||||
%INCLUDE "source/kernel/features/utils.asm"
|
||||
%INCLUDE "source/kernel/features/cli.asm"
|
||||
%INCLUDE "source/kernel/features/misc.asm"
|
||||
%INCLUDE "source/kernel/features/basic.asm"
|
||||
|
||||
; PROGRAMS
|
||||
%INCLUDE "source/kernel/programs/ed.asm"
|
||||
|
||||
; DATA/VARIABLES
|
||||
%INCLUDE "source/kernel/data.asm"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user