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 = (40 | ENVIRONMENT_EXPERIMENTAL);
911
912define_enum! {
913 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
914 #[repr(C)]
915 pub enum HwRenderInterfaceType {
916 Vulkan = 0,
917 }
918}
919
920// Base struct. All retro_hw_render_interface_* types
921// contain at least these fields.
922#[derive(Clone, PartialEq, Eq, Debug)]
923#[repr(C)]
924pub struct HwRenderInterface {
925 // HwRenderInterfaceType
926 pub interface_type: libc::c_uint,
927 pub interface_version: libc::c_uint,
928}
929
930// const struct HwRenderInterface ** --
931// Returns an API specific rendering interface for accessing API specific data.
932// Not all HW rendering APIs support or need this.
933// The contents of the returned pointer is specific to the rendering API
934// being used. See the various headers like libretro_vulkan.h, etc.
935//
936// GET_HW_RENDER_INTERFACE cannot be called before context_reset has been called.
937// Similarly, after context_destroyed callback returns,
938// the contents of the HW_RENDER_INTERFACE are invalidated.
939pub const ENVIRONMENT_GET_HW_RENDER_INTERFACE: libc::c_uint = (41 | ENVIRONMENT_EXPERIMENTAL);
940
941pub const MEMDESC_CONST: libc::c_uint = (1 << 0); // The frontend will never change this memory area once retro_load_game has returned.
942pub const MEMDESC_BIGENDIAN: libc::c_uint = (1 << 1); // The memory area contains big endian data. Default is little endian.
943pub 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.
944pub const MEMDESC_ALIGN_4: libc::c_uint = (2 << 16);
945pub const MEMDESC_ALIGN_8: libc::c_uint = (3 << 16);
946pub const MEMDESC_MINSIZE_2: libc::c_uint = (1 << 24); // All memory in this region is accessed at least 2 bytes at the time.
947pub const MEMDESC_MINSIZE_4: libc::c_uint = (2 << 24);
948pub const MEMDESC_MINSIZE_8: libc::c_uint = (3 << 24);
949
950#[derive(Clone, Debug)]
951#[repr(C)]
952pub struct MemoryDescriptor {
953 pub flags: u64,
954
955 // Pointer to the start of the relevant ROM or RAM chip.
956 // It's strongly recommended to use 'offset' if possible, rather than
957 // doing math on the pointer.
958 //
959 // If the same byte is mapped my multiple descriptors, their descriptors
960 // must have the same pointer.
961 // If 'start' does not point to the first byte in the pointer, put the
962 // difference in 'offset' instead.
963 //
964 // May be NULL if there's nothing usable here (e.g. hardware registers and
965 // open bus). No flags should be set if the pointer is NULL.
966 // It's recommended to minimize the number of descriptors if possible,
967 // but not mandatory.
968 pub ptr: *mut libc::c_void,
969 pub offset: libc::size_t,
970
971 // This is the location in the emulated address space
972 // where the mapping starts.
973 pub start: libc::size_t,
974
975 // Which bits must be same as in 'start' for this mapping to apply.
976 // The first memory descriptor to claim a certain byte is the one
977 // that applies.
978 // A bit which is set in 'start' must also be set in this.
979 // Can be zero, in which case each byte is assumed mapped exactly once.
980 // In this case, 'len' must be a power of two.
981 pub select: libc::size_t,
982
983 // If this is nonzero, the set bits are assumed not connected to the
984 // memory chip's address pins.
985 pub disconnect: libc::size_t,
986
987 // This one tells the size of the current memory area.
988 // If, after start+disconnect are applied, the address is higher than
989 // this, the highest bit of the address is cleared.
990 //
991 // If the address is still too high, the next highest bit is cleared.
992 // Can be zero, in which case it's assumed to be infinite (as limited
993 // by 'select' and 'disconnect').
994 pub len: libc::size_t,
995
996 // To go from emulated address to physical address, the following
997 // order applies:
998 // Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'.
999 //
1000 // The address space name must consist of only a-zA-Z0-9_-,
1001 // should be as short as feasible (maximum length is 8 plus the NUL),
1002 // and may not be any other address space plus one or more 0-9A-F
1003 // at the end.
1004 // However, multiple memory descriptors for the same address space is
1005 // allowed, and the address space name can be empty. NULL is treated
1006 // as empty.
1007 //
1008 // Address space names are case sensitive, but avoid lowercase if possible.
1009 // The same pointer may exist in multiple address spaces.
1010 //
1011 // Examples:
1012 // blank+blank - valid (multiple things may be mapped in the same namespace)
1013 // 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace)
1014 // 'A'+'B' - valid (neither is a prefix of each other)
1015 // 'S'+blank - valid ('S' is not in 0-9A-F)
1016 // 'a'+blank - valid ('a' is not in 0-9A-F)
1017 // 'a'+'A' - valid (neither is a prefix of each other)
1018 // 'AR'+blank - valid ('R' is not in 0-9A-F)
1019 // 'ARB'+blank - valid (the B can't be part of the address either, because
1020 // there is no namespace 'AR')
1021 // blank+'B' - not valid, because it's ambigous which address space B1234
1022 // would refer to.
1023 // The length can't be used for that purpose; the frontend may want
1024 // to append arbitrary data to an address, without a separator.
1025 pub addrspace: *const libc::c_char,
1026}
1027
1028// The frontend may use the largest value of 'start'+'select' in a
1029// certain namespace to infer the size of the address space.
1030//
1031// If the address space is larger than that, a mapping with .ptr=NULL
1032// should be at the end of the array, with .select set to all ones for
1033// as long as the address space is big.
1034//
1035// Sample descriptors (minus .ptr, and MEMFLAG_ on the flags):
1036// SNES WRAM:
1037// .start=0x7E0000, .len=0x20000
1038// (Note that this must be mapped before the ROM in most cases; some of the
1039// ROM mappers
1040// try to claim $7E0000, or at least $7E8000.)
1041// SNES SPC700 RAM:
1042// .addrspace="S", .len=0x10000
1043// SNES WRAM mirrors:
1044// .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000
1045// .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000
1046// SNES WRAM mirrors, alternate equivalent descriptor:
1047// .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF
1048// (Various similar constructions can be created by combining parts of
1049// the above two.)
1050// SNES LoROM (512KB, mirrored a couple of times):
1051// .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024
1052// .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024
1053// SNES HiROM (4MB):
1054// .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024
1055// .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024
1056// SNES ExHiROM (8MB):
1057// .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024
1058// .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024
1059// .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024
1060// .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024
1061// Clarify the size of the address space:
1062// .ptr=NULL, .select=0xFFFFFF
1063// .len can be implied by .select in many of them, but was included for clarity.
1064
1065#[derive(Clone, Debug)]
1066#[repr(C)]
1067pub struct MemoryMap {
1068 pub descriptors: *const MemoryDescriptor,
1069 pub num_descriptors: libc::c_uint,
1070}
1071
1072#[derive(Clone, Debug)]
1073#[repr(C)]
1074pub struct ControllerDescription {
1075 // Human-readable description of the controller. Even if using a generic
1076 // input device type, this can be set to the particular device type the
1077 // core uses.
1078 pub desc: *const libc::c_char,
1079
1080 // Device type passed to retro_set_controller_port_device(). If the device
1081 // type is a sub-class of a generic input device type, use the
1082 // DEVICE_SUBCLASS macro to create an ID.
1083 //
1084 // E.g. DEVICE_SUBCLASS(DEVICE_JOYPAD, 1).
1085 pub id: libc::c_uint,
1086}
1087
1088#[derive(Clone, Debug)]
1089#[repr(C)]
1090pub struct ControllerInfo {
1091 pub types: *const ControllerDescription,
1092 pub num_types: libc::c_uint,
1093}
1094
1095#[derive(Clone, Debug)]
1096#[repr(C)]
1097pub struct SubsystemMemoryInfo {
1098 // The extension associated with a memory type, e.g. "psram".
1099 pub extension: *const libc::c_char,
1100
1101 // The memory type for retro_get_memory(). This should be at
1102 // least 0x100 to avoid conflict with standardized
1103 // libretro memory types.
1104 pub kind: libc::c_uint,
1105}
1106
1107#[derive(Clone, Debug)]
1108#[repr(C)]
1109pub struct SubsystemRomInfo {
1110 // Describes what the content is (SGB BIOS, GB ROM, etc).
1111 pub desc: *const libc::c_char,
1112
1113 // Same definition as retro_get_system_info().
1114 pub valid_extensions: *const libc::c_char,
1115
1116 // Same definition as retro_get_system_info().
1117 pub need_fullpath: bool,
1118
1119 // Same definition as retro_get_system_info().
1120 pub block_extract: bool,
1121
1122 // This is set if the content is required to load a game.
1123 // If this is set to false, a zeroed-out retro_game_info can be passed.
1124 pub required: bool,
1125
1126 // Content can have multiple associated persistent
1127 // memory types (retro_get_memory()).
1128 pub memory: *const SubsystemMemoryInfo,
1129 pub num_memory: libc::c_uint,
1130}
1131
1132#[derive(Clone, Debug)]
1133#[repr(C)]
1134pub struct SubsystemInfo {
1135 // Human-readable string of the subsystem type, e.g. "Super GameBoy"
1136 pub desc: *const libc::c_char,
1137
1138 // A computer friendly short string identifier for the subsystem type.
1139 // This name must be [a-z].
1140 // E.g. if desc is "Super GameBoy", this can be "sgb".
1141 // This identifier can be used for command-line interfaces, etc.
1142 //
1143 pub ident: *const libc::c_char,
1144
1145 // Infos for each content file. The first entry is assumed to be the
1146 // "most significant" content for frontend purposes.
1147 // E.g. with Super GameBoy, the first content should be the GameBoy ROM,
1148 // as it is the most "significant" content to a user.
1149 // If a frontend creates new file paths based on the content used
1150 // (e.g. savestates), it should use the path for the first ROM to do so.
1151 pub roms: *const SubsystemRomInfo,
1152
1153 // Number of content files associated with a subsystem.
1154 pub num_roms: libc::c_uint,
1155
1156 // The type passed to retro_load_game_special().
1157 pub id: libc::c_uint,
1158}
1159
1160pub type ProcAddressFn = unsafe extern "C" fn();
1161
1162// libretro API extension functions:
1163// (None here so far).
1164//
1165// Get a symbol from a libretro core.
1166// Cores should only return symbols which are actual
1167// extensions to the libretro API.
1168//
1169// Frontends should not use this to obtain symbols to standard
1170// libretro entry points (static linking or dlsym).
1171//
1172// The symbol name must be equal to the function name,
1173// e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo".
1174// The returned function pointer must be cast to the corresponding type.
1175//
1176pub type GetProcAddressFn = unsafe extern "C" fn(sym: *const libc::c_char) -> ProcAddressFn;
1177
1178#[derive(Clone, Debug)]
1179#[repr(C)]
1180pub struct GetProcAddressInterface {
1181 pub get_proc_address: GetProcAddressFn,
1182}
1183
1184define_enum! {
1185 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1186 #[repr(C)]
1187 pub enum LogLevel {
1188 Debug = 0,
1189 Info = 1,
1190 Warn = 2,
1191 Error = 3,
1192 }
1193}
1194
1195// Logging function. Takes log level argument as well.
1196pub type LogPrintfFn = unsafe extern "C" fn(level: LogLevel, fmt: *const libc::c_char);
1197
1198#[derive(Clone, Debug)]
1199#[repr(C)]
1200pub struct LogCallback {
1201 pub log: LogPrintfFn,
1202}
1203
1204// Performance related functions
1205
1206// ID values for SIMD CPU features
1207pub const SIMD_SSE: libc::c_uint = (1 << 0);
1208pub const SIMD_SSE2: libc::c_uint = (1 << 1);
1209pub const SIMD_VMX: libc::c_uint = (1 << 2);
1210pub const SIMD_VMX128: libc::c_uint = (1 << 3);
1211pub const SIMD_AVX: libc::c_uint = (1 << 4);
1212pub const SIMD_NEON: libc::c_uint = (1 << 5);
1213pub const SIMD_SSE3: libc::c_uint = (1 << 6);
1214pub const SIMD_SSSE3: libc::c_uint = (1 << 7);
1215pub const SIMD_MMX: libc::c_uint = (1 << 8);
1216pub const SIMD_MMXEXT: libc::c_uint = (1 << 9);
1217pub const SIMD_SSE4: libc::c_uint = (1 << 10);
1218pub const SIMD_SSE42: libc::c_uint = (1 << 11);
1219pub const SIMD_AVX2: libc::c_uint = (1 << 12);
1220pub const SIMD_VFPU: libc::c_uint = (1 << 13);
1221pub const SIMD_PS: libc::c_uint = (1 << 14);
1222pub const SIMD_AES: libc::c_uint = (1 << 15);
1223pub const SIMD_VFPV3: libc::c_uint = (1 << 16);
1224pub const SIMD_VFPV4: libc::c_uint = (1 << 17);
1225pub const SIMD_POPCNT: libc::c_uint = (1 << 18);
1226pub const SIMD_MOVBE: libc::c_uint = (1 << 19);
1227
1228pub type PerfTick = u64;
1229pub type Time = i64;
1230
1231#[derive(Clone, Debug)]
1232#[repr(C)]
1233pub struct PerfCounter {
1234 pub ident: *const libc::c_char,
1235 pub start: PerfTick,
1236 pub total: PerfTick,
1237 pub call_cnt: PerfTick,
1238
1239 pub registered: bool,
1240}
1241
1242// Returns current time in microseconds.
1243// Tries to use the most accurate timer available.
1244pub type PerfGetTimeUsecFn = unsafe extern "C" fn() -> Time;
1245
1246// A simple counter. Usually nanoseconds, but can also be CPU cycles.
1247// Can be used directly if desired (when creating a more sophisticated
1248// performance counter system).
1249pub type PerfGetCounterFn = unsafe extern "C" fn() -> PerfTick;
1250
1251// Returns a bit-mask of detected CPU features (SIMD_*).
1252pub type GetCpuFeaturesFn = unsafe extern "C" fn() -> u64;
1253
1254// Asks frontend to log and/or display the state of performance counters.
1255// Performance counters can always be poked into manually as well.
1256pub type PerfLogFn = unsafe extern "C" fn();
1257
1258// Register a performance counter.
1259// ident field must be set with a discrete value and other values in
1260// retro_perf_counter must be 0.
1261// Registering can be called multiple times. To avoid calling to
1262// frontend redundantly, you can check registered field first.
1263pub type PerfRegisterFn = unsafe extern "C" fn(counter: *mut PerfCounter);
1264
1265// Starts a registered counter.
1266pub type PerfStartFn = unsafe extern "C" fn(counter: *mut PerfCounter);
1267
1268// Stops a registered counter.
1269pub type PerfStopFn = unsafe extern "C" fn(counter: *mut PerfCounter);
1270
1271// For convenience it can be useful to wrap register, start and stop in macros.
1272// E.g.:
1273// #ifdef LOG_PERFORMANCE
1274// #define PERFORMANCE_INIT(perf_cb, name) static struct PerfCounter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
1275// #define PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
1276// #define PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
1277// #else
1278// ... Blank macros ...
1279// #endif
1280//
1281// These can then be used mid-functions around code snippets.
1282//
1283// extern struct PerfCallback perf_cb; * Somewhere in the core.
1284//
1285// void do_some_heavy_work(void)
1286// {
1287// PERFORMANCE_INIT(cb, work_1;
1288// PERFORMANCE_START(cb, work_1);
1289// heavy_work_1();
1290// PERFORMANCE_STOP(cb, work_1);
1291//
1292// PERFORMANCE_INIT(cb, work_2);
1293// PERFORMANCE_START(cb, work_2);
1294// heavy_work_2();
1295// PERFORMANCE_STOP(cb, work_2);
1296// }
1297//
1298// void retro_deinit(void)
1299// {
1300// perf_cb.perf_log(); * Log all perf counters here for example.
1301// }
1302//
1303
1304#[derive(Clone, Debug)]
1305#[repr(C)]
1306pub struct PerfCallback {
1307 pub get_time_usec: PerfGetTimeUsecFn,
1308 pub get_cpu_features: GetCpuFeaturesFn,
1309
1310 pub get_perf_counter: PerfGetCounterFn,
1311 pub perf_register: PerfRegisterFn,
1312 pub perf_start: PerfStartFn,
1313 pub perf_stop: PerfStopFn,
1314 pub perf_log: PerfLogFn,
1315}
1316
1317define_enum! {
1318 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1319 #[repr(C)]
1320 pub enum SensorAction {
1321 AccelerometerEnable = 0,
1322 AccelerometerDisable = 1,
1323 }
1324}
1325
1326// ID values for SENSOR types.
1327pub const SENSOR_ACCELEROMETER_X: libc::c_uint = 0;
1328pub const SENSOR_ACCELEROMETER_Y: libc::c_uint = 1;
1329pub const SENSOR_ACCELEROMETER_Z: libc::c_uint = 2;
1330
1331pub type SetSensorStateFn = unsafe extern "C" fn(port: libc::c_uint, action: SensorAction, rate: libc::c_uint) -> bool;
1332
1333pub type SensorGetInputFn = unsafe extern "C" fn(port: libc::c_uint, id: libc::c_uint) -> f32;
1334
1335#[derive(Clone, Debug)]
1336#[repr(C)]
1337pub struct SensorInterface {
1338 pub set_sensor_state: SetSensorStateFn,
1339 pub get_sensor_input: SensorGetInputFn,
1340}
1341
1342define_enum! {
1343 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1344 #[repr(C)]
1345 pub enum CameraBuffer {
1346 OpenGLTexture = 0,
1347 RawFramebuffer = 1,
1348 }
1349}
1350
1351// Starts the camera driver. Can only be called in retro_run().
1352pub type CameraStartFn = unsafe extern "C" fn() -> bool;
1353
1354// Stops the camera driver. Can only be called in retro_run().
1355pub type CameraStopFn = unsafe extern "C" fn();
1356
1357// Callback which signals when the camera driver is initialized
1358// and/or deinitialized.
1359// retro_camera_start_t can be called in initialized callback.
1360pub type CameraLifetimeStatusFn = unsafe extern "C" fn();
1361
1362// A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
1363// Width, height and pitch are similar to retro_video_refresh_t.
1364// First pixel is top-left origin.
1365pub type CameraFrameRawFramebufferFn =
1366 unsafe extern "C" fn(buffer: *const u32, width: libc::c_uint, height: libc::c_uint, pitch: libc::size_t);
1367
1368// A callback for when OpenGL textures are used.
1369//
1370// texture_id is a texture owned by camera driver.
1371// Its state or content should be considered immutable, except for things like
1372// texture filtering and clamping.
1373//
1374// texture_target is the texture target for the GL texture.
1375// These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly
1376// more depending on extensions.
1377//
1378// affine points to a packed 3x3 column-major matrix used to apply an affine
1379// transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
1380// After transform, normalized texture coord (0, 0) should be bottom-left
1381// and (1, 1) should be top-right (or (width, height) for RECTANGLE).
1382//
1383// GL-specific typedefs are avoided here to avoid relying on gl.h in
1384// the API definition.
1385pub type CameraFrameOpenglTextureFn =
1386 unsafe extern "C" fn(texture_id: libc::c_uint, texture_target: libc::c_uint, affine: *const f32);
1387
1388#[derive(Clone, Debug)]
1389#[repr(C)]
1390pub struct CameraCallback {
1391 // Set by libretro core.
1392 // Example bitmask: caps = (1 << CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << CAMERA_BUFFER_RAW_FRAMEBUFFER).
1393 pub caps: u64,
1394
1395 // Desired resolution for camera. Is only used as a hint.
1396 pub width: libc::c_uint,
1397 pub height: libc::c_uint,
1398
1399 // Set by frontend.
1400 pub start: CameraStartFn,
1401 pub stop: CameraStopFn,
1402
1403 // Set by libretro core if raw framebuffer callbacks will be used.
1404 pub frame_raw_framebuffer: CameraFrameRawFramebufferFn,
1405
1406 // Set by libretro core if OpenGL texture callbacks will be used.
1407 pub frame_opengl_texture: CameraFrameOpenglTextureFn,
1408
1409 // Set by libretro core. Called after camera driver is initialized and
1410 // ready to be started.
1411 //
1412 // Can be NULL, in which this callback is not called.
1413 pub initialized: CameraLifetimeStatusFn,
1414
1415 // Set by libretro core. Called right before camera driver is
1416 // deinitialized.
1417 //
1418 // Can be NULL, in which this callback is not called.
1419 pub deinitialized: CameraLifetimeStatusFn,
1420}
1421
1422// Sets the interval of time and/or distance at which to update/poll
1423// location-based data.
1424//
1425// To ensure compatibility with all location-based implementations,
1426// values for both interval_ms and interval_distance should be provided.
1427//
1428// interval_ms is the interval expressed in milliseconds.
1429// interval_distance is the distance interval expressed in meters.
1430pub type LocationSetIntervalFn = unsafe extern "C" fn(interval_ms: libc::c_uint, interval_distance: libc::c_uint);
1431
1432// Start location services. The device will start listening for changes to the
1433// current location at regular intervals (which are defined with
1434// retro_location_set_interval_t).
1435pub type LocationStartFn = unsafe extern "C" fn() -> bool;
1436
1437// Stop location services. The device will stop listening for changes
1438// to the current location.
1439pub type LocationStopFn = unsafe extern "C" fn();
1440
1441// Get the position of the current location. Will set parameters to
1442// 0 if no new location update has happened since the last time.
1443pub type LocationGetPositionFn =
1444 unsafe extern "C" fn(lat: *mut f64, lon: *mut f64, horiz_accuracy: *mut f64, vert_accuracy: *mut f64) -> bool;
1445
1446// Callback which signals when the location driver is initialized
1447// and/or deinitialized.
1448//
1449// retro_location_start_t can be called in initialized callback.
1450pub type LocationLifetimeStatusFn = unsafe extern "C" fn();
1451
1452#[derive(Clone, Debug)]
1453#[repr(C)]
1454pub struct LocationCallback {
1455 pub start: LocationStartFn,
1456 pub stop: LocationStopFn,
1457 pub get_position: LocationGetPositionFn,
1458 pub set_interval: LocationSetIntervalFn,
1459
1460 pub initialized: LocationLifetimeStatusFn,
1461 pub deinitialized: LocationLifetimeStatusFn,
1462}
1463
1464define_enum! {
1465 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1466 #[repr(C)]
1467 pub enum RumbleEffect {
1468 Strong = 0,
1469 Weak = 1,
1470 }
1471}
1472
1473// Sets rumble state for joypad plugged in port 'port'.
1474// Rumble effects are controlled independently,
1475// and setting e.g. strong rumble does not override weak rumble.
1476// Strength has a range of [0, 0xffff].
1477//
1478// Returns true if rumble state request was honored.
1479// Calling this before first retro_run() is likely to return false.
1480pub type SetRumbleStateFn = unsafe extern "C" fn(port: libc::c_uint, effect: RumbleEffect, strength: u16) -> bool;
1481
1482#[derive(Clone, Debug)]
1483#[repr(C)]
1484pub struct RumbleInterface {
1485 pub set_rumble_state: SetRumbleStateFn,
1486}
1487
1488// Notifies libretro that audio data should be written.
1489pub type AudioCallbackFn = unsafe extern "C" fn();
1490
1491// True: Audio driver in frontend is active, and callback is
1492// expected to be called regularily.
1493// False: Audio driver in frontend is paused or inactive.
1494// Audio callback will not be called until set_state has been
1495// called with true.
1496//
1497// Initial state is false (inactive).
1498pub type AudioSetStateCallbackFn = unsafe extern "C" fn(enabled: bool);
1499
1500#[derive(Clone, Debug)]
1501#[repr(C)]
1502pub struct AudioCallback {
1503 pub callback: AudioCallbackFn,
1504 pub set_state: AudioSetStateCallbackFn,
1505}
1506
1507// Notifies a libretro core of time spent since last invocation
1508// of retro_run() in microseconds.
1509//
1510// It will be called right before retro_run() every frame.
1511// The frontend can tamper with timing to support cases like
1512// fast-forward, slow-motion and framestepping.
1513//
1514// In those scenarios the reference frame time value will be used.
1515pub type Usec = i64;
1516pub type FrameTimeCallbackFn = unsafe extern "C" fn(usec: Usec);
1517
1518#[derive(Clone, Debug)]
1519#[repr(C)]
1520pub struct FrameTimeCallback {
1521 pub callback: FrameTimeCallbackFn,
1522
1523 // Represents the time of one frame. It is computed as
1524 // 1000000 / fps, but the implementation will resolve the
1525 // rounding to ensure that framestepping, etc is exact.
1526 pub reference: Usec,
1527}
1528
1529// Pass this to retro_video_refresh_t if rendering to hardware.
1530// Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
1531pub const HW_FRAME_BUFFER_VALID: *const libc::c_void = -1 as libc::intptr_t as usize as *const libc::c_void;
1532
1533// Invalidates the current HW context.
1534// Any GL state is lost, and must not be deinitialized explicitly.
1535// If explicit deinitialization is desired by the libretro core,
1536// it should implement context_destroy callback.
1537// If called, all GPU resources must be reinitialized.
1538// Usually called when frontend reinits video driver.
1539// Also called first time video driver is initialized,
1540// allowing libretro core to initialize resources.
1541pub type HwContextResetFn = unsafe extern "C" fn();
1542
1543// Gets current framebuffer which is to be rendered to.
1544// Could change every frame potentially.
1545pub type HwGetCurrentFramebufferFn = unsafe extern "C" fn() -> libc::uintptr_t;
1546
1547// Get a symbol from HW context.
1548pub type HwGetProcAddressFn = unsafe extern "C" fn(sym: *const libc::c_char) -> ProcAddressFn;
1549
1550define_enum! {
1551 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1552 #[repr(C)]
1553 pub enum HwContextType {
1554 None = 0,
1555
1556 // OpenGL 2.x. Driver can choose to use latest compatibility context.
1557 OpenGL = 1,
1558 // OpenGL ES 2.0.
1559 OpenGLES2 = 2,
1560 // Modern desktop core GL context. Use version_major/
1561 // version_minor fields to set GL version.
1562 OpenGLCore = 3,
1563 // OpenGL ES 3.0
1564 OpenGLES3 = 4,
1565 // OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3,
1566 // use the corresponding enums directly.
1567 OpenGLESVersion = 5,
1568
1569 // Vulkan, see ENVIRONMENT_GET_HW_RENDER_INTERFACE.
1570 Vulkan = 6,
1571 }
1572}
1573
1574#[derive(Clone, Debug)]
1575#[repr(C)]
1576pub struct HwRenderCallback {
1577 // Which API to use. Set by libretro core. HwContextType
1578 pub context_type: libc::c_uint,
1579
1580 // Called when a context has been created or when it has been reset.
1581 // An OpenGL context is only valid after context_reset() has been called.
1582 //
1583 // When context_reset is called, OpenGL resources in the libretro
1584 // implementation are guaranteed to be invalid.
1585 //
1586 // It is possible that context_reset is called multiple times during an
1587 // application lifecycle.
1588 // If context_reset is called without any notification (context_destroy),
1589 // the OpenGL context was lost and resources should just be recreated
1590 // without any attempt to "free" old resources.
1591 pub context_reset: HwContextResetFn,
1592
1593 // Set by frontend.
1594 // TODO: This is rather obsolete. The frontend should not
1595 // be providing preallocated framebuffers.
1596 pub get_current_framebuffer: HwGetCurrentFramebufferFn,
1597
1598 // Set by frontend.
1599 pub get_proc_address: HwGetProcAddressFn,
1600
1601 // Set if render buffers should have depth component attached.
1602 // TODO: Obsolete.
1603 pub depth: bool,
1604
1605 // Set if stencil buffers should be attached.
1606 // TODO: Obsolete.
1607 pub stencil: bool,
1608
1609 // If depth and stencil are true, a packed 24/8 buffer will be added.
1610 // Only attaching stencil is invalid and will be ignored. */
1611 //
1612 // Use conventional bottom-left origin convention. If false,
1613 // standard libretro top-left origin semantics are used.
1614 // TODO: Move to GL specific interface.
1615 pub bottom_left_origin: bool,
1616
1617 // Major version number for core GL context or GLES 3.1+.
1618 pub version_major: libc::c_uint,
1619
1620 // Minor version number for core GL context or GLES 3.1+.
1621 pub version_minor: libc::c_uint,
1622
1623 // If this is true, the frontend will go very far to avoid
1624 // resetting context in scenarios like toggling fullscreen, etc.
1625 //
1626 // The reset callback might still be called in extreme situations
1627 // such as if the context is lost beyond recovery.
1628 //
1629 // For optimal stability, set this to false, and allow context to be
1630 // reset at any time.
1631 pub cache_context: bool,
1632
1633 // A callback to be called before the context is destroyed in a
1634 // controlled way by the frontend.
1635 //
1636 // OpenGL resources can be deinitialized cleanly at this step.
1637 // context_destroy can be set to NULL, in which resources will
1638 // just be destroyed without any notification.
1639 //
1640 // Even when context_destroy is non-NULL, it is possible that
1641 // context_reset is called without any destroy notification.
1642 // This happens if context is lost by external factors (such as
1643 // notified by GL_ARB_robustness).
1644 //
1645 // In this case, the context is assumed to be already dead,
1646 // and the libretro implementation must not try to free any OpenGL
1647 // resources in the subsequent context_reset.
1648 pub context_destroy: HwContextResetFn,
1649
1650 // Creates a debug context.
1651 pub debug_context: bool,
1652}
1653
1654// Callback type passed in ENVIRONMENT_SET_KEYBOARD_CALLBACK.
1655// Called by the frontend in response to keyboard events.
1656// down is set if the key is being pressed, or false if it is being released.
1657// keycode is the RETROK value of the char.
1658// character is the text character of the pressed key. (UTF-32).
1659// key_modifiers is a set of RETROKMOD values or'ed together.
1660//
1661// The pressed/keycode state can be indepedent of the character.
1662// It is also possible that multiple characters are generated from a
1663// single keypress.
1664// Keycode events should be treated separately from character events.
1665// However, when possible, the frontend should try to synchronize these.
1666// If only a character is posted, keycode should be RETROK_UNKNOWN.
1667//
1668// Similarily if only a keycode event is generated with no corresponding
1669// character, character should be 0.
1670pub type KeyboardEventFn =
1671 unsafe extern "C" fn(down: bool, keycode: libc::c_uint, character: u32, key_modifiers: u16);
1672
1673#[derive(Clone, Debug)]
1674#[repr(C)]
1675pub struct KeyboardCallback {
1676 pub callback: KeyboardEventFn,
1677}
1678
1679// Callbacks for ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
1680// Should be set for implementations which can swap out multiple disk
1681// images in runtime.
1682//
1683// If the implementation can do this automatically, it should strive to do so.
1684// However, there are cases where the user must manually do so.
1685//
1686// Overview: To swap a disk image, eject the disk image with
1687// set_eject_state(true).
1688// Set the disk index with set_image_index(index). Insert the disk again
1689// with set_eject_state(false).
1690
1691// If ejected is true, "ejects" the virtual disk tray.
1692// When ejected, the disk image index can be set.
1693pub type SetEjectStateFn = unsafe extern "C" fn(ejected: bool) -> bool;
1694
1695// Gets current eject state. The initial state is 'not ejected'.
1696pub type GetEjectStateFn = unsafe extern "C" fn() -> bool;
1697
1698// Gets current disk index. First disk is index 0.
1699// If return value is >= get_num_images(), no disk is currently inserted.
1700pub type GetImageIndexFn = unsafe extern "C" fn() -> libc::c_uint;
1701
1702// Sets image index. Can only be called when disk is ejected.
1703// The implementation supports setting "no disk" by using an
1704// index >= get_num_images().
1705pub type SetImageIndexFn = unsafe extern "C" fn(index: libc::c_uint) -> bool;
1706
1707// Gets total number of images which are available to use.
1708pub type GetNumImagesFn = unsafe extern "C" fn() -> libc::c_uint;
1709
1710// Replaces the disk image associated with index.
1711// Arguments to pass in info have same requirements as retro_load_game().
1712// Virtual disk tray must be ejected when calling this.
1713//
1714// Replacing a disk image with info = NULL will remove the disk image
1715// from the internal list.
1716// As a result, calls to get_image_index() can change.
1717//
1718// E.g. replace_image_index(1, NULL), and previous get_image_index()
1719// returned 4 before.
1720// Index 1 will be removed, and the new index is 3.
1721pub type ReplaceImageIndexFn = unsafe extern "C" fn(index: libc::c_uint, info: *const GameInfo) -> bool;
1722
1723// Adds a new valid index (get_num_images()) to the internal disk list.
1724// This will increment subsequent return values from get_num_images() by 1.
1725// This image index cannot be used until a disk image has been set
1726// with replace_image_index.
1727pub type AddImageIndexFn = unsafe extern "C" fn() -> bool;
1728
1729#[derive(Clone, Debug)]
1730#[repr(C)]
1731pub struct DiskControlCallback {
1732 pub set_eject_state: SetEjectStateFn,
1733 pub get_eject_state: GetEjectStateFn,
1734
1735 pub get_image_index: GetImageIndexFn,
1736 pub set_image_index: SetImageIndexFn,
1737 pub get_num_images: GetNumImagesFn,
1738
1739 pub replace_image_index: ReplaceImageIndexFn,
1740 pub add_image_index: AddImageIndexFn,
1741}
1742
1743define_enum! {
1744 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1745 #[repr(C)]
1746 pub enum PixelFormat {
1747 // ARGB1555, native endian.
1748 // Alpha bit has to be set to 0.
1749 // This pixel format is default for compatibility concerns only.
1750 // If a 15/16-bit pixel format is desired, consider using RGB565.
1751 ARGB1555 = 0,
1752
1753 // ARGB8888, native endian.
1754 // Alpha bits are ignored.
1755 ARGB8888 = 1,
1756
1757 // RGB565, native endian.
1758 // This pixel format is the recommended format to use if a 15/16-bit
1759 // format is desired as it is the pixel format that is typically
1760 // available on a wide range of low-power devices.
1761 //
1762 // It is also natively supported in APIs like OpenGL ES.
1763 RGB565 = 2,
1764 }
1765}
1766
1767#[derive(Clone, Debug)]
1768#[repr(C)]
1769pub struct Message {
1770 // Message to be displayed.
1771 pub msg: *const libc::c_char,
1772
1773 // Duration in frames of message.
1774 pub frames: libc::c_uint,
1775}
1776
1777// Describes how the libretro implementation maps a libretro input bind
1778// to its internal input system through a human readable string.
1779// This string can be used to better let a user configure input.
1780#[derive(Clone, Debug)]
1781#[repr(C)]
1782pub struct InputDescriptor {
1783 // Associates given parameters with a description.
1784 pub port: libc::c_uint,
1785 pub device: libc::c_uint,
1786 pub index: libc::c_uint,
1787 pub id: libc::c_uint,
1788
1789 // Human readable description for parameters.
1790 // The pointer must remain valid until
1791 // retro_unload_game() is called.
1792 pub description: *const libc::c_char,
1793}
1794
1795#[derive(Clone, Debug)]
1796#[repr(C)]
1797pub struct SystemInfo {
1798 // All pointers are owned by libretro implementation, and pointers must
1799 // remain valid until retro_deinit() is called. */
1800 //
1801 // Descriptive name of library. Should not contain any version numbers, etc.
1802 pub library_name: *const libc::c_char,
1803
1804 // Descriptive version of core.
1805 pub library_version: *const libc::c_char,
1806
1807 // A string listing probably content extensions the core will be able to load,
1808 // separated with pipe. I.e. "bin|rom|iso". Typically used for a GUI to filter out
1809 // extensions.
1810 pub valid_extensions: *const libc::c_char,
1811
1812 // If true, retro_load_game() is guaranteed to provide a valid pathname
1813 // in retro_game_info::path.
1814 // ::data and ::size are both invalid.
1815 //
1816 // If false, ::data and ::size are guaranteed to be valid, but ::path
1817 // might not be valid.
1818 //
1819 // This is typically set to true for libretro implementations that must
1820 // load from file.
1821 // Implementations should strive for setting this to false, as it allows
1822 // the frontend to perform patching, etc.
1823 pub need_fullpath: bool,
1824
1825 // If true, the frontend is not allowed to extract any archives before
1826 // loading the real content.
1827 // Necessary for certain libretro implementations that load games
1828 // from zipped archives.
1829 pub block_extract: bool,
1830}
1831
1832#[derive(Clone, Debug)]
1833#[repr(C)]
1834pub struct GameGeometry {
1835 // Nominal video width of game.
1836 pub base_width: libc::c_uint,
1837
1838 // Nominal video height of game.
1839 pub base_height: libc::c_uint,
1840
1841 // Maximum possible width of game.
1842 pub max_width: libc::c_uint,
1843
1844 // Maximum possible height of game.
1845 pub max_height: libc::c_uint,
1846
1847 // Nominal aspect ratio of game. If aspect_ratio is <= 0.0, an aspect ratio of
1848 // base_width / base_height is assumed. A frontend could override this setting, if
1849 // desired.
1850 pub aspect_ratio: f32,
1851}
1852
1853#[derive(Clone, Debug)]
1854#[repr(C)]
1855pub struct SystemTiming {
1856 // FPS of video content.
1857 pub fps: f64,
1858
1859 // Sampling rate of audio.
1860 pub sample_rate: f64,
1861}
1862
1863#[derive(Clone, Debug)]
1864#[repr(C)]
1865pub struct SystemAvInfo {
1866 pub geometry: GameGeometry,
1867 pub timing: SystemTiming,
1868}
1869
1870#[derive(Clone, Debug)]
1871#[repr(C)]
1872pub struct Variable {
1873 // Variable to query in ENVIRONMENT_GET_VARIABLE.
1874 // If NULL, obtains the complete environment string if more
1875 // complex parsing is necessary.
1876 //
1877 // The environment string is formatted as key-value pairs
1878 // delimited by semicolons as so:
1879 // "key1=value1;key2=value2;..."
1880 //
1881 pub key: *const libc::c_char,
1882
1883 // Value to be obtained. If key does not exist, it is set to NULL.
1884 pub value: *const libc::c_char,
1885}
1886
1887#[derive(Clone, Debug)]
1888#[repr(C)]
1889pub struct GameInfo {
1890 // Path to game, UTF-8 encoded. Usually used as a reference. May be NULL if rom
1891 // was loaded from stdin or similar. retro_system_info::need_fullpath guaranteed
1892 // that this path is valid.
1893 pub path: *const libc::c_char,
1894
1895 // Memory buffer of loaded game. Will be NULL if need_fullpath was set.
1896 pub data: *const libc::c_void,
1897
1898 // Size of memory buffer.
1899 pub size: libc::size_t,
1900
1901 // String of implementation specific meta-data.
1902 pub meta: *const libc::c_char,
1903}
1904
1905// The core will write to the buffer provided by retro_framebuffer::data.
1906pub const MEMORY_ACCESS_WRITE: libc::c_uint = (1 << 0);
1907
1908// The core will read from retro_framebuffer::data.
1909pub const MEMORY_ACCESS_READ: libc::c_uint = (1 << 1);
1910
1911// The memory in data is cached.
1912// If not cached, random writes and/or reading from the buffer is expected to be very slow.
1913pub const MEMORY_TYPE_CACHED: libc::c_uint = (1 << 0);
1914
1915#[derive(Clone, Debug)]
1916#[repr(C)]
1917pub struct Framebuffer {
1918 // The framebuffer which the core can render into. Set by frontend in
1919 // GET_CURRENT_SOFTWARE_FRAMEBUFFER. The initial contents of data are unspecified.
1920 pub data: *mut libc::c_void,
1921
1922 // The framebuffer width used by the core. Set by core.
1923 pub width: libc::c_uint,
1924
1925 // The framebuffer height used by the core. Set by core.
1926 pub height: libc::c_uint,
1927
1928 // The number of bytes between the beginning of a scanline, and beginning of the
1929 // next scanline. Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER.
1930 pub pitch: libc::size_t,
1931
1932 // The pixel format the core must use to render into data. This format could
1933 // differ from the format used in SET_PIXEL_FORMAT. Set by frontend in
1934 // GET_CURRENT_SOFTWARE_FRAMEBUFFER. A value from enum PixelFormat.
1935 pub format: libc::c_uint,
1936
1937 // How the core will access the memory in the framebuffer. MEMORY_ACCESS_*
1938 // flags. Set by core.
1939 pub access_flags: libc::c_uint,
1940
1941 // Flags telling core how the memory has been mapped. MEMORY_TYPE_* flags.
1942 // Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER.
1943 pub memory_flags: libc::c_uint,
1944}
1945
1946// Callbacks
1947
1948// Environment callback. Gives implementations a way of performing
1949// uncommon tasks. Extensible.
1950pub type EnvironmentFn = unsafe extern "C" fn(cmd: libc::c_uint, data: *mut libc::c_void) -> bool;
1951
1952// Render a frame. Pixel format is 15-bit 0RGB1555 native endian
1953// unless changed (see ENVIRONMENT_SET_PIXEL_FORMAT).
1954//
1955// Width and height specify dimensions of buffer.
1956// Pitch specifices length in bytes between two lines in buffer.
1957//
1958// For performance reasons, it is highly recommended to have a frame
1959// that is packed in memory, i.e. pitch == width * byte_per_pixel.
1960// Certain graphic APIs, such as OpenGL ES, do not like textures
1961// that are not packed in memory.
1962pub type VideoRefreshFn =
1963 unsafe extern "C" fn(data: *const libc::c_void, width: libc::c_uint, height: libc::c_uint, pitch: libc::size_t);
1964
1965// Renders a single audio frame. Should only be used if implementation
1966// generates a single sample at a time.
1967// Format is signed 16-bit native endian.
1968pub type AudioSampleFn = unsafe extern "C" fn(left: i16, right: i16);
1969
1970// Renders multiple audio frames in one go.
1971//
1972// One frame is defined as a sample of left and right channels, interleaved.
1973// I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
1974// Only one of the audio callbacks must ever be used.
1975pub type AudioSampleBatchFn = unsafe extern "C" fn(data: *const i16, frames: libc::size_t) -> libc::size_t;
1976
1977// Polls input.
1978pub type InputPollFn = unsafe extern "C" fn();
1979
1980// Queries for input for player 'port'. device will be masked with
1981// DEVICE_MASK.
1982//
1983// Specialization of devices such as DEVICE_JOYPAD_MULTITAP that
1984// have been set with retro_set_controller_port_device()
1985// will still use the higher level DEVICE_JOYPAD to request input.
1986pub type InputStateFn =
1987 unsafe extern "C" fn(port: libc::c_uint, device: libc::c_uint, index: libc::c_uint, id: libc::c_uint) -> i16;
1988
1989#[derive(Clone, Debug)]
1990pub struct CoreAPI {
1991 // Sets callbacks. retro_set_environment() is guaranteed to be called
1992 // before retro_init().
1993 //
1994 // The rest of the set_* functions are guaranteed to have been called
1995 // before the first call to retro_run() is made.
1996 pub retro_set_environment: unsafe extern "C" fn(callback: EnvironmentFn),
1997 pub retro_set_video_refresh: unsafe extern "C" fn(callback: VideoRefreshFn),
1998 pub retro_set_audio_sample: unsafe extern "C" fn(callback: AudioSampleFn),
1999 pub retro_set_audio_sample_batch: unsafe extern "C" fn(callback: AudioSampleBatchFn),
2000 pub retro_set_input_poll: unsafe extern "C" fn(callback: InputPollFn),
2001 pub retro_set_input_state: unsafe extern "C" fn(callback: InputStateFn),
2002
2003 // Library global initialization/deinitialization.
2004 pub retro_init: unsafe extern "C" fn(),
2005 pub retro_deinit: unsafe extern "C" fn(),
2006
2007 // Must return API_VERSION. Used to validate ABI compatibility
2008 // when the API is revised.
2009 pub retro_api_version: unsafe extern "C" fn() -> libc::c_uint,
2010
2011 // Gets statically known system info. Pointers provided in * info
2012 // must be statically allocated.
2013 // Can be called at any time, even before pub retro_init().
2014 pub retro_get_system_info: unsafe extern "C" fn(info: *mut SystemInfo),
2015
2016 // Gets information about system audio/video timings and geometry.
2017 // Can be called only after pub retro_load_game() has successfully completed.
2018 // NOTE: The implementation of this function might not initialize every
2019 // variable if needed.
2020 // E.g. geom.aspect_ratio might not be initialized if core doesn't
2021 // desire a particular aspect ratio.
2022 pub retro_get_system_av_info: unsafe extern "C" fn(info: *mut SystemAvInfo),
2023
2024 // Sets device to be used for player 'port'.
2025 // By default, DEVICE_JOYPAD is assumed to be plugged into all
2026 // available ports.
2027 // Setting a particular device type is not a guarantee that libretro cores
2028 // will only poll input based on that particular device type. It is only a
2029 // hint to the libretro core when a core cannot automatically detect the
2030 // appropriate input device type on its own. It is also relevant when a
2031 // core can change its behavior depending on device type.
2032 pub retro_set_controller_port_device: unsafe extern "C" fn(port: libc::c_uint, device: libc::c_uint),
2033
2034 // Resets the current game.
2035 pub retro_reset: unsafe extern "C" fn(),
2036
2037 // Runs the game for one video frame.
2038 // During pub retro_run(), input_poll callback must be called at least once.
2039 //
2040 // If a frame is not rendered for reasons where a game "dropped" a frame,
2041 // this still counts as a frame, and pub retro_run() should explicitly dupe
2042 // a frame if GET_CAN_DUPE returns true.
2043 // In this case, the video callback can take a NULL argument for data.
2044 pub retro_run: unsafe extern "C" fn(),
2045
2046 // Returns the amount of data the implementation requires to serialize
2047 // internal state (save states).
2048 //
2049 // Between calls to pub retro_load_game() and retro_unload_game(), the
2050 // returned size is never allowed to be larger than a previous returned
2051 // value, to ensure that the frontend can allocate a save state buffer once.
2052 pub retro_serialize_size: unsafe extern "C" fn() -> libc::size_t,
2053
2054 // Serializes internal state. If failed, or size is lower than
2055 // pub retro_serialize_size(), it should return false, true otherwise.
2056 pub retro_serialize: unsafe extern "C" fn(data: *mut libc::c_void, size: libc::size_t),
2057
2058 pub retro_unserialize: unsafe extern "C" fn(data: *const libc::c_void, size: libc::size_t) -> bool,
2059 pub retro_cheat_reset: unsafe extern "C" fn(),
2060 pub retro_cheat_set: unsafe extern "C" fn(index: libc::c_uint, enabled: bool, code: *const libc::c_char),
2061
2062 // Loads a game.
2063 pub retro_load_game: unsafe extern "C" fn(game: *const GameInfo) -> bool,
2064
2065 // Loads a "special" kind of game. Should not be used,
2066 // except in extreme cases.
2067 pub retro_load_game_special: unsafe extern "C" fn(game_type: libc::c_uint, info: *const GameInfo, num_info: libc::size_t) -> bool,
2068
2069 // Unloads a currently loaded game.
2070 pub retro_unload_game: unsafe extern "C" fn(),
2071
2072 // Gets region of game.
2073 pub retro_get_region: unsafe extern "C" fn() -> libc::c_uint,
2074
2075 // Gets region of memory.
2076 pub retro_get_memory_data: unsafe extern "C" fn(id: libc::c_uint) -> *mut libc::c_void,
2077 pub retro_get_memory_size: unsafe extern "C" fn(id: libc::c_uint) -> libc::size_t,
2078}