yaze
0.3.2
Link to the Past ROM Editor
Loading...
Searching...
No Matches
dungeon_torch_codec.h
Go to the documentation of this file.
1
#ifndef YAZE_ZELDA3_DUNGEON_DUNGEON_TORCH_CODEC_H_
2
#define YAZE_ZELDA3_DUNGEON_DUNGEON_TORCH_CODEC_H_
3
4
#include <cstdint>
5
6
namespace
yaze::zelda3
{
7
8
// Pure encode/decode helpers for entries in the lightable-torch table at
9
// `kTorchData`. `RoomDraw_LightableTorch` ($01:B509) tests bit 15 to select
10
// the lit tile data, then masks the word with `AND.w #$3FFF` before drawing.
11
// The retained bit 13 adds $2000 to the upper-layer $7E2000 tilemap base and
12
// therefore selects the lower/BG2 tilemap at $7E4000. Bit 14 is reserved by
13
// the torch table and must be preserved independently of the draw target.
14
//
15
// Word layout (high << 8 | low):
16
// bit 0 : unused (always 0; LSL-by-1 padding)
17
// bits 1..6 : px (6 bits, range 0..63)
18
// bits 7..12 : py (6 bits, range 0..63)
19
// bit 13 : draw target (0 = upper/BG1, 1 = lower/BG2)
20
// bit 14 : reserved (preserved on load/save)
21
// bit 15 : initially lit
22
//
23
// The codec represents the complete 6-bit coordinate fields. SaveAllTorches
24
// separately restricts editable 2x2 torch anchors to 0..62 so their art stays
25
// within the 64x64 room tilemap.
26
27
struct
LightableTorchEntry
{
28
uint8_t
px
= 0;
29
uint8_t
py
= 0;
30
uint8_t
draw_layer
= 0;
31
uint8_t
reserved
= 0;
32
bool
lit
=
false
;
33
};
34
35
struct
LightableTorchBytes
{
36
uint8_t
low
= 0;
37
uint8_t
high
= 0;
38
};
39
40
inline
LightableTorchEntry
DecodeLightableTorchEntry
(
41
const
LightableTorchBytes
& bytes) {
42
const
uint16_t word =
static_cast<
uint16_t
>
(bytes.
low
| (bytes.
high
<< 8));
43
return
LightableTorchEntry
{
44
.
px
=
static_cast<
uint8_t
>
((word >> 1) & 0x3F),
45
.py =
static_cast<
uint8_t
>
((word >> 7) & 0x3F),
46
.draw_layer =
static_cast<
uint8_t
>
((word >> 13) & 0x01),
47
.reserved =
static_cast<
uint8_t
>
((word >> 14) & 0x01),
48
.lit = (word & 0x8000) != 0,
49
};
50
}
51
52
inline
LightableTorchBytes
EncodeLightableTorchEntry
(
53
const
LightableTorchEntry
& entry) {
54
const
uint16_t word =
static_cast<
uint16_t
>
(
55
((entry.
px
& 0x3F) << 1) | ((entry.
py
& 0x3F) << 7) |
56
((entry.
draw_layer
& 0x01) << 13) | ((entry.
reserved
& 0x01) << 14) |
57
(entry.
lit
? 0x8000 : 0));
58
return
LightableTorchBytes
{
59
.
low
=
static_cast<
uint8_t
>
(word & 0xFF),
60
.high =
static_cast<
uint8_t
>
((word >> 8) & 0xFF),
61
};
62
}
63
64
}
// namespace yaze::zelda3
65
66
#endif
// YAZE_ZELDA3_DUNGEON_DUNGEON_TORCH_CODEC_H_
yaze::zelda3
Zelda 3 specific classes and functions.
Definition
dungeon_rendering_helpers.h:14
yaze::zelda3::DecodeLightableTorchEntry
LightableTorchEntry DecodeLightableTorchEntry(const LightableTorchBytes &bytes)
Definition
dungeon_torch_codec.h:40
yaze::zelda3::EncodeLightableTorchEntry
LightableTorchBytes EncodeLightableTorchEntry(const LightableTorchEntry &entry)
Definition
dungeon_torch_codec.h:52
yaze::zelda3::LightableTorchBytes
Definition
dungeon_torch_codec.h:35
yaze::zelda3::LightableTorchBytes::high
uint8_t high
Definition
dungeon_torch_codec.h:37
yaze::zelda3::LightableTorchBytes::low
uint8_t low
Definition
dungeon_torch_codec.h:36
yaze::zelda3::LightableTorchEntry
Definition
dungeon_torch_codec.h:27
yaze::zelda3::LightableTorchEntry::draw_layer
uint8_t draw_layer
Definition
dungeon_torch_codec.h:30
yaze::zelda3::LightableTorchEntry::lit
bool lit
Definition
dungeon_torch_codec.h:32
yaze::zelda3::LightableTorchEntry::py
uint8_t py
Definition
dungeon_torch_codec.h:29
yaze::zelda3::LightableTorchEntry::px
uint8_t px
Definition
dungeon_torch_codec.h:28
yaze::zelda3::LightableTorchEntry::reserved
uint8_t reserved
Definition
dungeon_torch_codec.h:31
src
zelda3
dungeon
dungeon_torch_codec.h
Generated by
1.10.0