Added text file printing

This commit is contained in:
2023-12-25 11:11:48 +01:00
parent e20b252ebc
commit d170d66512
5 changed files with 69 additions and 13 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ nasm -fbin src/kernel.asm -o build/kernel.bin
# Final binary # Final binary
nasm -fbin src/calc.asm -o build/calc.bin nasm -fbin src/calc.asm -o build/calc.bin
cat build/bootloader.bin build/kernel.bin build/calc.bin > build/os.bin nasm -fbin src/message.asm -o build/message.bin
cat build/bootloader.bin build/kernel.bin build/calc.bin build/message.bin > build/os.bin
# Run QEMU # Run QEMU
qemu-system-x86_64 -drive format=raw,file="./build/os.bin",index=0,media=disk -m 256M qemu-system-x86_64 -drive format=raw,file="./build/os.bin",index=0,media=disk -m 256M
+1 -1
View File
@@ -43,7 +43,7 @@ start:
xor bx, bx xor bx, bx
mov ah, 2 ; Read from disk mov ah, 2 ; Read from disk
mov al, 2 ; Read 2 sectors (1024B) mov al, 3 ; Read 3 sectors (1.5kB)
mov dl, byte [driveNumber] ; Drive number mov dl, byte [driveNumber] ; Drive number
mov ch, 0 ; Cylinder mov ch, 0 ; Cylinder
+4 -3
View File
@@ -13,8 +13,9 @@
filetable: filetable:
db 'boot',0,0,0,0,0,0,'bin',0,1,1 ; boot.bin - start: 1, size: 1 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 '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 'kernel',0,0,0,0, 'bin',0,3,3 ; kernel.bin - start: 3, size: 3
db 'calc',0,0,0,0,0,0,'bin',0,5,1 ; calc.bin - start: 5, size: 1 db 'calc',0,0,0,0,0,0,'bin',0,6,1 ; calc.bin - start: 6, size: 1
db 'message',0,0,0, 'txt',0,7,1 ; message.txt - start: 7, size: 1
times 512-($-$$) db 0 times 512-($-$$) db 0
+56 -8
View File
@@ -4,7 +4,6 @@ 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 bx, 0x8000
mov es, bx mov es, bx
xor bx, bx xor bx, bx
@@ -112,7 +111,7 @@ loadProgram:
.match: .match:
mov al, [es:bx] mov al, [es:bx]
cmp al, 0 ; 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 foundProgram
.restartSearch: .restartSearch:
mov di, userInput mov di, userInput
pop bx pop bx
@@ -123,19 +122,29 @@ loadProgram:
call print call print
jmp input jmp input
executeProgram: foundProgram:
mov al, [es:bx] mov al, [es:bx]
cmp al, 0 ; Loop until we find the extension cmp al, 0 ; Loop until we find the extension
jne .getMetadata jne .getMetadata
inc bx inc bx
jmp executeProgram jmp foundProgram
.getMetadata: .getMetadata:
add bx, 3 ; Skip the file extension mov al, [es:bx]
mov [fileExt], al
inc bx
mov al, [es:bx]
mov [fileExt+1], al
inc bx
mov al, [es:bx]
mov [fileExt+2], al
inc bx
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
mov ah, 0 ; Reset disk system mov ah, 0 ; Reset disk system
mov dl, byte [driveNumber] mov dl, byte [driveNumber]
@@ -157,6 +166,17 @@ executeProgram:
jmp input jmp input
.loaded: .loaded:
; Check file extension. If 'bin', then run, if 'txt', print
pop ax ; Restore file size
mov cx, 3 ; Check file extension
mov si, fileExt
mov ax, 0x2000
mov es, ax
mov di, binExt
repe cmpsb
jne .printText ; TODO: Check for more file extensions
mov ax, PROGRAM_LOC mov ax, PROGRAM_LOC
mov ds, ax mov ds, ax
mov es, ax mov es, ax
@@ -165,6 +185,27 @@ executeProgram:
mov ss, ax mov ss, ax
jmp PROGRAM_LOC:0x0000 jmp PROGRAM_LOC:0x0000
.printText:
mov bx, PROGRAM_LOC
mov es, bx
xor bx, bx
mov cx, 512
mul cx
mov cx, ax
mov ah, 0x0e
.textLoop:
mov al, [es:bx]
cmp al, 0
je .rep
int 0x10
.rep:
inc bx
dec cx
jnz .textLoop
mov si, newline
call print
jmp input
; ;
; Help - Prints the help message (helpMsg) ; Help - Prints the help message (helpMsg)
@@ -259,6 +300,8 @@ printFiletable:
inc bx inc bx
mov al, ' ' mov al, ' '
int 0x10 int 0x10
int 0x10
int 0x10
; File size ; File size
mov al, [es:bx] mov al, [es:bx]
inc bx inc bx
@@ -347,8 +390,8 @@ sectorLenText: db "512B", 0
kilobyteText: db "kB", 0 kilobyteText: db "kB", 0
oneHalfText: db ".5kB", 0 oneHalfText: db ".5kB", 0
fileListMsg: db " Filename E# St Size ", ENDL, \ fileListMsg: db " Filename E# St Size ", ENDL, \
"---------- ------------", ENDL, 0 "---------- ------- ------", ENDL, 0
helpMsg: db "Available Commands:", ENDL, \ helpMsg: db "Available Commands:", ENDL, \
"clear - Clears the screen", ENDL, \ "clear - Clears the screen", ENDL, \
@@ -365,10 +408,15 @@ gfxCmd: db "gfx", 0
rebootCmd: db "reboot", 0 rebootCmd: db "reboot", 0
clearCmd: db "clear", 0 clearCmd: db "clear", 0
; Files
fileExt: db " ", 0
binExt: db "bin", 0
txtExt: db "txt", 0
inputLen: db 0 inputLen: db 0
userInput: db 0 userInput: db 0
FILETAB_LOC equ 0x1000 FILETAB_LOC equ 0x1000
PROGRAM_LOC equ 0x8000 PROGRAM_LOC equ 0x8000
times 2*512-($-$$) db 0 times 3*512-($-$$) db 0
+6
View File
@@ -0,0 +1,6 @@
%define ENDL 0x0A, 0x0D
db "This is a very cool message!", ENDL, ENDL, \
"Kern is a 32-bit (16-bit for now) OS based on the x86 cpu architecture."
times 512-($-$$) db 0