15 return absl::InvalidArgumentError(
"ROM is not loaded");
23 const int mode7_gfx_addr = 0x0C4000;
24 std::vector<uint8_t> mode7_gfx_raw(0x4000);
26 for (
int i = 0; i < 0x4000; i++) {
33 std::vector<uint8_t> mode7_gfx(0x4000);
35 for (
int sy = 0; sy < 16 * 1024; sy += 1024) {
36 for (
int sx = 0; sx < 16 * 8; sx += 8) {
37 for (
int y = 0; y < 8 * 128; y += 128) {
38 for (
int x = 0; x < 8; x++) {
39 mode7_gfx[x + sx + y + sy] = mode7_gfx_raw[pos];
61 const int lw_pal_addr = 0x055B27;
62 for (
int i = 0; i < 128; i++) {
69 const int dw_pal_addr = 0x055C27;
70 for (
int i = 0; i < 128; i++) {
96 return absl::OkStatus();
112 const int base_addr = 0x054727;
113 int p1 = base_addr + 0x0000;
114 int p2 = base_addr + 0x0400;
115 int p3 = base_addr + 0x0800;
116 int p4 = base_addr + 0x0C00;
117 int p5 = base_addr + 0x1000;
124 while (count < 64 * 64) {
204 return absl::OkStatus();
213 for (
int yy = 0; yy < 64; yy++) {
214 for (
int xx = 0; xx < 64; xx++) {
215 uint8_t tile_id = tile_source[xx + (yy * 64)];
218 int tile_x = (tile_id % 16) * 8;
219 int tile_y = (tile_id / 16) * 8;
222 for (
int py = 0; py < 8; py++) {
223 for (
int px = 0; px < 8; px++) {
224 int src_index = (tile_x + px) + ((tile_y + py) * 128);
225 int dest_index = (xx * 8 + px) + ((yy * 8 + py) * 512);
227 if (src_index < tiles8_data.size() && dest_index < map_data.size()) {
228 map_data[dest_index] = tiles8_data[src_index];
238 return absl::OkStatus();
243 const int base_addr = 0x054727;
244 int p1 = base_addr + 0x0000;
245 int p2 = base_addr + 0x0400;
246 int p3 = base_addr + 0x0800;
247 int p4 = base_addr + 0x0C00;
248 int p5 = base_addr + 0x1000;
255 while (count < 64 * 64) {
323 return absl::OkStatus();
328 std::ifstream file(file_path, std::ios::binary | std::ios::ate);
329 if (!file.is_open()) {
330 return absl::NotFoundError(
"Could not open custom map file: " + file_path);
333 std::streamsize size = file.tellg();
335 return absl::InvalidArgumentError(
336 "Custom map file must be exactly 4096 bytes (64×64 tiles)");
339 file.seekg(0, std::ios::beg);
342 file.read(
reinterpret_cast<char*
>(
lw_map_tiles_.data()), 4096);
345 return absl::InternalError(
"Failed to read custom map data");
353 return absl::OkStatus();
357 bool use_dark_world) {
358 std::ofstream file(file_path, std::ios::binary);
359 if (!file.is_open()) {
360 return absl::InternalError(
"Could not create custom map file: " +
365 file.write(
reinterpret_cast<const char*
>(tiles.data()), tiles.size());
368 return absl::InternalError(
"Failed to write custom map data");
371 return absl::OkStatus();
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
absl::Status WriteByte(int addr, uint8_t value)
absl::StatusOr< uint8_t > ReadByte(int offset) const
absl::StatusOr< uint16_t > ReadWord(int offset) const
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 using SNES palette format.
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 ASSIGN_OR_RETURN(type_variable_name, expression)
#define RETURN_IF_ERROR(expr)
SNES color in 15-bit RGB format (BGR555)