yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
corner_routines.cc
Go to the documentation of this file.
1#include "corner_routines.h"
2
6
7namespace yaze {
8namespace zelda3 {
9namespace draw_routines {
10
11// Note: DrawWaterFace is defined in special_routines.cc along with other
12// water face variants (Empty, Spitting, Drenching)
13
14void DrawCorner4x4(const DrawContext& ctx) {
15 // Pattern: 4x4 grid corner (Type 2 corners 0x40-0x4F, 0x108-0x10F)
16 // Type 2 objects only have 8 tiles, so we need to handle both 16 and 8 tile
17 // cases
18
19 if (ctx.tiles.size() >= 16) {
20 // Full 4x4 pattern - Column-major ordering per ZScream
21 int tid = 0;
22 for (int xx = 0; xx < 4; xx++) {
23 for (int yy = 0; yy < 4; yy++) {
25 ctx.object.y_ + yy, ctx.tiles[tid++]);
26 }
27 }
28 } else if (ctx.tiles.size() >= 8) {
29 // Type 2 objects: 8 tiles arranged in 2x4 column-major pattern
30 // This is the standard Type 2 tile layout
31 int tid = 0;
32 for (int xx = 0; xx < 2; xx++) {
33 for (int yy = 0; yy < 4; yy++) {
35 ctx.object.y_ + yy, ctx.tiles[tid++]);
36 }
37 }
38 } else if (ctx.tiles.size() >= 4) {
39 // Fallback: 2x2 pattern
40 int tid = 0;
41 for (int xx = 0; xx < 2; xx++) {
42 for (int yy = 0; yy < 2; yy++) {
44 ctx.object.y_ + yy, ctx.tiles[tid++]);
45 }
46 }
47 }
48}
49
51 // Pattern: 4x4 Corner for Both BG (objects 0x108-0x10F for Type 2)
52 // Type 3 objects (0xF9B-0xF9D) only have 8 tiles, draw 2x4 pattern
53 if (ctx.tiles.size() >= 16) {
54 DrawCorner4x4(ctx);
55 } else if (ctx.tiles.size() >= 8) {
56 // Draw 2x4 corner pattern (column-major)
57 int tid = 0;
58 for (int xx = 0; xx < 2; xx++) {
59 for (int yy = 0; yy < 4; yy++) {
61 ctx.object.y_ + yy, ctx.tiles[tid++]);
62 }
63 }
64 } else if (ctx.tiles.size() >= 4) {
65 // Fallback: 2x2 pattern
66 DrawWaterFace(ctx);
67 }
68}
69
71 // Pattern: Weird Corner Bottom (objects 0x110-0x113 for Type 2)
72 // Type 3 objects (0xF9E-0xFA1) use 8 tiles in 4x2 bottom corner layout
73 if (ctx.tiles.size() >= 16) {
74 DrawCorner4x4(ctx);
75 } else if (ctx.tiles.size() >= 8) {
76 // Draw 4x2 bottom corner pattern (row-major for bottom corners)
77 int tid = 0;
78 for (int yy = 0; yy < 2; yy++) {
79 for (int xx = 0; xx < 4; xx++) {
81 ctx.object.y_ + yy, ctx.tiles[tid++]);
82 }
83 }
84 } else if (ctx.tiles.size() >= 4) {
85 DrawWaterFace(ctx);
86 }
87}
88
90 // Pattern: Weird Corner Top (objects 0x114-0x117 for Type 2)
91 // Type 3 objects (0xFA2-0xFA5) use 8 tiles in 4x2 top corner layout
92 if (ctx.tiles.size() >= 16) {
93 DrawCorner4x4(ctx);
94 } else if (ctx.tiles.size() >= 8) {
95 // Draw 4x2 top corner pattern (row-major for top corners)
96 int tid = 0;
97 for (int yy = 0; yy < 2; yy++) {
98 for (int xx = 0; xx < 4; xx++) {
100 ctx.object.y_ + yy, ctx.tiles[tid++]);
101 }
102 }
103 } else if (ctx.tiles.size() >= 4) {
104 DrawWaterFace(ctx);
105 }
106}
107
108void RegisterCornerRoutines(std::vector<DrawRoutineInfo>& registry) {
109 // Note: Routine IDs are assigned based on the assembly routine table
110 // These corner routines are part of the core 40 draw routines
111
112 registry.push_back(DrawRoutineInfo{
113 .id = 19, // DrawCorner4x4
114 .name = "Corner4x4",
115 .function = DrawCorner4x4,
116 .draws_to_both_bgs = false,
117 .base_width = 4,
118 .base_height = 4,
120 });
121
122 registry.push_back(DrawRoutineInfo{
123 .id = 35, // Draw4x4Corner_BothBG
124 .name = "4x4Corner_BothBG",
125 .function = Draw4x4Corner_BothBG,
126 .draws_to_both_bgs = true,
127 .base_width = 4,
128 .base_height = 4,
130 });
131
132 registry.push_back(DrawRoutineInfo{
133 .id = 36, // DrawWeirdCornerBottom_BothBG
134 .name = "WeirdCornerBottom_BothBG",
136 .draws_to_both_bgs = true,
137 .base_width = 4,
138 .base_height = 2,
140 });
141
142 registry.push_back(DrawRoutineInfo{
143 .id = 37, // DrawWeirdCornerTop_BothBG
144 .name = "WeirdCornerTop_BothBG",
145 .function = DrawWeirdCornerTop_BothBG,
146 .draws_to_both_bgs = true,
147 .base_width = 4,
148 .base_height = 2,
150 });
151}
152
153} // namespace draw_routines
154} // namespace zelda3
155} // namespace yaze
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 DrawWeirdCornerTop_BothBG(const DrawContext &ctx)
Draw a weird corner top pattern for both BG layers.
void RegisterCornerRoutines(std::vector< DrawRoutineInfo > &registry)
Register all corner draw routines to the registry.
void DrawCorner4x4(const DrawContext &ctx)
Draw a 4x4 grid corner pattern.
void DrawWaterFace(const DrawContext &ctx)
Draw water face pattern (2x2)
void DrawWeirdCornerBottom_BothBG(const DrawContext &ctx)
Draw a weird corner bottom pattern for both BG layers.
void Draw4x4Corner_BothBG(const DrawContext &ctx)
Draw a 4x4 corner for both BG layers.
Context passed to draw routines containing all necessary state.
std::span< const gfx::TileInfo > tiles
gfx::BackgroundBuffer & target_bg
Metadata about a draw routine.