Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into arrows
Browse files Browse the repository at this point in the history
adamperkowski committed Jul 28, 2024
2 parents 3b2a99f + 199ae46 commit 0bc2a54
Showing 2 changed files with 63 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ dd if=<your_binary_filename>.bin of=/dev/sdX && sync
```

> [!IMPORTANT]
> Make sure to replace `<your_binary_filename>.bin` with your downloaded/compiled binary name and **make sure to replace `/dev/sdX` with your USB's actual partition number. **Any data on it will be lost!**
> Make sure to replace `<your_binary_filename>.bin` with your downloaded/compiled binary name and make sure to replace `/dev/sdX` with your USB's actual partition number. **Any data on it will be lost!**
> [!NOTE]
>You can choose the device to boot off of from your BIOS boot menu (accessible by pressing <kbd>F8</kbd> or <kbd>F12</kbd>).
116 changes: 62 additions & 54 deletions asm/boot.asm
Original file line number Diff line number Diff line change
@@ -11,112 +11,120 @@ _start:
xor ax, ax
mov ds, ax
mov es, ax
mov bx, boot_msg
call print
mov cx, ax ;clear registers
mov bx, boot_msg
call print ;print the boot message

jmp shell

jmp $
jmp shell ;jmp to the shell

jmp $ ;failsafe - jmp to itself

shell:
mov ah, 0xE
mov al, '>'
int 0x10
int 0x10 ;print a '>'

mov bx, nl
call print
call print ;print the shell prompt

.input:
mov cl, 0
mov bx, buffer
mov cl, 0 ;initialize character counter
mov bx, buffer ;move the buffer address into bx
.get_input_loop:
mov ah, 0
int 0x16
int 0x16 ;get keypress

cmp al, 0x8
je .check_buffer
cmp al, 0x8
je .check_buffer ;check if backspace

cmp al, 0xD
je .print_input
je .print_input ;check if return key

cmp al, 0x20
jb .get_input_loop
jb .get_input_loop ;check if special key

cmp al, 0x7F
jae .get_input_loop
jae .get_input_loop ;check if special key

cmp cl, 255
je .get_input_loop
je .get_input_loop ;check if buffer is full

mov ah, 0xE
int 0x10
int 0x10 ;print input character

mov [bx], al
inc bx
inc cl
mov [bx], al ;add input character to the buffer
inc bx ;make bx point to the next location of the buffer
inc cl ;increment character counter

jmp .get_input_loop

.check_buffer:
.check_buffer:
cmp cl, 0
je .get_input_loop
jne .backspace
je .get_input_loop ;if buffer is empty jmp back to the input loop
jne .backspace ;if not, handle backspace

.backspace:
dec bx
mov ch, 0
mov [bx], ch
dec cl
dec bx ;make bx point to the previous character of the buffer
mov [bx], ch ;remove it from the buffer
dec cl ;decrement character counter

mov ah, 0xE
mov al, 0x8
int 0x10
int 0x10 ;move the cursor one character back
mov al, 0
int 0x10
int 0x10 ;overwrite the last entered character with a blank character
mov al, 0x8
int 0x10
jmp .get_input_loop
int 0x10 ;move the cursor one character back

jmp .get_input_loop ;jmp back to the input loop

.print_input:
mov ah, 0xE
mov al, 0xA
int 0x10
int 0x10
mov al, 0xD
int 0x10
mov bx, buffer
mov ch, 0
int 0x10 ;print newline

mov bx, buffer ;move buffer start address into bx
.print_input_loop:
mov al, [bx]
cmp al, 0
je .end_print_input
int 0x10
mov [bx], ch
inc bx
jmp .print_input_loop
mov al, [bx]

cmp al, 0 ;check if current character is a NULL-terminator
je shell ;if yes, stop printing

int 0x10 ;if not, print the character

.end_print_input:
jmp shell
mov [bx], ch ;clear current buffer location
inc bx ;make bx point to the next character of the buffer

jmp .print_input_loop

print:
mov ah, 0xE
.print_loop:
mov al, [bx]
cmp al, 0
je back
int 0x10
inc bx
jmp .print_loop
.print_loop: ;basically print_input_loop, but it doesnt clear the character after printing
mov al, [bx]

cmp al, 0 ;check if current character is a NULL-terminator
je back ;if yes, stop printing

int 0x10 ;if not, print the character
inc bx ;make bx point to the next character of the string

jmp .print_loop

back:
ret
ret ;return

cls:
pusha

mov ah, 0x00
mov al, 0x03
int 0x10
int 0x10 ;clear screen buffer

popa
ret

ret ;return

boot_msg: db 13, 10, "HighlightOS v0.0.1", 13, 10, 10, " Copyright (C) 2024", 13, 10, " Adam Perkowski", 0
nl: db 13, 10, 10, "hls <", 0

0 comments on commit 0bc2a54

Please sign in to comment.