yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
mock_rom.cc
Go to the documentation of this file.
2
3#include <vector>
4
5#include "absl/flags/declare.h"
6#include "absl/flags/flag.h"
7#include "absl/strings/str_format.h"
8#include "app/core/project.h"
10
11ABSL_DECLARE_FLAG(bool, mock_rom);
12
13namespace yaze {
14namespace cli {
15
16absl::Status InitializeMockRom(Rom& rom) {
17 // Create a minimal but valid SNES ROM header
18 // Zelda3 is a 1MB ROM (0x100000 bytes) in LoROM mapping
19 constexpr size_t kMockRomSize = 0x100000; // 1MB
20 std::vector<uint8_t> mock_data(kMockRomSize, 0x00);
21
22 // SNES header is at 0x7FC0 for LoROM
23 constexpr size_t kHeaderOffset = 0x7FC0;
24
25 // Set ROM title (21 bytes at 0x7FC0)
26 const char* title = "YAZE MOCK ROM TEST "; // 21 chars including spaces
27 for (size_t i = 0; i < 21; ++i) {
28 mock_data[kHeaderOffset + i] = title[i];
29 }
30
31 // ROM makeup byte (0x7FD5): $20 = LoROM, no special chips
32 mock_data[kHeaderOffset + 0x15] = 0x20;
33
34 // ROM type (0x7FD6): $00 = ROM only
35 mock_data[kHeaderOffset + 0x16] = 0x00;
36
37 // ROM size (0x7FD7): $09 = 1MB (2^9 KB = 512 KB = 1MB with header)
38 mock_data[kHeaderOffset + 0x17] = 0x09;
39
40 // SRAM size (0x7FD8): $03 = 8KB (Zelda3 standard)
41 mock_data[kHeaderOffset + 0x18] = 0x03;
42
43 // Country code (0x7FD9): $01 = USA
44 mock_data[kHeaderOffset + 0x19] = 0x01;
45
46 // Developer ID (0x7FDA): $33 = Extended header (Zelda3)
47 mock_data[kHeaderOffset + 0x1A] = 0x33;
48
49 // Version number (0x7FDB): $00 = 1.0
50 mock_data[kHeaderOffset + 0x1B] = 0x00;
51
52 // Checksum complement (0x7FDC-0x7FDD): We'll leave as 0x0000 for mock
53 // Checksum (0x7FDE-0x7FDF): We'll leave as 0x0000 for mock
54
55 // Load the mock data into the ROM
56 auto load_status = rom.LoadFromData(mock_data);
57 if (!load_status.ok()) {
58 return absl::InternalError(
59 absl::StrFormat("Failed to initialize mock ROM: %s",
60 load_status.message()));
61 }
62
63 // Initialize embedded labels so queries work without actual ROM data
64 core::YazeProject project;
65 auto labels_status = project.InitializeEmbeddedLabels();
66 if (!labels_status.ok()) {
67 return absl::InternalError(
68 absl::StrFormat("Failed to initialize embedded labels: %s",
69 labels_status.message()));
70 }
71
72 // Attach labels to ROM's resource label manager
73 if (rom.resource_label()) {
74 rom.resource_label()->labels_ = project.resource_labels;
75 rom.resource_label()->labels_loaded_ = true;
76 }
77
78 return absl::OkStatus();
79}
80
82 return absl::GetFlag(FLAGS_mock_rom);
83}
84
85} // namespace cli
86} // namespace yaze
87
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
absl::Status LoadFromData(const std::vector< uint8_t > &data, bool z3_load=true)
Definition rom.cc:381
core::ResourceLabelManager * resource_label()
Definition rom.h:220
ABSL_DECLARE_FLAG(bool, mock_rom)
absl::Status InitializeMockRom(Rom &rom)
Initialize a mock ROM for testing without requiring an actual ROM file.
Definition mock_rom.cc:16
bool ShouldUseMockRom()
Check if mock ROM mode should be used based on flags.
Definition mock_rom.cc:81
Main namespace for the application.
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
Definition project.h:235
Modern project structure with comprehensive settings consolidation.
Definition project.h:78
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > resource_labels
Definition project.h:100
absl::Status InitializeEmbeddedLabels()
Definition project.cc:887