From 2a1f31365dade481c32efc3307f94cc052d00f7f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 18 Feb 2026 13:19:52 +0100 Subject: refactor: split SDL bindings --- CMakeLists.txt | 12 ++++++++++++ libs/SDL.S | 4 ++++ libs/SDL/error.S | 8 ++++++++ libs/SDL/init.S | 31 +++++++++++++++++++++++++++++++ libs/SDL/render.S | 18 ++++++++++++++++++ libs/SDL/video.S | 23 +++++++++++++++++++++++ src/error.S | 1 + src/libs/sdl.S | 36 ------------------------------------ src/main.S | 4 +++- 9 files changed, 100 insertions(+), 37 deletions(-) create mode 100644 libs/SDL.S create mode 100644 libs/SDL/error.S create mode 100644 libs/SDL/init.S create mode 100644 libs/SDL/render.S create mode 100644 libs/SDL/video.S delete mode 100644 src/libs/sdl.S diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d88dcf..d8f7928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,17 @@ project("snake.s" find_package("SDL2" REQUIRED) +add_library("SDL2_bindings" INTERFACE + "libs/SDL.S" + "libs/SDL/init.S" + "libs/SDL/render.S" + "libs/SDL/video.S" +) + +target_include_directories("SDL2_bindings" INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/libs" +) + add_executable("snake.s" "src/error.S" "src/main.S" @@ -15,6 +26,7 @@ add_executable("snake.s" target_link_libraries("snake.s" PRIVATE "SDL2::SDL2" + "SDL2_bindings" ) install(TARGETS "snake.s") diff --git a/libs/SDL.S b/libs/SDL.S new file mode 100644 index 0000000..838f482 --- /dev/null +++ b/libs/SDL.S @@ -0,0 +1,4 @@ +#include "SDL/error.S" +#include "SDL/init.S" +#include "SDL/render.S" +#include "SDL/video.S" \ No newline at end of file diff --git a/libs/SDL/error.S b/libs/SDL/error.S new file mode 100644 index 0000000..19efb5a --- /dev/null +++ b/libs/SDL/error.S @@ -0,0 +1,8 @@ +//! @file error.S +//! +//! Assembler bindings for SDL2 (SDL_error.h) + +//! @fn char const * SDL_GetError(void) +//! @return the last error message +.type SDL_GetError, @function +.extern SDL_GetError \ No newline at end of file diff --git a/libs/SDL/init.S b/libs/SDL/init.S new file mode 100644 index 0000000..a2880c8 --- /dev/null +++ b/libs/SDL/init.S @@ -0,0 +1,31 @@ +//! @file init.S +//! +//! Assembler bindings for SDL2 (SDL.h) + +#define SDL_INIT_TIMER 0x00000001u +#define SDL_INIT_AUDIO 0x00000010u +#define SDL_INIT_VIDEO 0x00000020u +#define SDL_INIT_JOYSTICK 0x00000200u +#define SDL_INIT_HAPTIC 0x00001000u +#define SDL_INIT_GAMECONTROLLER 0x00002000u +#define SDL_INIT_EVENTS 0x00004000u +#define SDL_INIT_SENSOR 0x00008000u +#define SDL_INIT_NOPARACHUTE 0x00100000u +#define SDL_INIT_EVERYTHIN (SDL_INIT_TIMER | \ + SDL_INIT_AUDIO | \ + SDL_INIT_VIDEO | \ + SDL_INIT_EVENTS | \ + SDL_INIT_JOYSTICK | \ + SDL_INIT_HAPTIC | \ + SDL_INIT_GAMECONTROLLER | \ + SDL_INIT_SENSOR) + +//! @fn int SDL_Init(UInt32 flags) +//! @param flags subsystem initialization flags +//! @return 0 on success, a negative error code on failure +.type SDL_Init, @function +.extern SDL_Init + +//! @fn void SDL_Quit(void) +.type SDL_Quit, @function +.extern SDL_Quit \ No newline at end of file diff --git a/libs/SDL/render.S b/libs/SDL/render.S new file mode 100644 index 0000000..d422971 --- /dev/null +++ b/libs/SDL/render.S @@ -0,0 +1,18 @@ +//! @file render.S +//! +//! Assembler bindings for SDL2 (SDL_render.h) + +#define SDL_RENDERER_ACCELERATED 0x00000002u + +//! @fn SDL_Renderer * SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags); +//! @param the window where rendering is displayed. +//! @param index the index of the rendering driver to initialize, or -1 to initialize the first one supporting the requested flags +//! @param flags 0, or one or more SDL_RendererFlags OR'd together. +//! @return a valid rendering context or NULL on error. +.type SDL_CreateRenderer, @function +.extern SDL_CreateRenderer + +//! @fn void SDL_DestroyRenderer(SDL_Renderer * renderer); +//! @param renderer the renderer to destroy +.type SDL_DestroyRenderer, @function +.extern SDL_DestroyRenderer \ No newline at end of file diff --git a/libs/SDL/video.S b/libs/SDL/video.S new file mode 100644 index 0000000..f91cc89 --- /dev/null +++ b/libs/SDL/video.S @@ -0,0 +1,23 @@ +//! @file video.S +//! +//! Assembler bindings for SDL2 (SDL_video.h) + +#define SDL_WINDOW_SHOWN 0x00000004u + +#define SDL_WINDOWPOS_UNDEFINED 0x1FFF0000u + +//! @fn SDL_Window * SDL_CreateWindow(const char *title, int x, int y, int w, int h, uint32_t flags) +//! @param title the window title +//! @param x the X position of the window, or SDL_WINDOWPOS_UNDEFINED +//! @param y the Y position of the window, or SDL_WINDOWPOS_UNDEFINED +//! @param w the width of the window +//! @param h the height of the window +//! @param flags 0, or one or more SDL_WindowFlags OR'd together. +//! @return a valid window or NULL on error +.type SDL_CreateWindow, @function +.extern SDL_CreateWindow + +//! @fn void SDL_DestroyWindow(SDL_Window *window) +//! @param window the window to destroy +.type SDL_DestroyWindow, @function +.extern SDL_DestroyWindow diff --git a/src/error.S b/src/error.S index af441ce..44be8b0 100644 --- a/src/error.S +++ b/src/error.S @@ -1,4 +1,5 @@ #include "helpers/function.S" +#include "SDL/error.S" .section .text diff --git a/src/libs/sdl.S b/src/libs/sdl.S deleted file mode 100644 index 485dfd7..0000000 --- a/src/libs/sdl.S +++ /dev/null @@ -1,36 +0,0 @@ -//! @file sdl.S -//! -//! Assembler bindings for SDL2 - -#define SDL_INIT_TIMER 0x00000001u -#define SDL_INIT_AUDIO 0x00000010u -#define SDL_INIT_VIDEO 0x00000020u -#define SDL_INIT_JOYSTICK 0x00000200u -#define SDL_INIT_HAPTIC 0x00001000u -#define SDL_INIT_GAMECONTROLLER 0x00002000u - -#define SDL_RENDERER_ACCELERATED 0x00000002u - -#define SDL_WINDOW_SHOWN 0x00000004u - -#define SDL_WINDOWPOS_UNDEFINED 0x1FFF0000u - -// int SDL_Init(uint32_t flags) -.type SDL_Init, @function -.extern SDL_Init - -// SDL_Renderer * SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags); -.type SDL_CreateRenderer, @function -.extern SDL_CreateRenderer - -// SDL_Window * SDL_CreateWindow(const char *title, int x, int y, int w, int h, uint32_t flags) -.type SDL_CreateWindow, @function -.extern SDL_CreateWindow - -// void SDL_DestroyWindow(SDL_Window *window) -.type SDL_DestroyWindow, @function -.extern SDL_DestroyWindow - -// void SDL_Quit(void) -.type SDL_Quit, @function -.extern SDL_Quit \ No newline at end of file diff --git a/src/main.S b/src/main.S index 20d80e6..3a0da8a 100644 --- a/src/main.S +++ b/src/main.S @@ -1,5 +1,7 @@ #include "helpers/function.S" -#include "libs/sdl.S" +#include "SDL/init.S" +#include "SDL/render.S" +#include "SDL/video.S" #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 -- cgit v1.2.3