From 77e153f99cb279c1deb5b257fb54c7fdbdd4bc19 Mon Sep 17 00:00:00 2001 From: Daniel Hader Date: Wed, 26 Aug 2026 21:38:21 -0500 Subject: fixed screen entries being set incorrectly --- source/util.hpp | 62 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'source/util.hpp') diff --git a/source/util.hpp b/source/util.hpp index 7b39376..88a29ca 100644 --- a/source/util.hpp +++ b/source/util.hpp @@ -67,7 +67,7 @@ struct BGControlFlags { constexpr BGControlFlags &set_charblock_base(u16 block) { assert(block < 4); - this->flags = (this->flags & 0xfff3) | (block << 2); + this->flags = (this->flags & 0x000c) | (block << 2); return *this; } @@ -83,7 +83,7 @@ struct BGControlFlags { constexpr BGControlFlags &set_screenblock_base(u16 block) { assert(block < 32); - this->flags = (this->flags & 0xe0ff) | (block << 8); + this->flags = (this->flags & ~0x1f00) | (block << 8); return *this; } @@ -93,7 +93,7 @@ struct BGControlFlags { } constexpr BGControlFlags &set_size(BGControlSize size) { - this->flags = (this->flags & 0x3fff) | size; + this->flags = (this->flags & ~0xc000) | size; return *this; } @@ -129,34 +129,11 @@ typedef Color PaletteBank[16]; struct Tile4 { u32 data[8]; }; typedef Tile4 CharBlock4[512]; -template -static inline void volatile_copy(volatile T* dst, const T* src) { - using U = std::conditional_t<(sizeof(T) % sizeof(u32) == 0) && (alignof(T) % alignof(u32) == 0), u32, u16>; - static_assert(sizeof(T) % sizeof(U) == 0); - static_assert(alignof(T) % alignof(U) == 0); - auto *d = reinterpret_cast(dst); - auto *s = reinterpret_cast(src); - for (unsigned i = 0; i < sizeof(T) / sizeof(U); i++) { - d[i] = s[i]; - } -} - -static inline void set_tile(u16 block, u16 index, const Tile4 &tile) { - // TODO bounds check - volatile CharBlock4 *const blocks = reinterpret_cast(0x06000000); - volatile_copy(&blocks[block][index], &tile); -} - -static inline void set_bg_palette(u32 bank, u32 index, const Color &color) { - volatile PaletteBank *const banks = reinterpret_cast(0x05000000); - volatile_copy(&banks[bank][index], &color); -} - -// pair of screen entry bytes struct ScreenEntry { u16 data; constexpr ScreenEntry() : data(0) {} + constexpr ScreenEntry &set_tile_index(u16 tid) { assert(tid < 1024); this->data = (this->data & ~0x03ff) | tid; @@ -184,8 +161,33 @@ struct ScreenEntry { typedef ScreenEntry ScreenBlock[1024]; -CharBlock4 *const tile4_mem = reinterpret_cast(0x06000000); -PaletteBank *const palette_bg_bank = reinterpret_cast(0x05000000); -ScreenBlock *const screenblock_mem = reinterpret_cast(0x06000000); +template +static inline void volatile_copy(volatile T* dst, const T* src) { + using U = std::conditional_t<(sizeof(T) % sizeof(u32) == 0) && (alignof(T) % alignof(u32) == 0), u32, u16>; + static_assert(sizeof(T) % sizeof(U) == 0); + static_assert(alignof(T) % alignof(U) == 0); + auto *d = reinterpret_cast(dst); + auto *s = reinterpret_cast(src); + for (unsigned i = 0; i < sizeof(T) / sizeof(U); i++) { + d[i] = s[i]; + } +} + +static inline void set_tile(u16 block, u16 index, const Tile4 &tile) { + // TODO bounds check + volatile CharBlock4 *const blocks = reinterpret_cast(0x06000000); + volatile_copy(&blocks[block][index], &tile); +} + +static inline void set_bg_palette(u32 bank, u32 index, const Color &color) { + volatile PaletteBank *const banks = reinterpret_cast(0x05000000); + volatile_copy(&banks[bank][index], &color); +} + + +static inline void set_screen_entry(u32 block, u32 index, const ScreenEntry &entry) { + volatile ScreenBlock *const blocks = reinterpret_cast(0x06000000); + volatile_copy(&blocks[block][index], &entry); +} #endif -- cgit v1.2.3