yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
diagonal_routines.cc
Go to the documentation of this file.
1#include "diagonal_routines.h"
2
5
6namespace yaze {
7namespace zelda3 {
8namespace draw_routines {
9
10namespace {
11
12// USDASM routines 5/6 load size+7, then enter the shared loop at the label
13// that decrements once before the first draw. Routines 17/18 load size+6 and
14// enter before the draw. Both paths therefore render exactly size+6 columns.
15void DrawDiagonalColumns(const DrawContext& ctx, int y_step) {
16 if (ctx.tiles.size() < 5) {
17 return;
18 }
19
20 const int count = (ctx.object.size_ & 0x0F) + 6;
21 for (int step = 0; step < count; ++step) {
22 const int tile_x = ctx.object.x_ + step;
23 const int tile_y = ctx.object.y_ + step * y_step;
24 for (int row = 0; row < 5; ++row) {
25 DrawRoutineUtils::WriteTile8(ctx.target_bg, tile_x, tile_y + row,
26 ctx.tiles[row]);
27 }
28 }
29}
30
31} // namespace
32
34 DrawDiagonalColumns(ctx, /*y_step=*/-1);
35}
36
38 DrawDiagonalColumns(ctx, /*y_step=*/1);
39}
40
42 DrawDiagonalColumns(ctx, /*y_step=*/-1);
43}
44
46 DrawDiagonalColumns(ctx, /*y_step=*/1);
47}
48
49void RegisterDiagonalRoutines(std::vector<DrawRoutineInfo>& registry) {
50 // Note: Routine IDs are assigned based on the assembly routine table
51 // These diagonal routines are part of the core 40 draw routines
52
53 registry.push_back(DrawRoutineInfo{
54 .id = 5, // RoomDraw_DiagonalAcute_1to16
55 .name = "DiagonalAcute_1to16",
56 .function = DrawDiagonalAcute_1to16,
57 .draws_to_both_bgs = false,
58 .base_width = 0, // Variable based on size parameter
59 .base_height = 5,
60 .min_tiles = 5, // 2x2 + 1 diagonal step
62 });
63
64 registry.push_back(DrawRoutineInfo{
65 .id = 6, // RoomDraw_DiagonalGrave_1to16
66 .name = "DiagonalGrave_1to16",
67 .function = DrawDiagonalGrave_1to16,
68 .draws_to_both_bgs = false,
69 .base_width = 0, // Variable based on size parameter
70 .base_height = 5,
71 .min_tiles = 5, // 2x2 + 1 diagonal step
73 });
74
75 registry.push_back(DrawRoutineInfo{
76 .id = 17, // RoomDraw_DiagonalAcute_1to16_BothBG
77 .name = "DiagonalAcute_1to16_BothBG",
79 .draws_to_both_bgs = true,
80 .base_width = 0, // Variable based on size parameter
81 .base_height = 5,
82 .min_tiles = 5, // 2x2 + 1 diagonal step
84 });
85
86 registry.push_back(DrawRoutineInfo{
87 .id = 18, // RoomDraw_DiagonalGrave_1to16_BothBG
88 .name = "DiagonalGrave_1to16_BothBG",
90 .draws_to_both_bgs = true,
91 .base_width = 0, // Variable based on size parameter
92 .base_height = 5,
93 .min_tiles = 5, // 2x2 + 1 diagonal step
95 });
96}
97
98} // namespace draw_routines
99} // namespace zelda3
100} // 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 RegisterDiagonalRoutines(std::vector< DrawRoutineInfo > &registry)
Register all diagonal draw routines to the registry.
void DrawDiagonalGrave_1to16_BothBG(const DrawContext &ctx)
Draw diagonal grave () pattern for both BG layers.
void DrawDiagonalAcute_1to16_BothBG(const DrawContext &ctx)
Draw diagonal acute (/) pattern for both BG layers.
void DrawDiagonalAcute_1to16(const DrawContext &ctx)
Draw diagonal acute (/) pattern - draws 5 tiles vertically, moves up-right.
void DrawDiagonalGrave_1to16(const DrawContext &ctx)
Draw diagonal grave () pattern - draws 5 tiles vertically, moves down-right.
Context passed to draw routines containing all necessary state.
std::span< const gfx::TileInfo > tiles
gfx::BackgroundBuffer & target_bg
Metadata about a draw routine.