backend-infra-engineer: Release v0.3.0 snapshot

This commit is contained in:
scawful
2025-09-27 00:25:45 -04:00
parent 8ce29e1436
commit e32ac75b9c
346 changed files with 55946 additions and 11764 deletions

View File

@@ -1,67 +0,0 @@
#ifndef YAZE_BASE_DUNGEON_H_
#define YAZE_BASE_DUNGEON_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
typedef struct z3_object_door {
short id;
uint8_t x;
uint8_t y;
uint8_t size;
uint8_t type;
uint8_t layer;
} z3_object_door;
typedef struct z3_dungeon_destination {
uint8_t index;
uint8_t target;
uint8_t target_layer;
} z3_dungeon_destination;
typedef struct z3_staircase {
uint8_t id;
uint8_t room;
const char *label;
} z3_staircase;
typedef struct z3_chest {
uint8_t x;
uint8_t y;
uint8_t item;
bool picker;
bool big_chest;
} z3_chest;
typedef struct z3_chest_data {
uint8_t id;
bool size;
} z3_chest_data;
typedef enum z3_dungeon_background2 {
Off,
Parallax,
Dark,
OnTop,
Translucent,
Addition,
Normal,
Transparent,
DarkRoom
} z3_dungeon_background2;
typedef struct z3_dungeon_room {
z3_dungeon_background2 bg2;
z3_dungeon_destination pits;
z3_dungeon_destination stairs[4];
} z3_dungeon_room;
#ifdef __cplusplus
}
#endif
#endif // YAZE_BASE_DUNGEON_H_

View File

@@ -1,47 +0,0 @@
#ifndef YAZE_OVERWORLD_H
#define YAZE_OVERWORLD_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "sprite.h"
/**
* @brief Primitive of an overworld map.
*/
typedef struct z3_overworld_map {
uint8_t id; /**< ID of the overworld map. */
uint8_t parent_id;
uint8_t quadrant_id;
uint8_t world_id;
uint8_t game_state;
uint8_t area_graphics;
uint8_t area_palette;
uint8_t sprite_graphics[3];
uint8_t sprite_palette[3];
uint8_t area_music[4];
uint8_t static_graphics[16];
} z3_overworld_map;
/**
* @brief Primitive of the overworld.
*/
typedef struct z3_overworld {
void *impl; // yaze::Overworld*
uint8_t *tile32_data; /**< Pointer to the 32x32 tile data. */
uint8_t *tile16_data; /**< Pointer to the 16x16 tile data. */
z3_sprite **sprites; /**< Pointer to the sprites per map. */
z3_overworld_map **maps; /**< Pointer to the overworld maps. */
} z3_overworld;
#ifdef __cplusplus
}
#endif
#endif // YAZE_OVERWORLD_H

View File

@@ -1,32 +0,0 @@
#ifndef YAZE_BASE_SNES_COLOR_H_
#define YAZE_BASE_SNES_COLOR_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* @brief Primitive of 16-bit RGB SNES color.
*/
typedef struct snes_color {
uint16_t red; /**< Red component of the color. */
uint16_t blue; /**< Blue component of the color. */
uint16_t green; /**< Green component of the color. */
} snes_color;
/**
* @brief Primitive of a SNES color palette.
*/
typedef struct snes_palette {
unsigned int id; /**< ID of the palette. */
unsigned int size; /**< Size of the palette. */
snes_color* colors; /**< Pointer to the colors in the palette. */
} snes_palette;
#ifdef __cplusplus
}
#endif
#endif // YAZE_BASE_SNES_COLOR_H_

View File

@@ -1,40 +0,0 @@
#ifndef YAZE_INCL_SNES_TILE_H
#define YAZE_INCL_SNES_TILE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
typedef struct snes_tile8 {
uint32_t id;
uint32_t palette_id;
uint8_t data[64];
} snes_tile8;
typedef struct snes_tile_info {
uint16_t id;
uint8_t palette;
bool priority;
bool vertical_mirror;
bool horizontal_mirror;
} snes_tile_info;
typedef struct snes_tile16 {
snes_tile_info tiles[4];
} snes_tile16;
typedef struct snes_tile32 {
uint16_t t0;
uint16_t t1;
uint16_t t2;
uint16_t t3;
} snes_tile32;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,23 +0,0 @@
#ifndef YAZE_BASE_SPRITE_H_
#define YAZE_BASE_SPRITE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* @brief Primitive of a sprite.
*/
typedef struct z3_sprite {
const char* name; /**< Name of the sprite. */
uint8_t id; /**< ID of the sprite. */
uint8_t subtype; /**< Subtype of the sprite. */
} z3_sprite;
#ifdef __cplusplus
}
#endif
#endif // YAZE_BASE_SPRITE_H_

View File

