Made a better filetable, and added commands

Note: if you write the starting part of the command, it will still run
This commit is contained in:
2023-12-23 21:49:42 +01:00
parent 5d787348b1
commit 8b3cbc3e92
6 changed files with 239 additions and 76 deletions
+1 -1
View File
@@ -1 +1 @@
./build/** build
+13 -2
View File
@@ -3,8 +3,19 @@
start: start:
mov si, msg mov si, msg
call print call print
cli
hlt xor ax, ax
int 0x16
.return:
mov ax, 0x2000
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x2000:0x0000
%include "./src/print.asm" %include "./src/print.asm"
View File
+18 -6
View File
@@ -1,8 +1,20 @@
; Simple Filetable ; ------------------
db "{" ; Start ; Simple Filetable
db "kernel.bin:03," ; ------------------
db "calc:05," ;
db "coolThing:06" ; 16 Byte entries
db "}" ; End ; 0-9 - Filename
; 10-12 - File extension (type)
; 13 - Number of filetable entries
; 14 - Starting Sector
; 15 - Filesize in sectors (n * 512)
;
; ------------------
filetable:
db 'boot',0,0,0,0,0,0,'bin',0,1,1 ; boot.bin - start: 1, size: 1
db 'filetable',0,'txt',0,2,1 ; filetable.txt - start: 2, size: 1
db 'kernel',0,0,0,0,'bin',0,3,2 ; kernel.bin - start: 3, size: 2
db 'calc',0,0,0,0,0,0,'bin',0,5,1 ; calc.bin - start: 5, size: 1
times 512-($-$$) db 0 times 512-($-$$) db 0
+171 -67
View File
@@ -4,6 +4,11 @@ start:
; Save the drive number from stack ; Save the drive number from stack
mov byte [driveNumber], dl mov byte [driveNumber], dl
mov bx, 0x8000
mov es, bx
xor bx, bx
call resetTextMode call resetTextMode
; Print start message ; Print start message
@@ -14,7 +19,10 @@ start:
input: input:
mov si, prompt mov si, prompt
call print call print
mov di, userInput mov ax, 0x2000
mov ds, ax
mov es, ax
mov si, userInput
xor cx, cx xor cx, cx
.loop: .loop:
xor ax, ax ; Clear ax xor ax, ax ; Clear ax
@@ -26,25 +34,50 @@ input:
cmp al, 0x0d ; Compare with CR cmp al, 0x0d ; Compare with CR
je .enter je .enter
mov [di], al ; Add the input to userInput mov [si], al ; Add the input to userInput
inc cl inc cx
inc di inc si
jmp .loop jmp .loop
.enter: .enter:
mov al, 0x0a ; Print LF mov al, 0x0a ; Print LF
int 0x10 int 0x10
mov byte [di], 0 ; NULL terminate userInput (Replaces CR) mov byte [si], 0 ; NULL terminate userInput (Replaces CR)
mov byte [inputLen], cl mov byte [inputLen], cl
mov al, [userInput] cmp byte [inputLen], 0 ; Check if user input something
cmp al, 'H' je input
je help
cmp al, 'F' ; Runs a command in userInput
je fileBrowser runCommand:
cmp al, 'G' mov di, lsCmd
call .cmp
je fileList
mov di, gfxCmd
call .cmp
je graphicsTest je graphicsTest
cmp al, 'R'
mov di, helpCmd
call .cmp
je help
mov di, rebootCmd
call .cmp
je reboot je reboot
mov di, clearCmd
call .cmp
je clearScreen
jmp .end
.cmp:
push cx
mov si, userInput
repe cmpsb
pop cx
ret
.end:
; ;
; Load Program - Takes userInput and tries to run that file ; Load Program - Takes userInput and tries to run that file
; ;
@@ -55,13 +88,13 @@ loadProgram:
xor bx, bx ; Get [es:bx] to be start of filetable xor bx, bx ; Get [es:bx] to be start of filetable
.nextCh: .nextCh:
mov al, [es:bx] mov al, [es:bx]
cmp al, '}' ; Check for end of filetable cmp al, 0 ; Check for end of filetable
je .notFound je .notFound
cmp al, [di] ; Check for starting character cmp al, [di] ; Check for starting character
je .beginSearch je .beginSearch
inc bx add bx, 16 ; Move to the next entry
jmp .nextCh jmp .nextCh
.beginSearch: .beginSearch:
push bx ; Save position, if it doesn't equal push bx ; Save position, if it doesn't equal
@@ -78,7 +111,7 @@ loadProgram:
jmp .searchLoop jmp .searchLoop
.match: .match:
mov al, [es:bx] mov al, [es:bx]
cmp al, ':' ; Check if we are at the end of a filename cmp al, 0 ; Check if we are at the end of a filename
je executeProgram je executeProgram
.restartSearch: .restartSearch:
mov di, userInput mov di, userInput
@@ -90,30 +123,19 @@ loadProgram:
call print call print
jmp input jmp input
; Expects [es:bx] to point to a sector number folowed by a comma ('XX,' where X is 0-9)
executeProgram: executeProgram:
mov cl, 10 ; Get 10 to multiply with mov al, [es:bx]
xor al, al ; Reset al cmp al, 0 ; Loop until we find the extension
inc bx ; Skip ':' jne .getMetadata
.getSectorNum:
mov dl, [es:bx]
inc bx inc bx
cmp dl, ',' ; Check if its end of sector number jmp executeProgram
je .load .getMetadata:
cmp dl, '0' ; Check if it is a digit 0-9 add bx, 3 ; Skip the file extension
jl .notFound inc bx ; Ignore Number of FT entries for now
cmp dl, '9'
jg .notFound mov cl, [es:bx] ; Starting sector
sub dl, '0' ; Convert ASCII char to an integer inc bx
mul cl ; ax *= cl (al *= 10) mov al, [es:bx] ; Number of sectors to read
add al, dl ; al += dl
jmp .getSectorNum
.notFound:
mov si, sectorNotFoundMsg
call print
jmp input
.load:
mov cl, al ; Sector
mov ah, 0 ; Reset disk system mov ah, 0 ; Reset disk system
mov dl, byte [driveNumber] mov dl, byte [driveNumber]
@@ -125,7 +147,6 @@ executeProgram:
mov ah, 2 ; Read sectors into memory mov ah, 2 ; Read sectors into memory
mov dl, byte [driveNumber] mov dl, byte [driveNumber]
mov al, 1 ; Read 1 sector
mov ch, 0 ; Cylinder mov ch, 0 ; Cylinder
mov dh, 0 ; Head mov dh, 0 ; Head
int 0x13 int 0x13
@@ -154,10 +175,17 @@ help:
jmp input jmp input
; ;
; File Browser ; Clears the screen
; ;
fileBrowser: clearScreen:
mov si, browserMsg call resetTextMode
jmp input
;
; File list (ls)
;
fileList:
mov si, fileListMsg
call print call print
; Prints the filetable ; Prints the filetable
@@ -165,34 +193,99 @@ printFiletable:
mov bx, FILETAB_LOC mov bx, FILETAB_LOC
mov es, bx mov es, bx
xor bx, bx xor bx, bx
xor cx, cx xor cx, cx ; Entry byte couter
.filetableLoop: mov ah, 0x0e ; Prepare for printing
.filenameLoop:
mov al, [es:bx] ; Get filename character
cmp al, 0 ; Check if it's NULL
je .filenameEnd ; If so, end the filename reading
cmp cx, 9 ; Check if we already read 10 Bytes
je .filenameEnd
int 0x10 ; Else print the character
inc cx ; Increment byte counter
inc bx inc bx
mov al, [es:bx] ; Get the filetable character jmp .filenameLoop
cmp al, '}' ; Check for filetable end .filenameEnd:
push cx
.skipNull:
cmp cx, 0
je .done je .done
cmp al, ':' ; Check for sector number cmp cx, 10 ; Check if we're at the end of filename
je .sectorLoop je .fileExt ; If so, print extension
cmp al, ',' ; Check for another entry
je .entryLoop
inc cx inc cx
inc bx
jmp .skipNull
.fileExt:
; push cx ; Save the counter
mov al, '.' ; Print a "." to separate filename from extension
int 0x10 int 0x10
jmp .filetableLoop .fileExtLoop:
.sectorLoop: mov al, [es:bx]
cmp cx, 20 cmp cx, 13 ; Check if we printed 3 characters
je .filetableLoop je .fileExtEnd
cmp al, 0
je .fileExtEnd
int 0x10
inc cx
inc bx
jmp .fileExtLoop
.fileExtEnd:
cmp cx, 13
je .whitespace
inc cx
inc bx
mov al, ' ' ; Print whitespace
int 0x10
jmp .fileExtEnd
.whitespace:
pop cx
.wsLoop:
cmp cx, 11 ; Max filename length + 1 for spacing
je .fileInfo
mov al, ' ' mov al, ' '
int 0x10 int 0x10
inc cx inc cx
jmp .sectorLoop jmp .wsLoop
.entryLoop: .fileInfo:
; Entry number
mov dl, [es:bx]
call printHexByte
inc bx
mov al, ' '
int 0x10
; Start sector
mov dl, [es:bx]
call printHexByte
inc bx
mov al, ' '
int 0x10
; File size
mov al, [es:bx]
inc bx
cmp al, 1
je .oneSector ; Only print 512B
shr al, 1 ; Divide by 2
jc .oneHalf ; We had an odd number of sectors
add al, '0'
int 0x10
mov si, kilobyteText
call print
jmp .repeat
.oneHalf:
add al, '0'
int 0x10
mov si, oneHalfText
call print
jmp .repeat
.oneSector:
mov si, sectorLenText
call print
.repeat:
mov si, newline
call print
xor cx, cx xor cx, cx
mov si, newline jmp .filenameLoop
call print
jmp .filetableLoop
.done: .done:
mov si, newline
call print
jmp input jmp input
; ;
@@ -249,17 +342,28 @@ driveNumber: db 0
startMsg: db "kern.", ENDL, ENDL, 0 ; The bootup message startMsg: db "kern.", ENDL, ENDL, 0 ; The bootup message
prompt: db "> ", 0 ; Prompt for input prompt: db "> ", 0 ; Prompt for input
fileNotFoundMsg: db "File not found!", ENDL, 0 ; User tries to load nonexistent file fileNotFoundMsg: db "File not found!", ENDL, 0 ; User tries to load nonexistent file
sectorNotFoundMsg: db "Sector not found!", ENDL, 0 ; File in an incorrect sector in filetable
programLoadFailMsg: db "Failed while loading program!", ENDL, 0 ; File load fail programLoadFailMsg: db "Failed while loading program!", ENDL, 0 ; File load fail
sectorLenText: db "512B", 0
kilobyteText: db "kB", 0
oneHalfText: db ".5kB", 0
browserMsg: db " Filename Sector ", ENDL, \ fileListMsg: db " Filename E# St Size ", ENDL, \
"---------- --------", ENDL, 0 "---------- ------------", ENDL, 0
helpMsg: db "Available Commands:", ENDL, \ helpMsg: db "Available Commands:", ENDL, \
"F - List all files", ENDL, \ "clear - Clears the screen", ENDL, \
"G - Graphics mode test", ENDL, \ "gfx - Graphics mode test", ENDL, \
"H - Help", ENDL, \ "help - Prints this message", ENDL, \
"R - Reboot", ENDL, 0 "ls - List all files", ENDL, \
"reboot - Reboots the system", ENDL, 0
; Commands
; TODO: Put these into a file or something
lsCmd: db "ls", 0
helpCmd: db "help", 0
gfxCmd: db "gfx", 0
rebootCmd: db "reboot", 0
clearCmd: db "clear", 0
inputLen: db 0 inputLen: db 0
userInput: db 0 userInput: db 0
+36
View File
@@ -46,8 +46,44 @@ printHex:
popa popa
ret ret
;
; Prints a hex byte
; dl - Hex byte
;
printHexByte:
pusha
xor cx, cx
.loop:
mov al, dl
and al, 0xF0
ror al, 4
add al, '0'
cmp al, '9'
jle .hexNum
add al, 7
.hexNum:
mov ah, 0x0e
int 0x10
inc cx
cmp cx, 2
je .done
ror dl, 4
jmp .loop
.done:
popa
ret
hexString: db "0x0000", 0 hexString: db "0x0000", 0
;
; Clears the screen
;
clear:
pusha
; TODO: Make this function
popa
ret
; Usefull definitions ; Usefull definitions
%define ENDL 0x0a, 0x0d %define ENDL 0x0a, 0x0d
newline: db ENDL, 0 ; CRLF newline: db ENDL, 0 ; CRLF