[nostalgia/core] Add a background priority option

This commit is contained in:
Gary Talent 2023-12-20 19:00:23 -06:00
parent d0c90c39e0
commit 9840b6fdee
2 changed files with 16 additions and 14 deletions

View File

@ -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])
*/

View File

@ -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<uint16_t>(idx);
teagba::addSpriteUpdate(oa);
teagba::addSpriteUpdate({
.attr0 = uint16_t{0b11 << 8},
.idx = static_cast<uint16_t>(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<uint16_t>(idx);
teagba::addSpriteUpdate(oa);
teagba::addSpriteUpdate({
.attr0 = 0,
.idx = static_cast<uint16_t>(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<uint16_t>(
(static_cast<uint16_t>(s.y & ox::onMask<uint8_t>(0b111'1111)))
| (static_cast<uint16_t>(1) << 10) // enable alpha
@ -245,8 +246,7 @@ void setSprite(Context&, uint_t idx, Sprite const&s) noexcept {
(static_cast<uint16_t>(s.tileIdx & ox::onMask<uint16_t>(8)))
| (static_cast<uint16_t>(s.priority & 0b11) << 10)),
.idx = static_cast<uint16_t>(idx),
};
teagba::addSpriteUpdate(oa);
});
}
}