3#include "absl/strings/str_format.h"
18 return absl::FailedPreconditionError(
"ROM not loaded");
22 layout_id >=
static_cast<int>(kRoomLayoutPointers.size())) {
23 return absl::InvalidArgumentError(
24 absl::StrFormat(
"Invalid layout id %d", layout_id));
27 uint32_t snes_addr = kRoomLayoutPointers[layout_id];
28 int pc_addr =
SnesToPc(
static_cast<int>(snes_addr));
29 if (pc_addr < 0 || pc_addr >=
static_cast<int>(
rom_->
size())) {
30 return absl::OutOfRangeError(
31 absl::StrFormat(
"Layout pointer %d out of range", layout_id));
40 if (!addr_result.ok()) {
41 return addr_result.status();
44 int pos = addr_result.value();
49 printf(
"[RoomLayout] Loading layout %d from PC address 0x%05X\n",
52 LOG_DEBUG(
"[RoomLayout]",
"Loading layout %d from PC address 0x%05X",
56 while (pos + 2 <
static_cast<int>(
rom_->
size())) {
57 uint8_t b1 = rom_data[pos];
58 uint8_t b2 = rom_data[pos + 1];
60 if (b1 == 0xFF && b2 == 0xFF) {
64 printf(
"[RoomLayout] Layout %d terminated at pos=0x%05X after %d objects\n",
65 layout_id, pos, obj_index);
70 if (pos + 2 >=
static_cast<int>(
rom_->
size())) {
74 uint8_t b3 = rom_data[pos + 2];
78 b1, b2, b3,
static_cast<uint8_t
>(layer));
85 if (obj.
id_ == 0x001 || obj.
id_ == 0x002 ||
86 obj.
id_ == 0x061 || obj.
id_ == 0x062 ||
87 (obj.
id_ >= 0x100 && obj.
id_ <= 0x103)) {
88 printf(
"[RoomLayout] Layout %d obj[%d]: bytes=[%02X,%02X,%02X] -> id=0x%03X x=%d y=%d size=%d layer=%d tiles=%zu\n",
89 layout_id, obj_index, b1, b2, b3,
94 "Layout %d obj[%d]: bytes=[%02X,%02X,%02X] -> id=0x%03X x=%d y=%d size=%d layer=%d tiles=%zu",
95 layout_id, obj_index, b1, b2, b3,
100 printf(
"[RoomLayout] Layout %d loaded with %zu objects\n",
103 LOG_DEBUG(
"[RoomLayout]",
"Layout %d loaded with %zu objects",
106 return absl::OkStatus();
115 return absl::FailedPreconditionError(
"ROM not loaded");
119 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,...)
Zelda 3 specific classes and functions.
uint32_t SnesToPc(uint32_t addr) noexcept
Represents a group of palettes.