@@ -1,157 +1,586 @@
#ifndef YAZE_H
#define YAZE_H
/**
* @file yaze.h
* @brief Yet Another Zelda3 Editor (YAZE) - Public C API
*
* This header provides the main C API for YAZE, a modern ROM editor for
* The Legend of Zelda: A Link to the Past. This API allows external
* applications to interact with YAZE's functionality.
*
* @version 0.3.0
* @author YAZE Team
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "dungeon.h"
#include "overworld.h"
#include "snes_color.h"
#include "sprite.h"
#include "zelda.h"
typedef struct z3_rom z3_rom;
/**
* @defgroup version Version Information
* @{
*/
typedef struct yaze_project yaze_project;
typedef struct yaze_command_registry yaze_command_registry;
typedef struct yaze_event_dispatcher yaze_event_dispatcher;
/** Major version number */
#define YAZE_VERSION_MAJOR 0
/** Minor version number */
#define YAZE_VERSION_MINOR 3
/** Patch version number */
#define YAZE_VERSION_PATCH 0
/** Combined version as a string */
#define YAZE_VERSION_STRING "0.3.0"
/** Combined version as a number (major * 10000 + minor * 100 + patch) */
#define YAZE_VERSION_NUMBER 300
/** @} */
typedef struct yaze_editor_context {
z3_rom* rom;
yaze_project* project;
yaze_command_registry* command_registry;
yaze_event_dispatcher* event_dispatcher;
zelda3_rom* rom;
const char* error_message;
} yaze_editor_context;
void yaze_check_version(const char* version);
int yaze_init(yaze_editor_context*);
void yaze_cleanup(yaze_editor_context*);
struct yaze_project {
const char* name;
const char* filepath;
const char* rom_filename;
const char* code_folder;
const char* labels_filename;
};
yaze_project yaze_load_project(const char* filename);
struct z3_rom {
const char* filename;
const uint8_t* data;
size_t size;
void* impl; // yaze::Rom*
};
z3_rom* yaze_load_rom(const char* filename);
void yaze_unload_rom(z3_rom* rom);
typedef struct yaze_bitmap {
int width;
int height;
uint8_t bpp;
uint8_t* data;
} yaze_bitmap;
yaze_bitmap yaze_load_bitmap(const char* filename);
snes_color yaze_get_color_from_paletteset(const z3_rom* rom, int palette_set,
int palette, int color);
z3_overworld* yaze_load_overworld(const z3_rom* rom);
z3_dungeon_room* yaze_load_all_rooms(const z3_rom* rom);
struct yaze_command_registry {
void (*register_command)(const char* name, void (*command)(void));
};
struct yaze_event_dispatcher {
void (*register_event_hook)(void (*event_hook)(void));
};
typedef void (*yaze_initialize_func)(yaze_editor_context* context);
typedef void (*yaze_cleanup_func)(void);
typedef void (*yaze_extend_ui_func)(yaze_editor_context* context);
typedef void (*yaze_manipulate_rom_func)(z3_rom* rom);
typedef void (*yaze_command_func)(void);
typedef void (*yaze_event_hook_func)(void);
typedef enum {
YAZE_EVENT_ROM_LOADED,
YAZE_EVENT_ROM_SAVED,
YAZE_EVENT_SPRITE_MODIFIED,
YAZE_EVENT_PALETTE_CHANGED,
} yaze_event_type;
/**
* @defgroup core Core API
* @{
*/
/**
* @brief Extension interface for Yaze.
* @brief Status codes returned by YAZE functions
*
* All YAZE functions that can fail return a status code to indicate
* success or the type of error that occurred.
*/
typedef enum yaze_status {
YAZE_OK = 0, /**< Operation completed successfully */
YAZE_ERROR_UNKNOWN = -1, /**< Unknown error occurred */
YAZE_ERROR_INVALID_ARG = 1, /**< Invalid argument provided */
YAZE_ERROR_FILE_NOT_FOUND = 2, /**< File not found */
YAZE_ERROR_MEMORY = 3, /**< Memory allocation failed */
YAZE_ERROR_IO = 4, /**< I/O operation failed */
YAZE_ERROR_CORRUPTION = 5, /**< Data corruption detected */
YAZE_ERROR_NOT_INITIALIZED = 6, /**< Component not initialized */
} yaze_status;
/**
* @brief Convert a status code to a human-readable string
*
* @param status The status code to convert
* @return A null-terminated string describing the status
*/
const char* yaze_status_to_string(yaze_status status);
/**
* @brief Initialize the YAZE library
*
* This function must be called before using any other YAZE functions.
* It initializes internal subsystems and prepares the library for use.
*
* @return YAZE_OK on success, error code on failure
*/
yaze_status yaze_library_init(void);
/**
* @brief Shutdown the YAZE library
*
* This function cleans up resources allocated by yaze_library_init().
* After calling this function, no other YAZE functions should be called
* until yaze_library_init() is called again.
*/
void yaze_library_shutdown(void);
/**
* @brief Main entry point for the YAZE application
*
* @param argc Number of command line arguments
* @param argv Array of command line argument strings
* @return Exit code (0 for success, non-zero for error)
*/
int yaze_app_main(int argc, char** argv);
/**
* @brief Check if the current YAZE version is compatible with the expected version
*
* @param expected_version Expected version string (e.g., "0.3.0")
* @return true if compatible, false otherwise
*/
bool yaze_check_version_compatibility(const char* expected_version);
/**
* @brief Get the current YAZE version string
*
* @return A null-terminated string containing the version
*/
const char* yaze_get_version_string(void);
/**
* @brief Get the current YAZE version number
*
* @return Version number (major * 10000 + minor * 100 + patch)
*/
int yaze_get_version_number(void);
/**
* @brief Initialize a YAZE editor context
*
* Creates and initializes an editor context for working with ROM files.
* The context manages the ROM data and provides access to editing functions.
*
* @param context Pointer to context structure to initialize
* @param rom_filename Path to the ROM file to load (can be NULL to create empty context)
* @return YAZE_OK on success, error code on failure
*
* @note The caller is responsible for calling yaze_shutdown() to clean up the context
*/
yaze_status yaze_init(yaze_editor_context* context, const char* rom_filename);
/**
* @brief Shutdown and clean up a YAZE editor context
*
* Releases all resources associated with the context, including ROM data.
* After calling this function, the context should not be used.
*
* @param context Pointer to context to shutdown
* @return YAZE_OK on success, error code on failure
*/
yaze_status yaze_shutdown(yaze_editor_context* context);
/** @} */
/**
* @defgroup graphics Graphics and Bitmap Functions
* @{
*/
/**
* @brief Bitmap data structure
*
* Represents a bitmap image with pixel data and metadata.
*/
typedef struct yaze_bitmap {
int width; /**< Width in pixels */
int height; /**< Height in pixels */
uint8_t bpp; /**< Bits per pixel (1, 2, 4, 8) */
uint8_t* data; /**< Pixel data (caller owns memory) */
} yaze_bitmap;
/**
* @brief Load a bitmap from file
*
* Loads a bitmap image from the specified file. Supports common
* image formats and SNES-specific formats.
*
* @param filename Path to the image file
* @return Bitmap structure with loaded data, or empty bitmap on error
*
* @note The caller is responsible for freeing the data pointer
*/
yaze_bitmap yaze_load_bitmap(const char* filename);
/**
* @brief Free bitmap data
*
* Releases memory allocated for bitmap pixel data.
*
* @param bitmap Pointer to bitmap structure to free
*/
void yaze_free_bitmap(yaze_bitmap* bitmap);
/**
* @brief Create an empty bitmap
*
* Allocates a new bitmap with the specified dimensions.
*
* @param width Width in pixels
* @param height Height in pixels
* @param bpp Bits per pixel
* @return Initialized bitmap structure, or empty bitmap on error
*/
yaze_bitmap yaze_create_bitmap(int width, int height, uint8_t bpp);
/**
* @brief SNES color in 15-bit RGB format (BGR555)
*
* Represents a color in the SNES native format. Colors are stored
* as 8-bit values but only the lower 5 bits are used by the SNES.
*/
typedef struct snes_color {
uint16_t red; /**< Red component (0-255, but SNES uses 0-31) */
uint16_t green; /**< Green component (0-255, but SNES uses 0-31) */
uint16_t blue; /**< Blue component (0-255, but SNES uses 0-31) */
} snes_color;
/**
* @brief Convert RGB888 color to SNES color
*
* @param r Red component (0-255)
* @param g Green component (0-255)
* @param b Blue component (0-255)
* @return SNES color structure
*/
snes_color yaze_rgb_to_snes_color(uint8_t r, uint8_t g, uint8_t b);
/**
* @brief Convert SNES color to RGB888
*
* @param color SNES color to convert
* @param r Pointer to store red component (0-255)
* @param g Pointer to store green component (0-255)
* @param b Pointer to store blue component (0-255)
*/
void yaze_snes_color_to_rgb(snes_color color, uint8_t* r, uint8_t* g, uint8_t* b);
/**
* @brief SNES color palette
*
* Represents a color palette used by the SNES. Each palette contains
* up to 256 colors, though most modes use fewer colors per palette.
*/
typedef struct snes_palette {
uint16_t id; /**< Palette ID (0-255) */
uint16_t size; /**< Number of colors in palette (1-256) */
snes_color* colors; /**< Array of colors (caller owns memory) */
} snes_palette;
/**
* @brief Create an empty palette
*
* @param id Palette ID
* @param size Number of colors to allocate
* @return Initialized palette structure, or NULL on error
*/
snes_palette* yaze_create_palette(uint16_t id, uint16_t size);
/**
* @brief Free palette memory
*
* @param palette Pointer to palette to free
*/
void yaze_free_palette(snes_palette* palette);
/**
* @brief Load palette from ROM
*
* @param rom ROM to load palette from
* @param palette_id ID of palette to load
* @return Loaded palette, or NULL on error
*/
snes_palette* yaze_load_palette_from_rom(const zelda3_rom* rom, uint16_t palette_id);
/**
* @brief 8x8 SNES tile data
*
* Represents an 8x8 pixel tile with indexed color data.
* Each pixel value is an index into a palette.
*/
typedef struct snes_tile8 {
uint32_t id; /**< Tile ID for reference */
uint32_t palette_id; /**< Associated palette ID */
uint8_t data[64]; /**< 64 pixels in row-major order (y*8+x) */
} snes_tile8;
/**
* @brief Load tile data from ROM
*
* @param rom ROM to load from
* @param tile_id ID of tile to load
* @param bpp Bits per pixel (1, 2, 4, 8)
* @return Loaded tile data, or empty tile on error
*/
snes_tile8 yaze_load_tile_from_rom(const zelda3_rom* rom, uint32_t tile_id, uint8_t bpp);
/**
* @brief Convert tile data between different bit depths
*
* @param tile Source tile data
* @param from_bpp Source bits per pixel
* @param to_bpp Target bits per pixel
* @return Converted tile data
*/
snes_tile8 yaze_convert_tile_bpp(const snes_tile8* tile, uint8_t from_bpp, uint8_t to_bpp);
typedef struct snes_tile_info {
uint16_t id;
uint8_t palette;
bool priority;
bool vertical_mirror;
bool horizontal_mirror;
} snes_tile_info;
typedef struct snes_tile16 {
snes_tile_info tiles[4];
} snes_tile16;
typedef struct snes_tile32 {
uint16_t t0;
uint16_t t1;
uint16_t t2;
uint16_t t3;
} snes_tile32;
/** @} */
/**
* @defgroup rom ROM Manipulation
* @{
*/
/**
* @brief Load a ROM file
*
* Loads a Zelda 3 ROM file and validates its format.
*
* @param filename Path to ROM file (.sfc, .smc, etc.)
* @return Pointer to ROM structure, or NULL on error
*
* @note Caller must call yaze_unload_rom() to free memory
*/
zelda3_rom* yaze_load_rom_file(const char* filename);
/**
* @brief Validate ROM integrity
*
* Checks if the ROM data is valid and uncorrupted.
*
* @param rom ROM to validate
* @return YAZE_OK if valid, error code if corrupted
*/
yaze_status yaze_validate_rom(const zelda3_rom* rom);
/**
* @brief Get ROM information
*
* @param rom ROM to query
* @param version Pointer to store detected ROM version
* @param size Pointer to store ROM size in bytes
* @return YAZE_OK on success, error code on failure
*/
yaze_status yaze_get_rom_info(const zelda3_rom* rom, zelda3_version* version, uint64_t* size);
/**
* @brief Get a color from a palette set
*
* @details Yaze extensions can be written in C or Python.
* Retrieves a specific color from a palette set in the ROM.
*
* @param rom The ROM to get the color from
* @param palette_set The palette set index (0-255)
* @param palette The palette index within the set (0-15)
* @param color The color index within the palette (0-15)
* @return The color from the palette set
*/
snes_color yaze_get_color_from_paletteset(const zelda3_rom* rom,
int palette_set, int palette,
int color);
/** @} */
/**
* @defgroup overworld Overworld Functions
* @{
*/
/**
* @brief Load the overworld from ROM
*
* Loads and parses the overworld data from the ROM, including all maps,
* sprites, and related data structures.
*
* @param rom The ROM to load the overworld from
* @return Pointer to overworld structure, or NULL on error
*
* @note Caller must free the returned pointer when done
*/
zelda3_overworld* yaze_load_overworld(const zelda3_rom* rom);
/**
* @brief Free overworld data
*
* @param overworld Pointer to overworld to free
*/
void yaze_free_overworld(zelda3_overworld* overworld);
/**
* @brief Get overworld map by index
*
* @param overworld Overworld data
* @param map_index Map index (0-159 for most ROMs)
* @return Pointer to map data, or NULL if invalid index
*/
const zelda3_overworld_map* yaze_get_overworld_map(const zelda3_overworld* overworld, int map_index);
/**
* @brief Get total number of overworld maps
*
* @param overworld Overworld data
* @return Number of maps available
*/
int yaze_get_overworld_map_count(const zelda3_overworld* overworld);
/** @} */
/**
* @defgroup dungeon Dungeon Functions
* @{
*/
/**
* @brief Load all dungeon rooms from ROM
*
* Loads and parses all dungeon room data from the ROM.
*
* @param rom The ROM to load rooms from
* @param room_count Pointer to store the number of rooms loaded
* @return Array of room structures, or NULL on error
*
* @note Caller must free the returned array when done
*/
zelda3_dungeon_room* yaze_load_all_rooms(const zelda3_rom* rom, int* room_count);
/**
* @brief Load a specific dungeon room
*
* @param rom ROM to load from
* @param room_id Room ID to load (0-295 for most ROMs)
* @return Pointer to room data, or NULL on error
*/
const zelda3_dungeon_room* yaze_load_room(const zelda3_rom* rom, int room_id);
/**
* @brief Free dungeon room data
*
* @param rooms Array of rooms to free
* @param room_count Number of rooms in array
*/
void yaze_free_rooms(zelda3_dungeon_room* rooms, int room_count);
/** @} */
/**
* @defgroup messages Message System
* @{
*/
/**
* @brief Load all text messages from ROM
*
* Loads and parses all in-game text messages from the ROM.
*
* @param rom The ROM to load messages from
* @param messages Pointer to store array of messages
* @param message_count Pointer to store number of messages loaded
* @return YAZE_OK on success, error code on failure
*
* @note Caller must free the messages array when done
*/
yaze_status yaze_load_messages(const zelda3_rom* rom, zelda3_message** messages, int* message_count);
/**
* @brief Get a specific message by ID
*
* @param rom ROM to load from
* @param message_id Message ID to retrieve
* @return Pointer to message data, or NULL if not found
*/
const zelda3_message* yaze_get_message(const zelda3_rom* rom, int message_id);
/**
* @brief Free message data
*
* @param messages Array of messages to free
* @param message_count Number of messages in array
*/
void yaze_free_messages(zelda3_message* messages, int message_count);
/** @} */
/**
* @brief Function pointer to initialize the extension.
*
* @param context The editor context.
*/
typedef void (*yaze_initialize_func)(yaze_editor_context* context);
typedef void (*yaze_cleanup_func)(void);
/**
* @defgroup extensions Extension System
* @{
*/
/**
* @brief Extension interface for YAZE
*
* Defines the interface for YAZE extensions. Extensions can add new
* functionality to YAZE and can be written in C or other languages.
*/
typedef struct yaze_extension {
const char* name;
const char* version;
const char* name; /**< Extension name (must not be NULL) */
const char* version; /**< Extension version string */
const char* description; /**< Brief description of functionality */
const char* author; /**< Extension author */
int api_version; /**< Required YAZE API version */
/**
* @brief Function to initialize the extension.
* @brief Initialize the extension
*
* @details This function is called when the extension is loaded. It can be
* used to set up any resources or state needed by the extension.
*/
yaze_initialize_func initialize;
/**
* @brief Function to clean up the extension.
* Called when the extension is loaded. Use this to set up
* any resources or state needed by the extension.
*
* @details This function is called when the extension is unloaded. It can be
* used to clean up any resources or state used by the extension.
* @param context Editor context provided by YAZE
* @return YAZE_OK on success, error code on failure
*/
yaze_cleanup_func cleanup;
yaze_status (*initialize)(yaze_editor_context* context);
/**
* @brief Function to manipulate the ROM.
* @brief Clean up the extension
*
* @param rom The ROM to manipulate.
* Called when the extension is unloaded. Use this to clean up
* any resources or state used by the extension.
*/
void (*cleanup)(void);
/**
* @brief Get extension capabilities
*
*/
yaze_manipulate_rom_func manipulate_rom;
/**
* @brief Function to extend the UI.
* Returns a bitmask indicating what features this extension provides.
*
* @param context The editor context.
*
* @details This function is called when the extension is loaded. It can be
* used to add custom UI elements to the editor. The context parameter
* provides access to the project, command registry, event dispatcher, and
* ImGui context.
* @return Capability flags (see YAZE_EXT_CAP_* constants)
*/
yaze_extend_ui_func extend_ui;
/**
* @brief Register commands in the yaze_command_registry.
*/
yaze_command_func register_commands;
/**
* @brief Register custom tools in the yaze_command_registry.
*/
yaze_command_func register_custom_tools;
/**
* @brief Register event hooks in the yaze_event_dispatcher.
*/
void (*register_event_hooks)(yaze_event_type event,
yaze_event_hook_func hook);
uint32_t (*get_capabilities)(void);
} yaze_extension;
/** Extension capability flags */
#define YAZE_EXT_CAP_ROM_EDITING (1 << 0) /**< Can edit ROM data */
#define YAZE_EXT_CAP_GRAPHICS (1 << 1) /**< Provides graphics functions */
#define YAZE_EXT_CAP_AUDIO (1 << 2) /**< Provides audio functions */
#define YAZE_EXT_CAP_SCRIPTING (1 << 3) /**< Provides scripting support */
#define YAZE_EXT_CAP_IMPORT_EXPORT (1 << 4) /**< Can import/export data */
/**
* @brief Register an extension with YAZE
*
* @param extension Extension to register
* @return YAZE_OK on success, error code on failure
*/
yaze_status yaze_register_extension(const yaze_extension* extension);
/**
* @brief Unregister an extension
*
* @param name Name of extension to unregister
* @return YAZE_OK on success, error code on failure
*/
yaze_status yaze_unregister_extension(const char* name);
/** @} */
#ifdef __cplusplus
}
#endif

