rectangles work

This commit is contained in:
2025-06-11 15:50:22 +01:00
parent be7943320d
commit 4d71868ac6
17 changed files with 321 additions and 48 deletions

1
.gitignore vendored Executable file
View File

@@ -0,0 +1 @@
*.swp

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

View File

@@ -66,5 +66,5 @@ mkisofs -quiet -V 'MIKEOS' -input-charset iso8859-1 -o disk_images/crawos.iso -b
echo '>>> Done!' echo '>>> Done!'
sudo qemu-system-i386 -drive file=disk_images/crawos.flp,index=0,if=floppy,format=raw qemu-system-i386 -drive file=disk_images/crawos.flp,index=0,if=floppy,format=raw

BIN
disk_images/crawos.flp Normal file → Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

54
source/features/cli.asm Normal file → Executable file
View File

@@ -6,12 +6,12 @@ os_start_cli:
mov si, prompt mov si, prompt
call os_print_string call os_print_string
mov ax, 20
mov di, user_input mov di, user_input
call os_display_input call os_display_input
popa
ret
; ------------------------------------------------ ; ------------------------------------------------
@@ -26,21 +26,53 @@ os_read_cli:
mov di, help_string mov di, help_string
call os_compare_strings call os_compare_strings
cmp cl, 1 cmp cl, 1
je print_help_text 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
jmp .unkown
.unkown:
mov si, unknown_command
call os_print_string
mov si, user_input
call os_print_string_nl
jmp .finish
.finish: .finish:
popa
call os_start_cli call os_start_cli
print_help_text: clear:
call os_set_text_mode
call os_read_cli.finish
help:
mov si, help_text mov si, help_text
call os_print_string_nl call os_print_string_nl
call os_read_cli.finish call os_read_cli.finish
pong:
call game_pong
call os_read_cli.finish
user_input times 20 db 0 section .data
prompt db 'CrawOS: ', 0 user_input times 20 db 0
help_string db 'HELP', 0 prompt_length db 20
help_text db 'This is CrawOS, type "HELP" for help', 0 prompt db 'CrawOS: ', 0
command_result_text db 'You typed: ', 0 help_string db 'HELP', 0
true db 'TRUE', 0 clear_string db 'CLEAR', 0
false db 'FALSE', 0 pong_string db 'PONG', 0
help_text db 'This is CrawOS, type "HELP" for help, "CLEAR" to clear the screen', 0
command_result_text db 'You typed: ', 0
unknown_command db 'Error: Unkown Command.. ', 0

View File

@@ -0,0 +1,48 @@
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:
pusha
; 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:
popa
Iret

0
source/features/power.asm Normal file → Executable file
View File

View File

@@ -1,15 +1,4 @@
; ================================================================== ; SI = pointer to start of string to be printed
; MikeOS -- The Mike Operating System kernel
; Copyright (C) 2006 - 2021 MikeOS Developers -- see doc/LICENSE.TXT
;
; SCREEN HANDLING SYSTEM CALLS
; ==================================================================
; ------------------------------------------------------------------
; os_print_string -- Displays text
; IN: SI = message location (zero-terminated string)
; OUT: Nothing (registers preserved)
os_print_string: os_print_string:
pusha pusha
@@ -29,7 +18,8 @@ os_print_string:
; Exact same as the above procedure, but this adds a newline ; Exact same as the above procedure, but this adds a newline
; after priting, similar to the difference between Rust's print! and println! ; after priting, similar to the difference between Rust's print! and println!
os_print_string_nl: pusha os_print_string_nl:
pusha
mov ah, 0Eh ; int 10h teletype function, we're telling the BIOS we will print something mov ah, 0Eh ; int 10h teletype function, we're telling the BIOS we will print something
@@ -50,35 +40,33 @@ os_print_string_nl: pusha
os_print_newline: os_print_newline:
pusha pusha
mov ah, 0Eh
mov al, 13
int 10h
mov al, 10
int 10h
mov ah, 03h
int 10h
mov ah, 02h
add dh, 1
mov dl, 0
int 10h
popa popa
ret ret
; ------------------------------------------- ; -------------------------------------------
os_clear_screen: os_set_text_mode:
pusha pusha
; Set mode = 80x25 (text mode)
mov ah, 00h mov ah, 00h
mov al, 03h ; Set video mode to textmode (80x25). 16 colors, 8 pages mov al, 03h
int 10h int 10h
; Move cursor to the top left
mov ah, 02h mov ah, 02h
mov dh, 0 mov dh, 0
mov dl, 0 mov dl, 0
int 10h int 10h
popa popa
ret ret
; ------------------------------------------- ; -------------------------------------------
@@ -98,15 +86,17 @@ os_read_input:
; ------------------------------------------- ; -------------------------------------------
os_display_input: os_display_input:
pusha pusha
mov cx, [prompt_length]
.loop:
call .check_key_pressed call .check_key_pressed
jmp os_display_input jmp .loop
.check_key_pressed: .check_key_pressed:
call os_read_input call os_read_input
cmp al, 08h cmp al, 08h
je .backspace je .backspace
@@ -117,8 +107,12 @@ os_display_input:
cmp al, 1Bh cmp al, 1Bh
je .esc_key je .esc_key
cmp cx, 0
jb .check_key_pressed
call .print_current_input call .print_current_input
ret dec cx
jmp .check_key_pressed
.esc_key: .esc_key:
call os_reboot call os_reboot
@@ -126,11 +120,14 @@ os_display_input:
.enter_key: .enter_key:
mov al, 0 mov al, 0
stosb stosb
mov di, user_input popa
call os_read_cli call os_read_cli
.backspace: .backspace:
call .move_cursor_back ; then .move_cursor_back
call .loop ; Else .loop
.move_cursor_back:
mov ah, 0Eh mov ah, 0Eh
mov al, 08h mov al, 08h

