Overview
Hydra provides a comprehensive C API for embedding the Nintendo Switch emulator into applications. The API is designed to be portable and easy to use from various languages including Swift, C++, and others. The C API is declared insrc/core/c_api.h and provides access to:
- Emulation context management
- Configuration and settings
- Game loading and ROM handling
- User management
- Debugging and logging
- Filesystem operations
Core Types
hydra_string
A C-compatible string type for passing strings across the API boundary.Pointer to the string data (not null-terminated)
Length of the string in bytes
hydra_u128
A 128-bit unsigned integer type used for user IDs and other large values.hydra_uint2
A 2D unsigned integer vector for resolution and dimensions.Emulation Context
The emulation context is the core object that manages the emulator instance.hydra_create_emulation_context
Creates a new emulation context.Pointer to the created emulation context. Returns a non-null pointer on success.
hydra_emulation_context_destroy
Destroys an emulation context and frees associated resources.The emulation context to destroy
hydra_emulation_context_set_surface
Sets the rendering surface for the emulator.The emulation context
Platform-specific surface pointer (e.g., CAMetalLayer* on Metal)
hydra_emulation_context_load_and_start
Loads a game and starts emulation.The emulation context
The loader object containing the game to run
hydra_emulation_context_pause
Pauses emulation.The emulation context to pause
hydra_emulation_context_resume
Resumes paused emulation.The emulation context to resume
hydra_emulation_context_request_stop
Requests a graceful stop of emulation.The emulation context to stop
hydra_emulation_context_force_stop
Forces an immediate stop of emulation.The emulation context to stop
hydra_emulation_context_is_running
Checks if emulation is currently running.The emulation context to check
true if emulation is running, false otherwise
hydra_emulation_context_progress_frame
Advances emulation by one frame.The emulation context
Current display width in pixels
Current display height in pixels
Output parameter indicating if delta time average was updated
hydra_emulation_context_get_last_delta_time_average
Gets the average frame time.The emulation context
Average delta time in seconds
hydra_emulation_context_take_screenshot
Captures a screenshot of the current frame.The emulation context
hydra_emulation_context_capture_gpu_frame
Captures GPU frame data for debugging.The emulation context
Game Loading
hydra_create_loader_from_path
Creates a loader for a game file.Path to the game file (NSP, XCI, NCA, etc.)
Pointer to the loader object, or NULL on failure
hydra_loader_destroy
Destroys a loader object.The loader to destroy
hydra_loader_get_title_id
Gets the title ID of the loaded game.The loader object
The game’s title ID
hydra_loader_has_icon
Checks if the game has an icon.The loader object
true if the game has an icon, false otherwise
hydra_loader_extract_icon
Extracts the game icon to a file.The loader object
Destination path for the icon file
String Management
The C API provides utilities for working with string lists and maps.hydra_create_string_list
Creates a new string list.Non-null pointer to the created string list
hydra_string_list_destroy
Destroys a string list.The string list to destroy
hydra_string_list_get_count
Gets the number of strings in the list.The string list
Number of strings in the list
hydra_string_list_get
Gets a string at the specified index.The string list
Index of the string to retrieve
The string at the specified index
hydra_string_list_append
Appends a string to the list.The string list
The string to append
Error Handling
Most C API functions that can fail return NULL pointers or boolean values to indicate errors. Always check return values:Thread Safety
The emulation context is designed to be used from a single thread. If you need to interact with the emulator from multiple threads, use proper synchronization mechanisms. The debugger API provides explicit locking functions:Language Bindings
The C API is designed to be easily wrapped in other languages:Swift Example
src/frontend/swiftui/Api.swift for the complete Swift wrapper implementation.