499
incl/zelda.h Normal file
View File

@@ -0,0 +1,499 @@
#ifndef ZELDA_H
#define ZELDA_H
/**
* @file zelda.h
* @brief The Legend of Zelda: A Link to the Past - Data Structures and Constants
*
* This header defines data structures and constants specific to
* The Legend of Zelda: A Link to the Past ROM format and game data.
*
* @version 0.3.0
* @author YAZE Team
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
/**
* @defgroup rom_types ROM Types and Versions
* @{
*/
/**
* @brief Different versions of the game supported by YAZE
*
* YAZE supports multiple regional versions and ROM hacks of
* The Legend of Zelda: A Link to the Past.
*/
typedef enum zelda3_version {
ZELDA3_VERSION_UNKNOWN = 0, /**< Unknown or unsupported version */
ZELDA3_VERSION_US = 1, /**< US/North American version */
ZELDA3_VERSION_JP = 2, /**< Japanese version */
ZELDA3_VERSION_EU = 3, /**< European version */
ZELDA3_VERSION_PROTO = 4, /**< Prototype/development version */
ZELDA3_VERSION_RANDOMIZER = 5, /**< Randomizer ROM (experimental) */
// Legacy aliases for backward compatibility
US = ZELDA3_VERSION_US, /**< @deprecated Use ZELDA3_VERSION_US */
JP = ZELDA3_VERSION_JP, /**< @deprecated Use ZELDA3_VERSION_JP */
SD = ZELDA3_VERSION_PROTO, /**< @deprecated Use ZELDA3_VERSION_PROTO */
RANDO = ZELDA3_VERSION_RANDOMIZER, /**< @deprecated Use ZELDA3_VERSION_RANDOMIZER */
} zelda3_version;
/**
* @brief Detect ROM version from header data
*
* @param rom_data Pointer to ROM data
* @param size Size of ROM data in bytes
* @return Detected version, or ZELDA3_VERSION_UNKNOWN if not recognized
*/
zelda3_version zelda3_detect_version(const uint8_t* rom_data, size_t size);
/**
* @brief Get version name as string
*
* @param version Version enum value
* @return Human-readable version name
*/
const char* zelda3_version_to_string(zelda3_version version);
/**
* @brief ROM data pointers for different game versions
*
* Contains memory addresses where specific data structures are located
* within the ROM. These addresses vary between different regional versions.
*/
typedef struct zelda3_version_pointers {
// New Google C++ style names
uint32_t gfx_animated_pointer; /**< Animated graphics pointer */
uint32_t overworld_gfx_groups1; /**< Overworld graphics group 1 */
uint32_t overworld_gfx_groups2; /**< Overworld graphics group 2 */
uint32_t compressed_map32_pointers_high; /**< Map32 high pointers */
uint32_t compressed_map32_pointers_low; /**< Map32 low pointers */
uint32_t overworld_map_palette_group; /**< Map palette groups */
uint32_t overlay_pointers; /**< Overlay data pointers */
uint32_t overlay_pointers_bank; /**< Overlay bank number */
uint32_t overworld_tiles_type; /**< Tile type definitions */
uint32_t overworld_gfx_ptr1; /**< Graphics pointer 1 */
uint32_t overworld_gfx_ptr2; /**< Graphics pointer 2 */
uint32_t overworld_gfx_ptr3; /**< Graphics pointer 3 */
uint32_t map32_tile_tl; /**< 32x32 tile top-left */
uint32_t map32_tile_tr; /**< 32x32 tile top-right */
uint32_t map32_tile_bl; /**< 32x32 tile bottom-left */
uint32_t map32_tile_br; /**< 32x32 tile bottom-right */
uint32_t sprite_blockset_pointer; /**< Sprite graphics pointer */
uint32_t dungeon_palettes_groups; /**< Dungeon palette groups */
// Legacy aliases for backward compatibility (deprecated)
uint32_t kGfxAnimatedPointer; /**< @deprecated Use gfx_animated_pointer */
uint32_t kOverworldGfxGroups1; /**< @deprecated Use overworld_gfx_groups1 */
uint32_t kOverworldGfxGroups2; /**< @deprecated Use overworld_gfx_groups2 */
uint32_t kCompressedAllMap32PointersHigh; /**< @deprecated Use compressed_map32_pointers_high */
uint32_t kCompressedAllMap32PointersLow; /**< @deprecated Use compressed_map32_pointers_low */
uint32_t kOverworldMapPaletteGroup; /**< @deprecated Use overworld_map_palette_group */
uint32_t kOverlayPointers; /**< @deprecated Use overlay_pointers */
uint32_t kOverlayPointersBank; /**< @deprecated Use overlay_pointers_bank */
uint32_t kOverworldTilesType; /**< @deprecated Use overworld_tiles_type */
uint32_t kOverworldGfxPtr1; /**< @deprecated Use overworld_gfx_ptr1 */
uint32_t kOverworldGfxPtr2; /**< @deprecated Use overworld_gfx_ptr2 */
uint32_t kOverworldGfxPtr3; /**< @deprecated Use overworld_gfx_ptr3 */
uint32_t kMap32TileTL; /**< @deprecated Use map32_tile_tl */
uint32_t kMap32TileTR; /**< @deprecated Use map32_tile_tr */
uint32_t kMap32TileBL; /**< @deprecated Use map32_tile_bl */
uint32_t kMap32TileBR; /**< @deprecated Use map32_tile_br */
uint32_t kSpriteBlocksetPointer; /**< @deprecated Use sprite_blockset_pointer */
uint32_t kDungeonPalettesGroups; /**< @deprecated Use dungeon_palettes_groups */
} zelda3_version_pointers;
/**
* @brief Get version-specific pointers
*
* @param version ROM version
* @return Pointer to version-specific address structure
*/
const zelda3_version_pointers* zelda3_get_version_pointers(zelda3_version version);
const static zelda3_version_pointers zelda3_us_pointers = {
// New style names
0x10275, // gfx_animated_pointer
0x5D97, // overworld_gfx_groups1
0x6073, // overworld_gfx_groups2
0x1794D, // compressed_map32_pointers_high
0x17B2D, // compressed_map32_pointers_low
0x75504, // overworld_map_palette_group
0x77664, // overlay_pointers
0x0E, // overlay_pointers_bank
0x71459, // overworld_tiles_type
0x4F80, // overworld_gfx_ptr1
0x505F, // overworld_gfx_ptr2
0x513E, // overworld_gfx_ptr3
0x18000, // map32_tile_tl
0x1B400, // map32_tile_tr
0x20000, // map32_tile_bl
0x23400, // map32_tile_br
0x5B57, // sprite_blockset_pointer
0x75460, // dungeon_palettes_groups
// Legacy k-prefixed names (same values for backward compatibility)
0x10275, // kGfxAnimatedPointer
0x5D97, // kOverworldGfxGroups1
0x6073, // kOverworldGfxGroups2
0x1794D, // kCompressedAllMap32PointersHigh
0x17B2D, // kCompressedAllMap32PointersLow
0x75504, // kOverworldMapPaletteGroup
0x77664, // kOverlayPointers
0x0E, // kOverlayPointersBank
0x71459, // kOverworldTilesType
0x4F80, // kOverworldGfxPtr1
0x505F, // kOverworldGfxPtr2
0x513E, // kOverworldGfxPtr3
0x18000, // kMap32TileTL
0x1B400, // kMap32TileTR
0x20000, // kMap32TileBL
0x23400, // kMap32TileBR
0x5B57, // kSpriteBlocksetPointer
0x75460, // kDungeonPalettesGroups
};
const static zelda3_version_pointers zelda3_jp_pointers = {
// New style names
0x10624, // gfx_animated_pointer
0x5DD7, // overworld_gfx_groups1
0x60B3, // overworld_gfx_groups2
0x176B1, // compressed_map32_pointers_high
0x17891, // compressed_map32_pointers_low
0x67E74, // overworld_map_palette_group
0x3FAF4, // overlay_pointers
0x07, // overlay_pointers_bank
0x7FD94, // overworld_tiles_type
0x4FC0, // overworld_gfx_ptr1
0x509F, // overworld_gfx_ptr2
0x517E, // overworld_gfx_ptr3
0x18000, // map32_tile_tl
0x1B3C0, // map32_tile_tr
0x20000, // map32_tile_bl
0x233C0, // map32_tile_br
0x5B97, // sprite_blockset_pointer
0x67DD0, // dungeon_palettes_groups
// Legacy k-prefixed names (same values for backward compatibility)
0x10624, // kGfxAnimatedPointer
0x5DD7, // kOverworldGfxGroups1
0x60B3, // kOverworldGfxGroups2
0x176B1, // kCompressedAllMap32PointersHigh
0x17891, // kCompressedAllMap32PointersLow
0x67E74, // kOverworldMapPaletteGroup
0x3FAF4, // kOverlayPointers
0x07, // kOverlayPointersBank
0x7FD94, // kOverworldTilesType
0x4FC0, // kOverworldGfxPtr1
0x509F, // kOverworldGfxPtr2
0x517E, // kOverworldGfxPtr3
0x18000, // kMap32TileTL
0x1B3C0, // kMap32TileTR
0x20000, // kMap32TileBL
0x233C0, // kMap32TileBR
0x5B97, // kSpriteBlocksetPointer
0x67DD0, // kDungeonPalettesGroups
};
/**
* @brief ROM data structure
*
* Represents a loaded Zelda 3 ROM with its data and metadata.
*/
typedef struct zelda3_rom {
const char* filename; /**< Original filename (can be NULL) */
uint8_t* data; /**< ROM data (read-only for external users) */
uint64_t size; /**< Size of ROM data in bytes */
zelda3_version version; /**< Detected ROM version */
bool is_modified; /**< True if ROM has been modified */
void* impl; /**< Internal implementation pointer */
} zelda3_rom;
/** @} */
/**
* @defgroup rom_functions ROM File Operations
* @{
*/
/**
* @brief Load a ROM file
*
* @param filename Path to ROM file
* @return Loaded ROM structure, or NULL on error
*/
zelda3_rom* yaze_load_rom(const char* filename);
/**
* @brief Unload and free ROM data
*
* @param rom ROM to unload
*/
void yaze_unload_rom(zelda3_rom* rom);
/**
* @brief Save ROM to file
*
* @param rom ROM to save
* @param filename Output filename
* @return YAZE_OK on success, error code on failure
*/
int yaze_save_rom(zelda3_rom* rom, const char* filename);
/**
* @brief Create a copy of ROM data
*
* @param rom Source ROM
* @return Copy of ROM, or NULL on error
*/
zelda3_rom* yaze_copy_rom(const zelda3_rom* rom);
/** @} */
/**
* @defgroup messages Message Data Structures
* @{
*/
/**
* @brief In-game text message data
*
* Represents a text message from the game, including both raw
* ROM data and parsed/decoded text content.
*/
typedef struct zelda3_message {
uint16_t id; /**< Message ID (0-65535) */
uint32_t rom_address; /**< Address in ROM where message data starts */
uint16_t length; /**< Length of message data in bytes */
uint8_t* raw_data; /**< Raw message data from ROM */
char* parsed_text; /**< Decoded text content (UTF-8) */
bool is_compressed; /**< True if message uses compression */
uint8_t encoding_type; /**< Text encoding type used */
} zelda3_message;
/** @} */
/**
* @defgroup overworld Overworld Data Structures
* @{
*/
/**
* @brief Overworld map data
*
* Represents a single screen/area in the overworld, including
* graphics, palette, music, and sprite information.
*/
typedef struct zelda3_overworld_map {
uint16_t id; /**< Map ID (0-159 for most ROMs) */
uint8_t parent_id; /**< Parent map ID for sub-areas */
uint8_t quadrant_id; /**< Quadrant within parent (0-3) */
uint8_t world_id; /**< World number (Light/Dark) */
uint8_t game_state; /**< Game state requirements */
/* Graphics and Visual Properties */
uint8_t area_graphics; /**< Area graphics set ID */
uint8_t area_palette; /**< Area palette set ID */
uint8_t main_palette; /**< Main palette ID */
uint8_t animated_gfx; /**< Animated graphics ID */
/* Sprite Configuration */
uint8_t sprite_graphics[3]; /**< Sprite graphics sets */
uint8_t sprite_palette[3]; /**< Sprite palette sets */
/* Audio Configuration */
uint8_t area_music[4]; /**< Music tracks for different states */
/* Extended Graphics (ZSCustomOverworld) */
uint8_t static_graphics[16]; /**< Static graphics assignments */
uint8_t custom_tileset[8]; /**< Custom tileset assignments */
/* Screen Properties */
uint16_t area_specific_bg_color; /**< Background color override */
uint16_t subscreen_overlay; /**< Subscreen overlay settings */
/* Flags and Metadata */
bool is_large_map; /**< True for 32x32 maps */
bool has_special_gfx; /**< True if uses special graphics */
} zelda3_overworld_map;
/**
* @brief Complete overworld data
*
* Contains all overworld maps and related data for the entire game world.
*/
typedef struct zelda3_overworld {
void* impl; /**< Internal implementation pointer */
zelda3_overworld_map** maps; /**< Array of overworld maps */
int map_count; /**< Number of maps in array */
zelda3_version rom_version; /**< ROM version this data came from */
bool has_zsco_features; /**< True if ZSCustomOverworld features detected */
} zelda3_overworld;
/** @} */
/**
* @defgroup dungeon Dungeon Data Structures
* @{
*/
/**
* @brief Dungeon sprite definition
*
* Represents a sprite that can appear in dungeon rooms.
*/
typedef struct dungeon_sprite {
const char* name; /**< Sprite name (for debugging/display) */
uint8_t id; /**< Sprite type ID */
uint8_t subtype; /**< Sprite subtype/variant */
uint8_t x; /**< X position in room */
uint8_t y; /**< Y position in room */
uint8_t layer; /**< Layer (0=background, 1=foreground) */
uint16_t properties; /**< Additional sprite properties */
} dungeon_sprite;
/**
* @brief Background layer 2 effects
*
* Defines the different visual effects that can be applied to
* background layer 2 in dungeon rooms.
*/
typedef enum zelda3_bg2_effect {
ZELDA3_BG2_OFF = 0, /**< Background layer 2 disabled */
ZELDA3_BG2_PARALLAX = 1, /**< Parallax scrolling effect */
ZELDA3_BG2_DARK = 2, /**< Dark overlay effect */
ZELDA3_BG2_ON_TOP = 3, /**< Layer appears on top */
ZELDA3_BG2_TRANSLUCENT = 4, /**< Semi-transparent overlay */
ZELDA3_BG2_ADDITION = 5, /**< Additive blending */
ZELDA3_BG2_NORMAL = 6, /**< Normal blending */
ZELDA3_BG2_TRANSPARENT = 7, /**< Fully transparent */
ZELDA3_BG2_DARK_ROOM = 8 /**< Dark room effect */
} zelda3_bg2_effect;
// Legacy aliases for backward compatibility
typedef zelda3_bg2_effect background2;
#define Off ZELDA3_BG2_OFF
#define Parallax ZELDA3_BG2_PARALLAX
#define Dark ZELDA3_BG2_DARK
#define OnTop ZELDA3_BG2_ON_TOP
#define Translucent ZELDA3_BG2_TRANSLUCENT
#define Addition ZELDA3_BG2_ADDITION
#define Normal ZELDA3_BG2_NORMAL
#define Transparent ZELDA3_BG2_TRANSPARENT
#define DarkRoom ZELDA3_BG2_DARK_ROOM
/**
* @brief Dungeon door object
*
* Represents a door or passage between rooms.
*/
typedef struct object_door {
uint16_t id; /**< Door ID for reference */
uint8_t x; /**< X position in room (0-63) */
uint8_t y; /**< Y position in room (0-63) */
uint8_t size; /**< Door size (width/height) */
uint8_t type; /**< Door type (normal, locked, etc.) */
uint8_t layer; /**< Layer (0=background, 1=foreground) */
uint8_t key_type; /**< Required key type (0=none) */
bool is_locked; /**< True if door requires key */
} object_door;
/**
* @brief Staircase connection
*
* Represents stairs or holes that connect different rooms or levels.
*/
typedef struct staircase {
uint8_t id; /**< Staircase ID */
uint8_t room; /**< Target room ID (for backward compatibility) */
const char* label; /**< Description (for debugging) */
} staircase;
/**
* @brief Treasure chest
*
* Represents a chest containing an item.
*/
typedef struct chest {
uint8_t x; /**< X position in room */
uint8_t y; /**< Y position in room */
uint8_t item; /**< Item ID (for backward compatibility) */
bool picker; /**< Legacy field */
bool big_chest; /**< True for large chests */
} chest;
/**
* @brief Legacy chest data structure
*
* @deprecated Use chest structure instead
*/
typedef struct chest_data {
uint8_t id; /**< Chest ID */
bool size; /**< True for big chest */
} chest_data;
/**
* @brief Room transition destination
*
* Defines where the player goes when using stairs, holes, or other transitions.
*/
typedef struct destination {
uint8_t index; /**< Entrance index */
uint8_t target; /**< Target room ID */
uint8_t target_layer; /**< Target layer */
} destination;
/** @} */
/**
* @brief Complete dungeon room data
*
* Contains all objects, sprites, and properties for a single dungeon room.
*/
typedef struct zelda3_dungeon_room {
uint16_t id; /**< Room ID (0-295) */
background2 bg2; /**< Background layer 2 effect (legacy) */
/* Room Contents */
dungeon_sprite* sprites; /**< Array of sprites in room */
int sprite_count; /**< Number of sprites */
object_door* doors; /**< Array of doors */
int door_count; /**< Number of doors */
staircase* staircases; /**< Array of staircases */
int staircase_count; /**< Number of staircases */
chest* chests; /**< Array of chests */
int chest_count; /**< Number of chests */
/* Room Connections */
destination pits; /**< Pit fall destination */
destination stairs[4]; /**< Stair destinations (up to 4) */
/* Room Properties */
uint8_t floor_type; /**< Floor graphics type */
uint8_t wall_type; /**< Wall graphics type */
uint8_t palette_id; /**< Room palette ID */
uint8_t music_track; /**< Background music track */
/* Flags */
bool is_dark; /**< True if room requires lamp */
bool has_water; /**< True if room contains water */
bool blocks_items; /**< True if room blocks certain items */
} zelda3_dungeon_room;
/** @} */
#ifdef __cplusplus
}
#endif
#endif // ZELDA_H