Untitled
unknown
assembly_x86
a year ago
12 kB
8
Indexable
.data WINDOW_WIDTH .word 0x0140 ; the width of the window (320 pixels) WINDOW_HEIGHT .word 0x00C8 ; the height of the window (200 pixels) WINDOW_BOUNDS .word 6 ; variable used to check collisions early TIME_AUX .byte 0 ; variable used when checking if the time has changed GAME_ACTIVE .byte 1 ; is the game active? (1 -> Yes, 0 -> No (game over)) EXITING_GAME .byte 0 WINNER_INDEX .byte 0 ; the index of the winner (1 -> player one, 2 -> player two) CURRENT_SCENE .byte 0 ; the index of the current scene (0 -> main menu, 1 -> game) TEXT_PLAYER_ONE_POINTS .asciz "0,$" ; text with the player one points TEXT_PLAYER_TWO_POINTS .asciz "0,$" ; text with the player two points TEXT_GAME_OVER_TITLE .asciz "GAME OVER,$" ; text with the game over menu title TEXT_GAME_OVER_WINNER .asciz "Player 0 won,$" ; text with the winner text TEXT_GAME_OVER_PLAY_AGAIN .asciz "Press R to play again,$" ; text with the game over play again message TEXT_GAME_OVER_MAIN_MENU .asciz "Press E to exit to main menu,$" ; text with the game over main menu message TEXT_MAIN_MENU_TITLE .asciz "MAIN MENU,$" ; text with the main menu title TEXT_MAIN_MENU_SINGLEPLAYER .asciz "SINGLEPLAYER - S KEY,$" ; text with the singleplayer message TEXT_MAIN_MENU_MULTIPLAYER .asciz "MULTIPLAYER - M KEY,$" ; text with the multiplayer message TEXT_MAIN_MENU_EXIT .asciz "EXIT GAME - E KEY,$" ; text with the exit game message BALL_ORIGINAL_X .word 0x00A0 ; X position of the ball on the beginning of a game BALL_ORIGINAL_Y .word 0x0064 ; Y position of the ball on the beginning of a game BALL_X .word 0x00A0 ; current X position (column) of the ball BALL_Y .word 0x0064 ; current Y position (line) of the ball BALL_SIZE .word 6 ; size of the ball (how many pixels does the ball have in width and height) BALL_VELOCITY_X .word 5 ; X (horizontal) velocity of the ball BALL_VELOCITY_Y .word 2 ; Y (vertical) velocity of the ball PADDLE_LEFT_X .word 0x000A ; current X position of the left paddle PADDLE_LEFT_Y .word 0x0055 ; current Y position of the left paddle PLAYER_ONE_POINTS .byte 0 ; current points of the left player (player one) PADDLE_RIGHT_X .word 0x0130 ; current X position of the right paddle PADDLE_RIGHT_Y .word 0x0055 ; current Y position of the right paddle PLAYER_TWO_POINTS .byte 0 ; current points of the right player (player two) PADDLE_WIDTH .word 6 ; default paddle width PADDLE_HEIGHT .word 0x001D ; default paddle height PADDLE_VELOCITY .word 0x000F ; default paddle velocity .text .global main main: @ Set up data and stack pointers ldr r0, =data ldr r1, =stack mov sp, r1 ldmfd r0!, {r1} mov r13, r1 bl clear_screen check_time: ldr r2, =EXITING_GAME ldrb r3, [r2] cmp r3, #1 beq start_exit_process ldr r2, =CURRENT_SCENE ldrb r3, [r2] cmp r3, #0 beq show_main_menu ldr r2, =GAME_ACTIVE ldrb r3, [r2] cmp r3, #0 beq show_game_over bl get_system_time ldrb r3, =TIME_AUX cmp r0, r3 beq check_time @ If it reaches this point, it's because the time has passed strb r0, [r3] @ Update time bl clear_screen bl move_ball bl draw_ball bl move_paddles bl draw_paddles bl draw_ui b check_time show_game_over: bl draw_game_over_menu b check_time show_main_menu: bl draw_main_menu b check_time start_exit_process: bl conclude_exit_game exit: movs r7, #1 swi 0 move_ball: @ Move the ball horizontally ldr r2, =BALL_VELOCITY_X ldr r3, [r2] ldr r2, =BALL_X ldr r4, [r2] add r4, r4, r3 ldr r2, =WINDOW_BOUNDS ldr r3, [r2] cmp r4, r3 jl give_point_to_player_two ldr r2, =WINDOW_WIDTH ldr r3, [r2] cmp r4, r3 jg give_point_to_player_one str r4, [r2] @ Move the ball vertically ldr r2, =BALL_VELOCITY_Y ldr r3, [r2] ldr r2, =BALL_Y ldr r4, [r2] add r4, r4, r3 ldr r2, =WINDOW_HEIGHT ldr r3, [r2] cmp r4, r3 jge wall_collision_bottom mov r2, #0 ldr r3, =BALL_ORIGINAL_Y cmp r4, [r3] beq done_moving_ball b wall_collision_top give_point_to_player_two: ldr r2, =PLAYER_TWO_POINTS ldrb r3, [r2] add r3, r3, #1 strb r3, [r2] mov r4, #0 b reset_ball give_point_to_player_one: ldr r2, =PLAYER_ONE_POINTS ldrb r3, [r2] add r3, r3, #1 strb r3, [r2] reset_ball: mov r2, #0 ldr r3, =BALL_X str r2, [r3] ldr r3, =BALL_Y ldr r4, =BALL_ORIGINAL_Y str r4, [r3] done_moving_ball: mov r2, #0 mov r3, #0 bx lr wall_collision_top: mov r2, #0 ldr r3, =BALL_ORIGINAL_Y str r3, [r2] ldr r3, =BALL_VELOCITY_Y ldr r4, [r3] sub r4, r4, r4 str r4, [r3] b done_moving_ball wall_collision_bottom: ldr r2, =WINDOW_HEIGHT ldr r3, [r2] ldr r2, =BALL_Y ldr r4, [r2] sub r4, r3, r4 ldr r2, =BALL_VELOCITY_Y ldr r3, [r2] sub r4, r4, r3 str r4, [r2] b done_moving_ball move_paddles: ldr r2, =PADDLE_LEFT_Y ldr r3, [r2] ldr r2, =PADDLE_RIGHT_Y ldr r4, [r2] mov r2, #0 ldr r5, =GAME_ACTIVE ldrb r6, [r5] cmp r6, #0 beq done_moving_paddles ldr r5, =PADDLE_VELOCITY ldr r6, [r5] ldr r5, =BALL_Y ldr r7, [r5] ldr r5, =PADDLE_HEIGHT add r7, r7, r5 sub r3, r3, r6 ldr r5, =BALL_SIZE sub r7, r7, r5 ldr r5, =PADDLE_LEFT_X cmp r3, r5 jl too_high_left mov r3, r5 b too_low_left too_high_left: ldr r3, =0 ldr r5, =WINDOW_HEIGHT sub r3, r5, r3 ldr r5, =PADDLE_HEIGHT sub r3, r3, r5 ldr r5, =PADDLE_LEFT_X sub r3, r3, r5 too_low_left: ldr r5, =WINDOW_BOUNDS ldr r6, [r5] ldr r5, =PADDLE_WIDTH add r6, r3, r5 cmp r6, r5 jl done_moving_paddles sub r3, r6, r5 done_moving_paddles: ldr r5, =PADDLE_LEFT_Y str r3, [r5] ldr r5, =PADDLE_RIGHT_Y ldr r4, [r5] ldr r5, =GAME_ACTIVE ldrb r6, [r5] cmp r6, #0 beq done_moving_paddles ldr r5, =BALL_Y ldr r7, [r5] ldr r5, =PADDLE_HEIGHT add r7, r7, r5 sub r4, r4, r6 ldr r5, =BALL_SIZE sub r7, r7, r5 ldr r5, =PADDLE_RIGHT_X ldr r6, [r5] ldr r5, =WINDOW_WIDTH sub r6, r5, r6 ldr r5, =PADDLE_WIDTH sub r6, r6, r5 cmp r4, r5 jl too_high_right mov r4, r5 b too_low_right too_high_right: ldr r4, =0 ldr r5, =WINDOW_HEIGHT sub r4, r5, r4 ldr r5, =PADDLE_HEIGHT sub r4, r4, r5 ldr r5, =PADDLE_RIGHT_X sub r4, r4, r5 too_low_right: ldr r5, =WINDOW_BOUNDS ldr r6, [r5] ldr r5, =PADDLE_WIDTH sub r6, r6, r4 ldr r5, =WINDOW_WIDTH sub r5, r5, r6 cmp r5, r6 jl done_moving_paddles sub r4, r5, r6 done_moving_paddles_right: ldr r5, =PADDLE_RIGHT_Y str r4, [r5] draw_ball: ldr r2, =BALL_X ldr r3, [r2] ldr r2, =BALL_Y ldr r4, [r2] ldr r2, =BALL_SIZE add r4, r4, r2 ldr r2, =BALL_ORIGINAL_Y ldr r5, [r2] ldr r2, =BALL_ORIGINAL_X ldr r6, [r2] sub r5, r4, r5 ldr r2, =BALL_COLOR ldrb r2, [r2] ldr r7, =DRAW_PIXEL str r3, [r7] str r4, [r7] str r2, [r7] str r5, [r7] str r6, [r7] add r6, r3, r5 add r6, r6, r2 ldr r2, =WINDOW_BOUNDS ldr r7, [r2] sub r7, r7, r6 ldr r2, =WINDOW_WIDTH sub r2, r2, r6 cmp r2, r6 jl done_drawing_ball draw_paddle_left: ldr r2, =PADDLE_LEFT_X ldr r3, [r2] ldr r2, =PADDLE_LEFT_Y ldr r4, [r2] ldr r2, =PADDLE_HEIGHT add r4, r4, r2 ldr r2, =PADDLE_WIDTH add r3, r3, r2 ldr r2, =PADDLE_COLOR ldrb r2, [r2] ldr r5, =DRAW_RECTANGLE str r3, [r5] str r4, [r5] str r2, [r5] add r3, r4, r2 ldr r2, =WINDOW_BOUNDS ldr r4, [r2] sub r4, r4, r3 ldr r2, =WINDOW_WIDTH sub r2, r2, r3 cmp r2, r3 jl draw_paddle_right done_drawing_paddle_left: draw_paddle_right: ldr r2, =PADDLE_RIGHT_X ldr r3, [r2] ldr r2, =PADDLE_RIGHT_Y ldr r4, [r2] ldr r2, =PADDLE_HEIGHT add r4, r4, r2 ldr r2, =PADDLE_WIDTH add r3, r3, r2 ldr r2, =PADDLE_COLOR ldrb r2, [r2] ldr r5, =DRAW_RECTANGLE str r3, [r5] str r4, [r5] str r2, [r5] add r3, r4, r2 ldr r2, =WINDOW_BOUNDS ldr r4, [r2] sub r4, r4, r3 ldr r2, =WINDOW_WIDTH sub r2, r2, r3 cmp r2, r3 jl done_drawing_paddle_right done_drawing_paddle: bx lr update_display: ldr r2, =DRAW_SCREEN mov r3, #0 bx r2 check_victory: ldr r2, =PLAYER_ONE_POINTS ldrb r3, [r2] ldr r2, =PLAYER_TWO_POINTS ldrb r4, [r2] ldr r2, =WINNING_SCORE ldrb r5, [r2] cmp r3, r5 jge player_one_wins cmp r4, r5 jge player_two_wins player_one_wins: ldr r2, =PLAYER_ONE_SCORE_TEXT ldr r3, =PLAYER_ONE_SCORE_STRING ldr r4, =PLAYER_ONE_POINTS b update_score_text player_two_wins: ldr r2, =PLAYER_TWO_SCORE_TEXT ldr r3, =PLAYER_TWO_SCORE_STRING ldr r4, =PLAYER_TWO_POINTS update_score_text: ldrb r5, [r4] add r3, r3, #1 strb r5, [r3] ldr r3, =LCD_TEXT ldr r5, [r2] ldr r6, [r3] str r5, [r6] b reset_game reset_game: ldr r2, =GAME_ACTIVE strb r2, #0 mov r2, #0 ldr r3, =PLAYER_ONE_POINTS strb r2, [r3] ldr r3, =PLAYER_TWO_POINTS strb r2, [r3] ldr r3, =BALL_X str r2, [r3] ldr r3, =BALL_Y str r2, [r3] b update_display main: b reset_game .data WINDOW_WIDTH: .int 128 WINDOW_HEIGHT: .int 64 BALL_SIZE: .int 2 BALL_X: .int 0 BALL_Y: .int 0 BALL_VELOCITY_X: .int 1 BALL_VELOCITY_Y: .int 1 BALL_ORIGINAL_X: .int 64 BALL_ORIGINAL_Y: .int 32 BALL_COLOR: .byte 1 PADDLE_WIDTH: .int 2 PADDLE_HEIGHT: .int 16 PADDLE_LEFT_X: .int 4 PADDLE_LEFT_Y: .int 24 PADDLE_RIGHT_X: .int 122 PADDLE_RIGHT_Y: .int 24 PADDLE_COLOR: .byte 1 PADDLE_VELOCITY: .int 2 PLAYER_ONE_POINTS: .byte 0 PLAYER_TWO_POINTS: .byte 0 WINNING_SCORE: .byte 5 PLAYER_ONE_SCORE_TEXT: .asciz "Player 1: " PLAYER_TWO_SCORE_TEXT: .asciz "Player 2: " PLAYER_ONE_SCORE_STRING: .byte 0 PLAYER_TWO_SCORE_STRING: .byte 0 LCD_TEXT: .int 0x60000000 DRAW_PIXEL: .int 0x60000014 DRAW_RECTANGLE: .int 0x60000028 DRAW_SCREEN: .int 0x6000003C WINDOW_BOUNDS: .int 0x00000100 GAME_ACTIVE: .byte 0 .text
Editor is loading...