Moved stuff around and added a makefile also got a custom bootloader
based on the JazzOS bootloader (modified a bit)
This commit is contained in:
0
source/kernel/features/basic.asm
Normal file
0
source/kernel/features/basic.asm
Normal file
90
source/kernel/features/cli.asm
Executable file
90
source/kernel/features/cli.asm
Executable file
@@ -0,0 +1,90 @@
|
||||
os_start_cli:
|
||||
pusha
|
||||
|
||||
call os_print_newline
|
||||
|
||||
mov si, prompt
|
||||
call os_print_string
|
||||
|
||||
mov ax, 20
|
||||
|
||||
mov di, user_input
|
||||
|
||||
call os_display_input
|
||||
|
||||
|
||||
; ------------------------------------------------
|
||||
|
||||
os_read_cli:
|
||||
pusha
|
||||
|
||||
.output_the_user_input:
|
||||
call os_print_newline
|
||||
|
||||
.check_matches: ; Check if the user input matches any internal commands
|
||||
mov si, user_input
|
||||
mov di, help_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je help
|
||||
|
||||
mov si, user_input
|
||||
mov di, clear_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je clear
|
||||
|
||||
mov si, user_input
|
||||
mov di, pong_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je pong
|
||||
|
||||
mov si, user_input
|
||||
mov di, snake_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je snake
|
||||
|
||||
jmp .unkown
|
||||
|
||||
.unkown:
|
||||
mov si, unknown_command
|
||||
call os_print_string
|
||||
mov si, user_input
|
||||
call os_print_string_nl
|
||||
jmp .finish
|
||||
|
||||
.finish:
|
||||
popa
|
||||
call os_start_cli
|
||||
|
||||
clear:
|
||||
call os_set_text_mode
|
||||
call os_read_cli.finish
|
||||
|
||||
help:
|
||||
mov si, help_text
|
||||
call os_print_string_nl
|
||||
call os_read_cli.finish
|
||||
|
||||
pong:
|
||||
call game_pong
|
||||
call os_read_cli.finish
|
||||
|
||||
snake:
|
||||
call game_snake
|
||||
call os_read_cli.finish
|
||||
|
||||
section .data
|
||||
welcome_text db 'Welcome to CrawOS, the Cool, Real and AWsome Operating System', 0
|
||||
user_input times 20 db 0
|
||||
prompt_length db 20
|
||||
prompt db 'CrawOS sh> ', 0
|
||||
help_string db 'HELP', 0
|
||||
clear_string db 'CLEAR', 0
|
||||
pong_string db 'PONG', 0
|
||||
snake_string db 'SNAKE', 0
|
||||
help_text db 'This is for Cowards: "HELP" for this help text, "CLEAR" to clear the screen, esc to reboot', 0
|
||||
command_result_text db 'You typed: ', 0
|
||||
unknown_command db 'Error: Unkown Command.. ', 0
|
||||
0
source/kernel/features/disk.asm
Normal file
0
source/kernel/features/disk.asm
Normal file
53
source/kernel/features/graphics.asm
Normal file
53
source/kernel/features/graphics.asm
Normal file
@@ -0,0 +1,53 @@
|
||||
os_set_graphics_mode:
|
||||
pusha
|
||||
|
||||
mov ah, 00h
|
||||
mov al, 13h
|
||||
int 10h
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
; --------------------------------------
|
||||
|
||||
; x_end
|
||||
; y_end
|
||||
; x_start
|
||||
; y_start
|
||||
; colour
|
||||
os_draw_graphical_rectangle:
|
||||
; Tell BIOS we're changing 'da pixels!
|
||||
mov ah, 0Ch
|
||||
|
||||
mov al, 1100b
|
||||
|
||||
mov cx, [x_start]
|
||||
mov dx, [y_start]
|
||||
|
||||
jmp .x_loop
|
||||
|
||||
.x_loop:
|
||||
int 10h
|
||||
cmp cx, [x_end]
|
||||
je .next_row
|
||||
inc cx
|
||||
call .x_loop
|
||||
|
||||
.next_row:
|
||||
mov cx, [x_start]
|
||||
cmp dx, [y_end]
|
||||
je .finish
|
||||
inc dx ; Increase Row
|
||||
call .x_loop
|
||||
|
||||
.finish:
|
||||
ret
|
||||
|
||||
|
||||
section .data
|
||||
x_start dw 0
|
||||
y_start dw 0
|
||||
x_end dw 0
|
||||
y_end dw 0
|
||||
colour db 1111b
|
||||
|
||||
77
source/kernel/features/keyboard.asm
Normal file
77
source/kernel/features/keyboard.asm
Normal file
@@ -0,0 +1,77 @@
|
||||
; AX = key pressed
|
||||
os_read_input:
|
||||
mov ah, 11h ; BIOS call to check for key
|
||||
int 16h ; Interrupt
|
||||
jnz .key_pressed ; Jump if input isn't 0
|
||||
|
||||
hlt
|
||||
jmp os_read_input
|
||||
|
||||
.key_pressed:
|
||||
mov ah, 10h
|
||||
int 16h
|
||||
ret
|
||||
|
||||
; -------------------------------------------
|
||||
|
||||
os_display_input:
|
||||
pusha
|
||||
mov cx, [prompt_length]
|
||||
|
||||
.loop:
|
||||
call .check_key_pressed
|
||||
|
||||
jmp .loop
|
||||
|
||||
.check_key_pressed:
|
||||
call os_read_input
|
||||
|
||||
cmp al, 08h
|
||||
je .backspace
|
||||
|
||||
cmp al, 0Dh
|
||||
je .enter_key
|
||||
|
||||
cmp al, 1Bh
|
||||
je .esc_key
|
||||
|
||||
cmp cx, 0
|
||||
jb .check_key_pressed
|
||||
|
||||
call .print_current_input
|
||||
dec cx
|
||||
jmp .check_key_pressed
|
||||
|
||||
.esc_key:
|
||||
call os_reboot
|
||||
|
||||
.enter_key:
|
||||
mov al, 0
|
||||
stosb
|
||||
popa
|
||||
call os_read_cli
|
||||
|
||||
.backspace:
|
||||
call .move_cursor_back ; then .move_cursor_back
|
||||
call .loop ; Else .loop
|
||||
|
||||
.move_cursor_back:
|
||||
mov ah, 0Eh
|
||||
|
||||
mov al, 08h
|
||||
int 10h
|
||||
mov al, 20h
|
||||
int 10h
|
||||
mov al, 08h
|
||||
int 10h
|
||||
|
||||
dec di
|
||||
jmp os_display_input
|
||||
|
||||
.print_current_input:
|
||||
stosb
|
||||
|
||||
mov ah, 0Eh
|
||||
int 10h
|
||||
|
||||
ret
|
||||
0
source/kernel/features/math.asm
Normal file
0
source/kernel/features/math.asm
Normal file
6
source/kernel/features/power.asm
Executable file
6
source/kernel/features/power.asm
Executable file
@@ -0,0 +1,6 @@
|
||||
os_reboot:
|
||||
mov ax, 0x5307
|
||||
mov bx, 0x0001
|
||||
mov cx, 0x0003
|
||||
int 0x19
|
||||
|
||||
0
source/kernel/features/sound.asm
Normal file
0
source/kernel/features/sound.asm
Normal file
26
source/kernel/features/strings.asm
Executable file
26
source/kernel/features/strings.asm
Executable file
@@ -0,0 +1,26 @@
|
||||
; How string comparison works
|
||||
; DI => scasb compares value stored in DI which is 's' with 's' stored in AX register
|
||||
; and then increments DI if DF is 0
|
||||
; v
|
||||
; memory address 1: |s|n|a|t|0|
|
||||
; memory address 2: |s|n|a|k|e|0|
|
||||
; ^
|
||||
; SI => lodsb loads value stored at SI to AX and then increments SI if DF is 0
|
||||
os_compare_strings:
|
||||
cld
|
||||
|
||||
.compare:
|
||||
lodsb
|
||||
scasb ; Compare di to si
|
||||
jne .unequal ; If they are no equal, jump to .unequal
|
||||
cmp al, 0 ; Check if string is finished
|
||||
je .equal ; If it has, return true
|
||||
jmp .compare ; Finally, repeat
|
||||
|
||||
.unequal:
|
||||
mov cl, 0 ; Change to 0 if unquality is proven
|
||||
ret
|
||||
|
||||
.equal:
|
||||
mov cl, 1
|
||||
ret
|
||||
70
source/kernel/features/text.asm
Executable file
70
source/kernel/features/text.asm
Executable file
@@ -0,0 +1,70 @@
|
||||
; SI = pointer to start of string to be printed
|
||||
os_print_string:
|
||||
pusha
|
||||
|
||||
mov ah, 0Eh ; int 10h teletype function, we're telling the BIOS we will print something
|
||||
|
||||
.repeat:
|
||||
lodsb ; Get char from si into al
|
||||
cmp al, 0 ; Compare al to 0
|
||||
je .done ; If char is zero, end of string
|
||||
|
||||
int 10h ; Otherwise, print it
|
||||
jmp .repeat ; And move on to next char
|
||||
|
||||
.done:
|
||||
popa
|
||||
ret
|
||||
|
||||
; Exact same as the above procedure, but this adds a newline
|
||||
; after priting, similar to the difference between Rust's print! and println!
|
||||
os_print_string_nl:
|
||||
pusha
|
||||
|
||||
mov ah, 0Eh ; int 10h teletype function, we're telling the BIOS we will print something
|
||||
|
||||
.repeat:
|
||||
lodsb ; Get char from si into al
|
||||
cmp al, 0 ; Compare al to 0
|
||||
je .done ; If char is zero, end of string
|
||||
|
||||
int 10h ; Otherwise, print it
|
||||
jmp .repeat ; And move on to next char
|
||||
|
||||
.done:
|
||||
call os_print_newline
|
||||
popa
|
||||
ret
|
||||
|
||||
; --------------------------------------------
|
||||
|
||||
os_print_newline:
|
||||
pusha
|
||||
|
||||
mov ah, 0Eh
|
||||
mov al, 13
|
||||
int 10h
|
||||
mov al, 10
|
||||
int 10h
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
; -------------------------------------------
|
||||
|
||||
os_set_text_mode:
|
||||
pusha
|
||||
; Set mode = 80x25 (text mode)
|
||||
mov ah, 00h
|
||||
mov al, 03h
|
||||
int 10h
|
||||
|
||||
; Move cursor to the top left
|
||||
mov ah, 02h
|
||||
mov dh, 0
|
||||
mov dl, 0
|
||||
int 10h
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
Reference in New Issue
Block a user