yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_save_plan.cc
Go to the documentation of this file.
2
3#include "absl/strings/str_format.h"
6#include "rom/rom.h"
7#include "util/macro.h"
8
9namespace yaze::editor {
10
12 const Rom& rom, uint16_t sheet_id,
13 const std::vector<uint8_t>& expected_pixels,
14 const zelda3::GfxSheetPointerTables& tables) {
15 ASSIGN_OR_RETURN(const auto exact,
16 zelda3::ReadGfxSheetData(rom, sheet_id, tables));
17 if (gfx::SnesTo8bppSheet(exact, /*bpp=*/3) != expected_pixels) {
18 return absl::DataLossError(absl::StrFormat(
19 "Sheet 0x%02X decodes (game decoder) to different pixels than were "
20 "edited",
21 sheet_id));
22 }
23 if (zelda3::GetGfxSheetStorageKind(sheet_id) !=
25 return absl::OkStatus();
26 }
27 // The editor loads sheets with DecompressV2 (zelda3::LoadGameData); the
28 // sheet must also reopen as edited through that path.
29 ASSIGN_OR_RETURN(const uint32_t pc,
30 zelda3::ReadGfxSheetPc(rom, sheet_id, tables));
32 rom.data(), static_cast<int>(pc), 0x800,
33 /*mode=*/1, rom.size()));
34 if (loaded.size() < zelda3::kGfxSheet3bppBytes) {
35 return absl::DataLossError(
36 absl::StrFormat("Sheet 0x%02X reopens (editor loader) with %zu bytes",
37 sheet_id, loaded.size()));
38 }
39 loaded.resize(zelda3::kGfxSheet3bppBytes);
40 if (gfx::SnesTo8bppSheet(loaded, /*bpp=*/3) != expected_pixels) {
41 return absl::DataLossError(absl::StrFormat(
42 "Sheet 0x%02X reopens (editor loader) with different pixels than "
43 "were edited",
44 sheet_id));
45 }
46 return absl::OkStatus();
47}
48
50 if (!entry.refusal.empty()) {
51 return absl::StrFormat("Sheet 0x%02X: refused (%s)", entry.sheet_id,
52 entry.refusal);
53 }
55 return absl::StrFormat(
56 "Sheet 0x%02X: relocated 0x%06X -> 0x%06X, %zu -> %zu bytes",
57 entry.sheet_id, entry.old_pc, entry.new_pc, entry.old_stored_size,
58 entry.new_stored_size);
59 }
60 return absl::StrFormat("Sheet 0x%02X: in place at 0x%06X, %zu -> %zu bytes",
61 entry.sheet_id, entry.new_pc, entry.old_stored_size,
62 entry.new_stored_size);
63}
64
65} // namespace yaze::editor
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:49
auto data() const
Definition rom.h:201
auto size() const
Definition rom.h:200
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:62
Editors are the view controllers for the application.
std::string DescribeGraphicsSavePlanEntry(const GraphicsSavePlanEntry &entry)
"Sheet 0x92: in place at 0x0AED16, 1476 -> 1473 bytes".
absl::Status VerifyWrittenSheetPixels(const Rom &rom, uint16_t sheet_id, const std::vector< uint8_t > &expected_pixels, const zelda3::GfxSheetPointerTables &tables)
absl::StatusOr< std::vector< uint8_t > > DecompressV2(const uint8_t *data, int offset, int size, int mode, size_t rom_size)
Decompresses a buffer of data using the LC_LZ2 algorithm.
std::vector< uint8_t > SnesTo8bppSheet(std::span< const uint8_t > sheet, int bpp, int num_sheets)
Definition snes_tile.cc:133
constexpr size_t kGfxSheet3bppBytes
absl::StatusOr< std::vector< uint8_t > > ReadGfxSheetData(const Rom &rom, uint16_t sheet_id, const GfxSheetPointerTables &tables)
Returns the sheet's decoded bytes (SNES planar data).
GfxSheetStorageKind GetGfxSheetStorageKind(uint16_t sheet_id)
absl::StatusOr< uint32_t > ReadGfxSheetPc(const Rom &rom, uint16_t sheet_id, const GfxSheetPointerTables &tables)
Resolves a sheet's pointer. Does not read the sheet data.
zelda3::GfxSheetPlacement placement
PC offsets of the bank, high and low byte pointer tables.