frontend: omap: do centering on large resolutions
[pcsx_rearmed.git] / frontend / libretro.h
CommitLineData
38c2028e 1#ifndef LIBRETRO_H__
2#define LIBRETRO_H__
3
4#include <stdint.h>
5#include <stddef.h>
6
7#ifdef __cplusplus
8extern "C" {
9#else
10#if defined(_MSC_VER) && !defined(__cplusplus)
11#define bool unsigned char
12#define true 1
13#define false 0
14#else
15#include <stdbool.h>
16#endif
17#endif
18
19#define RETRO_API_VERSION 1
20
21#define RETRO_DEVICE_MASK 0xff
22#define RETRO_DEVICE_NONE 0
23#define RETRO_DEVICE_JOYPAD 1
24#define RETRO_DEVICE_MOUSE 2
25#define RETRO_DEVICE_KEYBOARD 3
26#define RETRO_DEVICE_LIGHTGUN 4
27#define RETRO_DEVICE_ANALOG 5
28
29#define RETRO_DEVICE_JOYPAD_MULTITAP ((1 << 8) | RETRO_DEVICE_JOYPAD)
30#define RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE ((1 << 8) | RETRO_DEVICE_LIGHTGUN)
31#define RETRO_DEVICE_LIGHTGUN_JUSTIFIER ((2 << 8) | RETRO_DEVICE_LIGHTGUN)
32#define RETRO_DEVICE_LIGHTGUN_JUSTIFIERS ((3 << 8) | RETRO_DEVICE_LIGHTGUN)
33
34#define RETRO_DEVICE_ID_JOYPAD_B 0
35#define RETRO_DEVICE_ID_JOYPAD_Y 1
36#define RETRO_DEVICE_ID_JOYPAD_SELECT 2
37#define RETRO_DEVICE_ID_JOYPAD_START 3
38#define RETRO_DEVICE_ID_JOYPAD_UP 4
39#define RETRO_DEVICE_ID_JOYPAD_DOWN 5
40#define RETRO_DEVICE_ID_JOYPAD_LEFT 6
41#define RETRO_DEVICE_ID_JOYPAD_RIGHT 7
42#define RETRO_DEVICE_ID_JOYPAD_A 8
43#define RETRO_DEVICE_ID_JOYPAD_X 9
44#define RETRO_DEVICE_ID_JOYPAD_L 10
45#define RETRO_DEVICE_ID_JOYPAD_R 11
46#define RETRO_DEVICE_ID_JOYPAD_L2 12
47#define RETRO_DEVICE_ID_JOYPAD_R2 13
48#define RETRO_DEVICE_ID_JOYPAD_L3 14
49#define RETRO_DEVICE_ID_JOYPAD_R3 15
50
51#define RETRO_DEVICE_INDEX_ANALOG_LEFT 0
52#define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1
53#define RETRO_DEVICE_ID_ANALOG_X 0
54#define RETRO_DEVICE_ID_ANALOG_Y 1
55
56#define RETRO_DEVICE_ID_MOUSE_X 0
57#define RETRO_DEVICE_ID_MOUSE_Y 1
58#define RETRO_DEVICE_ID_MOUSE_LEFT 2
59#define RETRO_DEVICE_ID_MOUSE_RIGHT 3
60
61#define RETRO_DEVICE_ID_LIGHTGUN_X 0
62#define RETRO_DEVICE_ID_LIGHTGUN_Y 1
63#define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2
64#define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3
65#define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4
66#define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5
67#define RETRO_DEVICE_ID_LIGHTGUN_START 6
68
69#define RETRO_REGION_NTSC 0
70#define RETRO_REGION_PAL 1
71
72#define RETRO_MEMORY_MASK 0xff
73#define RETRO_MEMORY_SAVE_RAM 0
74#define RETRO_MEMORY_RTC 1
75#define RETRO_MEMORY_SYSTEM_RAM 2
76#define RETRO_MEMORY_VIDEO_RAM 3
77
78#define RETRO_MEMORY_SNES_BSX_RAM ((1 << 8) | RETRO_MEMORY_SAVE_RAM)
79#define RETRO_MEMORY_SNES_BSX_PRAM ((2 << 8) | RETRO_MEMORY_SAVE_RAM)
80#define RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM ((3 << 8) | RETRO_MEMORY_SAVE_RAM)
81#define RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM ((4 << 8) | RETRO_MEMORY_SAVE_RAM)
82#define RETRO_MEMORY_SNES_GAME_BOY_RAM ((5 << 8) | RETRO_MEMORY_SAVE_RAM)
83#define RETRO_MEMORY_SNES_GAME_BOY_RTC ((6 << 8) | RETRO_MEMORY_RTC)
84
85#define RETRO_GAME_TYPE_BSX 0x101
86#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102
87#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103
88#define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104
89
90
91// Environment commands.
92#define RETRO_ENVIRONMENT_SET_ROTATION 1 // const unsigned * --
93 // Sets screen rotation of graphics.
94 // Is only implemented if rotation can be accelerated by hardware.
95 // Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180, 270 degrees
96 // counter-clockwise respectively.
97 //
98#define RETRO_ENVIRONMENT_GET_OVERSCAN 2 // bool * --
99 // Boolean value whether or not the implementation should use overscan, or crop away overscan.
100 //
101#define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 // bool * --
102 // Boolean value whether or not RetroArch supports frame duping,
103 // passing NULL to video frame callback.
104 //
105#define RETRO_ENVIRONMENT_GET_VARIABLE 4 // struct retro_variable * --
106 // Interface to aquire user-defined information from environment
107 // that cannot feasibly be supported in a multi-system way.
108 // Mostly used for obscure,
109 // specific features that the user can tap into when neseccary.
110 //
111#define RETRO_ENVIRONMENT_SET_VARIABLES 5 // const struct retro_variable * --
112 // Allows an implementation to signal the environment
113 // which variables it might want to check for later using GET_VARIABLE.
114 // 'data' points to an array of retro_variable structs terminated by a { NULL, NULL } element.
115 // retro_variable::value should contain a human readable description of the key.
116 //
117#define RETRO_ENVIRONMENT_SET_MESSAGE 6 // const struct retro_message * --
118 // Sets a message to be displayed in implementation-specific manner for a certain amount of 'frames'.
119 // Should not be used for trivial messages, which should simply be logged to stderr.
120#define RETRO_ENVIRONMENT_SHUTDOWN 7 // N/A (NULL) --
121 // Requests the frontend to shutdown.
122 // Should only be used if game has a specific
123 // way to shutdown the game from a menu item or similar.
124 //
125#define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8
126 // const unsigned * --
127 // Gives a hint to the frontend how demanding this implementation
128 // is on a system. E.g. reporting a level of 2 means
129 // this implementation should run decently on all frontends
130 // of level 2 and up.
131 //
132 // It can be used by the frontend to potentially warn
133 // about too demanding implementations.
134 //
135 // The levels are "floating", but roughly defined as:
136 // 1: Low-powered devices such as Raspberry Pi, smart phones, tablets, etc.
137 // 2: Medium-spec consoles, such as PS3/360, with sub-par CPUs.
138 // 3: Modern desktop/laptops with reasonably powerful CPUs.
139 // 4: High-end desktops with very powerful CPUs.
140 //
141 // This function can be called on a per-game basis,
142 // as certain games an implementation can play might be
143 // particularily demanding.
144 // If called, it should be called in retro_load_game().
145 //
146#define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
147 // const char ** --
148 // Returns the "system" directory of the frontend.
149 // This directory can be used to store system specific ROMs such as BIOSes, configuration data, etc.
150 // The returned value can be NULL.
151 // If so, no such directory is defined,
152 // and it's up to the implementation to find a suitable directory.
153 //
154#define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
155 // const enum retro_pixel_format * --
156 // Sets the internal pixel format used by the implementation.
157 // The default pixel format is RETRO_PIXEL_FORMAT_XRGB1555.
158 // If the call returns false, the frontend does not support this pixel format.
159 // This function should be called inside retro_load_game() or retro_get_system_av_info().
160
161enum retro_pixel_format
162{
163 RETRO_PIXEL_FORMAT_0RGB1555 = 0, // 0RGB1555, native endian. 0 bit must be set to 0.
164 RETRO_PIXEL_FORMAT_XRGB8888 // XRGB8888, native endian. X bits are ignored.
165};
166
167struct retro_message
168{
169 const char *msg; // Message to be displayed.
170 unsigned frames; // Duration in frames of message.
171};
172
173struct retro_system_info
174{
175 const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc.
176 const char *library_version; // Descriptive version of core.
177
178 const char *valid_extensions; // A string listing probably rom extensions the core will be able to load, separated with pipe.
179 // I.e. "bin|rom|iso".
180 // Typically used for a GUI to filter out extensions.
181
182 bool need_fullpath; // If true, retro_load_game() is guaranteed to provide a valid pathname in retro_game_info::path.
183 // ::data and ::size are both invalid.
184 // If false, ::data and ::size are guaranteed to be valid, but ::path might not be valid.
185 // This is typically set to true for libretro implementations that must load from file.
186 // Implementations should strive for setting this to false, as it allows the frontend to perform patching, etc.
187
188 bool block_extract; // If true, the frontend is not allowed to extract any archives before loading the real ROM.
189 // Necessary for certain libretro implementations that load games from zipped archives.
190};
191
192struct retro_game_geometry
193{
194 unsigned base_width; // Nominal video width of game.
195 unsigned base_height; // Nominal video height of game.
196 unsigned max_width; // Maximum possible width of game.
197 unsigned max_height; // Maximum possible height of game.
198
199 float aspect_ratio; // Nominal aspect ratio of game. If aspect_ratio is <= 0.0,
200 // an aspect ratio of base_width / base_height is assumed.
201 // A frontend could override this setting if desired.
202};
203
204struct retro_system_timing
205{
206 double fps; // FPS of video content.
207 double sample_rate; // Sampling rate of audio.
208};
209
210struct retro_system_av_info
211{
212 struct retro_game_geometry geometry;
213 struct retro_system_timing timing;
214};
215
216struct retro_variable
217{
218 const char *key; // Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.
219 // If NULL, obtains the complete environment string if more complex parsing is necessary.
220 // The environment string is formatted as key-value pairs delimited by semicolons as so:
221 // "key1=value1;key2=value2;..."
222 const char *value; // Value to be obtained. If key does not exist, it is set to NULL.
223};
224
225struct retro_game_info
226{
227 const char *path; // Path to game, UTF-8 encoded. Usually used as a reference.
228 // May be NULL if rom was loaded from stdin or similar.
229 // retro_system_info::need_fullpath guaranteed that this path is valid.
230 const void *data; // Memory buffer of loaded game. Will be NULL if need_fullpath was set.
231 size_t size; // Size of memory buffer.
232 const char *meta; // String of implementation specific meta-data.
233};
234
235// Callbacks
236//
237// Environment callback. Gives implementations a way of performing uncommon tasks. Extensible.
238typedef bool (*retro_environment_t)(unsigned cmd, void *data);
239
240// Render a frame. Pixel format is 15-bit 0RGB1555 native endian unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
241// Width and height specify dimensions of buffer.
242// Pitch specifices length in bytes between two lines in buffer.
243typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch);
244
245// Renders a single audio frame. Should only be used if implementation generates a single sample at a time.
246// Format is signed 16-bit native endian.
247typedef void (*retro_audio_sample_t)(int16_t left, int16_t right);
248// Renders multiple audio frames in one go. One frame is defined as a sample of left and right channels, interleaved.
249// I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
250// Only one of the audio callbacks must ever be used.
251typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, size_t frames);
252
253// Polls input.
254typedef void (*retro_input_poll_t)(void);
255// Queries for input for player 'port'. device will be masked with RETRO_DEVICE_MASK.
256// Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that have been set with retro_set_controller_port_device()
257// will still use the higher level RETRO_DEVICE_JOYPAD to request input.
258typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, unsigned index, unsigned id);
259
260// Sets callbacks. retro_set_environment() is guaranteed to be called before retro_init().
261// The rest of the set_* functions are guaranteed to have been called before the first call to retro_run() is made.
262void retro_set_environment(retro_environment_t);
263void retro_set_video_refresh(retro_video_refresh_t);
264void retro_set_audio_sample(retro_audio_sample_t);
265void retro_set_audio_sample_batch(retro_audio_sample_batch_t);
266void retro_set_input_poll(retro_input_poll_t);
267void retro_set_input_state(retro_input_state_t);
268
269// Library global initialization/deinitialization.
270void retro_init(void);
271void retro_deinit(void);
272
273// Must return RETRO_API_VERSION. Used to validate ABI compatibility when the API is revised.
274unsigned retro_api_version(void);
275
276// Gets statically known system info. Pointers provided in *info must be statically allocated.
277// Can be called at any time, even before retro_init().
278void retro_get_system_info(struct retro_system_info *info);
279
280// Gets information about system audio/video timings and geometry.
281// Can be called only after retro_load_game() has successfully completed.
282void retro_get_system_av_info(struct retro_system_av_info *info);
283
284// Sets device to be used for player 'port'.
285void retro_set_controller_port_device(unsigned port, unsigned device);
286
287// Resets the current game.
288void retro_reset(void);
289
290// Runs the game for one video frame.
291// During retro_run(), input_poll callback must be called at least once.
292//
293// If a frame is not rendered for reasons where a game "dropped" a frame,
294// this still counts as a frame, and retro_run() should explicitly dupe a frame if GET_CAN_DUPE returns true.
295// In this case, the video callback can take a NULL argument for data.
296void retro_run(void);
297
298// Returns the amount of data the implementation requires to serialize internal state (save states).
299// Beetween calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned value, to
300// ensure that the frontend can allocate a save state buffer once.
301size_t retro_serialize_size(void);
302
303// Serializes internal state. If failed, or size is lower than retro_serialize_size(), it should return false, true otherwise.
304bool retro_serialize(void *data, size_t size);
305bool retro_unserialize(const void *data, size_t size);
306
307void retro_cheat_reset(void);
308void retro_cheat_set(unsigned index, bool enabled, const char *code);
309
310// Loads a game.
311bool retro_load_game(const struct retro_game_info *game);
312
313// Loads a "special" kind of game. Should not be used except in extreme cases.
314bool retro_load_game_special(
315 unsigned game_type,
316 const struct retro_game_info *info, size_t num_info
317);
318
319// Unloads a currently loaded game.
320void retro_unload_game(void);
321
322// Gets region of game.
323unsigned retro_get_region(void);
324
325// Gets region of memory.
326void *retro_get_memory_data(unsigned id);
327size_t retro_get_memory_size(unsigned id);
328
329#ifdef __cplusplus
330}
331#endif
332
333#endif