3#include "absl/strings/str_format.h"
23 if (
id >= 0xA5 &&
id <= 0xAC)
25 if (
id == 0xC2 ||
id == 0xC3)
27 if (
id == 0xC6 ||
id == 0xD7 ||
id == 0xD9)
41 return absl::FailedPreconditionError(
"ROM not loaded");
45 layout_id >=
static_cast<int>(kRoomLayoutPointers.size())) {
46 return absl::InvalidArgumentError(
47 absl::StrFormat(
"Invalid layout id %d", layout_id));
50 uint32_t snes_addr = kRoomLayoutPointers[layout_id];
51 int pc_addr =
SnesToPc(
static_cast<int>(snes_addr));
52 if (pc_addr < 0 || pc_addr >=
static_cast<int>(
rom_->
size())) {
53 return absl::OutOfRangeError(
54 absl::StrFormat(
"Layout pointer %d out of range", layout_id));
63 if (!addr_result.ok()) {
64 return addr_result.status();
67 int pos = addr_result.value();
71 LOG_DEBUG(
"RoomLayout",
"Loading layout %d from PC address 0x%05X", layout_id,
75 while (pos + 2 <
static_cast<int>(
rom_->
size())) {
76 uint8_t b1 = rom_data[pos];
77 uint8_t b2 = rom_data[pos + 1];
79 if (b1 == 0xFF && b2 == 0xFF) {
82 "Layout %d terminated at pos=0x%05X after %d objects",
83 layout_id, pos, obj_index);
87 if (pos + 2 >=
static_cast<int>(
rom_->
size())) {
91 uint8_t b3 = rom_data[pos + 2];
95 b1, b2, b3,
static_cast<uint8_t
>(layer));
99 if (IsPitOrMaskObject(obj.
id_)) {
101 LOG_DEBUG(
"RoomLayout",
"Pit/mask object 0x%03X assigned to BG2 layer",
110 "Layout %d obj[%d]: bytes=[%02X,%02X,%02X] -> id=0x%03X x=%d "
111 "y=%d size=%d tiles=%zu",
112 layout_id, obj_index, b1, b2, b3, obj.
id_, obj.
x_, obj.
y_,
117 LOG_DEBUG(
"RoomLayout",
"Layout %d loaded with %zu objects", layout_id,
120 return absl::OkStatus();
129 return absl::FailedPreconditionError(
"ROM not loaded");
133 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.