BASIC interpreter
This commit is contained in:
0
.gitignore
vendored
Executable file → Normal file
0
.gitignore
vendored
Executable file → Normal file
0
build-linux.sh
Executable file → Normal file
0
build-linux.sh
Executable file → Normal file
0
data/README.md
Executable file → Normal file
0
data/README.md
Executable file → Normal file
@@ -1,2 +1,4 @@
|
|||||||
PRINT "Hello World!"
|
FOR A = 1 TO 10
|
||||||
|
PRINT A
|
||||||
|
NEXT A
|
||||||
END
|
END
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ command_result_text: db 'You typed: ', 0
|
|||||||
unknown_command: db 'Error: Unkown Command..\n ', 0
|
unknown_command: db 'Error: Unkown Command..\n ', 0
|
||||||
stringified_int: db 0,0,0,0,0,0 ; Can store up to 6 digits
|
stringified_int: db 0,0,0,0,0,0 ; Can store up to 6 digits
|
||||||
|
|
||||||
|
int_tmp: dw 0
|
||||||
; Disk operations
|
; Disk operations
|
||||||
disk_read_fail: db 'Error: Could not read disk\n', 0
|
disk_read_fail: db 'Error: Could not read disk\n', 0
|
||||||
file_not_found: db 'File not found\n', 0
|
file_not_found: db 'File not found\n', 0
|
||||||
@@ -59,3 +60,4 @@ read_write_flag: db 02
|
|||||||
empty_byte: db 0
|
empty_byte: db 0
|
||||||
empty_word: dw 0
|
empty_word: dw 0
|
||||||
empty_dword: dd 0
|
empty_dword: dd 0
|
||||||
|
tmp: db '97', 0
|
||||||
|
|||||||
@@ -318,7 +318,6 @@ clear_ram:
|
|||||||
assign:
|
assign:
|
||||||
cmp ax, VARIABLE ; Are we starting with a number var?
|
cmp ax, VARIABLE ; Are we starting with a number var?
|
||||||
je .do_num_var
|
je .do_num_var
|
||||||
|
|
||||||
mov di, string_vars ; Otherwise it's a string var
|
mov di, string_vars ; Otherwise it's a string var
|
||||||
mov ax, 128
|
mov ax, 128
|
||||||
mul bx ; (BX = string number, passed back from get_token)
|
mul bx ; (BX = string number, passed back from get_token)
|
||||||
|
|||||||
2
source/kernel/features/cli.asm
Executable file → Normal file
2
source/kernel/features/cli.asm
Executable file → Normal file
@@ -17,7 +17,7 @@ os_start_cli:
|
|||||||
|
|
||||||
os_read_cli:
|
os_read_cli:
|
||||||
pusha
|
pusha
|
||||||
mov si, user_input
|
mov ax, user_input
|
||||||
call string_upper_case ; Make the input uppercase so it's case insensitive
|
call string_upper_case ; Make the input uppercase so it's case insensitive
|
||||||
|
|
||||||
.output_the_user_input:
|
.output_the_user_input:
|
||||||
|
|||||||
@@ -308,6 +308,7 @@ disk_write_file:
|
|||||||
; OUT
|
; OUT
|
||||||
; output_buffer: the list (string)
|
; output_buffer: the list (string)
|
||||||
disk_list_contents:
|
disk_list_contents:
|
||||||
|
call disk_load_root
|
||||||
pusha
|
pusha
|
||||||
mov si, root_buffer
|
mov si, root_buffer
|
||||||
mov di, output_buffer
|
mov di, output_buffer
|
||||||
@@ -322,38 +323,22 @@ disk_list_contents:
|
|||||||
dec cx
|
dec cx
|
||||||
cmp cx, 0
|
cmp cx, 0
|
||||||
jne .space_loop
|
jne .space_loop
|
||||||
|
mov ax, [si+28d]
|
||||||
.file_attribute:
|
call string_cast_from_int
|
||||||
add si, 11d
|
|
||||||
lodsb
|
|
||||||
push si
|
push si
|
||||||
|
mov si, stringified_int
|
||||||
mov si, read_only
|
lodsb
|
||||||
cmp al, 1h
|
.output_file_size_loop:
|
||||||
je .add_string
|
stosb
|
||||||
mov si, hidden
|
lodsb
|
||||||
cmp al, 2h
|
cmp al, 0
|
||||||
je .add_string
|
jne .output_file_size_loop
|
||||||
mov si, system
|
.after_fs_loop:
|
||||||
cmp al, 4h
|
|
||||||
je .add_string
|
|
||||||
mov si, volume
|
|
||||||
cmp al, 8h
|
|
||||||
je .add_string
|
|
||||||
mov si, directory
|
|
||||||
cmp al, 10h
|
|
||||||
je .add_string
|
|
||||||
mov si, archive
|
|
||||||
cmp al, 20h
|
|
||||||
je .add_string
|
|
||||||
|
|
||||||
.after_file_attributes:
|
|
||||||
pop si
|
pop si
|
||||||
|
|
||||||
mov al, 0Ah
|
mov al, 0Ah
|
||||||
stosb
|
stosb
|
||||||
|
|
||||||
add si, 20d
|
add si, 20h
|
||||||
lodsb ; +1
|
lodsb ; +1
|
||||||
dec si ; -1
|
dec si ; -1
|
||||||
cmp al, 0 ; You've come to the end of the root entries
|
cmp al, 0 ; You've come to the end of the root entries
|
||||||
@@ -361,13 +346,6 @@ disk_list_contents:
|
|||||||
cmp al, 00E5h ; E5h is a marker that the Fat entry is available
|
cmp al, 00E5h ; E5h is a marker that the Fat entry is available
|
||||||
je .finish
|
je .finish
|
||||||
jmp .loop
|
jmp .loop
|
||||||
.add_string:
|
|
||||||
.add_string_loop:
|
|
||||||
lodsb
|
|
||||||
cmp ax, 00h
|
|
||||||
je .after_file_attributes
|
|
||||||
stosb
|
|
||||||
jmp .add_string_loop
|
|
||||||
.finish:
|
.finish:
|
||||||
mov cx, output_buffer
|
mov cx, output_buffer
|
||||||
sub di, cx
|
sub di, cx
|
||||||
|
|||||||
0
source/kernel/features/power.asm
Executable file → Normal file
0
source/kernel/features/power.asm
Executable file → Normal file
131
source/kernel/features/strings.asm
Executable file → Normal file
131
source/kernel/features/strings.asm
Executable file → Normal file
@@ -107,89 +107,84 @@ string_join:
|
|||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
; TODO
|
; TODO
|
||||||
|
; Converts a null terminated string to an integer
|
||||||
|
; IN: SI = string location (max 5 chars, up to '65536')
|
||||||
|
; OUT: AX = number
|
||||||
string_cast_to_int:
|
string_cast_to_int:
|
||||||
|
pusha
|
||||||
|
xor cx,cx
|
||||||
|
.loop:
|
||||||
|
xor ax,ax
|
||||||
|
lodsb
|
||||||
|
cmp al, 0
|
||||||
|
je .finish
|
||||||
|
sub al, 30h
|
||||||
|
mov bx, ax
|
||||||
|
mov ax, 10
|
||||||
|
mul cx ; Multiple the current value by 10
|
||||||
|
add ax, bx ; Then add the new digit
|
||||||
|
mov cx, ax
|
||||||
|
jmp .loop
|
||||||
|
.finish:
|
||||||
|
mov [int_tmp], cx
|
||||||
|
popa
|
||||||
|
mov ax, [int_tmp]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
; IN: AX = integer (unsigned)
|
||||||
|
; OUT: AX -> null-terminated string
|
||||||
|
|
||||||
; IN: AX = int
|
string_cast_from_int:
|
||||||
; OUT: AX = string location (output buffer)
|
|
||||||
string_cast_from_int: ; TODO I think this algorithm could be optimised
|
|
||||||
pusha
|
pusha
|
||||||
; Initialise base to decimal (base 10)
|
cld ; Write backwards
|
||||||
mov bx, 10
|
|
||||||
; clear the strigified int location
|
|
||||||
mov cx, 6
|
|
||||||
push ax
|
|
||||||
xor ax,ax
|
|
||||||
.clear_loop:
|
|
||||||
stosb
|
|
||||||
dec cx
|
|
||||||
cmp cx, 0
|
|
||||||
ja .clear_loop
|
|
||||||
; setup
|
|
||||||
pop ax
|
|
||||||
push ax
|
|
||||||
mov cx, -1
|
|
||||||
; loop over number to get the value of count (cx)
|
|
||||||
.count_loop:
|
|
||||||
xor dx,dx
|
|
||||||
div bx ; ax = ax // bx
|
|
||||||
inc cx
|
|
||||||
cmp ax, 0
|
|
||||||
ja .count_loop ; Jump if greater
|
|
||||||
pop ax
|
|
||||||
; loop over count downwards until count is 0
|
|
||||||
mov di, stringified_int
|
mov di, stringified_int
|
||||||
.stringify_loop:
|
|
||||||
mov cx,1 ;DEL
|
mov bx, 10 ; base
|
||||||
push cx
|
mov cx, 0 ; digit count
|
||||||
push bx
|
|
||||||
push ax
|
.convert_loop:
|
||||||
; Generate power of 10
|
xor dx, dx
|
||||||
mov ax, 1
|
div bx ; AX = AX / base, DX = remainder
|
||||||
mov cx,0 ;DEL
|
add dl, '0'
|
||||||
cmp cx, 1
|
push dx ; store digit
|
||||||
jl .after_power_loop
|
inc cx
|
||||||
.power_loop:
|
test ax, ax
|
||||||
mul bx
|
jnz .convert_loop
|
||||||
dec cx
|
|
||||||
cmp cx, 0
|
.write_loop:
|
||||||
ja .power_loop
|
|
||||||
.after_power_loop:
|
|
||||||
mov bx,ax
|
|
||||||
pop ax
|
pop ax
|
||||||
pop cx
|
|
||||||
; ax = ax DIV bx
|
|
||||||
; dx = ax MOD bx
|
|
||||||
xor dx,dx
|
|
||||||
div bx
|
|
||||||
pop bx
|
|
||||||
add ax, 30h
|
|
||||||
stosb
|
stosb
|
||||||
mov ax, dx
|
loop .write_loop
|
||||||
dec cx
|
|
||||||
cmp cx, 0
|
mov al, 0
|
||||||
ja .stringify_loop
|
stosb ; null terminator
|
||||||
.finish:
|
|
||||||
popa
|
popa
|
||||||
;mov ax, stringified_int
|
mov ax, stringified_int
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
|
||||||
; Get the length of a string
|
; Get the length of a string
|
||||||
; 'hello world', 0 is 11 characters long (excluding the terminator)
|
; 'hello world', 0 is 11 characters long (excluding the terminator)
|
||||||
; input: si points to the string to be counted
|
; input: ax points to the string to be counted
|
||||||
; output: cl holds the length
|
; output: ax holds the length
|
||||||
string_length:
|
string_length:
|
||||||
push si
|
push si
|
||||||
xor cl,cl ; Clear the al register
|
push cx
|
||||||
|
mov si, ax
|
||||||
|
xor ax,ax ; Clear the cx register
|
||||||
|
xor cx,cx
|
||||||
.loop:
|
.loop:
|
||||||
lodsb
|
lodsb
|
||||||
cmp al, 0
|
cmp al, 0
|
||||||
je .finish
|
je .finish
|
||||||
inc cl
|
inc cx
|
||||||
jmp .loop
|
jmp .loop
|
||||||
.finish:
|
.finish:
|
||||||
|
mov ax, cx
|
||||||
|
pop cx
|
||||||
pop si
|
pop si
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@@ -204,7 +199,9 @@ string_length:
|
|||||||
os_format_fat_filename:
|
os_format_fat_filename:
|
||||||
pusha
|
pusha
|
||||||
call string_upper_case
|
call string_upper_case
|
||||||
|
mov ax, si
|
||||||
call string_length ; Stores the length of the string in cl
|
call string_length ; Stores the length of the string in cl
|
||||||
|
mov cl, al
|
||||||
xor ch,ch ; Clear ch to reset it to 0
|
xor ch,ch ; Clear ch to reset it to 0
|
||||||
.character_loop:
|
.character_loop:
|
||||||
lodsb
|
lodsb
|
||||||
@@ -287,12 +284,15 @@ string_unformat_fat_filename:
|
|||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; -------------------------------------------------------------------------------------
|
||||||
|
|
||||||
; Convert a string to all upper/lower case
|
; Convert a string to all upper/lower case
|
||||||
; INPUT: si pointing to a string
|
; INPUT: ax pointing to a string
|
||||||
; OUPUT: the same string in memory will now be capitalised/decapitalised
|
; OUPUT: the same string in memory will now be capitalised/decapitalised
|
||||||
string_upper_case: ; to upper case
|
string_upper_case: ; to upper case
|
||||||
pusha
|
pusha
|
||||||
mov di, si
|
mov si,ax
|
||||||
|
mov di,si
|
||||||
.loop:
|
.loop:
|
||||||
lodsb ; Load the character into al
|
lodsb ; Load the character into al
|
||||||
inc di
|
inc di
|
||||||
@@ -310,8 +310,9 @@ string_upper_case: ; to upper case
|
|||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
os_lower_case: ; to lower case
|
string_lower_case: ; to lower case
|
||||||
pusha
|
pusha
|
||||||
|
mov si, ax
|
||||||
mov di, si
|
mov di, si
|
||||||
.loop:
|
.loop:
|
||||||
lodsb ; Load the character into al
|
lodsb ; Load the character into al
|
||||||
@@ -330,8 +331,6 @@ os_lower_case: ; to lower case
|
|||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
string_lower_case:
|
|
||||||
ret
|
|
||||||
string_input:
|
string_input:
|
||||||
ret
|
ret
|
||||||
string_print_2hex:
|
string_print_2hex:
|
||||||
|
|||||||
0
source/kernel/features/text.asm
Executable file → Normal file
0
source/kernel/features/text.asm
Executable file → Normal file
@@ -17,7 +17,6 @@ util_cat:
|
|||||||
util_ls:
|
util_ls:
|
||||||
pusha
|
pusha
|
||||||
|
|
||||||
call disk_load_root
|
|
||||||
call disk_list_contents
|
call disk_list_contents
|
||||||
|
|
||||||
mov si, output_buffer
|
mov si, output_buffer
|
||||||
|
|||||||
@@ -11,11 +11,9 @@ start:
|
|||||||
mov si, boot_message
|
mov si, boot_message
|
||||||
call os_print_string
|
call os_print_string
|
||||||
|
|
||||||
; TESTING
|
mov si, tmp
|
||||||
;mov ax, 3
|
mov ah, 0Eh
|
||||||
;call string_cast_from_int
|
int 10h
|
||||||
;mov si, stringified_int
|
|
||||||
;call os_print_string
|
|
||||||
|
|
||||||
call os_start_cli
|
call os_start_cli
|
||||||
hlt
|
hlt
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ sudo make
|
|||||||
sudo chown $(whoami) disk_images/*
|
sudo chown $(whoami) disk_images/*
|
||||||
qemu-system-i386\
|
qemu-system-i386\
|
||||||
-drive file=disk_images/crawos.img,if=floppy,format=raw\
|
-drive file=disk_images/crawos.img,if=floppy,format=raw\
|
||||||
-m 512m\
|
-m 8m\
|
||||||
-object memory-backend-file,id=pc.ram,size=512m,mem-path=/dev/shm/qemu-ram,share=on\
|
-object memory-backend-file,id=pc.ram,size=8m,mem-path=/dev/shm/qemu-ram,share=on\
|
||||||
-machine memory-backend=pc.ram\
|
-machine memory-backend=pc.ram\
|
||||||
-d in_asm,int -D ./detailed.log\
|
-d in_asm,int -D ./detailed.log\
|
||||||
$1 $2
|
$1 $2
|
||||||
|
|||||||
Reference in New Issue
Block a user