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