From 9840b6fdee26aca36771e8576d2cc88cbbb87a9f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 20 Dec 2023 19:00:23 -0600 Subject: [PATCH] [nostalgia/core] Add a background priority option --- .../core/include/nostalgia/core/gfx.hpp | 2 ++ src/nostalgia/modules/core/src/gba/gfx.cpp | 28 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp index d47763cd..6191cc7d 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp @@ -52,6 +52,8 @@ void setBgStatus(Context &ctx, unsigned bg, bool status) noexcept; void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbb) noexcept; +void setBgPriority(Context &ctx, uint_t bgIdx, uint_t priority) noexcept; + /** * @param section describes which section of the selected TileSheetSpace to use (e.g. MEM_PALLETE_BG[section]) */ diff --git a/src/nostalgia/modules/core/src/gba/gfx.cpp b/src/nostalgia/modules/core/src/gba/gfx.cpp index 2968dc28..ca0352c3 100644 --- a/src/nostalgia/modules/core/src/gba/gfx.cpp +++ b/src/nostalgia/modules/core/src/gba/gfx.cpp @@ -97,15 +97,16 @@ void setBgStatus(Context&, unsigned bg, bool status) noexcept { REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask); } -static void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept { +void setBgCbb(Context&, unsigned bgIdx, unsigned cbb) noexcept { auto &bgCtl = regBgCtl(bgIdx); const auto &cbbData = g_cbbData[cbb]; teagba::bgSetBpp(&bgCtl, cbbData.bpp); teagba::bgSetCbb(&bgCtl, cbb); } -void setBgCbb(Context&, unsigned bgIdx, unsigned cbb) noexcept { - setBgCbb(nullptr, bgIdx, cbb); +void setBgPriority(Context&, uint_t bgIdx, uint_t priority) noexcept { + auto &bgCtl = regBgCtl(bgIdx); + bgCtl = (bgCtl & 0b1111'1111'1111'1100u) | (priority & 0b11); } static ox::Error loadBgTileSheet( @@ -215,24 +216,24 @@ void clearTileLayer(Context&, unsigned bgIdx) noexcept { [[maybe_unused]] void hideSprite(Context&, unsigned idx) noexcept { //oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); - teagba::GbaSpriteAttrUpdate oa; - oa.attr0 = uint16_t{0b11 << 8}; - oa.idx = static_cast(idx); - teagba::addSpriteUpdate(oa); + teagba::addSpriteUpdate({ + .attr0 = uint16_t{0b11 << 8}, + .idx = static_cast(idx), + }); } [[maybe_unused]] void showSprite(Context&, unsigned idx) noexcept { //oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); - teagba::GbaSpriteAttrUpdate oa; - oa.attr0 &= uint16_t{0b1111'1100'1111'1111}; - oa.idx = static_cast(idx); - teagba::addSpriteUpdate(oa); + teagba::addSpriteUpdate({ + .attr0 = 0, + .idx = static_cast(idx), + }); } void setSprite(Context&, uint_t idx, Sprite const&s) noexcept { //oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); - teagba::GbaSpriteAttrUpdate const oa{ + teagba::addSpriteUpdate({ .attr0 = static_cast( (static_cast(s.y & ox::onMask(0b111'1111))) | (static_cast(1) << 10) // enable alpha @@ -245,8 +246,7 @@ void setSprite(Context&, uint_t idx, Sprite const&s) noexcept { (static_cast(s.tileIdx & ox::onMask(8))) | (static_cast(s.priority & 0b11) << 10)), .idx = static_cast(idx), - }; - teagba::addSpriteUpdate(oa); + }); } }