Before C Switch

This commit is contained in:
2024-03-08 19:28:09 +01:00
parent da52676e78
commit 2f3b4f6e6b
4 changed files with 47 additions and 39 deletions
+2
View File
@@ -39,3 +39,5 @@ _These images may be outdated, Idk_
- If you run the kernel.bin, loading files sorta breaks, because the program is running at 0x8000, but it thinks that it's at 0x2000 (i think) - If you run the kernel.bin, loading files sorta breaks, because the program is running at 0x8000, but it thinks that it's at 0x2000 (i think)
- If you run anything in the code editor and return to the kernel, you won't be able to load any files - If you run anything in the code editor and return to the kernel, you won't be able to load any files
- If you type only the starting letters of a command, it will still run (i.e. 'he' will run help) - If you type only the starting letters of a command, it will still run (i.e. 'he' will run help)
## [Old Version](https://github.com/Tom-on64/old-kern)
+5 -1
View File
@@ -256,6 +256,10 @@ getInput:
; Expects al to contain an ASCII character, will set bx to it's hex equivalent ; Expects al to contain an ASCII character, will set bx to it's hex equivalent
asciiToHex: asciiToHex:
cmp al, 'F'
jle .upperCase
sub al, 32
.upperCase:
cmp al, '9' cmp al, '9'
jle .getHex jle .getHex
sub al, 7 sub al, 7
@@ -275,7 +279,7 @@ saveFileMsg: db "Save as: ", 0 ; Make sure to erase
openFileMsg: db "Open file: ", 0 openFileMsg: db "Open file: ", 0
bytesMsg: db " Bytes", 0 bytesMsg: db " Bytes", 0
; savedMsg: db "Saved file as '", 0 ; savedMsg: db "Saved file as '", 0
; oepenedMsg: db "Editing file '", 0 ; openedMsg: db "Editing file '", 0
runMsg: db ENDL, ENDL, 0 runMsg: db ENDL, ENDL, 0
ranMsg: db ENDL, ENDL, " - Finished Execution - ", ENDL, 0 ranMsg: db ENDL, ENDL, " - Finished Execution - ", ENDL, 0
notFoundMsg: db "File not found! ", 0 ; Erase the user input notFoundMsg: db "File not found! ", 0 ; Erase the user input
+35 -36
View File
@@ -66,23 +66,16 @@ input:
je input je input
tokenize: ; Tokenize tokenize: ; Tokenize
mov byte cl, [inputLen] mov si, userInput
mov di, tokens .loop:
.tokenLoop: inc si
lodsb cmp byte [si], 0
cmp al, 0 ; Check for end of input je .done
je runCommand cmp byte [si], ' '
.wsLoop: jne .loop
cmp al, ' ' ; Compare with whitespace mov byte [si], 0
jne .stringLoop jmp .loop
lodsb .done:
jmp .wsLoop
.stringLoop:
cmp al, ' '
je .next
.next:
; Runs a command in userInput ; Runs a command in userInput
; Expects tokenized input ; Expects tokenized input
@@ -188,25 +181,33 @@ foundProgram:
inc bx ; Ignore Number of FT entries for now inc bx ; Ignore Number of FT entries for now
mov cl, [es:bx] ; Starting sector ; mov cl, [es:bx] ; Starting sector
inc bx ; inc bx
mov al, [es:bx] ; Number of sectors to read ; mov al, [es:bx] ; Number of sectors to read
push ax ; Save file size ; push ax ; Save file size
mov ah, 0 ; Reset disk system ; mov ah, 0 ; Reset disk system
mov dl, byte [driveNum] ; mov dl, byte [driveNum]
int 0x13 ; int 0x13
mov bx, PROGRAM_LOC ; mov bx, PROGRAM_LOC
mov es, bx ; mov es, bx
xor bx, bx ; [es:bx] - Place to load out program ; xor bx, bx ; [es:bx] - Place to load out program
mov ah, 2 ; Read sectors into memory ; mov ah, 2 ; Read sectors into memory
mov dl, byte [driveNum] ; mov dl, byte [driveNum]
mov ch, 0 ; Cylinder ; mov ch, 0 ; Cylinder
mov dh, 0 ; Head ; mov dh, 0 ; Head
int 0x13 ; int 0x13
jnc .loaded ; Loaded file successfully
mov byte dl, [driveNum] ; Drive number
push word userInput ; Filename
push word PROGRAM_LOC ; Dest. segment
push word 0x0000 ; Dest. offset
call loadFile
cmp byte al, 0
je .loaded ; Loaded file successfully
mov si, programLoadFailMsg mov si, programLoadFailMsg
call print call print
@@ -491,10 +492,8 @@ fileExt: db " ", 0
binExt: db "bin", 0 binExt: db "bin", 0
txtExt: db "txt", 0 txtExt: db "txt", 0
tokens: times 50 db 0 ; char[10][5] (List of 5 strings that are 10 chars long each or null terminated)
tokenLen: times 5 db 0 ; 5 lengths for each token
tokenCount: db 0
inputLen: db 0 inputLen: db 0
tokenCount: db 0
userInput: times 80 db 0 userInput: times 80 db 0
;; Constants ;; Constants
+5 -2
View File
@@ -1,7 +1,7 @@
; ;
; Loads a file from the filetable into a memory location ; Loads a file from the filetable into a memory location
; Params: ; Params:
; dl - Disk number ; dl - Disk number (byte)
; Filename (Null terminated) ; Filename (Null terminated)
; Destination location segment ; Destination location segment
; Destination location offset ; Destination location offset
@@ -42,6 +42,9 @@ loadFile:
stosb stosb
loop .filenamePadLoop loop .filenamePadLoop
.filenameDone: .filenameDone:
mov si, fileName
call print
mov ax, FILETAB_LOC mov ax, FILETAB_LOC
mov es, ax mov es, ax
xor di, di ; es:di - Filetable location xor di, di ; es:di - Filetable location
@@ -311,7 +314,7 @@ returnToCaller:
; Filename ; Filename
; ;
removeFile: removeFile:
ret
;; Variables ;; Variables
availableSector: db 0 availableSector: db 0