yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
inventory.cc
Go to the documentation of this file.
1#include "inventory.h"
2
8#include "rom/rom.h"
9#include "rom/snes.h"
10
11namespace yaze {
12namespace zelda3 {
13
14absl::Status Inventory::Create(Rom* rom, GameData* game_data) {
15 if (!rom || !rom->is_loaded()) {
16 return absl::InvalidArgumentError("ROM is not loaded");
17 }
19 game_data_ = game_data;
20
21 // Build the tileset first (loads 2BPP graphics)
23
24 // Load item icons from ROM
26
27 // TODO(scawful): For now, create a simple display bitmap
28 // Future: Oracle of Secrets menu editor will handle full menu layout
29 data_.reserve(256 * 256);
30 for (int i = 0; i < 256 * 256; i++) {
31 data_.push_back(0xFF);
32 }
33
34 bitmap_.Create(256, 256, 8, data_);
36
37 // Queue texture creation via Arena's deferred system
39 &bitmap_);
40
41 return absl::OkStatus();
42}
43
45 data_.clear();
46 tilesheets_.clear();
47 test_.clear();
49 tiles_.clear();
50 item_icons_.clear();
52 game_data_ = nullptr;
53}
54
55absl::Status Inventory::BuildTileset(Rom* rom) {
56 tilesheets_.reserve(6 * 0x2000);
57 for (int i = 0; i < 6 * 0x2000; i++)
58 tilesheets_.push_back(0xFF);
60 std::vector<uint8_t> test;
61 for (int i = 0; i < 0x4000; i++) {
62 test_.push_back(tilesheets_[i]);
63 }
64 for (int i = 0x8000; i < +0x8000 + 0x2000; i++) {
65 test_.push_back(tilesheets_[i]);
66 }
67 tilesheets_bmp_.Create(128, 0x130, 64, test_);
68 if (!game_data_) {
69 return absl::FailedPreconditionError("GameData not set for Inventory");
70 }
71 auto& hud_pal_group = game_data_->palette_groups.hud;
72 palette_ = hud_pal_group[0];
74
75 // Queue texture creation via Arena's deferred system
78
79 return absl::OkStatus();
80}
81
82absl::Status Inventory::LoadItemIcons(Rom* rom) {
83 // Convert SNES address to PC address
84 int pc_addr = SnesToPc(kItemIconsPtr);
85
86 // Define icon categories and their ROM offsets (relative to kItemIconsPtr)
87 // Based on bank_0D.asm ItemIcons structure
88 struct IconDef {
89 int offset;
90 std::string name;
91 };
92
93 // Bow icons (.bows section)
94 std::vector<IconDef> bow_icons = {{0x00, "No bow"},
95 {0x08, "Empty bow"},
96 {0x10, "Bow and arrows"},
97 {0x18, "Empty silvers bow"},
98 {0x20, "Silver bow and arrows"}};
99
100 // Boomerang icons (.booms section)
101 std::vector<IconDef> boom_icons = {{0x28, "No boomerang"},
102 {0x30, "Blue boomerang"},
103 {0x38, "Red boomerang"}};
104
105 // Hookshot icons (.hook section)
106 std::vector<IconDef> hook_icons = {{0x40, "No hookshot"}, {0x48, "Hookshot"}};
107
108 // Bomb icons (.bombs section)
109 std::vector<IconDef> bomb_icons = {{0x50, "No bombs"}, {0x58, "Bombs"}};
110
111 // Load all icon categories
112 auto load_icons = [&](const std::vector<IconDef>& icons) -> absl::Status {
113 for (const auto& icon_def : icons) {
114 ItemIcon icon;
115 int icon_addr = pc_addr + icon_def.offset;
116
117 ASSIGN_OR_RETURN(icon.tile_tl, rom->ReadWord(icon_addr));
118 ASSIGN_OR_RETURN(icon.tile_tr, rom->ReadWord(icon_addr + 2));
119 ASSIGN_OR_RETURN(icon.tile_bl, rom->ReadWord(icon_addr + 4));
120 ASSIGN_OR_RETURN(icon.tile_br, rom->ReadWord(icon_addr + 6));
121 icon.name = icon_def.name;
122
123 item_icons_.push_back(icon);
124 }
125 return absl::OkStatus();
126 };
127
128 RETURN_IF_ERROR(load_icons(bow_icons));
129 RETURN_IF_ERROR(load_icons(boom_icons));
130 RETURN_IF_ERROR(load_icons(hook_icons));
131 RETURN_IF_ERROR(load_icons(bomb_icons));
132
133 // Mushroom/Powder (.shroom)
134 std::vector<IconDef> shroom_icons = {{0x60, "No mushroom"},
135 {0x68, "Mushroom"}};
136 RETURN_IF_ERROR(load_icons(shroom_icons));
137
138 // Magic powder (.powder)
139 std::vector<IconDef> powder_icons = {{0x70, "No powder"}, {0x78, "Powder"}};
140 RETURN_IF_ERROR(load_icons(powder_icons));
141
142 // Fire rod (.fires)
143 std::vector<IconDef> fire_rod_icons = {{0x80, "No fire rod"},
144 {0x88, "Fire rod"}};
145 RETURN_IF_ERROR(load_icons(fire_rod_icons));
146
147 // Ice rod (.ices)
148 std::vector<IconDef> ice_rod_icons = {{0x90, "No ice rod"},
149 {0x98, "Ice rod"}};
150 RETURN_IF_ERROR(load_icons(ice_rod_icons));
151
152 // Medallions
153 std::vector<IconDef> medal_icons = {{0xA0, "No Bombos"}, {0xA8, "Bombos"},
154 {0xB0, "No Ether"}, {0xB8, "Ether"},
155 {0xC0, "No Quake"}, {0xC8, "Quake"}};
156 RETURN_IF_ERROR(load_icons(medal_icons));
157
158 // Utilities
159 std::vector<IconDef> util_icons = {{0xD0, "No lantern"}, {0xD8, "Lantern"},
160 {0xE0, "No hammer"}, {0xE8, "Hammer"},
161 {0xF0, "No flute"}, {0xF8, "Flute"},
162 {0x100, "No net"}, {0x108, "Bug net"},
163 {0x110, "No book"}, {0x118, "Book"}};
164 RETURN_IF_ERROR(load_icons(util_icons));
165
166 // Bottles
167 std::vector<IconDef> bottle_icons = {
168 {0x120, "No bottle"}, {0x128, "Empty bottle"}, {0x130, "Red potion"},
169 {0x138, "Green potion"}, {0x140, "Blue potion"}, {0x148, "Fairy"},
170 {0x150, "Bee"}, {0x158, "Good bee"}};
171 RETURN_IF_ERROR(load_icons(bottle_icons));
172
173 // Canes and Mirror
174 std::vector<IconDef> magic_icons = {
175 {0x160, "No Somaria"}, {0x168, "Cane of Somaria"},
176 {0x170, "No Byrna"}, {0x178, "Cane of Byrna"},
177 {0x180, "No Cape"}, {0x188, "Magic cape"},
178 {0x190, "No mirror"}, {0x198, "Magic mirror"}};
179 RETURN_IF_ERROR(load_icons(magic_icons));
180
181 // Passive equipment
182 std::vector<IconDef> equip_icons = {
183 {0x1A0, "No gloves"}, {0x1A8, "Power glove"}, {0x1B0, "Titan mitts"},
184 {0x1B8, "No boots"}, {0x1C0, "Pegasus boots"}, {0x1C8, "No flippers"},
185 {0x1D0, "Flippers"}, {0x1D8, "No pearl"}, {0x1E0, "Moon pearl"}};
186 RETURN_IF_ERROR(load_icons(equip_icons));
187
188 // Combat
189 std::vector<IconDef> combat_icons = {
190 {0x1E8, "No sword"}, {0x1F0, "Fighter sword"},
191 {0x1F8, "Master sword"}, {0x200, "Tempered sword"},
192 {0x208, "Golden sword"}, {0x210, "No shield"},
193 {0x218, "Blue shield"}, {0x220, "Red shield"},
194 {0x228, "Mirror shield"}, {0x230, "Green mail"},
195 {0x238, "Blue mail"}, {0x240, "Red mail"}};
196 RETURN_IF_ERROR(load_icons(combat_icons));
197
198 return absl::OkStatus();
199}
200
201} // namespace zelda3
202} // namespace yaze
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
absl::StatusOr< uint16_t > ReadWord(int offset) const
Definition rom.cc:571
bool is_loaded() const
Definition rom.h:155
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:36
static Arena & Get()
Definition arena.cc:21
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
Definition bitmap.cc:202
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap using SNES palette format.
Definition bitmap.cc:394
void ClearSelection()
Definition canvas.cc:273
absl::Status BuildTileset(Rom *rom)
Build the tileset from 2BPP graphics.
Definition inventory.cc:55
absl::Status Create(Rom *rom, GameData *game_data=nullptr)
Initialize and load inventory screen data from ROM.
Definition inventory.cc:14
gfx::SnesPalette palette_
Definition inventory.h:72
std::vector< uint8_t > data_
Definition inventory.h:66
std::vector< ItemIcon > item_icons_
Definition inventory.h:76
gfx::Bitmap tilesheets_bmp_
Definition inventory.h:71
std::vector< uint8_t > test_
Definition inventory.h:70
absl::Status LoadItemIcons(Rom *rom)
Load individual item icons from ROM.
Definition inventory.cc:82
std::vector< gfx::TileInfo > tiles_
Definition inventory.h:75
std::vector< uint8_t > tilesheets_
Definition inventory.h:69
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:62
absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics(const Rom &rom)
Loads 2BPP graphics sheets from ROM.
Definition game_data.cc:565
constexpr int kItemIconsPtr
Definition inventory.h:17
uint32_t SnesToPc(uint32_t addr) noexcept
Definition snes.h:8
#define RETURN_IF_ERROR(expr)
Definition snes.cc:22
gfx::PaletteGroupMap palette_groups
Definition game_data.h:92
Represents a single item icon (2x2 tiles = 4 tile words)
Definition inventory.h:22