From fc3a0bbbe9d20299a1e26123dc901daf5f1b3fb6 Mon Sep 17 00:00:00 2001 From: CrazyEttin <> Date: Thu, 17 Jun 2021 01:03:00 +0300 Subject: [PATCH] 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. --- src/BOOT.ASM | 23 +++++++++++++++--- src/CMPSTR.INC | 22 +++++++---------- src/PRINTSTR.INC | 9 +++---- src/READSTR.INC | 63 ++++++++++++++++++++++++++++++++++++++---------- src/SYSTEM.ASM | 15 +++--------- 5 files changed, 85 insertions(+), 47 deletions(-) diff --git a/src/BOOT.ASM b/src/BOOT.ASM index 43b76e0..4f8f289 100644 --- a/src/BOOT.ASM +++ b/src/BOOT.ASM @@ -112,6 +112,20 @@ add di, ax pop cx 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 loadfat: ;Load CX from the stack @@ -189,10 +203,11 @@ boot: jmp 0x0:0x500 ;Data -bootdev db 0x0 -sysfile db "SYSTEM BIN" -cluster dw 0x0 -pointer dw 0x500 +bootdev db 0x0 +sysfile db "SYSTEM BIN" +errormsg db "System not found", 0xd, 0xa, 0x0 +cluster dw 0x0 +pointer dw 0x500 ;Calculate the source arguments for loading data from the disk calcsource: diff --git a/src/CMPSTR.INC b/src/CMPSTR.INC index 014cdda..15a8110 100644 --- a/src/CMPSTR.INC +++ b/src/CMPSTR.INC @@ -6,35 +6,31 @@ cmpstr: push ax push bx +;Compare the strings .loop: - -;Load characters +;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 +;Repeat for the next characters inc si inc di jmp .loop -.neq: -;Clear the carry flag -clc +;Set the carry flag +.eq: +stc jmp .done -.eq: -;Set the carry flag -stc +;Clear the carry flag +.neq: +clc .done: diff --git a/src/PRINTSTR.INC b/src/PRINTSTR.INC index 7f3af5c..67c534d 100644 --- a/src/PRINTSTR.INC +++ b/src/PRINTSTR.INC @@ -5,20 +5,17 @@ printstr: ;Store the initial registers in the stack push ax +;Print the string .loop: - -;Load a character +;Load the current character lodsb - ;Check for the string end cmp al, 0x0 je .done - ;Print the character mov ah, 0xe int 0x10 - -;Repeat +;Repeat for the next character jmp .loop .done: diff --git a/src/READSTR.INC b/src/READSTR.INC index 16b7d42..3bb5fab 100644 --- a/src/READSTR.INC +++ b/src/READSTR.INC @@ -8,10 +8,10 @@ push bx push cx push dx +;Setup ;Store the input length in the stack mov ah, 0 push ax - ;Initialise the destination with spaces mov cx, ax mov al, 0x20 @@ -19,9 +19,8 @@ rep stosb pop ax push ax sub di, ax - -;Initialise the cursor pointer -mov bl, 0x1 +;Initialise the cursor pointer in BL and clear BH +mov bx, 0x1 .loop: @@ -29,6 +28,7 @@ mov bl, 0x1 mov ah, 0x0 int 0x16 +;Check for special keys and non-printing characters ;Check for return cmp al, 0xd je .return @@ -52,6 +52,7 @@ jle .loop cmp al, 0x7f je .loop +;Store and print a character .character: ;Store the character stosb @@ -62,26 +63,30 @@ int 0x10 inc bl jmp .loop -.erase: ;Replace the cursor position with a space +.erase: mov al, 0x20 jmp .character +;Move the cursor forward .space: call .nextchar inc di inc bl jmp .loop +;Move the cursor backward .backspace: ;Check for the input beginning cmp bl, 0x1 je .loop +;Move the cursor call .prevchar dec di dec bl jmp .loop +;Finish reading the string .return: ;Find and remove trailing spaces @@ -126,40 +131,72 @@ pop ax ret +;Move the cursor forward + +;Move forward within a line .nextchar: ;Get the cursor position mov ah, 0x3 int 0x10 -;Move from the end of a line to the beginning of the next one -cmp dl, [cpl] +;Check for the end of the line +cmp dl, 0x4f je .nextln -;Move forward within a line +;Move inc dl mov ah, 0x2 int 0x10 ret + +;Move to the beginning of the next line .nextln: +;Check if the current line is the last on screen +cmp dh, 0x18 +je .scroll +;Move mov ah, 0x2 inc dh -mov dl, 0x1 +mov dl, 0x0 int 0x10 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: ;Get the cursor position mov ah, 0x3 int 0x10 -;Move from the beginning of a line to the end of the previous one -cmp dl, 0x1 +;Check for the beginning of the line +cmp dl, 0x0 je .prevln -;Move backward within a line +;Move dec dl mov ah, 0x2 int 0x10 ret + +;Move to the end of the previous line .prevln: mov ah, 0x2 dec dh -mov dl, [cpl] +mov dl, 0x4f int 0x10 ret diff --git a/src/SYSTEM.ASM b/src/SYSTEM.ASM index be0ca14..3063924 100644 --- a/src/SYSTEM.ASM +++ b/src/SYSTEM.ASM @@ -26,13 +26,8 @@ mov sp, stack add sp, 0x100 sti -;Get the terminal width -mov ah, 0xf -int 0x10 -mov [cpl], ah - ;Print a welcome message -mov si, welcome +mov si, welcomemsg call println loop: @@ -98,13 +93,11 @@ jnc .error call keycode jmp loop .error: -mov si, error +mov si, errormsg call println jmp loop -cpl db 0x0 - -welcome db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0 +welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0 prompt db "> ", 0x0 @@ -115,7 +108,7 @@ cmd: .help db "help", 0x0 .keycode db "keycode", 0x0 -error db "Unknown command", 0x0 +errormsg db "Unknown command", 0x0 buffer times 0xff db 0x0