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 "app/rom.h"
9#include "app/snes.h"
10
11namespace yaze {
12namespace zelda3 {
13
14absl::Status Inventory::Create(Rom* rom) {
15 if (!rom || !rom->is_loaded()) {
16 return absl::InvalidArgumentError("ROM is not loaded");
17 }
18
19 // Build the tileset first (loads 2BPP graphics)
21
22 // Load item icons from ROM
24
25 // TODO(scawful): For now, create a simple display bitmap
26 // Future: Oracle of Secrets menu editor will handle full menu layout
27 data_.reserve(256 * 256);
28 for (int i = 0; i < 256 * 256; i++) {
29 data_.push_back(0xFF);
30 }
31
32 bitmap_.Create(256, 256, 8, data_);
34
35 // Queue texture creation via Arena's deferred system
38
39 return absl::OkStatus();
40}
41
42absl::Status Inventory::BuildTileset(Rom* rom) {
43 tilesheets_.reserve(6 * 0x2000);
44 for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
46 std::vector<uint8_t> test;
47 for (int i = 0; i < 0x4000; i++) {
48 test_.push_back(tilesheets_[i]);
49 }
50 for (int i = 0x8000; i < +0x8000 + 0x2000; i++) {
51 test_.push_back(tilesheets_[i]);
52 }
53 tilesheets_bmp_.Create(128, 0x130, 64, test_);
54 auto hud_pal_group = rom->palette_group().hud;
55 palette_ = hud_pal_group[0];
57
58 // Queue texture creation via Arena's deferred system
61
62 return absl::OkStatus();
63}
64
65absl::Status Inventory::LoadItemIcons(Rom* rom) {
66 // Convert SNES address to PC address
67 int pc_addr = SnesToPc(kItemIconsPtr);
68
69 // Define icon categories and their ROM offsets (relative to kItemIconsPtr)
70 // Based on bank_0D.asm ItemIcons structure
71 struct IconDef {
72 int offset;
73 std::string name;
74 };
75
76 // Bow icons (.bows section)
77 std::vector<IconDef> bow_icons = {
78 {0x00, "No bow"},
79 {0x08, "Empty bow"},
80 {0x10, "Bow and arrows"},
81 {0x18, "Empty silvers bow"},
82 {0x20, "Silver bow and arrows"}
83 };
84
85 // Boomerang icons (.booms section)
86 std::vector<IconDef> boom_icons = {
87 {0x28, "No boomerang"},
88 {0x30, "Blue boomerang"},
89 {0x38, "Red boomerang"}
90 };
91
92 // Hookshot icons (.hook section)
93 std::vector<IconDef> hook_icons = {
94 {0x40, "No hookshot"},
95 {0x48, "Hookshot"}
96 };
97
98 // Bomb icons (.bombs section)
99 std::vector<IconDef> bomb_icons = {
100 {0x50, "No bombs"},
101 {0x58, "Bombs"}
102 };
103
104 // Load all icon categories
105 auto load_icons = [&](const std::vector<IconDef>& icons) -> absl::Status {
106 for (const auto& icon_def : icons) {
107 ItemIcon icon;
108 int icon_addr = pc_addr + icon_def.offset;
109
110 ASSIGN_OR_RETURN(icon.tile_tl, rom->ReadWord(icon_addr));
111 ASSIGN_OR_RETURN(icon.tile_tr, rom->ReadWord(icon_addr + 2));
112 ASSIGN_OR_RETURN(icon.tile_bl, rom->ReadWord(icon_addr + 4));
113 ASSIGN_OR_RETURN(icon.tile_br, rom->ReadWord(icon_addr + 6));
114 icon.name = icon_def.name;
115
116 item_icons_.push_back(icon);
117 }
118 return absl::OkStatus();
119 };
120
121 RETURN_IF_ERROR(load_icons(bow_icons));
122 RETURN_IF_ERROR(load_icons(boom_icons));
123 RETURN_IF_ERROR(load_icons(hook_icons));
124 RETURN_IF_ERROR(load_icons(bomb_icons));
125
126 // TODO(scawful): Load remaining icon categories:
127 // - Mushroom/Powder (.shroom)
128 // - Magic powder (.powder)
129 // - Fire rod (.fires)
130 // - Ice rod (.ices)
131 // - Bombos medallion (.bombos)
132 // - Ether medallion (.ether)
133 // - Quake medallion (.quake)
134 // - Lantern (.lamp)
135 // - Hammer (.hammer)
136 // - Flute (.flute)
137 // - Bug net (.net)
138 // - Book of Mudora (.book)
139 // - Bottles (.bottles) - Multiple variants (empty, red potion, green potion, etc.)
140 // - Cane of Somaria (.canes)
141 // - Cane of Byrna (.byrn)
142 // - Magic cape (.cape)
143 // - Magic mirror (.mirror)
144 // - Gloves (.glove)
145 // - Boots (.boots)
146 // - Flippers (.flippers)
147 // - Moon pearl (.pearl)
148 // - Swords (.swords)
149 // - Shields (.shields)
150 // - Armor (.armor)
151
152 return absl::OkStatus();
153}
154
155} // namespace zelda3
156} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:74
auto palette_group() const
Definition rom.h:216
absl::StatusOr< uint16_t > ReadWord(int offset)
Definition rom.cc:668
bool is_loaded() const
Definition rom.h:200
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:32
static Arena & Get()
Definition arena.cc:15
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:162
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap.
Definition bitmap.cc:334
absl::Status BuildTileset(Rom *rom)
Build the tileset from 2BPP graphics.
Definition inventory.cc:42
gfx::SnesPalette palette_
Definition inventory.h:67
std::vector< uint8_t > data_
Definition inventory.h:61
std::vector< ItemIcon > item_icons_
Definition inventory.h:71
gfx::Bitmap tilesheets_bmp_
Definition inventory.h:66
std::vector< uint8_t > test_
Definition inventory.h:65
absl::Status LoadItemIcons(Rom *rom)
Load individual item icons from ROM.
Definition inventory.cc:65
absl::Status Create(Rom *rom)
Initialize and load inventory screen data from ROM.
Definition inventory.cc:14
std::vector< uint8_t > tilesheets_
Definition inventory.h:64
#define RETURN_IF_ERROR(expression)
Definition macro.h:53
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:61
constexpr int kItemIconsPtr
Definition inventory.h:16
Main namespace for the application.
Definition controller.cc:20
absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics(const Rom &rom)
Loads 2bpp graphics from Rom data.
Definition rom.cc:79
uint32_t SnesToPc(uint32_t addr) noexcept
Definition snes.h:8
Represents a single item icon (2x2 tiles = 4 tile words)
Definition inventory.h:21