From 189d92f96c76296a2565a6d9812f4cfe5381fef4 Mon Sep 17 00:00:00 2001 From: Gustavo Valiente Date: Sun, 6 Dec 2020 19:00:31 +0100 Subject: [PATCH] butano: sram code moved back from rom to ewram, since doing that doesn't make No$gba crash anymore --- butano/hw/include/bn_hw_sram.h | 4 +-- butano/hw/src/bn_hw_sram.bn_ewram.cpp | 41 +++++++++++++++++++++++++++ butano/hw/src/bn_hw_sram.cpp | 28 ------------------ butano/include/bn_documentation.h | 1 + docs/changelog.html | 2 +- 5 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 butano/hw/src/bn_hw_sram.bn_ewram.cpp diff --git a/butano/hw/include/bn_hw_sram.h b/butano/hw/include/bn_hw_sram.h index cc2329071..f2c96c402 100644 --- a/butano/hw/include/bn_hw_sram.h +++ b/butano/hw/include/bn_hw_sram.h @@ -12,9 +12,9 @@ namespace bn::hw::sram { void init(); - void write(const void* source, int size, int offset); + BN_CODE_EWRAM void write(const void* source, int size, int offset); - void read(void* destination, int size, int offset); + BN_CODE_EWRAM void read(void* destination, int size, int offset); } #endif diff --git a/butano/hw/src/bn_hw_sram.bn_ewram.cpp b/butano/hw/src/bn_hw_sram.bn_ewram.cpp new file mode 100644 index 000000000..0e735dec8 --- /dev/null +++ b/butano/hw/src/bn_hw_sram.bn_ewram.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 Gustavo Valiente gustavo.valiente@protonmail.com + * zlib License, see LICENSE file. + */ + +#include "../include/bn_hw_sram.h" + +#include "../include/bn_hw_tonc.h" + +namespace bn::hw::sram +{ + +void write(const void* source, int size, int offset) +{ + // This code should go in WRAM: + // http://problemkaputt.de/gbatek.htm#gbacartbackupsramfram (Reading and Writing section) + + volatile const uint8_t* source_ptr = static_cast(source); + volatile uint8_t* sram_ptr = reinterpret_cast(MEM_SRAM) + offset; + + for(int i = 0; i < size; i++) + { + sram_ptr[i] = source_ptr[i]; + } +} + +void read(void* destination, int size, int offset) +{ + // This code should go in WRAM: + // http://problemkaputt.de/gbatek.htm#gbacartbackupsramfram (Reading and Writing section) + + volatile const uint8_t* sram_ptr = reinterpret_cast(MEM_SRAM) + offset; + volatile uint8_t* destination_ptr = static_cast(destination); + + for(int i = 0; i < size; i++) + { + destination_ptr[i] = sram_ptr[i]; + } +} + +} diff --git a/butano/hw/src/bn_hw_sram.cpp b/butano/hw/src/bn_hw_sram.cpp index 901687fa0..ad5d97f4f 100644 --- a/butano/hw/src/bn_hw_sram.cpp +++ b/butano/hw/src/bn_hw_sram.cpp @@ -27,32 +27,4 @@ void init() BIT_SET(REG_WAITCNT_NV, BN_CFG_SRAM_WAIT_STATE); } -void write(const void* source, int size, int offset) -{ - // Maybe it should go in WRAM, but doing that crashes No$gba: - // http://problemkaputt.de/gbatek.htm#gbacartbackupsramfram (Reading and Writing section) - - volatile const uint8_t* source_ptr = static_cast(source); - volatile uint8_t* sram_ptr = reinterpret_cast(MEM_SRAM) + offset; - - for(int i = 0; i < size; i++) - { - sram_ptr[i] = source_ptr[i]; - } -} - -void read(void* destination, int size, int offset) -{ - // Maybe it should go in WRAM, but doing that crashes No$gba: - // http://problemkaputt.de/gbatek.htm#gbacartbackupsramfram (Reading and Writing section) - - volatile const uint8_t* sram_ptr = reinterpret_cast(MEM_SRAM) + offset; - volatile uint8_t* destination_ptr = static_cast(destination); - - for(int i = 0; i < size; i++) - { - destination_ptr[i] = sram_ptr[i]; - } -} - } diff --git a/butano/include/bn_documentation.h b/butano/include/bn_documentation.h index 4874f6bea..bf19736f6 100644 --- a/butano/include/bn_documentation.h +++ b/butano/include/bn_documentation.h @@ -1090,6 +1090,7 @@ * * * H-Blank effects EWRAM usage reduced (more than 2KB by default). * * Optimization level changed to `-O2` to avoid another No$gba crash. + * * SRAM code moved back from ROM to EWRAM, since doing that doesn't make No$gba crash anymore. * * * @section changelog_4_2_0 4.2.0 diff --git a/docs/changelog.html b/docs/changelog.html index b0ebdf4a2..0269dbace 100644 --- a/docs/changelog.html +++ b/docs/changelog.html @@ -69,7 +69,7 @@

