yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
draw_routine_registry.cc
Go to the documentation of this file.
2
3#include "core/features.h"
9
10namespace yaze {
11namespace zelda3 {
12
14 static DrawRoutineRegistry instance;
15 if (!instance.initialized_) {
16 instance.Initialize();
17 }
18 return instance;
19}
20
22 if (initialized_) return;
24 initialized_ = true;
25}
26
34
53
55 auto it = routine_map_.find(routine_id);
56 if (it == routine_map_.end()) {
57 return nullptr;
58 }
59 return it->second;
60}
61
63 const DrawRoutineInfo* info = GetRoutineInfo(routine_id);
64 return info != nullptr && info->draws_to_both_bgs;
65}
66
68 int* base_width,
69 int* base_height) const {
70 const DrawRoutineInfo* info = GetRoutineInfo(routine_id);
71 if (info == nullptr) {
72 return false;
73 }
74 if (base_width) *base_width = info->base_width;
75 if (base_height) *base_height = info->base_height;
76 return true;
77}
78
79int DrawRoutineRegistry::GetRoutineIdForObject(int16_t object_id) const {
80 auto it = object_to_routine_map_.find(object_id);
81 if (it != object_to_routine_map_.end()) {
82 return it->second;
83 }
84 return -1;
85}
86
89
90 // Subtype 1 Object Mappings (0x00-0xFF)
91 // Based on bank_01.asm routine table at $018200
92 object_to_routine_map_[0x00] = 0;
93 for (int id = 0x01; id <= 0x02; id++) {
95 }
96 for (int id = 0x03; id <= 0x04; id++) {
98 }
99 for (int id = 0x05; id <= 0x06; id++) {
101 }
102 for (int id = 0x07; id <= 0x08; id++) {
104 }
105 object_to_routine_map_[0x09] = 5;
106 for (int id = 0x0A; id <= 0x0B; id++) {
108 }
109
110 // Diagonal walls (0x0C-0x20)
111 for (int id : {0x0C, 0x0D, 0x10, 0x11, 0x14}) {
113 }
114 for (int id : {0x0E, 0x0F, 0x12, 0x13}) {
116 }
117 for (int id : {0x15, 0x18, 0x19, 0x1C, 0x1D, 0x20}) {
118 object_to_routine_map_[id] = 17;
119 }
120 for (int id : {0x16, 0x17, 0x1A, 0x1B, 0x1E, 0x1F}) {
121 object_to_routine_map_[id] = 18;
122 }
123
124 // Edge and Corner Objects (0x21-0x30)
125 object_to_routine_map_[0x21] = 20;
126 object_to_routine_map_[0x22] = 21;
127 for (int id = 0x23; id <= 0x2E; id++) {
128 object_to_routine_map_[id] = 22;
129 }
130 object_to_routine_map_[0x2F] = 23;
131 object_to_routine_map_[0x30] = 24;
132
133 // Custom Objects (0x31-0x32)
137 } else {
140 }
141 object_to_routine_map_[0x33] = 16;
142 object_to_routine_map_[0x34] = 25;
143 object_to_routine_map_[0x35] = 26;
144 object_to_routine_map_[0x36] = 27;
145 object_to_routine_map_[0x37] = 27;
146 object_to_routine_map_[0x38] = 28;
147 object_to_routine_map_[0x39] = 29;
148 object_to_routine_map_[0x3A] = 30;
149 object_to_routine_map_[0x3B] = 30;
150 object_to_routine_map_[0x3C] = 31;
151 object_to_routine_map_[0x3D] = 29;
152 object_to_routine_map_[0x3E] = 32;
153
154 for (int id = 0x3F; id <= 0x46; id++) {
155 object_to_routine_map_[id] = 22;
156 }
157 object_to_routine_map_[0x47] = 111;
158 object_to_routine_map_[0x48] = 112;
159 object_to_routine_map_[0x49] = 40;
160 object_to_routine_map_[0x4A] = 40;
161 object_to_routine_map_[0x4B] = 32;
162 object_to_routine_map_[0x4C] = 52;
163 object_to_routine_map_[0x4D] = 53;
164 object_to_routine_map_[0x4E] = 53;
165 object_to_routine_map_[0x4F] = 53;
166
167 object_to_routine_map_[0x50] = 51;
168 object_to_routine_map_[0x51] = 42;
169 object_to_routine_map_[0x52] = 42;
170 object_to_routine_map_[0x53] = 4;
171 object_to_routine_map_[0x54] = 38;
172 object_to_routine_map_[0x55] = 41;
173 object_to_routine_map_[0x56] = 41;
174 object_to_routine_map_[0x57] = 38;
175 object_to_routine_map_[0x58] = 38;
176 object_to_routine_map_[0x59] = 38;
177 object_to_routine_map_[0x5A] = 38;
178 object_to_routine_map_[0x5B] = 42;
179 object_to_routine_map_[0x5C] = 42;
180 object_to_routine_map_[0x5D] = 54;
181 object_to_routine_map_[0x5E] = 55;
183
184 // Vertical (0x60-0x6F)
185 object_to_routine_map_[0x60] = 7;
186 for (int id = 0x61; id <= 0x62; id++) {
188 }
189 for (int id = 0x63; id <= 0x64; id++) {
191 }
192 for (int id = 0x65; id <= 0x66; id++) {
193 object_to_routine_map_[id] = 10;
194 }
195 for (int id = 0x67; id <= 0x68; id++) {
196 object_to_routine_map_[id] = 11;
197 }
198 object_to_routine_map_[0x69] = 12;
199 for (int id = 0x6A; id <= 0x6B; id++) {
200 object_to_routine_map_[id] = 13;
201 }
202 object_to_routine_map_[0x6C] = 14;
203 object_to_routine_map_[0x6D] = 15;
204 object_to_routine_map_[0x6E] = 38;
205 object_to_routine_map_[0x6F] = 38;
206
207 // 0x70-0x7F
208 object_to_routine_map_[0x70] = 43;
209 object_to_routine_map_[0x71] = 44;
210 object_to_routine_map_[0x72] = 38;
211 object_to_routine_map_[0x73] = 45;
212 object_to_routine_map_[0x74] = 45;
213 object_to_routine_map_[0x75] = 46;
214 object_to_routine_map_[0x76] = 47;
215 object_to_routine_map_[0x77] = 47;
216 object_to_routine_map_[0x78] = 48;
217 object_to_routine_map_[0x79] = 13;
218 object_to_routine_map_[0x7A] = 13;
219 object_to_routine_map_[0x7B] = 48;
220 object_to_routine_map_[0x7C] = 49;
221 object_to_routine_map_[0x7D] = 11;
222 object_to_routine_map_[0x7E] = 38;
223 object_to_routine_map_[0x7F] = 50;
224
225 // 0x80-0x8F
226 object_to_routine_map_[0x80] = 50;
227 object_to_routine_map_[0x81] = 65;
228 object_to_routine_map_[0x82] = 65;
229 object_to_routine_map_[0x83] = 65;
230 object_to_routine_map_[0x84] = 65;
231 object_to_routine_map_[0x85] = 68;
232 object_to_routine_map_[0x86] = 68;
233 object_to_routine_map_[0x87] = 46;
234 object_to_routine_map_[0x88] = 66;
235 object_to_routine_map_[0x89] = 67;
239 object_to_routine_map_[0x8D] = 13;
240 object_to_routine_map_[0x8E] = 13;
241 object_to_routine_map_[0x8F] = 69;
242
243 // 0x90-0x9F
244 object_to_routine_map_[0x90] = 8;
245 object_to_routine_map_[0x91] = 8;
246 object_to_routine_map_[0x92] = 7;
247 object_to_routine_map_[0x93] = 7;
248 object_to_routine_map_[0x94] = 43;
249 object_to_routine_map_[0x95] = 70;
250 object_to_routine_map_[0x96] = 71;
251 for (int id = 0x97; id <= 0x9F; id++) {
252 object_to_routine_map_[id] = 38;
253 }
254
255 // 0xA0-0xAF (diagonal ceilings and big hole)
256 object_to_routine_map_[0xA0] = 75;
257 object_to_routine_map_[0xA5] = 75;
258 object_to_routine_map_[0xA9] = 75;
259 object_to_routine_map_[0xA1] = 76;
260 object_to_routine_map_[0xA6] = 76;
261 object_to_routine_map_[0xAA] = 76;
262 object_to_routine_map_[0xA2] = 77;
263 object_to_routine_map_[0xA7] = 77;
264 object_to_routine_map_[0xAB] = 77;
265 object_to_routine_map_[0xA3] = 78;
266 object_to_routine_map_[0xA8] = 78;
267 object_to_routine_map_[0xAC] = 78;
268 object_to_routine_map_[0xA4] = 61;
269 object_to_routine_map_[0xAD] = 38;
270 object_to_routine_map_[0xAE] = 38;
271 object_to_routine_map_[0xAF] = 38;
272
273 // 0xB0-0xBF
274 object_to_routine_map_[0xB0] = 72;
275 object_to_routine_map_[0xB1] = 72;
276 object_to_routine_map_[0xB2] = 16;
277 object_to_routine_map_[0xB3] = 22;
278 object_to_routine_map_[0xB4] = 22;
279 object_to_routine_map_[0xB5] = 8;
280 object_to_routine_map_[0xB6] = 1;
281 object_to_routine_map_[0xB7] = 1;
282 object_to_routine_map_[0xB8] = 0;
283 object_to_routine_map_[0xB9] = 0;
284 object_to_routine_map_[0xBA] = 16;
285 object_to_routine_map_[0xBB] = 55;
286 object_to_routine_map_[0xBC] = 73;
287 object_to_routine_map_[0xBD] = 74;
288 object_to_routine_map_[0xBE] = 38;
289 object_to_routine_map_[0xBF] = 38;
290
291 // 0xC0-0xCF (SuperSquare)
292 object_to_routine_map_[0xC0] = 56;
293 object_to_routine_map_[0xC1] = 79;
294 object_to_routine_map_[0xC2] = 56;
295 object_to_routine_map_[0xC3] = 57;
296 object_to_routine_map_[0xC4] = 59;
297 for (int id = 0xC5; id <= 0xCA; id++) {
298 object_to_routine_map_[id] = 58;
299 }
300 object_to_routine_map_[0xCB] = 38;
301 object_to_routine_map_[0xCC] = 38;
302 object_to_routine_map_[0xCD] = 80;
303 object_to_routine_map_[0xCE] = 81;
304 object_to_routine_map_[0xCF] = 38;
305
306 // 0xD0-0xDF
307 object_to_routine_map_[0xD0] = 38;
308 object_to_routine_map_[0xD1] = 58;
309 object_to_routine_map_[0xD2] = 58;
310 object_to_routine_map_[0xD3] = 38;
311 object_to_routine_map_[0xD4] = 38;
312 object_to_routine_map_[0xD5] = 38;
313 object_to_routine_map_[0xD6] = 38;
314 object_to_routine_map_[0xD7] = 57;
315 object_to_routine_map_[0xD8] = 64;
316 object_to_routine_map_[0xD9] = 58;
317 object_to_routine_map_[0xDA] = 64;
318 object_to_routine_map_[0xDB] = 60;
319 object_to_routine_map_[0xDC] = 82;
320 object_to_routine_map_[0xDD] = 63;
321 object_to_routine_map_[0xDE] = 62;
322 object_to_routine_map_[0xDF] = 58;
323
324 // 0xE0-0xEF
325 for (int id = 0xE0; id <= 0xE8; id++) {
326 object_to_routine_map_[id] = 58;
327 }
328 for (int id = 0xE9; id <= 0xEF; id++) {
329 object_to_routine_map_[id] = 38;
330 }
331
332 // 0xF0-0xFF (complete subtype 1 coverage)
333 for (int id = 0xF0; id <= 0xF7; id++) {
334 object_to_routine_map_[id] = 38;
335 }
336 object_to_routine_map_[0xF8] = 39; // Chest variant
337 for (int id = 0xF9; id <= 0xFD; id++) {
338 object_to_routine_map_[id] = 39;
339 }
340 object_to_routine_map_[0xFE] = 38; // Unused in vanilla
341 object_to_routine_map_[0xFF] = 38; // Unused in vanilla
342
343 // Subtype 2 Object Mappings (0x100-0x13F)
344 for (int id = 0x100; id <= 0x107; id++) {
345 object_to_routine_map_[id] = 16;
346 }
347 for (int id = 0x108; id <= 0x10F; id++) {
348 object_to_routine_map_[id] = 35;
349 }
350 for (int id = 0x110; id <= 0x113; id++) {
351 object_to_routine_map_[id] = 36;
352 }
353 for (int id = 0x114; id <= 0x117; id++) {
354 object_to_routine_map_[id] = 37;
355 }
356 for (int id = 0x118; id <= 0x11B; id++) {
358 }
359 object_to_routine_map_[0x11C] = 16;
360 object_to_routine_map_[0x11D] = 28;
361 object_to_routine_map_[0x11E] = 4;
362 object_to_routine_map_[0x11F] = 25;
363 object_to_routine_map_[0x120] = 25;
364 object_to_routine_map_[0x121] = 28;
365 object_to_routine_map_[0x122] = 98;
366 object_to_routine_map_[0x123] = 30;
367 object_to_routine_map_[0x124] = 16;
368 object_to_routine_map_[0x125] = 16;
369 object_to_routine_map_[0x126] = 28;
370 object_to_routine_map_[0x127] = 4;
371 object_to_routine_map_[0x128] = 98;
372 object_to_routine_map_[0x129] = 16;
373 object_to_routine_map_[0x12A] = 4;
374 object_to_routine_map_[0x12B] = 4;
375 object_to_routine_map_[0x12C] = 99;
376 object_to_routine_map_[0x12D] = 83;
377 object_to_routine_map_[0x12E] = 84;
378 object_to_routine_map_[0x12F] = 85;
379 for (int id = 0x130; id <= 0x133; id++) {
380 object_to_routine_map_[id] = 86;
381 }
382 object_to_routine_map_[0x134] = 4;
383 object_to_routine_map_[0x135] = 16;
384 object_to_routine_map_[0x136] = 16;
385 object_to_routine_map_[0x137] = 16;
386 object_to_routine_map_[0x138] = 88;
387 object_to_routine_map_[0x139] = 89;
388 object_to_routine_map_[0x13A] = 90;
389 object_to_routine_map_[0x13B] = 91;
390 object_to_routine_map_[0x13C] = 16;
391 object_to_routine_map_[0x13D] = 30;
392 object_to_routine_map_[0x13E] = 100;
393 object_to_routine_map_[0x13F] = 16;
394
395 // Subtype 3 Object Mappings (0xF80-0xFFF)
396 object_to_routine_map_[0xF80] = 94;
397 object_to_routine_map_[0xF81] = 95;
398 object_to_routine_map_[0xF82] = 96;
399 for (int id = 0xF83; id <= 0xF89; id++) {
400 object_to_routine_map_[id] = 33;
401 }
402 for (int id = 0xF8A; id <= 0xF8C; id++) {
403 object_to_routine_map_[id] = 33;
404 }
405 object_to_routine_map_[0xF8D] = 97;
406 object_to_routine_map_[0xF8E] = 33;
407 object_to_routine_map_[0xF8F] = 33;
408 object_to_routine_map_[0xF90] = 110;
409 object_to_routine_map_[0xF91] = 110;
410 object_to_routine_map_[0xF92] = 115;
411 object_to_routine_map_[0xF93] = 110;
412 object_to_routine_map_[0xF94] = 30;
413 object_to_routine_map_[0xF95] = 106;
414 object_to_routine_map_[0xF96] = 25;
415 object_to_routine_map_[0xF97] = 97;
416 object_to_routine_map_[0xF98] = 92;
417 object_to_routine_map_[0xF99] = 39;
418 object_to_routine_map_[0xF9A] = 39;
419 for (int id = 0xF9B; id <= 0xF9D; id++) {
420 object_to_routine_map_[id] = 86;
421 }
422 for (int id = 0xF9E; id <= 0xFA1; id++) {
423 object_to_routine_map_[id] = 87;
424 }
425 for (int id = 0xFA2; id <= 0xFA5; id++) {
426 object_to_routine_map_[id] = 110;
427 }
428 for (int id = 0xFA6; id <= 0xFA9; id++) {
429 object_to_routine_map_[id] = 87;
430 }
431 object_to_routine_map_[0xFAA] = 16;
432 object_to_routine_map_[0xFAB] = 110;
433 object_to_routine_map_[0xFAC] = 110;
434 object_to_routine_map_[0xFAD] = 16;
435 object_to_routine_map_[0xFAE] = 16;
436 object_to_routine_map_[0xFAF] = 110;
437 object_to_routine_map_[0xFB0] = 110;
438 object_to_routine_map_[0xFB1] = 114;
439 object_to_routine_map_[0xFB2] = 114;
440 object_to_routine_map_[0xFB3] = 86;
441 for (int id = 0xFB4; id <= 0xFB9; id++) {
442 object_to_routine_map_[id] = 16;
443 }
444 object_to_routine_map_[0xFBA] = 102;
445 object_to_routine_map_[0xFBB] = 102;
446 object_to_routine_map_[0xFBC] = 103;
447 object_to_routine_map_[0xFBD] = 103;
448 for (int id = 0xFBE; id <= 0xFC6; id++) {
449 object_to_routine_map_[id] = 110;
450 }
451 object_to_routine_map_[0xFC7] = 93;
452 object_to_routine_map_[0xFC8] = 16;
453 object_to_routine_map_[0xFC9] = 110;
454 object_to_routine_map_[0xFCA] = 110;
455 object_to_routine_map_[0xFCB] = 16;
456 object_to_routine_map_[0xFCC] = 16;
457 object_to_routine_map_[0xFCD] = 100;
458 object_to_routine_map_[0xFCE] = 30;
459 for (int id = 0xFCF; id <= 0xFD3; id++) {
460 object_to_routine_map_[id] = 110;
461 }
462 object_to_routine_map_[0xFD4] = 16;
463 object_to_routine_map_[0xFD5] = 101;
464 for (int id = 0xFD6; id <= 0xFDA; id++) {
465 object_to_routine_map_[id] = 110;
466 }
467 object_to_routine_map_[0xFDB] = 101;
468 object_to_routine_map_[0xFDC] = 103;
469 object_to_routine_map_[0xFDD] = 100;
470 object_to_routine_map_[0xFDE] = 110;
471 object_to_routine_map_[0xFDF] = 110;
472 object_to_routine_map_[0xFE0] = 108;
473 object_to_routine_map_[0xFE1] = 108;
474 object_to_routine_map_[0xFE2] = 16;
475 for (int id = 0xFE3; id <= 0xFE5; id++) {
476 object_to_routine_map_[id] = 110;
477 }
478 object_to_routine_map_[0xFE6] = 116;
479 object_to_routine_map_[0xFE7] = 30;
480 object_to_routine_map_[0xFE8] = 30;
481 object_to_routine_map_[0xFE9] = 107;
482 object_to_routine_map_[0xFEA] = 107;
483 object_to_routine_map_[0xFEB] = 113;
484 object_to_routine_map_[0xFEC] = 114;
485 object_to_routine_map_[0xFED] = 114;
486 object_to_routine_map_[0xFEE] = 107;
487 object_to_routine_map_[0xFEF] = 107;
488 object_to_routine_map_[0xFF0] = 104;
489 object_to_routine_map_[0xFF1] = 105;
490 object_to_routine_map_[0xFF2] = 106;
491 object_to_routine_map_[0xFF3] = 38;
492 object_to_routine_map_[0xFF4] = 16;
493 object_to_routine_map_[0xFF5] = 110;
494 object_to_routine_map_[0xFF6] = 16;
495 object_to_routine_map_[0xFF7] = 16;
496 object_to_routine_map_[0xFF8] = 109;
497 object_to_routine_map_[0xFF9] = 30;
498 object_to_routine_map_[0xFFA] = 16;
499 object_to_routine_map_[0xFFB] = 106;
500 for (int id = 0xFFC; id <= 0xFFE; id++) {
501 object_to_routine_map_[id] = 110;
502 }
503 object_to_routine_map_[0xFFF] = 38;
504}
505
506} // namespace zelda3
507} // namespace yaze
508
static Flags & get()
Definition features.h:118
Unified draw routine registry.
const DrawRoutineInfo * GetRoutineInfo(int routine_id) const
bool GetRoutineDimensions(int routine_id, int *base_width, int *base_height) const
std::unordered_map< int16_t, int > object_to_routine_map_
bool RoutineDrawsToBothBGs(int routine_id) const
std::unordered_map< int, const DrawRoutineInfo * > routine_map_
int GetRoutineIdForObject(int16_t object_id) const
std::vector< DrawRoutineInfo > routines_
static DrawRoutineRegistry & Get()
void RegisterDiagonalRoutines(std::vector< DrawRoutineInfo > &registry)
Register all diagonal draw routines to the registry.
void RegisterCornerRoutines(std::vector< DrawRoutineInfo > &registry)
Register all corner draw routines to the registry.
void RegisterDownwardsRoutines(std::vector< DrawRoutineInfo > &registry)
Register all downwards draw routines to the registry.
void RegisterRightwardsRoutines(std::vector< DrawRoutineInfo > &registry)
Register all rightwards draw routines to the registry.
void RegisterSpecialRoutines(std::vector< DrawRoutineInfo > &registry)
Register all special/miscellaneous draw routines to the registry.
Metadata about a draw routine.