diff --git a/SOURCE/HELP.INC b/SOURCE/HELP.INC deleted file mode 100644 index a8abcb8..0000000 --- a/SOURCE/HELP.INC +++ /dev/null @@ -1,10 +0,0 @@ -;Prints help. - -help: - -mov si, .help -call println - -ret - -.help db "Input:", 0xd, 0xa, "* Typing a character overwrites the cursor location.", 0xd, 0xa, "* The erase (=tab) key erases the cursor location.", 0xd, 0xa, "* The space and backspace keys move the cursor.", 0xd, 0xa, "Commands:", 0xd, 0xa, "* echo: echoes its input.", 0xd, 0xa, "* hello: a hello world program.", 0xd, 0xa, "* help: you are reading it.", 0xd, 0xa, "* keycode: echoes the BIOS code of a key.", 0x0 diff --git a/make.sh b/make.sh index 8ae9905..cd0971b 100755 --- a/make.sh +++ b/make.sh @@ -1,18 +1,22 @@ #!/bin/bash -cd SOURCE/ - -if [ "$1" == "-F1440" ] - then nasm BOOT.ASM -d F1440 -f bin -o ../BOOT.BIN - else nasm BOOT.ASM -f bin -o ../BOOT.BIN +rm -f EttinOS.img +if [[ ! -d "bin" ]] +then + mkdir bin fi -nasm SYSTEM.ASM -f bin -o ../SYSTEM.BIN + +cd src/ +if [ "$1" == "-F1440" ] + then nasm BOOT.ASM -d F1440 -f bin -o ../bin/BOOT.BIN + else nasm BOOT.ASM -f bin -o ../bin/BOOT.BIN +fi +nasm SYSTEM.ASM -f bin -o ../bin/SYSTEM.BIN cd .. -rm -f EttinOS.img -if [ "$1" == "-F1440" ] +if [ "$1" == "-1440" ] then mkfs.fat -C EttinOS.img 1440 else mkfs.fat -C EttinOS.img 360 fi -dd if=BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1 -mcopy -i EttinOS.img SYSTEM.BIN :: +dd if=bin/BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1 +mcopy -i EttinOS.img bin/SYSTEM.BIN :: diff --git a/SOURCE/BOOT.ASM b/src/BOOT.ASM similarity index 82% rename from SOURCE/BOOT.ASM rename to src/BOOT.ASM index d856c6c..43b76e0 100644 --- a/SOURCE/BOOT.ASM +++ b/src/BOOT.ASM @@ -7,7 +7,7 @@ nop ;Disk description tables %ifdef F1440 -;1.44 MB 3.5" floppy disk (enable by passing -d F1440 to NASM) +;1.44 MB 3.5" floppy disk (enable with the argument -d F1440 when building) oemlabel db "ETTINOS " sectorsize dw 0x200 ;bytes clustersize db 0x1 ;sectors @@ -52,17 +52,17 @@ filesystem db "FAT12 " start: -;Set up the data segment +;Setup +;Set up the data, stack, and extra segments mov ax, 0x0 mov ds, ax - +mov ss, ax +mov es, ax ;Set up the stack cli -mov ax, 0x0 -mov ss, ax -mov sp, 0x7c00 +mov sp, stack +add sp, 0x100 sti - ;Store the boot device number mov [bootdev], dl @@ -75,9 +75,7 @@ add ax, [bootsectors] push ax call calcsource ;Set the destination -mov si, 0x7e00 -mov bx, ds -mov es, bx +mov si, 0x7f00 mov bx, si ;Set the size push dx @@ -93,10 +91,8 @@ mov ah, 0x2 int 0x13 ;Search the root for the system -;Set DI to the root FAT -mov ax, ds -mov es, ax -mov di, 0x7e00 +;Set DI to the root +mov di, 0x7f00 ;Initialise the search loop mov cx, word [rootentries] mov ax, 0x0 @@ -110,13 +106,13 @@ rep cmpsb je loadfat ;Set DI to the next entry add ax, 0x20 -mov di, 0x7e00 +mov di, 0x7f00 add di, ax ;Load CX from the stack pop cx loop search -;Load the system FAT +;Load the system entry loadfat: ;Load CX from the stack pop cx @@ -127,7 +123,7 @@ mov word [cluster], ax mov ax, 0x1 call calcsource ;Set the destination -mov di, 0x7e00 +mov di, 0x7f00 mov bx, di ;Set the size mov ax, [sectorsperfat] @@ -140,20 +136,21 @@ int 0x13 ;Load a cluster loadcluster: ;Set the source +pop cx pop bx -pop ax -push ax -push bx -add ax, bx +mov ax, word [cluster] sub ax, 0x2 -add ax, word [cluster] +mul byte [clustersize] +add ax, bx +add ax, cx +push bx +push cx call calcsource ;Set the destination -mov ax, 0x0 -mov es, ax mov bx, word [pointer] ;Set the size -mov al, 0x1 +;mov al, 0x1 +mov al, [clustersize] ;Load mov ah, 0x2 int 0x13 @@ -165,7 +162,7 @@ mov bx, 0x3 mul bx mov bx, 0x2 div bx -mov si, 0x7e00 +mov si, 0x7f00 add si, ax mov ax, word [ds:si] or dx, dx @@ -182,19 +179,22 @@ contcalc: mov word [cluster], ax cmp ax, 0xff8 jge boot -add word [pointer], 0x200 +mov ax, [sectorsize] +mul word [clustersize] +add word [pointer], ax jmp loadcluster +;Boot the system boot: -jmp 0x0:0x9e00 - -sysfile db "SYSTEM BIN" +jmp 0x0:0x500 +;Data bootdev db 0x0 - +sysfile db "SYSTEM BIN" cluster dw 0x0 -pointer dw 0x9e00 +pointer dw 0x500 +;Calculate the source arguments for loading data from the disk calcsource: push ax push bx @@ -215,8 +215,10 @@ pop ax mov dl, byte [bootdev] ret +;Pad the binary to a full sector and make the disk bootable ;Padding times 0x1fe-($-$$) db 0x0 - ;Boot signature dw 0xaa55 + +stack: diff --git a/SOURCE/BYTE2HEX.INC b/src/BYTE2HEX.INC similarity index 100% rename from SOURCE/BYTE2HEX.INC rename to src/BYTE2HEX.INC diff --git a/SOURCE/CMPSTR.INC b/src/CMPSTR.INC similarity index 100% rename from SOURCE/CMPSTR.INC rename to src/CMPSTR.INC diff --git a/SOURCE/ECHO.INC b/src/ECHO.INC similarity index 100% rename from SOURCE/ECHO.INC rename to src/ECHO.INC diff --git a/src/FILEIFY.INC b/src/FILEIFY.INC new file mode 100644 index 0000000..b9c0bd5 --- /dev/null +++ b/src/FILEIFY.INC @@ -0,0 +1,120 @@ +;Reads a string, checks if it is a valid 8.3 file name, converts it into FAT formatting, and prints it. + +;To do: change the .test call to work with flags instead of direct jumps. + +fileify: + +;Read a string +mov di, buffer +mov al, 0xff +call readln + +;Set SI and DI +mov si, buffer +mov di, .file + +;Initialise the name with spaces +mov cx, 0xb +mov al, 0x20 +rep stosb +sub di, 0xb + +;Initialise the length counter for the main part of the name +mov bl, 0x8 + +.nameloop: + +;Load a character +lodsb + +;Check for a period +cmp al, 0x2e +je .initext + +call .test +jmp .nameloop + +.initext: +;Set DI and initialise the counter for the extension +mov bl, 0x3 +mov di, .file+0x8 + +.extloop: +call .test +jmp .extloop + +.error: +mov si, .errormsg +call println +jmp .done + +.print: +mov si, .name +call printstr +mov si, .extension +call printstr +mov al, 0x7c +call printch +call printnl + +.done: +ret + +.file times 0xc db 0x0 + +.errormsg db "Invalid file name", 0x0 + +.test: + +;Check for the string end +cmp al, 0x0 +je .print + +;Check for the length limit +cmp bl, 0x0 +je .error + +;Check for invalid characters +cmp al, 0x22 +je .error +cmp al, 0x2a +jl .contcheck1 +cmp al, 0x2c +jg .contcheck1 +jmp .error +.contcheck1: +cmp al, 0x2f +je .error +cmp al, 0x3a +jl .contcheck2 +cmp al, 0x3f +jg .contcheck2 +jmp .error +.contcheck2: +cmp al, 0x5b +jl .contcheck3 +cmp al, 0x5d +jg .contcheck3 +jmp .error +.contcheck3: +cmp al, 0x7c +je .error + +;Find and convert lower case letters to upper case +;Check for lower case +cmp al, 0x61 +jl .conttest +cmp al, 0x7a +jg .conttest +;Convert lower to upper case +sub al, 0x20 + +.conttest: + +;Store the character +stosb + +;Increase the counter +dec bl + +ret diff --git a/SOURCE/HELLO.INC b/src/HELLO.INC similarity index 100% rename from SOURCE/HELLO.INC rename to src/HELLO.INC diff --git a/src/HELP.INC b/src/HELP.INC new file mode 100644 index 0000000..c504ed5 --- /dev/null +++ b/src/HELP.INC @@ -0,0 +1,10 @@ +;Prints help. + +help: + +mov si, .help +call println + +ret + +.help db "Input:", 0xd, 0xa, " * Typing a character overwrites the cursor location.", 0xd, 0xa, " * The erase (=tab) key erases the cursor location.", 0xd, 0xa, " * The space and backspace keys move the cursor.", 0xd, 0xa, "Commands:", 0xd, 0xa, " * echo: echoes its input.", 0xd, 0xa, " * fileify: prints its input in FAT format if it is a valid filename.", 0xd, 0xa, " * hello: a hello world program.", 0xd, 0xa, " * help: you are reading it.", 0xd, 0xa, " * keycode: echoes the BIOS code of a key.", 0x0 diff --git a/SOURCE/KEYCODE.INC b/src/KEYCODE.INC similarity index 100% rename from SOURCE/KEYCODE.INC rename to src/KEYCODE.INC diff --git a/SOURCE/PRINTCH.INC b/src/PRINTCH.INC similarity index 100% rename from SOURCE/PRINTCH.INC rename to src/PRINTCH.INC diff --git a/SOURCE/PRINTLN.INC b/src/PRINTLN.INC similarity index 100% rename from SOURCE/PRINTLN.INC rename to src/PRINTLN.INC diff --git a/SOURCE/PRINTNL.INC b/src/PRINTNL.INC similarity index 100% rename from SOURCE/PRINTNL.INC rename to src/PRINTNL.INC diff --git a/SOURCE/PRINTSTR.INC b/src/PRINTSTR.INC similarity index 100% rename from SOURCE/PRINTSTR.INC rename to src/PRINTSTR.INC diff --git a/SOURCE/READCH.INC b/src/READCH.INC similarity index 100% rename from SOURCE/READCH.INC rename to src/READCH.INC diff --git a/SOURCE/READLN.INC b/src/READLN.INC similarity index 100% rename from SOURCE/READLN.INC rename to src/READLN.INC diff --git a/SOURCE/READSTR.INC b/src/READSTR.INC similarity index 100% rename from SOURCE/READSTR.INC rename to src/READSTR.INC diff --git a/SOURCE/SYSTEM.ASM b/src/SYSTEM.ASM similarity index 81% rename from SOURCE/SYSTEM.ASM rename to src/SYSTEM.ASM index 5ea6f85..b804cfd 100644 --- a/SOURCE/SYSTEM.ASM +++ b/src/SYSTEM.ASM @@ -1,5 +1,5 @@ CPU 8086 -ORG 0x9e00 +ORG 0x500 jmp start @@ -16,12 +16,19 @@ jmp start ;Commands %include "ECHO.INC" +;%include "FILEIFY.INC" %include "HELLO.INC" %include "HELP.INC" %include "KEYCODE.INC" start: +;Set up the stack +cli +mov sp, stack +add sp, 0x100 +sti + ;Get the terminal width mov ah, 0xf int 0x10 @@ -33,10 +40,10 @@ call println loop: +;Prompt for and read a command ;Print a prompt mov si, prompt call printstr - ;Read a command mov di, buffer mov al, 0xff @@ -52,10 +59,20 @@ je loop mov si, buffer mov di, cmd.echo call cmpstr +;jnc .fileify jnc .hello ;Execute call echo jmp loop +;.fileify: +;;Check +;mov si, buffer +;mov di, cmd.fileify +;call cmpstr +;jnc .hello +;;Execute +;call fileify +;jmp loop .hello: ;Check mov si, buffer @@ -96,10 +113,13 @@ prompt db "> ", 0x0 cmd: .echo db "echo", 0x0 +.fileify db "fileify", 0x0 .hello db "hello", 0x0 .help db "help", 0x0 .keycode db "keycode", 0x0 error db "Unknown command", 0x0 -buffer times 0xff db 0 +buffer times 0xff db 0x0 + +stack: