Add drive letter assignment and the ability to change the drive.

This commit is contained in:
CrazyEttin 2021-06-24 19:31:15 +03:00
parent 1758b807e0
commit f826fef4fc
1 changed files with 132 additions and 12 deletions

View File

@ -50,8 +50,9 @@ mov [0x82], ax
mov [0x86], ax mov [0x86], ax
mov [0x8a], ax mov [0x8a], ax
;Store the boot drive number ;Store the boot drive number and set the drive letter
mov [drive], dl mov [drive], dl
call setdriveletter
;Print a welcome message ;Print a welcome message
mov si, welcomemsg mov si, welcomemsg
@ -66,6 +67,10 @@ mov sp, 0x0
sti sti
;Prompt for and read a command ;Prompt for and read a command
;Print the drive letter
mov si, driveletter
mov ah, 0x0
int 0x21
;Print a prompt ;Print a prompt
mov si, prompt mov si, prompt
mov ah, 0x0 mov ah, 0x0
@ -76,10 +81,17 @@ mov al, 0x4e
mov ah, 0x3 mov ah, 0x3
int 0x21 int 0x21
;Load an execute the program ;Check for non-program stuff
;Check for an empty command ;Check for an empty command
cmp byte [input], 0x0 cmp byte [input], 0x0
jz shell 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 ;Load
mov bx, 0x2000 mov bx, 0x2000
mov si, input mov si, input
@ -87,30 +99,138 @@ mov ah, 0x0
int 0x22 int 0x22
;Check for errors ;Check for errors
cmp al, 0x1 cmp al, 0x1
je error je cmderror
;Execute ;Execute
jmp 0x2000 jmp 0x2000
;Print an error message and return to the shell ;Print a command error message and return to the shell
error: cmderror:
mov bh, 0x0 mov bh, 0x0
mov ah, 0x3 mov ah, 0x3
int 0x10 int 0x10
dec dh dec dh
mov ah, 0x2 mov ah, 0x2
int 0x10 int 0x10
mov si, errormsg mov si, cmderrormsg
mov ah, 0x2 mov ah, 0x2
int 0x21 int 0x21
jmp shell 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 ;Data
drive db 0x0 drive db 0x0
welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0 driveletter db "?:", 0x0
prompt db "> ", 0x0 welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
errormsg db "Unknown command", 0x0 prompt db "> ", 0x0
input times 0x4e db 0x0 driverrormsg db "Unknown drive", 0x0
crlf db 0xd, 0xa, 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 ;Print a CRLF
printcrlf: printcrlf: