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
3
#include "
zelda3/dungeon/draw_routines/draw_routine_registry.h
"
4
#include "
zelda3/dungeon/draw_routines/special_routines.h
"
5
#include "
zelda3/dungeon/room_object.h
"
6
7
namespace
yaze
{
8
namespace
zelda3 {
9
namespace
draw_routines {
10
11
// Note: DrawWaterFace is defined in special_routines.cc along with other
12
// water face variants (Empty, Spitting, Drenching)
13
14
void
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++) {
24
DrawRoutineUtils::WriteTile8
(ctx.
target_bg
, ctx.
object
.
x_
+ xx,
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++) {
34
DrawRoutineUtils::WriteTile8
(ctx.
target_bg
, ctx.
object
.
x_
+ xx,
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++) {
43
DrawRoutineUtils::WriteTile8
(ctx.
target_bg
, ctx.
object
.
x_
+ xx,
44
ctx.
object
.
y_
+ yy, ctx.
tiles
[tid++]);
45
}
46
}
47
}
48
}
49
50
void
Draw4x4Corner_BothBG
(
const
DrawContext
& ctx) {
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++) {
60
DrawRoutineUtils::WriteTile8
(ctx.
target_bg
, ctx.
object
.
x_
+ xx,
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
70
void
DrawWeirdCornerBottom_BothBG
(
const
DrawContext
& ctx) {
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++) {
80
DrawRoutineUtils::WriteTile8
(ctx.
target_bg
, ctx.
object
.
x_
+ xx,
81
ctx.
object
.
y_
+ yy, ctx.
tiles
[tid++]);
82
}
83
}
84
}
else
if
(ctx.
tiles
.size() >= 4) {
85
DrawWaterFace
(ctx);
86
}
87
}
88
89
void
DrawWeirdCornerTop_BothBG
(
const
DrawContext
& ctx) {
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++) {
99
DrawRoutineUtils::WriteTile8
(ctx.
target_bg
, ctx.
object
.
x_
+ xx,
100
ctx.
object
.
y_
+ yy, ctx.
tiles
[tid++]);
101
}
102
}
103
}
else
if
(ctx.
tiles
.size() >= 4) {
104
DrawWaterFace
(ctx);
105
}
106
}
107
108
void
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,
119
.category =
DrawRoutineInfo::Category::Corner
,
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,
129
.category =
DrawRoutineInfo::Category::Corner
,
130
});
131
132
registry.push_back(
DrawRoutineInfo
{
133
.
id
= 36,
// DrawWeirdCornerBottom_BothBG
134
.name =
"WeirdCornerBottom_BothBG"
,
135
.function =
DrawWeirdCornerBottom_BothBG
,
136
.draws_to_both_bgs =
true
,
137
.base_width = 4,
138
.base_height = 2,
139
.category =
DrawRoutineInfo::Category::Corner
,
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,
149
.category =
DrawRoutineInfo::Category::Corner
,
150
});
151
}
152
153
}
// namespace draw_routines
154
}
// namespace zelda3
155
}
// namespace yaze
yaze::zelda3::RoomObject::x_
uint8_t x_
Definition
room_object.h:140
yaze::zelda3::RoomObject::y_
uint8_t y_
Definition
room_object.h:141
corner_routines.h
draw_routine_registry.h
yaze::zelda3::DrawRoutineUtils::WriteTile8
void WriteTile8(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, const gfx::TileInfo &tile_info)
Write an 8x8 tile to the background buffer.
Definition
draw_routine_types.cc:10
yaze::zelda3::draw_routines::DrawWeirdCornerTop_BothBG
void DrawWeirdCornerTop_BothBG(const DrawContext &ctx)
Draw a weird corner top pattern for both BG layers.
Definition
corner_routines.cc:89
yaze::zelda3::draw_routines::RegisterCornerRoutines
void RegisterCornerRoutines(std::vector< DrawRoutineInfo > ®istry)
Register all corner draw routines to the registry.
Definition
corner_routines.cc:108
yaze::zelda3::draw_routines::DrawCorner4x4
void DrawCorner4x4(const DrawContext &ctx)
Draw a 4x4 grid corner pattern.
Definition
corner_routines.cc:14
yaze::zelda3::draw_routines::DrawWaterFace
void DrawWaterFace(const DrawContext &ctx)
Draw water face pattern (2x2)
Definition
special_routines.cc:191
yaze::zelda3::draw_routines::DrawWeirdCornerBottom_BothBG
void DrawWeirdCornerBottom_BothBG(const DrawContext &ctx)
Draw a weird corner bottom pattern for both BG layers.
Definition
corner_routines.cc:70
yaze::zelda3::draw_routines::Draw4x4Corner_BothBG
void Draw4x4Corner_BothBG(const DrawContext &ctx)
Draw a 4x4 corner for both BG layers.
Definition
corner_routines.cc:50
yaze
Definition
application.cc:18
room_object.h
special_routines.h
yaze::zelda3::DrawContext
Context passed to draw routines containing all necessary state.
Definition
draw_routine_types.h:26
yaze::zelda3::DrawContext::tiles
std::span< const gfx::TileInfo > tiles
Definition
draw_routine_types.h:29
yaze::zelda3::DrawContext::target_bg
gfx::BackgroundBuffer & target_bg
Definition
draw_routine_types.h:27
yaze::zelda3::DrawContext::object
const RoomObject & object
Definition
draw_routine_types.h:28
yaze::zelda3::DrawRoutineInfo
Metadata about a draw routine.
Definition
draw_routine_types.h:55
yaze::zelda3::DrawRoutineInfo::id
int id
Definition
draw_routine_types.h:56
yaze::zelda3::DrawRoutineInfo::Category::Corner
@ Corner
src
zelda3
dungeon
draw_routines
corner_routines.cc
Generated by
1.10.0