Move the system to low memory and tweak readln.

This commit is contained in:
CrazyEttin 2021-06-04 01:23:41 +03:00
parent 6e5019dcb7
commit 522905d77c
4 changed files with 93 additions and 85 deletions

View File

@ -6,4 +6,3 @@ nasm system.asm -f bin -O0 -o ../system.bin
cd .. cd ..
cat boot.bin system.bin > EttinOS.img cat boot.bin system.bin > EttinOS.img
rm boot.bin system.bin

View File

@ -24,31 +24,37 @@ db "FAT12 " ;File system type
start: start:
;Initialise ds ;Set up the data segment
mov ax, 0x0 mov ax, 0x0
mov ds, ax mov ds, ax
;Set up the stack
cli
mov ax, 0x0
mov ss, ax
mov sp, 0x7c00
sti
;Load the system ;Load the system
;Set the source ;Set the source
mov dl, 0x0
mov dh, 0x0 mov dh, 0x0
mov ch, 0x0 mov ch, 0x0
mov cl, 0x2 mov cl, 0x2
;Set the destination ;Set the destination
mov ax, 0x1000 mov ax, 0x0
mov es, ax mov es, ax
mov bx, 0x200 mov bx, 0x7e00
;Set the size ;Set the size
mov al, 0x20 mov al, 0x5
;Load ;Load
mov ah, 0x2 mov ah, 0x2
int 0x13 int 0x13
;Boot the system ;Boot the system
jmp 0x1000:0x200 jmp 0x0:0x7e00
;Padding ;Padding
times 0x1fe-($-$$) db 0 times 0x1fe-($-$$) db 0x0
;Boot signature ;Boot signature
dw 0xaa55 dw 0xaa55

View File

@ -2,14 +2,17 @@
readln: readln:
;Store the length ;Store the input length in the stack
mov [.length], al mov ah, 0
push ax
;Initialise the destination with spaces ;Initialise the destination with spaces
mov cx, [.length] mov cx, ax
mov al, 0x20 mov al, 0x20
rep stosb rep stosb
sub di, [.length] pop ax
push ax
sub di, ax
;Initialise the cursor pointer ;Initialise the cursor pointer
mov bl, 0x1 mov bl, 0x1
@ -34,7 +37,9 @@ cmp al, 0x8
je .backspace je .backspace
;Check for input end ;Check for input end
cmp bl, [.length] pop dx
push dx
cmp bl, dl
je .loop je .loop
;Check for space ;Check for space
@ -59,16 +64,7 @@ mov ah, 0xe
int 0x10 int 0x10
;Move the cursor pointer ;Move the cursor pointer
inc bl inc bl
call .checkln
.checkln:
;Get the cursor position
mov ah, 0x3
int 0x10
;Check if the current line is the last one of the input
cmp dh, [.lastln]
jle .loop
;If it is mark it as so
mov byte [.lastln], dh
jmp .loop jmp .loop
.erase: .erase:
@ -77,55 +73,14 @@ mov al, 0x20
jmp .char jmp .char
.space: .space:
;Get the cursor position call .nextchar
mov ah, 0x3
int 0x10
;Move from the end of a line to the beginning of the next one
cmp dl, [cpl]
je .nextln
;Move forward within a line
inc dl
mov ah, 0x2
int 0x10
inc di
inc bl
jmp .loop jmp .loop
.nextln:
mov ah, 0x2
inc dh
mov dl, 0x1
int 0x10
inc di
inc bl
;Go to the last input line check
jmp .checkln
.backspace: .backspace:
;Check for the input beginning ;Check for the input beginning
cmp bl, 0x1 cmp bl, 0x1
je .loop je .loop
;Get the cursor position call .prevchar
mov ah, 0x3
int 0x10
;Move from the beginning of a line to the end of the previous one
cmp dl, 0x1
je .prevln
;Move backward within a line
dec dl
mov ah, 0x2
int 0x10
dec di
dec bl
jmp .loop
.prevln:
mov ah, 0x2
dec dh
mov dl, [cpl]
int 0x10
dec di
dec bl
jmp .loop jmp .loop
.return: .return:
@ -133,7 +88,8 @@ jmp .loop
;Go to the end of the input ;Go to the end of the input
mov bh, 0x0 mov bh, 0x0
sub di, bx sub di, bx
add di, [.length] pop ax
add di, ax
.findtrailing: .findtrailing:
;Check for a trailing space ;Check for a trailing space
@ -158,11 +114,69 @@ call newline
ret ret
.length:
db 0x0
.cursor:
db 0x0
.lastln: .lastln:
db 0x0 db 0x0
.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]
je .nextln
;Move forward within a line
inc dl
mov ah, 0x2
int 0x10
inc di
inc bl
ret
.nextln:
mov ah, 0x2
inc dh
mov dl, 0x1
int 0x10
inc di
inc bl
;Go to the last input line check
call .checkln
ret
.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
je .prevln
;Move backward within a line
dec dl
mov ah, 0x2
int 0x10
dec di
dec bl
ret
.prevln:
mov ah, 0x2
dec dh
mov dl, [cpl]
int 0x10
dec di
dec bl
ret
.checkln:
;Get the cursor position
mov ah, 0x3
int 0x10
;Check if the current line is the last one of the input
cmp dh, [.lastln]
jg .markln
ret
.markln:
;Mark the current line as the last one of the input
mov byte [.lastln], dh
ret

View File

@ -1,4 +1,4 @@
[ORG 0x200] [ORG 0x7e00]
jmp start jmp start
;Calls ;Calls
@ -17,17 +17,6 @@ jmp start
start: start:
;Initialise ds
mov ax, 0x1000
mov ds, ax
;Set up the stack
cli
mov ax, 0x1000
mov ss, ax
mov sp, 0x200
sti
;Get the terminal width ;Get the terminal width
mov ah, 0xf mov ah, 0xf
int 0x10 int 0x10