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) {
28 case DiagnosticSeverity::kInfo: return "info";
29 case DiagnosticSeverity::kWarning: return "warning";
30 case DiagnosticSeverity::kError: return "error";
31 case DiagnosticSeverity::kCritical: return "critical";
32 }
33 return "unknown";
34}
35
40 std::string id; // Unique identifier, e.g., "tile16_corruption"
42 std::string message; // Human-readable description
43 std::string location; // Address or location, e.g., "0x1E878B"
44 std::string suggested_action; // What to do about it
45 bool fixable = false; // Can this be auto-fixed?
46
50 std::string FormatText() const {
51 std::string prefix;
52 switch (severity) {
53 case DiagnosticSeverity::kInfo: prefix = "[INFO]"; break;
54 case DiagnosticSeverity::kWarning: prefix = "[WARN]"; break;
55 case DiagnosticSeverity::kError: prefix = "[ERROR]"; break;
56 case DiagnosticSeverity::kCritical: prefix = "[CRITICAL]"; break;
57 }
58 std::string result = absl::StrFormat("%s %s", prefix, message);
59 if (!location.empty()) {
60 result += absl::StrFormat(" at %s", location);
61 }
62 if (fixable) {
63 result += " [fixable]";
64 }
65 return result;
66 }
67
71 std::string FormatJson() const {
72 return absl::StrFormat(
73 R"({"id":"%s","severity":"%s","message":"%s","location":"%s","suggested_action":"%s","fixable":%s})",
75 fixable ? "true" : "false");
76 }
77};
78
83 // Version info
84 uint8_t zs_custom_version = 0xFF; // 0xFF = vanilla, 2 = v2, 3 = v3
85 bool is_vanilla = true;
86 bool is_v2 = false;
87 bool is_v3 = false;
88
89 // Expanded data flags
90 bool has_expanded_tile16 = false;
91 bool has_expanded_tile32 = false;
92 bool has_expanded_pointer_tables = false; // Requires ASM patch
93
94 // ZSCustomOverworld features (ROM-level enable flags)
95 bool custom_bg_enabled = false;
101
105 std::string GetVersionString() const {
106 if (is_vanilla) return "Vanilla";
107 if (is_v2) return "ZSCustomOverworld v2";
108 if (is_v3) return "ZSCustomOverworld v3";
109 return absl::StrFormat("Unknown (0x%02X)", zs_custom_version);
110 }
111};
112
117 bool lw_dw_maps_valid = true; // Maps 0x00-0x7F
118 bool sw_maps_valid = true; // Maps 0x80-0x9F
119 bool tail_maps_valid = false; // Maps 0xA0-0xBF (requires expansion)
121 bool can_support_tail = false; // True only if expanded pointer tables exist
122};
123
128 bool uses_expanded = false;
130 std::vector<uint32_t> corrupted_addresses;
132};
133
138 std::string rom_path;
142 std::vector<DiagnosticFinding> findings;
143
144 // Summary counts
145 int info_count = 0;
147 int error_count = 0;
150
154 void AddFinding(const DiagnosticFinding& finding) {
155 findings.push_back(finding);
156 switch (finding.severity) {
161 }
162 if (finding.fixable) fixable_count++;
163 }
164
168 bool HasProblems() const {
169 return critical_count > 0 || error_count > 0;
170 }
171
175 bool HasFixable() const {
176 return fixable_count > 0;
177 }
178
182 int TotalFindings() const {
183 return static_cast<int>(findings.size());
184 }
185};
186
191 std::map<uint16_t, int> counts;
192 int total = 0;
193 int unique = 0;
194 int invalid = 0;
195 uint16_t most_common_map = 0;
197};
198
203 struct RomInfo {
204 std::string filename;
205 size_t size = 0;
206 uint8_t zs_version = 0xFF;
209 uint32_t checksum = 0;
210 };
211
212 struct DiffRegion {
213 uint32_t start;
214 uint32_t end;
216 std::string region_name;
218 };
219
222 bool sizes_match = false;
223 bool versions_match = false;
224 bool features_match = false;
225 std::vector<DiffRegion> diff_regions;
227};
228
229// =============================================================================
230// ROM Layout Constants (shared across diagnostic commands)
231// =============================================================================
232
233// ROM header locations (LoROM)
234constexpr uint32_t kSnesHeaderBase = 0x7FC0;
235constexpr uint32_t kChecksumComplementPos = 0x7FDC;
236constexpr uint32_t kChecksumPos = 0x7FDE;
237
238// Tile16 expanded region
239constexpr uint32_t kMap16TilesExpanded = 0x1E8000;
240constexpr uint32_t kMap16TilesExpandedEnd = 0x1F0000;
241constexpr uint32_t kMap16ExpandedFlagPos = 0x02FD28;
242constexpr uint32_t kMap32ExpandedFlagPos = 0x01772E;
243constexpr int kNumTile16Vanilla = 3752;
244constexpr int kNumTile16Expanded = 4096;
245
246// Pointer table layout (vanilla - 160 entries only!)
247// CRITICAL: These tables only cover maps 0x00-0x9F (160 maps)
248// Maps 0xA0-0xBF do NOT have pointer table entries without ASM expansion
249constexpr uint32_t kPtrTableLowBase = 0x1794D; // 160 entries × 3 bytes = 0x1E0
250constexpr uint32_t kPtrTableHighBase = 0x17B2D; // Starts right after low table
251constexpr int kVanillaMapCount = 160; // 0x00-0x9F only
252
253// ZSCustomOverworld version markers
254constexpr uint32_t kZSCustomVersionPos = 0x140145;
255
256// ZSCustomOverworld feature enable flags
257constexpr uint32_t kCustomBGEnabledPos = 0x140141;
258constexpr uint32_t kCustomMainPalettePos = 0x140142;
259constexpr uint32_t kCustomMosaicPos = 0x140143;
260constexpr uint32_t kCustomAnimatedGFXPos = 0x140146;
261constexpr uint32_t kCustomOverlayPos = 0x140147;
262constexpr uint32_t kCustomTileGFXPos = 0x140148;
263
264// ASM expansion markers for tail map support
265// When TailMapExpansion.asm patch is applied, these locations will be set:
266// - Marker byte at 0x1423FF ($28:A3FF) = 0xEA to indicate expansion
267// - New High table at 0x142400 ($28:A400) with 192 entries
268// - New Low table at 0x142640 ($28:A640) with 192 entries
269constexpr uint32_t kExpandedPtrTableMarker = 0x1423FF; // Marker location
270constexpr uint8_t kExpandedPtrTableMagic = 0xEA; // Marker value
271constexpr uint32_t kExpandedPtrTableHigh = 0x142400; // New high table
272constexpr uint32_t kExpandedPtrTableLow = 0x142640; // New low table
273constexpr int kExpandedMapCount = 192; // 0x00-0xBF
274
275// Known problematic addresses in tile16 region (from previous corruption)
276const uint32_t kProblemAddresses[] = {
277 0x1E878B, 0x1E95A3, 0x1ED6F3, 0x1EF540
278};
279
280} // namespace yaze::cli
281
282#endif // YAZE_CLI_HANDLERS_TOOLS_DIAGNOSTIC_TYPES_H
283
Namespace for the command line interface.
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
const uint32_t kProblemAddresses[]
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 corruption status.
std::vector< uint32_t > corrupted_addresses