Pong
I forgot to commit for a while and I haven't done much, but got the very basics of the game pong working. Signed-off-by: deadvey <deadvey@deadvey.com>
This commit is contained in:
@@ -66,5 +66,5 @@ mkisofs -quiet -V 'MIKEOS' -input-charset iso8859-1 -o disk_images/crawos.iso -b
|
|||||||
|
|
||||||
echo '>>> Done!'
|
echo '>>> Done!'
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
@@ -16,8 +16,6 @@ os_set_graphics_mode:
|
|||||||
; y_start
|
; y_start
|
||||||
; colour
|
; colour
|
||||||
os_draw_graphical_rectangle:
|
os_draw_graphical_rectangle:
|
||||||
pusha
|
|
||||||
|
|
||||||
; Tell BIOS we're changing 'da pixels!
|
; Tell BIOS we're changing 'da pixels!
|
||||||
mov ah, 0Ch
|
mov ah, 0Ch
|
||||||
|
|
||||||
@@ -28,21 +26,28 @@ os_draw_graphical_rectangle:
|
|||||||
|
|
||||||
jmp .x_loop
|
jmp .x_loop
|
||||||
|
|
||||||
.x_loop:
|
.x_loop:
|
||||||
int 10h
|
int 10h
|
||||||
cmp cx, [x_end]
|
cmp cx, [x_end]
|
||||||
je .next_row
|
je .next_row
|
||||||
inc cx
|
inc cx
|
||||||
call .x_loop
|
call .x_loop
|
||||||
|
|
||||||
.next_row:
|
.next_row:
|
||||||
mov cx, [x_start]
|
mov cx, [x_start]
|
||||||
cmp dx, [y_end]
|
cmp dx, [y_end]
|
||||||
je .finish
|
je .finish
|
||||||
inc dx ; Increase Row
|
inc dx ; Increase Row
|
||||||
call .x_loop
|
call .x_loop
|
||||||
|
|
||||||
.finish:
|
.finish:
|
||||||
popa
|
ret
|
||||||
Iret
|
|
||||||
|
|
||||||
|
section .data
|
||||||
|
x_start dw 0
|
||||||
|
y_start dw 0
|
||||||
|
x_end dw 0
|
||||||
|
y_end dw 0
|
||||||
|
colour db 1111b
|
||||||
|
|
||||||
|
@@ -1,162 +0,0 @@
|
|||||||
; ==================================================================
|
|
||||||
; 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
|
|
0
source/functions/math.asm
Normal file
0
source/functions/math.asm
Normal file
@@ -1,27 +1,99 @@
|
|||||||
game_pong:
|
game_pong:
|
||||||
pusha
|
call .draw_players
|
||||||
|
call .detect_input
|
||||||
|
|
||||||
call os_set_graphics_mode
|
; Clears screen and draws both players and ball
|
||||||
|
.draw_screen:
|
||||||
|
call os_set_graphics_mode ; Clear screen
|
||||||
|
.draw_p1:
|
||||||
|
; Player 1
|
||||||
|
mov ax, [p1_x]
|
||||||
|
mov [x_start], ax
|
||||||
|
mov [x_end], ax
|
||||||
|
|
||||||
call os_draw_graphical_rectangle
|
mov bx, [p1_y]
|
||||||
|
mov [y_start], bx
|
||||||
|
add bx, [bat_height]
|
||||||
|
mov [y_end], bx
|
||||||
|
|
||||||
|
call os_draw_graphical_rectangle ; Draw player 1
|
||||||
|
.draw_p2:
|
||||||
|
; Player 2
|
||||||
|
mov ax, [p2_x]
|
||||||
|
mov [x_start], ax
|
||||||
|
mov [x_end], ax
|
||||||
|
|
||||||
|
mov bx, [p2_y]
|
||||||
|
mov [y_start], bx
|
||||||
|
add bx, [bat_height]
|
||||||
|
mov [y_end], bx
|
||||||
|
|
||||||
|
call os_draw_graphical_rectangle ; Draw player 1
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Player 1 movements
|
||||||
|
.p1_up:
|
||||||
|
mov dx, [p1_y]
|
||||||
|
sub dx, 5
|
||||||
|
mov [p1_y], dx
|
||||||
|
call .draw_players
|
||||||
|
jmp .detect_input
|
||||||
|
.p1_down:
|
||||||
|
mov dx, [p1_y]
|
||||||
|
add dx, 5
|
||||||
|
mov [p1_y], dx
|
||||||
|
call .draw_players
|
||||||
|
jmp .detect_input
|
||||||
|
|
||||||
|
; Player 2 movements
|
||||||
|
.p2_up:
|
||||||
|
mov dx, [p2_y]
|
||||||
|
sub dx, 5
|
||||||
|
mov [p2_y], dx
|
||||||
|
call .draw_players
|
||||||
|
jmp .detect_input
|
||||||
|
.p2_down:
|
||||||
|
mov dx, [p2_y]
|
||||||
|
add dx, 5
|
||||||
|
mov [p2_y], dx
|
||||||
|
call .draw_players
|
||||||
|
jmp .detect_input
|
||||||
|
|
||||||
|
; Ball bouncing
|
||||||
|
.bounce_ball:
|
||||||
|
|
||||||
call os_set_text_mode
|
|
||||||
jmp .finish
|
|
||||||
|
|
||||||
.detect_input:
|
.detect_input:
|
||||||
call os_read_input
|
call os_read_input
|
||||||
cmp al, 08h
|
cmp al, 08h
|
||||||
je .finish
|
je .finish
|
||||||
jmp .detect_input
|
|
||||||
|
; Player 1
|
||||||
|
cmp al, 77h ; Pressed 'w' (player 1 up)
|
||||||
|
je .p1_up
|
||||||
|
cmp al, 73h ; Pressed 's' (player 1 down)
|
||||||
|
je .p1_down
|
||||||
|
|
||||||
|
; Player 2
|
||||||
|
cmp al, 5bh ; Pressed '[' (player 2 up)
|
||||||
|
je .p2_up
|
||||||
|
cmp al, 27h ; Pressed ''' (player 2 down)
|
||||||
|
je .p2_down
|
||||||
|
|
||||||
|
jmp .detect_input
|
||||||
|
|
||||||
.finish:
|
.finish:
|
||||||
call os_set_text_mode
|
call os_set_text_mode
|
||||||
popa
|
call os_start_cli
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
section .data
|
||||||
x_start dw 5
|
ball_x dw 5
|
||||||
y_start dw 5
|
ball_y dw 5
|
||||||
x_end dw 30
|
|
||||||
y_end dw 46
|
p1_x dw 5
|
||||||
colour db 1100b
|
p1_y dw 5
|
||||||
|
|
||||||
|
p2_x dw 315
|
||||||
|
p2_y dw 5
|
||||||
|
|
||||||
|
bat_height dw 20
|
||||||
|
86
source/games/pong_old.asm
Normal file
86
source/games/pong_old.asm
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
game_pong:
|
||||||
|
pusha
|
||||||
|
call os_set_graphics_mode
|
||||||
|
jmp .draw_player_1
|
||||||
|
jmp .draw_player_2
|
||||||
|
jmp .detect_inputi
|
||||||
|
.draw_player_1:
|
||||||
|
; X coords
|
||||||
|
mov ax, [p1_x]
|
||||||
|
mov [x_start], ax
|
||||||
|
mov [x_end], ax
|
||||||
|
|
||||||
|
; Y coords
|
||||||
|
mov bx, [p1_y]
|
||||||
|
mov [y_start], bx
|
||||||
|
add bx, [bat_height] ; Add the bat height to the y coord
|
||||||
|
mov [y_end], b
|
||||||
|
call os_draw_graphical_rectangle
|
||||||
|
ret
|
||||||
|
.draw_player_2:
|
||||||
|
; X coords
|
||||||
|
mov ax, [p2_x]
|
||||||
|
mov [x_start], ax
|
||||||
|
mov [x_end], ax
|
||||||
|
|
||||||
|
; Y coords
|
||||||
|
mov bx, [p2_y]
|
||||||
|
mov [y_start], bx
|
||||||
|
add bx, [bat_height] ; Add the bat height to the y coord
|
||||||
|
mov [y_end], bx
|
||||||
|
|
||||||
|
call os_draw_graphical_rectangle
|
||||||
|
ret
|
||||||
|
.detect_input:
|
||||||
|
call os_read_input
|
||||||
|
; Exit if backspace is pressed
|
||||||
|
cmp al, 08h
|
||||||
|
je .finish
|
||||||
|
; Go up when you press 'w'
|
||||||
|
cmp al, 77h
|
||||||
|
je .p1_up
|
||||||
|
; Go up when you press 's'
|
||||||
|
cmp al, 73h
|
||||||
|
je .p1_down
|
||||||
|
|
||||||
|
; Loop back
|
||||||
|
jmp .detect_input
|
||||||
|
.p1_down:
|
||||||
|
; X coords
|
||||||
|
mov ax, [p1_x]
|
||||||
|
mov [x_start], ax
|
||||||
|
mov [x_end], ax
|
||||||
|
|
||||||
|
; Y coords
|
||||||
|
mov bx, [p1_y]
|
||||||
|
add bx, 5 ; Move the bat down 5
|
||||||
|
mov [y_start], bx
|
||||||
|
add bx, [bat_height] ; Add the bat height to the y coord
|
||||||
|
mov [y_end], bx
|
||||||
|
|
||||||
|
call os_draw_graphical_rectangle
|
||||||
|
ret
|
||||||
|
.p1_up:
|
||||||
|
mov ax, [move_distance]
|
||||||
|
sub ax, [p1_y]
|
||||||
|
call os_draw_graphical_rectangle
|
||||||
|
ret
|
||||||
|
.finish:
|
||||||
|
call os_set_text_mode
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
|
||||||
|
section .data
|
||||||
|
x_start dw 0
|
||||||
|
y_start dw 0
|
||||||
|
x_end dw 0
|
||||||
|
y_end dw 0
|
||||||
|
|
||||||
|
p1_y dw 5
|
||||||
|
p2_y dw 0
|
||||||
|
p1_x dw 5
|
||||||
|
p2_x dw 30
|
||||||
|
|
||||||
|
bat_height dw 20
|
||||||
|
move_distance dw 5
|
||||||
|
colour db 1111b
|
@@ -60,7 +60,6 @@ Sides dw 2
|
|||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; FEATURES -- Code to pull into the kernel
|
; FEATURES -- Code to pull into the kernel
|
||||||
|
|
||||||
%INCLUDE "features/screen.asm"
|
%INCLUDE "features/screen.asm"
|
||||||
%INCLUDE "features/cli.asm"
|
%INCLUDE "features/cli.asm"
|
||||||
%INCLUDE "features/power.asm"
|
%INCLUDE "features/power.asm"
|
||||||
@@ -68,7 +67,10 @@ Sides dw 2
|
|||||||
%INCLUDE "features/graphics.asm"
|
%INCLUDE "features/graphics.asm"
|
||||||
%INCLUDE "features/sound.asm"
|
%INCLUDE "features/sound.asm"
|
||||||
|
|
||||||
; GAMES
|
; FUNCTIONS -- Other stuff that is useful
|
||||||
|
%INCLUDE "functios/math.asm"
|
||||||
|
|
||||||
|
; GAMES -- Games that I wrote for it
|
||||||
%INCLUDE "games/pong.asm"
|
%INCLUDE "games/pong.asm"
|
||||||
|
|
||||||
; ==================================================================
|
; ==================================================================
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user