diff --git a/SOURCE/BOOT.ASM b/SOURCE/BOOT.ASM index d60eb06..f80d4fe 100644 --- a/SOURCE/BOOT.ASM +++ b/SOURCE/BOOT.ASM @@ -1,9 +1,9 @@ [ORG 0x7c00] -jmp short start +jmp start nop ;1.44 MB 3.5" floppy disk description table -OEMLabel db "EttinOS " +OEMLabel db "ETTINOS " BytesPerSector dw 0x200 SectorsPerCluster db 0x1 BootRecordSectors dw 0x1 @@ -19,7 +19,7 @@ LargeSectors dd 0x0 DriveNumber dw 0x0 DriveSignature db 0x29 VolumeID dd 0x0 -VolumeLabel db "EttinOS " +VolumeLabel db "ETTINOS " FileSystem db "FAT12 " start: @@ -53,7 +53,7 @@ mov al, 0xe mov ah, 0x2 int 0x13 -;Search the root FAT for the system +;Search the root FAT for the system FAT ;Set DI to the root FAT mov ax, ds mov es, ax @@ -64,7 +64,7 @@ mov ax, 0x0 search: ;Store CX in the stack push cx -;Check for the binary +;Check for the system FAT mov si, sysfile mov cx, 0xb rep cmpsb @@ -79,7 +79,7 @@ loop search ;Load the system FAT loadsysfat: -;??? +;Store the first cluster mov ax, word [es:di+0xf] mov word [cluster], ax ;Set the source diff --git a/SOURCE/BYTE2HEX.INC b/SOURCE/BYTE2HEX.INC index a3588b2..655d346 100644 --- a/SOURCE/BYTE2HEX.INC +++ b/SOURCE/BYTE2HEX.INC @@ -1,4 +1,4 @@ -;Converts a byte in ah to a hex string at di. +;Converts a byte in AH to a hex string at DI. byte2hex: @@ -8,16 +8,16 @@ pusha ;Set a key for the hex digits mov si, .key -;Set a counter for the two characters of the hex string +;Set a counter for the two hex digits mov cx, 0x2 .loop: -;Read the byte +;Read a nibble rol ax, 0x4 mov bx, ax -;Convert the byte to a hex digit +;Convert the nibble to a hex digit and bx, 0xf mov bl, [si + bx] diff --git a/SOURCE/CMPSTR.INC b/SOURCE/CMPSTR.INC index 5098175..0eef00d 100644 --- a/SOURCE/CMPSTR.INC +++ b/SOURCE/CMPSTR.INC @@ -1,4 +1,4 @@ -;Compares strings from si and di and sets the carry flag if they are equal and clears it if not. +;Compares strings from SI and SI and sets the carry flag if they are equal and clears it if not. cmpstr: @@ -40,4 +40,4 @@ stc ;Load the initial registers from the stack popa -ret \ No newline at end of file +ret diff --git a/SOURCE/ECHO.INC b/SOURCE/ECHO.INC index c0a40dd..ab1f9bf 100644 --- a/SOURCE/ECHO.INC +++ b/SOURCE/ECHO.INC @@ -16,4 +16,4 @@ mov si, buffer call println .done: -ret \ No newline at end of file +ret diff --git a/SOURCE/HELP.INC b/SOURCE/HELP.INC index de4a565..02311f1 100644 --- a/SOURCE/HELP.INC +++ b/SOURCE/HELP.INC @@ -8,4 +8,4 @@ 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 \ No newline at end of file +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/SOURCE/KEYCODE.INC b/SOURCE/KEYCODE.INC index 263dc95..fdfb321 100644 --- a/SOURCE/KEYCODE.INC +++ b/SOURCE/KEYCODE.INC @@ -1,4 +1,4 @@ -;Reads a keypress and prints its BIOS code. +;Reads a keypress and prints its BIOS keycode. keycode: diff --git a/SOURCE/PRINTCH.INC b/SOURCE/PRINTCH.INC new file mode 100644 index 0000000..d508b3d --- /dev/null +++ b/SOURCE/PRINTCH.INC @@ -0,0 +1,8 @@ +;Prints a character from AL + +printch: + +mov ah, 0xe +int 0x10 + +ret diff --git a/SOURCE/PRINTLN.INC b/SOURCE/PRINTLN.INC index 911b38f..6045769 100644 --- a/SOURCE/PRINTLN.INC +++ b/SOURCE/PRINTLN.INC @@ -1,4 +1,4 @@ -;Prints a string from si until a null, followed by a newline. +;Prints a string from SI until a null, followed by a newline. println: diff --git a/SOURCE/PRINTSTR.INC b/SOURCE/PRINTSTR.INC index 4258d98..1ba6070 100644 --- a/SOURCE/PRINTSTR.INC +++ b/SOURCE/PRINTSTR.INC @@ -1,4 +1,4 @@ -;Prints a string from si until a null. +;Prints a string from SI until a null. printstr: @@ -16,7 +16,6 @@ je .done ;Print the character mov ah, 0xe -mov bx, 0x0 int 0x10 ;Repeat diff --git a/SOURCE/READCH.INC b/SOURCE/READCH.INC new file mode 100644 index 0000000..012e022 --- /dev/null +++ b/SOURCE/READCH.INC @@ -0,0 +1,29 @@ +;Reads a character to AL + +readch: + +;Store the initial registers +push bx +push ax + +;Read a keypress +mov ah, 0x0 +int 0x16 + +;Check for non-printing characters +cmp al, 0x1f +jle readch +cmp al, 0x7f +je readch + +;Print the character +mov ah, 0xe +int 0x10 + +;Load the initial registers +pop bx +mov ah, bh +pop bx + +.done: +ret diff --git a/SOURCE/READLN.INC b/SOURCE/READLN.INC index 572edd6..9da3cb8 100644 --- a/SOURCE/READLN.INC +++ b/SOURCE/READLN.INC @@ -1,4 +1,4 @@ -;Reads a string of at most al characters to di until a return and prints a newline. +;Reads a string of at most AL characters to DI until a return and prints a newline. readln: diff --git a/SOURCE/READSTR.INC b/SOURCE/READSTR.INC index 7422def..2c96c0f 100644 --- a/SOURCE/READSTR.INC +++ b/SOURCE/READSTR.INC @@ -1,4 +1,4 @@ -;Reads a string of at most al characters to di until a return. +;Reads a string of at most AL characters to DI until a return. readstr: @@ -29,32 +29,27 @@ int 0x16 ;Check for return cmp al, 0xd je .return - ;Check for backspace cmp al, 0x8 je .backspace - ;Check for input end pop dx push dx cmp bl, dl je .loop - ;Check for space cmp al, 0x20 je .space - ;Check for erase cmp al, 0x9 je .erase - ;Check for non-printing characters cmp al, 0x1f jle .loop cmp al, 0x7f je .loop -.char: +.character: ;Store the character stosb ;Print the character @@ -67,7 +62,7 @@ jmp .loop .erase: ;Replace the cursor position with a space mov al, 0x20 -jmp .char +jmp .character .space: call .nextchar @@ -86,19 +81,18 @@ jmp .loop .return: +;Find and remove trailing spaces ;Go to the end of the input pop ax mov bh, 0x0 sub ax, bx push di add di, ax - .findtrailing: ;Check for a trailing space cmp byte [di], 0x20 je .deltrailing jmp .end - .deltrailing: ;Delete a trailing space mov al, 0x0 @@ -106,8 +100,8 @@ stosb sub di, 0x2 jmp .findtrailing -.end: ;Move the cursor to the end of the input string +.end: pop di .findend: cmp byte [di], 0x0 @@ -138,7 +132,6 @@ inc dl mov ah, 0x2 int 0x10 ret - .nextln: mov ah, 0x2 inc dh @@ -158,7 +151,6 @@ dec dl mov ah, 0x2 int 0x10 ret - .prevln: mov ah, 0x2 dec dh diff --git a/SOURCE/SYSTEM.ASM b/SOURCE/SYSTEM.ASM index 0d76431..7d4eaae 100644 --- a/SOURCE/SYSTEM.ASM +++ b/SOURCE/SYSTEM.ASM @@ -2,13 +2,15 @@ jmp start ;Calls +%include "BYTE2HEX.INC" +%include "CMPSTR.INC" %include "PRINTNL.INC" +%include "PRINTCH.INC" %include "PRINTSTR.INC" %include "PRINTLN.INC" +%include "READCH.INC" %include "READSTR.INC" %include "READLN.INC" -%include "CMPSTR.INC" -%include "BYTE2HEX.INC" ;Commands %include "ECHO.INC" @@ -38,13 +40,11 @@ mov di, buffer mov al, 0xff call readln -exec: ;Identify and execute the command - +exec: ;Check for no command cmp byte [buffer], 0x0 je loop - .echo: ;Check mov si, buffer @@ -54,7 +54,6 @@ jnc .hello ;Execute call echo jmp loop - .hello: ;Check mov si, buffer @@ -64,7 +63,6 @@ jnc .help ;Execute call hello jmp loop - .help: ;Check mov si, buffer @@ -74,7 +72,6 @@ jnc .keycode ;Execute call help jmp loop - .keycode: ;Check mov si, buffer @@ -84,7 +81,6 @@ jnc .error ;Execute call keycode jmp loop - .error: mov si, error call println @@ -108,7 +104,6 @@ db "hello", 0x0 db "help", 0x0 .keycode: db "keycode", 0x0 - error: db "Unknown command", 0x0 diff --git a/make.sh b/make.sh index dfaa6fa..ffa2d71 100755 --- a/make.sh +++ b/make.sh @@ -1,14 +1,11 @@ #!/bin/bash cd SOURCE/ -nasm BOOT.ASM -f bin -O0 -o ../BOOT.BIN -nasm SYSTEM.ASM -f bin -O0 -o ../SYSTEM.BIN +nasm BOOT.ASM -f bin -o ../BOOT.BIN +nasm SYSTEM.ASM -f bin -o ../SYSTEM.BIN cd .. -if [[ -f EttinOS.img ]] -then - rm EttinOS.img -fi +rm -f EttinOS.img mkfs.fat -C EttinOS.img 1440 -mcopy -i EttinOS.img SYSTEM.BIN :: dd if=BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1 +mcopy -i EttinOS.img SYSTEM.BIN ::