Skip to content

Commit

Permalink
butano: subsystems rom usage reduced (thanks felixjones!)
Browse files Browse the repository at this point in the history
  • Loading branch information
GValiente committed Oct 1, 2023
1 parent 2a22a86 commit 3dceb60
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 32 deletions.
6 changes: 4 additions & 2 deletions butano/hw/src/bn_hw_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace
bool dmg_sync = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;


constexpr int _mix_length()
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace

constexpr int _max_channels = BN_CFG_AUDIO_MAX_MUSIC_CHANNELS + BN_CFG_AUDIO_MAX_SOUND_CHANNELS;

alignas(int) BN_DATA_EWRAM uint8_t maxmod_engine_buffer[
alignas(int) BN_DATA_EWRAM_BSS uint8_t maxmod_engine_buffer[
_max_channels * (MM_SIZEOF_MODCH + MM_SIZEOF_ACTCH + MM_SIZEOF_MIXCH) + _mix_length()];

alignas(int) uint8_t maxmod_mixing_buffer[_mix_length()];
Expand Down Expand Up @@ -194,6 +194,8 @@ namespace

void init()
{
new(&data) static_data();

irq::set_isr(irq::id::VBLANK, mmVBlank);
irq::enable(irq::id::VBLANK);

Expand Down
4 changes: 3 additions & 1 deletion butano/hw/src/bn_hw_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace
bool active = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;

void _check_active()
{
Expand Down Expand Up @@ -111,6 +111,8 @@ namespace

void init()
{
new(&data) static_data();

data.connection.init(_sendDataCallback, _receiveResponseCallback, _resetStateCallback);
irq::set_isr(irq::id::SERIAL, _serial_intr);
irq::set_isr(irq::id::TIMER1, _timer_intr);
Expand Down
2 changes: 1 addition & 1 deletion butano/hw/src/bn_hw_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static_assert(BN_CFG_EWRAM_WAIT_STATE == BN_EWRAM_WAIT_STATE_2 ||
#if BN_CFG_EWRAM_WAIT_STATE == BN_EWRAM_WAIT_STATE_1
namespace
{
BN_DATA_EWRAM unsigned ewram_data;
BN_DATA_EWRAM_BSS unsigned ewram_data;
}
#endif

Expand Down
1 change: 1 addition & 0 deletions butano/include/bn_documentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,7 @@
* * bn::assert::callback and bn::assert::set_callback added.
* * `BN_DATA_EWRAM_BSS` added.
* * bn::memory::used_static_ewram fixed.
* * Butano subsystems ROM usage reduced.
* * <a href="https://www.coranac.com/projects/#tonc">Tonclib</a> tiled surface functions added.
* * Unused <a href="https://www.coranac.com/projects/#tonc">Tonclib</a> functions and data removed.
*
Expand Down
4 changes: 3 additions & 1 deletion butano/src/bn_audio_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,13 @@ namespace
bool dmg_sync_enabled = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;
}

void init()
{
new(&data) static_data();

hw::audio::init();
}

Expand Down
9 changes: 5 additions & 4 deletions butano/src/bn_bg_blocks_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ namespace
}
};

void init()
items_list()
{
for(int index = 0; index < max_items; ++index)
{
Expand Down Expand Up @@ -384,7 +384,7 @@ namespace

private:
item_type _items[max_list_items];
alignas(int) int8_t _free_indices_array[max_items] = {};
alignas(int) int8_t _free_indices_array[max_items];
int _free_indices_size = max_items;

void _join(int index, int new_index)
Expand Down Expand Up @@ -437,7 +437,7 @@ namespace
bool delay_commit = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;


struct create_data
Expand Down Expand Up @@ -1166,11 +1166,12 @@ namespace

void init()
{
new(&data) static_data();

BN_BG_BLOCKS_LOG("bg_blocks_manager - INIT");

item_type new_item;
new_item.blocks_count = hw::bg_tiles::blocks_count();
data.items.init();
data.items.push_front(new_item);
data.free_blocks_count = new_item.blocks_count;

Expand Down
7 changes: 6 additions & 1 deletion butano/src/bn_bgs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ namespace
bool commit = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;


[[nodiscard]] bool _check_unique_regular_big_map(item_type& item)
Expand Down Expand Up @@ -502,6 +502,11 @@ namespace
}
}

void init()
{
new(&data) static_data();
}

int used_count()
{
return data.items_vector.size();
Expand Down
2 changes: 2 additions & 0 deletions butano/src/bn_bgs_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace bgs_manager
{
using id_type = void*;

void init();

[[nodiscard]] int used_count();

[[nodiscard]] int available_count();
Expand Down
6 changes: 4 additions & 2 deletions butano/src/bn_cameras_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ namespace

public:
item_type items[max_items];
alignas(int) uint8_t free_item_indexes_array[max_items] = {};
alignas(int) uint8_t free_item_indexes_array[max_items];
int free_item_indexes_size = max_items;
bool update = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;
}

void init()
{
new(&data) static_data();

for(int index = 0; index < max_items; ++index)
{
data.free_item_indexes_array[index] = uint8_t(index);
Expand Down
21 changes: 14 additions & 7 deletions butano/src/bn_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace
volatile bool waiting_for_vblank = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;

void enable()
{
Expand Down Expand Up @@ -311,13 +311,24 @@ void init()

void init(const string_view& keypad_commands)
{
new(&data) static_data();

// Initial wait:
hw::core::init();

// Init H-Blank effects system:
hblank_effects_manager::init();

// Init irq system:
hw::irq::init();
hw::irq::set_isr(hw::irq::id::HBLANK, hw::hblank_effects::_intr);

// Init hdma system:
hdma_manager::init();

// Init link system:
link_manager::init();

// Init audio system:
audio_manager::init();

Expand All @@ -330,18 +341,14 @@ void init(const string_view& keypad_commands)
// Init display:
display_manager::init();

// Init H-Blank effects system:
hblank_effects_manager::init();

// Init link system:
link_manager::init();

// Init high level systems:
memory_manager::init();
cameras_manager::init();
palettes_manager::init();
sprite_tiles_manager::init();
sprites_manager::init();
bg_blocks_manager::init();
bgs_manager::init();
keypad_manager::init(keypad_commands);

// First update:
Expand Down
4 changes: 3 additions & 1 deletion butano/src/bn_display_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace
bool commit_green_swap = false;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;

[[nodiscard]] pair<int, int> _blending_hw_weights(fixed top_weight, fixed bottom_weight)
{
Expand Down Expand Up @@ -101,6 +101,8 @@ namespace

void init()
{
new(&data) static_data();

unsigned initial_window_flags =
unsigned(hw::display::window_flag::SPRITES) |
unsigned(hw::display::window_flag::BLENDING);
Expand Down
1 change: 1 addition & 0 deletions butano/src/bn_gpio_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "bn_gpio_manager.h"

#include <new>
#include "../hw/include/bn_hw_gpio.h"

#include "bn_rumble.cpp.h"
Expand Down
4 changes: 3 additions & 1 deletion butano/src/bn_hblank_effects_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ namespace
hw_entries entries_b;
};

BN_DATA_EWRAM static_external_data external_data;
BN_DATA_EWRAM_BSS static_external_data external_data;
static_internal_data internal_data;

void _update_visible_item_index(int item_index)
Expand Down Expand Up @@ -1144,6 +1144,8 @@ namespace

void init()
{
new(&external_data) static_external_data();

hw::hblank_effects::commit_entries(internal_data.entries_b);

for(int index = max_items - 1; index >= 0; --index)
Expand Down
8 changes: 7 additions & 1 deletion butano/src/bn_hdma_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "bn_hdma_manager.h"

#include <new>
#include "bn_display.h"
#include "../hw/include/bn_hw_dma.h"
#include "../hw/include/bn_hw_memory.h"
Expand Down Expand Up @@ -149,7 +150,12 @@ namespace
entry high_priority_entry = entry(hw::dma::high_priority_channel());
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;
}

void init()
{
new(&data) static_data();
}

void enable()
Expand Down
2 changes: 2 additions & 0 deletions butano/src/bn_hdma_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace bn::hdma_manager
{
void init();

void enable();

void disable();
Expand Down
4 changes: 3 additions & 1 deletion butano/src/bn_keypad_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ namespace
#endif
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;
}

void init(const string_view& commands)
{
new(&data) static_data();

BN_ASSERT(commands.size() % 2 == 0, "Invalid commands size: ", commands.size());

data.commands = commands;
Expand Down
4 changes: 3 additions & 1 deletion butano/src/bn_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ namespace
best_fit_allocator allocator;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;
}

void init()
{
new(&data) static_data();

char* start = hw::memory::ewram_heap_start();
char* end = hw::memory::ewram_heap_end();
data.allocator.reset(static_cast<void*>(start), end - start);
Expand Down
7 changes: 6 additions & 1 deletion butano/src/bn_palettes_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ namespace
palettes_bank bg_palettes_bank;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;
}

void init()
{
new(&data) static_data();
}

palettes_bank& sprite_palettes_bank()
Expand Down
2 changes: 2 additions & 0 deletions butano/src/bn_palettes_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class palettes_bank;

namespace palettes_manager
{
void init();

[[nodiscard]] palettes_bank& sprite_palettes_bank();

[[nodiscard]] palettes_bank& bg_palettes_bank();
Expand Down
4 changes: 3 additions & 1 deletion butano/src/bn_sprite_affine_mats_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace
int last_index_to_remove_if_not_needed = 0;
};

BN_DATA_EWRAM static_data data;
BN_DATA_EWRAM_BSS static_data data;


void _update_flipped_identity(int index)
Expand Down Expand Up @@ -201,6 +201,8 @@ namespace

void init(void* handles)
{
new(&data) static_data();

data.handles_ptr = static_cast<hw::sprite_affine_mats::handle*>(handles);

for(int index = max_items - 1; index >= 0; --index)
Expand Down
Loading

0 comments on commit 3dceb60

Please sign in to comment.