From 4d71868ac63454358be28d210ea152fb02618d95 Mon Sep 17 00:00:00 2001 From: DeaDvey Date: Wed, 11 Jun 2025 15:50:22 +0100 Subject: [PATCH] rectangles work --- .gitignore | 1 + LICENSE | 0 README.md | 0 build-linux.sh | 2 +- disk_images/crawos.flp | Bin 1474560 -> 1474560 bytes disk_images/crawos.iso | Bin 1835008 -> 1835008 bytes source/.kernel.asm.swp | Bin 12288 -> 0 bytes source/features/cli.asm | 54 +++++++++--- source/features/graphics.asm | 48 +++++++++++ source/features/power.asm | 0 source/features/screen.asm | 67 +++++++-------- source/features/screen.asm~ | 162 +++++++++++++++++++++++++++++++++++ source/features/sound.asm | 0 source/features/strings.asm | 0 source/games/pong.asm | 27 ++++++ source/kernel.asm | 8 +- source/kernel.bin | Bin 355 -> 580 bytes 17 files changed, 321 insertions(+), 48 deletions(-) create mode 100755 .gitignore mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 disk_images/crawos.flp delete mode 100644 source/.kernel.asm.swp mode change 100644 => 100755 source/features/cli.asm create mode 100644 source/features/graphics.asm mode change 100644 => 100755 source/features/power.asm create mode 100755 source/features/screen.asm~ create mode 100644 source/features/sound.asm mode change 100644 => 100755 source/features/strings.asm create mode 100644 source/games/pong.asm 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 247e5bf5d22028dedb69dd8fe90ec1e747f18be4..3d3461d0394fd4ba4ff7cc7253cdcce4565e115c GIT binary patch delta 2095 zcmZo@h-zqv+Q7oZ;=u5qf3qOdd%?*HOq`QMSkMI2%s3RwPDe2_xG;fLZB}5q%st6P znqyxY;|nQ<7fUBAxahF+ZQwmCuz_oGn2TzCH=hsV3ucCwzy7~?{NIM7MBawCM8rnA zgtzf014Gg47itWiFQ5E>p~<*`VO8P_Lxva33@^_8-@>KMcj;P2-?nbTFZUPnO*ETW`PlCO}QlbTqh zP?C|VP@G(pnwrNDnO~|~T2z!@WTg z7|se<^Vu_5m#{d#`0^hlZY}1>RKnu);@SVi^9e7G|9^4z{|m!^FS!_A*!;8MC}Dp2 w?f(nKe~E`#8CV(Q81xu;VDa}raI*r_C@~raqv>EY8;lkOqa`7sk}#JQ03UMz8UO$Q delta 1841 zcmZo@h-zqv+Q7oZ^x^+zL8kYDlNFe_CyB72aMjE>bV`p$F*77Hg4JwRV7kmb$wiv= z#X*J_(IL-=eP&g|9qWxc<_`hlk-&ujf2`~Eo@B72>BK7 diff --git a/disk_images/crawos.iso b/disk_images/crawos.iso index a657729be692d4eb1c4365143b32351b0c830930..6dc1a1fb138f4912183eb437e5afd175ecd214bc 100644 GIT binary patch delta 1055 zcmZo@C}?OX*s!62hnwG!g@uWMfsuiMadTmF6Qi@Qw`Z`wTd;y>u)n35nSs8CTd;np zi<^R*r;lrJWN?V9uYyykr;m$kkb;_mvrCYxvwx6_g0qXhOPGtkQ%-46V&&w-CN(hy zFTDU)$Dm+;KYcH~U}q0cA0JOY_sItv3KWeDj7$y83=IuUO)L#e3@ljC1t$A7OK>6N zHy1Qd5UKa|_EZQ@O;PYF%~LQmR4_EPGO@HWFi`+$<}%hZFiJGARM0If%}gy(&<#`Y z_4Ic24_464%qu7@(M`@sEGkYdQOGRLx3Dm^)HPJl%~wdtEY6P4%uP&BE!IyiN-WPW z*2^r;SI|vTfb!CE3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YL)Q%K4zQ7~7qRWQ&| zC{9hz&r4BAsw_!WuvI8dEl4a%EXglYNX|$sN=zL?f~*edwyyXZ&iD7fhR>PIT%7b!&Q z`|7(eK(rYe#T%J`^>K1qEBNK-=~kr{9z?g7}iuiV}vr{P^UI#Ju!WD+UJ6tW*U!pMf(u zw?H8!M@PYcfq^qOzf2*$SVtkT0>VxMvpGQlnv+?Us*svjl3A3RQ>l=dr(kB{4N;Ve zP*j|no|~FiQml|#mRh8cn4XxKr=yTqtl*oOo$4P94zbLVVt5cj^rs;7JEoPS7Acfu zWESfvl&31Bb+3`uGX=$lNoT-JSoJJ<5=4Rlmmz0{E2+H`W6(y-f zd5JmjqyUZ-g+y@tXO<`=mVnDGVPmw+qefS6r~oHW)`I?Bq|tNn1M>aq|_2{5^xR( r1qne?SV3uVMxsJ~T3T^xNwGpoYC&pVO0hzI9;P-Y&yZjRLo)^dSAt>q 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 c2df7e40129f5dc526d51840b3d8b8b09c91e62d..5e5bb3ed9be6fe3a9a9bd7853a07c5f0c87f84aa 100644 GIT binary patch delta 477 zcmaFNbcAJsG{?R)#uriyFP2VJ&|&A>zLqSr6f7(8D-`Ts(baRbAu#21DPFPIr#ocq6pZv)3!fei|01wgd_ z%kBSHZQ(mBa5&*b!~cE0j4vYp?+{_wZ^8It-v5Lbx&QZBFzydyeDR*4;U{B>1&9~T z_~IdmS6`w6;wCb_xD4W!sJ>)i*tdo8g(OJN3#I=r85j~@to;AN{Qrw@|3O~h|Nr9c z{}*o=UOfNLfE|c97bTYa2U{sHc)0omFgW|TItDQW`1`ptgk)qED`XZcKosaGlvEZ> zmSq&I*HKUct5Q-Z$yZ3uNlh$LD9K1wC{8X)P0eG7%r6D0Oii&;U~nxe$}h4~2+hmR zFV9nO&d<$F%uCVJQ()M^9=w~8VJ9=gS;;?Z)|Il`FqE*p{Q7?*!{LpLhZD9iY!E&x zka##@3(p3gZa!c{*>IFFzx?+9h2p=&!>kOf3~~&53_Ji1v%e1j delta 205 zcmX@Y@|bCYH0z6l3@@fnRMz2QJ}a<=so@yoCWeV&s`W3J8D9SU|Kj<78;%kQ8{QIb z8|f037xD~;U#w@?z_4on3x*e33|sg%aGVv`pm0_IMEk!y@qg78zOw>{6JGTF-}i^% zMf!h`x=sHR4=22+`M>W4!+uuA7gY=mKN(AyU)=n^kBjj|@c$QI{xe_zeg+2TqQr9l tU@HX%4_BXn$*GL0;tY}br3xjL1*s`k3Jf7Zp{@*Wjy}Pzlg}{90RSKvQU3q{