diff options
| author | Daniel Hader <[email protected]> | 2026-08-26 21:38:21 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-08-26 21:38:21 -0500 |
| commit | 77e153f99cb279c1deb5b257fb54c7fdbdd4bc19 (patch) | |
| tree | 9f36695c9548c4b97eff08e183c1ae5f8d56d15a /source/util.hpp | |
| parent | 0532e04a9e273f2a9033a28cdbce1030a91c5bb4 (diff) | |
fixed screen entries being set incorrectly
Diffstat (limited to 'source/util.hpp')
| -rw-r--r-- | source/util.hpp | 62 |
1 files changed, 32 insertions, 30 deletions
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 <typename T> -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<volatile U*>(dst); - auto *s = reinterpret_cast<const U*>(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<volatile CharBlock4*>(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<volatile PaletteBank*>(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<CharBlock4*>(0x06000000); -PaletteBank *const palette_bg_bank = reinterpret_cast<PaletteBank*>(0x05000000); -ScreenBlock *const screenblock_mem = reinterpret_cast<ScreenBlock*>(0x06000000); +template <typename T> +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<volatile U*>(dst); + auto *s = reinterpret_cast<const U*>(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<volatile CharBlock4*>(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<volatile PaletteBank*>(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<volatile ScreenBlock*>(0x06000000); + volatile_copy(&blocks[block][index], &entry); +} #endif |
