yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
room_entrance.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_DUNGEON_ROOM_ENTRANCE_H
2#define YAZE_APP_ZELDA3_DUNGEON_ROOM_ENTRANCE_H
3
4#include <cstdint>
5
6#include "app/rom.h"
7
8namespace yaze {
9namespace app {
10namespace zelda3 {
11namespace dungeon {
12
13// ============================================================================
14// Dungeon Entrances Related Variables
15// ============================================================================
16
17// 0x14577 word value for each room
18constexpr int kEntranceRoom = 0x14813;
19
20// 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR
21constexpr int kEntranceScrollEdge = 0x1491D; // 0x14681
22constexpr int kEntranceYScroll = 0x14D45; // 0x14AA9 2 bytes each room
23constexpr int kEntranceXScroll = 0x14E4F; // 0x14BB3 2 bytes
24constexpr int kEntranceYPosition = 0x14F59; // 0x14CBD 2bytes
25constexpr int kEntranceXPosition = 0x15063; // 0x14DC7 2bytes
26constexpr int kEntranceCameraYTrigger = 0x1516D; // 0x14ED1 2bytes
27constexpr int kEntranceCameraXTrigger = 0x15277; // 0x14FDB 2bytes
28
29constexpr int kEntranceBlockset = 0x15381; // 0x150E5 1byte
30constexpr int kEntranceFloor = 0x15406; // 0x1516A 1byte
31constexpr int kEntranceDungeon = 0x1548B; // 0x151EF 1byte (dungeon id)
32constexpr int kEntranceDoor = 0x15510; // 0x15274 1byte
33
34// 1 byte, ---b ---a b = bg2, a = need to check
35constexpr int kEntranceLadderBG = 0x15595; // 0x152F9
36constexpr int kEntrancescrolling = 0x1561A; // 0x1537E 1byte --h- --v-
37constexpr int kEntranceScrollQuadrant = 0x1569F; // 0x15403 1byte
38constexpr int kEntranceExit = 0x15724; // 0x15488 2byte word
39constexpr int kEntranceMusic = 0x1582E; // 0x15592
40
41// word value for each room
42constexpr int kStartingEntranceroom = 0x15B6E; // 0x158D2
43
44// 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR
45constexpr int kStartingEntranceScrollEdge = 0x15B7C; // 0x158E0
46constexpr int kStartingEntranceYScroll = 0x15BB4; // 0x14AA9 //2bytes each room
47constexpr int kStartingEntranceXScroll = 0x15BC2; // 0x14BB3 //2bytes
48constexpr int kStartingEntranceYPosition = 0x15BD0; // 0x14CBD 2bytes
49constexpr int kStartingEntranceXPosition = 0x15BDE; // 0x14DC7 2bytes
50constexpr int kStartingEntranceCameraYTrigger = 0x15BEC; // 0x14ED1 2bytes
51constexpr int kStartingEntranceCameraXTrigger = 0x15BFA; // 0x14FDB 2bytes
52
53constexpr int kStartingEntranceBlockset = 0x15C08; // 0x150E5 1byte
54constexpr int kStartingEntranceFloor = 0x15C0F; // 0x1516A 1byte
55constexpr int kStartingEntranceDungeon = 0x15C16; // 0x151EF 1byte (dungeon id)
56
57constexpr int kStartingEntranceDoor = 0x15C2B; // 0x15274 1byte
58
59// 1 byte, ---b ---a b = bg2, a = need to check
60constexpr int kStartingEntranceLadderBG = 0x15C1D; // 0x152F9
61// 1byte --h- --v-
62constexpr int kStartingEntrancescrolling = 0x15C24; // 0x1537E
63constexpr int kStartingEntranceScrollQuadrant = 0x15C2B; // 0x15403 1byte
64constexpr int kStartingEntranceexit = 0x15C32; // 0x15488 //2byte word
65constexpr int kStartingEntrancemusic = 0x15C4E; // 0x15592
66constexpr int kStartingEntranceentrance = 0x15C40;
67
68constexpr int items_data_start = 0xDDE9; // save purpose
69constexpr int items_data_end = 0xE6B2; // save purpose
70constexpr int initial_equipement = 0x271A6;
71
72// item id you get instead if you already have that item
73constexpr int chests_backupitems = 0x3B528;
74constexpr int chests_yoffset = 0x4836C;
75constexpr int chests_xoffset = 0x4836C + (76 * 1);
76constexpr int chests_itemsgfx = 0x4836C + (76 * 2);
77constexpr int chests_itemswide = 0x4836C + (76 * 3);
78constexpr int chests_itemsproperties = 0x4836C + (76 * 4);
79constexpr int chests_sramaddress = 0x4836C + (76 * 5);
80constexpr int chests_sramvalue = 0x4836C + (76 * 7);
81constexpr int chests_msgid = 0x442DD;
82
83constexpr int dungeons_startrooms = 0x7939;
84constexpr int dungeons_endrooms = 0x792D;
85constexpr int dungeons_bossrooms = 0x10954; // short value
86
87// Bed Related Values (Starting location)
88constexpr int bedPositionX = 0x039A37; // short value
89constexpr int bedPositionY = 0x039A32; // short value
90
91// short value (on 2 different bytes)
92constexpr int bedPositionResetXLow = 0x02DE53;
93constexpr int bedPositionResetXHigh = 0x02DE58;
94
95// short value (on 2 different bytes)
96constexpr int bedPositionResetYLow = 0x02DE5D;
97constexpr int bedPositionResetYHigh = 0x02DE62;
98
99constexpr int bedSheetPositionX = 0x0480BD; // short value
100constexpr int bedSheetPositionY = 0x0480B8; // short value
101
106 public:
107 RoomEntrance() = default;
108 RoomEntrance(Rom &rom, uint8_t entrance_id, bool is_spawn_point = false)
109 : entrance_id_(entrance_id) {
110 room_ =
111 static_cast<short>((rom[kEntranceRoom + (entrance_id * 2) + 1] << 8) +
112 rom[kEntranceRoom + (entrance_id * 2)]);
113 y_position_ = static_cast<ushort>(
114 (rom[kEntranceYPosition + (entrance_id * 2) + 1] << 8) +
115 rom[kEntranceYPosition + (entrance_id * 2)]);
116 x_position_ = static_cast<ushort>(
117 (rom[kEntranceXPosition + (entrance_id * 2) + 1] << 8) +
118 rom[kEntranceXPosition + (entrance_id * 2)]);
119 camera_x_ = static_cast<ushort>(
120 (rom[kEntranceXScroll + (entrance_id * 2) + 1] << 8) +
121 rom[kEntranceXScroll + (entrance_id * 2)]);
122 camera_y_ = static_cast<ushort>(
123 (rom[kEntranceYScroll + (entrance_id * 2) + 1] << 8) +
124 rom[kEntranceYScroll + (entrance_id * 2)]);
125 camera_trigger_y_ = static_cast<ushort>(
126 (rom[(kEntranceCameraYTrigger + (entrance_id * 2)) + 1] << 8) +
127 rom[kEntranceCameraYTrigger + (entrance_id * 2)]);
128 camera_trigger_x_ = static_cast<ushort>(
129 (rom[(kEntranceCameraXTrigger + (entrance_id * 2)) + 1] << 8) +
130 rom[kEntranceCameraXTrigger + (entrance_id * 2)]);
131 blockset_ = rom[kEntranceBlockset + entrance_id];
132 music_ = rom[kEntranceMusic + entrance_id];
133 dungeon_id_ = rom[kEntranceDungeon + entrance_id];
134 floor_ = rom[kEntranceFloor + entrance_id];
135 door_ = rom[kEntranceDoor + entrance_id];
136 ladder_bg_ = rom[kEntranceLadderBG + entrance_id];
137 scrolling_ = rom[kEntrancescrolling + entrance_id];
138 scroll_quadrant_ = rom[kEntranceScrollQuadrant + entrance_id];
139 exit_ =
140 static_cast<short>((rom[kEntranceExit + (entrance_id * 2) + 1] << 8) +
141 rom[kEntranceExit + (entrance_id * 2)]);
142
143 camera_boundary_qn_ = rom[kEntranceScrollEdge + 0 + (entrance_id * 8)];
144 camera_boundary_fn_ = rom[kEntranceScrollEdge + 1 + (entrance_id * 8)];
145 camera_boundary_qs_ = rom[kEntranceScrollEdge + 2 + (entrance_id * 8)];
146 camera_boundary_fs_ = rom[kEntranceScrollEdge + 3 + (entrance_id * 8)];
147 camera_boundary_qw_ = rom[kEntranceScrollEdge + 4 + (entrance_id * 8)];
148 camera_boundary_fw_ = rom[kEntranceScrollEdge + 5 + (entrance_id * 8)];
149 camera_boundary_qe_ = rom[kEntranceScrollEdge + 6 + (entrance_id * 8)];
150 camera_boundary_fe_ = rom[kEntranceScrollEdge + 7 + (entrance_id * 8)];
151
152 if (is_spawn_point) {
153 room_ = static_cast<short>(
154 (rom[kStartingEntranceroom + (entrance_id * 2) + 1] << 8) +
155 rom[kStartingEntranceroom + (entrance_id * 2)]);
156
157 y_position_ = static_cast<ushort>(
158 (rom[kStartingEntranceYPosition + (entrance_id * 2) + 1] << 8) +
159 rom[kStartingEntranceYPosition + (entrance_id * 2)]);
160
161 x_position_ = static_cast<ushort>(
162 (rom[kStartingEntranceXPosition + (entrance_id * 2) + 1] << 8) +
163 rom[kStartingEntranceXPosition + (entrance_id * 2)]);
164
165 camera_x_ = static_cast<ushort>(
166 (rom[kStartingEntranceXScroll + (entrance_id * 2) + 1] << 8) +
167 rom[kStartingEntranceXScroll + (entrance_id * 2)]);
168
169 camera_y_ = static_cast<ushort>(
170 (rom[kStartingEntranceYScroll + (entrance_id * 2) + 1] << 8) +
171 rom[kStartingEntranceYScroll + (entrance_id * 2)]);
172
173 camera_trigger_y_ = static_cast<ushort>(
174 (rom[kStartingEntranceCameraYTrigger + (entrance_id * 2) + 1] << 8) +
175 rom[kStartingEntranceCameraYTrigger + (entrance_id * 2)]);
176
177 camera_trigger_x_ = static_cast<ushort>(
178 (rom[kStartingEntranceCameraXTrigger + (entrance_id * 2) + 1] << 8) +
179 rom[kStartingEntranceCameraXTrigger + (entrance_id * 2)]);
180
181 blockset_ = rom[kStartingEntranceBlockset + entrance_id];
182 music_ = rom[kStartingEntrancemusic + entrance_id];
183 dungeon_id_ = rom[kStartingEntranceDungeon + entrance_id];
184 floor_ = rom[kStartingEntranceFloor + entrance_id];
185 door_ = rom[kStartingEntranceDoor + entrance_id];
186
187 ladder_bg_ = rom[kStartingEntranceLadderBG + entrance_id];
188 scrolling_ = rom[kStartingEntrancescrolling + entrance_id];
190
191 exit_ = static_cast<short>(
192 ((rom[kStartingEntranceexit + (entrance_id * 2) + 1] & 0x01) << 8) +
193 rom[kStartingEntranceexit + (entrance_id * 2)]);
194
196 rom[kStartingEntranceScrollEdge + 0 + (entrance_id * 8)];
198 rom[kStartingEntranceScrollEdge + 1 + (entrance_id * 8)];
200 rom[kStartingEntranceScrollEdge + 2 + (entrance_id * 8)];
202 rom[kStartingEntranceScrollEdge + 3 + (entrance_id * 8)];
204 rom[kStartingEntranceScrollEdge + 4 + (entrance_id * 8)];
206 rom[kStartingEntranceScrollEdge + 5 + (entrance_id * 8)];
208 rom[kStartingEntranceScrollEdge + 6 + (entrance_id * 8)];
210 rom[kStartingEntranceScrollEdge + 7 + (entrance_id * 8)];
211 }
212 }
213
214 absl::Status Save(Rom &rom, int entrance_id, bool is_spawn_point = false) {
215 if (!is_spawn_point) {
217 rom.WriteShort(kEntranceYPosition + (entrance_id * 2), y_position_));
219 rom.WriteShort(kEntranceXPosition + (entrance_id * 2), x_position_));
221 rom.WriteShort(kEntranceYScroll + (entrance_id * 2), camera_y_));
223 rom.WriteShort(kEntranceXScroll + (entrance_id * 2), camera_x_));
225 kEntranceCameraXTrigger + (entrance_id * 2), camera_trigger_x_));
227 kEntranceCameraYTrigger + (entrance_id * 2), camera_trigger_y_));
228 RETURN_IF_ERROR(rom.WriteShort(kEntranceExit + (entrance_id * 2), exit_));
229 RETURN_IF_ERROR(rom.Write(kEntranceBlockset + entrance_id,
230 (uint8_t)(blockset_ & 0xFF)));
232 rom.Write(kEntranceMusic + entrance_id, (uint8_t)(music_ & 0xFF)));
233 RETURN_IF_ERROR(rom.Write(kEntranceDungeon + entrance_id,
234 (uint8_t)(dungeon_id_ & 0xFF)));
236 rom.Write(kEntranceDoor + entrance_id, (uint8_t)(door_ & 0xFF)));
238 rom.Write(kEntranceFloor + entrance_id, (uint8_t)(floor_ & 0xFF)));
239 RETURN_IF_ERROR(rom.Write(kEntranceLadderBG + entrance_id,
240 (uint8_t)(ladder_bg_ & 0xFF)));
241 RETURN_IF_ERROR(rom.Write(kEntrancescrolling + entrance_id,
242 (uint8_t)(scrolling_ & 0xFF)));
244 (uint8_t)(scroll_quadrant_ & 0xFF)));
245 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 0 + (entrance_id * 8),
247 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 1 + (entrance_id * 8),
249 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 2 + (entrance_id * 8),
251 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 3 + (entrance_id * 8),
253 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 4 + (entrance_id * 8),
255 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 5 + (entrance_id * 8),
257 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 6 + (entrance_id * 8),
259 RETURN_IF_ERROR(rom.Write(kEntranceScrollEdge + 7 + (entrance_id * 8),
261 } else {
263 rom.WriteShort(kStartingEntranceroom + (entrance_id * 2), room_));
265 kStartingEntranceYPosition + (entrance_id * 2), y_position_));
267 kStartingEntranceXPosition + (entrance_id * 2), x_position_));
269 kStartingEntranceYScroll + (entrance_id * 2), camera_y_));
271 kStartingEntranceXScroll + (entrance_id * 2), camera_x_));
273 rom.WriteShort(kStartingEntranceCameraXTrigger + (entrance_id * 2),
276 rom.WriteShort(kStartingEntranceCameraYTrigger + (entrance_id * 2),
279 rom.WriteShort(kStartingEntranceexit + (entrance_id * 2), exit_));
281 (uint8_t)(blockset_ & 0xFF)));
283 (uint8_t)(music_ & 0xFF)));
285 (uint8_t)(dungeon_id_ & 0xFF)));
287 (uint8_t)(door_ & 0xFF)));
289 (uint8_t)(floor_ & 0xFF)));
291 (uint8_t)(ladder_bg_ & 0xFF)));
293 (uint8_t)(scrolling_ & 0xFF)));
295 (uint8_t)(scroll_quadrant_ & 0xFF)));
297 rom.Write(kStartingEntranceScrollEdge + 0 + (entrance_id * 8),
300 rom.Write(kStartingEntranceScrollEdge + 1 + (entrance_id * 8),
303 rom.Write(kStartingEntranceScrollEdge + 2 + (entrance_id * 8),
306 rom.Write(kStartingEntranceScrollEdge + 3 + (entrance_id * 8),
309 rom.Write(kStartingEntranceScrollEdge + 4 + (entrance_id * 8),
312 rom.Write(kStartingEntranceScrollEdge + 5 + (entrance_id * 8),
315 rom.Write(kStartingEntranceScrollEdge + 6 + (entrance_id * 8),
318 rom.Write(kStartingEntranceScrollEdge + 7 + (entrance_id * 8),
320 }
321 return absl::OkStatus();
322 }
323
324 uint16_t entrance_id_;
325 uint16_t x_position_;
326 uint16_t y_position_;
327 uint16_t camera_x_;
328 uint16_t camera_y_;
331
332 int16_t room_;
333 uint8_t blockset_;
334 uint8_t floor_;
335 uint8_t dungeon_id_;
336 uint8_t ladder_bg_;
337 uint8_t scrolling_;
339 int16_t exit_;
340 uint8_t music_;
341 uint8_t door_;
342
351};
352
353} // namespace dungeon
354} // namespace zelda3
355} // namespace app
356} // namespace yaze
357
358#endif // YAZE_APP_ZELDA3_DUNGEON_ROOM_ENTRANCE_H
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:136
absl::Status WriteShort(int addr, uint16_t value)
Definition rom.h:363
absl::Status Write(int addr, int value)
Definition rom.h:325
Dungeon Room Entrance or Spawn Point.
RoomEntrance(Rom &rom, uint8_t entrance_id, bool is_spawn_point=false)
absl::Status Save(Rom &rom, int entrance_id, bool is_spawn_point=false)
#define RETURN_IF_ERROR(expression)
Definition constants.h:62
unsigned short ushort
Definition constants.h:112
constexpr int kStartingEntrancescrolling
constexpr int kStartingEntranceYScroll
constexpr int chests_backupitems
constexpr int bedPositionResetXLow
constexpr int chests_sramaddress
constexpr int kStartingEntranceLadderBG
constexpr int kEntranceXPosition
constexpr int kEntranceLadderBG
constexpr int initial_equipement
constexpr int chests_itemsproperties
constexpr int kStartingEntranceXPosition
constexpr int kEntranceScrollEdge
constexpr int kStartingEntrancemusic
constexpr int kEntrancescrolling
constexpr int bedPositionResetYLow
constexpr int kStartingEntranceBlockset
constexpr int kStartingEntranceDoor
constexpr int bedSheetPositionX
constexpr int kEntranceScrollQuadrant
constexpr int kEntranceCameraYTrigger
constexpr int kStartingEntranceroom
constexpr int kStartingEntranceScrollQuadrant
constexpr int bedPositionResetXHigh
constexpr int kStartingEntranceScrollEdge
constexpr int kStartingEntranceXScroll
constexpr int kEntranceBlockset
constexpr int bedPositionResetYHigh
constexpr int dungeons_bossrooms
constexpr int kStartingEntranceCameraYTrigger
constexpr int kStartingEntranceDungeon
constexpr int kStartingEntranceFloor
constexpr int kEntranceCameraXTrigger
constexpr int dungeons_endrooms
constexpr int kStartingEntranceentrance
constexpr int kStartingEntranceexit
constexpr int kStartingEntranceCameraXTrigger
constexpr int dungeons_startrooms
constexpr int kStartingEntranceYPosition
constexpr int kEntranceYPosition
Definition common.cc:22