yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
room_header_destination.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_ROOM_HEADER_DESTINATION_H_
2#define YAZE_ZELDA3_DUNGEON_ROOM_HEADER_DESTINATION_H_
3
4#include <cstdint>
5
6namespace yaze::zelda3 {
7
8// Room headers store stair and holewarp destinations as one byte. The game
9// writes that byte to $A0 in 8-bit mode and keeps $A1, the high byte of the
10// current room:
11// stairs $01:C3D0 LDA.l $7EC001,X / $01:C3D4 STA.b $A0
12// pits $07:94BA LDA.l $7EC000 / $07:94BE STA.b $A0
13// warp tile $07:D146 LDA.l $7EC000 / $07:D14A STA.b $A0
14// So a stair byte $1D in room $119 leads to $11D, not $01D.
15constexpr int ResolveHeaderDestinationRoom(int source_room_id,
16 uint8_t header_byte) {
17 return (source_room_id & 0xFF00) | header_byte;
18}
19
20// Inverse of ResolveHeaderDestinationRoom: the header byte that reaches
21// `destination_room_id` from `source_room_id`, or -1 when the destination is
22// on another $A1 page (0x000-0x0FF vs 0x100-0x1FF) and cannot be encoded.
23constexpr int EncodeHeaderDestinationRoom(int source_room_id,
24 int destination_room_id) {
25 if (destination_room_id < 0 ||
26 (destination_room_id & 0xFF00) != (source_room_id & 0xFF00)) {
27 return -1;
28 }
29 return destination_room_id & 0xFF;
30}
31
32} // namespace yaze::zelda3
33
34#endif // YAZE_ZELDA3_DUNGEON_ROOM_HEADER_DESTINATION_H_
Zelda 3 specific classes and functions.
constexpr int ResolveHeaderDestinationRoom(int source_room_id, uint8_t header_byte)
constexpr int EncodeHeaderDestinationRoom(int source_room_id, int destination_room_id)