15 return absl::InvalidArgumentError(
"ROM is not loaded");
22 const int mode7_gfx_addr = 0x0C4000;
23 std::vector<uint8_t> mode7_gfx_raw(0x4000);
25 for (
int i = 0; i < 0x4000; i++) {
32 std::vector<uint8_t> mode7_gfx(0x4000);
34 for (
int sy = 0; sy < 16 * 1024; sy += 1024) {
35 for (
int sx = 0; sx < 16 * 8; sx += 8) {
36 for (
int y = 0; y < 8 * 128; y += 128) {
37 for (
int x = 0; x < 8; x++) {
38 mode7_gfx[x + sx + y + sy] = mode7_gfx_raw[pos];
60 const int lw_pal_addr = 0x055B27;
61 for (
int i = 0; i < 128; i++) {
68 const int dw_pal_addr = 0x055C27;
69 for (
int i = 0; i < 128; i++) {
95 return absl::OkStatus();
104 const int base_addr = 0x054727;
105 int p1 = base_addr + 0x0000;
106 int p2 = base_addr + 0x0400;
107 int p3 = base_addr + 0x0800;
108 int p4 = base_addr + 0x0C00;
109 int p5 = base_addr + 0x1000;
116 while (count < 64 * 64) {
196 return absl::OkStatus();
205 for (
int yy = 0; yy < 64; yy++) {
206 for (
int xx = 0; xx < 64; xx++) {
207 uint8_t tile_id = tile_source[xx + (yy * 64)];
210 int tile_x = (tile_id % 16) * 8;
211 int tile_y = (tile_id / 16) * 8;
214 for (
int py = 0; py < 8; py++) {
215 for (
int px = 0; px < 8; px++) {
216 int src_index = (tile_x + px) + ((tile_y + py) * 128);
217 int dest_index = (xx * 8 + px) + ((yy * 8 + py) * 512);
219 if (src_index < tiles8_data.size() && dest_index < map_data.size()) {
220 map_data[dest_index] = tiles8_data[src_index];
230 return absl::OkStatus();
235 const int base_addr = 0x054727;
236 int p1 = base_addr + 0x0000;
237 int p2 = base_addr + 0x0400;
238 int p3 = base_addr + 0x0800;
239 int p4 = base_addr + 0x0C00;
240 int p5 = base_addr + 0x1000;
247 while (count < 64 * 64) {
314 return absl::OkStatus();
319 std::ifstream file(file_path, std::ios::binary | std::ios::ate);
320 if (!file.is_open()) {
321 return absl::NotFoundError(
"Could not open custom map file: " + file_path);
324 std::streamsize size = file.tellg();
326 return absl::InvalidArgumentError(
327 "Custom map file must be exactly 4096 bytes (64×64 tiles)");
330 file.seekg(0, std::ios::beg);
333 file.read(
reinterpret_cast<char*
>(
lw_map_tiles_.data()), 4096);
336 return absl::InternalError(
"Failed to read custom map data");
344 return absl::OkStatus();
348 bool use_dark_world) {
349 std::ofstream file(file_path, std::ios::binary);
350 if (!file.is_open()) {
351 return absl::InternalError(
"Could not create custom map file: " + file_path);
355 file.write(
reinterpret_cast<const char*
>(tiles.data()), tiles.size());
358 return absl::InternalError(
"Failed to write custom map data");
361 return absl::OkStatus();
The Rom class is used to load, save, and modify Rom data.
absl::Status WriteByte(int addr, uint8_t value)
absl::StatusOr< uint16_t > ReadWord(int offset)
absl::StatusOr< uint8_t > ReadByte(int offset)
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
const std::vector< uint8_t > & vector() const
void UpdateSurfacePixels()
Update SDL surface with current pixel data from data_ vector Call this after modifying pixel data via...
BitmapMetadata & metadata()
void set_active(bool active)
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap.
std::vector< uint8_t > & mutable_data()
void AddColor(const SnesColor &color)
std::array< uint8_t, 64 *64 > dw_map_tiles_
absl::Status SaveCustomMap(const std::string &file_path, bool use_dark_world)
Save map data to external binary file.
gfx::SnesPalette lw_palette_
absl::Status LoadCustomMap(const std::string &file_path)
Load custom map from external binary file.
std::array< uint8_t, 64 *64 > lw_map_tiles_
absl::Status LoadMapData(Rom *rom)
Load map tile data from ROM Reads the interleaved tile format from 4 ROM sections.
absl::Status Save(Rom *rom)
Save changes back to ROM.
absl::Status RenderMapLayer(bool use_dark_world)
Render map tiles into bitmap.
gfx::Bitmap tiles8_bitmap_
gfx::SnesPalette dw_palette_
absl::Status Create(Rom *rom)
Initialize and load overworld map data from ROM.
#define RETURN_IF_ERROR(expression)
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Main namespace for the application.
SNES color in 15-bit RGB format (BGR555)