Contents

  • 0.1.0
  • -

    4.3.0 (next release)

    • H-Blank effects EWRAM usage reduced (more than 2KB by default).
    • Optimization level changed to -O2 to avoid another No$gba crash.

    4.2.0

    • Sprite and background palettes can be generated from images alone, without tiles nor maps.
    • <cstddef> is always included (bn_cstddef.h header file removed).
    • bn::unordered_map and bn::unordered_set assignment fixed.

    4.1.0

    • H-Blank effects optimized (it fixes world_map example flickering).
    • SRAM code moved from EWRAM to ROM to avoid a No$gba crash.

    4.0.0

    3.3.0

    • HDMA properly supported (now it works at less than 60fps). See bn::hdma and the hdma_polygons example for more.
    • gba-link-connection remote timeout detection fixed.

    3.2.1

    bn::optional build fix.

    3.2.0

    bn::optional is now constexpr.

    3.1.0

    3.0.0

    Thanks to the awesome gba-link-connection, multiplayer support has been implemented! See bn::link and the link example for more.

    2.0.0

    • By removing some method overloads, lots of runtime asserts when creating resources have been removed.
    • bn::palette_bpp_mode has been renamed to bn::bpp_mode and bpp_mode() methods have been renamed to bpp().
    • 8 bits per pixel background tiles allocation fixed.

    1.0.0

    0.4.0

    • btn renamed to bn. No more API breaks will be made between minor releases after 1.0.0, promise.
    • Background tiles manager status can be printed in the log with bn::bg_tiles::log_status(). This is done automatically when a non-optional background tiles allocation fails too.
    • Background regular maps manager status can be printed in the log with bn::bg_maps::log_status(). This is done automatically when a non-optional regular background map allocation fails too.
    • Sprite tiles manager status can be printed in the log with bn::sprite_tiles::log_status(). This is done automatically when a non-optional sprite tiles allocation fails too.
    • Color palettes managers status can be printed in the log with bn::bg_palettes::log_status() and bn::sprite_palettes::log_status(). This is done automatically when a non-optional color palette allocation fails too.
    • Sprites destruction optimized.
    • Setters with an optional parameter added to some classes.
    • Optional components documentation fixed.
    • Other documentation improvements.

    0.3.0

    • Sprites update performance improved up to 30% in Butano Fighter thanks to avoid rebuilding sprites list as much as possible.
    • Profiler can show the maximum measured ticks per entry.
    • Assets tools print output binaries size.

    0.2.0

    • Performance improved up to 12% in Butano Fighter without -flto thanks to using less build translation units.
    • Documentation improved.

    0.1.0

    First release.

    +

    4.3.0 (next release)

    • H-Blank effects EWRAM usage reduced (more than 2KB by default).
    • Optimization level changed to -O2 to avoid another No$gba crash.
    • SRAM code moved back from ROM to EWRAM, since doing that doesn't make No$gba crash anymore.

    4.2.0

    • Sprite and background palettes can be generated from images alone, without tiles nor maps.
    • <cstddef> is always included (bn_cstddef.h header file removed).
    • bn::unordered_map and bn::unordered_set assignment fixed.

    4.1.0

    • H-Blank effects optimized (it fixes world_map example flickering).
    • SRAM code moved from EWRAM to ROM to avoid a No$gba crash.

    4.0.0

    3.3.0

    • HDMA properly supported (now it works at less than 60fps). See bn::hdma and the hdma_polygons example for more.
    • gba-link-connection remote timeout detection fixed.

    3.2.1

    bn::optional build fix.

    3.2.0

    bn::optional is now constexpr.

    3.1.0

    3.0.0

    Thanks to the awesome gba-link-connection, multiplayer support has been implemented! See bn::link and the link example for more.

    2.0.0

    • By removing some method overloads, lots of runtime asserts when creating resources have been removed.
    • bn::palette_bpp_mode has been renamed to bn::bpp_mode and bpp_mode() methods have been renamed to bpp().
    • 8 bits per pixel background tiles allocation fixed.

    1.0.0

    0.4.0

    • btn renamed to bn. No more API breaks will be made between minor releases after 1.0.0, promise.
    • Background tiles manager status can be printed in the log with bn::bg_tiles::log_status(). This is done automatically when a non-optional background tiles allocation fails too.
    • Background regular maps manager status can be printed in the log with bn::bg_maps::log_status(). This is done automatically when a non-optional regular background map allocation fails too.
    • Sprite tiles manager status can be printed in the log with bn::sprite_tiles::log_status(). This is done automatically when a non-optional sprite tiles allocation fails too.
    • Color palettes managers status can be printed in the log with bn::bg_palettes::log_status() and bn::sprite_palettes::log_status(). This is done automatically when a non-optional color palette allocation fails too.
    • Sprites destruction optimized.
    • Setters with an optional parameter added to some classes.
    • Optional components documentation fixed.
    • Other documentation improvements.

    0.3.0

    • Sprites update performance improved up to 30% in Butano Fighter thanks to avoid rebuilding sprites list as much as possible.
    • Profiler can show the maximum measured ticks per entry.
    • Assets tools print output binaries size.

    0.2.0

    • Performance improved up to 12% in Butano Fighter without -flto thanks to using less build translation units.
    • Documentation improved.

    0.1.0

    First release.