yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
pot_item_position.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_POT_ITEM_POSITION_H_
2#define YAZE_ZELDA3_DUNGEON_POT_ITEM_POSITION_H_
3
4#include <cstdint>
5#include <optional>
6
7namespace yaze::zelda3 {
8// Bank $01 stores the tilemap byte index in $0540 (e.g. $01B34C), with
9// bit 13 selecting the lower layer ($01B358). RevealPotItem ($01E6DD)
10// masks bit 15 before comparing that index. A 64-tile row is 128 bytes.
11// Preserve all non-coordinate bits, including unknown bit 0 and bit 14.
12inline constexpr uint16_t kPotItemCoordinateMask = 0x1FFE;
13constexpr int PotItemPixelX(uint16_t word) {
14 return ((word >> 1) & 63) * 8;
15}
16constexpr int PotItemPixelY(uint16_t word) {
17 return ((word >> 7) & 63) * 8;
18}
19constexpr std::optional<uint16_t> EncodePotItemPosition(int x, int y,
20 uint16_t original = 0) {
21 if (original == 0xFFFF || x < 0 || x > 504 || y < 0 || y > 504 ||
22 x % 8 != 0 || y % 8 != 0)
23 return std::nullopt;
24 const uint16_t word = static_cast<uint16_t>(
25 (original & ~kPotItemCoordinateMask) | ((y / 8) << 7) | ((x / 8) << 1));
26 // Never turn an authored entry into the end-of-list marker.
27 if (word == 0xFFFF)
28 return std::nullopt;
29 return word;
30}
31} // namespace yaze::zelda3
32#endif
Zelda 3 specific classes and functions.
constexpr int PotItemPixelX(uint16_t word)
constexpr uint16_t kPotItemCoordinateMask
constexpr std::optional< uint16_t > EncodePotItemPosition(int x, int y, uint16_t original=0)
constexpr int PotItemPixelY(uint16_t word)