162
source/features/screen.asm~ Executable file
View File

@@ -0,0 +1,162 @@
; ==================================================================
; MikeOS -- The Mike Operating System kernel
; Copyright (C) 2006 - 2021 MikeOS Developers -- see doc/LICENSE.TXT
;
; SCREEN HANDLING SYSTEM CALLS
; ==================================================================
; ------------------------------------------------------------------
; os_print_string -- Displays text
; IN: SI = message location (zero-terminated string)
; OUT: Nothing (registers preserved)
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, 03h
int 10h
mov ah, 02h
add dh, 1
mov dl, 0
int 10h
popa
ret
; -------------------------------------------
os_clear_screen:
pusha
mov ah, 00h
mov al, 03h ; Set video mode to textmode (80x25). 16 colors, 8 pages
int 10h
mov ah, 02h
mov dh, 0
mov dl, 0
int 10h
popa
ret
; -------------------------------------------
; 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 ; Characters remaining
.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
dec cx
call .print_current_input
ret
.esc_key:
call os_reboot
.enter_key:
mov al, 0
stosb
mov di, user_input
popa
call os_read_cli
.backspace:
cmp cx, prompt_length ; If bx < 20
jl .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
inc cx
jmp os_display_input
.print_current_input:
stosb
mov ah, 0Eh
int 10h
ret

View File

0
source/features/strings.asm Normal file → Executable file
View File

27
source/games/pong.asm Normal file
View File

@@ -0,0 +1,27 @@
game_pong:
pusha
call os_set_graphics_mode
call os_draw_graphical_rectangle
call os_set_text_mode
jmp .finish
.detect_input:
call os_read_input
cmp al, 08h
je .finish
jmp .detect_input
.finish:
call os_set_text_mode
popa
ret
section .data
x_start dw 5
y_start dw 5
x_end dw 30
y_end dw 46
colour db 1100b

View File

@@ -37,7 +37,8 @@ os_main:
je no_change je no_change
no_change: no_change:
call print_help_text mov si, help_text
call os_print_string_nl
call os_start_cli call os_start_cli
bootdev db 0 bootdev db 0
@@ -64,6 +65,11 @@ Sides dw 2
%INCLUDE "features/cli.asm" %INCLUDE "features/cli.asm"
%INCLUDE "features/power.asm" %INCLUDE "features/power.asm"
%INCLUDE "features/strings.asm" %INCLUDE "features/strings.asm"
%INCLUDE "features/graphics.asm"
%INCLUDE "features/sound.asm"
; GAMES
%INCLUDE "games/pong.asm"
; ================================================================== ; ==================================================================
; END OF KERNEL ; END OF KERNEL

Binary file not shown.