yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
offsets.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
6
7namespace {
8
10 // Dungeon
11 DungeonOffsets{/*torches=*/0x2736A, /*torch_count=*/0x88C1},
12 // Overworld (unused placeholder)
13 OverworldOffsets{/*dummy=*/0x33333},
14 // Text
16 /*bank=*/0x0E,
17 /*dictionary=*/0x74703,
18 /*dictionary_bound=*/0x748D9,
19 /*param_counts=*/0x7536B,
20 /*region1=*/0xE0000,
21 /*region1_bound=*/0xE8000,
22 /*region2=*/0x75F40,
23 /*region2_bound=*/0x77400,
24 /*max_message_length=*/0xE00,
25 /*codes=*/
27 /*zchar_base=*/0x00,
28 /*zchar_bound=*/0x67,
29 /*command_base=*/0x67,
30 /*command_bound=*/0x80,
31 /*msg_terminator=*/0x7F,
32 /*region_switch=*/0x80,
33 /*dict_base=*/0x88,
34 /*dict_bound=*/0xEA,
35 /*abs_terminator=*/0xFF,
36 }},
37};
38
39} // namespace
40
41std::optional<RegionOffsets> GetRegionOffsets(Region region) {
42 switch (region) {
43 case Region::kUs:
44 return kUsOffsets;
45 default:
46 return std::nullopt;
47 }
48}
49
50bool ValidateOffsets(const RegionOffsets& offsets, size_t rom_size_bytes) {
51 const auto within = [rom_size_bytes](uint32_t addr) {
52 return addr < rom_size_bytes;
53 };
54
55 // Text bounds
56 const auto& t = offsets.text;
57 if (!(within(t.dictionary) && within(t.dictionary_bound) &&
58 within(t.param_counts) && within(t.region1) &&
59 within(t.region1_bound) && within(t.region2) &&
60 within(t.region2_bound))) {
61 return false;
62 }
63 if (!(t.dictionary < t.dictionary_bound &&
64 t.region1 < t.region1_bound && t.region2 < t.region2_bound)) {
65 return false;
66 }
67
68 // Codes sanity: base < bound
69 const auto& c = t.codes;
70 if (!(c.zchar_base <= c.zchar_bound && c.command_base <= c.command_bound &&
71 c.dict_base <= c.dict_bound)) {
72 return false;
73 }
74
75 // Dungeon torch offsets should also be in range.
76 const auto& d = offsets.dungeon;
77 if (!(within(d.torches) && within(d.torch_count))) {
78 return false;
79 }
80
81 return true;
82}
83
84} // namespace yaze::zelda3::formats
std::optional< RegionOffsets > GetRegionOffsets(Region region)
Definition offsets.cc:41
bool ValidateOffsets(const RegionOffsets &offsets, size_t rom_size_bytes)
Definition offsets.cc:50