yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
object_parser.cc
Go to the documentation of this file.
1#include "object_parser.h"
2
3#include <algorithm>
4#include <cstring>
5
6#include "absl/strings/str_format.h"
7#include "util/log.h"
9
10// ROM addresses for object data are defined in room_object.h:
11// - kRoomObjectSubtype1 = 0x8000 (SNES $01:8000)
12// - kRoomObjectSubtype2 = 0x83F0 (SNES $01:83F0)
13// - kRoomObjectSubtype3 = 0x84F0 (SNES $01:84F0)
14// - kRoomObjectTileAddress = 0x1B52 (SNES $00:9B52)
15
16// Subtype 1 tile count lookup table (from ZScream's DungeonObjectData.cs)
17// Each entry specifies how many tiles to read for that object ID (0x00-0xF7)
18// Index directly by (object_id & 0xFF) for subtype 1 objects
19// clang-format off
20static constexpr uint8_t kSubtype1TileLengths[0xF8] = {
21 4, 8, 8, 8, 8, 8, 8, 4, 4, 5, 5, 5, 5, 5, 5, 5, // 0x00-0x0F
22 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 0x10-0x1F
23 5, 9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, // 0x20-0x2F
24 6, 1, 1, 16, 1, 1, 16, 16, 6, 8, 12, 12, 4, 8, 4, 3, // 0x30-0x3F
25 3, 3, 3, 3, 3, 3, 3, 0, 0, 8, 8, 4, 9, 16, 16, 16, // 0x40-0x4F
26 1, 18, 18, 4, 1, 8, 8, 1, 1, 1, 1, 18, 18, 15, 4, 3, // 0x50-0x5F
27 4, 8, 8, 8, 8, 8, 8, 4, 4, 3, 1, 1, 6, 6, 1, 1, // 0x60-0x6F
28 16, 1, 1, 16, 16, 8, 16, 16, 4, 1, 1, 4, 1, 4, 1, 8, // 0x70-0x7F
29 8, 12, 12, 12, 12, 18, 18, 8, 12, 4, 3, 3, 3, 1, 1, 6, // 0x80-0x8F
30 8, 8, 4, 4, 16, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90-0x9F
31 1, 1, 1, 1, 24, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xA0-0xAF
32 1, 1, 16, 3, 3, 8, 8, 8, 4, 4, 16, 4, 4, 4, 1, 1, // 0xB0-0xBF
33 1, 68, 1, 1, 8, 8, 8, 8, 8, 8, 8, 1, 1, 28, 28, 1, // 0xC0-0xCF
34 1, 8, 8, 0, 0, 0, 0, 1, 8, 8, 8, 8, 21, 16, 4, 8, // 0xD0-0xDF
35 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, // 0xE0-0xEF
36 1, 1, 1, 1, 1, 1, 1, 1 // 0xF0-0xF7
37};
38// clang-format on
39
40// Helper function to get tile count for Subtype 1 objects
41static inline int GetSubtype1TileCount(int object_id) {
42 int index = object_id & 0xFF;
43 if (index < 0xF8) {
44 int count = kSubtype1TileLengths[index];
45 return (count > 0) ? count : 8; // Default to 8 if table has 0
46 }
47 return 8; // Default for IDs >= 0xF8
48}
49
50namespace yaze {
51namespace zelda3 {
52
53absl::StatusOr<std::vector<gfx::TileInfo>> ObjectParser::ParseObject(
54 int16_t object_id) {
55 if (rom_ == nullptr) {
56 return absl::InvalidArgumentError("ROM is null");
57 }
58
59 // Validate object ID is non-negative
60 if (object_id < 0) {
61 return absl::InvalidArgumentError(
62 absl::StrFormat("Invalid object ID: %d", object_id));
63 }
64
65 int subtype = DetermineSubtype(object_id);
66
67 switch (subtype) {
68 case 1:
69 return ParseSubtype1(object_id);
70 case 2:
71 return ParseSubtype2(object_id);
72 case 3:
73 return ParseSubtype3(object_id);
74 default:
75 return absl::InvalidArgumentError(
76 absl::StrFormat("Invalid object subtype for ID: %#04x", object_id));
77 }
78}
79
80absl::StatusOr<ObjectRoutineInfo> ObjectParser::ParseObjectRoutine(
81 int16_t object_id) {
82 if (rom_ == nullptr) {
83 return absl::InvalidArgumentError("ROM is null");
84 }
85
86 auto subtype_info = GetObjectSubtype(object_id);
87 if (!subtype_info.ok()) {
88 return subtype_info.status();
89 }
90
91 ObjectRoutineInfo routine_info;
92 routine_info.routine_ptr = subtype_info->routine_ptr;
93 routine_info.tile_ptr = subtype_info->subtype_ptr;
94 routine_info.tile_count = subtype_info->max_tile_count;
95 routine_info.is_repeatable = true;
96 routine_info.is_orientation_dependent = true;
97
98 return routine_info;
99}
100
101absl::StatusOr<ObjectSubtypeInfo> ObjectParser::GetObjectSubtype(
102 int16_t object_id) {
104 info.subtype = DetermineSubtype(object_id);
105
106 switch (info.subtype) {
107 case 1: {
108 int index = object_id & 0xFF;
109 info.subtype_ptr = kRoomObjectSubtype1 + (index * 2);
110 info.routine_ptr = kRoomObjectSubtype1 + 0x200 + (index * 2);
111 info.max_tile_count =
112 GetSubtype1TileCount(object_id); // Use lookup table
113 break;
114 }
115 case 2: {
116 // Type 2 objects: 0x100-0x13F (64 objects only)
117 // Index mask 0x3F ensures we stay within 64-entry table bounds
118 int index = (object_id - 0x100) & 0x3F;
119 info.subtype_ptr = kRoomObjectSubtype2 + (index * 2);
120 // Routine table starts 128 bytes (64 entries * 2 bytes) after data table
121 info.routine_ptr = kRoomObjectSubtype2 + 0x80 + (index * 2);
122 info.max_tile_count = GetSubtype2TileCount(object_id);
123 break;
124 }
125 case 3: {
126 // Type 3 object IDs are 0xF80-0xFFF (128 objects)
127 // Table index should be 0-127
128 int index = (object_id - 0xF80) & 0x7F;
129 info.subtype_ptr = kRoomObjectSubtype3 + (index * 2);
130 info.routine_ptr = kRoomObjectSubtype3 + 0x100 + (index * 2);
131 info.max_tile_count = GetSubtype3TileCount(object_id);
132 break;
133 }
134 default:
135 return absl::InvalidArgumentError(
136 absl::StrFormat("Invalid object subtype for ID: %#04x", object_id));
137 }
138
139 return info;
140}
141
142absl::StatusOr<ObjectSizeInfo> ObjectParser::ParseObjectSize(
143 int16_t object_id, uint8_t size_byte) {
144 ObjectSizeInfo info;
145
146 // Extract size bits (0-3 for X, 4-7 for Y)
147 int size_x = size_byte & 0x03;
148 int size_y = (size_byte >> 2) & 0x03;
149
150 info.width_tiles = (size_x + 1) * 2; // Convert to tile count
151 info.height_tiles = (size_y + 1) * 2;
152
153 // Determine orientation based on object ID and size
154 // This is a heuristic based on the object naming patterns
155 if (object_id >= 0x80 && object_id <= 0xFF) {
156 // Objects 0x80-0xFF are typically vertical
157 info.is_horizontal = false;
158 } else {
159 // Objects 0x00-0x7F are typically horizontal
160 info.is_horizontal = true;
161 }
162
163 // Determine if object is repeatable
164 info.is_repeatable = (size_byte != 0);
165 info.repeat_count = size_byte == 0 ? 32 : size_byte;
166
167 return info;
168}
169
170absl::StatusOr<std::vector<gfx::TileInfo>> ObjectParser::ParseSubtype1(
171 int16_t object_id) {
172 int index = object_id & 0xFF;
173 int tile_ptr = kRoomObjectSubtype1 + (index * 2);
174
175 if (tile_ptr + 1 >= (int)rom_->size()) {
176 return absl::OutOfRangeError(
177 absl::StrFormat("Tile pointer out of range: %#06x", tile_ptr));
178 }
179
180 // Read tile data pointer (16-bit little-endian offset)
181 uint8_t low = rom_->data()[tile_ptr];
182 uint8_t high = rom_->data()[tile_ptr + 1];
183 int16_t offset = (int16_t)((high << 8) | low); // Signed offset!
184 int tile_data_ptr = kRoomObjectTileAddress + offset;
185
186 // DEBUG: Log wall objects 0x61/0x62 and ceiling 0xC0 to verify tile data
187 bool is_debug_object = (object_id == 0x61 || object_id == 0x62 ||
188 object_id == 0xC0 || object_id == 0xC2);
189 static int debug_count = 0;
190 if (debug_count < 10 || is_debug_object) {
191 LOG_DEBUG("ObjectParser",
192 "ParseSubtype1: obj=0x%02X%s tile_ptr=0x%04X (SNES $01:%04X)",
193 object_id, is_debug_object ? " (DEBUG)" : "", tile_ptr, tile_ptr);
194 LOG_DEBUG("ObjectParser",
195 " ROM[0x%04X..0x%04X]=0x%02X 0x%02X offset=%d (0x%04X)",
196 tile_ptr, tile_ptr + 1, low, high, offset, (uint16_t)offset);
197 LOG_DEBUG("ObjectParser",
198 " tile_data_ptr=0x%04X+0x%04X=0x%04X (SNES $00:%04X)",
199 kRoomObjectTileAddress, (uint16_t)offset, tile_data_ptr,
200 tile_data_ptr + 0x8000);
201
202 // Fix: Check for negative tile_data_ptr to prevent SIGSEGV on corrupted ROMs
203 if (tile_data_ptr >= 0 && tile_data_ptr + 8 < (int)rom_->size()) {
204 uint16_t tw0 =
205 rom_->data()[tile_data_ptr] | (rom_->data()[tile_data_ptr + 1] << 8);
206 uint16_t tw1 = rom_->data()[tile_data_ptr + 2] |
207 (rom_->data()[tile_data_ptr + 3] << 8);
208 LOG_DEBUG("ObjectParser", " First 2 tiles: $%04X(id=%d) $%04X(id=%d)",
209 tw0, tw0 & 0x3FF, tw1, tw1 & 0x3FF);
210 } else {
211 LOG_DEBUG("ObjectParser", " Tile data at 0x%04X: <OUT OF BOUNDS>",
212 tile_data_ptr);
213 }
214 if (!is_debug_object)
215 debug_count++;
216 }
217
218 // Use lookup table for correct tile count per object ID
219 int tile_count = GetSubtype1TileCount(object_id);
220 return ReadTileData(tile_data_ptr, tile_count);
221}
222
223absl::StatusOr<std::vector<gfx::TileInfo>> ObjectParser::ParseSubtype2(
224 int16_t object_id) {
225 // Type 2 objects: 0x100-0x13F (64 objects only)
226 int index = (object_id - 0x100) & 0x3F;
227 int tile_ptr = kRoomObjectSubtype2 + (index * 2);
228
229 if (tile_ptr + 1 >= (int)rom_->size()) {
230 return absl::OutOfRangeError(
231 absl::StrFormat("Tile pointer out of range: %#06x", tile_ptr));
232 }
233
234 // Read tile data pointer
235 uint8_t low = rom_->data()[tile_ptr];
236 uint8_t high = rom_->data()[tile_ptr + 1];
237 int tile_data_ptr = kRoomObjectTileAddress + ((high << 8) | low);
238
239 // Determine tile count based on object ID
240 int tile_count = GetSubtype2TileCount(object_id);
241
242 // DEBUG: Log corner tile loading (0x100-0x103)
243 bool is_corner = (object_id >= 0x100 && object_id <= 0x103);
244 if (is_corner) {
245 LOG_DEBUG("ObjectParser",
246 "ParseSubtype2: CORNER obj=0x%03X index=%d tile_ptr=0x%04X",
247 object_id, index, tile_ptr);
248 LOG_DEBUG("ObjectParser",
249 " ROM[0x%04X..0x%04X]=0x%02X 0x%02X offset=0x%04X", tile_ptr,
250 tile_ptr + 1, low, high, (high << 8) | low);
251 LOG_DEBUG(
252 "ObjectParser", " tile_data_ptr=0x%04X+0x%04X=0x%04X (tile_count=%d)",
253 kRoomObjectTileAddress, (high << 8) | low, tile_data_ptr, tile_count);
254
255 // Show first 2 tile words
256 if (tile_data_ptr >= 0 && tile_data_ptr + 4 < (int)rom_->size()) {
257 uint16_t tw0 =
258 rom_->data()[tile_data_ptr] | (rom_->data()[tile_data_ptr + 1] << 8);
259 uint16_t tw1 = rom_->data()[tile_data_ptr + 2] |
260 (rom_->data()[tile_data_ptr + 3] << 8);
261 LOG_DEBUG("ObjectParser", " First 2 tiles: $%04X(id=%d) $%04X(id=%d)",
262 tw0, tw0 & 0x3FF, tw1, tw1 & 0x3FF);
263 }
264 }
265
266 return ReadTileData(tile_data_ptr, tile_count);
267}
268
269absl::StatusOr<std::vector<gfx::TileInfo>> ObjectParser::ParseSubtype3(
270 int16_t object_id) {
271 // Type 3 object IDs are 0xF80-0xFFF (128 objects)
272 // Table index should be 0-127, calculated by subtracting base offset 0xF80
273 int index = (object_id - 0xF80) & 0x7F;
274 int tile_ptr = kRoomObjectSubtype3 + (index * 2);
275
276 if (tile_ptr + 1 >= (int)rom_->size()) {
277 return absl::OutOfRangeError(
278 absl::StrFormat("Tile pointer out of range: %#06x", tile_ptr));
279 }
280
281 // Read tile data pointer
282 uint8_t low = rom_->data()[tile_ptr];
283 uint8_t high = rom_->data()[tile_ptr + 1];
284 int tile_data_ptr = kRoomObjectTileAddress + ((high << 8) | low);
285
286 // Determine tile count based on object ID
287 int tile_count = GetSubtype3TileCount(object_id);
288 return ReadTileData(tile_data_ptr, tile_count);
289}
290
291absl::StatusOr<std::vector<gfx::TileInfo>> ObjectParser::ReadTileData(
292 int address, int tile_count) {
293 // Each tile is stored as a 16-bit word (2 bytes), not 8 bytes!
294 // ZScream: tiles.Add(new Tile(ROM.DATA[pos + ((i * 2))], ROM.DATA[pos + ((i *
295 // 2)) + 1]));
296 if (address < 0 || address + (tile_count * 2) >= (int)rom_->size()) {
297 return absl::OutOfRangeError(
298 absl::StrFormat("Tile data address out of range: %#06x", address));
299 }
300
301 std::vector<gfx::TileInfo> tiles;
302 tiles.reserve(tile_count);
303
304 // DEBUG: Log first tile read
305 static int debug_read_count = 0;
306 bool should_log = (debug_read_count < 3);
307
308 for (int i = 0; i < tile_count; i++) {
309 int tile_offset = address + (i * 2); // 2 bytes per tile word
310
311 // Read 1 word (2 bytes) per tile - this is the SNES tile format
312 uint16_t tile_word =
313 rom_->data()[tile_offset] | (rom_->data()[tile_offset + 1] << 8);
314
315 auto tile_info = gfx::WordToTileInfo(tile_word);
316 tiles.push_back(tile_info);
317
318 // DEBUG: Log first few tiles
319 if (should_log && i < 4) {
320 LOG_DEBUG("ObjectParser",
321 "ReadTile[%d]: addr=0x%06X word=0x%04X id=0x%03X pal=%d "
322 "mirror=(h:%d,v:%d)",
323 i, tile_offset, tile_word, tile_info.id_, tile_info.palette_,
324 tile_info.horizontal_mirror_, tile_info.vertical_mirror_);
325 }
326 }
327
328 if (should_log) {
329 LOG_DEBUG("ObjectParser",
330 "ReadTileData: addr=0x%06X count=%d loaded %zu tiles", address,
331 tile_count, tiles.size());
332 debug_read_count++;
333 }
334
335 return tiles;
336}
337
338int ObjectParser::GetSubtype2TileCount(int16_t object_id) const {
339 // 4x4 corners (0x100-0x10F): 16 tiles (32 bytes)
340 // These are RoomDraw_4x4 and RoomDraw_4x4Corner_BothBG routines
341 if (object_id >= 0x100 && object_id <= 0x10F) {
342 return 16;
343 }
344 // Weird corners (0x110-0x117): 12 tiles (24 bytes)
345 // These are RoomDraw_WeirdCornerBottom_BothBG and RoomDraw_WeirdCornerTop_BothBG
346 if (object_id >= 0x110 && object_id <= 0x117) {
347 return 12;
348 }
349 // Default: 8 tiles for other subtype 2 objects
350 return 8;
351}
352
353int ObjectParser::GetSubtype3TileCount(int16_t object_id) const {
354 // BigChest (0xFB1 = ASM 0x231) and OpenBigChest (0xFB2 = ASM 0x232): 12 tiles
355 // These use RoomDraw_1x3N_rightwards with N=4 (4 columns × 3 rows)
356 if (object_id == 0xFB1 || object_id == 0xFB2) {
357 return 12;
358 }
359 // TableRock4x3 variants (0xF94, 0xFCE, 0xFE7-0xFE8, 0xFEC-0xFED): 12 tiles
360 if (object_id == 0xF94 || object_id == 0xFCE ||
361 (object_id >= 0xFE7 && object_id <= 0xFE8) ||
362 (object_id >= 0xFEC && object_id <= 0xFED)) {
363 return 12;
364 }
365 // 4x4 pattern objects: 16 tiles
366 // (0xFC8 = 0x248, 0xFE6 = 0x266, 0xFEB = 0x26B, 0xFFA = 0x27A)
367 if (object_id == 0xFC8 || object_id == 0xFE6 || object_id == 0xFEB ||
368 object_id == 0xFFA) {
369 return 16;
370 }
371 // Default: 8 tiles for most subtype 3 objects
372 return 8;
373}
374
375int ObjectParser::DetermineSubtype(int16_t object_id) const {
376 // Type 3 IDs from decoding are 0xF80-0xFFF (b3 0xF8-0xFF shifted).
377 if (object_id >= 0xF80) {
378 return 3;
379 } else if (object_id >= 0x100) {
380 return 2;
381 } else {
382 return 1;
383 }
384}
385
387 ObjectDrawInfo info;
388
389 // Map object ID to draw routine based on ZScream's subtype1_routines table
390 // This is based on the DungeonObjectData.cs mapping from ZScream
391
392 if (object_id == 0x00) {
393 info.draw_routine_id = 0; // RoomDraw_Rightwards2x2_1to15or32
394 info.routine_name = "Rightwards2x2_1to15or32";
395 info.tile_count = 4;
396 info.is_horizontal = true;
397 } else if (object_id >= 0x01 && object_id <= 0x02) {
398 info.draw_routine_id = 1; // RoomDraw_Rightwards2x4_1to15or26
399 info.routine_name = "Rightwards2x4_1to15or26";
400 info.tile_count = 8;
401 info.is_horizontal = true;
402 } else if (object_id >= 0x03 && object_id <= 0x04) {
403 info.draw_routine_id = 2; // RoomDraw_Rightwards2x4spaced4_1to16
404 info.routine_name = "Rightwards2x4spaced4_1to16";
405 info.tile_count = 8;
406 info.is_horizontal = true;
407 } else if (object_id >= 0x05 && object_id <= 0x06) {
408 info.draw_routine_id = 3; // RoomDraw_Rightwards2x4spaced4_1to16_BothBG
409 info.routine_name = "Rightwards2x4spaced4_1to16_BothBG";
410 info.tile_count = 8;
411 info.is_horizontal = true;
412 info.both_layers = true;
413 } else if (object_id >= 0x07 && object_id <= 0x08) {
414 info.draw_routine_id = 4; // RoomDraw_Rightwards2x2_1to16
415 info.routine_name = "Rightwards2x2_1to16";
416 info.tile_count = 4;
417 info.is_horizontal = true;
418 } else if (object_id == 0x09) {
419 info.draw_routine_id = 5; // RoomDraw_DiagonalAcute_1to16
420 info.routine_name = "DiagonalAcute_1to16";
421 info.tile_count = 5;
422 info.is_horizontal = false;
423 } else if (object_id >= 0x0A && object_id <= 0x0B) {
424 info.draw_routine_id = 6; // RoomDraw_DiagonalGrave_1to16
425 info.routine_name = "DiagonalGrave_1to16";
426 info.tile_count = 5;
427 info.is_horizontal = false;
428 } else if (object_id >= 0x0C && object_id <= 0x0D) {
429 info.draw_routine_id = 17; // RoomDraw_DiagonalAcute_1to16_BothBG
430 info.routine_name = "DiagonalAcute_1to16_BothBG";
431 info.tile_count = 5;
432 info.is_horizontal = false;
433 info.both_layers = true;
434 } else if (object_id >= 0x0E && object_id <= 0x0F) {
435 info.draw_routine_id = 18; // RoomDraw_DiagonalGrave_1to16_BothBG
436 info.routine_name = "DiagonalGrave_1to16_BothBG";
437 info.tile_count = 5;
438 info.is_horizontal = false;
439 info.both_layers = true;
440 } else if (object_id >= 0x10 && object_id <= 0x11) {
441 info.draw_routine_id = 17; // RoomDraw_DiagonalAcute_1to16_BothBG
442 info.routine_name = "DiagonalAcute_1to16_BothBG";
443 info.tile_count = 5;
444 info.is_horizontal = false;
445 info.both_layers = true;
446 } else if (object_id >= 0x12 && object_id <= 0x13) {
447 info.draw_routine_id = 18; // RoomDraw_DiagonalGrave_1to16_BothBG
448 info.routine_name = "DiagonalGrave_1to16_BothBG";
449 info.tile_count = 5;
450 info.is_horizontal = false;
451 info.both_layers = true;
452 } else if (object_id >= 0x14 && object_id <= 0x15) {
453 info.draw_routine_id = 17; // RoomDraw_DiagonalAcute_1to16_BothBG
454 info.routine_name = "DiagonalAcute_1to16_BothBG";
455 info.tile_count = 5;
456 info.is_horizontal = false;
457 info.both_layers = true;
458 } else if (object_id >= 0x16 && object_id <= 0x17) {
459 info.draw_routine_id = 18; // RoomDraw_DiagonalGrave_1to16_BothBG
460 info.routine_name = "DiagonalGrave_1to16_BothBG";
461 info.tile_count = 5;
462 info.is_horizontal = false;
463 info.both_layers = true;
464 } else if (object_id >= 0x18 && object_id <= 0x19) {
465 info.draw_routine_id = 17; // RoomDraw_DiagonalAcute_1to16_BothBG
466 info.routine_name = "DiagonalAcute_1to16_BothBG";
467 info.tile_count = 5;
468 info.is_horizontal = false;
469 info.both_layers = true;
470 } else if (object_id >= 0x1A && object_id <= 0x1B) {
471 info.draw_routine_id = 18; // RoomDraw_DiagonalGrave_1to16_BothBG
472 info.routine_name = "DiagonalGrave_1to16_BothBG";
473 info.tile_count = 5;
474 info.is_horizontal = false;
475 info.both_layers = true;
476 } else if (object_id >= 0x1C && object_id <= 0x1D) {
477 info.draw_routine_id = 17; // RoomDraw_DiagonalAcute_1to16_BothBG
478 info.routine_name = "DiagonalAcute_1to16_BothBG";
479 info.tile_count = 5;
480 info.is_horizontal = false;
481 info.both_layers = true;
482 } else if (object_id >= 0x1E && object_id <= 0x1F) {
483 info.draw_routine_id = 18; // RoomDraw_DiagonalGrave_1to16_BothBG
484 info.routine_name = "DiagonalGrave_1to16_BothBG";
485 info.tile_count = 5;
486 info.is_horizontal = false;
487 info.both_layers = true;
488 } else if (object_id == 0x20) {
489 info.draw_routine_id = 17; // RoomDraw_DiagonalAcute_1to16_BothBG
490 info.routine_name = "DiagonalAcute_1to16_BothBG";
491 info.tile_count = 5;
492 info.is_horizontal = false;
493 info.both_layers = true;
494 } else if (object_id == 0x21) {
495 info.draw_routine_id = 20; // RoomDraw_Rightwards1x2_1to16_plus2
496 info.routine_name = "Rightwards1x2_1to16_plus2";
497 info.tile_count = 2;
498 info.is_horizontal = true;
499 } else if (object_id == 0x22) {
500 info.draw_routine_id = 20; // RoomDraw_Rightwards1x2_1to16_plus2
501 info.routine_name = "Rightwards1x2_1to16_plus2";
502 info.tile_count = 2;
503 info.is_horizontal = true;
504 } else if (object_id >= 0x23 && object_id <= 0x24) {
505 info.draw_routine_id = 21; // RoomDraw_RightwardsHasEdge1x1_1to16_plus3
506 info.routine_name = "RightwardsHasEdge1x1_1to16_plus3";
507 info.tile_count = 1;
508 info.is_horizontal = true;
509 } else if (object_id >= 0x25 && object_id <= 0x26) {
510 info.draw_routine_id = 22; // RoomDraw_RightwardsHasEdge1x1_1to16_plus2
511 info.routine_name = "RightwardsHasEdge1x1_1to16_plus2";
512 info.tile_count = 1;
513 info.is_horizontal = true;
514 } else if (object_id == 0x27) {
515 info.draw_routine_id = 23; // RoomDraw_RightwardsTopCorners1x2_1to16_plus13
516 info.routine_name = "RightwardsTopCorners1x2_1to16_plus13";
517 info.tile_count = 2;
518 info.is_horizontal = true;
519 } else if (object_id == 0x28) {
520 info.draw_routine_id =
521 24; // RoomDraw_RightwardsBottomCorners1x2_1to16_plus13
522 info.routine_name = "RightwardsBottomCorners1x2_1to16_plus13";
523 info.tile_count = 2;
524 info.is_horizontal = true;
525 } else if (object_id >= 0x29 && object_id <= 0x2E) {
526 info.draw_routine_id = 22; // RoomDraw_RightwardsHasEdge1x1_1to16_plus2
527 info.routine_name = "RightwardsHasEdge1x1_1to16_plus2";
528 info.tile_count = 1;
529 info.is_horizontal = true;
530 } else if (object_id == 0x2F) {
531 info.draw_routine_id = 23; // RoomDraw_RightwardsTopCorners1x2_1to16_plus13
532 info.routine_name = "RightwardsTopCorners1x2_1to16_plus13";
533 info.tile_count = 2;
534 info.is_horizontal = true;
535 } else if (object_id == 0x30) {
536 info.draw_routine_id =
537 24; // RoomDraw_RightwardsBottomCorners1x2_1to16_plus13
538 info.routine_name = "RightwardsBottomCorners1x2_1to16_plus13";
539 info.tile_count = 2;
540 info.is_horizontal = true;
541 } else if (object_id >= 0x31 && object_id <= 0x32) {
542 info.draw_routine_id = 14; // CustomDraw
543 info.routine_name = "CustomDraw";
544 info.tile_count = 1;
545 } else if (object_id == 0x33) {
546 info.draw_routine_id = 16; // RoomDraw_Rightwards4x4_1to16
547 info.routine_name = "Rightwards4x4_1to16";
548 info.tile_count = 16;
549 info.is_horizontal = true;
550 } else if (object_id == 0x34) {
551 info.draw_routine_id = 25; // RoomDraw_Rightwards1x1Solid_1to16_plus3
552 info.routine_name = "Rightwards1x1Solid_1to16_plus3";
553 info.tile_count = 1;
554 info.is_horizontal = true;
555 } else if (object_id == 0x35) {
556 info.draw_routine_id = 26; // RoomDraw_DoorSwitcherer
557 info.routine_name = "DoorSwitcherer";
558 info.tile_count = 1;
559 } else if (object_id >= 0x36 && object_id <= 0x37) {
560 info.draw_routine_id = 27; // RoomDraw_RightwardsDecor4x4spaced2_1to16
561 info.routine_name = "RightwardsDecor4x4spaced2_1to16";
562 info.tile_count = 16;
563 info.is_horizontal = true;
564 } else if (object_id == 0x38) {
565 info.draw_routine_id = 28; // RoomDraw_RightwardsStatue2x3spaced2_1to16
566 info.routine_name = "RightwardsStatue2x3spaced2_1to16";
567 info.tile_count = 6;
568 info.is_horizontal = true;
569 } else if (object_id == 0x39 || object_id == 0x3D) {
570 info.draw_routine_id = 29; // RoomDraw_RightwardsPillar2x4spaced4_1to16
571 info.routine_name = "RightwardsPillar2x4spaced4_1to16";
572 info.tile_count = 8;
573 info.is_horizontal = true;
574 } else if (object_id >= 0x3A && object_id <= 0x3B) {
575 info.draw_routine_id = 30; // RoomDraw_RightwardsDecor4x3spaced4_1to16
576 info.routine_name = "RightwardsDecor4x3spaced4_1to16";
577 info.tile_count = 12;
578 info.is_horizontal = true;
579 } else if (object_id == 0x3C) {
580 info.draw_routine_id = 31; // RoomDraw_RightwardsDoubled2x2spaced2_1to16
581 info.routine_name = "RightwardsDoubled2x2spaced2_1to16";
582 info.tile_count = 8;
583 info.is_horizontal = true;
584 } else if (object_id == 0x3E) {
585 info.draw_routine_id = 32; // RoomDraw_RightwardsDecor2x2spaced12_1to16
586 info.routine_name = "RightwardsDecor2x2spaced12_1to16";
587 info.tile_count = 4;
588 info.is_horizontal = true;
589 } else if (object_id >= 0x3F && object_id <= 0x40) {
590 info.draw_routine_id =
591 22; // RoomDraw_RightwardsHasEdge1x1_1to16_plus2 (variant)
592 info.routine_name = "RightwardsHasEdge1x1_1to16_plus2";
593 info.tile_count = 1;
594 info.is_horizontal = true;
595 } else if (object_id >= 0x40 && object_id <= 0x4F) {
596 info.draw_routine_id = 19; // RoomDraw_Corner4x4 (Type 2 corners)
597 info.routine_name = "Corner4x4";
598 info.tile_count = 16;
599 info.is_horizontal = true;
600 } else if (object_id >= 0x60 && object_id <= 0x6F) {
601 // Vertical objects (Subtype 1)
602 if (object_id == 0x60) {
603 info.draw_routine_id = 7; // RoomDraw_Downwards2x2_1to15or32
604 info.routine_name = "Downwards2x2_1to15or32";
605 info.tile_count = 4;
606 info.is_horizontal = false;
607 } else if (object_id >= 0x61 && object_id <= 0x62) {
608 info.draw_routine_id = 8; // RoomDraw_Downwards4x2_1to15or26
609 info.routine_name = "Downwards4x2_1to15or26";
610 info.tile_count = 8;
611 info.is_horizontal = false;
612 } else if (object_id >= 0x63 && object_id <= 0x64) {
613 info.draw_routine_id = 9; // RoomDraw_Downwards4x2_1to16_BothBG
614 info.routine_name = "Downwards4x2_1to16_BothBG";
615 info.tile_count = 8;
616 info.is_horizontal = false;
617 info.both_layers = true;
618 } else if (object_id >= 0x65 && object_id <= 0x66) {
619 info.draw_routine_id = 10; // RoomDraw_DownwardsDecor4x2spaced4_1to16
620 info.routine_name = "DownwardsDecor4x2spaced4_1to16";
621 info.tile_count = 8;
622 info.is_horizontal = false;
623 } else if (object_id >= 0x67 && object_id <= 0x68) {
624 info.draw_routine_id = 11; // RoomDraw_Downwards2x2_1to16
625 info.routine_name = "Downwards2x2_1to16";
626 info.tile_count = 4;
627 info.is_horizontal = false;
628 } else if (object_id == 0x69) {
629 info.draw_routine_id = 12; // RoomDraw_DownwardsHasEdge1x1_1to16_plus3
630 info.routine_name = "DownwardsHasEdge1x1_1to16_plus3";
631 info.tile_count = 1;
632 info.is_horizontal = false;
633 } else if (object_id >= 0x6A && object_id <= 0x6B) {
634 info.draw_routine_id = 13; // RoomDraw_DownwardsEdge1x1_1to16
635 info.routine_name = "DownwardsEdge1x1_1to16";
636 info.tile_count = 1;
637 info.is_horizontal = false;
638 } else if (object_id == 0x6C) {
639 info.draw_routine_id =
640 14; // RoomDraw_DownwardsLeftCorners2x1_1to16_plus12
641 info.routine_name = "DownwardsLeftCorners2x1_1to16_plus12";
642 info.tile_count = 2;
643 info.is_horizontal = false;
644 } else if (object_id == 0x6D) {
645 info.draw_routine_id =
646 15; // RoomDraw_DownwardsRightCorners2x1_1to16_plus12
647 info.routine_name = "DownwardsRightCorners2x1_1to16_plus12";
648 info.tile_count = 2;
649 info.is_horizontal = false;
650 } else {
651 info.draw_routine_id = 16; // Default
652 info.routine_name = "DefaultSolid";
653 info.tile_count = 1;
654 }
655 } else if (object_id >= 0x100 && object_id <= 0x10F) {
656 info.draw_routine_id = 16; // RoomDraw_Rightwards4x4_1to16 (Type 2)
657 info.routine_name = "Rightwards4x4_1to16";
658 info.tile_count = 16;
659 info.is_horizontal = true;
660 } else {
661 // Default to simple 1x1 solid for unmapped objects
662 info.draw_routine_id = 25; // Use solid block routine (0x34)
663 info.routine_name = "DefaultSolid";
664 info.tile_count = 1;
665 info.is_horizontal = true;
666 }
667
668 return info;
669}
670
671} // namespace zelda3
672} // namespace yaze
auto data() const
Definition rom.h:135
auto size() const
Definition rom.h:134
absl::StatusOr< ObjectSubtypeInfo > GetObjectSubtype(int16_t object_id)
Get object subtype information.
absl::StatusOr< ObjectRoutineInfo > ParseObjectRoutine(int16_t object_id)
Parse object routine data.
absl::StatusOr< ObjectSizeInfo > ParseObjectSize(int16_t object_id, uint8_t size_byte)
Parse object size and orientation.
int GetSubtype3TileCount(int16_t object_id) const
Get tile count for subtype 3 objects.
absl::StatusOr< std::vector< gfx::TileInfo > > ParseSubtype2(int16_t object_id)
Parse subtype 2 objects (0x100-0x1FF)
absl::StatusOr< std::vector< gfx::TileInfo > > ParseObject(int16_t object_id)
Parse object data directly from ROM.
int GetSubtype2TileCount(int16_t object_id) const
Get tile count for subtype 2 objects.
absl::StatusOr< std::vector< gfx::TileInfo > > ParseSubtype1(int16_t object_id)
Parse subtype 1 objects (0x00-0xFF)
absl::StatusOr< std::vector< gfx::TileInfo > > ParseSubtype3(int16_t object_id)
Parse subtype 3 objects (0x200+)
absl::StatusOr< std::vector< gfx::TileInfo > > ReadTileData(int address, int tile_count)
Read tile data from ROM.
ObjectDrawInfo GetObjectDrawInfo(int16_t object_id) const
Get draw routine information for an object.
int DetermineSubtype(int16_t object_id) const
Determine object subtype from ID.
#define LOG_DEBUG(category, format,...)
Definition log.h:103
TileInfo WordToTileInfo(uint16_t word)
Definition snes_tile.cc:378
constexpr int kRoomObjectSubtype3
Definition room_object.h:46
constexpr int kRoomObjectSubtype1
Definition room_object.h:44
constexpr int kRoomObjectSubtype2
Definition room_object.h:45
constexpr int kRoomObjectTileAddress
Definition room_object.h:47
Draw routine information for object rendering.
Object routine information.
Object size and orientation information.
Object subtype information.