From 2f3b4f6e6bbb5585076c82aa05685a781c2c44aa Mon Sep 17 00:00:00 2001 From: Tom-on64 Date: Fri, 8 Mar 2024 19:28:09 +0100 Subject: [PATCH] Before C Switch --- README.md | 2 ++ src/fs/edit.asm | 6 +++- src/kernel.asm | 71 ++++++++++++++++++++++++------------------------ src/lib/disk.asm | 7 +++-- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index cf1071d..0812f44 100644 --- a/README.md +++ b/README.md @@ -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 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) + +## [Old Version](https://github.com/Tom-on64/old-kern) diff --git a/src/fs/edit.asm b/src/fs/edit.asm index 0e86338..0637402 100644 --- a/src/fs/edit.asm +++ b/src/fs/edit.asm @@ -256,6 +256,10 @@ getInput: ; Expects al to contain an ASCII character, will set bx to it's hex equivalent asciiToHex: + cmp al, 'F' + jle .upperCase + sub al, 32 +.upperCase: cmp al, '9' jle .getHex sub al, 7 @@ -275,7 +279,7 @@ saveFileMsg: db "Save as: ", 0 ; Make sure to erase openFileMsg: db "Open file: ", 0 bytesMsg: db " Bytes", 0 ; savedMsg: db "Saved file as '", 0 -; oepenedMsg: db "Editing file '", 0 +; openedMsg: db "Editing file '", 0 runMsg: db ENDL, ENDL, 0 ranMsg: db ENDL, ENDL, " - Finished Execution - ", ENDL, 0 notFoundMsg: db "File not found! ", 0 ; Erase the user input diff --git a/src/kernel.asm b/src/kernel.asm index 62e8118..fd6a2d8 100644 --- a/src/kernel.asm +++ b/src/kernel.asm @@ -66,23 +66,16 @@ input: je input tokenize: ; Tokenize - mov byte cl, [inputLen] - mov di, tokens -.tokenLoop: - lodsb - cmp al, 0 ; Check for end of input - je runCommand -.wsLoop: - cmp al, ' ' ; Compare with whitespace - jne .stringLoop - lodsb - jmp .wsLoop -.stringLoop: - cmp al, ' ' - je .next - -.next: - + mov si, userInput +.loop: + inc si + cmp byte [si], 0 + je .done + cmp byte [si], ' ' + jne .loop + mov byte [si], 0 + jmp .loop +.done: ; Runs a command in userInput ; Expects tokenized input @@ -188,25 +181,33 @@ foundProgram: inc bx ; Ignore Number of FT entries for now - mov cl, [es:bx] ; Starting sector - inc bx - mov al, [es:bx] ; Number of sectors to read - push ax ; Save file size + ; mov cl, [es:bx] ; Starting sector + ; inc bx + ; mov al, [es:bx] ; Number of sectors to read + ; push ax ; Save file size - mov ah, 0 ; Reset disk system - mov dl, byte [driveNum] - int 0x13 + ; mov ah, 0 ; Reset disk system + ; mov dl, byte [driveNum] + ; int 0x13 - mov bx, PROGRAM_LOC - mov es, bx - xor bx, bx ; [es:bx] - Place to load out program + ; mov bx, PROGRAM_LOC + ; mov es, bx + ; xor bx, bx ; [es:bx] - Place to load out program - mov ah, 2 ; Read sectors into memory - mov dl, byte [driveNum] - mov ch, 0 ; Cylinder - mov dh, 0 ; Head - int 0x13 - jnc .loaded ; Loaded file successfully + ; mov ah, 2 ; Read sectors into memory + ; mov dl, byte [driveNum] + ; mov ch, 0 ; Cylinder + ; mov dh, 0 ; Head + ; int 0x13 + + 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 call print @@ -491,10 +492,8 @@ fileExt: db " ", 0 binExt: db "bin", 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 +tokenCount: db 0 userInput: times 80 db 0 ;; Constants diff --git a/src/lib/disk.asm b/src/lib/disk.asm index 004e89f..59a11e7 100644 --- a/src/lib/disk.asm +++ b/src/lib/disk.asm @@ -1,7 +1,7 @@ ; ; Loads a file from the filetable into a memory location ; Params: -; dl - Disk number +; dl - Disk number (byte) ; Filename (Null terminated) ; Destination location segment ; Destination location offset @@ -42,6 +42,9 @@ loadFile: stosb loop .filenamePadLoop .filenameDone: + mov si, fileName + call print + mov ax, FILETAB_LOC mov es, ax xor di, di ; es:di - Filetable location @@ -311,8 +314,8 @@ returnToCaller: ; Filename ; removeFile: + ret - ;; Variables availableSector: db 0 exitCode: db 0