yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
gfx_sheet_storage.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_GFX_SHEET_STORAGE_H
2#define YAZE_ZELDA3_GFX_SHEET_STORAGE_H
3
4#include <array>
5#include <cstddef>
6#include <cstdint>
7#include <functional>
8#include <map>
9#include <set>
10#include <string>
11#include <vector>
12
13#include "absl/status/status.h"
14#include "absl/status/statusor.h"
15#include "rom/rom.h"
16
17namespace yaze::zelda3 {
18
31constexpr size_t kGfxSheetCount = 223;
32constexpr size_t kGfxSheet3bppBytes = 0x600;
33constexpr size_t kGfxSheet2bppBytes = 0x800;
34
40
43
46 uint32_t bank = 0x4F80;
47 uint32_t high = 0x505F;
48 uint32_t low = 0x513E;
49};
50
54bool UsesJapaneseGfxSheetTables(const Rom& rom);
55
58 uint32_t begin = 0;
59 uint32_t end = 0;
60};
61
64 uint16_t sheet_id = 0;
66 uint32_t pc = 0;
67 // Bytes the sheet occupies at pc (compressed size including the 0xFF
68 // terminator, or 0x600 for raw sheets).
69 size_t stored_size = 0;
70 // Bytes the sheet expands to.
71 size_t decoded_size = 0;
72};
73
75absl::StatusOr<uint32_t> ReadGfxSheetPc(
76 const Rom& rom, uint16_t sheet_id,
77 const GfxSheetPointerTables& tables = {});
78
81absl::StatusOr<GfxSheetExtent> ReadGfxSheetExtent(
82 const Rom& rom, uint16_t sheet_id,
83 const GfxSheetPointerTables& tables = {});
84
86absl::StatusOr<std::vector<uint8_t>> ReadGfxSheetData(
87 const Rom& rom, uint16_t sheet_id,
88 const GfxSheetPointerTables& tables = {});
89
91constexpr int kGfxSheetBlockCount = 16;
92
95std::array<int, 4> GfxSheetBlockTiles(int block);
96
99bool IsGfxSheetBlockEmpty(const std::vector<uint8_t>& data, int block,
100 int bpp = 3);
101
104 // Free space a sheet may move to when its new stream no longer fits.
105 // Bytes in these ranges that no sheet pointer references are free.
106 // Empty means relocation is refused.
107 std::vector<GfxSheetPcRange> allocation_regions;
108 // Sheets that must never be written.
109 std::set<uint16_t> reserved_sheets;
110 // 16x16 blocks (0-15) per sheet whose pixels must not change.
111 std::map<uint16_t, std::vector<uint16_t>> reserved_blocks;
112 // Returns an error when [begin, end) must not be written (for example a
113 // hack-manifest protected region). Unset means no extra check.
114 std::function<absl::Status(uint32_t begin, uint32_t end)> check_write;
115};
116
118
120 uint16_t sheet_id = 0;
122 uint32_t old_pc = 0;
123 uint32_t new_pc = 0;
124 // 0 when the old stream could not be measured.
125 size_t old_stored_size = 0;
126 size_t new_stored_size = 0;
127};
128
144absl::StatusOr<GfxSheetWriteResult> WriteGfxSheet(
145 Rom& rom, uint16_t sheet_id, const std::vector<uint8_t>& snes_3bpp,
146 const GfxSheetWritePolicy& policy,
147 const GfxSheetPointerTables& tables = {});
148
149} // namespace yaze::zelda3
150
151#endif // YAZE_ZELDA3_GFX_SHEET_STORAGE_H
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
Zelda 3 specific classes and functions.
absl::StatusOr< GfxSheetExtent > ReadGfxSheetExtent(const Rom &rom, uint16_t sheet_id, const GfxSheetPointerTables &tables)
constexpr size_t kGfxSheet3bppBytes
std::array< int, 4 > GfxSheetBlockTiles(int block)
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).
absl::StatusOr< GfxSheetWriteResult > WriteGfxSheet(Rom &rom, uint16_t sheet_id, const std::vector< uint8_t > &snes_3bpp, const GfxSheetWritePolicy &policy, const GfxSheetPointerTables &tables)
Writes one edited 3bpp sheet to the ROM buffer.
constexpr size_t kGfxSheet2bppBytes
bool IsGfxSheetBlockEmpty(const std::vector< uint8_t > &data, int block, int bpp)
GfxSheetStorageKind GetGfxSheetStorageKind(uint16_t sheet_id)
constexpr size_t kGfxSheetCount
bool UsesJapaneseGfxSheetTables(const Rom &rom)
constexpr int kGfxSheetBlockCount
16x16 blocks per sheet: 8 columns x 2 rows over the 128x32 sheet.
const char * GfxSheetStorageKindName(GfxSheetStorageKind kind)
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.
Where one sheet's bytes live and how many bytes they occupy.
Half-open PC range [begin, end).
PC offsets of the bank, high and low byte pointer tables.
Rules a sheet write must follow.
std::vector< GfxSheetPcRange > allocation_regions
std::function< absl::Status(uint32_t begin, uint32_t end)> check_write
std::map< uint16_t, std::vector< uint16_t > > reserved_blocks