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