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 // TODO(scawful): Load remaining icon categories:
122 // - Mushroom/Powder (.shroom)
123 // - Magic powder (.powder)
124 // - Fire rod (.fires)
125 // - Ice rod (.ices)
126 // - Bombos medallion (.bombos)
127 // - Ether medallion (.ether)
128 // - Quake medallion (.quake)
129 // - Lantern (.lamp)
130 // - Hammer (.hammer)
131 // - Flute (.flute)
132 // - Bug net (.net)
133 // - Book of Mudora (.book)
134 // - Bottles (.bottles) - Multiple variants (empty, red potion, green potion,
135 // etc.)
136 // - Cane of Somaria (.canes)
137 // - Cane of Byrna (.byrn)
138 // - Magic cape (.cape)
139 // - Magic mirror (.mirror)
140 // - Gloves (.glove)
141 // - Boots (.boots)
142 // - Flippers (.flippers)
143 // - Moon pearl (.pearl)
144 // - Swords (.swords)
145 // - Shields (.shields)
146 // - Armor (.armor)
147
148 return absl::OkStatus();
149}
150
151} // namespace zelda3
152} // 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:228
bool is_loaded() const
Definition rom.h:128
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:34
static Arena & Get()
Definition arena.cc:19
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:199
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap using SNES palette format.
Definition bitmap.cc:382
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:456
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