apollo_hyper_libretro_sys/lib.rs
1// Copyright (C) 2016 Jan Bujak
2// Copyright (C) 2010-2016 The RetroArch team
3//
4// ---------------------------------------------------------------------------------------
5// The following license statement only applies to this libretro API header (libretro.h).
6// ---------------------------------------------------------------------------------------
7//
8// Permission is hereby granted, free of charge,
9// to any person obtaining a copy of this software and associated documentation files (the "Software"),
10// to deal in the Software without restriction, including without limitation the rights to
11// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12// and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23extern crate libc;
24
25macro_rules! define_enum {
26 (
27 $( #[$enum_attr:meta] )*
28 pub enum $typename:ident {
29 $( $( $( #[$variant_attr:meta] )* $variant:ident ),+ = $value:expr ),+,
30 }
31 ) => {
32 #[allow(non_camel_case_types)]
33 $( #[$enum_attr] )*
34 pub enum $typename {
35 $( $( $( #[$variant_attr] )* $variant ),+ = $value ),+,
36 }
37
38 impl $typename {
39 pub fn from_uint( value: libc::c_uint ) -> Option< Self > {
40 $( $(
41 if value == $typename::$variant as libc::c_uint {
42 return Some( $typename::$variant )
43 }
44 )+ )+
45
46 None
47 }
48
49 pub fn to_uint( self ) -> libc::c_uint {
50 use std::mem::transmute;
51 unsafe {
52 // This will generate an error at compile time if the size
53 // of the enum is not equal to the size of libc::c_uint.
54 transmute( self )
55 }
56 }
57 }
58 };
59}
60
61// Used for checking API/ABI mismatches that can break libretro
62// implementations.
63// It is not incremented for compatible changes to the API.
64pub const API_VERSION: libc::c_uint = 1;
65
66// Libretro's fundamental device abstractions.
67//
68// Libretro's input system consists of some standardized device types,
69// such as a joypad (with/without analog), mouse, keyboard, lightgun
70// and a pointer.
71//
72// The functionality of these devices are fixed, and individual cores
73// map their own concept of a controller to libretro's abstractions.
74// This makes it possible for frontends to map the abstract types to a
75// real input device, and not having to worry about binding input
76// correctly to arbitrary controller layouts.
77
78pub const DEVICE_TYPE_SHIFT: libc::c_uint = 8;
79pub const DEVICE_MASK: libc::c_uint = (1 << DEVICE_TYPE_SHIFT) - 1;
80// TODO: Insert DEVICE_SUBCLASS here
81
82// Input disabled.
83pub const DEVICE_NONE: libc::c_uint = 0;
84
85// The JOYPAD is called RetroPad. It is essentially a Super Nintendo
86// controller, but with additional L2/R2/L3/R3 buttons, similar to a
87// PS1 DualShock.
88pub const DEVICE_JOYPAD: libc::c_uint = 1;
89
90// The mouse is a simple mouse, similar to Super Nintendo's mouse.
91// X and Y coordinates are reported relatively to last poll (poll callback).
92// It is up to the libretro implementation to keep track of where the mouse
93// pointer is supposed to be on the screen.
94// The frontend must make sure not to interfere with its own hardware
95// mouse pointer.
96pub const DEVICE_MOUSE: libc::c_uint = 2;
97
98// KEYBOARD device lets one poll for raw key pressed.
99// It is poll based, so input callback will return with the current
100// pressed state.
101// For event/text based keyboard input, see
102// ENVIRONMENT_SET_KEYBOARD_CALLBACK.
103pub const DEVICE_KEYBOARD: libc::c_uint = 3;
104
105// Lightgun X/Y coordinates are reported relatively to last poll,
106// similar to mouse.
107pub const DEVICE_LIGHTGUN: libc::c_uint = 4;
108
109// The ANALOG device is an extension to JOYPAD (RetroPad).
110// Similar to DualShock it adds two analog sticks.
111// This is treated as a separate device type as it returns values in the
112// full analog range of [-0x8000, 0x7fff]. Positive X axis is right.
113// Positive Y axis is down.
114// Only use ANALOG type when polling for analog values of the axes.
115pub const DEVICE_ANALOG: libc::c_uint = 5;
116
117// Abstracts the concept of a pointing mechanism, e.g. touch.
118// This allows libretro to query in absolute coordinates where on the
119// screen a mouse (or something similar) is being placed.
120// For a touch centric device, coordinates reported are the coordinates
121// of the press.
122//
123// Coordinates in X and Y are reported as:
124// [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen,
125// and 0x7fff corresponds to the far right/bottom of the screen.
126// The "screen" is here defined as area that is passed to the frontend and
127// later displayed on the monitor.
128//
129// The frontend is free to scale/resize this screen as it sees fit, however,
130// (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the
131// game image, etc.
132//
133// To check if the pointer coordinates are valid (e.g. a touch display
134// actually being touched), PRESSED returns 1 or 0.
135//
136// If using a mouse on a desktop, PRESSED will usually correspond to the
137// left mouse button, but this is a frontend decision.
138// PRESSED will only return 1 if the pointer is inside the game screen.
139//
140// For multi-touch, the index variable can be used to successively query
141// more presses.
142// If index = 0 returns true for _PRESSED, coordinates can be extracted
143// with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with
144// index = 1, and so on.
145// Eventually _PRESSED will return false for an index. No further presses
146// are registered at this point.
147pub const DEVICE_POINTER: libc::c_uint = 6;
148
149// Buttons for the RetroPad (JOYPAD).
150// The placement of these is equivalent to placements on the
151// Super Nintendo controller.
152//
153// L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
154pub const DEVICE_ID_JOYPAD_B: libc::c_uint = 0;
155pub const DEVICE_ID_JOYPAD_Y: libc::c_uint = 1;
156pub const DEVICE_ID_JOYPAD_SELECT: libc::c_uint = 2;
157pub const DEVICE_ID_JOYPAD_START: libc::c_uint = 3;
158pub const DEVICE_ID_JOYPAD_UP: libc::c_uint = 4;
159pub const DEVICE_ID_JOYPAD_DOWN: libc::c_uint = 5;
160pub const DEVICE_ID_JOYPAD_LEFT: libc::c_uint = 6;
161pub const DEVICE_ID_JOYPAD_RIGHT: libc::c_uint = 7;
162pub const DEVICE_ID_JOYPAD_A: libc::c_uint = 8;
163pub const DEVICE_ID_JOYPAD_X: libc::c_uint = 9;
164pub const DEVICE_ID_JOYPAD_L: libc::c_uint = 10;
165pub const DEVICE_ID_JOYPAD_R: libc::c_uint = 11;
166pub const DEVICE_ID_JOYPAD_L2: libc::c_uint = 12;
167pub const DEVICE_ID_JOYPAD_R2: libc::c_uint = 13;
168pub const DEVICE_ID_JOYPAD_L3: libc::c_uint = 14;
169pub const DEVICE_ID_JOYPAD_R3: libc::c_uint = 15;
170
171// Index / ID values for ANALOG device.
172pub const DEVICE_INDEX_ANALOG_LEFT: libc::c_uint = 0;
173pub const DEVICE_INDEX_ANALOG_RIGHT: libc::c_uint = 1;
174pub const DEVICE_ID_ANALOG_X: libc::c_uint = 0;
175pub const DEVICE_ID_ANALOG_Y: libc::c_uint = 1;
176
177// ID values for MOUSE.
178pub const DEVICE_ID_MOUSE_X: libc::c_uint = 0;
179pub const DEVICE_ID_MOUSE_Y: libc::c_uint = 1;
180pub const DEVICE_ID_MOUSE_LEFT: libc::c_uint = 2;
181pub const DEVICE_ID_MOUSE_RIGHT: libc::c_uint = 3;
182pub const DEVICE_ID_MOUSE_WHEELUP: libc::c_uint = 4;
183pub const DEVICE_ID_MOUSE_WHEELDOWN: libc::c_uint = 5;
184pub const DEVICE_ID_MOUSE_MIDDLE: libc::c_uint = 6;
185pub const DEVICE_ID_MOUSE_HORIZ_WHEELUP: libc::c_uint = 7;
186pub const DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: libc::c_uint = 8;
187
188// ID values for LIGHTGUN types.
189pub const DEVICE_ID_LIGHTGUN_X: libc::c_uint = 0;
190pub const DEVICE_ID_LIGHTGUN_Y: libc::c_uint = 1;
191pub const DEVICE_ID_LIGHTGUN_TRIGGER: libc::c_uint = 2;
192pub const DEVICE_ID_LIGHTGUN_CURSOR: libc::c_uint = 3;
193pub const DEVICE_ID_LIGHTGUN_TURBO: libc::c_uint = 4;
194pub const DEVICE_ID_LIGHTGUN_PAUSE: libc::c_uint = 5;
195pub const DEVICE_ID_LIGHTGUN_START: libc::c_uint = 6;
196
197// ID values for POINTER.
198pub const DEVICE_ID_POINTER_X: libc::c_uint = 0;
199pub const DEVICE_ID_POINTER_Y: libc::c_uint = 1;
200pub const DEVICE_ID_POINTER_PRESSED: libc::c_uint = 2;
201
202define_enum! {
203 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
204 #[repr(C)]
205 pub enum Region {
206 NTSC = 0,
207 PAL = 1,
208 }
209}
210
211define_enum! {
212 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
213 #[repr(C)]
214 pub enum Language {
215 English = 0,
216 Japanese = 1,
217 French = 2,
218 Spanish = 3,
219 German = 4,
220 Italian = 5,
221 Dutch = 6,
222 Portuguese = 7,
223 Russian = 8,
224 Korean = 9,
225 ChineseTraditional = 10,
226 ChineseSimplified = 11,
227 Esperanto = 12,
228 Polish = 13,
229 }
230}
231
232// Passed to retro_get_memory_data/size().
233// If the memory type doesn't apply to the
234// implementation NULL/0 can be returned.
235pub const MEMORY_MASK: libc::c_uint = 0xff;
236
237// Regular save RAM. This RAM is usually found on a game cartridge,
238// backed up by a battery.
239//
240// If save game data is too complex for a single memory buffer,
241// the SAVE_DIRECTORY (preferably) or SYSTEM_DIRECTORY environment
242// callback can be used.
243pub const MEMORY_SAVE_RAM: libc::c_uint = 0;
244
245// Some games have a built-in clock to keep track of time.
246// This memory is usually just a couple of bytes to keep track of time.
247pub const MEMORY_RTC: libc::c_uint = 1;
248
249// System ram lets a frontend peek into a game systems main RAM.
250pub const MEMORY_SYSTEM_RAM: libc::c_uint = 2;
251
252// Video ram lets a frontend peek into a game systems video RAM (VRAM).
253pub const MEMORY_VIDEO_RAM: libc::c_uint = 3;
254
255define_enum! {
256 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
257 #[repr(C)]
258 pub enum Key {
259 Unknown = 0,
260
261 Backspace = 8,
262 Tab = 9,
263 Clear = 12,
264 Return = 13,
265 Pause = 19,
266 Escape = 27,
267 Space = 32,
268 ExclamationMark = 33,
269 DoubleQuotes = 34,
270 Hash = 35,
271 Dollar = 36,
272 Ampersand = 38,
273 Quote = 39,
274 LeftParen = 40,
275 RightParen = 41,
276 Asterisk = 42,
277 Plus = 43,
278 Comma = 44,
279 Minus = 45,
280 Period = 46,
281 Slash = 47,
282 Number_0 = 48,
283 Number_1 = 49,
284 Number_2 = 50,
285 Number_3 = 51,
286 Number_4 = 52,
287 Number_5 = 53,
288 Number_6 = 54,
289 Number_7 = 55,
290 Number_8 = 56,
291 Number_9 = 57,
292 Colon = 58,
293 Semicolon = 59,
294 Less = 60,
295 Equals = 61,
296 Greater = 62,
297 QuestionMark = 63,
298 At = 64,
299 LeftBracket = 91,
300 Backslash = 92,
301 RightBracket = 93,
302 Caret = 94,
303 Underscore = 95,
304 Backquote = 96,
305 A = 97,
306 B = 98,
307 C = 99,
308 D = 100,
309 E = 101,
310 F = 102,
311 G = 103,
312 H = 104,
313 I = 105,
314 J = 106,
315 K = 107,
316 L = 108,
317 M = 109,
318 N = 110,
319 O = 111,
320 P = 112,
321 Q = 113,
322 R = 114,
323 S = 115,
324 T = 116,
325 U = 117,
326 V = 118,
327 W = 119,
328 X = 120,
329 Y = 121,
330 Z = 122,
331 Delete = 127,
332
333 Kp0 = 256,
334 Kp1 = 257,
335 Kp2 = 258,
336 Kp3 = 259,
337 Kp4 = 260,
338 Kp5 = 261,
339 Kp6 = 262,
340 Kp7 = 263,
341 Kp8 = 264,
342 Kp9 = 265,
343 KpPeriod = 266,
344 KpDivide = 267,
345 KpMultiply = 268,
346 KpMinus = 269,
347 KpPlus = 270,
348 KpEnter = 271,
349 KpEquals = 272,
350
351 Up = 273,
352 Down = 274,
353 Right = 275,
354 Left = 276,
355 Insert = 277,
356 Home = 278,
357 End = 279,
358 PageUp = 280,
359 PageDown = 281,
360
361 F1 = 282,
362 F2 = 283,
363 F3 = 284,
364 F4 = 285,
365 F5 = 286,
366 F6 = 287,
367 F7 = 288,
368 F8 = 289,
369 F9 = 290,
370 F10 = 291,
371 F11 = 292,
372 F12 = 293,
373 F13 = 294,
374 F14 = 295,
375 F15 = 296,
376
377 Numlock = 300,
378 Capslock = 301,
379 Scrollock = 302,
380 RShift = 303,
381 LShift = 304,
382 RCtrl = 305,
383 LCtrl = 306,
384 RAlt = 307,
385 LAlt = 308,
386 RMeta = 309,
387 LMeta = 310,
388 LSuper = 311,
389 RSuper = 312,
390 Mode = 313,
391 Compose = 314,
392
393 Help = 315,
394 Print = 316,
395 Sysrq = 317,
396 Break = 318,
397 Menu = 319,
398 Power = 320,
399 Euro = 321,
400 Undo = 322,
401 }
402}
403
404define_enum! {
405 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
406 #[repr(C)]
407 pub enum Mod {
408 None = 0x0000,
409
410 Shift = 0x01,
411 Ctrl = 0x02,
412 Alt = 0x04,
413 Meta = 0x08,
414
415 Numlock = 0x10,
416 Capslock = 0x20,
417 Scrollock = 0x40,
418 }
419}
420
421// If set, this call is not part of the public libretro API yet. It can
422// change or be removed at any time.
423pub const ENVIRONMENT_EXPERIMENTAL: libc::c_uint = 0x10000;
424
425// Environment callback to be used internally in frontend.
426pub const ENVIRONMENT_PRIVATE: libc::c_uint = 0x20000;
427
428// Environment commands.
429
430// const unsigned * --
431// Sets screen rotation of graphics.
432// Is only implemented if rotation can be accelerated by hardware.
433// Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180,
434// 270 degrees counter-clockwise respectively.
435pub const ENVIRONMENT_SET_ROTATION: libc::c_uint = 1;
436
437// bool * --
438// Boolean value whether or not the implementation should use overscan,
439// or crop away overscan.
440pub const ENVIRONMENT_GET_OVERSCAN: libc::c_uint = 2;
441
442// bool * --
443// Boolean value whether or not frontend supports frame duping,
444// passing NULL to video frame callback.
445pub const ENVIRONMENT_GET_CAN_DUPE: libc::c_uint = 3;
446
447// Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES),
448// and reserved to avoid possible ABI clash.
449
450// const struct Message * --
451// Sets a message to be displayed in implementation-specific manner
452// for a certain amount of 'frames'.
453// Should not be used for trivial messages, which should simply be
454// logged via ENVIRONMENT_GET_LOG_INTERFACE (or as a
455// fallback, stderr).
456pub const ENVIRONMENT_SET_MESSAGE: libc::c_uint = 6;
457
458// N/A (NULL) --
459// Requests the frontend to shutdown.
460// Should only be used if game has a specific
461// way to shutdown the game from a menu item or similar.
462pub const ENVIRONMENT_SHUTDOWN: libc::c_uint = 7;
463
464// const unsigned * --
465// Gives a hint to the frontend how demanding this implementation
466// is on a system. E.g. reporting a level of 2 means
467// this implementation should run decently on all frontends
468// of level 2 and up.
469//
470// It can be used by the frontend to potentially warn
471// about too demanding implementations.
472//
473// The levels are "floating".
474//
475// This function can be called on a per-game basis,
476// as certain games an implementation can play might be
477// particularly demanding.
478//
479// If called, it should be called in retro_load_game().
480pub const ENVIRONMENT_SET_PERFORMANCE_LEVEL: libc::c_uint = 8;
481
482// const char ** --
483// Returns the "system" directory of the frontend.
484// This directory can be used to store system specific
485// content such as BIOSes, configuration data, etc.
486// The returned value can be NULL.
487// If so, no such directory is defined,
488// and it's up to the implementation to find a suitable directory.
489//
490// NOTE: Some cores used this folder also for "save" data such as
491// memory cards, etc, for lack of a better place to put it.
492// This is now discouraged, and if possible, cores should try to
493// use the new GET_SAVE_DIRECTORY.
494pub const ENVIRONMENT_GET_SYSTEM_DIRECTORY: libc::c_uint = 9;
495
496// const enum PixelFormat * --
497// Sets the internal pixel format used by the implementation.
498// The default pixel format is RGB1555.
499// This pixel format however, is deprecated (see enum PixelFormat).
500// If the call returns false, the frontend does not support this pixel
501// format.
502//
503// This function should be called inside retro_load_game() or
504// retro_get_system_av_info().
505pub const ENVIRONMENT_SET_PIXEL_FORMAT: libc::c_uint = 10;
506
507// const struct InputDescriptor * --
508// Sets an array of retro_input_descriptors.
509// It is up to the frontend to present this in a usable way.
510// The array is terminated by retro_input_descriptor::description
511// being set to NULL.
512//
513// This function can be called at any time, but it is recommended
514// to call it as early as possible.
515pub const ENVIRONMENT_SET_INPUT_DESCRIPTORS: libc::c_uint = 11;
516
517// const struct KeyboardCallback * --
518// Sets a callback function used to notify core about keyboard events.
519pub const ENVIRONMENT_SET_KEYBOARD_CALLBACK: libc::c_uint = 12;
520
521// const struct DiskControlCallback * --
522// Sets an interface which frontend can use to eject and insert
523// disk images.
524//
525// This is used for games which consist of multiple images and
526// must be manually swapped out by the user (e.g. PSX).
527pub const ENVIRONMENT_SET_DISK_CONTROL_INTERFACE: libc::c_uint = 13;
528
529// struct HwRenderCallback * --
530// Sets an interface to let a libretro core render with
531// hardware acceleration.
532//
533// Should be called in retro_load_game().
534//
535// If successful, libretro cores will be able to render to a
536// frontend-provided framebuffer.
537//
538// The size of this framebuffer will be at least as large as
539// max_width/max_height provided in get_av_info().
540//
541// If HW rendering is used, pass only HW_FRAME_BUFFER_VALID or
542// NULL to retro_video_refresh_t.
543pub const ENVIRONMENT_SET_HW_RENDER: libc::c_uint = 14;
544
545// struct Variable * --
546// Interface to acquire user-defined information from environment
547// that cannot feasibly be supported in a multi-system way.
548// 'key' should be set to a key which has already been set by
549// SET_VARIABLES.
550//
551// 'data' will be set to a value or NULL.
552pub const ENVIRONMENT_GET_VARIABLE: libc::c_uint = 15;
553
554// const struct Variable * --
555// Allows an implementation to signal the environment
556// which variables it might want to check for later using
557// GET_VARIABLE.
558// This allows the frontend to present these variables to
559// a user dynamically.
560// This should be called as early as possible (ideally in
561// retro_set_environment).
562//
563// 'data' points to an array of retro_variable structs
564// terminated by a { NULL, NULL } element.
565// retro_variable::key should be namespaced to not collide
566// with other implementations' keys. E.g. A core called
567// 'foo' should use keys named as 'foo_option'.
568// retro_variable::value should contain a human readable
569// description of the key as well as a '|' delimited list
570// of expected values.
571//
572// The number of possible options should be very limited,
573// i.e. it should be feasible to cycle through options
574// without a keyboard.
575//
576// First entry should be treated as a default.
577//
578// Example entry:
579// { "foo_option", "Speed hack coprocessor X; false|true" }
580//
581// Text before first ';' is description. This ';' must be
582// followed by a space, and followed by a list of possible
583// values split up with '|'.
584//
585// Only strings are operated on. The possible values will
586// generally be displayed and stored as-is by the frontend.
587pub const ENVIRONMENT_SET_VARIABLES: libc::c_uint = 16;
588
589// bool * --
590// Result is set to true if some variables are updated by
591// frontend since last call to ENVIRONMENT_GET_VARIABLE.
592// Variables should be queried with GET_VARIABLE.
593pub const ENVIRONMENT_GET_VARIABLE_UPDATE: libc::c_uint = 17;
594
595// const bool * --
596// If true, the libretro implementation supports calls to
597// retro_load_game() with NULL as argument.
598//
599// Used by cores which can run without particular game data.
600// This should be called within retro_set_environment() only.
601pub const ENVIRONMENT_SET_SUPPORT_NO_GAME: libc::c_uint = 18;
602
603// const char ** --
604// Retrieves the absolute path from where this libretro
605// implementation was loaded.
606// NULL is returned if the libretro was loaded statically
607// (i.e. linked statically to frontend), or if the path cannot be
608// determined.
609//
610// Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can
611// be loaded without ugly hacks.
612pub const ENVIRONMENT_GET_LIBRETRO_PATH: libc::c_uint = 19;
613
614// Environment 20 was an obsolete version of SET_AUDIO_CALLBACK.
615// It was not used by any known core at the time,
616// and was removed from the API.
617
618// const struct AudioCallback * --
619// Sets an interface which is used to notify a libretro core about audio
620// being available for writing.
621// The callback can be called from any thread, so a core using this must
622// have a thread safe audio implementation.
623// It is intended for games where audio and video are completely
624// asynchronous and audio can be generated on the fly.
625// This interface is not recommended for use with emulators which have
626// highly synchronous audio.
627//
628// The callback only notifies about writability; the libretro core still
629// has to call the normal audio callbacks
630// to write audio. The audio callbacks must be called from within the
631// notification callback.
632// The amount of audio data to write is up to the implementation.
633// Generally, the audio callback will be called continously in a loop.
634//
635// Due to thread safety guarantees and lack of sync between audio and
636// video, a frontend can selectively disallow this interface based on
637// internal configuration. A core using this interface must also
638// implement the "normal" audio interface.
639//
640// A libretro core using SET_AUDIO_CALLBACK should also make use of
641// SET_FRAME_TIME_CALLBACK.
642pub const ENVIRONMENT_SET_AUDIO_CALLBACK: libc::c_uint = 22;
643
644// const struct FrameTimeCallback * --
645// Lets the core know how much time has passed since last
646// invocation of retro_run().
647// The frontend can tamper with the timing to fake fast-forward,
648// slow-motion, frame stepping, etc.
649// In this case the delta time will use the reference value
650// in frame_time_callback..
651pub const ENVIRONMENT_SET_FRAME_TIME_CALLBACK: libc::c_uint = 21;
652
653// struct RumbleInterface * --
654// Gets an interface which is used by a libretro core to set
655// state of rumble motors in controllers.
656// A strong and weak motor is supported, and they can be
657// controlled indepedently.
658pub const ENVIRONMENT_GET_RUMBLE_INTERFACE: libc::c_uint = 23;
659
660// uint64_t * --
661// Gets a bitmask telling which device type are expected to be
662// handled properly in a call to retro_input_state_t.
663// Devices which are not handled or recognized always return
664// 0 in retro_input_state_t.
665// Example bitmask: caps = (1 << DEVICE_JOYPAD) | (1 << DEVICE_ANALOG).
666// Should only be called in retro_run().
667pub const ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES: libc::c_uint = 24;
668
669// struct SensorInterface * --
670// Gets access to the sensor interface.
671// The purpose of this interface is to allow
672// setting state related to sensors such as polling rate,
673// enabling/disable it entirely, etc.
674// Reading sensor state is done via the normal
675// input_state_callback API.
676pub const ENVIRONMENT_GET_SENSOR_INTERFACE: libc::c_uint = 25 | ENVIRONMENT_EXPERIMENTAL;
677
678// struct CameraCallback * --
679// Gets an interface to a video camera driver.
680// A libretro core can use this interface to get access to a
681// video camera.
682// New video frames are delivered in a callback in same
683// thread as retro_run().
684//
685// GET_CAMERA_INTERFACE should be called in retro_load_game().
686//
687// Depending on the camera implementation used, camera frames
688// will be delivered as a raw framebuffer,
689// or as an OpenGL texture directly.
690//
691// The core has to tell the frontend here which types of
692// buffers can be handled properly.
693// An OpenGL texture can only be handled when using a
694// libretro GL core (SET_HW_RENDER).
695// It is recommended to use a libretro GL core when
696// using camera interface.
697//
698// The camera is not started automatically. The retrieved start/stop
699// functions must be used to explicitly
700// start and stop the camera driver.
701//
702pub const ENVIRONMENT_GET_CAMERA_INTERFACE: libc::c_uint = 26 | ENVIRONMENT_EXPERIMENTAL;
703
704// struct LogCallback * --
705// Gets an interface for logging. This is useful for
706// logging in a cross-platform way
707// as certain platforms cannot use use stderr for logging.
708// It also allows the frontend to
709// show logging information in a more suitable way.
710// If this interface is not used, libretro cores should
711// log to stderr as desired.
712pub const ENVIRONMENT_GET_LOG_INTERFACE: libc::c_uint = 27;
713
714// struct PerfCallback * --
715// Gets an interface for performance counters. This is useful
716// for performance logging in a cross-platform way and for detecting
717// architecture-specific features, such as SIMD support.
718pub const ENVIRONMENT_GET_PERF_INTERFACE: libc::c_uint = 28;
719
720// struct LocationCallback * --
721// Gets access to the location interface.
722// The purpose of this interface is to be able to retrieve
723// location-based information from the host device,
724// such as current latitude / longitude.
725pub const ENVIRONMENT_GET_LOCATION_INTERFACE: libc::c_uint = 29;
726
727// const char ** --
728// Returns the "core assets" directory of the frontend.
729// This directory can be used to store specific assets that the
730// core relies upon, such as art assets,
731// input data, etc etc.
732// The returned value can be NULL.
733// If so, no such directory is defined,
734// and it's up to the implementation to find a suitable directory.
735pub const ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY: libc::c_uint = 30;
736
737// const char ** --
738// Returns the "save" directory of the frontend.
739// This directory can be used to store SRAM, memory cards,
740// high scores, etc, if the libretro core
741// cannot use the regular memory interface (retro_get_memory_data()).
742//
743// NOTE: libretro cores used to check GET_SYSTEM_DIRECTORY for
744// similar things before.
745// They should still check GET_SYSTEM_DIRECTORY if they want to
746// be backwards compatible.
747// The path here can be NULL. It should only be non-NULL if the
748// frontend user has set a specific save path.
749pub const ENVIRONMENT_GET_SAVE_DIRECTORY: libc::c_uint = 31;
750
751// const struct SystemAvInfo * --
752// Sets a new av_info structure. This can only be called from
753// within retro_run().
754// This should *only* be used if the core is completely altering the
755// internal resolutions, aspect ratios, timings, sampling rate, etc.
756// Calling this can require a full reinitialization of video/audio
757// drivers in the frontend, so it is important to call it very sparingly,
758// and usually only with the users explicit consent.
759//
760// An eventual driver reinitialize will happen so that video and
761// audio callbacks happening after this call within the same retro_run()
762// call will target the newly initialized driver.
763//
764// This callback makes it possible to support configurable resolutions
765// in games, which can be useful to avoid setting the "worst case" in max_width/max_height.
766//
767// *** HIGHLY RECOMMENDED*** Do not call this callback every time
768// resolution changes in an emulator core if it's
769// expected to be a temporary change, for the reasons of possible
770// driver reinitialization.
771// This call is not a free pass for not trying to provide
772// correct values in retro_get_system_av_info(). If you need to change
773// things like aspect ratio or nominal width/height,
774// use ENVIRONMENT_SET_GEOMETRY, which is a softer variant
775// of SET_SYSTEM_AV_INFO.
776//
777// If this returns false, the frontend does not acknowledge a
778// changed av_info struct.
779pub const ENVIRONMENT_SET_SYSTEM_AV_INFO: libc::c_uint = 32;
780
781// const struct GetProcAddressInterface * --
782// Allows a libretro core to announce support for the
783// get_proc_address() interface.
784// This interface allows for a standard way to extend libretro where
785// use of environment calls are too indirect,
786// e.g. for cases where the frontend wants to call directly into the core.
787//
788// If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK
789// ** MUST** be called from within retro_set_environment().
790pub const ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK: libc::c_uint = 33;
791
792// const struct SubsystemInfo * --
793// This environment call introduces the concept of libretro "subsystems".
794// A subsystem is a variant of a libretro core which supports
795// different kinds of games.
796// The purpose of this is to support e.g. emulators which might
797// have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo.
798// It can also be used to pick among subsystems in an explicit way
799// if the libretro implementation is a multi-system emulator itself.
800//
801// Loading a game via a subsystem is done with retro_load_game_special(),
802// and this environment call allows a libretro core to expose which
803// subsystems are supported for use with retro_load_game_special().
804// A core passes an array of retro_game_special_info which is terminated
805// with a zeroed out retro_game_special_info struct.
806//
807// If a core wants to use this functionality, SET_SUBSYSTEM_INFO
808// ** MUST** be called from within retro_set_environment().
809pub const ENVIRONMENT_SET_SUBSYSTEM_INFO: libc::c_uint = 34;
810
811// const struct ControllerInfo * --
812// This environment call lets a libretro core tell the frontend
813// which controller types are recognized in calls to
814// retro_set_controller_port_device().
815//
816// Some emulators such as Super Nintendo
817// support multiple lightgun types which must be specifically
818// selected from.
819// It is therefore sometimes necessary for a frontend to be able
820// to tell the core about a special kind of input device which is
821// not covered by the libretro input API.
822//
823// In order for a frontend to understand the workings of an input device,
824// it must be a specialized type
825// of the generic device types already defined in the libretro API.
826//
827// Which devices are supported can vary per input port.
828// The core must pass an array of const struct ControllerInfo which
829// is terminated with a blanked out struct. Each element of the struct
830// corresponds to an ascending port index to
831// retro_set_controller_port_device().
832// Even if special device types are set in the libretro core,
833// libretro should only poll input based on the base input device types.
834pub const ENVIRONMENT_SET_CONTROLLER_INFO: libc::c_uint = 35;
835
836// const struct MemoryMap * --
837// This environment call lets a libretro core tell the frontend
838// about the memory maps this core emulates.
839// This can be used to implement, for example, cheats in a core-agnostic way.
840//
841// Should only be used by emulators; it doesn't make much sense for
842// anything else.
843// It is recommended to expose all relevant pointers through
844// retro_get_memory_* as well.
845//
846// Can be called from retro_init and retro_load_game.
847pub const ENVIRONMENT_SET_MEMORY_MAPS: libc::c_uint = 36 | ENVIRONMENT_EXPERIMENTAL;
848
849// const struct GameGeometry * --
850// This environment call is similar to SET_SYSTEM_AV_INFO for changing
851// video parameters, but provides a guarantee that drivers will not be
852// reinitialized.
853// This can only be called from within retro_run().
854//
855// The purpose of this call is to allow a core to alter nominal
856// width/heights as well as aspect ratios on-the-fly, which can be
857// useful for some emulators to change in run-time.
858//
859// max_width/max_height arguments are ignored and cannot be changed
860// with this call as this could potentially require a reinitialization or a
861// non-constant time operation.
862// If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required.
863//
864// A frontend must guarantee that this environment call completes in
865// constant time.
866pub const ENVIRONMENT_SET_GEOMETRY: libc::c_uint = 37;
867
868// const char **
869// Returns the specified username of the frontend, if specified by the user.
870// This username can be used as a nickname for a core that has online facilities
871// or any other mode where personalization of the user is desirable.
872// The returned value can be NULL.
873// If this environ callback is used by a core that requires a valid username,
874// a default username should be specified by the core.
875pub const ENVIRONMENT_GET_USERNAME: libc::c_uint = 38;
876
877// unsigned * --
878// Returns the specified language of the frontend, if specified by the user.
879// It can be used by the core for localization purposes.
880pub const ENVIRONMENT_GET_LANGUAGE: libc::c_uint = 39;
881
882// struct Framebuffer * --
883// Returns a preallocated framebuffer which the core can use for rendering
884// the frame into when not using SET_HW_RENDER.
885// The framebuffer returned from this call must not be used
886// after the current call to retro_run() returns.
887//
888// The goal of this call is to allow zero-copy behavior where a core
889// can render directly into video memory, avoiding extra bandwidth cost by copying
890// memory from core to video memory.
891//
892// If this call succeeds and the core renders into it,
893// the framebuffer pointer and pitch can be passed to retro_video_refresh_t.
894// If the buffer from GET_CURRENT_SOFTWARE_FRAMEBUFFER is to be used,
895// the core must pass the exact
896// same pointer as returned by GET_CURRENT_SOFTWARE_FRAMEBUFFER;
897// i.e. passing a pointer which is offset from the
898// buffer is undefined. The width, height and pitch parameters
899// must also match exactly to the values obtained from GET_CURRENT_SOFTWARE_FRAMEBUFFER.
900//
901// It is possible for a frontend to return a different pixel format
902// than the one used in SET_PIXEL_FORMAT. This can happen if the frontend
903// needs to perform conversion.
904//
905// It is still valid for a core to render to a different buffer
906// even if GET_CURRENT_SOFTWARE_FRAMEBUFFER succeeds.
907//
908// A frontend must make sure that the pointer obtained from this function is
909// writeable (and readable).
910pub const ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER: libc::c_uint =
911 40 | ENVIRONMENT_EXPERIMENTAL;
912
913define_enum! {
914 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
915 #[repr(C)]
916 pub enum HwRenderInterfaceType {
917 Vulkan = 0,
918 }
919}
920
921// Base struct. All retro_hw_render_interface_* types
922// contain at least these fields.
923#[derive(Clone, PartialEq, Eq, Debug)]
924#[repr(C)]
925pub struct HwRenderInterface {
926 // HwRenderInterfaceType
927 pub interface_type: libc::c_uint,
928 pub interface_version: libc::c_uint,
929}
930
931// const struct HwRenderInterface ** --
932// Returns an API specific rendering interface for accessing API specific data.
933// Not all HW rendering APIs support or need this.
934// The contents of the returned pointer is specific to the rendering API
935// being used. See the various headers like libretro_vulkan.h, etc.
936//
937// GET_HW_RENDER_INTERFACE cannot be called before context_reset has been called.
938// Similarly, after context_destroyed callback returns,
939// the contents of the HW_RENDER_INTERFACE are invalidated.
940pub const ENVIRONMENT_GET_HW_RENDER_INTERFACE: libc::c_uint = 41 | ENVIRONMENT_EXPERIMENTAL;
941
942pub const MEMDESC_CONST: libc::c_uint = 1 << 0; // The frontend will never change this memory area once retro_load_game has returned.
943pub const MEMDESC_BIGENDIAN: libc::c_uint = 1 << 1; // The memory area contains big endian data. Default is little endian.
944pub const MEMDESC_ALIGN_2: libc::c_uint = 1 << 16; // All memory access in this area is aligned to their own size, or 2, whichever is smaller.
945pub const MEMDESC_ALIGN_4: libc::c_uint = 2 << 16;
946pub const MEMDESC_ALIGN_8: libc::c_uint = 3 << 16;
947pub const MEMDESC_MINSIZE_2: libc::c_uint = 1 << 24; // All memory in this region is accessed at least 2 bytes at the time.
948pub const MEMDESC_MINSIZE_4: libc::c_uint = 2 << 24;
949pub const MEMDESC_MINSIZE_8: libc::c_uint = 3 << 24;
950
951#[derive(Clone, Debug)]
952#[repr(C)]
953pub struct MemoryDescriptor {
954 pub flags: u64,
955
956 // Pointer to the start of the relevant ROM or RAM chip.
957 // It's strongly recommended to use 'offset' if possible, rather than
958 // doing math on the pointer.
959 //
960 // If the same byte is mapped my multiple descriptors, their descriptors
961 // must have the same pointer.
962 // If 'start' does not point to the first byte in the pointer, put the
963 // difference in 'offset' instead.
964 //
965 // May be NULL if there's nothing usable here (e.g. hardware registers and
966 // open bus). No flags should be set if the pointer is NULL.
967 // It's recommended to minimize the number of descriptors if possible,
968 // but not mandatory.
969 pub ptr: *mut libc::c_void,
970 pub offset: libc::size_t,
971
972 // This is the location in the emulated address space
973 // where the mapping starts.
974 pub start: libc::size_t,
975
976 // Which bits must be same as in 'start' for this mapping to apply.
977 // The first memory descriptor to claim a certain byte is the one
978 // that applies.
979 // A bit which is set in 'start' must also be set in this.
980 // Can be zero, in which case each byte is assumed mapped exactly once.
981 // In this case, 'len' must be a power of two.
982 pub select: libc::size_t,
983
984 // If this is nonzero, the set bits are assumed not connected to the
985 // memory chip's address pins.
986 pub disconnect: libc::size_t,
987
988 // This one tells the size of the current memory area.
989 // If, after start+disconnect are applied, the address is higher than
990 // this, the highest bit of the address is cleared.
991 //
992 // If the address is still too high, the next highest bit is cleared.
993 // Can be zero, in which case it's assumed to be infinite (as limited
994 // by 'select' and 'disconnect').
995 pub len: libc::size_t,
996
997 // To go from emulated address to physical address, the following
998 // order applies:
999 // Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'.
1000 //
1001 // The address space name must consist of only a-zA-Z0-9_-,
1002 // should be as short as feasible (maximum length is 8 plus the NUL),
1003 // and may not be any other address space plus one or more 0-9A-F
1004 // at the end.
1005 // However, multiple memory descriptors for the same address space is
1006 // allowed, and the address space name can be empty. NULL is treated
1007 // as empty.
1008 //
1009 // Address space names are case sensitive, but avoid lowercase if possible.
1010 // The same pointer may exist in multiple address spaces.
1011 //
1012 // Examples:
1013 // blank+blank - valid (multiple things may be mapped in the same namespace)
1014 // 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace)
1015 // 'A'+'B' - valid (neither is a prefix of each other)
1016 // 'S'+blank - valid ('S' is not in 0-9A-F)
1017 // 'a'+blank - valid ('a' is not in 0-9A-F)
1018 // 'a'+'A' - valid (neither is a prefix of each other)
1019 // 'AR'+blank - valid ('R' is not in 0-9A-F)
1020 // 'ARB'+blank - valid (the B can't be part of the address either, because
1021 // there is no namespace 'AR')
1022 // blank+'B' - not valid, because it's ambigous which address space B1234
1023 // would refer to.
1024 // The length can't be used for that purpose; the frontend may want
1025 // to append arbitrary data to an address, without a separator.
1026 pub addrspace: *const libc::c_char,
1027}
1028
1029// The frontend may use the largest value of 'start'+'select' in a
1030// certain namespace to infer the size of the address space.
1031//
1032// If the address space is larger than that, a mapping with .ptr=NULL
1033// should be at the end of the array, with .select set to all ones for
1034// as long as the address space is big.
1035//
1036// Sample descriptors (minus .ptr, and MEMFLAG_ on the flags):
1037// SNES WRAM:
1038// .start=0x7E0000, .len=0x20000
1039// (Note that this must be mapped before the ROM in most cases; some of the
1040// ROM mappers
1041// try to claim $7E0000, or at least $7E8000.)
1042// SNES SPC700 RAM:
1043// .addrspace="S", .len=0x10000
1044// SNES WRAM mirrors:
1045// .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000
1046// .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000
1047// SNES WRAM mirrors, alternate equivalent descriptor:
1048// .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF
1049// (Various similar constructions can be created by combining parts of
1050// the above two.)
1051// SNES LoROM (512KB, mirrored a couple of times):
1052// .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024
1053// .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024
1054// SNES HiROM (4MB):
1055// .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024
1056// .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024
1057// SNES ExHiROM (8MB):
1058// .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024
1059// .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024
1060// .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024
1061// .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024
1062// Clarify the size of the address space:
1063// .ptr=NULL, .select=0xFFFFFF
1064// .len can be implied by .select in many of them, but was included for clarity.
1065
1066#[derive(Clone, Debug)]
1067#[repr(C)]
1068pub struct MemoryMap {
1069 pub descriptors: *const MemoryDescriptor,
1070 pub num_descriptors: libc::c_uint,
1071}
1072
1073#[derive(Clone, Debug)]
1074#[repr(C)]
1075pub struct ControllerDescription {
1076 // Human-readable description of the controller. Even if using a generic
1077 // input device type, this can be set to the particular device type the
1078 // core uses.
1079 pub desc: *const libc::c_char,
1080
1081 // Device type passed to retro_set_controller_port_device(). If the device
1082 // type is a sub-class of a generic input device type, use the
1083 // DEVICE_SUBCLASS macro to create an ID.
1084 //
1085 // E.g. DEVICE_SUBCLASS(DEVICE_JOYPAD, 1).
1086 pub id: libc::c_uint,
1087}
1088
1089#[derive(Clone, Debug)]
1090#[repr(C)]
1091pub struct ControllerInfo {
1092 pub types: *const ControllerDescription,
1093 pub num_types: libc::c_uint,
1094}
1095
1096#[derive(Clone, Debug)]
1097#[repr(C)]
1098pub struct SubsystemMemoryInfo {
1099 // The extension associated with a memory type, e.g. "psram".
1100 pub extension: *const libc::c_char,
1101
1102 // The memory type for retro_get_memory(). This should be at
1103 // least 0x100 to avoid conflict with standardized
1104 // libretro memory types.
1105 pub kind: libc::c_uint,
1106}
1107
1108#[derive(Clone, Debug)]
1109#[repr(C)]
1110pub struct SubsystemRomInfo {
1111 // Describes what the content is (SGB BIOS, GB ROM, etc).
1112 pub desc: *const libc::c_char,
1113
1114 // Same definition as retro_get_system_info().
1115 pub valid_extensions: *const libc::c_char,
1116
1117 // Same definition as retro_get_system_info().
1118 pub need_fullpath: bool,
1119
1120 // Same definition as retro_get_system_info().
1121 pub block_extract: bool,
1122
1123 // This is set if the content is required to load a game.
1124 // If this is set to false, a zeroed-out retro_game_info can be passed.
1125 pub required: bool,
1126
1127 // Content can have multiple associated persistent
1128 // memory types (retro_get_memory()).
1129 pub memory: *const SubsystemMemoryInfo,
1130 pub num_memory: libc::c_uint,
1131}
1132
1133#[derive(Clone, Debug)]
1134#[repr(C)]
1135pub struct SubsystemInfo {
1136 // Human-readable string of the subsystem type, e.g. "Super GameBoy"
1137 pub desc: *const libc::c_char,
1138
1139 // A computer friendly short string identifier for the subsystem type.
1140 // This name must be [a-z].
1141 // E.g. if desc is "Super GameBoy", this can be "sgb".
1142 // This identifier can be used for command-line interfaces, etc.
1143 //
1144 pub ident: *const libc::c_char,
1145
1146 // Infos for each content file. The first entry is assumed to be the
1147 // "most significant" content for frontend purposes.
1148 // E.g. with Super GameBoy, the first content should be the GameBoy ROM,
1149 // as it is the most "significant" content to a user.
1150 // If a frontend creates new file paths based on the content used
1151 // (e.g. savestates), it should use the path for the first ROM to do so.
1152 pub roms: *const SubsystemRomInfo,
1153
1154 // Number of content files associated with a subsystem.
1155 pub num_roms: libc::c_uint,
1156
1157 // The type passed to retro_load_game_special().
1158 pub id: libc::c_uint,
1159}
1160
1161pub type ProcAddressFn = unsafe extern "C" fn();
1162
1163// libretro API extension functions:
1164// (None here so far).
1165//
1166// Get a symbol from a libretro core.
1167// Cores should only return symbols which are actual
1168// extensions to the libretro API.
1169//
1170// Frontends should not use this to obtain symbols to standard
1171// libretro entry points (static linking or dlsym).
1172//
1173// The symbol name must be equal to the function name,
1174// e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo".
1175// The returned function pointer must be cast to the corresponding type.
1176//
1177pub type GetProcAddressFn = unsafe extern "C" fn(sym: *const libc::c_char) -> ProcAddressFn;
1178
1179#[derive(Clone, Debug)]
1180#[repr(C)]
1181pub struct GetProcAddressInterface {
1182 pub get_proc_address: GetProcAddressFn,
1183}
1184
1185define_enum! {
1186 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1187 #[repr(C)]
1188 pub enum LogLevel {
1189 Debug = 0,
1190 Info = 1,
1191 Warn = 2,
1192 Error = 3,
1193 }
1194}
1195
1196// Logging function. Takes log level argument as well.
1197pub type LogPrintfFn = unsafe extern "C" fn(level: LogLevel, fmt: *const libc::c_char, args: ...);
1198
1199#[derive(Clone, Debug)]
1200#[repr(C)]
1201pub struct LogCallback {
1202 pub log: LogPrintfFn,
1203}
1204
1205// Performance related functions
1206
1207// ID values for SIMD CPU features
1208pub const SIMD_SSE: libc::c_uint = 1 << 0;
1209pub const SIMD_SSE2: libc::c_uint = 1 << 1;
1210pub const SIMD_VMX: libc::c_uint = 1 << 2;
1211pub const SIMD_VMX128: libc::c_uint = 1 << 3;
1212pub const SIMD_AVX: libc::c_uint = 1 << 4;
1213pub const SIMD_NEON: libc::c_uint = 1 << 5;
1214pub const SIMD_SSE3: libc::c_uint = 1 << 6;
1215pub const SIMD_SSSE3: libc::c_uint = 1 << 7;
1216pub const SIMD_MMX: libc::c_uint = 1 << 8;
1217pub const SIMD_MMXEXT: libc::c_uint = 1 << 9;
1218pub const SIMD_SSE4: libc::c_uint = 1 << 10;
1219pub const SIMD_SSE42: libc::c_uint = 1 << 11;
1220pub const SIMD_AVX2: libc::c_uint = 1 << 12;
1221pub const SIMD_VFPU: libc::c_uint = 1 << 13;
1222pub const SIMD_PS: libc::c_uint = 1 << 14;
1223pub const SIMD_AES: libc::c_uint = 1 << 15;
1224pub const SIMD_VFPV3: libc::c_uint = 1 << 16;
1225pub const SIMD_VFPV4: libc::c_uint = 1 << 17;
1226pub const SIMD_POPCNT: libc::c_uint = 1 << 18;
1227pub const SIMD_MOVBE: libc::c_uint = 1 << 19;
1228
1229pub type PerfTick = u64;
1230pub type Time = i64;
1231
1232#[derive(Clone, Debug)]
1233#[repr(C)]
1234pub struct PerfCounter {
1235 pub ident: *const libc::c_char,
1236 pub start: PerfTick,
1237 pub total: PerfTick,
1238 pub call_cnt: PerfTick,
1239
1240 pub registered: bool,
1241}
1242
1243// Returns current time in microseconds.
1244// Tries to use the most accurate timer available.
1245pub type PerfGetTimeUsecFn = unsafe extern "C" fn() -> Time;
1246
1247// A simple counter. Usually nanoseconds, but can also be CPU cycles.
1248// Can be used directly if desired (when creating a more sophisticated
1249// performance counter system).
1250pub type PerfGetCounterFn = unsafe extern "C" fn() -> PerfTick;
1251
1252// Returns a bit-mask of detected CPU features (SIMD_*).
1253pub type GetCpuFeaturesFn = unsafe extern "C" fn() -> u64;
1254
1255// Asks frontend to log and/or display the state of performance counters.
1256// Performance counters can always be poked into manually as well.
1257pub type PerfLogFn = unsafe extern "C" fn();
1258
1259// Register a performance counter.
1260// ident field must be set with a discrete value and other values in
1261// retro_perf_counter must be 0.
1262// Registering can be called multiple times. To avoid calling to
1263// frontend redundantly, you can check registered field first.
1264pub type PerfRegisterFn = unsafe extern "C" fn(counter: *mut PerfCounter);
1265
1266// Starts a registered counter.
1267pub type PerfStartFn = unsafe extern "C" fn(counter: *mut PerfCounter);
1268
1269// Stops a registered counter.
1270pub type PerfStopFn = unsafe extern "C" fn(counter: *mut PerfCounter);
1271
1272// For convenience it can be useful to wrap register, start and stop in macros.
1273// E.g.:
1274// #ifdef LOG_PERFORMANCE
1275// #define PERFORMANCE_INIT(perf_cb, name) static struct PerfCounter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
1276// #define PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
1277// #define PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
1278// #else
1279// ... Blank macros ...
1280// #endif
1281//
1282// These can then be used mid-functions around code snippets.
1283//
1284// extern struct PerfCallback perf_cb; * Somewhere in the core.
1285//
1286// void do_some_heavy_work(void)
1287// {
1288// PERFORMANCE_INIT(cb, work_1;
1289// PERFORMANCE_START(cb, work_1);
1290// heavy_work_1();
1291// PERFORMANCE_STOP(cb, work_1);
1292//
1293// PERFORMANCE_INIT(cb, work_2);
1294// PERFORMANCE_START(cb, work_2);
1295// heavy_work_2();
1296// PERFORMANCE_STOP(cb, work_2);
1297// }
1298//
1299// void retro_deinit(void)
1300// {
1301// perf_cb.perf_log(); * Log all perf counters here for example.
1302// }
1303//
1304
1305#[derive(Clone, Debug)]
1306#[repr(C)]
1307pub struct PerfCallback {
1308 pub get_time_usec: PerfGetTimeUsecFn,
1309 pub get_cpu_features: GetCpuFeaturesFn,
1310
1311 pub get_perf_counter: PerfGetCounterFn,
1312 pub perf_register: PerfRegisterFn,
1313 pub perf_start: PerfStartFn,
1314 pub perf_stop: PerfStopFn,
1315 pub perf_log: PerfLogFn,
1316}
1317
1318define_enum! {
1319 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1320 #[repr(C)]
1321 pub enum SensorAction {
1322 AccelerometerEnable = 0,
1323 AccelerometerDisable = 1,
1324 }
1325}
1326
1327// ID values for SENSOR types.
1328pub const SENSOR_ACCELEROMETER_X: libc::c_uint = 0;
1329pub const SENSOR_ACCELEROMETER_Y: libc::c_uint = 1;
1330pub const SENSOR_ACCELEROMETER_Z: libc::c_uint = 2;
1331
1332pub type SetSensorStateFn =
1333 unsafe extern "C" fn(port: libc::c_uint, action: SensorAction, rate: libc::c_uint) -> bool;
1334
1335pub type SensorGetInputFn = unsafe extern "C" fn(port: libc::c_uint, id: libc::c_uint) -> f32;
1336
1337#[derive(Clone, Debug)]
1338#[repr(C)]
1339pub struct SensorInterface {
1340 pub set_sensor_state: SetSensorStateFn,
1341 pub get_sensor_input: SensorGetInputFn,
1342}
1343
1344define_enum! {
1345 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1346 #[repr(C)]
1347 pub enum CameraBuffer {
1348 OpenGLTexture = 0,
1349 RawFramebuffer = 1,
1350 }
1351}
1352
1353// Starts the camera driver. Can only be called in retro_run().
1354pub type CameraStartFn = unsafe extern "C" fn() -> bool;
1355
1356// Stops the camera driver. Can only be called in retro_run().
1357pub type CameraStopFn = unsafe extern "C" fn();
1358
1359// Callback which signals when the camera driver is initialized
1360// and/or deinitialized.
1361// retro_camera_start_t can be called in initialized callback.
1362pub type CameraLifetimeStatusFn = unsafe extern "C" fn();
1363
1364// A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
1365// Width, height and pitch are similar to retro_video_refresh_t.
1366// First pixel is top-left origin.
1367pub type CameraFrameRawFramebufferFn = unsafe extern "C" fn(
1368 buffer: *const u32,
1369 width: libc::c_uint,
1370 height: libc::c_uint,
1371 pitch: libc::size_t,
1372);
1373
1374// A callback for when OpenGL textures are used.
1375//
1376// texture_id is a texture owned by camera driver.
1377// Its state or content should be considered immutable, except for things like
1378// texture filtering and clamping.
1379//
1380// texture_target is the texture target for the GL texture.
1381// These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly
1382// more depending on extensions.
1383//
1384// affine points to a packed 3x3 column-major matrix used to apply an affine
1385// transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
1386// After transform, normalized texture coord (0, 0) should be bottom-left
1387// and (1, 1) should be top-right (or (width, height) for RECTANGLE).
1388//
1389// GL-specific typedefs are avoided here to avoid relying on gl.h in
1390// the API definition.
1391pub type CameraFrameOpenglTextureFn = unsafe extern "C" fn(
1392 texture_id: libc::c_uint,
1393 texture_target: libc::c_uint,
1394 affine: *const f32,
1395);
1396
1397#[derive(Clone, Debug)]
1398#[repr(C)]
1399pub struct CameraCallback {
1400 // Set by libretro core.
1401 // Example bitmask: caps = (1 << CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << CAMERA_BUFFER_RAW_FRAMEBUFFER).
1402 pub caps: u64,
1403
1404 // Desired resolution for camera. Is only used as a hint.
1405 pub width: libc::c_uint,
1406 pub height: libc::c_uint,
1407
1408 // Set by frontend.
1409 pub start: CameraStartFn,
1410 pub stop: CameraStopFn,
1411
1412 // Set by libretro core if raw framebuffer callbacks will be used.
1413 pub frame_raw_framebuffer: CameraFrameRawFramebufferFn,
1414
1415 // Set by libretro core if OpenGL texture callbacks will be used.
1416 pub frame_opengl_texture: CameraFrameOpenglTextureFn,
1417
1418 // Set by libretro core. Called after camera driver is initialized and
1419 // ready to be started.
1420 //
1421 // Can be NULL, in which this callback is not called.
1422 pub initialized: CameraLifetimeStatusFn,
1423
1424 // Set by libretro core. Called right before camera driver is
1425 // deinitialized.
1426 //
1427 // Can be NULL, in which this callback is not called.
1428 pub deinitialized: CameraLifetimeStatusFn,
1429}
1430
1431// Sets the interval of time and/or distance at which to update/poll
1432// location-based data.
1433//
1434// To ensure compatibility with all location-based implementations,
1435// values for both interval_ms and interval_distance should be provided.
1436//
1437// interval_ms is the interval expressed in milliseconds.
1438// interval_distance is the distance interval expressed in meters.
1439pub type LocationSetIntervalFn =
1440 unsafe extern "C" fn(interval_ms: libc::c_uint, interval_distance: libc::c_uint);
1441
1442// Start location services. The device will start listening for changes to the
1443// current location at regular intervals (which are defined with
1444// retro_location_set_interval_t).
1445pub type LocationStartFn = unsafe extern "C" fn() -> bool;
1446
1447// Stop location services. The device will stop listening for changes
1448// to the current location.
1449pub type LocationStopFn = unsafe extern "C" fn();
1450
1451// Get the position of the current location. Will set parameters to
1452// 0 if no new location update has happened since the last time.
1453pub type LocationGetPositionFn = unsafe extern "C" fn(
1454 lat: *mut f64,
1455 lon: *mut f64,
1456 horiz_accuracy: *mut f64,
1457 vert_accuracy: *mut f64,
1458) -> bool;
1459
1460// Callback which signals when the location driver is initialized
1461// and/or deinitialized.
1462//
1463// retro_location_start_t can be called in initialized callback.
1464pub type LocationLifetimeStatusFn = unsafe extern "C" fn();
1465
1466#[derive(Clone, Debug)]
1467#[repr(C)]
1468pub struct LocationCallback {
1469 pub start: LocationStartFn,
1470 pub stop: LocationStopFn,
1471 pub get_position: LocationGetPositionFn,
1472 pub set_interval: LocationSetIntervalFn,
1473
1474 pub initialized: LocationLifetimeStatusFn,
1475 pub deinitialized: LocationLifetimeStatusFn,
1476}
1477
1478define_enum! {
1479 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1480 #[repr(C)]
1481 pub enum RumbleEffect {
1482 Strong = 0,
1483 Weak = 1,
1484 }
1485}
1486
1487// Sets rumble state for joypad plugged in port 'port'.
1488// Rumble effects are controlled independently,
1489// and setting e.g. strong rumble does not override weak rumble.
1490// Strength has a range of [0, 0xffff].
1491//
1492// Returns true if rumble state request was honored.
1493// Calling this before first retro_run() is likely to return false.
1494pub type SetRumbleStateFn =
1495 unsafe extern "C" fn(port: libc::c_uint, effect: RumbleEffect, strength: u16) -> bool;
1496
1497#[derive(Clone, Debug)]
1498#[repr(C)]
1499pub struct RumbleInterface {
1500 pub set_rumble_state: SetRumbleStateFn,
1501}
1502
1503// Notifies libretro that audio data should be written.
1504pub type AudioCallbackFn = unsafe extern "C" fn();
1505
1506// True: Audio driver in frontend is active, and callback is
1507// expected to be called regularily.
1508// False: Audio driver in frontend is paused or inactive.
1509// Audio callback will not be called until set_state has been
1510// called with true.
1511//
1512// Initial state is false (inactive).
1513pub type AudioSetStateCallbackFn = unsafe extern "C" fn(enabled: bool);
1514
1515#[derive(Clone, Debug)]
1516#[repr(C)]
1517pub struct AudioCallback {
1518 pub callback: AudioCallbackFn,
1519 pub set_state: AudioSetStateCallbackFn,
1520}
1521
1522// Notifies a libretro core of time spent since last invocation
1523// of retro_run() in microseconds.
1524//
1525// It will be called right before retro_run() every frame.
1526// The frontend can tamper with timing to support cases like
1527// fast-forward, slow-motion and framestepping.
1528//
1529// In those scenarios the reference frame time value will be used.
1530pub type Usec = i64;
1531pub type FrameTimeCallbackFn = unsafe extern "C" fn(usec: Usec);
1532
1533#[derive(Clone, Debug)]
1534#[repr(C)]
1535pub struct FrameTimeCallback {
1536 pub callback: FrameTimeCallbackFn,
1537
1538 // Represents the time of one frame. It is computed as
1539 // 1000000 / fps, but the implementation will resolve the
1540 // rounding to ensure that framestepping, etc is exact.
1541 pub reference: Usec,
1542}
1543
1544// Pass this to retro_video_refresh_t if rendering to hardware.
1545// Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
1546pub const HW_FRAME_BUFFER_VALID: *const libc::c_void =
1547 -1 as libc::intptr_t as usize as *const libc::c_void;
1548
1549// Invalidates the current HW context.
1550// Any GL state is lost, and must not be deinitialized explicitly.
1551// If explicit deinitialization is desired by the libretro core,
1552// it should implement context_destroy callback.
1553// If called, all GPU resources must be reinitialized.
1554// Usually called when frontend reinits video driver.
1555// Also called first time video driver is initialized,
1556// allowing libretro core to initialize resources.
1557pub type HwContextResetFn = unsafe extern "C" fn();
1558
1559// Gets current framebuffer which is to be rendered to.
1560// Could change every frame potentially.
1561pub type HwGetCurrentFramebufferFn = unsafe extern "C" fn() -> libc::uintptr_t;
1562
1563// Get a symbol from HW context.
1564pub type HwGetProcAddressFn = unsafe extern "C" fn(sym: *const libc::c_char) -> ProcAddressFn;
1565
1566define_enum! {
1567 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1568 #[repr(C)]
1569 pub enum HwContextType {
1570 None = 0,
1571
1572 // OpenGL 2.x. Driver can choose to use latest compatibility context.
1573 OpenGL = 1,
1574 // OpenGL ES 2.0.
1575 OpenGLES2 = 2,
1576 // Modern desktop core GL context. Use version_major/
1577 // version_minor fields to set GL version.
1578 OpenGLCore = 3,
1579 // OpenGL ES 3.0
1580 OpenGLES3 = 4,
1581 // OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3,
1582 // use the corresponding enums directly.
1583 OpenGLESVersion = 5,
1584
1585 // Vulkan, see ENVIRONMENT_GET_HW_RENDER_INTERFACE.
1586 Vulkan = 6,
1587 }
1588}
1589
1590#[derive(Clone, Debug)]
1591#[repr(C)]
1592pub struct HwRenderCallback {
1593 // Which API to use. Set by libretro core. HwContextType
1594 pub context_type: libc::c_uint,
1595
1596 // Called when a context has been created or when it has been reset.
1597 // An OpenGL context is only valid after context_reset() has been called.
1598 //
1599 // When context_reset is called, OpenGL resources in the libretro
1600 // implementation are guaranteed to be invalid.
1601 //
1602 // It is possible that context_reset is called multiple times during an
1603 // application lifecycle.
1604 // If context_reset is called without any notification (context_destroy),
1605 // the OpenGL context was lost and resources should just be recreated
1606 // without any attempt to "free" old resources.
1607 pub context_reset: HwContextResetFn,
1608
1609 // Set by frontend.
1610 // TODO: This is rather obsolete. The frontend should not
1611 // be providing preallocated framebuffers.
1612 pub get_current_framebuffer: HwGetCurrentFramebufferFn,
1613
1614 // Set by frontend.
1615 pub get_proc_address: HwGetProcAddressFn,
1616
1617 // Set if render buffers should have depth component attached.
1618 // TODO: Obsolete.
1619 pub depth: bool,
1620
1621 // Set if stencil buffers should be attached.
1622 // TODO: Obsolete.
1623 pub stencil: bool,
1624
1625 // If depth and stencil are true, a packed 24/8 buffer will be added.
1626 // Only attaching stencil is invalid and will be ignored. */
1627 //
1628 // Use conventional bottom-left origin convention. If false,
1629 // standard libretro top-left origin semantics are used.
1630 // TODO: Move to GL specific interface.
1631 pub bottom_left_origin: bool,
1632
1633 // Major version number for core GL context or GLES 3.1+.
1634 pub version_major: libc::c_uint,
1635
1636 // Minor version number for core GL context or GLES 3.1+.
1637 pub version_minor: libc::c_uint,
1638
1639 // If this is true, the frontend will go very far to avoid
1640 // resetting context in scenarios like toggling fullscreen, etc.
1641 //
1642 // The reset callback might still be called in extreme situations
1643 // such as if the context is lost beyond recovery.
1644 //
1645 // For optimal stability, set this to false, and allow context to be
1646 // reset at any time.
1647 pub cache_context: bool,
1648
1649 // A callback to be called before the context is destroyed in a
1650 // controlled way by the frontend.
1651 //
1652 // OpenGL resources can be deinitialized cleanly at this step.
1653 // context_destroy can be set to NULL, in which resources will
1654 // just be destroyed without any notification.
1655 //
1656 // Even when context_destroy is non-NULL, it is possible that
1657 // context_reset is called without any destroy notification.
1658 // This happens if context is lost by external factors (such as
1659 // notified by GL_ARB_robustness).
1660 //
1661 // In this case, the context is assumed to be already dead,
1662 // and the libretro implementation must not try to free any OpenGL
1663 // resources in the subsequent context_reset.
1664 pub context_destroy: HwContextResetFn,
1665
1666 // Creates a debug context.
1667 pub debug_context: bool,
1668}
1669
1670// Callback type passed in ENVIRONMENT_SET_KEYBOARD_CALLBACK.
1671// Called by the frontend in response to keyboard events.
1672// down is set if the key is being pressed, or false if it is being released.
1673// keycode is the RETROK value of the char.
1674// character is the text character of the pressed key. (UTF-32).
1675// key_modifiers is a set of RETROKMOD values or'ed together.
1676//
1677// The pressed/keycode state can be indepedent of the character.
1678// It is also possible that multiple characters are generated from a
1679// single keypress.
1680// Keycode events should be treated separately from character events.
1681// However, when possible, the frontend should try to synchronize these.
1682// If only a character is posted, keycode should be RETROK_UNKNOWN.
1683//
1684// Similarily if only a keycode event is generated with no corresponding
1685// character, character should be 0.
1686pub type KeyboardEventFn =
1687 unsafe extern "C" fn(down: bool, keycode: libc::c_uint, character: u32, key_modifiers: u16);
1688
1689#[derive(Clone, Debug)]
1690#[repr(C)]
1691pub struct KeyboardCallback {
1692 pub callback: KeyboardEventFn,
1693}
1694
1695// Callbacks for ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
1696// Should be set for implementations which can swap out multiple disk
1697// images in runtime.
1698//
1699// If the implementation can do this automatically, it should strive to do so.
1700// However, there are cases where the user must manually do so.
1701//
1702// Overview: To swap a disk image, eject the disk image with
1703// set_eject_state(true).
1704// Set the disk index with set_image_index(index). Insert the disk again
1705// with set_eject_state(false).
1706
1707// If ejected is true, "ejects" the virtual disk tray.
1708// When ejected, the disk image index can be set.
1709pub type SetEjectStateFn = unsafe extern "C" fn(ejected: bool) -> bool;
1710
1711// Gets current eject state. The initial state is 'not ejected'.
1712pub type GetEjectStateFn = unsafe extern "C" fn() -> bool;
1713
1714// Gets current disk index. First disk is index 0.
1715// If return value is >= get_num_images(), no disk is currently inserted.
1716pub type GetImageIndexFn = unsafe extern "C" fn() -> libc::c_uint;
1717
1718// Sets image index. Can only be called when disk is ejected.
1719// The implementation supports setting "no disk" by using an
1720// index >= get_num_images().
1721pub type SetImageIndexFn = unsafe extern "C" fn(index: libc::c_uint) -> bool;
1722
1723// Gets total number of images which are available to use.
1724pub type GetNumImagesFn = unsafe extern "C" fn() -> libc::c_uint;
1725
1726// Replaces the disk image associated with index.
1727// Arguments to pass in info have same requirements as retro_load_game().
1728// Virtual disk tray must be ejected when calling this.
1729//
1730// Replacing a disk image with info = NULL will remove the disk image
1731// from the internal list.
1732// As a result, calls to get_image_index() can change.
1733//
1734// E.g. replace_image_index(1, NULL), and previous get_image_index()
1735// returned 4 before.
1736// Index 1 will be removed, and the new index is 3.
1737pub type ReplaceImageIndexFn =
1738 unsafe extern "C" fn(index: libc::c_uint, info: *const GameInfo) -> bool;
1739
1740// Adds a new valid index (get_num_images()) to the internal disk list.
1741// This will increment subsequent return values from get_num_images() by 1.
1742// This image index cannot be used until a disk image has been set
1743// with replace_image_index.
1744pub type AddImageIndexFn = unsafe extern "C" fn() -> bool;
1745
1746#[derive(Clone, Debug)]
1747#[repr(C)]
1748pub struct DiskControlCallback {
1749 pub set_eject_state: SetEjectStateFn,
1750 pub get_eject_state: GetEjectStateFn,
1751
1752 pub get_image_index: GetImageIndexFn,
1753 pub set_image_index: SetImageIndexFn,
1754 pub get_num_images: GetNumImagesFn,
1755
1756 pub replace_image_index: ReplaceImageIndexFn,
1757 pub add_image_index: AddImageIndexFn,
1758}
1759
1760define_enum! {
1761 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1762 #[repr(C)]
1763 pub enum PixelFormat {
1764 // ARGB1555, native endian.
1765 // Alpha bit has to be set to 0.
1766 // This pixel format is default for compatibility concerns only.
1767 // If a 15/16-bit pixel format is desired, consider using RGB565.
1768 ARGB1555 = 0,
1769
1770 // ARGB8888, native endian.
1771 // Alpha bits are ignored.
1772 ARGB8888 = 1,
1773
1774 // RGB565, native endian.
1775 // This pixel format is the recommended format to use if a 15/16-bit
1776 // format is desired as it is the pixel format that is typically
1777 // available on a wide range of low-power devices.
1778 //
1779 // It is also natively supported in APIs like OpenGL ES.
1780 RGB565 = 2,
1781 }
1782}
1783
1784#[derive(Clone, Debug)]
1785#[repr(C)]
1786pub struct Message {
1787 // Message to be displayed.
1788 pub msg: *const libc::c_char,
1789
1790 // Duration in frames of message.
1791 pub frames: libc::c_uint,
1792}
1793
1794// Describes how the libretro implementation maps a libretro input bind
1795// to its internal input system through a human readable string.
1796// This string can be used to better let a user configure input.
1797#[derive(Clone, Debug)]
1798#[repr(C)]
1799pub struct InputDescriptor {
1800 // Associates given parameters with a description.
1801 pub port: libc::c_uint,
1802 pub device: libc::c_uint,
1803 pub index: libc::c_uint,
1804 pub id: libc::c_uint,
1805
1806 // Human readable description for parameters.
1807 // The pointer must remain valid until
1808 // retro_unload_game() is called.
1809 pub description: *const libc::c_char,
1810}
1811
1812#[derive(Clone, Debug)]
1813#[repr(C)]
1814pub struct SystemInfo {
1815 // All pointers are owned by libretro implementation, and pointers must
1816 // remain valid until retro_deinit() is called. */
1817 //
1818 // Descriptive name of library. Should not contain any version numbers, etc.
1819 pub library_name: *const libc::c_char,
1820
1821 // Descriptive version of core.
1822 pub library_version: *const libc::c_char,
1823
1824 // A string listing probably content extensions the core will be able to load,
1825 // separated with pipe. I.e. "bin|rom|iso". Typically used for a GUI to filter out
1826 // extensions.
1827 pub valid_extensions: *const libc::c_char,
1828
1829 // If true, retro_load_game() is guaranteed to provide a valid pathname
1830 // in retro_game_info::path.
1831 // ::data and ::size are both invalid.
1832 //
1833 // If false, ::data and ::size are guaranteed to be valid, but ::path
1834 // might not be valid.
1835 //
1836 // This is typically set to true for libretro implementations that must
1837 // load from file.
1838 // Implementations should strive for setting this to false, as it allows
1839 // the frontend to perform patching, etc.
1840 pub need_fullpath: bool,
1841
1842 // If true, the frontend is not allowed to extract any archives before
1843 // loading the real content.
1844 // Necessary for certain libretro implementations that load games
1845 // from zipped archives.
1846 pub block_extract: bool,
1847}
1848
1849#[derive(Clone, Debug)]
1850#[repr(C)]
1851pub struct GameGeometry {
1852 // Nominal video width of game.
1853 pub base_width: libc::c_uint,
1854
1855 // Nominal video height of game.
1856 pub base_height: libc::c_uint,
1857
1858 // Maximum possible width of game.
1859 pub max_width: libc::c_uint,
1860
1861 // Maximum possible height of game.
1862 pub max_height: libc::c_uint,
1863
1864 // Nominal aspect ratio of game. If aspect_ratio is <= 0.0, an aspect ratio of
1865 // base_width / base_height is assumed. A frontend could override this setting, if
1866 // desired.
1867 pub aspect_ratio: f32,
1868}
1869
1870#[derive(Clone, Debug)]
1871#[repr(C)]
1872pub struct SystemTiming {
1873 // FPS of video content.
1874 pub fps: f64,
1875
1876 // Sampling rate of audio.
1877 pub sample_rate: f64,
1878}
1879
1880#[derive(Clone, Debug)]
1881#[repr(C)]
1882pub struct SystemAvInfo {
1883 pub geometry: GameGeometry,
1884 pub timing: SystemTiming,
1885}
1886
1887#[derive(Clone, Debug)]
1888#[repr(C)]
1889pub struct Variable {
1890 // Variable to query in ENVIRONMENT_GET_VARIABLE.
1891 // If NULL, obtains the complete environment string if more
1892 // complex parsing is necessary.
1893 //
1894 // The environment string is formatted as key-value pairs
1895 // delimited by semicolons as so:
1896 // "key1=value1;key2=value2;..."
1897 //
1898 pub key: *const libc::c_char,
1899
1900 // Value to be obtained. If key does not exist, it is set to NULL.
1901 pub value: *const libc::c_char,
1902}
1903
1904#[derive(Clone, Debug)]
1905#[repr(C)]
1906pub struct GameInfo {
1907 // Path to game, UTF-8 encoded. Usually used as a reference. May be NULL if rom
1908 // was loaded from stdin or similar. retro_system_info::need_fullpath guaranteed
1909 // that this path is valid.
1910 pub path: *const libc::c_char,
1911
1912 // Memory buffer of loaded game. Will be NULL if need_fullpath was set.
1913 pub data: *const libc::c_void,
1914
1915 // Size of memory buffer.
1916 pub size: libc::size_t,
1917
1918 // String of implementation specific meta-data.
1919 pub meta: *const libc::c_char,
1920}
1921
1922// The core will write to the buffer provided by retro_framebuffer::data.
1923pub const MEMORY_ACCESS_WRITE: libc::c_uint = 1 << 0;
1924
1925// The core will read from retro_framebuffer::data.
1926pub const MEMORY_ACCESS_READ: libc::c_uint = 1 << 1;
1927
1928// The memory in data is cached.
1929// If not cached, random writes and/or reading from the buffer is expected to be very slow.
1930pub const MEMORY_TYPE_CACHED: libc::c_uint = 1 << 0;
1931
1932#[derive(Clone, Debug)]
1933#[repr(C)]
1934pub struct Framebuffer {
1935 // The framebuffer which the core can render into. Set by frontend in
1936 // GET_CURRENT_SOFTWARE_FRAMEBUFFER. The initial contents of data are unspecified.
1937 pub data: *mut libc::c_void,
1938
1939 // The framebuffer width used by the core. Set by core.
1940 pub width: libc::c_uint,
1941
1942 // The framebuffer height used by the core. Set by core.
1943 pub height: libc::c_uint,
1944
1945 // The number of bytes between the beginning of a scanline, and beginning of the
1946 // next scanline. Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER.
1947 pub pitch: libc::size_t,
1948
1949 // The pixel format the core must use to render into data. This format could
1950 // differ from the format used in SET_PIXEL_FORMAT. Set by frontend in
1951 // GET_CURRENT_SOFTWARE_FRAMEBUFFER. A value from enum PixelFormat.
1952 pub format: libc::c_uint,
1953
1954 // How the core will access the memory in the framebuffer. MEMORY_ACCESS_*
1955 // flags. Set by core.
1956 pub access_flags: libc::c_uint,
1957
1958 // Flags telling core how the memory has been mapped. MEMORY_TYPE_* flags.
1959 // Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER.
1960 pub memory_flags: libc::c_uint,
1961}
1962
1963// Callbacks
1964
1965// Environment callback. Gives implementations a way of performing
1966// uncommon tasks. Extensible.
1967pub type EnvironmentFn = unsafe extern "C" fn(cmd: libc::c_uint, data: *mut libc::c_void) -> bool;
1968
1969// Render a frame. Pixel format is 15-bit 0RGB1555 native endian
1970// unless changed (see ENVIRONMENT_SET_PIXEL_FORMAT).
1971//
1972// Width and height specify dimensions of buffer.
1973// Pitch specifices length in bytes between two lines in buffer.
1974//
1975// For performance reasons, it is highly recommended to have a frame
1976// that is packed in memory, i.e. pitch == width * byte_per_pixel.
1977// Certain graphic APIs, such as OpenGL ES, do not like textures
1978// that are not packed in memory.
1979pub type VideoRefreshFn = unsafe extern "C" fn(
1980 data: *const libc::c_void,
1981 width: libc::c_uint,
1982 height: libc::c_uint,
1983 pitch: libc::size_t,
1984);
1985
1986// Renders a single audio frame. Should only be used if implementation
1987// generates a single sample at a time.
1988// Format is signed 16-bit native endian.
1989pub type AudioSampleFn = unsafe extern "C" fn(left: i16, right: i16);
1990
1991// Renders multiple audio frames in one go.
1992//
1993// One frame is defined as a sample of left and right channels, interleaved.
1994// I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
1995// Only one of the audio callbacks must ever be used.
1996pub type AudioSampleBatchFn =
1997 unsafe extern "C" fn(data: *const i16, frames: libc::size_t) -> libc::size_t;
1998
1999// Polls input.
2000pub type InputPollFn = unsafe extern "C" fn();
2001
2002// Queries for input for player 'port'. device will be masked with
2003// DEVICE_MASK.
2004//
2005// Specialization of devices such as DEVICE_JOYPAD_MULTITAP that
2006// have been set with retro_set_controller_port_device()
2007// will still use the higher level DEVICE_JOYPAD to request input.
2008pub type InputStateFn = unsafe extern "C" fn(
2009 port: libc::c_uint,
2010 device: libc::c_uint,
2011 index: libc::c_uint,
2012 id: libc::c_uint,
2013) -> i16;
2014
2015#[derive(Clone, Debug)]
2016pub struct CoreAPI {
2017 // Sets callbacks. retro_set_environment() is guaranteed to be called
2018 // before retro_init().
2019 //
2020 // The rest of the set_* functions are guaranteed to have been called
2021 // before the first call to retro_run() is made.
2022 pub retro_set_environment: unsafe extern "C" fn(callback: EnvironmentFn),
2023 pub retro_set_video_refresh: unsafe extern "C" fn(callback: VideoRefreshFn),
2024 pub retro_set_audio_sample: unsafe extern "C" fn(callback: AudioSampleFn),
2025 pub retro_set_audio_sample_batch: unsafe extern "C" fn(callback: AudioSampleBatchFn),
2026 pub retro_set_input_poll: unsafe extern "C" fn(callback: InputPollFn),
2027 pub retro_set_input_state: unsafe extern "C" fn(callback: InputStateFn),
2028
2029 // Library global initialization/deinitialization.
2030 pub retro_init: unsafe extern "C" fn(),
2031 pub retro_deinit: unsafe extern "C" fn(),
2032
2033 // Must return API_VERSION. Used to validate ABI compatibility
2034 // when the API is revised.
2035 pub retro_api_version: unsafe extern "C" fn() -> libc::c_uint,
2036
2037 // Gets statically known system info. Pointers provided in * info
2038 // must be statically allocated.
2039 // Can be called at any time, even before pub retro_init().
2040 pub retro_get_system_info: unsafe extern "C" fn(info: *mut SystemInfo),
2041
2042 // Gets information about system audio/video timings and geometry.
2043 // Can be called only after pub retro_load_game() has successfully completed.
2044 // NOTE: The implementation of this function might not initialize every
2045 // variable if needed.
2046 // E.g. geom.aspect_ratio might not be initialized if core doesn't
2047 // desire a particular aspect ratio.
2048 pub retro_get_system_av_info: unsafe extern "C" fn(info: *mut SystemAvInfo),
2049
2050 // Sets device to be used for player 'port'.
2051 // By default, DEVICE_JOYPAD is assumed to be plugged into all
2052 // available ports.
2053 // Setting a particular device type is not a guarantee that libretro cores
2054 // will only poll input based on that particular device type. It is only a
2055 // hint to the libretro core when a core cannot automatically detect the
2056 // appropriate input device type on its own. It is also relevant when a
2057 // core can change its behavior depending on device type.
2058 pub retro_set_controller_port_device:
2059 unsafe extern "C" fn(port: libc::c_uint, device: libc::c_uint),
2060
2061 // Resets the current game.
2062 pub retro_reset: unsafe extern "C" fn(),
2063
2064 // Runs the game for one video frame.
2065 // During pub retro_run(), input_poll callback must be called at least once.
2066 //
2067 // If a frame is not rendered for reasons where a game "dropped" a frame,
2068 // this still counts as a frame, and pub retro_run() should explicitly dupe
2069 // a frame if GET_CAN_DUPE returns true.
2070 // In this case, the video callback can take a NULL argument for data.
2071 pub retro_run: unsafe extern "C" fn(),
2072
2073 // Returns the amount of data the implementation requires to serialize
2074 // internal state (save states).
2075 //
2076 // Between calls to pub retro_load_game() and retro_unload_game(), the
2077 // returned size is never allowed to be larger than a previous returned
2078 // value, to ensure that the frontend can allocate a save state buffer once.
2079 pub retro_serialize_size: unsafe extern "C" fn() -> libc::size_t,
2080
2081 // Serializes internal state. If failed, or size is lower than
2082 // pub retro_serialize_size(), it should return false, true otherwise.
2083 pub retro_serialize: unsafe extern "C" fn(data: *mut libc::c_void, size: libc::size_t),
2084
2085 pub retro_unserialize:
2086 unsafe extern "C" fn(data: *const libc::c_void, size: libc::size_t) -> bool,
2087 pub retro_cheat_reset: unsafe extern "C" fn(),
2088 pub retro_cheat_set:
2089 unsafe extern "C" fn(index: libc::c_uint, enabled: bool, code: *const libc::c_char),
2090
2091 // Loads a game.
2092 pub retro_load_game: unsafe extern "C" fn(game: *const GameInfo) -> bool,
2093
2094 // Loads a "special" kind of game. Should not be used,
2095 // except in extreme cases.
2096 pub retro_load_game_special: unsafe extern "C" fn(
2097 game_type: libc::c_uint,
2098 info: *const GameInfo,
2099 num_info: libc::size_t,
2100 ) -> bool,
2101
2102 // Unloads a currently loaded game.
2103 pub retro_unload_game: unsafe extern "C" fn(),
2104
2105 // Gets region of game.
2106 pub retro_get_region: unsafe extern "C" fn() -> libc::c_uint,
2107
2108 // Gets region of memory.
2109 pub retro_get_memory_data: unsafe extern "C" fn(id: libc::c_uint) -> *mut libc::c_void,
2110 pub retro_get_memory_size: unsafe extern "C" fn(id: libc::c_uint) -> libc::size_t,
2111}