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