From f826fef4fc0119ab1bb53879afb87989bd43919f Mon Sep 17 00:00:00 2001 From: CrazyEttin <> Date: Thu, 24 Jun 2021 19:31:15 +0300 Subject: [PATCH] Add drive letter assignment and the ability to change the drive. --- src/SYSTEM.ASM | 144 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 132 insertions(+), 12 deletions(-) diff --git a/src/SYSTEM.ASM b/src/SYSTEM.ASM index a76ff1b..8d8d215 100644 --- a/src/SYSTEM.ASM +++ b/src/SYSTEM.ASM @@ -50,8 +50,9 @@ mov [0x82], ax mov [0x86], ax mov [0x8a], ax -;Store the boot drive number +;Store the boot drive number and set the drive letter mov [drive], dl +call setdriveletter ;Print a welcome message mov si, welcomemsg @@ -66,6 +67,10 @@ mov sp, 0x0 sti ;Prompt for and read a command +;Print the drive letter +mov si, driveletter +mov ah, 0x0 +int 0x21 ;Print a prompt mov si, prompt mov ah, 0x0 @@ -76,10 +81,17 @@ mov al, 0x4e mov ah, 0x3 int 0x21 -;Load an execute the program +;Check for non-program stuff ;Check for an empty command cmp byte [input], 0x0 jz shell +;Check for a drive change command +mov si, input + 1 +mov di, driveletter + 1 +call cmpstr +jnc changedrive + +;Load an execute a program ;Load mov bx, 0x2000 mov si, input @@ -87,30 +99,138 @@ mov ah, 0x0 int 0x22 ;Check for errors cmp al, 0x1 -je error +je cmderror ;Execute jmp 0x2000 -;Print an error message and return to the shell -error: +;Print a command error message and return to the shell +cmderror: mov bh, 0x0 mov ah, 0x3 int 0x10 dec dh mov ah, 0x2 int 0x10 -mov si, errormsg +mov si, cmderrormsg mov ah, 0x2 int 0x21 jmp shell +;Change the drive +changedrive: +;Check which drive to change to +cmp byte [input], "a" +je .a +cmp byte [input], "A" +je .a +cmp byte [input], "b" +je .b +cmp byte [input], "B" +je .b +cmp byte [input], "c" +je .c +cmp byte [input], "C" +je .c +cmp byte [input], "d" +je .d +cmp byte [input], "D" +je .d +;Print a drive error message and return to the shell +mov si, driverrormsg +mov ah, 0x2 +int 0x21 +jmp shell +;Change +.a: +mov dl, 0x0 +mov byte [drive], dl +call setdriveletter +jmp shell +.b: +mov dl, 0x1 +mov byte [drive], dl +call setdriveletter +jmp shell +.c: +mov dl, 0x2 +mov byte [drive], dl +call setdriveletter +jmp shell +.d: +mov dl, 0x3 +mov byte [drive], dl +call setdriveletter +jmp shell + ;Data -drive db 0x0 -welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0 -prompt db "> ", 0x0 -errormsg db "Unknown command", 0x0 -input times 0x4e db 0x0 -crlf db 0xd, 0xa, 0x0 +drive db 0x0 +driveletter db "?:", 0x0 +welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0 +prompt db "> ", 0x0 +driverrormsg db "Unknown drive", 0x0 +cmderrormsg db "Unknown command", 0x0 +input times 0x4e db 0x0 +crlf db 0xd, 0xa, 0x0 + +;Set the drive letter +setdriveletter: +;Check the drive number +cmp dl, 0x0 +je .a +cmp dl, 0x1 +je .b +cmp dl, 0x2 +je .c +cmp dl, 0x3 +je .d +ret +;Set +.a: +mov byte [driveletter], "A" +ret +.b: +mov byte [driveletter], "B" +ret +.c: +mov byte [driveletter], "C" +ret +.d: +mov byte [driveletter], "D" +ret + +;Compare two strings ending in a null at SI and DI and clear the carry flag if they are equal and set it if not +cmpstr: +;Store the initial registers in the stack +push ax +push bx +;Compare the strings +.loop: +;Load the current characters +mov al, [si] +mov bl, [di] +;Compare the characters +cmp al, bl +;Check for difference +jne .neq +;Check for the string end +cmp al, 0x0 +je .eq +;Repeat for the next characters +inc si +inc di +jmp .loop +;Clear the carry flag +.eq: +clc +jmp .done +;Set the carry flag +.neq: +stc +.done: +;Load the initial registers from the stack +pop bx +pop ax +ret ;Print a CRLF printcrlf: