From 8395128efa6f57a0a529fadd8f6b3a18a3205ab1 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 21 Dec 2023 21:18:01 -0600 Subject: [PATCH] [teagba] Update to newer conventions --- deps/teagba/include/teagba/addresses.hpp | 6 ++-- deps/teagba/include/teagba/registers.hpp | 35 +++++++----------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/deps/teagba/include/teagba/addresses.hpp b/deps/teagba/include/teagba/addresses.hpp index e84bc8bd..bfeff546 100644 --- a/deps/teagba/include/teagba/addresses.hpp +++ b/deps/teagba/include/teagba/addresses.hpp @@ -49,7 +49,7 @@ using BgCtl = uint16_t; #define REG_BG3CTL *reinterpret_cast(0x0400'000e) [[nodiscard]] -inline auto ®BgCtl(uintptr_t bgIdx) noexcept { +inline volatile BgCtl ®BgCtl(uintptr_t bgIdx) noexcept { return *reinterpret_cast(0x0400'0008 + 2 * bgIdx); } @@ -60,7 +60,7 @@ inline auto ®BgCtl(uintptr_t bgIdx) noexcept { #define REG_BG3HOFS *reinterpret_cast(0x0400'001c) [[nodiscard]] -inline volatile auto ®BgHofs(auto bgIdx) noexcept { +inline volatile uint32_t ®BgHofs(auto bgIdx) noexcept { return *reinterpret_cast(0x0400'0010 + 4 * bgIdx); } @@ -71,7 +71,7 @@ inline volatile auto ®BgHofs(auto bgIdx) noexcept { #define REG_BG3VOFS *reinterpret_cast(0x0400'001e) [[nodiscard]] -inline volatile auto ®BgVofs(auto bgIdx) noexcept { +inline volatile uint32_t ®BgVofs(auto bgIdx) noexcept { return *reinterpret_cast(0x0400'0012 + 4 * bgIdx); } diff --git a/deps/teagba/include/teagba/registers.hpp b/deps/teagba/include/teagba/registers.hpp index 02d5dbba..a807165f 100644 --- a/deps/teagba/include/teagba/registers.hpp +++ b/deps/teagba/include/teagba/registers.hpp @@ -8,8 +8,8 @@ namespace teagba { -inline auto bgSetSbb(volatile BgCtl *bgCtl, unsigned sbb) noexcept { - *bgCtl = static_cast(*bgCtl & ~0b11111'0000'0000u) | static_cast(sbb << 8); +inline auto bgSetSbb(volatile BgCtl &bgCtl, unsigned sbb) noexcept { + bgCtl = static_cast(bgCtl & ~0b11111'0000'0000u) | static_cast(sbb << 8); } [[nodiscard]] @@ -17,14 +17,9 @@ constexpr unsigned bgPri(BgCtl bgCtl) noexcept { return bgCtl & 1; } -[[nodiscard]] -inline auto bgPri(const volatile BgCtl *bgCtl) noexcept { - return bgPri(*bgCtl); -} - -inline auto bgSetPri(volatile BgCtl *bgCtl, unsigned pri) noexcept { +inline auto bgSetPri(volatile BgCtl &bgCtl, unsigned pri) noexcept { pri = pri & 0b1; - *bgCtl = static_cast(*bgCtl & ~0b1u) | static_cast(pri << 0); + bgCtl = static_cast(bgCtl & ~0b1u) | static_cast(pri << 0); } [[nodiscard]] @@ -32,17 +27,12 @@ constexpr unsigned bgBpp(BgCtl bgCtl) noexcept { return ((bgCtl >> 7) & 1) ? 8 : 4; } -[[nodiscard]] -inline auto bgBpp(const volatile BgCtl *bgCtl) noexcept { - return bgBpp(*bgCtl); -} - -inline auto bgSetBpp(volatile BgCtl *bgCtl, unsigned bpp) noexcept { +inline auto bgSetBpp(volatile BgCtl &bgCtl, unsigned bpp) noexcept { constexpr auto Bpp8 = 1 << 7; if (bpp == 4) { - *bgCtl = *bgCtl | ((*bgCtl | Bpp8) ^ Bpp8); // set to use 4 bits per pixel + bgCtl = bgCtl | ((bgCtl | Bpp8) ^ Bpp8); // set to use 4 bits per pixel } else { - *bgCtl = *bgCtl | Bpp8; // set to use 8 bits per pixel + bgCtl = bgCtl | Bpp8; // set to use 8 bits per pixel } } @@ -51,19 +41,14 @@ constexpr auto bgCbb(BgCtl bgCtl) noexcept { return (bgCtl >> 2) & 0b11u; } -[[nodiscard]] -inline auto bgCbb(const volatile BgCtl *bgCtl) noexcept { - return bgCbb(*bgCtl); -} - -inline auto bgSetCbb(volatile BgCtl *bgCtl, unsigned cbb) noexcept { +inline auto bgSetCbb(volatile BgCtl &bgCtl, unsigned cbb) noexcept { cbb = cbb & 0b11; - *bgCtl = static_cast(*bgCtl & ~0b1100u) | static_cast(cbb << 2); + bgCtl = static_cast(bgCtl & ~0b1100u) | static_cast(cbb << 2); } constexpr void iterateBgCtl(auto cb) noexcept { for (auto bgCtl = ®_BG0CTL; bgCtl <= ®_BG3CTL; bgCtl += 2) { - cb(bgCtl); + cb(*bgCtl); } }