mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
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:
+1
-1
@@ -1 +1 @@
|
||||
./build/**
|
||||
build
|
||||
|
||||
+13
-2
@@ -3,8 +3,19 @@
|
||||
start:
|
||||
mov si, msg
|
||||
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"
|
||||
|
||||
|
||||
+17
-5
@@ -1,8 +1,20 @@
|
||||
; ------------------
|
||||
; Simple Filetable
|
||||
db "{" ; Start
|
||||
db "kernel.bin:03,"
|
||||
db "calc:05,"
|
||||
db "coolThing:06"
|
||||
db "}" ; End
|
||||
; ------------------
|
||||
;
|
||||
; 16 Byte entries
|
||||
; 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
|
||||
|
||||
+171
-67
@@ -4,6 +4,11 @@ start:
|
||||
; Save the drive number from stack
|
||||
mov byte [driveNumber], dl
|
||||
|
||||
|
||||
mov bx, 0x8000
|
||||
mov es, bx
|
||||
xor bx, bx
|
||||
|
||||
call resetTextMode
|
||||
|
||||
; Print start message
|
||||
@@ -14,7 +19,10 @@ start:
|
||||
input:
|
||||
mov si, prompt
|
||||
call print
|
||||
mov di, userInput
|
||||
mov ax, 0x2000
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov si, userInput
|
||||
xor cx, cx
|
||||
.loop:
|
||||
xor ax, ax ; Clear ax
|
||||
@@ -26,25 +34,50 @@ input:
|
||||
cmp al, 0x0d ; Compare with CR
|
||||
je .enter
|
||||
|
||||
mov [di], al ; Add the input to userInput
|
||||
inc cl
|
||||
inc di
|
||||
mov [si], al ; Add the input to userInput
|
||||
inc cx
|
||||
inc si
|
||||
jmp .loop
|
||||
.enter:
|
||||
mov al, 0x0a ; Print LF
|
||||
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 al, [userInput]
|
||||
cmp al, 'H'
|
||||
je help
|
||||
cmp al, 'F'
|
||||
je fileBrowser
|
||||
cmp al, 'G'
|
||||
cmp byte [inputLen], 0 ; Check if user input something
|
||||
je input
|
||||
|
||||
; Runs a command in userInput
|
||||
runCommand:
|
||||
mov di, lsCmd
|
||||
call .cmp
|
||||
je fileList
|
||||
|
||||
mov di, gfxCmd
|
||||
call .cmp
|
||||
je graphicsTest
|
||||
cmp al, 'R'
|
||||
|
||||
mov di, helpCmd
|
||||
call .cmp
|
||||
je help
|
||||
|
||||
mov di, rebootCmd
|
||||
call .cmp
|
||||
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
|
||||
;
|
||||
@@ -55,13 +88,13 @@ loadProgram:
|
||||
xor bx, bx ; Get [es:bx] to be start of filetable
|
||||
.nextCh:
|
||||
mov al, [es:bx]
|
||||
cmp al, '}' ; Check for end of filetable
|
||||
cmp al, 0 ; Check for end of filetable
|
||||
je .notFound
|
||||
|
||||
cmp al, [di] ; Check for starting character
|
||||
je .beginSearch
|
||||
|
||||
inc bx
|
||||
add bx, 16 ; Move to the next entry
|
||||
jmp .nextCh
|
||||
.beginSearch:
|
||||
push bx ; Save position, if it doesn't equal
|
||||
@@ -78,7 +111,7 @@ loadProgram:
|
||||
jmp .searchLoop
|
||||
.match:
|
||||
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
|
||||
.restartSearch:
|
||||
mov di, userInput
|
||||
@@ -90,30 +123,19 @@ loadProgram:
|
||||
call print
|
||||
jmp input
|
||||
|
||||
; Expects [es:bx] to point to a sector number folowed by a comma ('XX,' where X is 0-9)
|
||||
executeProgram:
|
||||
mov cl, 10 ; Get 10 to multiply with
|
||||
xor al, al ; Reset al
|
||||
inc bx ; Skip ':'
|
||||
.getSectorNum:
|
||||
mov dl, [es:bx]
|
||||
mov al, [es:bx]
|
||||
cmp al, 0 ; Loop until we find the extension
|
||||
jne .getMetadata
|
||||
inc bx
|
||||
cmp dl, ',' ; Check if its end of sector number
|
||||
je .load
|
||||
cmp dl, '0' ; Check if it is a digit 0-9
|
||||
jl .notFound
|
||||
cmp dl, '9'
|
||||
jg .notFound
|
||||
sub dl, '0' ; Convert ASCII char to an integer
|
||||
mul cl ; ax *= cl (al *= 10)
|
||||
add al, dl ; al += dl
|
||||
jmp .getSectorNum
|
||||
.notFound:
|
||||
mov si, sectorNotFoundMsg
|
||||
call print
|
||||
jmp input
|
||||
.load:
|
||||
mov cl, al ; Sector
|
||||
jmp executeProgram
|
||||
.getMetadata:
|
||||
add bx, 3 ; Skip the file extension
|
||||
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
|
||||
|
||||
mov ah, 0 ; Reset disk system
|
||||
mov dl, byte [driveNumber]
|
||||
@@ -125,7 +147,6 @@ executeProgram:
|
||||
|
||||
mov ah, 2 ; Read sectors into memory
|
||||
mov dl, byte [driveNumber]
|
||||
mov al, 1 ; Read 1 sector
|
||||
mov ch, 0 ; Cylinder
|
||||
mov dh, 0 ; Head
|
||||
int 0x13
|
||||
@@ -154,10 +175,17 @@ help:
|
||||
jmp input
|
||||
|
||||
;
|
||||
; File Browser
|
||||
; Clears the screen
|
||||
;
|
||||
fileBrowser:
|
||||
mov si, browserMsg
|
||||
clearScreen:
|
||||
call resetTextMode
|
||||
jmp input
|
||||
|
||||
;
|
||||
; File list (ls)
|
||||
;
|
||||
fileList:
|
||||
mov si, fileListMsg
|
||||
call print
|
||||
|
||||
; Prints the filetable
|
||||
@@ -165,34 +193,99 @@ printFiletable:
|
||||
mov bx, FILETAB_LOC
|
||||
mov es, bx
|
||||
xor bx, bx
|
||||
xor cx, cx
|
||||
.filetableLoop:
|
||||
xor cx, cx ; Entry byte couter
|
||||
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
|
||||
mov al, [es:bx] ; Get the filetable character
|
||||
cmp al, '}' ; Check for filetable end
|
||||
jmp .filenameLoop
|
||||
.filenameEnd:
|
||||
push cx
|
||||
.skipNull:
|
||||
cmp cx, 0
|
||||
je .done
|
||||
cmp al, ':' ; Check for sector number
|
||||
je .sectorLoop
|
||||
cmp al, ',' ; Check for another entry
|
||||
je .entryLoop
|
||||
cmp cx, 10 ; Check if we're at the end of filename
|
||||
je .fileExt ; If so, print extension
|
||||
inc cx
|
||||
inc bx
|
||||
jmp .skipNull
|
||||
.fileExt:
|
||||
; push cx ; Save the counter
|
||||
mov al, '.' ; Print a "." to separate filename from extension
|
||||
int 0x10
|
||||
jmp .filetableLoop
|
||||
.sectorLoop:
|
||||
cmp cx, 20
|
||||
je .filetableLoop
|
||||
.fileExtLoop:
|
||||
mov al, [es:bx]
|
||||
cmp cx, 13 ; Check if we printed 3 characters
|
||||
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, ' '
|
||||
int 0x10
|
||||
inc cx
|
||||
jmp .sectorLoop
|
||||
.entryLoop:
|
||||
jmp .wsLoop
|
||||
.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
|
||||
mov si, newline
|
||||
call print
|
||||
jmp .filetableLoop
|
||||
jmp .filenameLoop
|
||||
.done:
|
||||
mov si, newline
|
||||
call print
|
||||
jmp input
|
||||
|
||||
;
|
||||
@@ -249,17 +342,28 @@ driveNumber: db 0
|
||||
startMsg: db "kern.", ENDL, ENDL, 0 ; The bootup message
|
||||
prompt: db "> ", 0 ; Prompt for input
|
||||
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
|
||||
sectorLenText: db "512B", 0
|
||||
kilobyteText: db "kB", 0
|
||||
oneHalfText: db ".5kB", 0
|
||||
|
||||
browserMsg: db " Filename Sector ", ENDL, \
|
||||
"---------- --------", ENDL, 0
|
||||
fileListMsg: db " Filename E# St Size ", ENDL, \
|
||||
"---------- ------------", ENDL, 0
|
||||
|
||||
helpMsg: db "Available Commands:", ENDL, \
|
||||
"F - List all files", ENDL, \
|
||||
"G - Graphics mode test", ENDL, \
|
||||
"H - Help", ENDL, \
|
||||
"R - Reboot", ENDL, 0
|
||||
"clear - Clears the screen", ENDL, \
|
||||
"gfx - Graphics mode test", ENDL, \
|
||||
"help - Prints this message", ENDL, \
|
||||
"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
|
||||
userInput: db 0
|
||||
|
||||
@@ -46,8 +46,44 @@ printHex:
|
||||
popa
|
||||
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
|
||||
|
||||
;
|
||||
; Clears the screen
|
||||
;
|
||||
clear:
|
||||
pusha
|
||||
; TODO: Make this function
|
||||
popa
|
||||
ret
|
||||
|
||||
; Usefull definitions
|
||||
%define ENDL 0x0a, 0x0d
|
||||
newline: db ENDL, 0 ; CRLF
|
||||
|
||||
Reference in New Issue
Block a user