Class
HsCore
Description [src]
abstract class Hs.Core : GObject.Object
{
/* No available fields */
}
Base class for the cores.
To register the core in the frontend, it must have an exported function
GType hs_get_core_type (void), returning the GType of the
core class.
Subclasses must override the following virtual methods:
Hs.CoreClass.load_romHs.CoreClass.poll_inputHs.CoreClass.run_frameHs.CoreClass.resetHs.CoreClass.reload_saveHs.CoreClass.load_stateHs.CoreClass.save_stateHs.CoreClass.get_frame_rateHs.CoreClass.get_aspect_ratioHs.CoreClass.get_sample_rate
Everything else is optional and should be overridden as needed for the particular core.
HsCore also provides methods proxying to HsFrontend, such as
hs_core_play_samples(). This is done just for convenience, so that cores
don’t have to use hs_core_get_frontend() manually.
Platform Support
Every platform has its own interface for platform-specific methods:
HsNesCore for NES and so on. Cores must implement the corresponding
interfaces for their supported platforms.
Firmware
Some platforms require the original BIOS files. They can be queried using
hs_core_query_firmware_path(). When doing this, that firmware will be
marked as used, and the frontend can query that.
The list of available firmware IDs differs depending on the platform; they
are documented for their respective platform interfaces. For example,
PlayStation firmware IDs are defined in HsPlayStationFirmware.
The frontend will call hs_core_set_firmware_path() for all required types
before calling hs_core_load_rom().
Running the Game
Every core must override the Hs.CoreClass.load_rom method and load the
provided game, as well as initialize input and output within it.
After that, the game can be started using the Hs.CoreClass.start method, and
stopped with Hs.CoreClass.stop. When pausing and unpausing the game,
Hs.CoreClass.pause and Hs.CoreClass.resume will be called respectively. All
of these methods are optional, for example a single-threaded core doesn’t
need to override pause() and resume().
On every frame, the frontend calls Hs.CoreClass.run_frame. The core is
expected to run a single frame of emulation in it, as well as output video
and audio as appropriate.
The game can be reset with Hs.CoreClass.reset.
Frame Clock
Most cores don’t have a built-in frame clock and the frontend must provide
one, based on the value of Hs.CoreClass.get_frame_rate.
In case the core has one, it must implement
Hs.CoreClass.has_internal_frame_clock and return TRUE from there. In that
case the frontend must not use a frame clock itself and instead run frames
without delays.
Since the frontend can’t support fast forward when the core has its own frame
clock, the core must also implement Hs.CoreClass.set_speed_factor in this case.
Fast Forward
Region
Cores should override the Hs.CoreClass.get_region method to signal their
region (NTSC/PAL) where appropriate. The frontend may use this info for e.g.
deciding which video filter to use.
Input
The core must override the Hs.CoreClass.poll_input method and read input from
the provided HsInputState.
HsInputState contains input data for every platform, and the core must only
access the state from its current platform. If the core supports multiple
platforms, it must query the current platform first. Accessing any other
platform will result in undefined behavior.
The specific layout of the input data will differ depending on the platform,
see the corresponding documentation - for example, HsNesInputState for
NES.
Note
Add-on platforms do not have their own input state and reuse the one from their base platform.
Rumble
To use gamepad rumble, call hs_core_rumble().
Audio Output
Cores must override the Hs.CoreClass.get_sample_rate method, providing their
audio sample rate. Optionally, Hs.CoreClass.get_channels can be overridden as
well, providing the number of audio channels the core uses. If not
overridden, frontend will assume 2 channels.
To play audio, the core should call hs_core_play_samples(). The number
of samples should be consistent with the framerate.
Video Output
Every core must override the Hs.CoreClass.get_frame_rate and
Hs.CoreClass.get_aspect_ratio methods, reporting their current framerate and
aspect ratio.
Software Rendering
To use software rendering, the core must create a context using
hs_core_create_software_context() within load_rom().
For software contexts, the size and format of the framebuffer must be
provided right away and cannot be changed later, though the core is allowed
to recreate the context later. If the core can use multiple resolutions and
it’s not known at the creation time, provide the maximum size, and then use a
smaller area via hs_software_context_set_area(),
hs_software_context_set_row_stride() and/or
hs_software_context_set_offset().
To output the data, call hs_software_context_acquire_framebuffer() and
write your pixel data into that buffer. Once done, call
hs_software_context_release_framebuffer(). Try to spend as little time as
possible between these two calls. If the core needs to have access to a
framebuffer the whole time, allocate a separate buffer and render into it,
then copy its context into the frontend’s framebuffer in
hs_core_run_frame().
OpenGL Rendering
To use OpenGL, the core must create a context using
hs_core_create_gl_context() within load_rom().
GL contexts need to be realized before being used, using
hs_gl_context_realize(). This can fail, for example if the core requested
an unavailable profile or version. If that happens, the core should try a
different configuration or software rendering if possible, before failing to
load entirely.
After that, the context needs to be resized using hs_gl_context_set_size().
This can be done at any time.
The core must render its output into the default framebuffer, provided by the
frontend and accessed with hs_gl_context_get_default_framebuffer(). The
framebuffer will have a color attachment, as well as depth and stencil
attachment according to the flags passed into create_gl_context().
Use hs_gl_context_get_proc_address() to retrieve OpenGL symbols if the
core doesn’t have a way to do it on its own.
After rendering each frame, the core must call
hs_gl_context_swap_buffers().
OpenGL core output will often be vertically flipped. Pass
HS_GL_FLAGS_FLIPPED flag when creating the context to let the frontend
know that this is the case.
Before disposing the context, hs_gl_context_unrealize() must be called.
Reporting field metadata for TV consoles
When outputting TV signal, cores should report their interlacing field, overscan area and colorburst phase to the frontend, which can use this data to deinterlace the output, accurately emulate NTSC/PAL signal and crop overscan.
This should typically be done in Hs.CoreClass.run_frame.
Interlacing
The core should output interlaced video one field at a time. Do not attempt to blend fields or deinterlace the output, that will be done on the frontend side.
If the emulator cannot output one field at a time, change the rowstride and offset on your buffer to pick one field out of the deinterlaced output.
If the signal is interlaced, call hs_software_context_set_interlacing()
or hs_gl_context_set_interlacing() and pass
HS_INTERLACING_ODD_FIELD or HS_INTERLACING_EVEN_FIELD respectively.
If the signal is progressive, pass HS_INTERLACING_NONE.
Overscan
Call hs_software_context_set_overscan() or hs_gl_context_set_overscan()
with the desired overscan area. Do not crop it directly in the output or
blank it. Do not account for it when calculating aspect ratio or handling
pointer input, that will be done by the frontend.
Important
Overscan is not to be confused with hs_software_context_set_area();
area exists to use a smaller portion of the framebuffer, while overscan
exists to crop blank or garbage pixels near the edges, which would
normally be not visible on a TV. The frontend may still choose to show
overscan, while it will never show anything outside of the framebuffer area.
Colorburst Phase
Platforms like NES or PC Engine change their colorburst phase over time, sometimes in different ways depending on the game, region, and whether the output is progressive or interlaced.
Call hs_software_context_set_colorburst() or
hs_gl_context_set_colorburst() to report it.
The number of possible phases will depend on the platform and it’s frontend’s responsibility to handle that.
When possible, the colorburst phase should be derived from the emulator’s
own state. If the core has to track it itself, it should be manually reset
upon restart, and restored when loading a state, using
hs_core_get_colorburst_offset().
Save Data
The save data is stored in the save location, received as the save_path
parameter in Hs.CoreClass.load_rom and Hs.CoreClass.reload_save.
The core can either save its data directly into that location, or create a folder there and have save data inside it.
The frontend provides no guarantees about the ROM filenames, so the core must
not base its save data filenames on the ROM filename. Instead, use names like
save, save.dat, or base it on the game’s internal identifiers.
The core does not have to monitor the save location for changes - when the
frontend changes the save data, it must call Hs.CoreClass.reload_save to
request that. Note that the save path may be different with every
reload_save() call, and the core needs to switch to the new path and forget
about the previous location.
Some cores update their save data as soon as possible, whenever the game
modifies it. Those cores that don’t do that must implement
Hs.CoreClass.sync_save and save it there.
Save States
Cores must override two methods: Hs.CoreClass.load_state and
Hs.CoreClass.save_state. Both of these methods are asynchronous and don’t
have to be completed right away.
Multiple Media
Some games come on multiple media, e.g. multiple CDs on PlayStation. In that
case, Hs.CoreClass.load_rom will receive multiple filenames in rom_paths
and the core will need to switch which disc is currently active.
For this, the core must implement Hs.CoreClass.get_media_length,
Hs.CoreClass.get_current_media and Hs.CoreClass.set_current_media. They will
be called by the frontend to query and change the current media respectively.
When changing the current media from the core (both within
set_current_media() and otherwise), the core must call
hs_core_notify_current_media().
The frontend can access HsCore:current-media for convenience.
Note
For platforms like FDS that use double-sided media, each side counts as a separate media, not just each disk. As such, a 2-disk FDS game will have 4 media, corresponding to sides 1A, 1B, 2A and 2B respectively.
Logging
To log information, use hs_core_log(). It’s printf()-formatted and has
hs_core_log_valist() and hs_core_log_literal() variants as well.
Cores should not output anything directly to standard output.
Cache
Some cores need a location for temporary files, shader cache etc. Use
hs_core_get_cache_path() to get the cache location. Cores should not use
any other directories for this purpose.
The core is responsible for creating the cache file/directory if it doesn’t exist.
Note
The frontend may use a shared directory for everything or a separate directory for each game. Do not store per-game data like saves in the cache location.
Powering off
Some systems can power themselves off. Use hs_core_power_off() to signal
that to the frontend.
Instance methods
hs_core_load_state_finish
Finishes an asynchronous save state loading operation started with
hs_core_load_state().
hs_core_save_state_finish
Finishes an asynchronous state saving operation started with
hs_core_save_state().
Signals
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.
Class structure
struct HsCoreClass {
GObjectClass parent_class;
gboolean (* load_rom) (
HsCore* self,
const char** rom_paths,
int n_rom_paths,
const char* save_path,
GError** error
);
void (* start) (
HsCore* self
);
void (* poll_input) (
HsCore* self,
HsInputState* input_state
);
void (* run_frame) (
HsCore* self
);
gboolean (* reset) (
HsCore* self,
gboolean hard,
GError** error
);
void (* stop) (
HsCore* self
);
void (* pause) (
HsCore* self
);
void (* resume) (
HsCore* self
);
gboolean (* reload_save) (
HsCore* self,
const char* save_path,
GError** error
);
gboolean (* sync_save) (
HsCore* self,
GError** error
);
void (* load_state) (
HsCore* self,
const char* path,
HsStateCallback callback
);
void (* save_state) (
HsCore* self,
const char* path,
HsStateCallback callback
);
double (* get_frame_rate) (
HsCore* self
);
double (* get_aspect_ratio) (
HsCore* self
);
double (* get_sample_rate) (
HsCore* self
);
int (* get_channels) (
HsCore* self
);
HsRegion (* get_region) (
HsCore* self
);
guint (* get_media_length) (
HsCore* self
);
guint (* get_current_media) (
HsCore* self
);
void (* set_current_media) (
HsCore* self,
guint media
);
gboolean (* has_internal_frame_clock) (
HsCore* self
);
void (* set_speed_factor) (
HsCore* self,
double speed_factor
);
}
No description available.
Class members
parent_class: GObjectClassNo description available.
load_rom: gboolean (* load_rom) ( HsCore* self, const char** rom_paths, int n_rom_paths, const char* save_path, GError** error )No description available.
start: void (* start) ( HsCore* self )No description available.
poll_input: void (* poll_input) ( HsCore* self, HsInputState* input_state )No description available.
run_frame: void (* run_frame) ( HsCore* self )No description available.
reset: gboolean (* reset) ( HsCore* self, gboolean hard, GError** error )No description available.
stop: void (* stop) ( HsCore* self )No description available.
pause: void (* pause) ( HsCore* self )No description available.
resume: void (* resume) ( HsCore* self )No description available.
reload_save: gboolean (* reload_save) ( HsCore* self, const char* save_path, GError** error )No description available.
sync_save: gboolean (* sync_save) ( HsCore* self, GError** error )No description available.
load_state: void (* load_state) ( HsCore* self, const char* path, HsStateCallback callback )Loads a save state from
path.The core must call
callbackonce it’s finished, passing the error it got if the load failed, orNULLif it succeeded.save_state: void (* save_state) ( HsCore* self, const char* path, HsStateCallback callback )Saves the current state into
path.The core must call
callbackonce it’s finished, passing the error it got if the load failed, orNULLif it succeeded.get_frame_rate: double (* get_frame_rate) ( HsCore* self )No description available.
get_aspect_ratio: double (* get_aspect_ratio) ( HsCore* self )No description available.
get_sample_rate: double (* get_sample_rate) ( HsCore* self )No description available.
get_channels: int (* get_channels) ( HsCore* self )No description available.
get_region: HsRegion (* get_region) ( HsCore* self )No description available.
get_media_length: guint (* get_media_length) ( HsCore* self )No description available.
get_current_media: guint (* get_current_media) ( HsCore* self )No description available.
set_current_media: void (* set_current_media) ( HsCore* self, guint media )No description available.
has_internal_frame_clock: gboolean (* has_internal_frame_clock) ( HsCore* self )No description available.
set_speed_factor: void (* set_speed_factor) ( HsCore* self, double speed_factor )No description available.
Virtual methods
Hs.CoreClass.get_media_length
Gets the number of media for the current game (e.g. CDs on PlayStation).