8namespace DrawRoutineUtils {
13 void* user_data =
nullptr;
14 bool trace_only =
false;
21 g_trace_state.
hook = hook;
27 g_trace_state = TraceState{};
35 if (g_trace_state.
hook) {
36 g_trace_state.
hook(tile_x, tile_y, tile_info, g_trace_state.
user_data);
47 std::span<const gfx::TileInfo> tiles,
int offset) {
51 if (offset + 3 >=
static_cast<int>(tiles.size()))
return;
54 WriteTile8(bg, tile_x + 1, tile_y, tiles[offset + 1]);
55 WriteTile8(bg, tile_x, tile_y + 1, tiles[offset + 2]);
56 WriteTile8(bg, tile_x + 1, tile_y + 1, tiles[offset + 3]);
60 std::span<const gfx::TileInfo> tiles,
int offset) {
66 if (offset + 7 >=
static_cast<int>(tiles.size()))
return;
68 for (
int row = 0; row < 4; row++) {
69 WriteTile8(bg, tile_x, tile_y + row, tiles[offset + row * 2]);
70 WriteTile8(bg, tile_x + 1, tile_y + row, tiles[offset + row * 2 + 1]);
75 std::span<const gfx::TileInfo> tiles,
int offset) {
79 if (offset + 7 >=
static_cast<int>(tiles.size()))
return;
81 for (
int col = 0; col < 4; col++) {
82 WriteTile8(bg, tile_x + col, tile_y, tiles[offset + col]);
83 WriteTile8(bg, tile_x + col, tile_y + 1, tiles[offset + 4 + col]);
88 std::span<const gfx::TileInfo> tiles,
int offset) {
94 if (offset + 15 >=
static_cast<int>(tiles.size()))
return;
96 for (
int row = 0; row < 4; row++) {
97 for (
int col = 0; col < 4; col++) {
98 WriteTile8(bg, tile_x + col, tile_y + row, tiles[offset + row * 4 + col]);
void SetTileAt(int x, int y, uint16_t value)
SNES 16-bit tile metadata container.
uint16_t TileInfoToWord(TileInfo tile_info)
thread_local TraceState g_trace_state
void DrawBlock2x2(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 2x2 block of tiles (16x16 pixels)
void DrawBlock2x4(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 2x4 block of tiles (16x32 pixels)
void SetTraceHook(TraceHookFn hook, void *user_data, bool trace_only)
void DrawBlock4x2(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 4x2 block of tiles (32x16 pixels)
void(*)(int tile_x, int tile_y, const gfx::TileInfo &tile_info, void *user_data) TraceHookFn
bool IsValidTilePosition(int tile_x, int tile_y)
Check if tile position is within canvas bounds.
void WriteTile8(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, const gfx::TileInfo &tile_info)
Write an 8x8 tile to the background buffer.
void DrawBlock4x4(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 4x4 block of tiles (32x32 pixels)