yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
rom.cc
Go to the documentation of this file.
1#include "rom.h"
2
3#include <algorithm>
4#include <array>
5#include <chrono>
6#include <cstddef>
7#include <cstdint>
8#include <cstring>
9#include <ctime>
10#include <filesystem>
11#include <fstream>
12#include <string>
13#include <vector>
14
15#include "absl/status/status.h"
16#include "absl/status/statusor.h"
17#include "absl/strings/str_cat.h"
18#include "absl/strings/string_view.h"
19#include "app/core/features.h"
21#include "app/gfx/compression.h"
22#include "app/gfx/snes_color.h"
24#include "app/gfx/snes_tile.h"
25#include "util/hex.h"
26#include "util/log.h"
27#include "util/macro.h"
28
29namespace yaze {
30using core::Renderer;
31constexpr int Uncompressed3BPPSize = 0x0600;
32
33uint32_t GetGraphicsAddress(const uint8_t *data, uint8_t addr, uint32_t ptr1,
34 uint32_t ptr2, uint32_t ptr3) {
35 return SnesToPc(AddressFromBytes(data[ptr1 + addr], data[ptr2 + addr],
36 data[ptr3 + addr]));
37}
38
39absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom &rom) {
40 std::vector<uint8_t> sheet;
41 const uint8_t sheets[] = {113, 114, 218, 219, 220, 221};
42
43 for (const auto &sheet_id : sheets) {
44 auto offset = GetGraphicsAddress(rom.data(), sheet_id,
48 ASSIGN_OR_RETURN(auto decomp_sheet,
49 gfx::lc_lz2::DecompressV2(rom.data(), offset))
50 auto converted_sheet = gfx::SnesTo8bppSheet(decomp_sheet, 2);
51 for (const auto &each_pixel : converted_sheet) {
52 sheet.push_back(each_pixel);
53 }
54 }
55 return sheet;
56}
57
58absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
59 const Rom &rom) {
60 const uint32_t kLinkGfxOffset = 0x80000; // $10:8000
61 const uint16_t kLinkGfxLength = 0x800; // 0x4000 or 0x7000?
62 std::array<gfx::Bitmap, kNumLinkSheets> link_graphics;
63 for (uint32_t i = 0; i < kNumLinkSheets; i++) {
65 auto link_sheet_data,
66 rom.ReadByteVector(/*offset=*/kLinkGfxOffset + (i * kLinkGfxLength),
67 /*length=*/kLinkGfxLength))
68 auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
69 link_graphics[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
70 gfx::kTilesheetDepth, link_sheet_8bpp);
72 link_graphics[i].ApplyPalette(rom.palette_group().armors[0]);)
73 Renderer::GetInstance().RenderBitmap(&link_graphics[i]);
74 }
75 return link_graphics;
76}
77
78absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>> LoadAllGraphicsData(
79 Rom &rom, bool defer_render) {
80 std::array<gfx::Bitmap, kNumGfxSheets> graphics_sheets;
81 std::vector<uint8_t> sheet;
82 bool bpp3 = false;
83
84 for (uint32_t i = 0; i < kNumGfxSheets; i++) {
85 if (i >= 115 && i <= 126) { // uncompressed sheets
86 sheet.resize(Uncompressed3BPPSize);
87 auto offset = GetGraphicsAddress(
91 std::copy(rom.data() + offset, rom.data() + offset + Uncompressed3BPPSize,
92 sheet.begin());
93 bpp3 = true;
94 } else if (i == 113 || i == 114 || i >= 218) {
95 bpp3 = false;
96 } else {
97 auto offset = GetGraphicsAddress(
101 ASSIGN_OR_RETURN(sheet, gfx::lc_lz2::DecompressV2(rom.data(), offset))
102 bpp3 = true;
103 }
104
105 if (bpp3) {
106 auto converted_sheet = gfx::SnesTo8bppSheet(sheet, 3);
107 graphics_sheets[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
108 gfx::kTilesheetDepth, converted_sheet);
109 if (graphics_sheets[i].is_active()) {
110 if (i > 115) {
111 // Apply sprites palette
112 RETURN_IF_ERROR(graphics_sheets[i].ApplyPaletteWithTransparent(
113 rom.palette_group().global_sprites[0], 0));
114 } else {
115 RETURN_IF_ERROR(graphics_sheets[i].ApplyPaletteWithTransparent(
116 rom.palette_group().dungeon_main[0], 0));
117 }
118 }
119
120 if (!defer_render) {
121 graphics_sheets[i].CreateTexture(Renderer::GetInstance().renderer());
122 }
123
124 for (int j = 0; j < graphics_sheets[i].size(); ++j) {
125 rom.mutable_graphics_buffer()->push_back(graphics_sheets[i].at(j));
126 }
127
128 } else {
129 for (int j = 0; j < graphics_sheets[0].size(); ++j) {
130 rom.mutable_graphics_buffer()->push_back(0xFF);
131 }
132 }
133 }
134 return graphics_sheets;
135}
136
138 Rom &rom, std::array<gfx::Bitmap, kNumGfxSheets> &gfx_sheets) {
139 for (int i = 0; i < kNumGfxSheets; i++) {
140 if (gfx_sheets[i].is_active()) {
141 int to_bpp = 3;
142 std::vector<uint8_t> final_data;
143 bool compressed = true;
144 if (i >= 115 && i <= 126) {
145 compressed = false;
146 } else if (i == 113 || i == 114 || i >= 218) {
147 to_bpp = 2;
148 continue;
149 }
150
151 std::cout << "Sheet ID " << i << " BPP: " << to_bpp << std::endl;
152 auto sheet_data = gfx_sheets[i].vector();
153 std::cout << "Sheet data size: " << sheet_data.size() << std::endl;
154 final_data = gfx::Bpp8SnesToIndexed(sheet_data, 8);
155 int size = 0;
156 if (compressed) {
157 auto compressed_data = gfx::HyruleMagicCompress(
158 final_data.data(), final_data.size(), &size, 1);
159 for (int j = 0; j < size; j++) {
160 sheet_data[j] = compressed_data[j];
161 }
162 }
163 auto offset = GetGraphicsAddress(
167 std::copy(final_data.begin(), final_data.end(), rom.begin() + offset);
168 }
169 }
170 return absl::OkStatus();
171}
172
173absl::Status Rom::LoadFromFile(const std::string &filename, bool z3_load) {
174 if (filename.empty()) {
175 return absl::InvalidArgumentError(
176 "Could not load ROM: parameter `filename` is empty.");
177 }
178 std::string full_filename = std::filesystem::absolute(filename).string();
179 filename_ = full_filename;
180
181 std::ifstream file(filename_, std::ios::binary);
182 if (!file.is_open()) {
183 return absl::NotFoundError(
184 absl::StrCat("Could not open ROM file: ", filename_));
185 }
186
187 // Get file size and resize rom_data_
188 try {
189 size_ = std::filesystem::file_size(filename_);
190 } catch (const std::filesystem::filesystem_error &e) {
191 // Try to get the file size from the open file stream
192 file.seekg(0, std::ios::end);
193 if (!file) {
194 return absl::InternalError(absl::StrCat(
195 "Could not get file size: ", filename_, " - ", e.what()));
196 }
197 size_ = file.tellg();
198 }
199 rom_data_.resize(size_);
200
201 // Read file into rom_data_
202 file.read(reinterpret_cast<char *>(rom_data_.data()), size_);
203 file.close();
204
205 // Set is_loaded_ flag and return success
206 is_loaded_ = true;
207
208 if (z3_load) {
210 }
211
212 // Set up the resource labels
213 std::string resource_label_filename = absl::StrFormat("%s.labels", filename);
214 resource_label_manager_.LoadLabels(resource_label_filename);
215 return absl::OkStatus();
216}
217
218absl::Status Rom::LoadFromData(const std::vector<uint8_t> &data, bool z3_load) {
219 if (data.empty()) {
220 return absl::InvalidArgumentError(
221 "Could not load ROM: parameter `data` is empty.");
222 }
223 if (!palette_groups_.empty()) palette_groups_.clear();
224
225 rom_data_ = data;
226 size_ = data.size();
227 is_loaded_ = true;
228
229 if (z3_load) {
231 }
232 return absl::OkStatus();
233}
234
235absl::StatusOr<uint8_t> Rom::ReadByte(int offset) {
236 if (offset >= static_cast<int>(rom_data_.size())) {
237 return absl::FailedPreconditionError("Offset out of range");
238 }
239 return rom_data_[offset];
240}
241
242absl::StatusOr<uint16_t> Rom::ReadWord(int offset) {
243 if (offset + 1 >= static_cast<int>(rom_data_.size())) {
244 return absl::FailedPreconditionError("Offset out of range");
245 }
246 auto result = (uint16_t)(rom_data_[offset] | (rom_data_[offset + 1] << 8));
247 return result;
248}
249
250absl::StatusOr<uint32_t> Rom::ReadLong(int offset) {
251 if (offset + 2 >= static_cast<int>(rom_data_.size())) {
252 return absl::OutOfRangeError("Offset out of range");
253 }
254 auto result = (uint32_t)(rom_data_[offset] | (rom_data_[offset + 1] << 8) |
255 (rom_data_[offset + 2] << 16));
256 return result;
257}
258
259absl::StatusOr<std::vector<uint8_t>> Rom::ReadByteVector(
260 uint32_t offset, uint32_t length) const {
261 if (offset + length > static_cast<uint32_t>(rom_data_.size())) {
262 return absl::OutOfRangeError("Offset and length out of range");
263 }
264 std::vector<uint8_t> result;
265 for (uint32_t i = offset; i < offset + length; i++) {
266 result.push_back(rom_data_[i]);
267 }
268 return result;
269}
270
271absl::StatusOr<gfx::Tile16> Rom::ReadTile16(uint32_t tile16_id) {
272 // Skip 8 bytes per tile.
273 auto tpos = kTile16Ptr + (tile16_id * 0x08);
274 gfx::Tile16 tile16 = {};
275 ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos))
276 tile16.tile0_ = gfx::WordToTileInfo(new_tile0);
277 tpos += 2;
278 ASSIGN_OR_RETURN(auto new_tile1, ReadWord(tpos))
279 tile16.tile1_ = gfx::WordToTileInfo(new_tile1);
280 tpos += 2;
281 ASSIGN_OR_RETURN(auto new_tile2, ReadWord(tpos))
282 tile16.tile2_ = gfx::WordToTileInfo(new_tile2);
283 tpos += 2;
284 ASSIGN_OR_RETURN(auto new_tile3, ReadWord(tpos))
285 tile16.tile3_ = gfx::WordToTileInfo(new_tile3);
286 return tile16;
287}
288
289absl::Status Rom::WriteTile16(int tile16_id, const gfx::Tile16 &tile) {
290 // Skip 8 bytes per tile.
291 auto tpos = kTile16Ptr + (tile16_id * 0x08);
293 tpos += 2;
295 tpos += 2;
297 tpos += 2;
299 return absl::OkStatus();
300}
301
302absl::Status Rom::WriteByte(int addr, uint8_t value) {
303 if (addr >= static_cast<int>(rom_data_.size())) {
304 return absl::OutOfRangeError(absl::StrFormat(
305 "Attempt to write byte %#02x value failed, address %d out of range",
306 value, addr));
307 }
308 rom_data_[addr] = value;
309 util::logf("WriteByte: %#06X: %s", addr, util::HexByte(value).data());
310 return absl::OkStatus();
311}
312
313absl::Status Rom::WriteWord(int addr, uint16_t value) {
314 if (addr + 1 >= static_cast<int>(rom_data_.size())) {
315 return absl::OutOfRangeError(absl::StrFormat(
316 "Attempt to write word %#04x value failed, address %d out of range",
317 value, addr));
318 }
319 rom_data_[addr] = (uint8_t)(value & 0xFF);
320 rom_data_[addr + 1] = (uint8_t)((value >> 8) & 0xFF);
321 util::logf("WriteWord: %#06X: %s", addr, util::HexWord(value).data());
322 return absl::OkStatus();
323}
324
325absl::Status Rom::WriteShort(int addr, uint16_t value) {
326 if (addr + 1 >= static_cast<int>(rom_data_.size())) {
327 return absl::OutOfRangeError(absl::StrFormat(
328 "Attempt to write short %#04x value failed, address %d out of range",
329 value, addr));
330 }
331 rom_data_[addr] = (uint8_t)(value & 0xFF);
332 rom_data_[addr + 1] = (uint8_t)((value >> 8) & 0xFF);
333 util::logf("WriteShort: %#06X: %s", addr, util::HexWord(value).data());
334 return absl::OkStatus();
335}
336
337absl::Status Rom::WriteLong(uint32_t addr, uint32_t value) {
338 if (addr + 2 >= static_cast<uint32_t>(rom_data_.size())) {
339 return absl::OutOfRangeError(absl::StrFormat(
340 "Attempt to write long %#06x value failed, address %d out of range",
341 value, addr));
342 }
343 rom_data_[addr] = (uint8_t)(value & 0xFF);
344 rom_data_[addr + 1] = (uint8_t)((value >> 8) & 0xFF);
345 rom_data_[addr + 2] = (uint8_t)((value >> 16) & 0xFF);
346 util::logf("WriteLong: %#06X: %s", addr, util::HexLong(value).data());
347 return absl::OkStatus();
348}
349
350absl::Status Rom::WriteVector(int addr, std::vector<uint8_t> data) {
351 if (addr + static_cast<int>(data.size()) >
352 static_cast<int>(rom_data_.size())) {
353 return absl::InvalidArgumentError(absl::StrFormat(
354 "Attempt to write vector value failed, address %d out of range", addr));
355 }
356 for (int i = 0; i < static_cast<int>(data.size()); i++) {
357 rom_data_[addr + i] = data[i];
358 }
359 util::logf("WriteVector: %#06X: %s", addr, util::HexByte(data[0]).data());
360 return absl::OkStatus();
361}
362
363absl::Status Rom::WriteColor(uint32_t address, const gfx::SnesColor &color) {
364 uint16_t bgr = ((color.snes() >> 10) & 0x1F) | ((color.snes() & 0x1F) << 10) |
365 (color.snes() & 0x7C00);
366
367 // Write the 16-bit color value to the ROM at the specified address
368 util::logf("WriteColor: %#06X: %s", address, util::HexWord(bgr).data());
369 return WriteShort(address, bgr);
370}
371
372absl::Status Rom::LoadZelda3() {
373 // Check if the ROM has a header
374 constexpr size_t kBaseRomSize = 1048576; // 1MB
375 constexpr size_t kHeaderSize = 0x200; // 512 bytes
376 if (size_ % kBaseRomSize == kHeaderSize) {
377 auto header = std::vector<uint8_t>(rom_data_.begin(),
378 rom_data_.begin() + kHeaderSize);
379 rom_data_.erase(rom_data_.begin(), rom_data_.begin() + kHeaderSize);
380 size_ -= 0x200;
381 }
382
383 // Copy ROM title
384 constexpr uint32_t kTitleStringOffset = 0x7FC0;
385 constexpr uint32_t kTitleStringLength = 20;
386 title_.resize(kTitleStringLength);
387 std::copy(rom_data_.begin() + kTitleStringOffset,
388 rom_data_.begin() + kTitleStringOffset + kTitleStringLength,
389 title_.begin());
390 if (rom_data_[kTitleStringOffset + 0x19] == 0) {
392 } else {
394 }
395
396 // Load additional resources
398 // TODO Load gfx groups or expanded ZS values
400
401 // Expand the ROM data to 2MB without changing the data in the first 1MB
402 rom_data_.resize(kBaseRomSize * 2);
403 size_ = kBaseRomSize * 2;
404
405 return absl::OkStatus();
406}
407
408absl::Status Rom::SaveToFile(bool backup, bool save_new, std::string filename) {
409 absl::Status non_firing_status;
410 if (rom_data_.empty()) {
411 return absl::InternalError("ROM data is empty.");
412 }
413
414 // Check if filename is empty
415 if (filename == "") {
417 }
418
419 // Check if backup is enabled
420 if (backup) {
421 // Create a backup file with timestamp in its name
422 auto now = std::chrono::system_clock::now();
423 auto now_c = std::chrono::system_clock::to_time_t(now);
424 std::string backup_filename =
425 absl::StrCat(filename, "_backup_", std::ctime(&now_c));
426
427 // Remove newline character from ctime()
428 backup_filename.erase(
429 std::remove(backup_filename.begin(), backup_filename.end(), '\n'),
430 backup_filename.end());
431
432 // Replace spaces with underscores
433 std::replace(backup_filename.begin(), backup_filename.end(), ' ', '_');
434
435 // Now, copy the original file to the backup file
436 try {
437 std::filesystem::copy(filename_, backup_filename,
438 std::filesystem::copy_options::overwrite_existing);
439 } catch (const std::filesystem::filesystem_error &e) {
440 non_firing_status = absl::InternalError(absl::StrCat(
441 "Could not create backup file: ", backup_filename, " - ", e.what()));
442 }
443 }
444
445 // Run the other save functions
446 if (core::FeatureFlags::get().kSaveAllPalettes)
448 if (core::FeatureFlags::get().kSaveGfxGroups)
450
451 if (save_new) {
452 // Create a file of the same name and append the date between the filename
453 // and file extension
454 auto now = std::chrono::system_clock::now();
455 auto now_c = std::chrono::system_clock::to_time_t(now);
456 auto filename_no_ext = filename.substr(0, filename.find_last_of("."));
457 std::cout << filename_no_ext << std::endl;
458 filename = absl::StrCat(filename_no_ext, "_", std::ctime(&now_c));
459 // Remove spaces from new_filename and replace with _
460 filename.erase(std::remove(filename.begin(), filename.end(), ' '),
461 filename.end());
462 // Remove newline character from ctime()
463 filename.erase(std::remove(filename.begin(), filename.end(), '\n'),
464 filename.end());
465 // Add the file extension back to the new_filename
466 filename = filename + ".sfc";
467 std::cout << filename << std::endl;
468 }
469
470 // Open the file that we know exists for writing
471 std::ofstream file(filename.data(), std::ios::binary | std::ios::app);
472 if (!file) {
473 // Create the file if it does not exist
474 file.open(filename.data(), std::ios::binary);
475 if (!file) {
476 return absl::InternalError(
477 absl::StrCat("Could not open or create ROM file: ", filename));
478 }
479 }
480
481 // Save the data to the file
482 try {
483 file.write(
484 static_cast<const char *>(static_cast<const void *>(rom_data_.data())),
485 rom_data_.size());
486 } catch (const std::ofstream::failure &e) {
487 return absl::InternalError(absl::StrCat(
488 "Error while writing to ROM file: ", filename, " - ", e.what()));
489 }
490
491 // Check for write errors
492 if (!file) {
493 return absl::InternalError(
494 absl::StrCat("Error while writing to ROM file: ", filename));
495 }
496
497 if (!non_firing_status.ok()) {
498 return non_firing_status;
499 }
500
501 return absl::OkStatus();
502}
503
504absl::Status Rom::SavePalette(int index, const std::string &group_name,
505 gfx::SnesPalette &palette) {
506 for (size_t j = 0; j < palette.size(); ++j) {
507 gfx::SnesColor color = palette[j];
508 // If the color is modified, save the color to the ROM
509 if (color.is_modified()) {
511 WriteColor(gfx::GetPaletteAddress(group_name, index, j), color));
512 color.set_modified(false); // Reset the modified flag after saving
513 }
514 }
515 return absl::OkStatus();
516}
517
518absl::Status Rom::SaveAllPalettes() {
520 palette_groups_.for_each([&](gfx::PaletteGroup &group) -> absl::Status {
521 for (size_t i = 0; i < group.size(); ++i) {
522 RETURN_IF_ERROR(
523 SavePalette(i, group.name(), *group.mutable_palette(i)));
524 }
525 return absl::OkStatus();
526 }));
527
528 return absl::OkStatus();
529}
530
531absl::Status Rom::LoadGfxGroups() {
532 ASSIGN_OR_RETURN(auto main_blockset_ptr, ReadWord(kGfxGroupsPointer));
533 main_blockset_ptr = SnesToPc(main_blockset_ptr);
534
535 for (uint32_t i = 0; i < kNumMainBlocksets; i++) {
536 for (int j = 0; j < 8; j++) {
537 main_blockset_ids[i][j] = rom_data_[main_blockset_ptr + (i * 8) + j];
538 }
539 }
540
541 for (uint32_t i = 0; i < kNumRoomBlocksets; i++) {
542 for (int j = 0; j < 4; j++) {
543 room_blockset_ids[i][j] = rom_data_[kEntranceGfxGroup + (i * 4) + j];
544 }
545 }
546
547 for (uint32_t i = 0; i < kNumSpritesets; i++) {
548 for (int j = 0; j < 4; j++) {
549 spriteset_ids[i][j] =
550 rom_data_[version_constants().kSpriteBlocksetPointer + (i * 4) + j];
551 }
552 }
553
554 for (uint32_t i = 0; i < kNumPalettesets; i++) {
555 for (int j = 0; j < 4; j++) {
556 paletteset_ids[i][j] =
557 rom_data_[version_constants().kDungeonPalettesGroups + (i * 4) + j];
558 }
559 }
560
561 return absl::OkStatus();
562}
563
564absl::Status Rom::SaveGroupsToRom() {
565 ASSIGN_OR_RETURN(auto main_blockset_ptr, ReadWord(kGfxGroupsPointer));
566 main_blockset_ptr = SnesToPc(main_blockset_ptr);
567
568 for (uint32_t i = 0; i < kNumMainBlocksets; i++) {
569 for (int j = 0; j < 8; j++) {
570 rom_data_[main_blockset_ptr + (i * 8) + j] = main_blockset_ids[i][j];
571 }
572 }
573
574 for (uint32_t i = 0; i < kNumRoomBlocksets; i++) {
575 for (int j = 0; j < 4; j++) {
576 rom_data_[kEntranceGfxGroup + (i * 4) + j] = room_blockset_ids[i][j];
577 }
578 }
579
580 for (uint32_t i = 0; i < kNumSpritesets; i++) {
581 for (int j = 0; j < 4; j++) {
582 rom_data_[version_constants().kSpriteBlocksetPointer + (i * 4) + j] =
583 spriteset_ids[i][j];
584 }
585 }
586
587 for (uint32_t i = 0; i < kNumPalettesets; i++) {
588 for (int j = 0; j < 4; j++) {
589 rom_data_[version_constants().kDungeonPalettesGroups + (i * 4) + j] =
590 paletteset_ids[i][j];
591 }
592 }
593
594 return absl::OkStatus();
595}
596
597std::shared_ptr<Rom> SharedRom::shared_rom_ = nullptr;
598
599} // namespace yaze
static Renderer & GetInstance()
Definition renderer.h:26
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:59
absl::StatusOr< std::vector< uint8_t > > ReadByteVector(uint32_t offset, uint32_t length) const
Definition rom.cc:259
zelda3_version version_
Definition rom.h:266
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
Definition rom.cc:173
auto mutable_graphics_buffer()
Definition rom.h:175
auto begin()
Definition rom.h:166
absl::Status SaveGroupsToRom()
Definition rom.cc:564
std::vector< uint8_t > rom_data_
Definition rom.h:254
gfx::PaletteGroupMap palette_groups_
Definition rom.h:263
auto palette_group() const
Definition rom.h:176
absl::StatusOr< gfx::Tile16 > ReadTile16(uint32_t tile16_id)
Definition rom.cc:271
absl::Status WriteColor(uint32_t address, const gfx::SnesColor &color)
Definition rom.cc:363
auto filename() const
Definition rom.h:171
absl::Status LoadFromData(const std::vector< uint8_t > &data, bool z3_load=true)
Definition rom.cc:218
absl::Status WriteByte(int addr, uint8_t value)
Definition rom.cc:302
absl::Status SaveToFile(bool backup, bool save_new=false, std::string filename="")
Saves the Rom data to a file.
Definition rom.cc:408
absl::Status LoadZelda3()
Definition rom.cc:372
std::array< std::array< uint8_t, 4 >, kNumSpritesets > spriteset_ids
Definition rom.h:190
std::array< std::array< uint8_t, 4 >, kNumPalettesets > paletteset_ids
Definition rom.h:191
absl::StatusOr< uint16_t > ReadWord(int offset)
Definition rom.cc:242
absl::Status WriteVector(int addr, std::vector< uint8_t > data)
Definition rom.cc:350
std::string title_
Definition rom.h:248
absl::Status WriteTile16(int tile16_id, const gfx::Tile16 &tile)
Definition rom.cc:289
std::array< std::array< uint8_t, 4 >, kNumRoomBlocksets > room_blockset_ids
Definition rom.h:189
absl::StatusOr< uint32_t > ReadLong(int offset)
Definition rom.cc:250
auto data() const
Definition rom.h:164
zelda3_version_pointers version_constants() const
Definition rom.h:184
ResourceLabelManager resource_label_manager_
Definition rom.h:260
absl::Status LoadGfxGroups()
Definition rom.cc:531
bool is_loaded_
Definition rom.h:242
std::string filename_
Definition rom.h:251
unsigned long size_
Definition rom.h:245
absl::Status SavePalette(int index, const std::string &group_name, gfx::SnesPalette &palette)
Definition rom.cc:504
absl::StatusOr< uint8_t > ReadByte(int offset)
Definition rom.cc:235
absl::Status WriteShort(int addr, uint16_t value)
Definition rom.cc:325
absl::Status WriteWord(int addr, uint16_t value)
Definition rom.cc:313
absl::Status WriteLong(uint32_t addr, uint32_t value)
Definition rom.cc:337
std::array< std::array< uint8_t, 8 >, kNumMainBlocksets > main_blockset_ids
Definition rom.h:188
absl::Status SaveAllPalettes()
Saves all palettes in the Rom.
Definition rom.cc:518
static std::shared_ptr< Rom > shared_rom_
Definition rom.h:392
static Flags & get()
Definition features.h:69
The Renderer class represents the renderer for the Yaze application.
Definition renderer.h:24
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
Definition renderer.h:48
SNES Color container.
Definition snes_color.h:38
bool is_modified() const
Definition snes_color.h:91
uint16_t snes() const
Definition snes_color.h:90
void set_modified(bool m)
Definition snes_color.h:94
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Tile composition of four 8x8 tiles.
Definition snes_tile.h:129
#define RETURN_IF_ERROR(expression)
Definition macro.h:62
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:70
absl::StatusOr< std::vector< uint8_t > > DecompressV2(const uint8_t *data, int offset, int size, int mode)
Decompresses a buffer of data using the LC_LZ2 algorithm.
constexpr int kTilesheetHeight
Definition snes_tile.h:16
constexpr int kTilesheetWidth
Definition snes_tile.h:15
uint16_t TileInfoToWord(TileInfo tile_info)
Definition snes_tile.cc:313
constexpr int kTilesheetDepth
Definition snes_tile.h:17
std::vector< uint8_t > Bpp8SnesToIndexed(std::vector< uint8_t > data, uint64_t bpp)
Definition snes_tile.cc:211
uint32_t GetPaletteAddress(const std::string &group_name, size_t palette_index, size_t color_index)
TileInfo WordToTileInfo(uint16_t word)
Definition snes_tile.cc:330
std::vector< uint8_t > HyruleMagicCompress(uint8_t const *const src, int const oldsize, int *const size, int const flag)
absl::Status LoadAllPalettes(const std::vector< uint8_t > &rom_data, PaletteGroupMap &groups)
Loads all the palettes for the game.
std::vector< uint8_t > SnesTo8bppSheet(const std::vector< uint8_t > &sheet, int bpp, int num_sheets)
Definition snes_tile.cc:151
std::string HexWord(uint16_t word, HexStringParams params)
Definition hex.cc:46
std::string HexByte(uint8_t byte, HexStringParams params)
Definition hex.cc:33
std::string HexLong(uint32_t dword, HexStringParams params)
Definition hex.cc:59
Main namespace for the application.
Definition controller.cc:18
constexpr uint32_t kGfxGroupsPointer
Definition rom.h:36
absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics(const Rom &rom)
Loads 2bpp graphics from Rom data.
Definition rom.cc:39
absl::StatusOr< std::array< gfx::Bitmap, kNumLinkSheets > > LoadLinkGraphics(const Rom &rom)
Loads the players 4bpp graphics sheet from Rom data.
Definition rom.cc:58
constexpr int Uncompressed3BPPSize
Definition rom.cc:31
constexpr uint32_t kNumLinkSheets
Definition rom.h:31
constexpr uint32_t kEntranceGfxGroup
Definition rom.h:42
constexpr uint32_t kNumSpritesets
Definition rom.h:40
int AddressFromBytes(uint8_t bank, uint8_t high, uint8_t low) noexcept
Definition rom.h:358
constexpr uint32_t kTile16Ptr
Definition rom.h:32
constexpr uint32_t kNumMainBlocksets
Definition rom.h:38
constexpr uint32_t kNumRoomBlocksets
Definition rom.h:39
constexpr uint32_t kNumGfxSheets
Definition rom.h:30
absl::StatusOr< std::array< gfx::Bitmap, kNumGfxSheets > > LoadAllGraphicsData(Rom &rom, bool defer_render)
This function iterates over all graphics sheets in the Rom and loads them into memory....
Definition rom.cc:78
uint32_t GetGraphicsAddress(const uint8_t *data, uint8_t addr, uint32_t ptr1, uint32_t ptr2, uint32_t ptr3)
Definition rom.cc:33
constexpr uint32_t kNumPalettesets
Definition rom.h:41
absl::Status SaveAllGraphicsData(Rom &rom, std::array< gfx::Bitmap, kNumGfxSheets > &gfx_sheets)
Definition rom.cc:137
uint32_t SnesToPc(uint32_t addr) noexcept
Definition rom.h:328
Represents a group of palettes.
uint32_t kOverworldGfxPtr1
Definition zelda.h:33
uint32_t kOverworldGfxPtr2
Definition zelda.h:34
uint32_t kOverworldGfxPtr3
Definition zelda.h:35
@ US
Definition zelda.h:14
@ JP
Definition zelda.h:15