yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
rom_patch_utility.cc
Go to the documentation of this file.
1#include <filesystem>
2#include <fstream>
3#include <iomanip>
4#include <iostream>
5#include <vector>
6
7#include "app/rom.h"
10
11using namespace yaze::zelda3;
12using namespace yaze;
13
15 public:
16 static absl::Status CreateV3PatchedROM(const std::string& input_rom_path,
17 const std::string& output_rom_path) {
18 // Load the vanilla ROM
19 Rom rom;
20 RETURN_IF_ERROR(rom.LoadFromFile(input_rom_path));
21
22 // Apply ZSCustomOverworld v3 settings
24
25 // Save the patched ROM
26 return rom.SaveToFile(Rom::SaveSettings{.filename = output_rom_path});
27 }
28
29 private:
30 static absl::Status ApplyV3Patch(Rom& rom) {
31 // Set ASM version to v3
33
34 // Enable v3 features
41
42 // Apply v3 settings to first 10 maps for testing
43 for (int i = 0; i < 10; i++) {
44 // Set area sizes (mix of different sizes)
45 AreaSizeEnum area_size = static_cast<AreaSizeEnum>(i % 4);
46 rom.WriteByte(kOverworldScreenSize + i, static_cast<uint8_t>(area_size));
47
48 // Set main palettes
50
51 // Set area-specific background colors
52 uint16_t bg_color = 0x0000 + (i * 0x1000);
54 bg_color & 0xFF);
56 (bg_color >> 8) & 0xFF);
57
58 // Set subscreen overlays
59 uint16_t overlay = 0x0090 + i;
61 overlay & 0xFF);
63 (overlay >> 8) & 0xFF);
64
65 // Set animated GFX
67
68 // Set custom tile GFX groups (8 bytes per map)
69 for (int j = 0; j < 8; j++) {
71 0x20 + j + i);
72 }
73
74 // Set mosaic settings
76
77 // Set expanded message IDs
78 uint16_t message_id = 0x1000 + i;
79 rom.WriteByte(kOverworldMessagesExpanded + (i * 2), message_id & 0xFF);
80 rom.WriteByte(kOverworldMessagesExpanded + (i * 2) + 1,
81 (message_id >> 8) & 0xFF);
82 }
83
84 return absl::OkStatus();
85 }
86};
87
88int main(int argc, char* argv[]) {
89 if (argc != 3) {
90 std::cerr << "Usage: " << argv[0] << " <input_rom> <output_rom>"
91 << std::endl;
92 return 1;
93 }
94
95 std::string input_rom = argv[1];
96 std::string output_rom = argv[2];
97
98 auto status = ROMPatchUtility::CreateV3PatchedROM(input_rom, output_rom);
99 if (!status.ok()) {
100 std::cerr << "Failed to create patched ROM: " << status.message()
101 << std::endl;
102 return 1;
103 }
104
105 std::cout << "Successfully created v3 patched ROM: " << output_rom
106 << std::endl;
107 return 0;
108}
static absl::Status CreateV3PatchedROM(const std::string &input_rom_path, const std::string &output_rom_path)
static absl::Status ApplyV3Patch(Rom &rom)
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:74
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
Definition rom.cc:292
absl::Status WriteByte(int addr, uint8_t value)
Definition rom.cc:728
absl::Status SaveToFile(const SaveSettings &settings)
Definition rom.cc:539
#define RETURN_IF_ERROR(expression)
Definition macro.h:53
Zelda 3 specific classes and functions.
constexpr int OverworldCustomTileGFXGroupEnabled
constexpr int OverworldCustomAreaSpecificBGEnabled
constexpr int kOverworldScreenSize
Definition overworld.h:69
constexpr int OverworldCustomMosaicArray
constexpr int OverworldCustomAnimatedGFXEnabled
constexpr int OverworldCustomMainPaletteEnabled
constexpr int OverworldCustomMainPaletteArray
constexpr int OverworldCustomASMHasBeenApplied
Definition common.h:50
constexpr int kOverworldMessagesExpanded
constexpr int OverworldCustomAnimatedGFXArray
constexpr int OverworldCustomMosaicEnabled
constexpr int OverworldCustomTileGFXGroupArray
constexpr int OverworldCustomSubscreenOverlayEnabled
constexpr int OverworldCustomAreaSpecificBGPalette
constexpr int OverworldCustomSubscreenOverlayArray
Main namespace for the application.
Definition controller.cc:20
std::string filename
Definition rom.h:80