yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_sprite_io.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_OVERWORLD_SPRITE_IO_H
2#define YAZE_ZELDA3_OVERWORLD_SPRITE_IO_H
3
4#include <array>
5#include <cstdint>
6#include <optional>
7#include <utility>
8#include <vector>
9#include "absl/status/statusor.h"
10#include "rom/rom.h"
11
12namespace yaze::zelda3 {
13// PC offsets: USDASM bank_09, Overworld_Sprites_EMPTY through the start of
14// RoomData_SpritePointers. Expanded tables reclaim the original OW pointers.
15constexpr int kOverworldSpriteDataStart = 0x4CB41;
16constexpr int kOverworldSpriteDataEnd = 0x4D62E;
18 std::array<int, 3> tables;
19 std::array<int, 3> counts;
21};
23// Operand of the room sprite pointer-table load in bank $09 (vanilla
24// LDA $09D62E,X at $09:C298). ZScream can move that table below $09:D62E, so
25// the overworld region ends at whichever comes first.
26constexpr int kRoomSpritePointerTableOperand = 0x4C298;
27// Exclusive PC end of the overworld sprite region for this ROM.
28int GetOverworldSpriteRegionEnd(const Rom& rom);
29using OverworldSpriteBytes = std::vector<uint8_t>; // y, x, id; final FF
31 std::array<std::array<std::optional<OverworldSpriteBytes>, 160>, 3>;
34 std::vector<uint8_t> bytes;
35};
36using OverworldSpriteSavePlan = std::vector<OverworldSpriteWrite>;
37
38absl::StatusOr<OverworldSpriteBytes> ReadOverworldSpriteList(
39 const Rom& rom, int pointer_address);
40// Preserve every untouched list, including entries outside the editor's loaded
41// maps. Deduplicate exact ordered streams; reject overflow before any mutation.
42absl::StatusOr<OverworldSpriteSavePlan> PlanOverworldSpriteSave(
43 const Rom& rom, const OverworldSpriteEdits& edits);
44// Minimal-diff edit of one (game state, map) list: rewrite in place when the
45// list is unshared and fits (or the bytes after it are unreferenced), else
46// copy the list into unreferenced region bytes and repoint only this slot.
47// Fails with ResourceExhausted when no unreferenced run can hold the list.
57 int pointer_pc = 0;
58 int old_list_pc = 0;
60 int new_list_pc = 0;
62 // Other (state, map) slots whose lists alias or overlap the old list.
63 std::vector<std::pair<int, int>> sharers;
64 int region_start = 0;
65 int region_end = 0;
66 int unreferenced_bytes = 0; // before the edit
68};
69absl::StatusOr<OverworldSpriteListEditPlan> PlanOverworldSpriteListEdit(
70 const Rom& rom, int state, int map,
71 const OverworldSpriteBytes& replacement);
72// Atomic, fenced publication; outer write fences remain effective.
73absl::Status ApplyOverworldSpriteSave(Rom& rom,
74 const OverworldSpriteSavePlan& plan);
75} // namespace yaze::zelda3
76#endif
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.
std::vector< uint8_t > OverworldSpriteBytes
absl::StatusOr< OverworldSpriteListEditPlan > PlanOverworldSpriteListEdit(const Rom &rom, int state, int map, const OverworldSpriteBytes &replacement)
constexpr int kOverworldSpriteDataEnd
constexpr int kRoomSpritePointerTableOperand
absl::StatusOr< OverworldSpriteBytes > ReadOverworldSpriteList(const Rom &rom, int pointer_address)
absl::Status ApplyOverworldSpriteSave(Rom &rom, const OverworldSpriteSavePlan &plan)
constexpr int kOverworldSpriteDataStart
int GetOverworldSpriteRegionEnd(const Rom &rom)
const char * OverworldSpriteEditStrategyName(OverworldSpriteEditStrategy s)
std::array< std::array< std::optional< OverworldSpriteBytes >, 160 >, 3 > OverworldSpriteEdits
absl::StatusOr< OverworldSpriteSavePlan > PlanOverworldSpriteSave(const Rom &rom, const OverworldSpriteEdits &edits)
OverworldSpriteLayout GetOverworldSpriteLayout(const Rom &rom)
std::vector< OverworldSpriteWrite > OverworldSpriteSavePlan
std::vector< std::pair< int, int > > sharers