diff options
| -rw-r--r-- | libs/SDL.S | 1 | ||||
| -rw-r--r-- | libs/SDL/rect.S | 10 | ||||
| -rw-r--r-- | src/helpers/function.S | 12 | ||||
| -rw-r--r-- | src/main.S | 21 |
4 files changed, 42 insertions, 2 deletions
@@ -1,4 +1,5 @@ #include "SDL/error.S" #include "SDL/init.S" +#include "SDL/rect.S" #include "SDL/render.S" #include "SDL/video.S"
\ No newline at end of file diff --git a/libs/SDL/rect.S b/libs/SDL/rect.S new file mode 100644 index 0000000..f402324 --- /dev/null +++ b/libs/SDL/rect.S @@ -0,0 +1,10 @@ +//! @file rect.S +//! +//! Assembler bindings for SDL2 (SDL_rect.h) + +#define OFFSET_SDL_Rect_x 0 +#define OFFSET_SDL_Rect_y 4 +#define OFFSET_SDL_Rect_w 8 +#define OFFSET_SDL_Rect_h 12 + +#define SIZE_SDL_Rect 16
\ No newline at end of file diff --git a/src/helpers/function.S b/src/helpers/function.S index 5d9c155..af41905 100644 --- a/src/helpers/function.S +++ b/src/helpers/function.S @@ -52,6 +52,13 @@ mov \register, .L\scope\()_\name\()(%rbp) .endm +.macro _function_address_of_local scope, name, register + _function_require_locals + lea .L\scope\()_\name\()(%rbp), \register +.endm + + + .macro function_begin name _function_require_no_function @@ -66,6 +73,10 @@ _function_allocate_local_variables \name .endm + .macro address_of_local var_name, register + _function_address_of_local \name, \var_name, \register + .endm + .macro load_local var_name, register _function_load_local \name, \var_name, \register .endm @@ -92,6 +103,7 @@ .set .L_FUNCTION_IS_IN_FUNCTION_DEFINITION, 0 .set .L_FUNCTION_LOCALS_ALLOCATED, 0 .purgem allocate_locals + .purgem address_of_local .purgem function_end .purgem function_exit .purgem load_local @@ -1,5 +1,6 @@ #include "helpers/function.S" #include "SDL/init.S" +#include "SDL/rect.S" #include "SDL/render.S" #include "SDL/video.S" @@ -27,6 +28,7 @@ define_local window_handle, 8 define_local renderer_handle, 8 + define_local rect, SIZE_SDL_Rect allocate_locals // initialize SDL @@ -61,7 +63,7 @@ lea failed_to_create_window(%rip), %rdi call _print_sdl_error@PLT mov $1, %rax - function_exit + jmp .Lquit_sdl 1: lea succeeded_to_create_window(%rip), %rdi xor %rax, %rax @@ -85,16 +87,31 @@ xor %rax, %rax call printf@PLT + mov $(SCREEN_HEIGHT / 2), %r8 + mov $(SCREEN_WIDTH / 2), %r9 + + address_of_local rect, %rdi + mov %r8, OFFSET_SDL_Rect_w(%rdi) + mov %r8, OFFSET_SDL_Rect_h(%rdi) + mov %r9, %r10 + shr $1, %r9 + sub %r9, %r10 + mov %r10, OFFSET_SDL_Rect_x(%rdi) + mov %r8, %r10 + sub %r9, %r10 + mov %r10, OFFSET_SDL_Rect_y(%rdi) + .Ldestroy_renderer: // destroy the renderer load_local renderer_handle, %rdi - call SDL_DestroyRenderer + call SDL_DestroyRenderer@PLT .Ldestroy_window: // destroy the window load_local window_handle, %rdi call SDL_DestroyWindow@PLT + .Lquit_sdl: call SDL_Quit@PLT xor %rax, %rax |
