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:
134
source/kernel/games/pong.asm
Normal file
134
source/kernel/games/pong.asm
Normal file
@@ -0,0 +1,134 @@
|
||||
game_pong:
|
||||
call .draw_screen
|
||||
call .detect_input
|
||||
|
||||
; 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
|
||||
|
||||
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
|
||||
.draw_ball:
|
||||
; The ball
|
||||
mov ax, [ball_x]
|
||||
mov [x_start], ax
|
||||
mov [x_end], ax
|
||||
|
||||
mov bx, [ball_y]
|
||||
mov [y_start], bx
|
||||
mov [y_end], bx
|
||||
|
||||
call os_draw_graphical_rectangle ; Draw the ball
|
||||
|
||||
ret
|
||||
|
||||
; Player 1 movements
|
||||
.p1_up:
|
||||
mov dx, [p1_y]
|
||||
sub dx, 5
|
||||
mov [p1_y], dx
|
||||
jmp .detect_input
|
||||
.p1_down:
|
||||
mov dx, [p1_y]
|
||||
add dx, 5
|
||||
mov [p1_y], dx
|
||||
jmp .detect_input
|
||||
|
||||
; Player 2 movements
|
||||
.p2_up:
|
||||
mov dx, [p2_y]
|
||||
sub dx, 5
|
||||
mov [p2_y], dx
|
||||
jmp .detect_input
|
||||
.p2_down:
|
||||
mov dx, [p2_y]
|
||||
add dx, 5
|
||||
mov [p2_y], dx
|
||||
jmp .detect_input
|
||||
|
||||
; Ball bouncing
|
||||
; This should move the ball along one frame
|
||||
; The ball moves 1 pixel per frame, however this is usually
|
||||
; at an angle, so we need sin and cos
|
||||
.bounce_ball:
|
||||
; Change the x coords
|
||||
fld dword [ball_angle]
|
||||
fcos
|
||||
fld dword [precise_ball_x]
|
||||
faddp
|
||||
frndint
|
||||
fstp dword [ball_x]
|
||||
|
||||
; Change the y coords
|
||||
fld dword [ball_angle]
|
||||
fsin
|
||||
fld dword [precise_ball_y]
|
||||
faddp
|
||||
frndint
|
||||
fstp dword [ball_y]
|
||||
|
||||
ret
|
||||
|
||||
.detect_input:
|
||||
call os_read_input
|
||||
cmp al, 08h
|
||||
je .finish
|
||||
|
||||
; 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
|
||||
|
||||
call .bounce_ball
|
||||
call .draw_screen
|
||||
|
||||
jmp .detect_input
|
||||
|
||||
.finish:
|
||||
call os_set_text_mode
|
||||
call os_start_cli
|
||||
|
||||
section .data
|
||||
ball_x dw 100
|
||||
ball_y dw 100
|
||||
precise_ball_x dw 100
|
||||
precise_ball_y dw 100
|
||||
ball_angle dw 1 ; In radians
|
||||
cos_ball_angle dw 0
|
||||
sin_ball_angle dw 0
|
||||
|
||||
p1_x dw 5
|
||||
p1_y dw 5
|
||||
|
||||
p2_x dw 315
|
||||
p2_y dw 5
|
||||
|
||||
bat_height dw 20
|
||||
94
source/kernel/games/snake.asm
Normal file
94
source/kernel/games/snake.asm
Normal file
@@ -0,0 +1,94 @@
|
||||
game_snake:
|
||||
call .draw_screen
|
||||
call .detect_input
|
||||
|
||||
.draw_screen:
|
||||
call os_set_graphics_mode ; Clear screen
|
||||
.draw_snake_loop:
|
||||
mov ax, [snake_x]
|
||||
mov [x_start], ax
|
||||
mov [x_end], ax
|
||||
|
||||
mov bx, [snake_y]
|
||||
mov [y_start], bx
|
||||
mov [y_end], bx
|
||||
|
||||
call os_draw_graphical_rectangle
|
||||
ret
|
||||
|
||||
; Player 1 movements
|
||||
.up:
|
||||
mov dword [snake_direction], 0
|
||||
jmp .end_detect_input
|
||||
.down:
|
||||
mov dword [snake_direction], 2
|
||||
jmp .end_detect_input
|
||||
.left:
|
||||
mov dword [snake_direction], 3
|
||||
jmp .end_detect_input
|
||||
.right:
|
||||
mov dword [snake_direction], 1
|
||||
jmp .end_detect_input
|
||||
|
||||
.move_up:
|
||||
mov dx, [snake_y]
|
||||
sub dx, 1
|
||||
mov [snake_y], dx
|
||||
ret
|
||||
.move_down:
|
||||
mov dx, [snake_y]
|
||||
add dx, 1
|
||||
mov [snake_y], dx
|
||||
ret
|
||||
.move_left:
|
||||
mov dx, [snake_x]
|
||||
sub dx, 1
|
||||
mov [snake_x], dx
|
||||
ret
|
||||
.move_right:
|
||||
mov dx, [snake_x]
|
||||
add dx, 1
|
||||
mov [snake_x], dx
|
||||
ret
|
||||
|
||||
.move_snake:
|
||||
cmp dword [snake_direction], 0
|
||||
je .move_up
|
||||
cmp dword [snake_direction], 1
|
||||
je .move_right
|
||||
cmp dword [snake_direction], 2
|
||||
je .move_down
|
||||
; Else it must be left
|
||||
jmp .move_left
|
||||
|
||||
|
||||
.detect_input:
|
||||
call os_read_input
|
||||
cmp al, 08h
|
||||
je .finish
|
||||
|
||||
; Player 1
|
||||
cmp al, 77h ; Pressed 'w' up
|
||||
je .up
|
||||
cmp al, 61h ; Pressed 'a' left
|
||||
je .left
|
||||
cmp al, 73h ; Pressed 's' down
|
||||
je .down
|
||||
cmp al, 64h ; Pressed 'd' right
|
||||
je .right
|
||||
.end_detect_input:
|
||||
call .move_snake
|
||||
call .draw_screen
|
||||
|
||||
jmp .detect_input
|
||||
|
||||
.finish:
|
||||
call os_set_text_mode
|
||||
call os_start_cli
|
||||
|
||||
|
||||
section .data:
|
||||
snake_x: dw 5
|
||||
snake_y: dw 5
|
||||
snake_direction: dw 1 ; 0=up, 1=right, 2=down, 3=left
|
||||
snake_length: dw 1
|
||||
Reference in New Issue
Block a user