diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/build-linux.sh b/build-linux.sh index bf0a29b..66caf65 100755 --- a/build-linux.sh +++ b/build-linux.sh @@ -66,5 +66,5 @@ mkisofs -quiet -V 'MIKEOS' -input-charset iso8859-1 -o disk_images/crawos.iso -b 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 diff --git a/disk_images/crawos.flp b/disk_images/crawos.flp old mode 100644 new mode 100755 index 247e5bf..3d3461d Binary files a/disk_images/crawos.flp and b/disk_images/crawos.flp differ diff --git a/disk_images/crawos.iso b/disk_images/crawos.iso index a657729..6dc1a1f 100644 Binary files a/disk_images/crawos.iso and b/disk_images/crawos.iso differ diff --git a/source/.kernel.asm.swp b/source/.kernel.asm.swp deleted file mode 100644 index e50700a..0000000 Binary files a/source/.kernel.asm.swp and /dev/null differ diff --git a/source/features/cli.asm b/source/features/cli.asm old mode 100644 new mode 100755 index 7e2765f..ecb1fc4 --- a/source/features/cli.asm +++ b/source/features/cli.asm @@ -6,12 +6,12 @@ os_start_cli: mov si, prompt call os_print_string + mov ax, 20 + mov di, user_input call os_display_input - popa - ret ; ------------------------------------------------ @@ -26,21 +26,53 @@ os_read_cli: mov di, help_string call os_compare_strings 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: + popa call os_start_cli -print_help_text: +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 -user_input times 20 db 0 -prompt db 'CrawOS: ', 0 -help_string db 'HELP', 0 -help_text db 'This is CrawOS, type "HELP" for help', 0 -command_result_text db 'You typed: ', 0 -true db 'TRUE', 0 -false db 'FALSE', 0 +section .data + user_input times 20 db 0 + prompt_length db 20 + prompt db 'CrawOS: ', 0 + help_string db 'HELP', 0 + clear_string db 'CLEAR', 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 diff --git a/source/features/graphics.asm b/source/features/graphics.asm new file mode 100644 index 0000000..a56b42f --- /dev/null +++ b/source/features/graphics.asm @@ -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 + diff --git a/source/features/power.asm b/source/features/power.asm old mode 100644 new mode 100755 diff --git a/source/features/screen.asm b/source/features/screen.asm index e9c1ed6..894e367 100755 --- a/source/features/screen.asm +++ b/source/features/screen.asm @@ -1,15 +1,4 @@ -; ================================================================== -; 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) - +; SI = pointer to start of string to be printed os_print_string: pusha @@ -29,7 +18,8 @@ os_print_string: ; 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 +os_print_string_nl: + pusha 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: 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 ret - ; ------------------------------------------- -os_clear_screen: - pusha - +os_set_text_mode: + pusha + ; Set mode = 80x25 (text mode) mov ah, 00h - mov al, 03h ; Set video mode to textmode (80x25). 16 colors, 8 pages + mov al, 03h int 10h + ; Move cursor to the top left mov ah, 02h mov dh, 0 mov dl, 0 int 10h - popa - ret + popa + ret ; ------------------------------------------- @@ -98,15 +86,17 @@ os_read_input: ; ------------------------------------------- -os_display_input: +os_display_input: pusha - + mov cx, [prompt_length] + +.loop: call .check_key_pressed - jmp os_display_input + jmp .loop .check_key_pressed: - call os_read_input + call os_read_input cmp al, 08h je .backspace @@ -117,8 +107,12 @@ os_display_input: cmp al, 1Bh je .esc_key + cmp cx, 0 + jb .check_key_pressed + call .print_current_input - ret + dec cx + jmp .check_key_pressed .esc_key: call os_reboot @@ -126,11 +120,14 @@ os_display_input: .enter_key: mov al, 0 stosb - mov di, user_input - + 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 diff --git a/source/features/screen.asm~ b/source/features/screen.asm~ new file mode 100755 index 0000000..c20a56b --- /dev/null +++ b/source/features/screen.asm~ @@ -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 diff --git a/source/features/sound.asm b/source/features/sound.asm new file mode 100644 index 0000000..e69de29 diff --git a/source/features/strings.asm b/source/features/strings.asm old mode 100644 new mode 100755 diff --git a/source/games/pong.asm b/source/games/pong.asm new file mode 100644 index 0000000..6018bdd --- /dev/null +++ b/source/games/pong.asm @@ -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 diff --git a/source/kernel.asm b/source/kernel.asm index a34ecb3..ea73479 100755 --- a/source/kernel.asm +++ b/source/kernel.asm @@ -37,7 +37,8 @@ os_main: je no_change no_change: - call print_help_text + mov si, help_text + call os_print_string_nl call os_start_cli bootdev db 0 @@ -64,6 +65,11 @@ Sides dw 2 %INCLUDE "features/cli.asm" %INCLUDE "features/power.asm" %INCLUDE "features/strings.asm" + %INCLUDE "features/graphics.asm" + %INCLUDE "features/sound.asm" + +; GAMES + %INCLUDE "games/pong.asm" ; ================================================================== ; END OF KERNEL diff --git a/source/kernel.bin b/source/kernel.bin index c2df7e4..5e5bb3e 100644 Binary files a/source/kernel.bin and b/source/kernel.bin differ