Add an error message to the bootloader in case the system is not found, fix two related bugs in readstr related to movement between lines and scrolling, and tidy the code up a bit.

This commit is contained in:
CrazyEttin 2021-06-17 01:03:00 +03:00
parent 45a11e601f
commit fc3a0bbbe9
5 changed files with 85 additions and 47 deletions

View File

@ -112,6 +112,20 @@ add di, ax
pop cx pop cx
loop search loop search
;Print an error message if the system is not found
mov si, errormsg
printerror:
;Load a character
lodsb
;Check for the string end
cmp al, 0x0
je $
;Print the character
mov ah, 0xe
int 0x10
;Repeat
jmp printerror
;Load the system entry ;Load the system entry
loadfat: loadfat:
;Load CX from the stack ;Load CX from the stack
@ -189,10 +203,11 @@ boot:
jmp 0x0:0x500 jmp 0x0:0x500
;Data ;Data
bootdev db 0x0 bootdev db 0x0
sysfile db "SYSTEM BIN" sysfile db "SYSTEM BIN"
cluster dw 0x0 errormsg db "System not found", 0xd, 0xa, 0x0
pointer dw 0x500 cluster dw 0x0
pointer dw 0x500
;Calculate the source arguments for loading data from the disk ;Calculate the source arguments for loading data from the disk
calcsource: calcsource:

View File

@ -6,35 +6,31 @@ cmpstr:
push ax push ax
push bx push bx
;Compare the strings
.loop: .loop:
;Load the current characters
;Load characters
mov al, [si] mov al, [si]
mov bl, [di] mov bl, [di]
;Compare the characters ;Compare the characters
cmp al, bl cmp al, bl
;Check for difference ;Check for difference
jne .neq jne .neq
;Check for the string end ;Check for the string end
cmp al, 0x0 cmp al, 0x0
je .eq je .eq
;Repeat for the next characters
;Repeat
inc si inc si
inc di inc di
jmp .loop jmp .loop
.neq: ;Set the carry flag
;Clear the carry flag .eq:
clc stc
jmp .done jmp .done
.eq: ;Clear the carry flag
;Set the carry flag .neq:
stc clc
.done: .done:

View File

@ -5,20 +5,17 @@ printstr:
;Store the initial registers in the stack ;Store the initial registers in the stack
push ax push ax
;Print the string
.loop: .loop:
;Load the current character
;Load a character
lodsb lodsb
;Check for the string end ;Check for the string end
cmp al, 0x0 cmp al, 0x0
je .done je .done
;Print the character ;Print the character
mov ah, 0xe mov ah, 0xe
int 0x10 int 0x10
;Repeat for the next character
;Repeat
jmp .loop jmp .loop
.done: .done:

View File

@ -8,10 +8,10 @@ push bx
push cx push cx
push dx push dx
;Setup
;Store the input length in the stack ;Store the input length in the stack
mov ah, 0 mov ah, 0
push ax push ax
;Initialise the destination with spaces ;Initialise the destination with spaces
mov cx, ax mov cx, ax
mov al, 0x20 mov al, 0x20
@ -19,9 +19,8 @@ rep stosb
pop ax pop ax
push ax push ax
sub di, ax sub di, ax
;Initialise the cursor pointer in BL and clear BH
;Initialise the cursor pointer mov bx, 0x1
mov bl, 0x1
.loop: .loop:
@ -29,6 +28,7 @@ mov bl, 0x1
mov ah, 0x0 mov ah, 0x0
int 0x16 int 0x16
;Check for special keys and non-printing characters
;Check for return ;Check for return
cmp al, 0xd cmp al, 0xd
je .return je .return
@ -52,6 +52,7 @@ jle .loop
cmp al, 0x7f cmp al, 0x7f
je .loop je .loop
;Store and print a character
.character: .character:
;Store the character ;Store the character
stosb stosb
@ -62,26 +63,30 @@ int 0x10
inc bl inc bl
jmp .loop jmp .loop
.erase:
;Replace the cursor position with a space ;Replace the cursor position with a space
.erase:
mov al, 0x20 mov al, 0x20
jmp .character jmp .character
;Move the cursor forward
.space: .space:
call .nextchar call .nextchar
inc di inc di
inc bl inc bl
jmp .loop jmp .loop
;Move the cursor backward
.backspace: .backspace:
;Check for the input beginning ;Check for the input beginning
cmp bl, 0x1 cmp bl, 0x1
je .loop je .loop
;Move the cursor
call .prevchar call .prevchar
dec di dec di
dec bl dec bl
jmp .loop jmp .loop
;Finish reading the string
.return: .return:
;Find and remove trailing spaces ;Find and remove trailing spaces
@ -126,40 +131,72 @@ pop ax
ret ret
;Move the cursor forward
;Move forward within a line
.nextchar: .nextchar:
;Get the cursor position ;Get the cursor position
mov ah, 0x3 mov ah, 0x3
int 0x10 int 0x10
;Move from the end of a line to the beginning of the next one ;Check for the end of the line
cmp dl, [cpl] cmp dl, 0x4f
je .nextln je .nextln
;Move forward within a line ;Move
inc dl inc dl
mov ah, 0x2 mov ah, 0x2
int 0x10 int 0x10
ret ret
;Move to the beginning of the next line
.nextln: .nextln:
;Check if the current line is the last on screen
cmp dh, 0x18
je .scroll
;Move
mov ah, 0x2 mov ah, 0x2
inc dh inc dh
mov dl, 0x1 mov dl, 0x0
int 0x10 int 0x10
ret ret
;Scroll the screen up by one line
.scroll:
;Scroll
mov ah, 0x6
mov al, 0x1
mov bh, 0x7
mov ch, 0x0
mov cl, 0x0
mov dh, 0x18
mov dl, 0x4f
int 0x10
;Move to the beginning of the new line
mov ah, 0x2
mov bh, 0x0
mov dl, 0x0
int 0x10
ret
;Move the cursor backward
;Move backward within a line
.prevchar: .prevchar:
;Get the cursor position ;Get the cursor position
mov ah, 0x3 mov ah, 0x3
int 0x10 int 0x10
;Move from the beginning of a line to the end of the previous one ;Check for the beginning of the line
cmp dl, 0x1 cmp dl, 0x0
je .prevln je .prevln
;Move backward within a line ;Move
dec dl dec dl
mov ah, 0x2 mov ah, 0x2
int 0x10 int 0x10
ret ret
;Move to the end of the previous line
.prevln: .prevln:
mov ah, 0x2 mov ah, 0x2
dec dh dec dh
mov dl, [cpl] mov dl, 0x4f
int 0x10 int 0x10
ret ret

View File

@ -26,13 +26,8 @@ mov sp, stack
add sp, 0x100 add sp, 0x100
sti sti
;Get the terminal width
mov ah, 0xf
int 0x10
mov [cpl], ah
;Print a welcome message ;Print a welcome message
mov si, welcome mov si, welcomemsg
call println call println
loop: loop:
@ -98,13 +93,11 @@ jnc .error
call keycode call keycode
jmp loop jmp loop
.error: .error:
mov si, error mov si, errormsg
call println call println
jmp loop jmp loop
cpl db 0x0 welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
welcome db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
prompt db "> ", 0x0 prompt db "> ", 0x0
@ -115,7 +108,7 @@ cmd:
.help db "help", 0x0 .help db "help", 0x0
.keycode db "keycode", 0x0 .keycode db "keycode", 0x0
error db "Unknown command", 0x0 errormsg db "Unknown command", 0x0
buffer times 0xff db 0x0 buffer times 0xff db 0x0