diff --git a/deps/teagba/include/teagba/addresses.hpp b/deps/teagba/include/teagba/addresses.hpp index 23380b12..6b2e5e20 100644 --- a/deps/teagba/include/teagba/addresses.hpp +++ b/deps/teagba/include/teagba/addresses.hpp @@ -54,25 +54,41 @@ inline volatile BgCtl ®BgCtl(uintptr_t const bgIdx) noexcept { } // background horizontal scrolling registers -#define REG_BG0HOFS (*reinterpret_cast(0x0400'0010)) -#define REG_BG1HOFS (*reinterpret_cast(0x0400'0014)) -#define REG_BG2HOFS (*reinterpret_cast(0x0400'0018)) -#define REG_BG3HOFS (*reinterpret_cast(0x0400'001c)) +#define REG_BG0HOFS (*reinterpret_cast(0x0400'0010)) +#define REG_BG1HOFS (*reinterpret_cast(0x0400'0014)) +#define REG_BG2HOFS (*reinterpret_cast(0x0400'0018)) +#define REG_BG3HOFS (*reinterpret_cast(0x0400'001c)) [[nodiscard]] -volatile uint32_t ®BgHofs(auto const bgIdx) noexcept { - return *reinterpret_cast(0x0400'0010 + 4 * bgIdx); +volatile int16_t ®BgHofs(auto const bgIdx) noexcept { + return *reinterpret_cast(0x0400'0010 + 4 * bgIdx); } // background vertical scrolling registers -#define REG_BG0VOFS (*reinterpret_cast(0x0400'0012)) -#define REG_BG1VOFS (*reinterpret_cast(0x0400'0016)) -#define REG_BG2VOFS (*reinterpret_cast(0x0400'001a)) -#define REG_BG3VOFS (*reinterpret_cast(0x0400'001e)) +#define REG_BG0VOFS (*reinterpret_cast(0x0400'0012)) +#define REG_BG1VOFS (*reinterpret_cast(0x0400'0016)) +#define REG_BG2VOFS (*reinterpret_cast(0x0400'001a)) +#define REG_BG3VOFS (*reinterpret_cast(0x0400'001e)) [[nodiscard]] -volatile uint32_t ®BgVofs(auto const bgIdx) noexcept { - return *reinterpret_cast(0x0400'0012 + 4 * bgIdx); +volatile int16_t ®BgVofs(auto const bgIdx) noexcept { + return *reinterpret_cast(0x0400'0012 + 4 * bgIdx); +} + +// background scrolling registers + +struct OffsetPair { + int16_t x{}, y{}; +}; + +#define REG_BG0OFS (*reinterpret_cast(0x0400'0010)) +#define REG_BG1OFS (*reinterpret_cast(0x0400'0014)) +#define REG_BG2OFS (*reinterpret_cast(0x0400'0018)) +#define REG_BG3OFS (*reinterpret_cast(0x0400'001c)) + +[[nodiscard]] +volatile OffsetPair ®BgOfs(auto const bgIdx) noexcept { + return *reinterpret_cast(0x0400'0010 + sizeof(OffsetPair) * bgIdx); } ///////////////////////////////////////////////////////////////// diff --git a/deps/teagba/include/teagba/gfx.hpp b/deps/teagba/include/teagba/gfx.hpp index bd18bb3f..4a252122 100644 --- a/deps/teagba/include/teagba/gfx.hpp +++ b/deps/teagba/include/teagba/gfx.hpp @@ -41,4 +41,8 @@ void addSpriteUpdate(GbaSpriteAttrUpdate const &upd) noexcept; void applySpriteUpdates() noexcept; +void setBgOffset(uint16_t bg, int16_t x, int16_t y) noexcept; + +void scrollBgOffset(uint16_t bg, int16_t x, int16_t y) noexcept; + } diff --git a/deps/teagba/src/gfx.cpp b/deps/teagba/src/gfx.cpp index b458eeff..cd1e38b3 100644 --- a/deps/teagba/src/gfx.cpp +++ b/deps/teagba/src/gfx.cpp @@ -12,7 +12,7 @@ namespace teagba { static ox::Array g_spriteBuffer; -GbaSpriteAttrUpdate &spriteAttr(size_t i) noexcept { +GbaSpriteAttrUpdate &spriteAttr(size_t const i) noexcept { return g_spriteBuffer[i]; } @@ -29,4 +29,16 @@ void applySpriteUpdates() noexcept { } } +void setBgOffset(uint16_t const bg, int16_t const x, int16_t const y) noexcept { + auto &o = regBgOfs(bg); + o.x = x; + o.y = y; +} + +void scrollBgOffset(uint16_t const bg, int16_t const x, int16_t const y) noexcept { + auto &o = regBgOfs(bg); + o.x = o.x + x; + o.y = o.y + y; +} + }