libretro.h 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  1. /* Copyright (C) 2010-2014 The RetroArch team
  2. *
  3. * ---------------------------------------------------------------------------------------
  4. * The following license statement only applies to this libretro API header (libretro.h).
  5. * ---------------------------------------------------------------------------------------
  6. *
  7. * Permission is hereby granted, free of charge,
  8. * to any person obtaining a copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
  11. * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef LIBRETRO_H__
  23. #define LIBRETRO_H__
  24. #include <stdint.h>
  25. #include <stddef.h>
  26. #include <limits.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #ifndef __cplusplus
  31. #if defined(_MSC_VER) && !defined(SN_TARGET_PS3)
  32. /* Hack applied for MSVC when compiling in C89 mode
  33. * as it isn't C99-compliant. */
  34. #define bool unsigned char
  35. #define true 1
  36. #define false 0
  37. #else
  38. #include <stdbool.h>
  39. #endif
  40. #endif
  41. /* Used for checking API/ABI mismatches that can break libretro
  42. * implementations.
  43. * It is not incremented for compatible changes to the API.
  44. */
  45. #define RETRO_API_VERSION 1
  46. /*
  47. * Libretro's fundamental device abstractions.
  48. *
  49. * Libretro's input system consists of some standardized device types,
  50. * such as a joypad (with/without analog), mouse, keyboard, lightgun
  51. * and a pointer.
  52. *
  53. * The functionality of these devices are fixed, and individual cores
  54. * map their own concept of a controller to libretro's abstractions.
  55. * This makes it possible for frontends to map the abstract types to a
  56. * real input device, and not having to worry about binding input
  57. * correctly to arbitrary controller layouts.
  58. */
  59. #define RETRO_DEVICE_TYPE_SHIFT 8
  60. #define RETRO_DEVICE_MASK ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1)
  61. #define RETRO_DEVICE_SUBCLASS(base, id) (((id + 1) << RETRO_DEVICE_TYPE_SHIFT) | base)
  62. /* Input disabled. */
  63. #define RETRO_DEVICE_NONE 0
  64. /* The JOYPAD is called RetroPad. It is essentially a Super Nintendo
  65. * controller, but with additional L2/R2/L3/R3 buttons, similar to a
  66. * PS1 DualShock. */
  67. #define RETRO_DEVICE_JOYPAD 1
  68. /* The mouse is a simple mouse, similar to Super Nintendo's mouse.
  69. * X and Y coordinates are reported relatively to last poll (poll callback).
  70. * It is up to the libretro implementation to keep track of where the mouse
  71. * pointer is supposed to be on the screen.
  72. * The frontend must make sure not to interfere with its own hardware
  73. * mouse pointer.
  74. */
  75. #define RETRO_DEVICE_MOUSE 2
  76. /* KEYBOARD device lets one poll for raw key pressed.
  77. * It is poll based, so input callback will return with the current
  78. * pressed state.
  79. * For event/text based keyboard input, see
  80. * RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
  81. */
  82. #define RETRO_DEVICE_KEYBOARD 3
  83. /* Lightgun X/Y coordinates are reported relatively to last poll,
  84. * similar to mouse. */
  85. #define RETRO_DEVICE_LIGHTGUN 4
  86. /* The ANALOG device is an extension to JOYPAD (RetroPad).
  87. * Similar to DualShock it adds two analog sticks.
  88. * This is treated as a separate device type as it returns values in the
  89. * full analog range of [-0x8000, 0x7fff]. Positive X axis is right.
  90. * Positive Y axis is down.
  91. * Only use ANALOG type when polling for analog values of the axes.
  92. */
  93. #define RETRO_DEVICE_ANALOG 5
  94. /* Abstracts the concept of a pointing mechanism, e.g. touch.
  95. * This allows libretro to query in absolute coordinates where on the
  96. * screen a mouse (or something similar) is being placed.
  97. * For a touch centric device, coordinates reported are the coordinates
  98. * of the press.
  99. *
  100. * Coordinates in X and Y are reported as:
  101. * [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen,
  102. * and 0x7fff corresponds to the far right/bottom of the screen.
  103. * The "screen" is here defined as area that is passed to the frontend and
  104. * later displayed on the monitor.
  105. *
  106. * The frontend is free to scale/resize this screen as it sees fit, however,
  107. * (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the
  108. * game image, etc.
  109. *
  110. * To check if the pointer coordinates are valid (e.g. a touch display
  111. * actually being touched), PRESSED returns 1 or 0.
  112. *
  113. * If using a mouse on a desktop, PRESSED will usually correspond to the
  114. * left mouse button, but this is a frontend decision.
  115. * PRESSED will only return 1 if the pointer is inside the game screen.
  116. *
  117. * For multi-touch, the index variable can be used to successively query
  118. * more presses.
  119. * If index = 0 returns true for _PRESSED, coordinates can be extracted
  120. * with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with
  121. * index = 1, and so on.
  122. * Eventually _PRESSED will return false for an index. No further presses
  123. * are registered at this point. */
  124. #define RETRO_DEVICE_POINTER 6
  125. /* Buttons for the RetroPad (JOYPAD).
  126. * The placement of these is equivalent to placements on the
  127. * Super Nintendo controller.
  128. * L2/R2/L3/R3 buttons correspond to the PS1 DualShock. */
  129. #define RETRO_DEVICE_ID_JOYPAD_B 0
  130. #define RETRO_DEVICE_ID_JOYPAD_Y 1
  131. #define RETRO_DEVICE_ID_JOYPAD_SELECT 2
  132. #define RETRO_DEVICE_ID_JOYPAD_START 3
  133. #define RETRO_DEVICE_ID_JOYPAD_UP 4
  134. #define RETRO_DEVICE_ID_JOYPAD_DOWN 5
  135. #define RETRO_DEVICE_ID_JOYPAD_LEFT 6
  136. #define RETRO_DEVICE_ID_JOYPAD_RIGHT 7
  137. #define RETRO_DEVICE_ID_JOYPAD_A 8
  138. #define RETRO_DEVICE_ID_JOYPAD_X 9
  139. #define RETRO_DEVICE_ID_JOYPAD_L 10
  140. #define RETRO_DEVICE_ID_JOYPAD_R 11
  141. #define RETRO_DEVICE_ID_JOYPAD_L2 12
  142. #define RETRO_DEVICE_ID_JOYPAD_R2 13
  143. #define RETRO_DEVICE_ID_JOYPAD_L3 14
  144. #define RETRO_DEVICE_ID_JOYPAD_R3 15
  145. /* Index / Id values for ANALOG device. */
  146. #define RETRO_DEVICE_INDEX_ANALOG_LEFT 0
  147. #define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1
  148. #define RETRO_DEVICE_ID_ANALOG_X 0
  149. #define RETRO_DEVICE_ID_ANALOG_Y 1
  150. /* Id values for MOUSE. */
  151. #define RETRO_DEVICE_ID_MOUSE_X 0
  152. #define RETRO_DEVICE_ID_MOUSE_Y 1
  153. #define RETRO_DEVICE_ID_MOUSE_LEFT 2
  154. #define RETRO_DEVICE_ID_MOUSE_RIGHT 3
  155. #define RETRO_DEVICE_ID_MOUSE_WHEELUP 4
  156. #define RETRO_DEVICE_ID_MOUSE_WHEELDOWN 5
  157. #define RETRO_DEVICE_ID_MOUSE_MIDDLE 6
  158. /* Id values for LIGHTGUN types. */
  159. #define RETRO_DEVICE_ID_LIGHTGUN_X 0
  160. #define RETRO_DEVICE_ID_LIGHTGUN_Y 1
  161. #define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2
  162. #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3
  163. #define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4
  164. #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5
  165. #define RETRO_DEVICE_ID_LIGHTGUN_START 6
  166. /* Id values for POINTER. */
  167. #define RETRO_DEVICE_ID_POINTER_X 0
  168. #define RETRO_DEVICE_ID_POINTER_Y 1
  169. #define RETRO_DEVICE_ID_POINTER_PRESSED 2
  170. /* Returned from retro_get_region(). */
  171. #define RETRO_REGION_NTSC 0
  172. #define RETRO_REGION_PAL 1
  173. /* Id values for LANGUAGE */
  174. enum retro_language
  175. {
  176. RETRO_LANGUAGE_ENGLISH = 0,
  177. RETRO_LANGUAGE_JAPANESE = 1,
  178. RETRO_LANGUAGE_FRENCH = 2,
  179. RETRO_LANGUAGE_SPANISH = 3,
  180. RETRO_LANGUAGE_GERMAN = 4,
  181. RETRO_LANGUAGE_ITALIAN = 5,
  182. RETRO_LANGUAGE_DUTCH = 6,
  183. RETRO_LANGUAGE_PORTUGUESE = 7,
  184. RETRO_LANGUAGE_RUSSIAN = 8,
  185. RETRO_LANGUAGE_KOREAN = 9,
  186. RETRO_LANGUAGE_CHINESE_TRADITIONAL = 10,
  187. RETRO_LANGUAGE_CHINESE_SIMPLIFIED = 11,
  188. RETRO_LANGUAGE_LAST,
  189. /* Ensure sizeof(enum) == sizeof(int) */
  190. RETRO_LANGUAGE_DUMMY = INT_MAX
  191. };
  192. /* Passed to retro_get_memory_data/size().
  193. * If the memory type doesn't apply to the
  194. * implementation NULL/0 can be returned.
  195. */
  196. #define RETRO_MEMORY_MASK 0xff
  197. /* Regular save RAM. This RAM is usually found on a game cartridge,
  198. * backed up by a battery.
  199. * If save game data is too complex for a single memory buffer,
  200. * the SAVE_DIRECTORY (preferably) or SYSTEM_DIRECTORY environment
  201. * callback can be used. */
  202. #define RETRO_MEMORY_SAVE_RAM 0
  203. /* Some games have a built-in clock to keep track of time.
  204. * This memory is usually just a couple of bytes to keep track of time.
  205. */
  206. #define RETRO_MEMORY_RTC 1
  207. /* System ram lets a frontend peek into a game systems main RAM. */
  208. #define RETRO_MEMORY_SYSTEM_RAM 2
  209. /* Video ram lets a frontend peek into a game systems video RAM (VRAM). */
  210. #define RETRO_MEMORY_VIDEO_RAM 3
  211. /* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */
  212. enum retro_key
  213. {
  214. RETROK_UNKNOWN = 0,
  215. RETROK_FIRST = 0,
  216. RETROK_BACKSPACE = 8,
  217. RETROK_TAB = 9,
  218. RETROK_CLEAR = 12,
  219. RETROK_RETURN = 13,
  220. RETROK_PAUSE = 19,
  221. RETROK_ESCAPE = 27,
  222. RETROK_SPACE = 32,
  223. RETROK_EXCLAIM = 33,
  224. RETROK_QUOTEDBL = 34,
  225. RETROK_HASH = 35,
  226. RETROK_DOLLAR = 36,
  227. RETROK_AMPERSAND = 38,
  228. RETROK_QUOTE = 39,
  229. RETROK_LEFTPAREN = 40,
  230. RETROK_RIGHTPAREN = 41,
  231. RETROK_ASTERISK = 42,
  232. RETROK_PLUS = 43,
  233. RETROK_COMMA = 44,
  234. RETROK_MINUS = 45,
  235. RETROK_PERIOD = 46,
  236. RETROK_SLASH = 47,
  237. RETROK_0 = 48,
  238. RETROK_1 = 49,
  239. RETROK_2 = 50,
  240. RETROK_3 = 51,
  241. RETROK_4 = 52,
  242. RETROK_5 = 53,
  243. RETROK_6 = 54,
  244. RETROK_7 = 55,
  245. RETROK_8 = 56,
  246. RETROK_9 = 57,
  247. RETROK_COLON = 58,
  248. RETROK_SEMICOLON = 59,
  249. RETROK_LESS = 60,
  250. RETROK_EQUALS = 61,
  251. RETROK_GREATER = 62,
  252. RETROK_QUESTION = 63,
  253. RETROK_AT = 64,
  254. RETROK_LEFTBRACKET = 91,
  255. RETROK_BACKSLASH = 92,
  256. RETROK_RIGHTBRACKET = 93,
  257. RETROK_CARET = 94,
  258. RETROK_UNDERSCORE = 95,
  259. RETROK_BACKQUOTE = 96,
  260. RETROK_a = 97,
  261. RETROK_b = 98,
  262. RETROK_c = 99,
  263. RETROK_d = 100,
  264. RETROK_e = 101,
  265. RETROK_f = 102,
  266. RETROK_g = 103,
  267. RETROK_h = 104,
  268. RETROK_i = 105,
  269. RETROK_j = 106,
  270. RETROK_k = 107,
  271. RETROK_l = 108,
  272. RETROK_m = 109,
  273. RETROK_n = 110,
  274. RETROK_o = 111,
  275. RETROK_p = 112,
  276. RETROK_q = 113,
  277. RETROK_r = 114,
  278. RETROK_s = 115,
  279. RETROK_t = 116,
  280. RETROK_u = 117,
  281. RETROK_v = 118,
  282. RETROK_w = 119,
  283. RETROK_x = 120,
  284. RETROK_y = 121,
  285. RETROK_z = 122,
  286. RETROK_DELETE = 127,
  287. RETROK_KP0 = 256,
  288. RETROK_KP1 = 257,
  289. RETROK_KP2 = 258,
  290. RETROK_KP3 = 259,
  291. RETROK_KP4 = 260,
  292. RETROK_KP5 = 261,
  293. RETROK_KP6 = 262,
  294. RETROK_KP7 = 263,
  295. RETROK_KP8 = 264,
  296. RETROK_KP9 = 265,
  297. RETROK_KP_PERIOD = 266,
  298. RETROK_KP_DIVIDE = 267,
  299. RETROK_KP_MULTIPLY = 268,
  300. RETROK_KP_MINUS = 269,
  301. RETROK_KP_PLUS = 270,
  302. RETROK_KP_ENTER = 271,
  303. RETROK_KP_EQUALS = 272,
  304. RETROK_UP = 273,
  305. RETROK_DOWN = 274,
  306. RETROK_RIGHT = 275,
  307. RETROK_LEFT = 276,
  308. RETROK_INSERT = 277,
  309. RETROK_HOME = 278,
  310. RETROK_END = 279,
  311. RETROK_PAGEUP = 280,
  312. RETROK_PAGEDOWN = 281,
  313. RETROK_F1 = 282,
  314. RETROK_F2 = 283,
  315. RETROK_F3 = 284,
  316. RETROK_F4 = 285,
  317. RETROK_F5 = 286,
  318. RETROK_F6 = 287,
  319. RETROK_F7 = 288,
  320. RETROK_F8 = 289,
  321. RETROK_F9 = 290,
  322. RETROK_F10 = 291,
  323. RETROK_F11 = 292,
  324. RETROK_F12 = 293,
  325. RETROK_F13 = 294,
  326. RETROK_F14 = 295,
  327. RETROK_F15 = 296,
  328. RETROK_NUMLOCK = 300,
  329. RETROK_CAPSLOCK = 301,
  330. RETROK_SCROLLOCK = 302,
  331. RETROK_RSHIFT = 303,
  332. RETROK_LSHIFT = 304,
  333. RETROK_RCTRL = 305,
  334. RETROK_LCTRL = 306,
  335. RETROK_RALT = 307,
  336. RETROK_LALT = 308,
  337. RETROK_RMETA = 309,
  338. RETROK_LMETA = 310,
  339. RETROK_LSUPER = 311,
  340. RETROK_RSUPER = 312,
  341. RETROK_MODE = 313,
  342. RETROK_COMPOSE = 314,
  343. RETROK_HELP = 315,
  344. RETROK_PRINT = 316,
  345. RETROK_SYSREQ = 317,
  346. RETROK_BREAK = 318,
  347. RETROK_MENU = 319,
  348. RETROK_POWER = 320,
  349. RETROK_EURO = 321,
  350. RETROK_UNDO = 322,
  351. RETROK_LAST,
  352. RETROK_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
  353. };
  354. enum retro_mod
  355. {
  356. RETROKMOD_NONE = 0x0000,
  357. RETROKMOD_SHIFT = 0x01,
  358. RETROKMOD_CTRL = 0x02,
  359. RETROKMOD_ALT = 0x04,
  360. RETROKMOD_META = 0x08,
  361. RETROKMOD_NUMLOCK = 0x10,
  362. RETROKMOD_CAPSLOCK = 0x20,
  363. RETROKMOD_SCROLLOCK = 0x40,
  364. RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
  365. };
  366. /* If set, this call is not part of the public libretro API yet. It can
  367. * change or be removed at any time. */
  368. #define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000
  369. /* Environment callback to be used internally in frontend. */
  370. #define RETRO_ENVIRONMENT_PRIVATE 0x20000
  371. /* Environment commands. */
  372. #define RETRO_ENVIRONMENT_SET_ROTATION 1 /* const unsigned * --
  373. * Sets screen rotation of graphics.
  374. * Is only implemented if rotation can be accelerated by hardware.
  375. * Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180,
  376. * 270 degrees counter-clockwise respectively.
  377. */
  378. #define RETRO_ENVIRONMENT_GET_OVERSCAN 2 /* bool * --
  379. * Boolean value whether or not the implementation should use overscan,
  380. * or crop away overscan.
  381. */
  382. #define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 /* bool * --
  383. * Boolean value whether or not frontend supports frame duping,
  384. * passing NULL to video frame callback.
  385. */
  386. /* Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES),
  387. * and reserved to avoid possible ABI clash.
  388. */
  389. #define RETRO_ENVIRONMENT_SET_MESSAGE 6 /* const struct retro_message * --
  390. * Sets a message to be displayed in implementation-specific manner
  391. * for a certain amount of 'frames'.
  392. * Should not be used for trivial messages, which should simply be
  393. * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a
  394. * fallback, stderr).
  395. */
  396. #define RETRO_ENVIRONMENT_SHUTDOWN 7 /* N/A (NULL) --
  397. * Requests the frontend to shutdown.
  398. * Should only be used if game has a specific
  399. * way to shutdown the game from a menu item or similar.
  400. */
  401. #define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8
  402. /* const unsigned * --
  403. * Gives a hint to the frontend how demanding this implementation
  404. * is on a system. E.g. reporting a level of 2 means
  405. * this implementation should run decently on all frontends
  406. * of level 2 and up.
  407. *
  408. * It can be used by the frontend to potentially warn
  409. * about too demanding implementations.
  410. *
  411. * The levels are "floating".
  412. *
  413. * This function can be called on a per-game basis,
  414. * as certain games an implementation can play might be
  415. * particularly demanding.
  416. * If called, it should be called in retro_load_game().
  417. */
  418. #define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
  419. /* const char ** --
  420. * Returns the "system" directory of the frontend.
  421. * This directory can be used to store system specific
  422. * content such as BIOSes, configuration data, etc.
  423. * The returned value can be NULL.
  424. * If so, no such directory is defined,
  425. * and it's up to the implementation to find a suitable directory.
  426. *
  427. * NOTE: Some cores used this folder also for "save" data such as
  428. * memory cards, etc, for lack of a better place to put it.
  429. * This is now discouraged, and if possible, cores should try to
  430. * use the new GET_SAVE_DIRECTORY.
  431. */
  432. #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
  433. /* const enum retro_pixel_format * --
  434. * Sets the internal pixel format used by the implementation.
  435. * The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555.
  436. * This pixel format however, is deprecated (see enum retro_pixel_format).
  437. * If the call returns false, the frontend does not support this pixel
  438. * format.
  439. *
  440. * This function should be called inside retro_load_game() or
  441. * retro_get_system_av_info().
  442. */
  443. #define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11
  444. /* const struct retro_input_descriptor * --
  445. * Sets an array of retro_input_descriptors.
  446. * It is up to the frontend to present this in a usable way.
  447. * The array is terminated by retro_input_descriptor::description
  448. * being set to NULL.
  449. * This function can be called at any time, but it is recommended
  450. * to call it as early as possible.
  451. */
  452. #define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12
  453. /* const struct retro_keyboard_callback * --
  454. * Sets a callback function used to notify core about keyboard events.
  455. */
  456. #define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13
  457. /* const struct retro_disk_control_callback * --
  458. * Sets an interface which frontend can use to eject and insert
  459. * disk images.
  460. * This is used for games which consist of multiple images and
  461. * must be manually swapped out by the user (e.g. PSX).
  462. */
  463. #define RETRO_ENVIRONMENT_SET_HW_RENDER 14
  464. /* struct retro_hw_render_callback * --
  465. * Sets an interface to let a libretro core render with
  466. * hardware acceleration.
  467. * Should be called in retro_load_game().
  468. * If successful, libretro cores will be able to render to a
  469. * frontend-provided framebuffer.
  470. * The size of this framebuffer will be at least as large as
  471. * max_width/max_height provided in get_av_info().
  472. * If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or
  473. * NULL to retro_video_refresh_t.
  474. */
  475. #define RETRO_ENVIRONMENT_GET_VARIABLE 15
  476. /* struct retro_variable * --
  477. * Interface to acquire user-defined information from environment
  478. * that cannot feasibly be supported in a multi-system way.
  479. * 'key' should be set to a key which has already been set by
  480. * SET_VARIABLES.
  481. * 'data' will be set to a value or NULL.
  482. */
  483. #define RETRO_ENVIRONMENT_SET_VARIABLES 16
  484. /* const struct retro_variable * --
  485. * Allows an implementation to signal the environment
  486. * which variables it might want to check for later using
  487. * GET_VARIABLE.
  488. * This allows the frontend to present these variables to
  489. * a user dynamically.
  490. * This should be called as early as possible (ideally in
  491. * retro_set_environment).
  492. *
  493. * 'data' points to an array of retro_variable structs
  494. * terminated by a { NULL, NULL } element.
  495. * retro_variable::key should be namespaced to not collide
  496. * with other implementations' keys. E.g. A core called
  497. * 'foo' should use keys named as 'foo_option'.
  498. * retro_variable::value should contain a human readable
  499. * description of the key as well as a '|' delimited list
  500. * of expected values.
  501. *
  502. * The number of possible options should be very limited,
  503. * i.e. it should be feasible to cycle through options
  504. * without a keyboard.
  505. *
  506. * First entry should be treated as a default.
  507. *
  508. * Example entry:
  509. * { "foo_option", "Speed hack coprocessor X; false|true" }
  510. *
  511. * Text before first ';' is description. This ';' must be
  512. * followed by a space, and followed by a list of possible
  513. * values split up with '|'.
  514. *
  515. * Only strings are operated on. The possible values will
  516. * generally be displayed and stored as-is by the frontend.
  517. */
  518. #define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17
  519. /* bool * --
  520. * Result is set to true if some variables are updated by
  521. * frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE.
  522. * Variables should be queried with GET_VARIABLE.
  523. */
  524. #define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18
  525. /* const bool * --
  526. * If true, the libretro implementation supports calls to
  527. * retro_load_game() with NULL as argument.
  528. * Used by cores which can run without particular game data.
  529. * This should be called within retro_set_environment() only.
  530. */
  531. #define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19
  532. /* const char ** --
  533. * Retrieves the absolute path from where this libretro
  534. * implementation was loaded.
  535. * NULL is returned if the libretro was loaded statically
  536. * (i.e. linked statically to frontend), or if the path cannot be
  537. * determined.
  538. * Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can
  539. * be loaded without ugly hacks.
  540. */
  541. /* Environment 20 was an obsolete version of SET_AUDIO_CALLBACK.
  542. * It was not used by any known core at the time,
  543. * and was removed from the API. */
  544. #define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22
  545. /* const struct retro_audio_callback * --
  546. * Sets an interface which is used to notify a libretro core about audio
  547. * being available for writing.
  548. * The callback can be called from any thread, so a core using this must
  549. * have a thread safe audio implementation.
  550. * It is intended for games where audio and video are completely
  551. * asynchronous and audio can be generated on the fly.
  552. * This interface is not recommended for use with emulators which have
  553. * highly synchronous audio.
  554. *
  555. * The callback only notifies about writability; the libretro core still
  556. * has to call the normal audio callbacks
  557. * to write audio. The audio callbacks must be called from within the
  558. * notification callback.
  559. * The amount of audio data to write is up to the implementation.
  560. * Generally, the audio callback will be called continously in a loop.
  561. *
  562. * Due to thread safety guarantees and lack of sync between audio and
  563. * video, a frontend can selectively disallow this interface based on
  564. * internal configuration. A core using this interface must also
  565. * implement the "normal" audio interface.
  566. *
  567. * A libretro core using SET_AUDIO_CALLBACK should also make use of
  568. * SET_FRAME_TIME_CALLBACK.
  569. */
  570. #define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21
  571. /* const struct retro_frame_time_callback * --
  572. * Lets the core know how much time has passed since last
  573. * invocation of retro_run().
  574. * The frontend can tamper with the timing to fake fast-forward,
  575. * slow-motion, frame stepping, etc.
  576. * In this case the delta time will use the reference value
  577. * in frame_time_callback..
  578. */
  579. #define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23
  580. /* struct retro_rumble_interface * --
  581. * Gets an interface which is used by a libretro core to set
  582. * state of rumble motors in controllers.
  583. * A strong and weak motor is supported, and they can be
  584. * controlled indepedently.
  585. */
  586. #define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24
  587. /* uint64_t * --
  588. * Gets a bitmask telling which device type are expected to be
  589. * handled properly in a call to retro_input_state_t.
  590. * Devices which are not handled or recognized always return
  591. * 0 in retro_input_state_t.
  592. * Example bitmask: caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG).
  593. * Should only be called in retro_run().
  594. */
  595. #define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL)
  596. /* struct retro_sensor_interface * --
  597. * Gets access to the sensor interface.
  598. * The purpose of this interface is to allow
  599. * setting state related to sensors such as polling rate,
  600. * enabling/disable it entirely, etc.
  601. * Reading sensor state is done via the normal
  602. * input_state_callback API.
  603. */
  604. #define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL)
  605. /* struct retro_camera_callback * --
  606. * Gets an interface to a video camera driver.
  607. * A libretro core can use this interface to get access to a
  608. * video camera.
  609. * New video frames are delivered in a callback in same
  610. * thread as retro_run().
  611. *
  612. * GET_CAMERA_INTERFACE should be called in retro_load_game().
  613. *
  614. * Depending on the camera implementation used, camera frames
  615. * will be delivered as a raw framebuffer,
  616. * or as an OpenGL texture directly.
  617. *
  618. * The core has to tell the frontend here which types of
  619. * buffers can be handled properly.
  620. * An OpenGL texture can only be handled when using a
  621. * libretro GL core (SET_HW_RENDER).
  622. * It is recommended to use a libretro GL core when
  623. * using camera interface.
  624. *
  625. * The camera is not started automatically. The retrieved start/stop
  626. * functions must be used to explicitly
  627. * start and stop the camera driver.
  628. */
  629. #define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27
  630. /* struct retro_log_callback * --
  631. * Gets an interface for logging. This is useful for
  632. * logging in a cross-platform way
  633. * as certain platforms cannot use use stderr for logging.
  634. * It also allows the frontend to
  635. * show logging information in a more suitable way.
  636. * If this interface is not used, libretro cores should
  637. * log to stderr as desired.
  638. */
  639. #define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28
  640. /* struct retro_perf_callback * --
  641. * Gets an interface for performance counters. This is useful
  642. * for performance logging in a cross-platform way and for detecting
  643. * architecture-specific features, such as SIMD support.
  644. */
  645. #define RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE 29
  646. /* struct retro_location_callback * --
  647. * Gets access to the location interface.
  648. * The purpose of this interface is to be able to retrieve
  649. * location-based information from the host device,
  650. * such as current latitude / longitude.
  651. */
  652. #define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30
  653. /* const char ** --
  654. * Returns the "content" directory of the frontend.
  655. * This directory can be used to store specific assets that the
  656. * core relies upon, such as art assets,
  657. * input data, etc etc.
  658. * The returned value can be NULL.
  659. * If so, no such directory is defined,
  660. * and it's up to the implementation to find a suitable directory.
  661. */
  662. #define RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY 31
  663. /* const char ** --
  664. * Returns the "save" directory of the frontend.
  665. * This directory can be used to store SRAM, memory cards,
  666. * high scores, etc, if the libretro core
  667. * cannot use the regular memory interface (retro_get_memory_data()).
  668. *
  669. * NOTE: libretro cores used to check GET_SYSTEM_DIRECTORY for
  670. * similar things before.
  671. * They should still check GET_SYSTEM_DIRECTORY if they want to
  672. * be backwards compatible.
  673. * The path here can be NULL. It should only be non-NULL if the
  674. * frontend user has set a specific save path.
  675. */
  676. #define RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO 32
  677. /* const struct retro_system_av_info * --
  678. * Sets a new av_info structure. This can only be called from
  679. * within retro_run().
  680. * This should *only* be used if the core is completely altering the
  681. * internal resolutions, aspect ratios, timings, sampling rate, etc.
  682. * Calling this can require a full reinitialization of video/audio
  683. * drivers in the frontend,
  684. *
  685. * so it is important to call it very sparingly, and usually only with
  686. * the users explicit consent.
  687. * An eventual driver reinitialize will happen so that video and
  688. * audio callbacks
  689. * happening after this call within the same retro_run() call will
  690. * target the newly initialized driver.
  691. *
  692. * This callback makes it possible to support configurable resolutions
  693. * in games, which can be useful to
  694. * avoid setting the "worst case" in max_width/max_height.
  695. *
  696. * ***HIGHLY RECOMMENDED*** Do not call this callback every time
  697. * resolution changes in an emulator core if it's
  698. * expected to be a temporary change, for the reasons of possible
  699. * driver reinitialization.
  700. * This call is not a free pass for not trying to provide
  701. * correct values in retro_get_system_av_info(). If you need to change
  702. * things like aspect ratio or nominal width/height,
  703. * use RETRO_ENVIRONMENT_SET_GEOMETRY, which is a softer variant
  704. * of SET_SYSTEM_AV_INFO.
  705. *
  706. * If this returns false, the frontend does not acknowledge a
  707. * changed av_info struct.
  708. */
  709. #define RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK 33
  710. /* const struct retro_get_proc_address_interface * --
  711. * Allows a libretro core to announce support for the
  712. * get_proc_address() interface.
  713. * This interface allows for a standard way to extend libretro where
  714. * use of environment calls are too indirect,
  715. * e.g. for cases where the frontend wants to call directly into the core.
  716. *
  717. * If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK
  718. * **MUST** be called from within retro_set_environment().
  719. */
  720. #define RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO 34
  721. /* const struct retro_subsystem_info * --
  722. * This environment call introduces the concept of libretro "subsystems".
  723. * A subsystem is a variant of a libretro core which supports
  724. * different kinds of games.
  725. * The purpose of this is to support e.g. emulators which might
  726. * have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo.
  727. * It can also be used to pick among subsystems in an explicit way
  728. * if the libretro implementation is a multi-system emulator itself.
  729. *
  730. * Loading a game via a subsystem is done with retro_load_game_special(),
  731. * and this environment call allows a libretro core to expose which
  732. * subsystems are supported for use with retro_load_game_special().
  733. * A core passes an array of retro_game_special_info which is terminated
  734. * with a zeroed out retro_game_special_info struct.
  735. *
  736. * If a core wants to use this functionality, SET_SUBSYSTEM_INFO
  737. * **MUST** be called from within retro_set_environment().
  738. */
  739. #define RETRO_ENVIRONMENT_SET_CONTROLLER_INFO 35
  740. /* const struct retro_controller_info * --
  741. * This environment call lets a libretro core tell the frontend
  742. * which controller types are recognized in calls to
  743. * retro_set_controller_port_device().
  744. *
  745. * Some emulators such as Super Nintendo
  746. * support multiple lightgun types which must be specifically
  747. * selected from.
  748. * It is therefore sometimes necessary for a frontend to be able
  749. * to tell the core about a special kind of input device which is
  750. * not covered by the libretro input API.
  751. *
  752. * In order for a frontend to understand the workings of an input device,
  753. * it must be a specialized type
  754. * of the generic device types already defined in the libretro API.
  755. *
  756. * Which devices are supported can vary per input port.
  757. * The core must pass an array of const struct retro_controller_info which
  758. * is terminated with a blanked out struct. Each element of the struct
  759. * corresponds to an ascending port index to
  760. * retro_set_controller_port_device().
  761. * Even if special device types are set in the libretro core,
  762. * libretro should only poll input based on the base input device types.
  763. */
  764. #define RETRO_ENVIRONMENT_SET_MEMORY_MAPS (36 | RETRO_ENVIRONMENT_EXPERIMENTAL)
  765. /* const struct retro_memory_map * --
  766. * This environment call lets a libretro core tell the frontend
  767. * about the memory maps this core emulates.
  768. * This can be used to implement, for example, cheats in a core-agnostic way.
  769. *
  770. * Should only be used by emulators; it doesn't make much sense for
  771. * anything else.
  772. * It is recommended to expose all relevant pointers through
  773. * retro_get_memory_* as well.
  774. *
  775. * Can be called from retro_init and retro_load_game.
  776. */
  777. #define RETRO_ENVIRONMENT_SET_GEOMETRY 37
  778. /* const struct retro_game_geometry * --
  779. * This environment call is similar to SET_SYSTEM_AV_INFO for changing
  780. * video parameters, but provides a guarantee that drivers will not be
  781. * reinitialized.
  782. * This can only be called from within retro_run().
  783. *
  784. * The purpose of this call is to allow a core to alter nominal
  785. * width/heights as well as aspect ratios on-the-fly, which can be
  786. * useful for some emulators to change in run-time.
  787. *
  788. * max_width/max_height arguments are ignored and cannot be changed
  789. * with this call as this could potentially require a reinitialization or a
  790. * non-constant time operation.
  791. * If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required.
  792. *
  793. * A frontend must guarantee that this environment call completes in
  794. * constant time.
  795. */
  796. #define RETRO_ENVIRONMENT_GET_USERNAME 38
  797. /* const char **
  798. * Returns the specified username of the frontend, if specified by the user.
  799. * This username can be used as a nickname for a core that has online facilities
  800. * or any other mode where personalization of the user is desirable.
  801. * The returned value can be NULL.
  802. * If this environ callback is used by a core that requires a valid username,
  803. * a default username should be specified by the core.
  804. */
  805. #define RETRO_ENVIRONMENT_GET_LANGUAGE 39
  806. /* unsigned * --
  807. * Returns the specified language of the frontend, if specified by the user.
  808. * It can be used by the core for localization purposes.
  809. */
  810. #define RETRO_MEMDESC_CONST (1 << 0) /* The frontend will never change this memory area once retro_load_game has returned. */
  811. #define RETRO_MEMDESC_BIGENDIAN (1 << 1) /* The memory area contains big endian data. Default is little endian. */
  812. #define RETRO_MEMDESC_ALIGN_2 (1 << 16) /* All memory access in this area is aligned to their own size, or 2, whichever is smaller. */
  813. #define RETRO_MEMDESC_ALIGN_4 (2 << 16)
  814. #define RETRO_MEMDESC_ALIGN_8 (3 << 16)
  815. #define RETRO_MEMDESC_MINSIZE_2 (1 << 24) /* All memory in this region is accessed at least 2 bytes at the time. */
  816. #define RETRO_MEMDESC_MINSIZE_4 (2 << 24)
  817. #define RETRO_MEMDESC_MINSIZE_8 (3 << 24)
  818. struct retro_memory_descriptor
  819. {
  820. uint64_t flags;
  821. /* Pointer to the start of the relevant ROM or RAM chip.
  822. * It's strongly recommended to use 'offset' if possible, rather than
  823. * doing math on the pointer.
  824. *
  825. * If the same byte is mapped my multiple descriptors, their descriptors
  826. * must have the same pointer.
  827. * If 'start' does not point to the first byte in the pointer, put the
  828. * difference in 'offset' instead.
  829. *
  830. * May be NULL if there's nothing usable here (e.g. hardware registers and
  831. * open bus). No flags should be set if the pointer is NULL.
  832. * It's recommended to minimize the number of descriptors if possible,
  833. * but not mandatory. */
  834. void *ptr;
  835. size_t offset;
  836. /* This is the location in the emulated address space
  837. * where the mapping starts. */
  838. size_t start;
  839. /* Which bits must be same as in 'start' for this mapping to apply.
  840. * The first memory descriptor to claim a certain byte is the one
  841. * that applies.
  842. * A bit which is set in 'start' must also be set in this.
  843. * Can be zero, in which case each byte is assumed mapped exactly once.
  844. * In this case, 'len' must be a power of two. */
  845. size_t select;
  846. /* If this is nonzero, the set bits are assumed not connected to the
  847. * memory chip's address pins. */
  848. size_t disconnect;
  849. /* This one tells the size of the current memory area.
  850. * If, after start+disconnect are applied, the address is higher than
  851. * this, the highest bit of the address is cleared.
  852. *
  853. * If the address is still too high, the next highest bit is cleared.
  854. * Can be zero, in which case it's assumed to be infinite (as limited
  855. * by 'select' and 'disconnect'). */
  856. size_t len;
  857. /* To go from emulated address to physical address, the following
  858. * order applies:
  859. * Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'.
  860. *
  861. * The address space name must consist of only a-zA-Z0-9_-,
  862. * should be as short as feasible (maximum length is 8 plus the NUL),
  863. * and may not be any other address space plus one or more 0-9A-F
  864. * at the end.
  865. * However, multiple memory descriptors for the same address space is
  866. * allowed, and the address space name can be empty. NULL is treated
  867. * as empty.
  868. *
  869. * Address space names are case sensitive, but avoid lowercase if possible.
  870. * The same pointer may exist in multiple address spaces.
  871. *
  872. * Examples:
  873. * blank+blank - valid (multiple things may be mapped in the same namespace)
  874. * 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace)
  875. * 'A'+'B' - valid (neither is a prefix of each other)
  876. * 'S'+blank - valid ('S' is not in 0-9A-F)
  877. * 'a'+blank - valid ('a' is not in 0-9A-F)
  878. * 'a'+'A' - valid (neither is a prefix of each other)
  879. * 'AR'+blank - valid ('R' is not in 0-9A-F)
  880. * 'ARB'+blank - valid (the B can't be part of the address either, because
  881. * there is no namespace 'AR')
  882. * blank+'B' - not valid, because it's ambigous which address space B1234
  883. * would refer to.
  884. * The length can't be used for that purpose; the frontend may want
  885. * to append arbitrary data to an address, without a separator. */
  886. const char *addrspace;
  887. };
  888. /* The frontend may use the largest value of 'start'+'select' in a
  889. * certain namespace to infer the size of the address space.
  890. *
  891. * If the address space is larger than that, a mapping with .ptr=NULL
  892. * should be at the end of the array, with .select set to all ones for
  893. * as long as the address space is big.
  894. *
  895. * Sample descriptors (minus .ptr, and RETRO_MEMFLAG_ on the flags):
  896. * SNES WRAM:
  897. * .start=0x7E0000, .len=0x20000
  898. * (Note that this must be mapped before the ROM in most cases; some of the
  899. * ROM mappers
  900. * try to claim $7E0000, or at least $7E8000.)
  901. * SNES SPC700 RAM:
  902. * .addrspace="S", .len=0x10000
  903. * SNES WRAM mirrors:
  904. * .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000
  905. * .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000
  906. * SNES WRAM mirrors, alternate equivalent descriptor:
  907. * .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF
  908. * (Various similar constructions can be created by combining parts of
  909. * the above two.)
  910. * SNES LoROM (512KB, mirrored a couple of times):
  911. * .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024
  912. * .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024
  913. * SNES HiROM (4MB):
  914. * .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024
  915. * .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024
  916. * SNES ExHiROM (8MB):
  917. * .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024
  918. * .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024
  919. * .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024
  920. * .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024
  921. * Clarify the size of the address space:
  922. * .ptr=NULL, .select=0xFFFFFF
  923. * .len can be implied by .select in many of them, but was included for clarity.
  924. */
  925. struct retro_memory_map
  926. {
  927. const struct retro_memory_descriptor *descriptors;
  928. unsigned num_descriptors;
  929. };
  930. struct retro_controller_description
  931. {
  932. /* Human-readable description of the controller. Even if using a generic
  933. * input device type, this can be set to the particular device type the
  934. * core uses. */
  935. const char *desc;
  936. /* Device type passed to retro_set_controller_port_device(). If the device
  937. * type is a sub-class of a generic input device type, use the
  938. * RETRO_DEVICE_SUBCLASS macro to create an ID.
  939. *
  940. * E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1). */
  941. unsigned id;
  942. };
  943. struct retro_controller_info
  944. {
  945. const struct retro_controller_description *types;
  946. unsigned num_types;
  947. };
  948. struct retro_subsystem_memory_info
  949. {
  950. /* The extension associated with a memory type, e.g. "psram". */
  951. const char *extension;
  952. /* The memory type for retro_get_memory(). This should be at
  953. * least 0x100 to avoid conflict with standardized
  954. * libretro memory types. */
  955. unsigned type;
  956. };
  957. struct retro_subsystem_rom_info
  958. {
  959. /* Describes what the content is (SGB BIOS, GB ROM, etc). */
  960. const char *desc;
  961. /* Same definition as retro_get_system_info(). */
  962. const char *valid_extensions;
  963. /* Same definition as retro_get_system_info(). */
  964. bool need_fullpath;
  965. /* Same definition as retro_get_system_info(). */
  966. bool block_extract;
  967. /* This is set if the content is required to load a game.
  968. * If this is set to false, a zeroed-out retro_game_info can be passed. */
  969. bool required;
  970. /* Content can have multiple associated persistent
  971. * memory types (retro_get_memory()). */
  972. const struct retro_subsystem_memory_info *memory;
  973. unsigned num_memory;
  974. };
  975. struct retro_subsystem_info
  976. {
  977. /* Human-readable string of the subsystem type, e.g. "Super GameBoy" */
  978. const char *desc;
  979. /* A computer friendly short string identifier for the subsystem type.
  980. * This name must be [a-z].
  981. * E.g. if desc is "Super GameBoy", this can be "sgb".
  982. * This identifier can be used for command-line interfaces, etc.
  983. */
  984. const char *ident;
  985. /* Infos for each content file. The first entry is assumed to be the
  986. * "most significant" content for frontend purposes.
  987. * E.g. with Super GameBoy, the first content should be the GameBoy ROM,
  988. * as it is the most "significant" content to a user.
  989. * If a frontend creates new file paths based on the content used
  990. * (e.g. savestates), it should use the path for the first ROM to do so. */
  991. const struct retro_subsystem_rom_info *roms;
  992. /* Number of content files associated with a subsystem. */
  993. unsigned num_roms;
  994. /* The type passed to retro_load_game_special(). */
  995. unsigned id;
  996. };
  997. typedef void (*retro_proc_address_t)(void);
  998. /* libretro API extension functions:
  999. * (None here so far).
  1000. *
  1001. * Get a symbol from a libretro core.
  1002. * Cores should only return symbols which are actual
  1003. * extensions to the libretro API.
  1004. *
  1005. * Frontends should not use this to obtain symbols to standard
  1006. * libretro entry points (static linking or dlsym).
  1007. *
  1008. * The symbol name must be equal to the function name,
  1009. * e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo".
  1010. * The returned function pointer must be cast to the corresponding type.
  1011. */
  1012. typedef retro_proc_address_t (*retro_get_proc_address_t)(const char *sym);
  1013. struct retro_get_proc_address_interface
  1014. {
  1015. retro_get_proc_address_t get_proc_address;
  1016. };
  1017. enum retro_log_level
  1018. {
  1019. RETRO_LOG_DEBUG = 0,
  1020. RETRO_LOG_INFO,
  1021. RETRO_LOG_WARN,
  1022. RETRO_LOG_ERROR,
  1023. RETRO_LOG_DUMMY = INT_MAX
  1024. };
  1025. /* Logging function. Takes log level argument as well. */
  1026. typedef void (*retro_log_printf_t)(enum retro_log_level level,
  1027. const char *fmt, ...);
  1028. struct retro_log_callback
  1029. {
  1030. retro_log_printf_t log;
  1031. };
  1032. /* Performance related functions */
  1033. /* ID values for SIMD CPU features */
  1034. #define RETRO_SIMD_SSE (1 << 0)
  1035. #define RETRO_SIMD_SSE2 (1 << 1)
  1036. #define RETRO_SIMD_VMX (1 << 2)
  1037. #define RETRO_SIMD_VMX128 (1 << 3)
  1038. #define RETRO_SIMD_AVX (1 << 4)
  1039. #define RETRO_SIMD_NEON (1 << 5)
  1040. #define RETRO_SIMD_SSE3 (1 << 6)
  1041. #define RETRO_SIMD_SSSE3 (1 << 7)
  1042. #define RETRO_SIMD_MMX (1 << 8)
  1043. #define RETRO_SIMD_MMXEXT (1 << 9)
  1044. #define RETRO_SIMD_SSE4 (1 << 10)
  1045. #define RETRO_SIMD_SSE42 (1 << 11)
  1046. #define RETRO_SIMD_AVX2 (1 << 12)
  1047. #define RETRO_SIMD_VFPU (1 << 13)
  1048. #define RETRO_SIMD_PS (1 << 14)
  1049. #define RETRO_SIMD_AES (1 << 15)
  1050. typedef uint64_t retro_perf_tick_t;
  1051. typedef int64_t retro_time_t;
  1052. struct retro_perf_counter
  1053. {
  1054. const char *ident;
  1055. retro_perf_tick_t start;
  1056. retro_perf_tick_t total;
  1057. retro_perf_tick_t call_cnt;
  1058. bool registered;
  1059. };
  1060. /* Returns current time in microseconds.
  1061. * Tries to use the most accurate timer available.
  1062. */
  1063. typedef retro_time_t (*retro_perf_get_time_usec_t)(void);
  1064. /* A simple counter. Usually nanoseconds, but can also be CPU cycles.
  1065. * Can be used directly if desired (when creating a more sophisticated
  1066. * performance counter system).
  1067. * */
  1068. typedef retro_perf_tick_t (*retro_perf_get_counter_t)(void);
  1069. /* Returns a bit-mask of detected CPU features (RETRO_SIMD_*). */
  1070. typedef uint64_t (*retro_get_cpu_features_t)(void);
  1071. /* Asks frontend to log and/or display the state of performance counters.
  1072. * Performance counters can always be poked into manually as well.
  1073. */
  1074. typedef void (*retro_perf_log_t)(void);
  1075. /* Register a performance counter.
  1076. * ident field must be set with a discrete value and other values in
  1077. * retro_perf_counter must be 0.
  1078. * Registering can be called multiple times. To avoid calling to
  1079. * frontend redundantly, you can check registered field first. */
  1080. typedef void (*retro_perf_register_t)(struct retro_perf_counter *counter);
  1081. /* Starts a registered counter. */
  1082. typedef void (*retro_perf_start_t)(struct retro_perf_counter *counter);
  1083. /* Stops a registered counter. */
  1084. typedef void (*retro_perf_stop_t)(struct retro_perf_counter *counter);
  1085. /* For convenience it can be useful to wrap register, start and stop in macros.
  1086. * E.g.:
  1087. * #ifdef LOG_PERFORMANCE
  1088. * #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
  1089. * #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
  1090. * #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
  1091. * #else
  1092. * ... Blank macros ...
  1093. * #endif
  1094. *
  1095. * These can then be used mid-functions around code snippets.
  1096. *
  1097. * extern struct retro_perf_callback perf_cb; * Somewhere in the core.
  1098. *
  1099. * void do_some_heavy_work(void)
  1100. * {
  1101. * RETRO_PERFORMANCE_INIT(cb, work_1;
  1102. * RETRO_PERFORMANCE_START(cb, work_1);
  1103. * heavy_work_1();
  1104. * RETRO_PERFORMANCE_STOP(cb, work_1);
  1105. *
  1106. * RETRO_PERFORMANCE_INIT(cb, work_2);
  1107. * RETRO_PERFORMANCE_START(cb, work_2);
  1108. * heavy_work_2();
  1109. * RETRO_PERFORMANCE_STOP(cb, work_2);
  1110. * }
  1111. *
  1112. * void retro_deinit(void)
  1113. * {
  1114. * perf_cb.perf_log(); * Log all perf counters here for example.
  1115. * }
  1116. */
  1117. struct retro_perf_callback
  1118. {
  1119. retro_perf_get_time_usec_t get_time_usec;
  1120. retro_get_cpu_features_t get_cpu_features;
  1121. retro_perf_get_counter_t get_perf_counter;
  1122. retro_perf_register_t perf_register;
  1123. retro_perf_start_t perf_start;
  1124. retro_perf_stop_t perf_stop;
  1125. retro_perf_log_t perf_log;
  1126. };
  1127. /* FIXME: Document the sensor API and work out behavior.
  1128. * It will be marked as experimental until then.
  1129. */
  1130. enum retro_sensor_action
  1131. {
  1132. RETRO_SENSOR_ACCELEROMETER_ENABLE = 0,
  1133. RETRO_SENSOR_ACCELEROMETER_DISABLE,
  1134. RETRO_SENSOR_DUMMY = INT_MAX
  1135. };
  1136. /* Id values for SENSOR types. */
  1137. #define RETRO_SENSOR_ACCELEROMETER_X 0
  1138. #define RETRO_SENSOR_ACCELEROMETER_Y 1
  1139. #define RETRO_SENSOR_ACCELEROMETER_Z 2
  1140. typedef bool (*retro_set_sensor_state_t)(unsigned port,
  1141. enum retro_sensor_action action, unsigned rate);
  1142. typedef float (*retro_sensor_get_input_t)(unsigned port, unsigned id);
  1143. struct retro_sensor_interface
  1144. {
  1145. retro_set_sensor_state_t set_sensor_state;
  1146. retro_sensor_get_input_t get_sensor_input;
  1147. };
  1148. enum retro_camera_buffer
  1149. {
  1150. RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0,
  1151. RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER,
  1152. RETRO_CAMERA_BUFFER_DUMMY = INT_MAX
  1153. };
  1154. /* Starts the camera driver. Can only be called in retro_run(). */
  1155. typedef bool (*retro_camera_start_t)(void);
  1156. /* Stops the camera driver. Can only be called in retro_run(). */
  1157. typedef void (*retro_camera_stop_t)(void);
  1158. /* Callback which signals when the camera driver is initialized
  1159. * and/or deinitialized.
  1160. * retro_camera_start_t can be called in initialized callback.
  1161. */
  1162. typedef void (*retro_camera_lifetime_status_t)(void);
  1163. /* A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
  1164. * Width, height and pitch are similar to retro_video_refresh_t.
  1165. * First pixel is top-left origin.
  1166. */
  1167. typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer,
  1168. unsigned width, unsigned height, size_t pitch);
  1169. /* A callback for when OpenGL textures are used.
  1170. *
  1171. * texture_id is a texture owned by camera driver.
  1172. * Its state or content should be considered immutable, except for things like
  1173. * texture filtering and clamping.
  1174. *
  1175. * texture_target is the texture target for the GL texture.
  1176. * These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly
  1177. * more depending on extensions.
  1178. *
  1179. * affine points to a packed 3x3 column-major matrix used to apply an affine
  1180. * transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
  1181. * After transform, normalized texture coord (0, 0) should be bottom-left
  1182. * and (1, 1) should be top-right (or (width, height) for RECTANGLE).
  1183. *
  1184. * GL-specific typedefs are avoided here to avoid relying on gl.h in
  1185. * the API definition.
  1186. */
  1187. typedef void (*retro_camera_frame_opengl_texture_t)(unsigned texture_id,
  1188. unsigned texture_target, const float *affine);
  1189. struct retro_camera_callback
  1190. {
  1191. /* Set by libretro core.
  1192. * Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER).
  1193. */
  1194. uint64_t caps;
  1195. unsigned width; /* Desired resolution for camera. Is only used as a hint. */
  1196. unsigned height;
  1197. retro_camera_start_t start; /* Set by frontend. */
  1198. retro_camera_stop_t stop; /* Set by frontend. */
  1199. /* Set by libretro core if raw framebuffer callbacks will be used. */
  1200. retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer;
  1201. /* Set by libretro core if OpenGL texture callbacks will be used. */
  1202. retro_camera_frame_opengl_texture_t frame_opengl_texture;
  1203. /* Set by libretro core. Called after camera driver is initialized and
  1204. * ready to be started.
  1205. * Can be NULL, in which this callback is not called.
  1206. */
  1207. retro_camera_lifetime_status_t initialized;
  1208. /* Set by libretro core. Called right before camera driver is
  1209. * deinitialized.
  1210. * Can be NULL, in which this callback is not called.
  1211. */
  1212. retro_camera_lifetime_status_t deinitialized;
  1213. };
  1214. /* Sets the interval of time and/or distance at which to update/poll
  1215. * location-based data.
  1216. *
  1217. * To ensure compatibility with all location-based implementations,
  1218. * values for both interval_ms and interval_distance should be provided.
  1219. *
  1220. * interval_ms is the interval expressed in milliseconds.
  1221. * interval_distance is the distance interval expressed in meters.
  1222. */
  1223. typedef void (*retro_location_set_interval_t)(unsigned interval_ms,
  1224. unsigned interval_distance);
  1225. /* Start location services. The device will start listening for changes to the
  1226. * current location at regular intervals (which are defined with
  1227. * retro_location_set_interval_t). */
  1228. typedef bool (*retro_location_start_t)(void);
  1229. /* Stop location services. The device will stop listening for changes
  1230. * to the current location. */
  1231. typedef void (*retro_location_stop_t)(void);
  1232. /* Get the position of the current location. Will set parameters to
  1233. * 0 if no new location update has happened since the last time. */
  1234. typedef bool (*retro_location_get_position_t)(double *lat, double *lon,
  1235. double *horiz_accuracy, double *vert_accuracy);
  1236. /* Callback which signals when the location driver is initialized
  1237. * and/or deinitialized.
  1238. * retro_location_start_t can be called in initialized callback.
  1239. */
  1240. typedef void (*retro_location_lifetime_status_t)(void);
  1241. struct retro_location_callback
  1242. {
  1243. retro_location_start_t start;
  1244. retro_location_stop_t stop;
  1245. retro_location_get_position_t get_position;
  1246. retro_location_set_interval_t set_interval;
  1247. retro_location_lifetime_status_t initialized;
  1248. retro_location_lifetime_status_t deinitialized;
  1249. };
  1250. enum retro_rumble_effect
  1251. {
  1252. RETRO_RUMBLE_STRONG = 0,
  1253. RETRO_RUMBLE_WEAK = 1,
  1254. RETRO_RUMBLE_DUMMY = INT_MAX
  1255. };
  1256. /* Sets rumble state for joypad plugged in port 'port'.
  1257. * Rumble effects are controlled independently,
  1258. * and setting e.g. strong rumble does not override weak rumble.
  1259. * Strength has a range of [0, 0xffff].
  1260. *
  1261. * Returns true if rumble state request was honored.
  1262. * Calling this before first retro_run() is likely to return false. */
  1263. typedef bool (*retro_set_rumble_state_t)(unsigned port,
  1264. enum retro_rumble_effect effect, uint16_t strength);
  1265. struct retro_rumble_interface
  1266. {
  1267. retro_set_rumble_state_t set_rumble_state;
  1268. };
  1269. /* Notifies libretro that audio data should be written. */
  1270. typedef void (*retro_audio_callback_t)(void);
  1271. /* True: Audio driver in frontend is active, and callback is
  1272. * expected to be called regularily.
  1273. * False: Audio driver in frontend is paused or inactive.
  1274. * Audio callback will not be called until set_state has been
  1275. * called with true.
  1276. * Initial state is false (inactive).
  1277. */
  1278. typedef void (*retro_audio_set_state_callback_t)(bool enabled);
  1279. struct retro_audio_callback
  1280. {
  1281. retro_audio_callback_t callback;
  1282. retro_audio_set_state_callback_t set_state;
  1283. };
  1284. /* Notifies a libretro core of time spent since last invocation
  1285. * of retro_run() in microseconds.
  1286. *
  1287. * It will be called right before retro_run() every frame.
  1288. * The frontend can tamper with timing to support cases like
  1289. * fast-forward, slow-motion and framestepping.
  1290. *
  1291. * In those scenarios the reference frame time value will be used. */
  1292. typedef int64_t retro_usec_t;
  1293. typedef void (*retro_frame_time_callback_t)(retro_usec_t usec);
  1294. struct retro_frame_time_callback
  1295. {
  1296. retro_frame_time_callback_t callback;
  1297. /* Represents the time of one frame. It is computed as
  1298. * 1000000 / fps, but the implementation will resolve the
  1299. * rounding to ensure that framestepping, etc is exact. */
  1300. retro_usec_t reference;
  1301. };
  1302. /* Pass this to retro_video_refresh_t if rendering to hardware.
  1303. * Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
  1304. * */
  1305. #define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)
  1306. /* Invalidates the current HW context.
  1307. * Any GL state is lost, and must not be deinitialized explicitly.
  1308. * If explicit deinitialization is desired by the libretro core,
  1309. * it should implement context_destroy callback.
  1310. * If called, all GPU resources must be reinitialized.
  1311. * Usually called when frontend reinits video driver.
  1312. * Also called first time video driver is initialized,
  1313. * allowing libretro core to initialize resources.
  1314. */
  1315. typedef void (*retro_hw_context_reset_t)(void);
  1316. /* Gets current framebuffer which is to be rendered to.
  1317. * Could change every frame potentially.
  1318. */
  1319. typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void);
  1320. /* Get a symbol from HW context. */
  1321. typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym);
  1322. enum retro_hw_context_type
  1323. {
  1324. RETRO_HW_CONTEXT_NONE = 0,
  1325. /* OpenGL 2.x. Driver can choose to use latest compatibility context. */
  1326. RETRO_HW_CONTEXT_OPENGL = 1,
  1327. /* OpenGL ES 2.0. */
  1328. RETRO_HW_CONTEXT_OPENGLES2 = 2,
  1329. /* Modern desktop core GL context. Use version_major/
  1330. * version_minor fields to set GL version. */
  1331. RETRO_HW_CONTEXT_OPENGL_CORE = 3,
  1332. /* OpenGL ES 3.0 */
  1333. RETRO_HW_CONTEXT_OPENGLES3 = 4,
  1334. /* OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3,
  1335. * use the corresponding enums directly. */
  1336. RETRO_HW_CONTEXT_OPENGLES_VERSION = 5,
  1337. RETRO_HW_CONTEXT_DUMMY = INT_MAX
  1338. };
  1339. struct retro_hw_render_callback
  1340. {
  1341. /* Which API to use. Set by libretro core. */
  1342. enum retro_hw_context_type context_type;
  1343. /* Called when a context has been created or when it has been reset.
  1344. * An OpenGL context is only valid after context_reset() has been called.
  1345. *
  1346. * When context_reset is called, OpenGL resources in the libretro
  1347. * implementation are guaranteed to be invalid.
  1348. *
  1349. * It is possible that context_reset is called multiple times during an
  1350. * application lifecycle.
  1351. * If context_reset is called without any notification (context_destroy),
  1352. * the OpenGL context was lost and resources should just be recreated
  1353. * without any attempt to "free" old resources.
  1354. */
  1355. retro_hw_context_reset_t context_reset;
  1356. /* Set by frontend. */
  1357. retro_hw_get_current_framebuffer_t get_current_framebuffer;
  1358. /* Set by frontend. */
  1359. retro_hw_get_proc_address_t get_proc_address;
  1360. /* Set if render buffers should have depth component attached. */
  1361. bool depth;
  1362. /* Set if stencil buffers should be attached. */
  1363. bool stencil;
  1364. /* If depth and stencil are true, a packed 24/8 buffer will be added.
  1365. * Only attaching stencil is invalid and will be ignored. */
  1366. /* Use conventional bottom-left origin convention. If false,
  1367. * standard libretro top-left origin semantics are used. */
  1368. bool bottom_left_origin;
  1369. /* Major version number for core GL context or GLES 3.1+. */
  1370. unsigned version_major;
  1371. /* Minor version number for core GL context or GLES 3.1+. */
  1372. unsigned version_minor;
  1373. /* If this is true, the frontend will go very far to avoid
  1374. * resetting context in scenarios like toggling fullscreen, etc.
  1375. */
  1376. bool cache_context;
  1377. /* The reset callback might still be called in extreme situations
  1378. * such as if the context is lost beyond recovery.
  1379. *
  1380. * For optimal stability, set this to false, and allow context to be
  1381. * reset at any time.
  1382. */
  1383. /* A callback to be called before the context is destroyed in a
  1384. * controlled way by the frontend. */
  1385. retro_hw_context_reset_t context_destroy;
  1386. /* OpenGL resources can be deinitialized cleanly at this step.
  1387. * context_destroy can be set to NULL, in which resources will
  1388. * just be destroyed without any notification.
  1389. *
  1390. * Even when context_destroy is non-NULL, it is possible that
  1391. * context_reset is called without any destroy notification.
  1392. * This happens if context is lost by external factors (such as
  1393. * notified by GL_ARB_robustness).
  1394. *
  1395. * In this case, the context is assumed to be already dead,
  1396. * and the libretro implementation must not try to free any OpenGL
  1397. * resources in the subsequent context_reset.
  1398. */
  1399. /* Creates a debug context. */
  1400. bool debug_context;
  1401. };
  1402. /* Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
  1403. * Called by the frontend in response to keyboard events.
  1404. * down is set if the key is being pressed, or false if it is being released.
  1405. * keycode is the RETROK value of the char.
  1406. * character is the text character of the pressed key. (UTF-32).
  1407. * key_modifiers is a set of RETROKMOD values or'ed together.
  1408. *
  1409. * The pressed/keycode state can be indepedent of the character.
  1410. * It is also possible that multiple characters are generated from a
  1411. * single keypress.
  1412. * Keycode events should be treated separately from character events.
  1413. * However, when possible, the frontend should try to synchronize these.
  1414. * If only a character is posted, keycode should be RETROK_UNKNOWN.
  1415. *
  1416. * Similarily if only a keycode event is generated with no corresponding
  1417. * character, character should be 0.
  1418. */
  1419. typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode,
  1420. uint32_t character, uint16_t key_modifiers);
  1421. struct retro_keyboard_callback
  1422. {
  1423. retro_keyboard_event_t callback;
  1424. };
  1425. /* Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
  1426. * Should be set for implementations which can swap out multiple disk
  1427. * images in runtime.
  1428. *
  1429. * If the implementation can do this automatically, it should strive to do so.
  1430. * However, there are cases where the user must manually do so.
  1431. *
  1432. * Overview: To swap a disk image, eject the disk image with
  1433. * set_eject_state(true).
  1434. * Set the disk index with set_image_index(index). Insert the disk again
  1435. * with set_eject_state(false).
  1436. */
  1437. /* If ejected is true, "ejects" the virtual disk tray.
  1438. * When ejected, the disk image index can be set.
  1439. */
  1440. typedef bool (*retro_set_eject_state_t)(bool ejected);
  1441. /* Gets current eject state. The initial state is 'not ejected'. */
  1442. typedef bool (*retro_get_eject_state_t)(void);
  1443. /* Gets current disk index. First disk is index 0.
  1444. * If return value is >= get_num_images(), no disk is currently inserted.
  1445. */
  1446. typedef unsigned (*retro_get_image_index_t)(void);
  1447. /* Sets image index. Can only be called when disk is ejected.
  1448. * The implementation supports setting "no disk" by using an
  1449. * index >= get_num_images().
  1450. */
  1451. typedef bool (*retro_set_image_index_t)(unsigned index);
  1452. /* Gets total number of images which are available to use. */
  1453. typedef unsigned (*retro_get_num_images_t)(void);
  1454. struct retro_game_info;
  1455. /* Replaces the disk image associated with index.
  1456. * Arguments to pass in info have same requirements as retro_load_game().
  1457. * Virtual disk tray must be ejected when calling this.
  1458. *
  1459. * Replacing a disk image with info = NULL will remove the disk image
  1460. * from the internal list.
  1461. * As a result, calls to get_image_index() can change.
  1462. *
  1463. * E.g. replace_image_index(1, NULL), and previous get_image_index()
  1464. * returned 4 before.
  1465. * Index 1 will be removed, and the new index is 3.
  1466. */
  1467. typedef bool (*retro_replace_image_index_t)(unsigned index,
  1468. const struct retro_game_info *info);
  1469. /* Adds a new valid index (get_num_images()) to the internal disk list.
  1470. * This will increment subsequent return values from get_num_images() by 1.
  1471. * This image index cannot be used until a disk image has been set
  1472. * with replace_image_index. */
  1473. typedef bool (*retro_add_image_index_t)(void);
  1474. struct retro_disk_control_callback
  1475. {
  1476. retro_set_eject_state_t set_eject_state;
  1477. retro_get_eject_state_t get_eject_state;
  1478. retro_get_image_index_t get_image_index;
  1479. retro_set_image_index_t set_image_index;
  1480. retro_get_num_images_t get_num_images;
  1481. retro_replace_image_index_t replace_image_index;
  1482. retro_add_image_index_t add_image_index;
  1483. };
  1484. enum retro_pixel_format
  1485. {
  1486. /* 0RGB1555, native endian.
  1487. * 0 bit must be set to 0.
  1488. * This pixel format is default for compatibility concerns only.
  1489. * If a 15/16-bit pixel format is desired, consider using RGB565. */
  1490. RETRO_PIXEL_FORMAT_0RGB1555 = 0,
  1491. /* XRGB8888, native endian.
  1492. * X bits are ignored. */
  1493. RETRO_PIXEL_FORMAT_XRGB8888 = 1,
  1494. /* RGB565, native endian.
  1495. * This pixel format is the recommended format to use if a 15/16-bit
  1496. * format is desired as it is the pixel format that is typically
  1497. * available on a wide range of low-power devices.
  1498. *
  1499. * It is also natively supported in APIs like OpenGL ES. */
  1500. RETRO_PIXEL_FORMAT_RGB565 = 2,
  1501. /* Ensure sizeof() == sizeof(int). */
  1502. RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX
  1503. };
  1504. struct retro_message
  1505. {
  1506. const char *msg; /* Message to be displayed. */
  1507. unsigned frames; /* Duration in frames of message. */
  1508. };
  1509. /* Describes how the libretro implementation maps a libretro input bind
  1510. * to its internal input system through a human readable string.
  1511. * This string can be used to better let a user configure input. */
  1512. struct retro_input_descriptor
  1513. {
  1514. /* Associates given parameters with a description. */
  1515. unsigned port;
  1516. unsigned device;
  1517. unsigned index;
  1518. unsigned id;
  1519. /* Human readable description for parameters.
  1520. * The pointer must remain valid until
  1521. * retro_unload_game() is called. */
  1522. const char *description;
  1523. };
  1524. struct retro_system_info
  1525. {
  1526. /* All pointers are owned by libretro implementation, and pointers must
  1527. * remain valid until retro_deinit() is called. */
  1528. const char *library_name; /* Descriptive name of library. Should not
  1529. * contain any version numbers, etc. */
  1530. const char *library_version; /* Descriptive version of core. */
  1531. const char *valid_extensions; /* A string listing probably content
  1532. * extensions the core will be able to
  1533. * load, separated with pipe.
  1534. * I.e. "bin|rom|iso".
  1535. * Typically used for a GUI to filter
  1536. * out extensions. */
  1537. /* If true, retro_load_game() is guaranteed to provide a valid pathname
  1538. * in retro_game_info::path.
  1539. * ::data and ::size are both invalid.
  1540. *
  1541. * If false, ::data and ::size are guaranteed to be valid, but ::path
  1542. * might not be valid.
  1543. *
  1544. * This is typically set to true for libretro implementations that must
  1545. * load from file.
  1546. * Implementations should strive for setting this to false, as it allows
  1547. * the frontend to perform patching, etc. */
  1548. bool need_fullpath;
  1549. /* If true, the frontend is not allowed to extract any archives before
  1550. * loading the real content.
  1551. * Necessary for certain libretro implementations that load games
  1552. * from zipped archives. */
  1553. bool block_extract;
  1554. };
  1555. struct retro_game_geometry
  1556. {
  1557. unsigned base_width; /* Nominal video width of game. */
  1558. unsigned base_height; /* Nominal video height of game. */
  1559. unsigned max_width; /* Maximum possible width of game. */
  1560. unsigned max_height; /* Maximum possible height of game. */
  1561. float aspect_ratio; /* Nominal aspect ratio of game. If
  1562. * aspect_ratio is <= 0.0, an aspect ratio
  1563. * of base_width / base_height is assumed.
  1564. * A frontend could override this setting,
  1565. * if desired. */
  1566. };
  1567. struct retro_system_timing
  1568. {
  1569. double fps; /* FPS of video content. */
  1570. double sample_rate; /* Sampling rate of audio. */
  1571. };
  1572. struct retro_system_av_info
  1573. {
  1574. struct retro_game_geometry geometry;
  1575. struct retro_system_timing timing;
  1576. };
  1577. struct retro_variable
  1578. {
  1579. /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.
  1580. * If NULL, obtains the complete environment string if more
  1581. * complex parsing is necessary.
  1582. * The environment string is formatted as key-value pairs
  1583. * delimited by semicolons as so:
  1584. * "key1=value1;key2=value2;..."
  1585. */
  1586. const char *key;
  1587. /* Value to be obtained. If key does not exist, it is set to NULL. */
  1588. const char *value;
  1589. };
  1590. struct retro_game_info
  1591. {
  1592. const char *path; /* Path to game, UTF-8 encoded.
  1593. * Usually used as a reference.
  1594. * May be NULL if rom was loaded from stdin
  1595. * or similar.
  1596. * retro_system_info::need_fullpath guaranteed
  1597. * that this path is valid. */
  1598. const void *data; /* Memory buffer of loaded game. Will be NULL
  1599. * if need_fullpath was set. */
  1600. size_t size; /* Size of memory buffer. */
  1601. const char *meta; /* String of implementation specific meta-data. */
  1602. };
  1603. /* Callbacks */
  1604. /* Environment callback. Gives implementations a way of performing
  1605. * uncommon tasks. Extensible. */
  1606. typedef bool (*retro_environment_t)(unsigned cmd, void *data);
  1607. /* Render a frame. Pixel format is 15-bit 0RGB1555 native endian
  1608. * unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
  1609. *
  1610. * Width and height specify dimensions of buffer.
  1611. * Pitch specifices length in bytes between two lines in buffer.
  1612. *
  1613. * For performance reasons, it is highly recommended to have a frame
  1614. * that is packed in memory, i.e. pitch == width * byte_per_pixel.
  1615. * Certain graphic APIs, such as OpenGL ES, do not like textures
  1616. * that are not packed in memory.
  1617. */
  1618. typedef void (*retro_video_refresh_t)(const void *data, unsigned width,
  1619. unsigned height, size_t pitch);
  1620. /* Renders a single audio frame. Should only be used if implementation
  1621. * generates a single sample at a time.
  1622. * Format is signed 16-bit native endian.
  1623. */
  1624. typedef void (*retro_audio_sample_t)(int16_t left, int16_t right);
  1625. /* Renders multiple audio frames in one go.
  1626. *
  1627. * One frame is defined as a sample of left and right channels, interleaved.
  1628. * I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
  1629. * Only one of the audio callbacks must ever be used.
  1630. */
  1631. typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data,
  1632. size_t frames);
  1633. /* Polls input. */
  1634. typedef void (*retro_input_poll_t)(void);
  1635. /* Queries for input for player 'port'. device will be masked with
  1636. * RETRO_DEVICE_MASK.
  1637. *
  1638. * Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that
  1639. * have been set with retro_set_controller_port_device()
  1640. * will still use the higher level RETRO_DEVICE_JOYPAD to request input.
  1641. */
  1642. typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device,
  1643. unsigned index, unsigned id);
  1644. /* Sets callbacks. retro_set_environment() is guaranteed to be called
  1645. * before retro_init().
  1646. *
  1647. * The rest of the set_* functions are guaranteed to have been called
  1648. * before the first call to retro_run() is made. */
  1649. void retro_set_environment(retro_environment_t);
  1650. void retro_set_video_refresh(retro_video_refresh_t);
  1651. void retro_set_audio_sample(retro_audio_sample_t);
  1652. void retro_set_audio_sample_batch(retro_audio_sample_batch_t);
  1653. void retro_set_input_poll(retro_input_poll_t);
  1654. void retro_set_input_state(retro_input_state_t);
  1655. /* Library global initialization/deinitialization. */
  1656. void retro_init(void);
  1657. void retro_deinit(void);
  1658. /* Must return RETRO_API_VERSION. Used to validate ABI compatibility
  1659. * when the API is revised. */
  1660. unsigned retro_api_version(void);
  1661. /* Gets statically known system info. Pointers provided in *info
  1662. * must be statically allocated.
  1663. * Can be called at any time, even before retro_init(). */
  1664. void retro_get_system_info(struct retro_system_info *info);
  1665. /* Gets information about system audio/video timings and geometry.
  1666. * Can be called only after retro_load_game() has successfully completed.
  1667. * NOTE: The implementation of this function might not initialize every
  1668. * variable if needed.
  1669. * E.g. geom.aspect_ratio might not be initialized if core doesn't
  1670. * desire a particular aspect ratio. */
  1671. void retro_get_system_av_info(struct retro_system_av_info *info);
  1672. /* Sets device to be used for player 'port'.
  1673. * By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all
  1674. * available ports.
  1675. * Setting a particular device type is not a guarantee that libretro cores
  1676. * will only poll input based on that particular device type. It is only a
  1677. * hint to the libretro core when a core cannot automatically detect the
  1678. * appropriate input device type on its own. It is also relevant when a
  1679. * core can change its behavior depending on device type. */
  1680. void retro_set_controller_port_device(unsigned port, unsigned device);
  1681. /* Resets the current game. */
  1682. void retro_reset(void);
  1683. /* Runs the game for one video frame.
  1684. * During retro_run(), input_poll callback must be called at least once.
  1685. *
  1686. * If a frame is not rendered for reasons where a game "dropped" a frame,
  1687. * this still counts as a frame, and retro_run() should explicitly dupe
  1688. * a frame if GET_CAN_DUPE returns true.
  1689. * In this case, the video callback can take a NULL argument for data.
  1690. */
  1691. void retro_run(void);
  1692. /* Returns the amount of data the implementation requires to serialize
  1693. * internal state (save states).
  1694. * Between calls to retro_load_game() and retro_unload_game(), the
  1695. * returned size is never allowed to be larger than a previous returned
  1696. * value, to ensure that the frontend can allocate a save state buffer once.
  1697. */
  1698. size_t retro_serialize_size(void);
  1699. /* Serializes internal state. If failed, or size is lower than
  1700. * retro_serialize_size(), it should return false, true otherwise. */
  1701. bool retro_serialize(void *data, size_t size);
  1702. bool retro_unserialize(const void *data, size_t size);
  1703. void retro_cheat_reset(void);
  1704. void retro_cheat_set(unsigned index, bool enabled, const char *code);
  1705. /* Loads a game. */
  1706. bool retro_load_game(const struct retro_game_info *game);
  1707. /* Loads a "special" kind of game. Should not be used,
  1708. * except in extreme cases. */
  1709. bool retro_load_game_special(
  1710. unsigned game_type,
  1711. const struct retro_game_info *info, size_t num_info
  1712. );
  1713. /* Unloads a currently loaded game. */
  1714. void retro_unload_game(void);
  1715. /* Gets region of game. */
  1716. unsigned retro_get_region(void);
  1717. /* Gets region of memory. */
  1718. void *retro_get_memory_data(unsigned id);
  1719. size_t retro_get_memory_size(unsigned id);
  1720. #ifdef __cplusplus
  1721. }
  1722. #endif
  1723. #endif