yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
semantic_introspection.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_DEBUG_SEMANTIC_INTROSPECTION_H
2#define YAZE_APP_EMU_DEBUG_SEMANTIC_INTROSPECTION_H
3
4#include <cstdint>
5#include <string>
6#include <vector>
7
8#include "absl/status/statusor.h"
10
11namespace yaze {
12namespace emu {
13namespace debug {
14
15// ALTTP-specific RAM addresses
16namespace alttp {
17// Game Mode
18constexpr uint32_t kGameMode = 0x7E0010;
19constexpr uint32_t kSubmodule = 0x7E0011;
20constexpr uint32_t kIndoorFlag = 0x7E001B;
21
22// Player
23constexpr uint32_t kLinkYLow = 0x7E0020;
24constexpr uint32_t kLinkYHigh = 0x7E0021;
25constexpr uint32_t kLinkXLow = 0x7E0022;
26constexpr uint32_t kLinkXHigh = 0x7E0023;
27constexpr uint32_t kLinkDirection = 0x7E002F;
28constexpr uint32_t kLinkState = 0x7E005D;
29constexpr uint32_t kLinkLayer = 0x7E00EE;
30constexpr uint32_t kLinkHealth = 0x7E00F6;
31constexpr uint32_t kLinkMaxHealth = 0x7E00F7;
32
33// Location
34constexpr uint32_t kOverworldArea = 0x7E008A;
35constexpr uint32_t kDungeonRoom = 0x7E00A0;
36constexpr uint32_t kDungeonRoomLow = 0x7E00A0;
37constexpr uint32_t kDungeonRoomHigh = 0x7E00A1;
38
39// Sprites (base addresses, add slot offset 0-15)
40constexpr uint32_t kSpriteYLow = 0x7E0D00;
41constexpr uint32_t kSpriteYHigh = 0x7E0D20;
42constexpr uint32_t kSpriteXLow = 0x7E0D10;
43constexpr uint32_t kSpriteXHigh = 0x7E0D30;
44constexpr uint32_t kSpriteState = 0x7E0DD0;
45constexpr uint32_t kSpriteType = 0x7E0E20;
46
47// Frame timing
48constexpr uint32_t kFrameCounter = 0x7E001A;
49} // namespace alttp
50
55 uint8_t id; // Sprite slot ID (0-15)
56 uint16_t x; // X coordinate
57 uint16_t y; // Y coordinate
58 uint8_t type; // Sprite type ID
59 std::string type_name; // Human-readable sprite type name
60 uint8_t state; // Sprite state
61 std::string state_name; // Human-readable state (Active, Dead, etc.)
62};
63
68 uint16_t x; // X coordinate
69 uint16_t y; // Y coordinate
70 uint8_t state; // Action state
71 std::string state_name; // Human-readable state (Walking, Attacking, etc.)
72 uint8_t direction; // Facing direction (0=up, 2=down, 4=left, 6=right)
73 std::string direction_name; // Human-readable direction
74 uint8_t layer; // Z-layer (upper/lower)
75 uint8_t health; // Current health
76 uint8_t max_health; // Maximum health
77};
78
83 bool indoors; // True if in dungeon/house, false if overworld
84 uint8_t overworld_area; // Overworld area ID (if outdoors)
85 uint16_t dungeon_room; // Dungeon room ID (if indoors)
86 std::string room_name; // Human-readable location name
87 std::string area_name; // Human-readable area name
88};
89
94 uint8_t main_mode; // Main game mode value
95 uint8_t submodule; // Submodule value
96 std::string mode_name; // Human-readable mode name
97 bool in_game; // True if actively playing (not in menu/title)
98 bool in_transition; // True if transitioning between screens
99};
100
104struct FrameInfo {
105 uint8_t frame_counter; // Current frame counter value
106 bool is_lag_frame; // True if this frame is lagging
107};
108
119
128 public:
133 explicit SemanticIntrospectionEngine(Memory* memory);
135
140 absl::StatusOr<SemanticGameState> GetSemanticState();
141
146 absl::StatusOr<std::string> GetStateAsJson();
147
152 absl::StatusOr<PlayerState> GetPlayerState();
153
158 absl::StatusOr<std::vector<SpriteState>> GetSpriteStates();
159
164 absl::StatusOr<LocationContext> GetLocationContext();
165
170 absl::StatusOr<GameModeState> GetGameModeState();
171
172 private:
173 Memory* memory_; // Non-owning pointer to SNES memory
174
175 // Helper methods for name lookups
176 std::string GetGameModeName(uint8_t mode, uint8_t submodule);
177 std::string GetPlayerStateName(uint8_t state);
178 std::string GetPlayerDirectionName(uint8_t direction);
179 std::string GetSpriteTypeName(uint8_t type);
180 std::string GetSpriteStateName(uint8_t state);
181 std::string GetOverworldAreaName(uint8_t area);
182 std::string GetDungeonRoomName(uint16_t room);
183};
184
185} // namespace debug
186} // namespace emu
187} // namespace yaze
188
189#endif // YAZE_APP_EMU_DEBUG_SEMANTIC_INTROSPECTION_H
Memory interface.
Definition memory.h:64
Engine for extracting semantic game state from SNES memory.
absl::StatusOr< LocationContext > GetLocationContext()
Get the current location context.
absl::StatusOr< GameModeState > GetGameModeState()
Get the current game mode state.
SemanticIntrospectionEngine(Memory *memory)
Construct a new Semantic Introspection Engine.
absl::StatusOr< std::string > GetStateAsJson()
Get the semantic state as JSON string.
absl::StatusOr< SemanticGameState > GetSemanticState()
Get the complete semantic game state.
absl::StatusOr< PlayerState > GetPlayerState()
Get only the player state.
absl::StatusOr< std::vector< SpriteState > > GetSpriteStates()
Get all active sprite states.
std::string GetGameModeName(uint8_t mode, uint8_t submodule)
constexpr uint32_t kLinkDirection
constexpr uint32_t kOverworldArea
constexpr uint32_t kDungeonRoomHigh
constexpr uint32_t kDungeonRoomLow
constexpr uint32_t kLinkMaxHealth
Semantic representation of the game mode.
Semantic representation of the current location.
Semantic representation of the player state.
Semantic representation of a sprite entity.