yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
diagnostic_types.h
Go to the documentation of this file.
1#ifndef YAZE_CLI_HANDLERS_TOOLS_DIAGNOSTIC_TYPES_H
2#define YAZE_CLI_HANDLERS_TOOLS_DIAGNOSTIC_TYPES_H
3
4#include <cstdint>
5#include <map>
6#include <string>
7#include <vector>
8
9#include "absl/strings/str_format.h"
10
11namespace yaze::cli {
12
17 kInfo, // Informational, no action needed
18 kWarning, // Potential issue, may need attention
19 kError, // Problem detected, should be fixed
20 kCritical // Severe issue, requires immediate attention
21};
22
26inline std::string SeverityToString(DiagnosticSeverity severity) {
27 switch (severity) {
29 return "info";
31 return "warning";
33 return "error";
35 return "critical";
36 }
37 return "unknown";
38}
39
44 std::string id; // Unique identifier, e.g., "tile16_corruption"
46 std::string message; // Human-readable description
47 std::string location; // Address or location, e.g., "0x1E878B"
48 std::string suggested_action; // What to do about it
49 bool fixable = false; // Can this be auto-fixed?
50
54 std::string FormatText() const {
55 std::string prefix;
56 switch (severity) {
58 prefix = "[INFO]";
59 break;
61 prefix = "[WARN]";
62 break;
64 prefix = "[ERROR]";
65 break;
67 prefix = "[CRITICAL]";
68 break;
69 }
70 std::string result = absl::StrFormat("%s %s", prefix, message);
71 if (!location.empty()) {
72 result += absl::StrFormat(" at %s", location);
73 }
74 if (fixable) {
75 result += " [fixable]";
76 }
77 return result;
78 }
79
83 std::string FormatJson() const {
84 return absl::StrFormat(
85 R"({"id":"%s","severity":"%s","message":"%s","location":"%s","suggested_action":"%s","fixable":%s})",
87 fixable ? "true" : "false");
88 }
89};
90
95 // Version info
96 uint8_t zs_custom_version = 0xFF; // 0xFF = vanilla, 2 = v2, 3 = v3
97 bool is_vanilla = true;
98 bool is_v2 = false;
99 bool is_v3 = false;
100
101 // Expanded data flags
104 bool has_expanded_pointer_tables = false; // Requires ASM patch
105
106 // ZSCustomOverworld features (ROM-level enable flags)
107 bool custom_bg_enabled = false;
113
117 std::string GetVersionString() const {
118 if (is_vanilla)
119 return "Vanilla";
120 if (is_v2)
121 return "ZSCustomOverworld v2";
122 if (is_v3)
123 return "ZSCustomOverworld v3";
124 return absl::StrFormat("Unknown (0x%02X)", zs_custom_version);
125 }
126};
127
132 bool lw_dw_maps_valid = true; // Maps 0x00-0x7F
133 bool sw_maps_valid = true; // Maps 0x80-0x9F
134 bool tail_maps_valid = false; // Maps 0xA0-0xBF (requires expansion)
136 bool can_support_tail = false; // True only if expanded pointer tables exist
137};
138
145 bool uses_expanded = false;
146};
147
152 std::string rom_path;
156 std::vector<DiagnosticFinding> findings;
157
158 // Summary counts
159 int info_count = 0;
161 int error_count = 0;
164
168 void AddFinding(const DiagnosticFinding& finding) {
169 findings.push_back(finding);
170 switch (finding.severity) {
172 info_count++;
173 break;
176 break;
178 error_count++;
179 break;
182 break;
183 }
184 if (finding.fixable)
186 }
187
191 bool HasProblems() const { return critical_count > 0 || error_count > 0; }
192
196 bool HasFixable() const { return fixable_count > 0; }
197
201 int TotalFindings() const { return static_cast<int>(findings.size()); }
202};
203
208 std::map<uint16_t, int> counts;
209 int total = 0;
210 int unique = 0;
211 int invalid = 0;
212 uint16_t most_common_map = 0;
214};
215
220 struct RomInfo {
221 std::string filename;
222 size_t size = 0;
223 uint8_t zs_version = 0xFF;
226 uint32_t checksum = 0;
227 };
228
229 struct DiffRegion {
230 uint32_t start;
231 uint32_t end;
233 std::string region_name;
235 };
236
239 bool sizes_match = false;
240 bool versions_match = false;
241 bool features_match = false;
242 std::vector<DiffRegion> diff_regions;
244};
245
246// =============================================================================
247// ROM Layout Constants (shared across diagnostic commands)
248// =============================================================================
249
250// ROM header locations (LoROM)
251constexpr uint32_t kSnesHeaderBase = 0x7FC0;
252constexpr uint32_t kChecksumComplementPos = 0x7FDC;
253constexpr uint32_t kChecksumPos = 0x7FDE;
254
255// Tile16 expanded region
256constexpr uint32_t kMap16TilesExpanded = 0x1E8000;
257constexpr uint32_t kMap16TilesExpandedEnd = 0x1F0000;
258constexpr uint32_t kMap16ExpandedFlagPos = 0x02FD28;
259constexpr uint32_t kMap32ExpandedFlagPos = 0x01772E;
260constexpr int kNumTile16Vanilla = 3752;
261constexpr int kNumTile16Expanded = 4096;
262
263// Pointer table layout (vanilla - 160 entries only!)
264// CRITICAL: These tables only cover maps 0x00-0x9F (160 maps)
265// Maps 0xA0-0xBF do NOT have pointer table entries without ASM expansion
266constexpr uint32_t kPtrTableLowBase = 0x1794D; // 160 entries × 3 bytes = 0x1E0
267constexpr uint32_t kPtrTableHighBase = 0x17B2D; // Starts right after low table
268constexpr int kVanillaMapCount = 160; // 0x00-0x9F only
269
270// ZSCustomOverworld version markers
271constexpr uint32_t kZSCustomVersionPos = 0x140145;
272
273// ZSCustomOverworld feature enable flags
274constexpr uint32_t kCustomBGEnabledPos = 0x140141;
275constexpr uint32_t kCustomMainPalettePos = 0x140142;
276constexpr uint32_t kCustomMosaicPos = 0x140143;
277constexpr uint32_t kCustomAnimatedGFXPos = 0x140146;
278constexpr uint32_t kCustomOverlayPos = 0x140147;
279constexpr uint32_t kCustomTileGFXPos = 0x140148;
280
281// ASM expansion markers for tail map support
282// When TailMapExpansion.asm patch is applied, these locations will be set:
283// - Marker byte at 0x1423FF ($28:A3FF) = 0xEA to indicate expansion
284// - New High table at 0x142400 ($28:A400) with 192 entries
285// - New Low table at 0x142640 ($28:A640) with 192 entries
286constexpr uint32_t kExpandedPtrTableMarker = 0x1423FF; // Marker location
287constexpr uint8_t kExpandedPtrTableMagic = 0xEA; // Marker value
288constexpr uint32_t kExpandedPtrTableHigh = 0x142400; // New high table
289constexpr uint32_t kExpandedPtrTableLow = 0x142640; // New low table
290constexpr int kExpandedMapCount = 192; // 0x00-0xBF
291
292} // namespace yaze::cli
293
294#endif // YAZE_CLI_HANDLERS_TOOLS_DIAGNOSTIC_TYPES_H
constexpr uint32_t kExpandedPtrTableLow
constexpr uint32_t kCustomBGEnabledPos
constexpr uint32_t kExpandedPtrTableMarker
constexpr uint32_t kChecksumPos
constexpr uint32_t kPtrTableHighBase
constexpr uint32_t kCustomOverlayPos
constexpr uint8_t kExpandedPtrTableMagic
std::string SeverityToString(DiagnosticSeverity severity)
Convert severity to string for output.
constexpr uint32_t kMap32ExpandedFlagPos
constexpr uint32_t kZSCustomVersionPos
constexpr int kExpandedMapCount
constexpr uint32_t kMap16ExpandedFlagPos
constexpr uint32_t kExpandedPtrTableHigh
constexpr uint32_t kPtrTableLowBase
constexpr uint32_t kCustomMosaicPos
constexpr uint32_t kMap16TilesExpanded
constexpr uint32_t kCustomTileGFXPos
constexpr uint32_t kMap16TilesExpandedEnd
constexpr int kNumTile16Vanilla
constexpr uint32_t kSnesHeaderBase
constexpr int kVanillaMapCount
constexpr int kNumTile16Expanded
constexpr uint32_t kCustomAnimatedGFXPos
DiagnosticSeverity
Severity level for diagnostic findings.
constexpr uint32_t kChecksumComplementPos
constexpr uint32_t kCustomMainPalettePos
A single diagnostic finding.
std::string FormatText() const
Format finding for text output.
std::string FormatJson() const
Format finding as JSON object string.
Complete diagnostic report.
std::vector< DiagnosticFinding > findings
int TotalFindings() const
Get total finding count.
bool HasProblems() const
Check if report has any critical or error findings.
void AddFinding(const DiagnosticFinding &finding)
Add a finding and update counts.
bool HasFixable() const
Check if report has any fixable findings.
Entity distribution statistics for coverage analysis.
std::map< uint16_t, int > counts
Map pointer validation status.
ROM comparison result for baseline comparisons.
std::vector< DiffRegion > diff_regions
ROM feature detection results.
std::string GetVersionString() const
Get version as human-readable string.
Tile16 region status. Every 16-bit value is a legal tile word (vhopppcc cccccccc),...