3#include "absl/strings/str_format.h"
22 if (
id >= 0x9B &&
id <= 0xA6)
30 if (
id == 0xFBE ||
id == 0xFBF)
40 return absl::FailedPreconditionError(
"ROM not loaded");
44 layout_id >=
static_cast<int>(kRoomLayoutPointers.size())) {
45 return absl::InvalidArgumentError(
46 absl::StrFormat(
"Invalid layout id %d", layout_id));
49 uint32_t snes_addr = kRoomLayoutPointers[layout_id];
50 int pc_addr =
SnesToPc(
static_cast<int>(snes_addr));
51 if (pc_addr < 0 || pc_addr >=
static_cast<int>(
rom_->
size())) {
52 return absl::OutOfRangeError(
53 absl::StrFormat(
"Layout pointer %d out of range", layout_id));
62 if (!addr_result.ok()) {
63 return addr_result.status();
66 int pos = addr_result.value();
70 LOG_DEBUG(
"RoomLayout",
"Loading layout %d from PC address 0x%05X", layout_id,
74 while (pos + 2 <
static_cast<int>(
rom_->
size())) {
75 uint8_t b1 = rom_data[pos];
76 uint8_t b2 = rom_data[pos + 1];
78 if (b1 == 0xFF && b2 == 0xFF) {
81 "Layout %d terminated at pos=0x%05X after %d objects",
82 layout_id, pos, obj_index);
86 if (pos + 2 >=
static_cast<int>(
rom_->
size())) {
90 uint8_t b3 = rom_data[pos + 2];
94 b1, b2, b3,
static_cast<uint8_t
>(layer));
98 if (IsPitOrMaskObject(obj.
id_)) {
100 LOG_DEBUG(
"RoomLayout",
"Pit/mask object 0x%03X assigned to BG2 layer",
109 "Layout %d obj[%d]: bytes=[%02X,%02X,%02X] -> id=0x%03X x=%d "
110 "y=%d size=%d tiles=%zu",
111 layout_id, obj_index, b1, b2, b3, obj.
id_, obj.
x_, obj.
y_,
116 LOG_DEBUG(
"RoomLayout",
"Layout %d loaded with %zu objects", layout_id,
119 return absl::OkStatus();
128 return absl::FailedPreconditionError(
"ROM not loaded");
132 return absl::OkStatus();
Interface for accessing dungeon game state.
Draws dungeon objects to background buffers using game patterns.
absl::Status DrawObjectList(const std::vector< RoomObject > &objects, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group, const DungeonState *state=nullptr, gfx::BackgroundBuffer *layout_bg1=nullptr)
Draw all objects in a room.
std::vector< RoomObject > objects_
absl::Status Draw(int room_id, const uint8_t *gfx_data, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group, DungeonState *state) const
absl::StatusOr< int > GetLayoutAddress(int layout_id) const
absl::Status LoadLayout(int layout_id)
static RoomObject DecodeObjectFromBytes(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t layer)
const std::vector< gfx::TileInfo > & tiles() const
#define LOG_DEBUG(category, format,...)
bool IsPitOrMaskObject(int16_t id)
Zelda 3 specific classes and functions.
uint32_t SnesToPc(uint32_t addr) noexcept
Represents a group of palettes.