diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-02-18 15:24:23 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-02-18 15:24:23 +0100 |
| commit | 943e24c81926f2392c341001cca69b58536c8129 (patch) | |
| tree | 4b1873fa69c75af91b33b3a384218f8a38743b1a /src | |
| parent | 2a1f31365dade481c32efc3307f94cc052d00f7f (diff) | |
| download | snake.s-943e24c81926f2392c341001cca69b58536c8129.tar.xz snake.s-943e24c81926f2392c341001cca69b58536c8129.zip | |
feat: create a simple square
Diffstat (limited to 'src')
| -rw-r--r-- | src/helpers/function.S | 12 | ||||
| -rw-r--r-- | src/main.S | 21 |
2 files changed, 31 insertions, 2 deletions
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 |
