Skip to content

Commit

Permalink
Remove the compatibility padding for non-stm32
Browse files Browse the repository at this point in the history
Not needed elsewhere. Reduces RAM usage for the API to 64 bytes
  • Loading branch information
Daft-Freak committed Jul 1, 2024
1 parent de8aa17 commit 7cfbb06
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
6 changes: 1 addition & 5 deletions 32blit-pico/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static GameMetadata get_metadata() {
// blit API
static const blit::APIConst blit_api_const {
blit::api_version_major, blit::api_version_minor,
{},

::channels,

::set_screen_mode,
Expand Down Expand Up @@ -142,20 +142,16 @@ static const blit::APIConst blit_api_const {
::is_multiplayer_connected,
::set_multiplayer_enabled,
::send_multiplayer_message,
0,

nullptr, // flash_to_tmp
nullptr, // tmp_file_closed

::get_metadata,

0,

::set_screen_mode_format,

nullptr, // i2c_send
nullptr, // i2c_recieve
0,

nullptr, // set_raw_cdc_enabled
nullptr, // cdc_write
Expand Down
5 changes: 0 additions & 5 deletions 32blit-sdl/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void blit_send_message(const uint8_t *data, uint16_t length) {
// blit API
static const blit::APIConst blit_api_const {
blit::api_version_major, blit::api_version_minor,
{},
channels,

::set_screen_mode,
Expand Down Expand Up @@ -215,20 +214,16 @@ static const blit::APIConst blit_api_const {
blit_is_multiplayer_connected,
blit_set_multiplayer_enabled,
blit_send_message,
0,

nullptr, // flash_to_tmp
nullptr, // tmp_file_closed

::get_metadata,

0,

::set_screen_mode_format,

nullptr, // i2c_send
nullptr, // i2c_recieve
0,

nullptr, // set_raw_cdc_enabled
nullptr, // cdc_write
Expand Down
4 changes: 4 additions & 0 deletions 32blit-stm32/Src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
extern char __api_start;
#pragma GCC diagnostic ignored "-Warray-bounds"

#ifndef BLIT_API_SPLIT_COMPAT
#error "BLIT_API_SPLIT_COMPAT not set!"
#endif

namespace blit {
// for compatibility reasons, these are the same thing
const APIConst &api = *(APIConst *)&__api_start;
Expand Down
2 changes: 1 addition & 1 deletion 32blit.toolchain
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif ()

set(CDC_FIFO_BUFFERS 64)

set(COMMON_FLAGS "${MCU_FLAGS} -fsingle-precision-constant -Wall -fdata-sections -ffunction-sections -Wattributes -Wdouble-promotion -Werror=double-promotion -mno-pic-data-is-text-relative -mno-single-pic-base")
set(COMMON_FLAGS "${MCU_FLAGS} -fsingle-precision-constant -Wall -fdata-sections -ffunction-sections -Wattributes -Wdouble-promotion -Werror=double-promotion -mno-pic-data-is-text-relative -mno-single-pic-base -DBLIT_API_SPLIT_COMPAT")

set(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} -fno-exceptions")
Expand Down
27 changes: 19 additions & 8 deletions 32blit/engine/api_private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include "../types/vec2.hpp"
#include "../types/vec3.hpp"

// compatibility with API layout before const/data split
#ifdef BLIT_API_SPLIT_COMPAT
#define COMPAT_PAD(type, name, size) type name[size]
#else
#define COMPAT_PAD(type, name, size)
#endif

namespace blit {

using AllocateCallback = uint8_t *(*)(size_t);
Expand Down Expand Up @@ -66,7 +73,7 @@ namespace blit {
uint16_t version_major;
uint16_t version_minor;

uint8_t pad[48]; // was data
COMPAT_PAD(uint8_t, pad, 48); // was data

AudioChannel *channels;

Expand Down Expand Up @@ -114,21 +121,21 @@ namespace blit {
bool (*is_multiplayer_connected)();
void (*set_multiplayer_enabled)(bool enabled);
void (*send_message)(const uint8_t *data, uint16_t len);
uintptr_t pad2; // was message_recieved
COMPAT_PAD(uintptr_t, pad2, 1); // was message_recieved

const uint8_t *(*flash_to_tmp)(const std::string &filename, uint32_t &size);
void (*tmp_file_closed)(const uint8_t *ptr);

GameMetadata (*get_metadata)();

uint8_t pad3; // was data
COMPAT_PAD(uint8_t, pad3, 1); // was data

bool (*set_screen_mode_format)(ScreenMode new_mode, SurfaceTemplate &new_surf_template);

// raw i2c access
bool (*i2c_send)(uint8_t address, uint8_t reg, const uint8_t *data, uint16_t len);
bool (*i2c_receive)(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len);
uintptr_t pad4; // was i2c_completed
COMPAT_PAD(uintptr_t, pad4, 1); // was i2c_completed

// raw cdc
bool (*set_raw_cdc_enabled)(bool enabled);
Expand All @@ -153,26 +160,30 @@ namespace blit {
Vec3 tilt;
Pen LED;

uintptr_t pad2[32];
COMPAT_PAD(uintptr_t, pad2, 32);

// multiplayer
void (*message_received)(const uint8_t *data, uint16_t len); // set by user

uintptr_t pad3[3];
COMPAT_PAD(uintptr_t, pad3, 3);

bool tick_function_changed;

uintptr_t pad4[3];
COMPAT_PAD(uintptr_t, pad4, 3);

// raw i2c access
void (*i2c_completed)(uint8_t address, uint8_t reg, const uint8_t *data, uint16_t len); // callback when done

uintptr_t pad5[5];
COMPAT_PAD(uintptr_t, pad5, 5);
};

#pragma pack(pop)

#ifdef BLIT_API_SPLIT_COMPAT
static_assert(sizeof(APIConst) == sizeof(APIData));
#else
static_assert(sizeof(APIData) <= 256);
#endif

extern const APIConst &api;
extern APIData &api_data;
Expand Down

0 comments on commit 7cfbb06

Please sign in to comment.