Lua: Fix type confusion between signed and unsigned
[lsnes.git] / include / interface / c-interface.h
blob201c2f947e315fba4663f6095f768904db425e6f
1 #ifndef _interface__c_interface__h__included__
2 #define _interface__c_interface__h__included__
4 /*
6 Copyright (c) 2013 Ilari Liusvaara
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
28 /**
29 * Some general information about the interface:
30 * - The parameter type for LSNES_CORE_FOO is struct lsnes_core_foo*
31 * - There are also some other enumerations/structures.
32 * - The only exposed entry point (lsnes_core_entrypoint) has fp type of lsnes_core_func_t.
33 * - By nature, this interface does not reference any symbols (exception is lsnes_register_builtin_core).
34 * - Some fields may be conditional on API version.
35 * - The following functions are required:
36 * * LSNES_CORE_ENUMERATE_CORES
37 * * LSNES_CORE_GET_CORE_INFO
38 * * LSNES_CORE_GET_TYPE_INFO
39 * * LSNES_CORE_GET_REGION_INFO
40 * * LSNES_CORE_GET_SYSREGION_INFO
41 * * LSNES_CORE_GET_AV_STATE
42 * * LSNES_CORE_EMULATE
43 * * LSNES_CORE_SAVESTATE
44 * * LSNES_CORE_LOADSTATE
45 * * LSNES_CORE_GET_CONTROLLERCONFIG
46 * * LSNES_CORE_LOAD_ROM
47 * - Scratch buffers from emulator side last for duration of the call.
48 * - Scratch buffers form core side last until next call.
49 * - Never free buffer from emulator in core or vice versa.
50 * - The spaces for Core, Type, Region and Sysregion IDs are distinct.
51 * - If you only have one region, use ID of 0 for that and GET_REGION/SET_REGION are not needed.
54 #include <unistd.h>
55 #include <stdint.h>
56 #include <time.h>
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
62 //API version.
63 #define LSNES_CORE_API 0
65 /** Constants. **/
66 //VMA is read-only.
67 #define LSNES_CORE_VMA_READONLY 1
68 //VMA has special semantics (no read/write consistency).
69 #define LSNES_CORE_VMA_SPECIAL 2
70 //VMA is volatile (and uninitialized on poweron).
71 #define LSNES_CORE_VMA_VOLATILE 4
73 /** Capabilities. **/
74 //Core supports multiple regions (By supporting LSNES_CORE_GET_REGION/LSNES_CORE_SET_REGION).
75 #define LSNES_CORE_CAP1_MULTIREGION 0x00000001U
76 //Core supports poll flags (By supporting LSNES_CORE_GET_PFLAG/LSNES_CORE_SET_PFLAG).
77 #define LSNES_CORE_CAP1_PFLAG 0x00000002U
78 //Core supports actions (By supporting LSNES_CORE_GET_ACTION_FLAGS/LSNES_CORE_EXECUTE_ACTION).
79 #define LSNES_CORE_CAP1_ACTION 0x00000004U
80 //Core supports bus map (By supporting LSNES_CORE_GET_BUS_MAPPING).
81 #define LSNES_CORE_CAP1_BUSMAP 0x00000008U
82 //Core supports SRAM (By supporting LSNES_CORE_ENUMERATE_SRAM/LSNES_CORE_LOAD_SRAM/LSNES_CORE_SAVE_SRAM).
83 #define LSNES_CORE_CAP1_SRAM 0x00000010U
84 //Core supports resets (By supporting LSNES_CORE_GET_RESET_ACTION). LSNES_CORE_CAP1_ACTION is required.
85 #define LSNES_CORE_CAP1_RESET 0x00000020U
86 //Core supports custom scale computation (By supporting LSNES_CORE_COMPUTE_SCALE).
87 #define LSNES_CORE_CAP1_SCALE 0x00000040U
88 //Core supports explicit save points (By supporting LSNES_CORE_RUNTOSAVE).
89 #define LSNES_CORE_CAP1_RUNTOSAVE 0x00000080U
90 //Core supports powerons (By supporting LSNES_CORE_POWERON).
91 #define LSNES_CORE_CAP1_POWERON 0x00000100U
92 //Core supports cartridge unload (By supporting LSNES_CORE_UNLOAD_CARTRIDGE).
93 #define LSNES_CORE_CAP1_UNLOAD 0x00000200U
94 //Core supports debugging (By supporting LSNES_CORE_DEBUG_RESET and LSNES_CORE_SET_DEBUG_FLAGS[breakpoints]).
95 //LSNES_CORE_CAP1_MEMWATCH is required.
96 #define LSNES_CORE_CAP1_DEBUG 0x00000400U
97 //Core supports tracing (By supporting LSNES_CORE_DEBUG_RESET and LSNES_CORE_SET_DEBUG_FLAGS[tracing]).
98 //LSNES_CORE_CAP1_MEMWATCH is required.
99 #define LSNES_CORE_CAP1_TRACE 0x00000800U
100 //Core supports cheating (By supporting LSNES_CORE_DEBUG_RESET and LSNES_CORE_SET_CHEAT).
101 //LSNES_CORE_CAP1_MEMWATCH is required.
102 #define LSNES_CORE_CAP1_CHEAT 0x00001000U
103 //Core supports cover pages (By supporting LSNES_CORE_DRAW_COVER).
104 #define LSNES_CORE_CAP1_COVER 0x00002000U
105 //Core supports pre-emulate (By supporting LSNES_CORE_PRE_EMULATE).
106 #define LSNES_CORE_CAP1_PREEMULATE 0x00004000U
107 //Core supports registers (By supporting LSNES_CORE_GET_DEVICE_REGS).
108 #define LSNES_CORE_CAP1_REGISTERS 0x00008000U
109 //Core supports memory watch (By supporting LSNES_CORE_GET_VMA_LIST).
110 #define LSNES_CORE_CAP1_MEMWATCH 0x00010000U
111 //Core supports lightguns (By setting lightgun_height/lightgun_width in LSNES_CORE_GET_AV_STATE).
112 #define LSNES_CORE_CAP1_LIGHTGUN 0x00020000U
113 //Core supports fast reinit (By supporting LSNES_CORE_REINIT).
114 #define LSNES_CORE_CAP1_REINIT 0x00040000U
115 //Reserved capabilities.
116 #define LSNES_CORE_CAP1_RESERVED19 0x00080000U
117 #define LSNES_CORE_CAP1_RESERVED20 0x00100000U
118 #define LSNES_CORE_CAP1_RESERVED21 0x00200000U
119 #define LSNES_CORE_CAP1_RESERVED22 0x00400000U
120 #define LSNES_CORE_CAP1_RESERVED23 0x00800000U
121 #define LSNES_CORE_CAP1_RESERVED24 0x01000000U
122 #define LSNES_CORE_CAP1_RESERVED25 0x02000000U
123 #define LSNES_CORE_CAP1_RESERVED26 0x04000000U
124 #define LSNES_CORE_CAP1_RESERVED27 0x08000000U
125 #define LSNES_CORE_CAP1_RESERVED28 0x10000000U
126 #define LSNES_CORE_CAP1_RESERVED29 0x20000000U
127 #define LSNES_CORE_CAP1_RESERVED30 0x40000000U
128 #define LSNES_CORE_CAP1_CAPS2 0x80000000U
130 #define LSNES_END_OF_LIST 0xFFFFFFFFU
132 //Do action <action> on item <item> with parameters <params>.
133 //If successful, return 0.
134 //If supported but unsuccessful, return -1 and fill <error> (will not be released, only needs to be stable to next
135 //call).
136 //In dynamic libs, this is looked up as lsnes_core_fn.
137 typedef int(*lsnes_core_func_t)(unsigned action, unsigned item, void* params, const char** error);
139 //Pixel format.
140 enum lsnes_core_pixel_format
142 LSNES_CORE_PIXFMT_RGB15,
143 LSNES_CORE_PIXFMT_BGR15,
144 LSNES_CORE_PIXFMT_RGB16,
145 LSNES_CORE_PIXFMT_BGR16,
146 LSNES_CORE_PIXFMT_RGB24,
147 LSNES_CORE_PIXFMT_BGR24,
148 LSNES_CORE_PIXFMT_RGB32,
149 LSNES_CORE_PIXFMT_LRGB
152 //Framebuffer.
153 struct lsnes_core_framebuffer_info
155 //Pixel format of framebuffer.
156 enum lsnes_core_pixel_format type;
157 //The physical memory backing the framebuffer.
158 const char* mem;
159 //Physical width of framebuffer.
160 size_t physwidth;
161 //Physical height of framebuffer.
162 size_t physheight;
163 //Physical stride of framebuffer (in bytes).
164 size_t physstride;
165 //Visible width of framebuffer.
166 size_t width;
167 //Visible height of framebuffer.
168 size_t height;
169 //Visible stride of framebuffer (in bytes).
170 size_t stride;
171 //Visible X offset of framebuffer.
172 size_t offset_x;
173 //Visible Y offset of framebuffer.
174 size_t offset_y;
177 struct lsnes_core_sram
179 //Name.
180 const char* name;
181 //Content size.
182 size_t size;
183 //Data.
184 const char* data;
187 struct lsnes_core_system_setting
189 //Name.
190 const char* name;
191 //Value.
192 const char* value;
195 struct lsnes_core_disassembler
197 //Name.
198 const char* name;
199 //Routine.
200 const char* (*fn)(uint64_t base, unsigned char(*fetch)(void* ctx), void* ctx);
203 //Font rendering request.
204 struct lsnes_core_fontrender_req
206 //Input: Context to pass to callbacks.
207 void* cb_ctx;
208 //Input: Allocate bitmap memory.
209 //cb_ctx => cb_ctx from above.
210 //mem_size => Number of bytes needed to allocate.
211 //return buffer at least mem_size bytes. Or return NULL on error.
212 void* (*alloc)(void* cb_ctx, size_t mem_size);
213 //Input: Text to render (UTF-8).
214 const char* text;
215 //Input: Length of text in bytes. If negative, text is null-terminated.
216 ssize_t text_len;
217 //Input: Bytes per pixel to request. Can be 1, 2, 3 or 4.
218 unsigned bytes_pp;
219 //Input: Foreground color (native endian).
220 unsigned fg_color;
221 //Input: Background color (native endian).
222 unsigned bg_color;
223 //Output: The allocated bitmap (this comes from ->alloc). Not released on failure.
224 void* bitmap;
225 //Output: Width of the bitmap.
226 size_t width;
227 //Output: Height of the bitmap.
228 size_t height;
231 //Request 0: Initialize and enumerate cores.
232 //Item: 0.
233 //Default action: (required)
234 //Called as the first call. Do the needed initialization and return list of core IDs.
235 #define LSNES_CORE_ENUMERATE_CORES 0
236 struct lsnes_core_enumerate_cores
238 //Output: List of sysregion ids. Terminated by 0xFFFFFFFF.
239 unsigned* sysregions;
240 //Input: Emulator capability flags 1.
241 unsigned emu_flags1;
242 //Input: Function to print message line.
243 void (*message)(const char* msg, size_t length);
244 //Input: Get input.
245 short (*get_input)(unsigned port, unsigned index, unsigned control);
246 //Input: Notify that state of action has updated.
247 void (*notify_action_update)();
248 //Input: Notify that time has ticked.
249 void (*timer_tick)(uint32_t increment, uint32_t per_second);
250 //Input: Get firmware path. The return value is temporary.
251 const char* (*get_firmware_path)();
252 //Input: Get cartridge base path. The return value is temporary.
253 const char* (*get_base_path)();
254 //Input: Get current time.
255 time_t (*get_time)();
256 //Input: Get random seed.
257 time_t (*get_randomseed)();
258 //Input: Notify that memory has been read.
259 void (*memory_read)(uint64_t addr, uint64_t value);
260 //Input: Notify that memory is about to be written.
261 void (*memory_write)(uint64_t addr, uint64_t value);
262 //Input: Notify that memory is about to be executed.
263 void (*memory_execute)(uint64_t addr, uint64_t cpunum);
264 //Input: Notify memory trace event. Str needs to be valid during call.
265 void (*memory_trace)(uint64_t proc, const char* str, int insn);
266 //Input: Submit sound.
267 void (*submit_sound)(const int16_t* samples, size_t count, int stereo, double rate);
268 //Input: Notify latch event. Parameters are NULL-terminated and need to be remain during call.
269 void (*notify_latch)(const char** params);
270 //Input: Output a frame.
271 void (*submit_frame)(struct lsnes_core_framebuffer_info* fb, uint32_t fps_n, uint32_t fps_d);
272 //Input: Add disassembler. Only available if emu_flags1>=1.
273 void* (*add_disasm)(struct lsnes_core_disassembler* disasm);
274 //Input: Remove disassembler. Only available if emu_flags1>=1.
275 void (*remove_disasm)(void* handle);
276 //Input: Render text into bitmap. Returns 0 on success, -1 on failure. Only available if emu_flags>=2.
277 int (*render_text)(struct lsnes_core_fontrender_req* req);
280 //Request 1: Request information about core.
281 //Item id: Core ID.
282 //Default action: (required)
283 //Obtain information about core.
284 #define LSNES_CORE_GET_CORE_INFO 1
285 struct lsnes_core_get_core_info_aparam
287 //Name of the parameter.
288 const char* name;
289 //Model:
290 //bool: boolean
291 //int:<val>,<val>: Integer in specified range.
292 //string[:<regex>]: String with regex.
293 //enum:<json-array-of-strings>: Enumeration.
294 //toggle: Not a real parameter, boolean toggle, must be the first.
295 const char* model;
297 struct lsnes_core_get_core_info_action
299 //Internal id of the action.
300 int id;
301 //Internal name of the action.
302 const char* iname;
303 //Human-readable Name of the action
304 const char* hname;
305 //Array of parameters. Terminated by parameter with NULL name.
306 struct lsnes_core_get_core_info_aparam* parameters;
308 struct lsnes_core_get_core_info
310 //Output: The JSON text.
311 const char* json;
312 //Output: JSON pointer to root of the port array.
313 const char* root_ptr;
314 //Output: Short core name.
315 const char* shortname;
316 //Output: Full core name.
317 const char* fullname;
318 //Output: Capability flags #1 (LSNES_CORE_CAP1_*).
319 unsigned cap_flags1;
320 //Output: Array of actions. Terminated by action with NUL iname. Only if LSNES_CORE_CAP1_ACTION is set.
321 struct lsnes_core_get_core_info_action* actions;
322 //Output: List of trace CPUs. Terminated by NULL. Only if LSNES_CORE_CAP1_TRACE is set.
323 const char** trace_cpu_list;
326 //Request 2: Request information about system type.
327 //Item id: Type ID.
328 //Default action: (required)
329 //Obtain information about system type.
330 #define LSNES_CORE_GET_TYPE_INFO 2
331 struct lsnes_core_get_type_info_paramval
333 const char* iname;
334 const char* hname;
335 signed index;
337 struct lsnes_core_get_type_info_param
339 //Internal name.
340 const char* iname;
341 //Human-readable name.
342 const char* hname;
343 //Default value.
344 const char* dflt;
345 //Enumeration of values (if enumerated, ended by value with NULL iname).
346 //If values are false and true, this is boolean.
347 struct lsnes_core_get_type_info_paramval* values;
348 //Validation regex (only for non-enumerated).
349 const char* regex;
351 struct lsnes_core_get_type_info_romimage
353 //Internal name.
354 const char* iname;
355 //Human-readable name.
356 const char* hname;
357 //Mandatory mask (OR of all preset ones must equal OR of all).
358 unsigned mandatory;
359 //Pass mode: 0 => Content. 1 => Filename, 2 => Directory.
360 int pass_mode;
361 //Optional header size.
362 unsigned headersize;
363 //Standard extensions (split by ;).
364 const char* extensions;
366 struct lsnes_core_get_type_info
368 //Output: ID of core emulating this.
369 unsigned core;
370 //Output: internal name.
371 const char* iname;
372 //Output: human-readable name.
373 const char* hname;
374 //Output: Short System name (e.g. SNES).
375 const char* sysname;
376 //Output: BIOS name.
377 const char* bios;
378 //Output: List of regions. Terminated by 0xFFFFFFFF.
379 unsigned* regions;
380 //Output: List of images. Terminated by image with NULL iname.
381 struct lsnes_core_get_type_info_romimage* images;
382 //Output: List of settings. Terminated by setting with NULL iname.
383 struct lsnes_core_get_type_info_param* settings;
386 //Request 3: Request information about region.
387 //Item id: Region ID.
388 //Default action: (required)
389 //Obtain information about region.
390 #define LSNES_CORE_GET_REGION_INFO 3
391 struct lsnes_core_get_region_info
393 //Output: Internal name.
394 const char* iname;
395 //Output: Human-readable name.
396 const char* hname;
397 //Output: Priority
398 unsigned priority;
399 //Output: Multi-region flag.
400 int multi;
401 //Output: Fps numerator.
402 uint32_t fps_n;
403 //Output: Fps denomerator.
404 uint32_t fps_d;
405 //Output: Compatible run regions, ended with 0xFFFFFFFF.
406 unsigned* compatible_runs;
409 //Request 4: Get sysregion info.
410 //Item id: Sysregion ID.
411 //Default action: (required)
412 //Get information about specific sysregion.
413 #define LSNES_CORE_GET_SYSREGION_INFO 4
414 struct lsnes_core_get_sysregion_info
416 //Output: The name of sysregion.
417 const char* name;
418 //Output: The type ID.
419 unsigned type;
420 //Output: The region ID.
421 unsigned region;
422 //Output: The system name this is for.
423 const char* for_system;
427 //Request 5: Get current A/V state.
428 //Item: Core ID.
429 //Default action: (required)
430 //Fill the structure with current A/V state.
431 #define LSNES_CORE_GET_AV_STATE 5
432 struct lsnes_core_get_av_state
434 uint32_t fps_n;
435 uint32_t fps_d;
436 double par;
437 uint32_t rate_n;
438 uint32_t rate_d;
439 unsigned lightgun_width;
440 unsigned lightgun_height;
444 //Request 6: Emulate a frame
445 //Item: Core ID.
446 //Default action: (required).
447 //Emulate a frame and output the video and audio data resulting.
448 #define LSNES_CORE_EMULATE 6
449 struct lsnes_core_emulate
453 //Request 7: Save state.
454 //Item: Core ID.
455 //Default action: (required).
456 //Save core state.
457 #define LSNES_CORE_SAVESTATE 7
458 struct lsnes_core_savestate
460 //Output: Size of the savestate.
461 size_t size;
462 //Output: Savestate data. Only needs to be stable to next call.
463 const char* data;
466 //Request 8: Load state.
467 //Item: Core ID.
468 //Default action: (required).
469 //Load core state.
470 #define LSNES_CORE_LOADSTATE 8
471 struct lsnes_core_loadstate
473 //Input: Size of the savestate.
474 size_t size;
475 //Input: Savestate data. Only stable during call.
476 const char* data;
479 //Request 9: Get controller set.
480 //Item id: Type ID.
481 //Default action: (required).
482 //Get the controller set.
483 #define LSNES_CORE_GET_CONTROLLERCONFIG 9
484 struct lsnes_core_get_controllerconfig_logical_entry
486 //port
487 unsigned port;
488 //controller
489 unsigned controller;
491 struct lsnes_core_get_controllerconfig
493 //Input: System settings. Ended by entry with NULL name.
494 struct lsnes_core_system_setting* settings;
495 //Output: Port types, indexed by 0-based ID to port type root JSON array. Ended by 0xFFFFFFFF.
496 unsigned* controller_types;
497 //Output: Logical map (ended by 0,0).
498 struct lsnes_core_get_controllerconfig_logical_entry* logical_map;
501 //Request 10: Load ROM.
502 //Item id: Type ID.
503 //Default action: (required).
504 //Load given ROM.
505 #define LSNES_CORE_LOAD_ROM 10
506 struct lsnes_core_load_rom_image
508 //ROM image (or filename thereof)
509 const char* data;
510 //Size of ROM image.
511 size_t size;
512 //Markup.
513 const char* markup;
515 struct lsnes_core_load_rom
517 //Input: The image set.
518 struct lsnes_core_load_rom_image* images;
519 //Input: System settings. Ended by entry with NULL name.
520 struct lsnes_core_system_setting* settings;
521 //Input: RTC second.
522 uint64_t rtc_sec;
523 //Input: RTC subsecond.
524 uint64_t rtc_subsec;
527 //Request 11: Get region.
528 //Item: Core ID.
529 //Default action: Fill region 0.
530 //Return the current region.
531 #define LSNES_CORE_GET_REGION 11
532 struct lsnes_core_get_region
534 //Output: The region.
535 unsigned region;
538 //Request 12: Set region.
539 //Item: Core ID.
540 //Default action: If region is 0, succeed, otherwise fail.
541 //Set current region.
542 #define LSNES_CORE_SET_REGION 12
543 struct lsnes_core_set_region
545 //Input: The region ID.
546 unsigned region;
549 //Request 13: Deinitialize
550 //Item: 0.
551 //Default action: No-op
552 //Deinitialize the state.
553 #define LSNES_CORE_DEINITIALIZE 13
554 struct lsnes_core_deinitialize
558 //Request 14: Get poll flag state.
559 //Item: Core ID.
560 //Default action: Return flag inferred from polls.
561 //Return the poll flag state.
562 //The poll flag gets automatically set to 1 if core reads controllers.
563 #define LSNES_CORE_GET_PFLAG 14
564 struct lsnes_core_get_pflag
566 //Output: The poll flag state.
567 int pflag;
570 //Request 15: Set poll flag state.
571 //Item: Core ID.
572 //Default action: Set flag inferred from polls.
573 //Sets the poll flag state.
574 #define LSNES_CORE_SET_PFLAG 15
575 struct lsnes_core_set_pflag
577 //Input: The poll flag state.
578 int pflag;
581 //Request 16: Get action flags.
582 //Item: Core ID.
583 //Default action: Act as if flags was 1.
584 //Get flags for given action.
585 #define LSNES_CORE_GET_ACTION_FLAGS 16
586 struct lsnes_core_get_action_flags
588 //Input: The ID of action.
589 unsigned action;
590 //Output: The flags.
591 //Bit 0: Enabled.
592 //Bit 1: Checked.
593 unsigned flags;
596 //Request 17: Execute action.
597 //Item: Core ID.
598 //Default action: Do nothing.
599 //Execute given action.
600 #define LSNES_CORE_EXECUTE_ACTION 17
601 struct lsnes_core_execute_action_param
603 union {
604 int boolean;
605 int64_t integer;
606 struct {
607 const char* base;
608 size_t length;
609 } string;
612 struct lsnes_core_execute_action
614 //Input: The ID of action.
615 unsigned action;
616 //Parameters block (length is set by action info).
617 struct lsnes_core_execute_action_param* params;
620 //Request 18: Get bus mapping.
621 //Item: Core ID.
622 //Default action: base=0, size=0 (no mapping).
623 //Get the base and size of bus mapping.
624 #define LSNES_CORE_GET_BUS_MAPPING 18
625 struct lsnes_core_get_bus_mapping
627 //Output: The base address of the mapping.
628 uint64_t base;
629 //Output: The size of the mapping.
630 uint64_t size;
633 //Request 19: Enumerate SRAMs.
634 //Item iD: Core ID.
635 //Default action: Return empty set.
636 //Get the set of SRAMs available.
637 #define LSNES_CORE_ENUMERATE_SRAM 19
638 struct lsnes_core_enumerate_sram
640 //Output: List of SRAMs, NULL terminated (valid until next call).
641 const char** srams;
644 //Request 20: Save SRAMs.
645 //Item id: Core ID.
646 //Default action: Return empty set.
647 //Save the contents of SRAMs.
648 #define LSNES_CORE_SAVE_SRAM 20
649 struct lsnes_core_save_sram
651 //Output: The SRAMs, terminated by entry with NULL name. Valid until next call.
652 struct lsnes_core_sram* srams;
655 //Request 21: Load SRAMs.
656 //Item id: Core ID.
657 //Default action: Warn about any SRAMs present.
658 //Load the contents of SRAMs.
659 #define LSNES_CORE_LOAD_SRAM 21
660 struct lsnes_core_load_sram
662 //Intput: The SRAMs, terminated by entry with NULL name. Valid during call.
663 struct lsnes_core_sram* srams;
666 //Request 22: Get reset action number.
667 //Item id: Core ID.
668 //Default action: Return -1 for both (not supported).
669 //Return the IDs for reset actions.
670 #define LSNES_CORE_GET_RESET_ACTION 22
671 struct lsnes_core_get_reset_action
673 //Output: Soft reset action (-1 if not supported).
674 int softreset;
675 //Output: Hard reset action (-1 if not supported).
676 int hardreset;
679 //Request 23: Get scale factors.
680 //Item id: Core ID.
681 //Default action: Scale to at least 360 width, 320 height.
682 //Compute scale factors for given resolution.
683 #define LSNES_CORE_COMPUTE_SCALE 23
684 struct lsnes_core_compute_scale
686 //Input: Width
687 unsigned width;
688 //Input: Height.
689 unsigned height;
690 //Output: Horizontal scale factor.
691 uint32_t hfactor;
692 //Output: Vertical scale factor.
693 uint32_t vfactor;
696 //Request 24: Run to save.
697 //Item id: Core ID.
698 //Default action: Do nothing.
699 //Run to next save point (can be at most frame).
700 #define LSNES_CORE_RUNTOSAVE 24
701 struct lsnes_core_runtosave
705 //Request 25: Poweron the system
706 //Item id: Core ID.
707 //Default action: Do nothing.
708 //Powers on the emulate system.
709 #define LSNES_CORE_POWERON 25
710 struct lsnes_core_poweron
714 //Request 26: Unload the ROM.
715 //Item id: Core ID.
716 //Default action: Do nothing.
717 //Signals that the ROM is no longer needed and can be unloaded.
718 #define LSNES_CORE_UNLOAD_CARTRIDGE 26
719 struct lsnes_core_unload_cartridge
723 //Request 27: Reset debugging.
724 //Item id: Core ID.
725 //Default action: Do nothing.
726 //Signals that debugging system should discard all breakpoints, cheats and tracks.
727 #define LSNES_CORE_DEBUG_RESET 27
728 struct lsnes_core_debug_reset
732 //Request 28: Set debug flags.
733 //Item id: Core ID.
734 //Default action: Do nothing.
735 //Set debugging flags.
736 #define LSNES_CORE_SET_DEBUG_FLAGS 28
737 struct lsnes_core_set_debug_flags
739 //Input: Address or CPU id.
740 uint64_t addr;
741 //Input: Flags to set.
742 //1 => Break on read.
743 //2 => Break on write.
744 //4 => Break on execute.
745 //8 => Trace.
746 unsigned set;
747 //Input: Flags to clear.
748 unsigned clear;
751 //Request 29: Set cheat.
752 //Item id: Core ID.
753 //Default action: Do nothing.
754 //Set or clear cheat.
755 #define LSNES_CORE_SET_CHEAT 29
756 struct lsnes_core_set_cheat
758 //Input: Address to set on.
759 uint64_t addr;
760 //Input: Value to set.
761 uint64_t value;
762 //Input: If nonzero, set cheat, else clear it.
763 int set;
766 //Request 30: Draw cover page.
767 //Item id: Core ID.
768 //Default action: Draw black screen.
769 //Draw the cover page.
770 #define LSNES_CORE_DRAW_COVER 30
771 struct lsnes_core_draw_cover
773 //Output: The cover page. Needs to stay valid to next call.
774 struct lsnes_core_framebuffer_info* coverpage;
777 //Request 31: Set system controls before emulating frame.
778 //Item id: Core ID.
779 //Default action: Do nothing.
780 //Set the system controls before frame is emulated.
781 #define LSNES_CORE_PRE_EMULATE 31
782 struct lsnes_core_pre_emulate
784 //Input: Context to pass to the function.
785 void* context;
786 //Input: Set input function.
787 void (*set_input)(void* context, unsigned port, unsigned controller, unsigned index, short value);
790 //Request 32: Get list of device registers.
791 //Item id: Core ID.
792 //Default action: Return no registers.
793 //Return list of device registers.
794 #define LSNES_CORE_GET_DEVICE_REGS 32
795 struct lsnes_core_get_device_regs_reg
797 //Name of the register.
798 const char* name;
799 //Read function.
800 uint64_t (*read)();
801 //Write function.
802 void (*write)(uint64_t v);
803 //Is boolean?
804 int boolean;
806 struct lsnes_core_get_device_regs
808 //Output: List of registers. Terminated with register with NULL name.
809 struct lsnes_core_get_device_regs_reg* regs;
812 //Request 33: Get VMA list.
813 //Item id: Core ID.
814 //Default action: Return no VMAs.
815 //Get the list of VMAs.
816 #define LSNES_CORE_GET_VMA_LIST 33
817 struct lsnes_core_get_vma_list_vma
819 //Name of region.
820 const char* name;
821 //Base address.
822 uint64_t base;
823 //Size of region.
824 uint64_t size;
825 //Endianess of region (-1 => little, 0 => host, 1 => big).
826 int endian;
827 //flags (LSNES_CORE_VMA_*).
828 int flags;
829 //Direct mapping for the region. If not NULL, read/write will not be used, instead all operations directly
830 //manipulate this buffer (faster). Must be NULL for special regions.
831 unsigned char* direct_map;
832 //Function to read region (if direct_map is NULL).
833 uint8_t (*read)(uint64_t offset);
834 //Function to write region (if direct_map is NULL and readonly is 0).
835 void (*write)(uint64_t offset, uint8_t value);
837 struct lsnes_core_get_vma_list
839 //Output: List of VMAs. NULL-terminated.
840 struct lsnes_core_get_vma_list_vma** vmas;
843 //Request 34: Reinit core to last loaded state.
844 //Item id: Core ID.
845 //Default action: Emulate using loadstate.
846 //Signals that the core state should be reset to state just after last load (load savestate at moment of initial
847 //poweron).
848 #define LSNES_CORE_REINIT 27
849 struct lsnes_core_reinit
854 #ifdef LSNES_BUILD_AS_BUILTIN_CORE
855 void lsnes_register_builtin_core(lsnes_core_func_t fn);
856 #else
857 int lsnes_core_entrypoint(unsigned action, unsigned item, void* params, const char** error);
858 #endif
860 #ifdef __cplusplus
862 #endif
864 #endif