├── .gitignore
├── .gitmodules
├── .npmignore
├── .nvmrc
├── Makefile.common
├── Makefile.gambatte
├── Makefile.vbanext
├── README.md
├── dist
├── archjs-gambatte.js
└── archjs-vbanext.js
├── example
├── index.html
├── main.js
└── vendors
│ ├── CoreJs-0.9.6.min.js
│ └── FpsMeter-0.3.1.min.js
├── includes
└── libretro.h
├── package.json
└── sources
├── bridge_retro.c
├── bridge_retro.h
├── bridge_virtjs.c
├── bridge_virtjs.h
├── bridge_virtjs.js
├── epilogue.js
├── frontend.c
├── frontend.h
├── input_formats.c
├── input_formats.h
├── main.c
└── prologue.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /dist/archjs-gambatte
2 | /dist/archjs-vbanext
3 |
4 | .#*
5 | *.o
6 | *.tmp
7 |
8 | *.a
9 | *.bc
10 |
11 | *.gb
12 | *.gbc
13 | *.gba
14 | *.sav
15 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "example/virtjs"]
2 | path = example/virtjs
3 | url = https://github.com/arcanis/virtjs.git
4 | [submodule "example/taisel"]
5 | path = example/taisel
6 | url = https://github.com/start9/taisel.git
7 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | /example/
2 | /includes/
3 | /sources/
4 | /systems/
5 |
6 | /Makefile.*
7 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | node
2 |
--------------------------------------------------------------------------------
/Makefile.common:
--------------------------------------------------------------------------------
1 | ifndef ENGINE_NAME
2 | $(error "You need to define the engine architecture")
3 | endif
4 |
5 | ifndef ENGINE_ROM_NAME
6 | $(error "You need to define the engine default rom name")
7 | endif
8 |
9 | SHELL = bash
10 |
11 | CFLAGS = -std=c99
12 |
13 | CPPFLAGS += -W -Wall -Werror -Wno-unused-parameter
14 | CPPFLAGS += -I $(shell pwd)/includes
15 |
16 | ifdef EMMAKEN_COMPILER
17 |
18 | MEMORY = $$((64*1024*1024))
19 |
20 | TARGET = dist/archjs-$(ENGINE_NAME).js
21 |
22 | SOURCES = \
23 | systems/libretro-$(ENGINE_NAME).bc \
24 | sources/bridge_retro.c.o \
25 | sources/bridge_virtjs.js \
26 | sources/frontend.c.o \
27 | sources/input_formats.c.o \
28 | sources/main.c.o
29 |
30 | EXTRA_SOURCES = \
31 | sources/prologue.js \
32 | sources/epilogue.js \
33 | Makefile.$(ENGINE_NAME) \
34 | Makefile.common
35 |
36 | LDFLAGS += --memory-init-file 0
37 | LDFLAGS += -s NO_EXIT_RUNTIME=1 -s INVOKE_RUN=0 -s TOTAL_MEMORY=$(MEMORY)
38 |
39 | else
40 |
41 | TARGET = dist/archjs-$(ENGINE_NAME)
42 |
43 | SOURCES = \
44 | sources/bridge_retro.c.o \
45 | sources/bridge_virtjs.c.o \
46 | sources/frontend.c.o \
47 | sources/input_formats.c.o \
48 | sources/main.c.o
49 |
50 | EXTRA_SOURCES = \
51 | systems/libretro-$(ENGINE_NAME).so \
52 | Makefile.$(ENGINE_NAME) \
53 | Makefile.common
54 |
55 | CPPFLAGS += $(shell pkg-config --cflags sdl2)
56 |
57 | LDFLAGS += -L systems -lretro-$(ENGINE_NAME)
58 | LDFLAGS += $(shell pkg-config --libs sdl2)
59 |
60 | endif
61 |
62 | ifdef DEBUG
63 |
64 | CPPFLAGS += -g
65 |
66 | else
67 |
68 | CPPFLAGS += -O3
69 | LDFLAGS += -O3
70 |
71 | ifdef EMMAKEN_COMPILER
72 | LDFLAGS += --llvm-lto 3 -s OUTLINING_LIMIT=50000 -s PRECISE_F32=2
73 | endif
74 |
75 | endif
76 |
77 | all: $(TARGET)
78 |
79 | $(TARGET): $(SOURCES) $(EXTRA_SOURCES)
80 | $(CXX) -o $(TARGET) $(filter-out %.js, $(SOURCES)) $(addprefix --js-library , $(filter %.js, $(SOURCES))) $(LDFLAGS)
81 | ifdef EMMAKEN_COMPILER
82 | cat sources/prologue.js | sed -e 's/@(ENGINE_NAME)/$(ENGINE_NAME)/g' -e 's/@(ENGINE_ROM_NAME)/$(ENGINE_ROM_NAME)/' > $(TARGET).tmp
83 | cat $(TARGET) >> $(TARGET).tmp
84 | cat sources/epilogue.js | sed -e 's/@(ENGINE_NAME)/$(ENGINE_NAME)/g' -e 's/@(ENGINE_ROM_NAME)/$(ENGINE_ROM_NAME)/' >> $(TARGET).tmp
85 | mv $(TARGET).tmp $(TARGET)
86 | endif
87 |
88 | %.c.o: %.c Makefile.$(ENGINE_NAME) Makefile.common
89 | $(CC) -c -o $(@) $(<) $(CFLAGS) $(CPPFLAGS)
90 |
91 | clean:
92 | @$(RM) -f **/*.o
93 | @$(RM) -f **/*.tmp
94 |
95 | fclean: clean
96 | @$(RM) -f $(TARGET)
97 |
98 | re: clean all
99 |
100 | .PHONY: all clean re
101 |
--------------------------------------------------------------------------------
/Makefile.gambatte:
--------------------------------------------------------------------------------
1 | ENGINE_NAME=gambatte
2 | ENGINE_ROM_NAME=game.gb
3 |
4 | include Makefile.common
5 |
--------------------------------------------------------------------------------
/Makefile.vbanext:
--------------------------------------------------------------------------------
1 | ENGINE_NAME=vbanext
2 | ENGINE_ROM_NAME=game.gba
3 |
4 | include Makefile.common
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Archjs
2 |
3 | Archjs is a [Libretro](http://www.libretro.com/) frontend dedicated to one specific purpose : being easily compiled to Javascript using [Emscripten](http://kripken.github.io/emscripten-site/).
4 |
5 | Once compiled to Javascript, the scripts export [Virtjs](http://virtjs.com/) engines (available in the `Archjs` global), which can then be instanciated just like any other engine ([documentation here](http://virtjs.com/documentation/instanciating-an-emulator/)).
6 |
7 | ## Supported cores
8 |
9 | Since we're only a libretro frontend, we should work with most emscripten-compatible libretro cores. However, it is not so common, so you should check each one to see if they support it. The following cores have been tested with Archjs:
10 |
11 | - [Gambatte](https://github.com/libretro/gambatte-libretro)
12 | - [VBA-Next](https://github.com/libretro/vba-next)
13 |
14 | ## Multi-format cores
15 |
16 | Some cores may support multiple kinds of games. In such event, you may use the file name option of the `loadArrayBuffer()` method to tell the emulator about the actual file name (since they often rely on the file extension to select the right emulator). However, each core also has a main extension (such as `.gb` for Gambatte, or `.gba` for VBA-Next) which will be used if you omit to specify the arraybuffer file name.
17 |
18 | ## SDL frontend
19 |
20 | In order to be easily debugged, Archjs ships with a small SDL frontend, mimicking Virtjs devices.
21 |
22 | **Note** This frontend is only used when `make` is called without using emscripten, and is not present in the dist Javascript builds, which does not use the SDL at all (we instead except you to plug whatever device you want to usexs).
23 |
24 | ## License
25 |
26 | Archjs is supported and maintained by the [Start9](https://github.com/start9/) organization. The frontend is available under the [GPL v3 license](https://www.gnu.org/copyleft/gpl.html).
27 |
28 | ## Contributing
29 |
30 | If you notice a bug or want to suggest a feature, feel free to open an issue or pull request on the repository. However, keep in mind that the focus of Archjs is to remain simple (in order to be both easily compiled and heavily optimized by Emscripten).
31 |
32 | We also hang out on the #start9-dev irc network on Freenode, so feel free to join us there.
33 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | Click to select a file
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/example/main.js:
--------------------------------------------------------------------------------
1 | var AudiojsAudio = Audiojs.extra.AudiojsAudio;
2 | var KeyboardInput = Virtjs.devices.inputs.KeyboardInput;
3 | var WebGLScreen = Virtjs.devices.screens.WebGLScreen;
4 | var AnimationFrameTimer = Virtjs.devices.timers.AnimationFrameTimer;
5 | var fetchArrayBuffer = Virtjs.utils.DataUtils.fetchArrayBuffer;
6 |
7 | function listenShortcuts(engine) {
8 |
9 | var state = null;
10 |
11 | window.addEventListener('keydown', function (e) {
12 |
13 | if (e.keyCode !== 112 && e.keyCode !== 113)
14 | return ;
15 |
16 | e.preventDefault();
17 |
18 | if (e.keyCode === 112) {
19 | state = engine.getState();
20 | } else if (e.keyCode === 113) {
21 | state && engine.setState(state);
22 | }
23 |
24 | });
25 |
26 | }
27 |
28 | function run(arrayBuffer, { fileName }) {
29 |
30 | var meter = new FPSMeter({ });
31 | var Engine = Archjs.byName[ENGINE];
32 |
33 | var canvas = document.querySelector('#screen');
34 |
35 | var screen = new WebGLScreen({ canvas });
36 | screen.setOutputSize(canvas.width, canvas.height);
37 |
38 | var input = new KeyboardInput({ codeMap: Engine.codeMap });
39 |
40 | var timer = new AnimationFrameTimer();
41 |
42 | timer.start(function () {
43 | meter.tickStart();
44 | }, function () {
45 | meter.tick();
46 | });
47 |
48 | var audio = new AudiojsAudio();
49 |
50 | var engine = new Engine({ devices: {
51 | screen, timer, input, audio
52 | } });
53 |
54 | engine.loadArrayBuffer(arrayBuffer, { fileName });
55 |
56 | listenShortcuts(engine);
57 |
58 | }
59 |
60 | function load(what, fileName) {
61 |
62 | return fetchArrayBuffer(what).then(function (arrayBuffer) {
63 |
64 | document.querySelector('#selector').style.display = 'none';
65 | document.querySelector('#overlay').style.display = 'none';
66 |
67 | return run(arrayBuffer, fileName);
68 |
69 | });
70 |
71 | }
72 |
73 | if (GAMEPATH) {
74 |
75 | load(GAMEPATH, GAMEPATH.substr(GAMEPATH.lastIndexOf('/') + 1));
76 |
77 | } else {
78 |
79 | var selector = document.querySelector('#selector');
80 |
81 | selector.addEventListener('change', function () {
82 | load(selector.files[0], selector.files[0].name);
83 | });
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/example/vendors/CoreJs-0.9.6.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Core.js 0.9.6
3 | * https://github.com/zloirock/core-js
4 | * License: http://rock.mit-license.org
5 | * © 2015 Denis Pushkarev
6 | */
7 | !function(a){"use strict";var b=null,c=null;!function(c){function a(d){if(b[d])return b[d].exports;var e=b[d]={exports:{},id:d,loaded:!1};return c[d].call(e.exports,e,e.exports,a),e.loaded=!0,e.exports}var b={};return a.m=c,a.c=b,a.p="",a(0)}([function(b,c,a){a(1),a(4),a(2),a(5),a(3),a(6),a(10),a(9),a(8),a(7),a(11),a(12),a(13),a(14),a(15),a(16),a(18),a(17),a(19),a(20),a(21),a(22),a(23),a(24),a(25),a(26),a(27),a(38),a(31),a(28),a(29),a(30),a(32),a(33),a(34),a(35),a(36),a(37),a(39),a(40),a(41),a(42),a(43),a(44),a(45),a(46),a(47),a(48)},function(S,R,d){function D(a,b){return function(g){var c,e=r(g),f=0,d=[];for(c in e)c!=i&&l(e,c)&&d.push(c);for(;b>f;)l(e,c=a[f++])&&(~o.call(d,c)||d.push(c));return d}}function w(a){return!b.isObject(a)}function p(){}function B(a){return function(){return a.apply(b.ES5Object(this),arguments)}}function C(a){return function(h,d){g.fn(h);var c=r(this),e=s(c.length),b=a?e-1:0,f=a?-1:1;if(arguments.length<2)for(;;){if(b in c){d=c[b],b+=f;break}b+=f,g(a?b>=0:e>b,"Reduce of empty array with no initial value")}for(;a?b>=0:e>b;b+=f)b in c&&(d=h(d,c[b],b,this));return d}}function e(a){return a>9?a:"0"+a}var b=d(52),y=d(53),h=d(54),c=d(49),N=d(58),f=d(55),i=d(56).safe("__proto__"),g=d(57),u=g.obj,v=Object.prototype,m=[],n=m.slice,o=m.indexOf,A=h.classof,l=b.has,x=b.setDesc,M=b.getDesc,q=b.setDescs,z=b.isFunction,r=b.toObject,s=b.toLength,t=!1,P=d(59)(!1),H=f(0),I=f(1),J=f(2),K=f(3),L=f(4);if(!b.DESC){try{t=8==x(y("div"),"x",{get:function(){return 8}}).x}catch(Q){}b.setDesc=function(b,c,a){if(t)try{return x(b,c,a)}catch(d){}if("get"in a||"set"in a)throw TypeError("Accessors not supported!");return"value"in a&&(u(b)[c]=a.value),b},b.getDesc=function(c,d){if(t)try{return M(c,d)}catch(e){}return l(c,d)?b.desc(!v.propertyIsEnumerable.call(c,d),c[d]):a},b.setDescs=q=function(a,c){u(a);for(var d,e=b.getKeys(c),g=e.length,f=0;g>f;)b.setDesc(a,d=e[f++],c[d]);return a}}c(c.S+c.F*!b.DESC,"Object",{getOwnPropertyDescriptor:b.getDesc,defineProperty:b.setDesc,defineProperties:q});var j="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","),F=j.concat("length","prototype"),G=j.length,k=function(){var a,c=y("iframe"),d=G,e=">";for(c.style.display="none",b.html.appendChild(c),c.src="javascript:",a=c.contentWindow.document,a.open(),a.write("1&&(a=Math.min(a,b.toInteger(f))),0>a&&(a=s(d+a));a>=0;a--)if(a in c&&c[a]===e)return a;return-1}}),c(c.P,"String",{trim:d(62)(/^\s*([\s\S]*\S)?\s*$/,"$1")}),c(c.S,"Date",{now:function(){return+new Date}});var E=new Date(-5e13-1),O=!(E.toISOString&&"0385-07-25T07:06:39.999Z"==E.toISOString()&&d(60)(function(){new Date(0/0).toISOString()}));c(c.P+c.F*O,"Date",{toISOString:function(){if(!isFinite(this))throw RangeError("Invalid time value");var a=this,b=a.getUTCFullYear(),c=a.getUTCMilliseconds(),d=0>b?"-":b>9999?"+":"";return d+("00000"+Math.abs(b)).slice(d?-6:-4)+"-"+e(a.getUTCMonth()+1)+"-"+e(a.getUTCDate())+"T"+e(a.getUTCHours())+":"+e(a.getUTCMinutes())+":"+e(a.getUTCSeconds())+"."+(c>99?c:"0"+e(c))+"Z"}}),"Object"==A(function(){return arguments}())&&(h.classof=function(a){var b=A(a);return"Object"==b&&z(a.callee)?"Arguments":b})},function(c,d,a){var b=a(49);b(b.S,"Object",{assign:a(50)})},function(c,d,a){var b=a(49);b(b.S,"Object",{setPrototypeOf:a(51).set})},function(G,F,g){function z(a){var f=h[a]=b.set(q(e.prototype),x,a);return b.DESC&&k&&i(Object.prototype,a,{configurable:!0,set:function(b){d(this,c)&&d(this[c],a)&&(this[c][a]=!1),i(this,a,s(1,b))}}),f}function p(a,b,e){return e&&d(h,b)&&(e.enumerable?(d(a,c)&&a[c][b]&&(a[c][b]=!1),e.enumerable=!1):(d(a,c)||i(a,c,s(1,{})),a[c][b]=!0)),i(a,b,e)}function n(a,b){D(a);for(var c,d=B(b=l(b)),e=0,f=d.length;f>e;)p(a,c=d[e++],b[c]);return a}function y(b,c){return c===a?q(b):n(q(b),c)}function w(a,b){var e=C(a=l(a),b);return!e||!d(h,b)||d(a,c)&&a[c][b]||(e.enumerable=!0),e}function v(g){for(var a,b=t(l(g)),e=[],f=0;b.length>f;)d(h,a=b[f++])||a==c||e.push(a);return e}function u(f){for(var a,b=t(l(f)),c=[],e=0;b.length>e;)d(h,a=b[e++])&&c.push(h[a]);return c}var b=g(52),r=g(54).set,m=g(56),f=g(49),E=g(61),B=g(63),D=g(57).obj,d=b.has,q=b.create,C=b.getDesc,i=b.setDesc,s=b.desc,t=b.getNames,l=b.toObject,e=b.g.Symbol,k=!1,x=m("tag"),c=m("hidden"),j={},h={},o=b.isFunction(e);o||(e=function(a){if(this instanceof e)throw TypeError("Symbol is not a constructor");return z(m(a))},b.hide(e.prototype,"toString",function(){return this[x]}),b.create=y,b.setDesc=p,b.getDesc=w,b.setDescs=n,b.getNames=v,b.getSymbols=u);var A={"for":function(a){return d(j,a+="")?j[a]:j[a]=e(a)},keyFor:function(a){return E(j,a)},useSetter:function(){k=!0},useSimple:function(){k=!1}};b.each.call("hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),function(a){var b=g(64)(a);A[a]=o?b:z(b)}),k=!0,f(f.G+f.W,{Symbol:e}),f(f.S,"Symbol",A),f(f.S+f.F*!o,"Object",{create:y,defineProperty:p,defineProperties:n,getOwnPropertyDescriptor:w,getOwnPropertyNames:v,getOwnPropertySymbols:u}),r(e,"Symbol"),r(Math,"Math",!0),r(b.g.JSON,"JSON",!0)},function(c,d,b){var a=b(49);a(a.S,"Object",{is:function(a,b){return a===b?0!==a||1/a===1/b:a!=a&&b!=b}})},function(e,f,a){var b=a(52),c=a(54),d={};d[a(64)("toStringTag")]="z",b.FW&&"z"!=c(d)&&b.hide(Object.prototype,"toString",function(){return"[object "+c.classof(this)+"]"})},function(l,k,j){function i(a){var b,c;if(h(b=a.valueOf)&&!d(c=b.call(a)))return c;if(h(b=a.toString)&&!d(c=b.call(a)))return c;throw TypeError("Can't convert object to number")}function e(a){if(d(a)&&(a=i(a)),"string"==typeof a&&a.length>2&&48==a.charCodeAt(0)){var b=!1;switch(a.charCodeAt(1)){case 66:case 98:b=!0;case 79:case 111:return parseInt(a.slice(2),b?2:8)}}return+a}var a=j(52),d=a.isObject,h=a.isFunction,g="Number",b=a.g[g],c=b,f=b.prototype;!a.FW||b("0o1")&&b("0b1")||(b=function(a){return this instanceof b?new c(e(a)):e(a)},a.each.call(a.DESC?a.getNames(c):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger".split(","),function(d){a.has(c,d)&&!a.has(b,d)&&a.setDesc(b,d,a.getDesc(c,d))}),b.prototype=f,f.constructor=b,a.hide(a.g,g,b))},function(e,f,b){var a=b(52),c=b(64)("hasInstance"),d=Function.prototype;c in d||a.setDesc(d,c,{value:function(b){if(!a.isFunction(this)||!a.isObject(b))return!1;if(!a.isObject(this.prototype))return b instanceof this;for(;b=a.getProto(b);)if(this.prototype===b)return!0;return!1}})},function(f,g,e){var a=e(52),b="name",c=a.setDesc,d=Function.prototype;b in d||a.FW&&a.DESC&&c(d,b,{configurable:!0,get:function(){var d=(this+"").match(/^\s*function ([^ (]*)/),e=d?d[1]:"";return a.has(this,b)||c(this,b,a.desc(5,e)),e},set:function(d){a.has(this,b)||c(this,b,a.desc(0,d))}})},function(g,h,e){function a(g,e){var a=(b.core.Object||{})[g]||Object[g],h=0,i={};i[g]=1==e?function(b){return d(b)?a(b):b}:2==e?function(b){return d(b)?a(b):!0}:3==e?function(b){return d(b)?a(b):!1}:4==e?function(b,c){return a(f(b),c)}:5==e?function(c){return a(Object(b.assertDefined(c)))}:function(b){return a(f(b))};try{a("z")}catch(j){h=1}c(c.S+c.F*h,"Object",i)}var b=e(52),c=e(49),d=b.isObject,f=b.toObject;a("freeze",1),a("seal",1),a("preventExtensions",1),a("isFrozen",2),a("isSealed",2),a("isExtensible",3),a("getOwnPropertyDescriptor",4),a("getPrototypeOf",5),a("keys"),a("getOwnPropertyNames")},function(i,j,b){function c(a){return!d.isObject(a)&&f(a)&&h(a)===a}var d=b(52),e=b(49),g=Math.abs,h=Math.floor,f=d.g.isFinite,a=9007199254740991;e(e.S,"Number",{EPSILON:Math.pow(2,-52),isFinite:function(a){return"number"==typeof a&&f(a)},isInteger:c,isNaN:function(a){return a!=a},isSafeInteger:function(b){return c(b)&&g(b)<=a},MAX_SAFE_INTEGER:a,MIN_SAFE_INTEGER:-a,parseFloat:parseFloat,parseInt:parseInt})},function(u,t,r){function q(a){return a+1/k-1/k}function h(a){return 0==(a=+a)||a!=a?a:0>a?-1:1}function n(a){return isFinite(a=+a)&&0!=a?0>a?-n(-a):b(a+g(a*a+1)):a}function e(a){return 0==(a=+a)?a:a>-1e-6&&1e-6>a?a+a*a/2:c(a)-1}var a=1/0,m=r(49),j=Math.E,d=Math.pow,l=Math.abs,c=Math.exp,b=Math.log,g=Math.sqrt,p=Math.ceil,o=Math.floor,k=d(2,-52),f=d(2,-23),s=d(2,127)*(2-f),i=d(2,-126);m(m.S,"Math",{acosh:function(a){return(a=+a)<1?0/0:isFinite(a)?b(a/j+g(a+1)*g(a-1)/j)+1:a},asinh:n,atanh:function(a){return 0==(a=+a)?a:b((1+a)/(1-a))/2},cbrt:function(a){return h(a=+a)*d(l(a),1/3)},clz32:function(a){return(a>>>=0)?31-o(b(a+.5)*Math.LOG2E):32},cosh:function(a){return(c(a=+a)+c(-a))/2},expm1:e,fround:function(g){var d,b,c=l(g),e=h(g);return i>c?e*q(c/i/f)*i*f:(d=(1+f/k)*c,b=d-(d-c),b>s||b!=b?e*a:e*b)},hypot:function(){for(var b,f=0,c=arguments.length,h=c,i=Array(c),e=-a;c--;){if(b=i[c]=+arguments[c],b==a||b==-a)return a;b>e&&(e=b)}for(e=b||1;h--;)f+=d(i[h]/e,2);return e*g(f)},imul:function(f,g){var a=65535,b=+f,c=+g,d=a&b,e=a&c;return 0|d*e+((a&b>>>16)*e+d*(a&c>>>16)<<16>>>0)},log1p:function(a){return(a=+a)>-1e-8&&1e-8>a?a-a*a/2:b(1+a)},log10:function(a){return b(a)/Math.LN10},log2:function(a){return b(a)/Math.LN2},sign:h,sinh:function(a){return l(a=+a)<1?(e(a)-e(-a))/2:(c(a-1)-c(-a-1))*(j/2)},tanh:function(b){var d=e(b=+b),f=e(-b);return d==a?1:f==a?-1:(d-f)/(c(b)+c(-b))},trunc:function(a){return(a>0?o:p)(a)}})},function(f,g,b){var a=b(49),e=b(52).toIndex,c=String.fromCharCode,d=String.fromCodePoint;a(a.S+a.F*(!!d&&1!=d.length),"String",{fromCodePoint:function(){for(var a,b=[],f=arguments.length,d=0;f>d;){if(a=+arguments[d++],e(a,1114111)!==a)throw RangeError(a+" is not a valid code point");b.push(65536>a?c(a):c(((a-=65536)>>10)+55296,a%1024+56320))}return b.join("")}})},function(d,e,a){var b=a(52),c=a(49);c(c.S,"String",{raw:function(e){for(var d=b.toObject(e.raw),f=b.toLength(d.length),g=arguments.length,c=[],a=0;f>a;)c.push(d[a++]+""),g>a&&c.push(arguments[a]+"");return c.join("")}})},function(g,h,a){var d=a(52).set,e=a(65)(!0),b=a(56).safe("iter"),f=a(66),c=f.step;a(67)(String,"String",function(a){d(this,b,{o:a+"",i:0})},function(){var a,d=this[b],f=d.o,g=d.i;return g>=f.length?c(1):(a=e(f,g),d.i+=a.length,c(0,a))})},function(d,e,a){var b=a(49),c=a(65)(!1);b(b.P,"String",{codePointAt:function(a){return c(this,a)}})},function(e,f,a){var c=a(52),d=a(54),b=a(49);b(b.P,"String",{includes:function(a){if("RegExp"==d(a))throw TypeError();return!!~(c.assertDefined(this)+"").indexOf(a,arguments[1])}})},function(g,h,b){var d=b(52),f=b(54),c=b(49),e=d.toLength;c(c.P+c.F*!b(60)(function(){"q".endsWith(/./)}),"String",{endsWith:function(b){if("RegExp"==f(b))throw TypeError();var c=d.assertDefined(this)+"",g=arguments[1],h=e(c.length),i=g===a?h:Math.min(e(g),h);return b+="",c.slice(i-b.length,i)===b}})},function(c,d,a){var b=a(49);b(b.P,"String",{repeat:a(68)})},function(e,f,a){var c=a(52),d=a(54),b=a(49);b(b.P+b.F*!a(60)(function(){"q".startsWith(/./)}),"String",{startsWith:function(a){if("RegExp"==d(a))throw TypeError();var b=c.assertDefined(this)+"",e=c.toLength(Math.min(arguments[1],b.length));return a+="",b.slice(e,e+a.length)===a}})},function(h,i,b){var d=b(52),f=b(69),c=b(49),e=b(66),g=b(70);c(c.S+c.F*!b(71)(function(a){Array.from(a)}),"Array",{from:function(o){var l,c,i,j,h=Object(d.assertDefined(o)),m=arguments[1],k=m!==a,n=k?f(m,arguments[2],2):a,b=0;if(e.is(h))for(j=e.get(h),c=new("function"==typeof this?this:Array);!(i=j.next()).done;b++)c[b]=k?g(j,n,[i.value,b],!0):i.value;else for(c=new("function"==typeof this?this:Array)(l=d.toLength(h.length));l>b;b++)c[b]=k?n(h[b],b):h[b];return c.length=b,c}})},function(c,d,b){var a=b(49);a(a.S,"Array",{of:function(){for(var a=0,b=arguments.length,c=new("function"==typeof this?this:Array)(b);b>a;)c[a]=arguments[a++];return c.length=b,c}})},function(i,j,b){var e=b(52),d=b(72),f=b(56).safe("iter"),g=b(66),c=g.step,h=g.Iterators;b(67)(Array,"Array",function(a,b){e.set(this,f,{o:e.toObject(a),i:0,k:b})},function(){var d=this[f],e=d.o,g=d.k,b=d.i++;return!e||b>=e.length?(d.o=a,c(1)):"keys"==g?c(0,b):"values"==g?c(0,e[b]):c(0,[b,e[b]])},"values"),h.Arguments=h.Array,d("keys"),d("values"),d("entries")},function(b,c,a){a(73)(Array)},function(f,g,b){var c=b(52),e=b(49),d=c.toIndex;e(e.P,"Array",{copyWithin:function(k,l){var f=Object(c.assertDefined(this)),g=c.toLength(f.length),b=d(k,g),e=d(l,g),j=arguments[2],m=j===a?g:d(j,g),h=Math.min(m-e,g-b),i=1;for(b>e&&e+h>b&&(i=-1,e=e+h-1,b=b+h-1);h-->0;)e in f?f[b]=f[e]:delete f[b],b+=i,e+=i;return f}}),b(72)("copyWithin")},function(f,g,b){var c=b(52),d=b(49),e=c.toIndex;d(d.P,"Array",{fill:function(h){for(var b=Object(c.assertDefined(this)),d=c.toLength(b.length),f=e(arguments[1],d),g=arguments[2],i=g===a?d:e(g,d);i>f;)b[f++]=h;return b}}),b(72)("fill")},function(f,g,a){var b="find",c=a(49),d=!0,e=a(55)(5);b in[]&&Array(1)[b](function(){d=!1}),c(c.P+c.F*d,"Array",{find:function(a){return e(this,a,arguments[1])}}),a(72)(b)},function(D,C,c){function h(b){var c=o(b)[s];return c!=a?c:b}function v(b){var a;return A(b)&&(a=b.then),g(a)?a:!1}function p(a){var b=a.c;b.length&&x(function(){function f(b){var e,g,f=d?b.ok:b.fail;try{f?(d||(a.h=!0),e=f===!0?c:f(c),e===b.P?b.rej(TypeError("Promise-chain cycle")):(g=v(e))?g.call(e,b.res,b.rej):b.res(e)):b.rej(c)}catch(h){b.rej(h)}}for(var c=a.v,d=1==a.s,e=0;b.length>e;)f(b[e++]);b.length=0})}function t(e){var a,b=e[i],c=b.a||b.c,d=0;if(b.h)return!1;for(;c.length>d;)if(a=c[d++],a.fail||!t(a.P))return!1;return!0}function l(c){var d,b=this;b.d||(b.d=!0,b=b.r||b,b.v=c,b.s=2,b.a=b.c.slice(),setTimeout(function(){x(function(){t(d=b.p)&&("process"==u(k)?k.emit("unhandledRejection",c,d):n.console&&g(console.error)&&console.error("Unhandled promise rejection",c)),b.a=a})},1),p(b))}function w(c){var d,b,a=this;if(!a.d){a.d=!0,a=a.r||a;try{(d=v(c))?(b={r:a,d:!1},d.call(c,j(w,b,1),j(l,b,1))):(a.v=c,a.s=1,p(a))}catch(e){l.call(b||{r:a,d:!1},e)}}}var e=c(52),j=c(69),u=c(54),d=c(49),r=c(57),y=c(74),z=c(51).set,B=c(73),s=c(64)("species"),i=c(56).safe("record"),f="Promise",n=e.g,k=n.process,x=k&&k.nextTick||c(75).set,b=n[f],g=e.isFunction,A=e.isObject,q=r.fn,o=r.obj,m=function(){function a(d){var c=new b(d);return z(c,a.prototype),c}var d,c=!1;try{c=g(b)&&g(b.resolve)&&b.resolve(d=new b(function(){}))==d,z(a,b),a.prototype=e.create(b.prototype,{constructor:{value:a}}),a.resolve(5).then(function(){})instanceof a||(c=!1)}catch(f){c=!1}return c}();m||(b=function(d){q(d);var c={p:r.inst(this,b,f),c:[],a:a,s:0,d:!1,v:a,h:!1};e.hide(this,i,c);try{d(j(w,c,1),j(l,c,1))}catch(g){l.call(c,g)}},e.mix(b.prototype,{then:function(e,f){var h=o(o(this).constructor)[s],c={ok:g(e)?e:!0,fail:g(f)?f:!1},j=c.P=new(h!=a?h:b)(function(a,b){c.res=q(a),c.rej=q(b)}),d=this[i];return d.c.push(c),d.a&&d.a.push(c),d.s&&p(d),j},"catch":function(b){return this.then(a,b)}})),d(d.G+d.W+d.F*!m,{Promise:b}),u.set(b,f),B(b),B(e.core[f]),d(d.S+d.F*!m,f,{reject:function(a){return new(h(this))(function(c,b){b(a)})},resolve:function(a){return A(a)&&i in a&&e.getProto(a)===this.prototype?a:new(h(this))(function(b){b(a)})}}),d(d.S+d.F*!(m&&c(71)(function(a){b.all(a)["catch"](function(){})})),f,{all:function(c){var b=h(this),a=[];return new b(function(g,h){y(c,!1,a.push,a);var d=a.length,f=Array(d);d?e.each.call(a,function(a,c){b.resolve(a).then(function(a){f[c]=a,--d||g(f)},h)}):g(f)})},race:function(b){var a=h(this);return new a(function(c,d){y(b,!1,function(b){a.resolve(b).then(c,d)})})}})},function(c,d,b){var a=b(76);b(77)("Map",{get:function(c){var b=a.getEntry(this,c);return b&&b.v},set:function(b,c){return a.def(this,0===b?0:b,c)}},a,!0)},function(c,d,a){var b=a(76);a(77)("Set",{add:function(a){return b.def(this,a=0===a?0:a,a)}},b)},function(l,k,e){var c=e(52),j=e(54),b=c.g.RegExp,d=b,f=b.prototype,g=/a/g,h=new b(g)!==g,i=function(){try{return"/a/i"==b(g,"i")}catch(a){}}();c.FW&&c.DESC&&(h&&i||(b=function(c,f){var e="RegExp"==j(c),g=f===a;return this instanceof b||!e||!g?h?new d(e&&!g?c.source:c,f):new d(e?c.source:c,e&&g?c.flags:f):c},c.each.call(c.getNames(d),function(a){a in b||c.setDesc(b,a,{configurable:!0,get:function(){return d[a]},set:function(b){d[a]=b}})}),f.constructor=b,b.prototype=f,c.hide(c.g,"RegExp",b)),"g"!=/./g.flags&&c.setDesc(f,"flags",{configurable:!0,get:e(62)(/^.*\/(\w*)$/,"$1")})),e(73)(b)},function(m,l,d){var a=d(52),b=d(78),e=b.leakStore,j=b.ID,g=b.WEAK,k=a.has,h=a.isObject,i=Object.isFrozen||a.core.Object.isFrozen,f={},c=d(77)("WeakMap",{get:function(a){if(h(a)){if(i(a))return e(this).get(a);if(k(a,g))return a[g][this[j]]}},set:function(a,c){return b.def(this,a,c)}},b,!0,!0);a.FW&&7!=(new c).set((Object.freeze||Object)(f),7).get(f)&&a.each.call(["delete","has","get","set"],function(a){var b=c.prototype[a];c.prototype[a]=function(c,d){if(h(c)&&i(c)){var f=e(this)[a](c,d);return"set"==a?this:f}return b.call(this,c,d)}})},function(c,d,a){var b=a(78);a(77)("WeakSet",{add:function(a){return b.def(this,a,!0)}},b,!1,!0)},function(v,u,d){function p(c){b.set(this,k,{o:c,k:a,i:0})}var b=d(52),e=d(49),g=d(51),o=d(66),q=d(64)("iterator"),k=d(56).safe("iter"),j=o.step,m=d(57),f=b.isObject,h=b.getProto,i=b.g.Reflect,l=Function.apply,c=m.obj,r=Object.isExtensible||b.isObject,s=Object.preventExtensions||b.it,t=!(i&&i.enumerate&&q in i.enumerate({}));o.create(p,"Object",function(){var d,b=this[k],c=b.k;if(c==a){b.k=c=[];for(d in b.o)c.push(d)}do if(b.i>=c.length)return j(1);while(!((d=c[b.i++])in b.o));return j(0,d)});var n={apply:function(a,b,c){return l.call(a,b,c)},construct:function(a,g){var c=m.fn(arguments.length<3?a:arguments[2]).prototype,d=b.create(f(c)?c:Object.prototype),e=l.call(a,d,g);return f(e)?e:d},defineProperty:function(a,d,e){c(a);try{return b.setDesc(a,d,e),!0}catch(f){return!1}},deleteProperty:function(a,d){var e=b.getDesc(c(a),d);return e&&!e.configurable?!1:delete a[d]},get:function w(e,g){var i,j=arguments.length<3?e:arguments[2],d=b.getDesc(c(e),g);return d?b.has(d,"value")?d.value:d.get===a?a:d.get.call(j):f(i=h(e))?w(i,g,j):a},getOwnPropertyDescriptor:function(a,d){return b.getDesc(c(a),d)},getPrototypeOf:function(a){return h(c(a))},has:function(a,b){return b in a},isExtensible:function(a){return r(c(a))},ownKeys:d(79),preventExtensions:function(a){c(a);try{return s(a),!0}catch(b){return!1}},set:function x(i,g,j){var k,l,e=arguments.length<4?i:arguments[3],d=b.getDesc(c(i),g);if(!d){if(f(l=h(i)))return x(l,g,j,e);d=b.desc(0)}return b.has(d,"value")?d.writable!==!1&&f(e)?(k=b.getDesc(e,g)||b.desc(0),k.value=j,b.setDesc(e,g,k),!0):!1:d.set===a?!1:(d.set.call(e,j),!0)}};g&&(n.setPrototypeOf=function(a,b){g.check(a,b);try{return g.set(a,b),!0}catch(c){return!1}}),e(e.G,{Reflect:{}}),e(e.S+e.F*t,"Reflect",{enumerate:function(a){return new p(c(a))}}),e(e.S,"Reflect",n)},function(d,e,a){var b=a(49),c=a(59)(!0);b(b.P,"Array",{includes:function(a){return c(this,a,arguments[1])}}),a(72)("includes")},function(d,e,a){var b=a(49),c=a(65)(!0);b(b.P,"String",{at:function(a){return c(this,a)}})},function(d,e,a){var b=a(49),c=a(80);b(b.P,"String",{lpad:function(a){return c(this,a,arguments[1],!0)}})},function(f,g,a){var b="findIndex",c=a(49),d=!0,e=a(55)(6);b in[]&&Array(1)[b](function(){d=!1}),c(c.P+c.F*d,"Array",{findIndex:function(a){return e(this,a,arguments[1])}}),a(72)(b)},function(d,e,a){var b=a(49),c=a(80);b(b.P,"String",{rpad:function(a){return c(this,a,arguments[1],!1)}})},function(c,d,a){var b=a(49);b(b.S,"RegExp",{escape:a(62)(/([\\\-[\]{}()*+?.,^$|])/g,"\\$1",!0)})},function(e,f,b){var a=b(52),c=b(49),d=b(79);c(c.S,"Object",{getOwnPropertyDescriptors:function(e){var b=a.toObject(e),c={};return a.each.call(d(b),function(d){a.setDesc(c,d,a.desc(0,a.getDesc(b,d)))}),c}})},function(e,f,a){function b(a){return function(i){var h,d=c.toObject(i),e=c.getKeys(d),f=e.length,b=0,g=Array(f);if(a)for(;f>b;)g[b]=[h=e[b++],d[h]];else for(;f>b;)g[b]=d[e[b++]];return g}}var c=a(52),d=a(49);d(d.S,"Object",{values:b(!1),entries:b(!0)})},function(b,c,a){a(81)("Map")},function(b,c,a){a(81)("Set")},function(d,e,b){var a=b(49),c=b(75);a(a.G+a.B,{setImmediate:c.set,clearImmediate:c.clear})},function(g,h,a){a(23);var b=a(52),d=a(66).Iterators,e=a(64)("iterator"),f=d.Array,c=b.g.NodeList;!b.FW||!c||e in c.prototype||b.hide(c.prototype,e,f),d.NodeList=f},function(i,j,a){function d(a){return f?function(c,d){return a(g(h,[].slice.call(arguments,2),b.isFunction(c)?c:Function(c)),d)}:a}var b=a(52),c=a(49),g=a(58),h=a(82),e=b.g.navigator,f=!!e&&/MSIE .\./.test(e.userAgent);c(c.G+c.B+c.F*f,{setTimeout:d(b.g.setTimeout),setInterval:d(b.g.setInterval)})},function(h,i,b){function c(f,c){e.each.call(f.split(","),function(e){c==a&&e in g?d[e]=g[e]:e in[]&&(d[e]=b(69)(Function.call,[][e],c))})}var e=b(52),f=b(49),g=e.core.Array||Array,d={};c("pop,reverse,shift,keys,values,entries",1),c("indexOf,every,some,forEach,map,filter,find,findIndex,includes",3),c("join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill,turn"),f(f.S,"Array",d)},function(f,i,g){function e(a,b){return function(){return a.apply(b,arguments)}}function a(j,k,n){var f,l,g,o,m=j&a.G,i=m?c:j&a.S?c[k]:(c[k]||{}).prototype,p=m?d:d[k]||(d[k]={});m&&(n=k);for(f in n)l=!(j&a.F)&&i&&f in i,g=(l?i:n)[f],o=j&a.B&&l?e(g,c):j&a.P&&h(g)?e(Function.call,g):g,i&&!l&&(m?i[f]=g:delete i[f]&&b.hide(i,f,g)),p[f]!=g&&b.hide(p,f,o)}var b=g(52),c=b.g,d=b.core,h=b.isFunction;c.core=d,a.F=1,a.G=2,a.S=4,a.P=8,a.B=16,a.W=32,f.exports=a},function(c,e,a){var b=a(52),d=a(63);c.exports=Object.assign||function(i){for(var a=Object(b.assertDefined(i)),j=arguments.length,c=1;j>c;)for(var e,f=b.ES5Object(arguments[c++]),g=d(f),k=g.length,h=0;k>h;)a[e=g[h++]]=f[e];return a}},function(f,g,b){function c(b,a){e.obj(b),e(null===a||d.isObject(a),a,": can't set as prototype!")}var d=b(52),e=b(57);f.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(e,a){try{a=b(69)(Function.call,d.getDesc(Object.prototype,"__proto__").set,2),a({},[])}catch(f){e=!0}return function(b,d){return c(b,d),e?b.__proto__=d:a(b,d),b}}():a),check:c}},function(w,x,v){function f(a){return isNaN(a=+a)?0:(a>0?r:q)(a)}function h(a,b){return{enumerable:!(1&a),configurable:!(2&a),writable:!(4&a),value:b}}function i(a,b,c){return a[b]=c,a}function j(a){return k?function(b,c,d){return g.setDesc(b,c,h(a,d))}:i}function u(a){return null!==a&&("object"==typeof a||"function"==typeof a)}function t(a){return"function"==typeof a}function m(b){if(b==a)throw TypeError("Can't call method on "+b);return b}var d="undefined"!=typeof self?self:Function("return this")(),o={},n=Object.defineProperty,p={}.hasOwnProperty,q=Math.ceil,r=Math.floor,s=Math.max,l=Math.min,k=!!function(){try{return 2==n({},"a",{get:function(){return 2}}).a}catch(a){}}(),e=j(1),g=w.exports=v(83)({g:d,core:o,html:d.document&&document.documentElement,isObject:u,isFunction:t,it:function(a){return a},that:function(){return this},toInteger:f,toLength:function(a){return a>0?l(f(a),9007199254740991):0},toIndex:function(a,b){return a=f(a),0>a?s(a+b,0):l(a,b)},has:function(a,b){return p.call(a,b)},create:Object.create,getProto:Object.getPrototypeOf,DESC:k,desc:h,getDesc:Object.getOwnPropertyDescriptor,setDesc:n,setDescs:Object.defineProperties,getKeys:Object.keys,getNames:Object.getOwnPropertyNames,getSymbols:Object.getOwnPropertySymbols,assertDefined:m,ES5Object:Object,toObject:function(a){return g.ES5Object(m(a))},hide:e,def:j(0),set:d.Symbol?i:e,mix:function(a,b){for(var c in b)e(a,c,b[c]);return a},each:[].forEach});a!==b&&(b=o),a!==c&&(c=d)},function(d,g,e){var b=e(52),a=b.g.document,c=b.isObject,f=c(a)&&c(a.createElement);d.exports=function(b){return f?a.createElement(b):{}}},function(f,h,d){function b(a){return g.call(a).slice(8,-1)}var e=d(52),c=d(64)("toStringTag"),g={}.toString;b.classof=function(d){var e,f;return d==a?d===a?"Undefined":"Null":"string"==typeof(f=(e=Object(d))[c])?f:b(e)},b.set=function(a,b,d){a&&!e.has(a=d?a:a.prototype,c)&&e.hide(a,c,b)},f.exports=b},function(d,f,c){var b=c(52),e=c(69);d.exports=function(c){var f=1==c,h=2==c,i=3==c,d=4==c,g=6==c,j=5==c||g;return function(u,s,t){for(var l,n,q=Object(b.assertDefined(u)),o=b.ES5Object(q),r=e(s,t,3),p=b.toLength(o.length),k=0,m=f?Array(p):h?[]:a;p>k;k++)if((j||k in o)&&(l=o[k],n=r(l,k,q),c))if(f)m[k]=n;else if(n)switch(c){case 3:return!0;case 5:return l;case 6:return k;case 2:m.push(l)}else if(d)return!1;return g?-1:i||d?d:m}}},function(b,e,c){function a(a){return"Symbol("+a+")_"+(++d+Math.random()).toString(36)}var d=0;a.safe=c(52).g.Symbol||a,b.exports=a},function(c,e,d){function a(c,a,b){if(!c)throw TypeError(b?a+b:a)}var b=d(52);a.def=b.assertDefined,a.fn=function(a){if(!b.isFunction(a))throw TypeError(a+" is not a function!");return a},a.obj=function(a){if(!b.isObject(a))throw TypeError(a+" is not an object!");return a},a.inst=function(a,b,c){if(!(a instanceof b))throw TypeError(c+": use the 'new' operator!");return a},c.exports=a},function(b){b.exports=function(c,b,d){var e=d===a;switch(b.length){case 0:return e?c():c.call(d);case 1:return e?c(b[0]):c.call(d,b[0]);case 2:return e?c(b[0],b[1]):c.call(d,b[0],b[1]);case 3:return e?c(b[0],b[1],b[2]):c.call(d,b[0],b[1],b[2]);case 4:return e?c(b[0],b[1],b[2],b[3]):c.call(d,b[0],b[1],b[2],b[3]);case 5:return e?c(b[0],b[1],b[2],b[3],b[4]):c.call(d,b[0],b[1],b[2],b[3],b[4])}return c.apply(d,b)}},function(b,d,c){var a=c(52);b.exports=function(b){return function(h,e,i){var f,d=a.toObject(h),g=a.toLength(d.length),c=a.toIndex(i,g);if(b&&e!=e){for(;g>c;)if(f=d[c++],f!=f)return!0}else for(;g>c;c++)if((b||c in d)&&d[c]===e)return b||c;return!b&&-1}}},function(a){a.exports=function(a){try{return a(),!1}catch(b){return!0}}},function(b,d,c){var a=c(52);b.exports=function(f,g){for(var b,c=a.toObject(f),d=a.getKeys(c),h=d.length,e=0;h>e;)if(c[b=d[e++]]===g)return b}},function(a){a.exports=function(b,a,c){var d=a===Object(a)?function(b){return a[b]}:a;return function(a){return((c?a:this)+"").replace(b,d)}}},function(b,d,c){var a=c(52);b.exports=function(b){var c=a.getKeys(b),e=a.getDesc,d=a.getSymbols;return d&&a.each.call(d(b),function(a){e(b,a).enumerable&&c.push(a)}),c}},function(d,e,a){var b=a(52).g,c={};d.exports=function(d){return c[d]||(c[d]=b.Symbol&&b.Symbol[d]||a(56).safe("Symbol."+d))}},function(c,e,d){var b=d(52);c.exports=function(c){return function(i,j){var e,g,f=b.assertDefined(i)+"",d=b.toInteger(j),h=f.length;return 0>d||d>=h?c?"":a:(e=f.charCodeAt(d),55296>e||e>56319||d+1===h||(g=f.charCodeAt(d+1))<56320||g>57343?c?f.charAt(d):e:c?f.slice(d,d+2):(e-55296<<10)+(g-56320)+65536)}}},function(j,k,b){function h(b,d){a.hide(b,f,d),c in[]&&a.hide(b,c,d)}var a=b(52),d=b(54),i=b(57).obj,f=b(64)("iterator"),c="@@iterator",e={},g={};h(g,a.that),j.exports={BUGGY:"keys"in[]&&!("next"in[].keys()),Iterators:e,step:function(a,b){return{value:b,done:!!a}},is:function(h){var b=Object(h),g=a.g.Symbol,i=g&&g.iterator||c;return i in b||f in b||a.has(e,d.classof(b))},get:function(b){var g=a.g.Symbol,h=b[g&&g.iterator||c],j=h||b[f]||e[d.classof(b)];return i(j.call(b))},set:h,create:function(b,c,e,f){b.prototype=a.create(f||g,{next:a.desc(1,e)}),d.set(b,c+" Iterator")}}},function(k,l,c){var e=c(49),a=c(52),j=c(54),b=c(66),i=c(64)("iterator"),h="@@iterator",g="keys",d="values",f=b.Iterators;k.exports=function(s,n,q,x,l,w,v){function m(b){function a(a){return new q(a,b)}switch(b){case g:return function(){return a(this)};case d:return function(){return a(this)}}return function(){return a(this)}}b.create(q,n,x);var o,p,t=n+" Iterator",c=s.prototype,r=c[i]||c[h]||l&&c[l],k=r||m(l);if(r){var u=a.getProto(k.call(new s));j.set(u,t,!0),a.FW&&a.has(c,h)&&b.set(u,a.that)}if(a.FW&&b.set(c,k),f[n]=k,f[t]=a.that,l)if(o={keys:w?k:m(g),values:l==d?k:m(d),entries:l!=d?k:m("entries")},v)for(p in o)p in c||a.hide(c,p,o[p]);else e(e.P+e.F*b.BUGGY,n,o)}},function(b,d,c){var a=c(52);b.exports=function(e){var c=a.assertDefined(this)+"",d="",b=a.toInteger(e);if(0>b||b==1/0)throw RangeError("Count can't be negative");for(;b>0;(b>>>=1)&&(c+=c))1&b&&(d+=c);return d}},function(b,e,c){var d=c(57).fn;b.exports=function(b,c,e){if(d(b),~e&&c===a)return b;switch(e){case 1:return function(a){return b.call(c,a)};case 2:return function(a,d){return b.call(c,a,d)};case 3:return function(a,d,e){return b.call(c,a,d,e)}}return function(){return b.apply(c,arguments)}}},function(e,g,f){function b(b){var c=b["return"];c!==a&&d(c.call(b))}function c(e,c,a,f){try{return f?c(d(a)[0],a[1]):c(a)}catch(g){throw b(e),g}}var d=f(57).obj;c.close=b,e.exports=c},function(d,f,e){var a=e(64)("iterator"),b=!1;try{var c=[7][a]();c["return"]=function(){b=!0},Array.from(c,function(){throw 2})}catch(g){}d.exports=function(f){if(!b)return!1;var d=!1;try{var c=[7],e=c[a]();e.next=function(){d=!0},c[a]=function(){return e},f(c)}catch(g){}return d}},function(d,e,c){var a=c(52),b=c(64)("unscopables");!a.FW||b in[]||a.hide(Array.prototype,b,{}),d.exports=function(c){a.FW&&([][b][c]=!0)}},function(d,e,b){var a=b(52),c=b(64)("species");d.exports=function(b){!a.DESC||c in b||a.setDesc(b,c,{configurable:!0,get:a.that})}},function(c,f,a){var d=a(69),e=a(66).get,b=a(70);c.exports=function(g,c,h,i){for(var f,a=e(g),j=d(h,i,c?2:1);!(f=a.next()).done;)if(b(a,j,f.value,c)===!1)return b.close(a)}},function(x,y,c){function f(){var a=+this;if(g.has(d,a)){var b=d[a];delete d[a],b()}}function s(a){f.call(a.data)}var b,l,i,g=c(52),h=c(69),w=c(54),v=c(58),n=c(53),a=g.g,e=g.isFunction,p=g.html,q=a.process,m=a.setImmediate,k=a.clearImmediate,t=a.postMessage,u=a.addEventListener,r=a.MessageChannel,j=0,d={},o="onreadystatechange";e(m)&&e(k)||(m=function(a){for(var c=[],f=1;arguments.length>f;)c.push(arguments[f++]);return d[++j]=function(){v(e(a)?a:Function(a),c)},b(j),j},k=function(a){delete d[a]},"process"==w(q)?b=function(a){q.nextTick(h(f,a,1))}:u&&e(t)&&!a.importScripts?(b=function(a){t(a,"*")},u("message",s,!1)):e(r)?(l=new r,i=l.port2,l.port1.onmessage=s,b=h(i.postMessage,i,1)):b=o in n("script")?function(a){p.appendChild(n("script"))[o]=function(){p.removeChild(this),f.call(a)}}:function(a){setTimeout(h(f,a,1),0)}),x.exports={set:m,clear:k}},function(r,x,d){function o(a,b){if(!u(a))return("string"==typeof a?"S":"P")+a;if(q(a))return"F";if(!p(a,l)){if(!b)return"E";v(a,l,++w)}return"O"+a[l]}function j(c,d){var a,e=o(d);if("F"!=e)return c[i][e];for(a=c[b];a;a=a.n)if(a.k==d)return a}var c=d(52),s=d(69),e=d(56).safe,n=d(57),t=d(74),k=d(66).step,p=c.has,h=c.set,u=c.isObject,v=c.hide,q=Object.isFrozen||c.core.Object.isFrozen,l=e("id"),i=e("O1"),f=e("last"),b=e("first"),m=e("iter"),g=c.DESC?e("size"):"size",w=0;r.exports={getConstructor:function(e,k,l){function d(){var j=n.inst(this,d,e),m=arguments[0];h(j,i,c.create(null)),h(j,g,0),h(j,f,a),h(j,b,a),m!=a&&t(m,k,j[l],j);
8 |
9 | }return c.mix(d.prototype,{clear:function(){for(var d=this,e=d[i],c=d[b];c;c=c.n)c.r=!0,c.p&&(c.p=c.p.n=a),delete e[c.i];d[b]=d[f]=a,d[g]=0},"delete":function(h){var c=this,a=j(c,h);if(a){var d=a.n,e=a.p;delete c[i][a.i],a.r=!0,e&&(e.n=d),d&&(d.p=e),c[b]==a&&(c[b]=d),c[f]==a&&(c[f]=e),c[g]--}return!!a},forEach:function(c){for(var a,d=s(c,arguments[1],3);a=a?a.n:this[b];)for(d(a.v,a.k,this);a&&a.r;)a=a.p},has:function(a){return!!j(this,a)}}),c.DESC&&c.setDesc(d.prototype,"size",{get:function(){return n.def(this[g])}}),d},def:function(c,e,l){var h,k,d=j(c,e);return d?d.v=l:(c[f]=d={i:k=o(e,!0),k:e,v:l,p:h=c[f],n:a,r:!1},c[b]||(c[b]=d),h&&(h.n=d),c[g]++,"F"!=k&&(c[i][k]=d)),c},getEntry:j,setIter:function(e,f,c){d(67)(e,f,function(a,b){h(this,m,{o:a,k:b})},function(){for(var d=this[m],e=d.k,c=d.l;c&&c.r;)c=c.p;return d.o&&(d.l=c=c?c.n:d.o[b])?"keys"==e?k(0,c.k):"values"==e?k(0,c.v):k(0,[c.k,c.v]):(d.o=a,k(1))},c?"entries":"values",!c,!0)}}},function(f,j,b){var c=b(52),d=b(49),g=b(66).BUGGY,h=b(74),e=b(73),i=b(57).inst;f.exports=function(j,u,t,l,n){function o(a,b){var d=k[a];c.FW&&(k[a]=function(a,c){var e=d.call(this,0===a?0:a,c);return b?this:e})}var p=c.g[j],f=p,m=l?"set":"add",k=f&&f.prototype,s={};if(c.isFunction(f)&&(n||!g&&k.forEach&&k.entries)){var r,q=new f,v=q[m](n?{}:-0,1);b(71)(function(a){new f(a)})||(f=function(){i(this,f,j);var b=new p,c=arguments[0];return c!=a&&h(c,l,b[m],b),b},f.prototype=k,c.FW&&(k.constructor=f)),n||q.forEach(function(b,a){r=1/a===-(1/0)}),r&&(o("delete"),o("has"),l&&o("get")),(r||v!==q)&&o(m,!0)}else f=t.getConstructor(j,l,m),c.mix(f.prototype,u);return b(54).set(f,j),s[j]=f,d(d.G+d.W+d.F*(f!=p),s),e(f),e(c.core[j]),n||t.setIter(f,j,l),f}},function(r,u,f){function h(a,b){return p(a.array,function(a){return a[0]===b})}function g(b){return b[k]||m(b,k,{array:[],get:function(c){var b=h(this,c);return b?b[1]:a},has:function(a){return!!h(this,a)},set:function(a,b){var c=h(this,a);c?c[1]=b:this.array.push([a,b])},"delete":function(b){var a=t(this.array,function(a){return a[0]===b});return~a&&this.array.splice(a,1),!!~a}})[k]}var c=f(52),i=f(56).safe,n=f(57),q=f(74),e=c.has,l=c.isObject,m=c.hide,j=Object.isFrozen||c.core.Object.isFrozen,s=0,d=i("id"),b=i("weak"),k=i("leak"),o=f(55),p=o(5),t=o(6);r.exports={getConstructor:function(h,i,k){function f(){c.set(n.inst(this,f,h),d,s++);var b=arguments[0];b!=a&&q(b,i,this[k],this)}return c.mix(f.prototype,{"delete":function(a){return l(a)?j(a)?g(this)["delete"](a):e(a,b)&&e(a[b],this[d])&&delete a[b][this[d]]:!1},has:function(a){return l(a)?j(a)?g(this).has(a):e(a,b)&&e(a[b],this[d]):!1}}),f},def:function(c,a,f){return j(n.obj(a))?g(c).set(a,f):(e(a,b)||m(a,b,{}),a[b][c[d]]=f),c},leakStore:g,WEAK:b,ID:d}},function(c,e,a){var b=a(52),d=a(57).obj;c.exports=function(a){d(a);var c=b.getNames(a),e=b.getSymbols;return e?c.concat(e(a)):c}},function(d,f,b){var c=b(52),e=b(68);d.exports=function(k,g,h,i){var f=c.assertDefined(k)+"";if(g===a)return f;var l=c.toInteger(g),d=l-f.length;if(0>d||d===1/0)throw new RangeError("Cannot satisfy string length "+g+" for string: "+f);var j=h===a?" ":h+"",b=e.call(j,Math.ceil(d/j.length));return b.length>d&&(b=i?b.slice(b.length-d):b.slice(0,d)),i?b.concat(f):f.concat(b)}},function(c,e,a){var b=a(49),d=a(74);c.exports=function(a){b(b.P,a,{toJSON:function(){var a=[];return d(this,!1,a.push,a),a}})}},function(c,f,a){var d=a(52),b=a(58),e=a(57).fn;c.exports=function(){for(var h=e(this),a=arguments.length,c=Array(a),f=0,i=d.path._,g=!1;a>f;)(c[f]=arguments[f++])===i&&(g=!0);return function(){var d,j=this,k=arguments.length,e=0,f=0;if(!g&&!k)return b(h,c,j);if(d=c.slice(),g)for(;a>e;e++)d[e]===i&&(d[e]=arguments[f++]);for(;k>f;)d.push(arguments[f++]);return b(h,d,j)}}},function(a){a.exports=function(a){return a.FW=!0,a.path=a.g,a}}]),"undefined"!=typeof module&&module.exports?module.exports=b:"function"==typeof define&&define.amd?define(function(){return b}):c.core=b}();
10 | //# sourceMappingURL=shim.min.js.map
--------------------------------------------------------------------------------
/example/vendors/FpsMeter-0.3.1.min.js:
--------------------------------------------------------------------------------
1 | /*! FPSMeter 0.3.1 - 9th May 2013 | https://github.com/Darsain/fpsmeter */
2 | (function(m,j){function s(a,e){for(var g in e)try{a.style[g]=e[g]}catch(j){}return a}function H(a){return null==a?String(a):"object"===typeof a||"function"===typeof a?Object.prototype.toString.call(a).match(/\s([a-z]+)/i)[1].toLowerCase()||"object":typeof a}function R(a,e){if("array"!==H(e))return-1;if(e.indexOf)return e.indexOf(a);for(var g=0,j=e.length;gd.interval?(x=M(k),m()):(x=setTimeout(k,d.interval),P=M(m))}function G(a){a=a||window.event;a.preventDefault?(a.preventDefault(),a.stopPropagation()):(a.returnValue=
6 | !1,a.cancelBubble=!0);b.toggle()}function U(){d.toggleOn&&S(f.container,d.toggleOn,G,1);a.removeChild(f.container)}function V(){f.container&&U();h=D.theme[d.theme];y=h.compiledHeatmaps||[];if(!y.length&&h.heatmaps.length){for(p=0;p=m?m*(1+j):m+j-m*j;0===l?g="#000":(t=2*m-l,k=(l-t)/l,g*=6,n=Math.floor(g),
7 | v=g-n,v*=l*k,0===n||6===n?(n=l,k=t+v,l=t):1===n?(n=l-v,k=l,l=t):2===n?(n=t,k=l,l=t+v):3===n?(n=t,k=l-v):4===n?(n=t+v,k=t):(n=l,k=t,l-=v),g="#"+N(n)+N(k)+N(l));b[e]=g}}h.compiledHeatmaps=y}f.container=s(document.createElement("div"),h.container);f.count=f.container.appendChild(s(document.createElement("div"),h.count));f.legend=f.container.appendChild(s(document.createElement("div"),h.legend));f.graph=d.graph?f.container.appendChild(s(document.createElement("div"),h.graph)):0;w.length=0;for(var q in f)f[q]&&
8 | h[q].heatOn&&w.push({name:q,el:f[q]});u.length=0;if(f.graph){f.graph.style.width=d.history*h.column.width+(d.history-1)*h.column.spacing+"px";for(c=0;c
27 | #include
28 | #include
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | #ifndef __cplusplus
35 | #if defined(_MSC_VER) && !defined(SN_TARGET_PS3)
36 | /* Hack applied for MSVC when compiling in C89 mode
37 | * as it isn't C99-compliant. */
38 | #define bool unsigned char
39 | #define true 1
40 | #define false 0
41 | #else
42 | #include
43 | #endif
44 | #endif
45 |
46 | /* Used for checking API/ABI mismatches that can break libretro
47 | * implementations.
48 | * It is not incremented for compatible changes to the API.
49 | */
50 | #define RETRO_API_VERSION 1
51 |
52 | /*
53 | * Libretro's fundamental device abstractions.
54 | *
55 | * Libretro's input system consists of some standardized device types,
56 | * such as a joypad (with/without analog), mouse, keyboard, lightgun
57 | * and a pointer.
58 | *
59 | * The functionality of these devices are fixed, and individual cores
60 | * map their own concept of a controller to libretro's abstractions.
61 | * This makes it possible for frontends to map the abstract types to a
62 | * real input device, and not having to worry about binding input
63 | * correctly to arbitrary controller layouts.
64 | */
65 |
66 | #define RETRO_DEVICE_TYPE_SHIFT 8
67 | #define RETRO_DEVICE_MASK ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1)
68 | #define RETRO_DEVICE_SUBCLASS(base, id) (((id + 1) << RETRO_DEVICE_TYPE_SHIFT) | base)
69 |
70 | /* Input disabled. */
71 | #define RETRO_DEVICE_NONE 0
72 |
73 | /* The JOYPAD is called RetroPad. It is essentially a Super Nintendo
74 | * controller, but with additional L2/R2/L3/R3 buttons, similar to a
75 | * PS1 DualShock. */
76 | #define RETRO_DEVICE_JOYPAD 1
77 |
78 | /* The mouse is a simple mouse, similar to Super Nintendo's mouse.
79 | * X and Y coordinates are reported relatively to last poll (poll callback).
80 | * It is up to the libretro implementation to keep track of where the mouse
81 | * pointer is supposed to be on the screen.
82 | * The frontend must make sure not to interfere with its own hardware
83 | * mouse pointer.
84 | */
85 | #define RETRO_DEVICE_MOUSE 2
86 |
87 | /* KEYBOARD device lets one poll for raw key pressed.
88 | * It is poll based, so input callback will return with the current
89 | * pressed state.
90 | * For event/text based keyboard input, see
91 | * RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
92 | */
93 | #define RETRO_DEVICE_KEYBOARD 3
94 |
95 | /* Lightgun X/Y coordinates are reported relatively to last poll,
96 | * similar to mouse. */
97 | #define RETRO_DEVICE_LIGHTGUN 4
98 |
99 | /* The ANALOG device is an extension to JOYPAD (RetroPad).
100 | * Similar to DualShock it adds two analog sticks.
101 | * This is treated as a separate device type as it returns values in the
102 | * full analog range of [-0x8000, 0x7fff]. Positive X axis is right.
103 | * Positive Y axis is down.
104 | * Only use ANALOG type when polling for analog values of the axes.
105 | */
106 | #define RETRO_DEVICE_ANALOG 5
107 |
108 | /* Abstracts the concept of a pointing mechanism, e.g. touch.
109 | * This allows libretro to query in absolute coordinates where on the
110 | * screen a mouse (or something similar) is being placed.
111 | * For a touch centric device, coordinates reported are the coordinates
112 | * of the press.
113 | *
114 | * Coordinates in X and Y are reported as:
115 | * [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen,
116 | * and 0x7fff corresponds to the far right/bottom of the screen.
117 | * The "screen" is here defined as area that is passed to the frontend and
118 | * later displayed on the monitor.
119 | *
120 | * The frontend is free to scale/resize this screen as it sees fit, however,
121 | * (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the
122 | * game image, etc.
123 | *
124 | * To check if the pointer coordinates are valid (e.g. a touch display
125 | * actually being touched), PRESSED returns 1 or 0.
126 | *
127 | * If using a mouse on a desktop, PRESSED will usually correspond to the
128 | * left mouse button, but this is a frontend decision.
129 | * PRESSED will only return 1 if the pointer is inside the game screen.
130 | *
131 | * For multi-touch, the index variable can be used to successively query
132 | * more presses.
133 | * If index = 0 returns true for _PRESSED, coordinates can be extracted
134 | * with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with
135 | * index = 1, and so on.
136 | * Eventually _PRESSED will return false for an index. No further presses
137 | * are registered at this point. */
138 | #define RETRO_DEVICE_POINTER 6
139 |
140 | /* Buttons for the RetroPad (JOYPAD).
141 | * The placement of these is equivalent to placements on the
142 | * Super Nintendo controller.
143 | * L2/R2/L3/R3 buttons correspond to the PS1 DualShock. */
144 | #define RETRO_DEVICE_ID_JOYPAD_B 0
145 | #define RETRO_DEVICE_ID_JOYPAD_Y 1
146 | #define RETRO_DEVICE_ID_JOYPAD_SELECT 2
147 | #define RETRO_DEVICE_ID_JOYPAD_START 3
148 | #define RETRO_DEVICE_ID_JOYPAD_UP 4
149 | #define RETRO_DEVICE_ID_JOYPAD_DOWN 5
150 | #define RETRO_DEVICE_ID_JOYPAD_LEFT 6
151 | #define RETRO_DEVICE_ID_JOYPAD_RIGHT 7
152 | #define RETRO_DEVICE_ID_JOYPAD_A 8
153 | #define RETRO_DEVICE_ID_JOYPAD_X 9
154 | #define RETRO_DEVICE_ID_JOYPAD_L 10
155 | #define RETRO_DEVICE_ID_JOYPAD_R 11
156 | #define RETRO_DEVICE_ID_JOYPAD_L2 12
157 | #define RETRO_DEVICE_ID_JOYPAD_R2 13
158 | #define RETRO_DEVICE_ID_JOYPAD_L3 14
159 | #define RETRO_DEVICE_ID_JOYPAD_R3 15
160 |
161 | /* Index / Id values for ANALOG device. */
162 | #define RETRO_DEVICE_INDEX_ANALOG_LEFT 0
163 | #define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1
164 | #define RETRO_DEVICE_ID_ANALOG_X 0
165 | #define RETRO_DEVICE_ID_ANALOG_Y 1
166 |
167 | /* Id values for MOUSE. */
168 | #define RETRO_DEVICE_ID_MOUSE_X 0
169 | #define RETRO_DEVICE_ID_MOUSE_Y 1
170 | #define RETRO_DEVICE_ID_MOUSE_LEFT 2
171 | #define RETRO_DEVICE_ID_MOUSE_RIGHT 3
172 | #define RETRO_DEVICE_ID_MOUSE_WHEELUP 4
173 | #define RETRO_DEVICE_ID_MOUSE_WHEELDOWN 5
174 | #define RETRO_DEVICE_ID_MOUSE_MIDDLE 6
175 |
176 | /* Id values for LIGHTGUN types. */
177 | #define RETRO_DEVICE_ID_LIGHTGUN_X 0
178 | #define RETRO_DEVICE_ID_LIGHTGUN_Y 1
179 | #define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2
180 | #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3
181 | #define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4
182 | #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5
183 | #define RETRO_DEVICE_ID_LIGHTGUN_START 6
184 |
185 | /* Id values for POINTER. */
186 | #define RETRO_DEVICE_ID_POINTER_X 0
187 | #define RETRO_DEVICE_ID_POINTER_Y 1
188 | #define RETRO_DEVICE_ID_POINTER_PRESSED 2
189 |
190 | /* Returned from retro_get_region(). */
191 | #define RETRO_REGION_NTSC 0
192 | #define RETRO_REGION_PAL 1
193 |
194 | /* Id values for LANGUAGE */
195 | enum retro_language
196 | {
197 | RETRO_LANGUAGE_ENGLISH = 0,
198 | RETRO_LANGUAGE_JAPANESE = 1,
199 | RETRO_LANGUAGE_FRENCH = 2,
200 | RETRO_LANGUAGE_SPANISH = 3,
201 | RETRO_LANGUAGE_GERMAN = 4,
202 | RETRO_LANGUAGE_ITALIAN = 5,
203 | RETRO_LANGUAGE_DUTCH = 6,
204 | RETRO_LANGUAGE_PORTUGUESE = 7,
205 | RETRO_LANGUAGE_RUSSIAN = 8,
206 | RETRO_LANGUAGE_KOREAN = 9,
207 | RETRO_LANGUAGE_CHINESE_TRADITIONAL = 10,
208 | RETRO_LANGUAGE_CHINESE_SIMPLIFIED = 11,
209 | RETRO_LANGUAGE_LAST,
210 |
211 | /* Ensure sizeof(enum) == sizeof(int) */
212 | RETRO_LANGUAGE_DUMMY = INT_MAX
213 | };
214 |
215 | /* Passed to retro_get_memory_data/size().
216 | * If the memory type doesn't apply to the
217 | * implementation NULL/0 can be returned.
218 | */
219 | #define RETRO_MEMORY_MASK 0xff
220 |
221 | /* Regular save RAM. This RAM is usually found on a game cartridge,
222 | * backed up by a battery.
223 | * If save game data is too complex for a single memory buffer,
224 | * the SAVE_DIRECTORY (preferably) or SYSTEM_DIRECTORY environment
225 | * callback can be used. */
226 | #define RETRO_MEMORY_SAVE_RAM 0
227 |
228 | /* Some games have a built-in clock to keep track of time.
229 | * This memory is usually just a couple of bytes to keep track of time.
230 | */
231 | #define RETRO_MEMORY_RTC 1
232 |
233 | /* System ram lets a frontend peek into a game systems main RAM. */
234 | #define RETRO_MEMORY_SYSTEM_RAM 2
235 |
236 | /* Video ram lets a frontend peek into a game systems video RAM (VRAM). */
237 | #define RETRO_MEMORY_VIDEO_RAM 3
238 |
239 | /* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */
240 | enum retro_key
241 | {
242 | RETROK_UNKNOWN = 0,
243 | RETROK_FIRST = 0,
244 | RETROK_BACKSPACE = 8,
245 | RETROK_TAB = 9,
246 | RETROK_CLEAR = 12,
247 | RETROK_RETURN = 13,
248 | RETROK_PAUSE = 19,
249 | RETROK_ESCAPE = 27,
250 | RETROK_SPACE = 32,
251 | RETROK_EXCLAIM = 33,
252 | RETROK_QUOTEDBL = 34,
253 | RETROK_HASH = 35,
254 | RETROK_DOLLAR = 36,
255 | RETROK_AMPERSAND = 38,
256 | RETROK_QUOTE = 39,
257 | RETROK_LEFTPAREN = 40,
258 | RETROK_RIGHTPAREN = 41,
259 | RETROK_ASTERISK = 42,
260 | RETROK_PLUS = 43,
261 | RETROK_COMMA = 44,
262 | RETROK_MINUS = 45,
263 | RETROK_PERIOD = 46,
264 | RETROK_SLASH = 47,
265 | RETROK_0 = 48,
266 | RETROK_1 = 49,
267 | RETROK_2 = 50,
268 | RETROK_3 = 51,
269 | RETROK_4 = 52,
270 | RETROK_5 = 53,
271 | RETROK_6 = 54,
272 | RETROK_7 = 55,
273 | RETROK_8 = 56,
274 | RETROK_9 = 57,
275 | RETROK_COLON = 58,
276 | RETROK_SEMICOLON = 59,
277 | RETROK_LESS = 60,
278 | RETROK_EQUALS = 61,
279 | RETROK_GREATER = 62,
280 | RETROK_QUESTION = 63,
281 | RETROK_AT = 64,
282 | RETROK_LEFTBRACKET = 91,
283 | RETROK_BACKSLASH = 92,
284 | RETROK_RIGHTBRACKET = 93,
285 | RETROK_CARET = 94,
286 | RETROK_UNDERSCORE = 95,
287 | RETROK_BACKQUOTE = 96,
288 | RETROK_a = 97,
289 | RETROK_b = 98,
290 | RETROK_c = 99,
291 | RETROK_d = 100,
292 | RETROK_e = 101,
293 | RETROK_f = 102,
294 | RETROK_g = 103,
295 | RETROK_h = 104,
296 | RETROK_i = 105,
297 | RETROK_j = 106,
298 | RETROK_k = 107,
299 | RETROK_l = 108,
300 | RETROK_m = 109,
301 | RETROK_n = 110,
302 | RETROK_o = 111,
303 | RETROK_p = 112,
304 | RETROK_q = 113,
305 | RETROK_r = 114,
306 | RETROK_s = 115,
307 | RETROK_t = 116,
308 | RETROK_u = 117,
309 | RETROK_v = 118,
310 | RETROK_w = 119,
311 | RETROK_x = 120,
312 | RETROK_y = 121,
313 | RETROK_z = 122,
314 | RETROK_DELETE = 127,
315 |
316 | RETROK_KP0 = 256,
317 | RETROK_KP1 = 257,
318 | RETROK_KP2 = 258,
319 | RETROK_KP3 = 259,
320 | RETROK_KP4 = 260,
321 | RETROK_KP5 = 261,
322 | RETROK_KP6 = 262,
323 | RETROK_KP7 = 263,
324 | RETROK_KP8 = 264,
325 | RETROK_KP9 = 265,
326 | RETROK_KP_PERIOD = 266,
327 | RETROK_KP_DIVIDE = 267,
328 | RETROK_KP_MULTIPLY = 268,
329 | RETROK_KP_MINUS = 269,
330 | RETROK_KP_PLUS = 270,
331 | RETROK_KP_ENTER = 271,
332 | RETROK_KP_EQUALS = 272,
333 |
334 | RETROK_UP = 273,
335 | RETROK_DOWN = 274,
336 | RETROK_RIGHT = 275,
337 | RETROK_LEFT = 276,
338 | RETROK_INSERT = 277,
339 | RETROK_HOME = 278,
340 | RETROK_END = 279,
341 | RETROK_PAGEUP = 280,
342 | RETROK_PAGEDOWN = 281,
343 |
344 | RETROK_F1 = 282,
345 | RETROK_F2 = 283,
346 | RETROK_F3 = 284,
347 | RETROK_F4 = 285,
348 | RETROK_F5 = 286,
349 | RETROK_F6 = 287,
350 | RETROK_F7 = 288,
351 | RETROK_F8 = 289,
352 | RETROK_F9 = 290,
353 | RETROK_F10 = 291,
354 | RETROK_F11 = 292,
355 | RETROK_F12 = 293,
356 | RETROK_F13 = 294,
357 | RETROK_F14 = 295,
358 | RETROK_F15 = 296,
359 |
360 | RETROK_NUMLOCK = 300,
361 | RETROK_CAPSLOCK = 301,
362 | RETROK_SCROLLOCK = 302,
363 | RETROK_RSHIFT = 303,
364 | RETROK_LSHIFT = 304,
365 | RETROK_RCTRL = 305,
366 | RETROK_LCTRL = 306,
367 | RETROK_RALT = 307,
368 | RETROK_LALT = 308,
369 | RETROK_RMETA = 309,
370 | RETROK_LMETA = 310,
371 | RETROK_LSUPER = 311,
372 | RETROK_RSUPER = 312,
373 | RETROK_MODE = 313,
374 | RETROK_COMPOSE = 314,
375 |
376 | RETROK_HELP = 315,
377 | RETROK_PRINT = 316,
378 | RETROK_SYSREQ = 317,
379 | RETROK_BREAK = 318,
380 | RETROK_MENU = 319,
381 | RETROK_POWER = 320,
382 | RETROK_EURO = 321,
383 | RETROK_UNDO = 322,
384 |
385 | RETROK_LAST,
386 |
387 | RETROK_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
388 | };
389 |
390 | enum retro_mod
391 | {
392 | RETROKMOD_NONE = 0x0000,
393 |
394 | RETROKMOD_SHIFT = 0x01,
395 | RETROKMOD_CTRL = 0x02,
396 | RETROKMOD_ALT = 0x04,
397 | RETROKMOD_META = 0x08,
398 |
399 | RETROKMOD_NUMLOCK = 0x10,
400 | RETROKMOD_CAPSLOCK = 0x20,
401 | RETROKMOD_SCROLLOCK = 0x40,
402 |
403 | RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
404 | };
405 |
406 | /* If set, this call is not part of the public libretro API yet. It can
407 | * change or be removed at any time. */
408 | #define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000
409 | /* Environment callback to be used internally in frontend. */
410 | #define RETRO_ENVIRONMENT_PRIVATE 0x20000
411 |
412 | /* Environment commands. */
413 | #define RETRO_ENVIRONMENT_SET_ROTATION 1 /* const unsigned * --
414 | * Sets screen rotation of graphics.
415 | * Is only implemented if rotation can be accelerated by hardware.
416 | * Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180,
417 | * 270 degrees counter-clockwise respectively.
418 | */
419 | #define RETRO_ENVIRONMENT_GET_OVERSCAN 2 /* bool * --
420 | * Boolean value whether or not the implementation should use overscan,
421 | * or crop away overscan.
422 | */
423 | #define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 /* bool * --
424 | * Boolean value whether or not frontend supports frame duping,
425 | * passing NULL to video frame callback.
426 | */
427 |
428 | /* Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES),
429 | * and reserved to avoid possible ABI clash.
430 | */
431 |
432 | #define RETRO_ENVIRONMENT_SET_MESSAGE 6 /* const struct retro_message * --
433 | * Sets a message to be displayed in implementation-specific manner
434 | * for a certain amount of 'frames'.
435 | * Should not be used for trivial messages, which should simply be
436 | * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a
437 | * fallback, stderr).
438 | */
439 | #define RETRO_ENVIRONMENT_SHUTDOWN 7 /* N/A (NULL) --
440 | * Requests the frontend to shutdown.
441 | * Should only be used if game has a specific
442 | * way to shutdown the game from a menu item or similar.
443 | */
444 | #define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8
445 | /* const unsigned * --
446 | * Gives a hint to the frontend how demanding this implementation
447 | * is on a system. E.g. reporting a level of 2 means
448 | * this implementation should run decently on all frontends
449 | * of level 2 and up.
450 | *
451 | * It can be used by the frontend to potentially warn
452 | * about too demanding implementations.
453 | *
454 | * The levels are "floating".
455 | *
456 | * This function can be called on a per-game basis,
457 | * as certain games an implementation can play might be
458 | * particularly demanding.
459 | * If called, it should be called in retro_load_game().
460 | */
461 | #define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
462 | /* const char ** --
463 | * Returns the "system" directory of the frontend.
464 | * This directory can be used to store system specific
465 | * content such as BIOSes, configuration data, etc.
466 | * The returned value can be NULL.
467 | * If so, no such directory is defined,
468 | * and it's up to the implementation to find a suitable directory.
469 | *
470 | * NOTE: Some cores used this folder also for "save" data such as
471 | * memory cards, etc, for lack of a better place to put it.
472 | * This is now discouraged, and if possible, cores should try to
473 | * use the new GET_SAVE_DIRECTORY.
474 | */
475 | #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
476 | /* const enum retro_pixel_format * --
477 | * Sets the internal pixel format used by the implementation.
478 | * The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555.
479 | * This pixel format however, is deprecated (see enum retro_pixel_format).
480 | * If the call returns false, the frontend does not support this pixel
481 | * format.
482 | *
483 | * This function should be called inside retro_load_game() or
484 | * retro_get_system_av_info().
485 | */
486 | #define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11
487 | /* const struct retro_input_descriptor * --
488 | * Sets an array of retro_input_descriptors.
489 | * It is up to the frontend to present this in a usable way.
490 | * The array is terminated by retro_input_descriptor::description
491 | * being set to NULL.
492 | * This function can be called at any time, but it is recommended
493 | * to call it as early as possible.
494 | */
495 | #define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12
496 | /* const struct retro_keyboard_callback * --
497 | * Sets a callback function used to notify core about keyboard events.
498 | */
499 | #define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13
500 | /* const struct retro_disk_control_callback * --
501 | * Sets an interface which frontend can use to eject and insert
502 | * disk images.
503 | * This is used for games which consist of multiple images and
504 | * must be manually swapped out by the user (e.g. PSX).
505 | */
506 | #define RETRO_ENVIRONMENT_SET_HW_RENDER 14
507 | /* struct retro_hw_render_callback * --
508 | * Sets an interface to let a libretro core render with
509 | * hardware acceleration.
510 | * Should be called in retro_load_game().
511 | * If successful, libretro cores will be able to render to a
512 | * frontend-provided framebuffer.
513 | * The size of this framebuffer will be at least as large as
514 | * max_width/max_height provided in get_av_info().
515 | * If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or
516 | * NULL to retro_video_refresh_t.
517 | */
518 | #define RETRO_ENVIRONMENT_GET_VARIABLE 15
519 | /* struct retro_variable * --
520 | * Interface to acquire user-defined information from environment
521 | * that cannot feasibly be supported in a multi-system way.
522 | * 'key' should be set to a key which has already been set by
523 | * SET_VARIABLES.
524 | * 'data' will be set to a value or NULL.
525 | */
526 | #define RETRO_ENVIRONMENT_SET_VARIABLES 16
527 | /* const struct retro_variable * --
528 | * Allows an implementation to signal the environment
529 | * which variables it might want to check for later using
530 | * GET_VARIABLE.
531 | * This allows the frontend to present these variables to
532 | * a user dynamically.
533 | * This should be called as early as possible (ideally in
534 | * retro_set_environment).
535 | *
536 | * 'data' points to an array of retro_variable structs
537 | * terminated by a { NULL, NULL } element.
538 | * retro_variable::key should be namespaced to not collide
539 | * with other implementations' keys. E.g. A core called
540 | * 'foo' should use keys named as 'foo_option'.
541 | * retro_variable::value should contain a human readable
542 | * description of the key as well as a '|' delimited list
543 | * of expected values.
544 | *
545 | * The number of possible options should be very limited,
546 | * i.e. it should be feasible to cycle through options
547 | * without a keyboard.
548 | *
549 | * First entry should be treated as a default.
550 | *
551 | * Example entry:
552 | * { "foo_option", "Speed hack coprocessor X; false|true" }
553 | *
554 | * Text before first ';' is description. This ';' must be
555 | * followed by a space, and followed by a list of possible
556 | * values split up with '|'.
557 | *
558 | * Only strings are operated on. The possible values will
559 | * generally be displayed and stored as-is by the frontend.
560 | */
561 | #define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17
562 | /* bool * --
563 | * Result is set to true if some variables are updated by
564 | * frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE.
565 | * Variables should be queried with GET_VARIABLE.
566 | */
567 | #define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18
568 | /* const bool * --
569 | * If true, the libretro implementation supports calls to
570 | * retro_load_game() with NULL as argument.
571 | * Used by cores which can run without particular game data.
572 | * This should be called within retro_set_environment() only.
573 | */
574 | #define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19
575 | /* const char ** --
576 | * Retrieves the absolute path from where this libretro
577 | * implementation was loaded.
578 | * NULL is returned if the libretro was loaded statically
579 | * (i.e. linked statically to frontend), or if the path cannot be
580 | * determined.
581 | * Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can
582 | * be loaded without ugly hacks.
583 | */
584 |
585 | /* Environment 20 was an obsolete version of SET_AUDIO_CALLBACK.
586 | * It was not used by any known core at the time,
587 | * and was removed from the API. */
588 | #define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22
589 | /* const struct retro_audio_callback * --
590 | * Sets an interface which is used to notify a libretro core about audio
591 | * being available for writing.
592 | * The callback can be called from any thread, so a core using this must
593 | * have a thread safe audio implementation.
594 | * It is intended for games where audio and video are completely
595 | * asynchronous and audio can be generated on the fly.
596 | * This interface is not recommended for use with emulators which have
597 | * highly synchronous audio.
598 | *
599 | * The callback only notifies about writability; the libretro core still
600 | * has to call the normal audio callbacks
601 | * to write audio. The audio callbacks must be called from within the
602 | * notification callback.
603 | * The amount of audio data to write is up to the implementation.
604 | * Generally, the audio callback will be called continously in a loop.
605 | *
606 | * Due to thread safety guarantees and lack of sync between audio and
607 | * video, a frontend can selectively disallow this interface based on
608 | * internal configuration. A core using this interface must also
609 | * implement the "normal" audio interface.
610 | *
611 | * A libretro core using SET_AUDIO_CALLBACK should also make use of
612 | * SET_FRAME_TIME_CALLBACK.
613 | */
614 | #define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21
615 | /* const struct retro_frame_time_callback * --
616 | * Lets the core know how much time has passed since last
617 | * invocation of retro_run().
618 | * The frontend can tamper with the timing to fake fast-forward,
619 | * slow-motion, frame stepping, etc.
620 | * In this case the delta time will use the reference value
621 | * in frame_time_callback..
622 | */
623 | #define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23
624 | /* struct retro_rumble_interface * --
625 | * Gets an interface which is used by a libretro core to set
626 | * state of rumble motors in controllers.
627 | * A strong and weak motor is supported, and they can be
628 | * controlled indepedently.
629 | */
630 | #define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24
631 | /* uint64_t * --
632 | * Gets a bitmask telling which device type are expected to be
633 | * handled properly in a call to retro_input_state_t.
634 | * Devices which are not handled or recognized always return
635 | * 0 in retro_input_state_t.
636 | * Example bitmask: caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG).
637 | * Should only be called in retro_run().
638 | */
639 | #define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL)
640 | /* struct retro_sensor_interface * --
641 | * Gets access to the sensor interface.
642 | * The purpose of this interface is to allow
643 | * setting state related to sensors such as polling rate,
644 | * enabling/disable it entirely, etc.
645 | * Reading sensor state is done via the normal
646 | * input_state_callback API.
647 | */
648 | #define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL)
649 | /* struct retro_camera_callback * --
650 | * Gets an interface to a video camera driver.
651 | * A libretro core can use this interface to get access to a
652 | * video camera.
653 | * New video frames are delivered in a callback in same
654 | * thread as retro_run().
655 | *
656 | * GET_CAMERA_INTERFACE should be called in retro_load_game().
657 | *
658 | * Depending on the camera implementation used, camera frames
659 | * will be delivered as a raw framebuffer,
660 | * or as an OpenGL texture directly.
661 | *
662 | * The core has to tell the frontend here which types of
663 | * buffers can be handled properly.
664 | * An OpenGL texture can only be handled when using a
665 | * libretro GL core (SET_HW_RENDER).
666 | * It is recommended to use a libretro GL core when
667 | * using camera interface.
668 | *
669 | * The camera is not started automatically. The retrieved start/stop
670 | * functions must be used to explicitly
671 | * start and stop the camera driver.
672 | */
673 | #define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27
674 | /* struct retro_log_callback * --
675 | * Gets an interface for logging. This is useful for
676 | * logging in a cross-platform way
677 | * as certain platforms cannot use use stderr for logging.
678 | * It also allows the frontend to
679 | * show logging information in a more suitable way.
680 | * If this interface is not used, libretro cores should
681 | * log to stderr as desired.
682 | */
683 | #define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28
684 | /* struct retro_perf_callback * --
685 | * Gets an interface for performance counters. This is useful
686 | * for performance logging in a cross-platform way and for detecting
687 | * architecture-specific features, such as SIMD support.
688 | */
689 | #define RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE 29
690 | /* struct retro_location_callback * --
691 | * Gets access to the location interface.
692 | * The purpose of this interface is to be able to retrieve
693 | * location-based information from the host device,
694 | * such as current latitude / longitude.
695 | */
696 | #define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30
697 | /* const char ** --
698 | * Returns the "content" directory of the frontend.
699 | * This directory can be used to store specific assets that the
700 | * core relies upon, such as art assets,
701 | * input data, etc etc.
702 | * The returned value can be NULL.
703 | * If so, no such directory is defined,
704 | * and it's up to the implementation to find a suitable directory.
705 | */
706 | #define RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY 31
707 | /* const char ** --
708 | * Returns the "save" directory of the frontend.
709 | * This directory can be used to store SRAM, memory cards,
710 | * high scores, etc, if the libretro core
711 | * cannot use the regular memory interface (retro_get_memory_data()).
712 | *
713 | * NOTE: libretro cores used to check GET_SYSTEM_DIRECTORY for
714 | * similar things before.
715 | * They should still check GET_SYSTEM_DIRECTORY if they want to
716 | * be backwards compatible.
717 | * The path here can be NULL. It should only be non-NULL if the
718 | * frontend user has set a specific save path.
719 | */
720 | #define RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO 32
721 | /* const struct retro_system_av_info * --
722 | * Sets a new av_info structure. This can only be called from
723 | * within retro_run().
724 | * This should *only* be used if the core is completely altering the
725 | * internal resolutions, aspect ratios, timings, sampling rate, etc.
726 | * Calling this can require a full reinitialization of video/audio
727 | * drivers in the frontend,
728 | *
729 | * so it is important to call it very sparingly, and usually only with
730 | * the users explicit consent.
731 | * An eventual driver reinitialize will happen so that video and
732 | * audio callbacks
733 | * happening after this call within the same retro_run() call will
734 | * target the newly initialized driver.
735 | *
736 | * This callback makes it possible to support configurable resolutions
737 | * in games, which can be useful to
738 | * avoid setting the "worst case" in max_width/max_height.
739 | *
740 | * ***HIGHLY RECOMMENDED*** Do not call this callback every time
741 | * resolution changes in an emulator core if it's
742 | * expected to be a temporary change, for the reasons of possible
743 | * driver reinitialization.
744 | * This call is not a free pass for not trying to provide
745 | * correct values in retro_get_system_av_info(). If you need to change
746 | * things like aspect ratio or nominal width/height,
747 | * use RETRO_ENVIRONMENT_SET_GEOMETRY, which is a softer variant
748 | * of SET_SYSTEM_AV_INFO.
749 | *
750 | * If this returns false, the frontend does not acknowledge a
751 | * changed av_info struct.
752 | */
753 | #define RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK 33
754 | /* const struct retro_get_proc_address_interface * --
755 | * Allows a libretro core to announce support for the
756 | * get_proc_address() interface.
757 | * This interface allows for a standard way to extend libretro where
758 | * use of environment calls are too indirect,
759 | * e.g. for cases where the frontend wants to call directly into the core.
760 | *
761 | * If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK
762 | * **MUST** be called from within retro_set_environment().
763 | */
764 | #define RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO 34
765 | /* const struct retro_subsystem_info * --
766 | * This environment call introduces the concept of libretro "subsystems".
767 | * A subsystem is a variant of a libretro core which supports
768 | * different kinds of games.
769 | * The purpose of this is to support e.g. emulators which might
770 | * have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo.
771 | * It can also be used to pick among subsystems in an explicit way
772 | * if the libretro implementation is a multi-system emulator itself.
773 | *
774 | * Loading a game via a subsystem is done with retro_load_game_special(),
775 | * and this environment call allows a libretro core to expose which
776 | * subsystems are supported for use with retro_load_game_special().
777 | * A core passes an array of retro_game_special_info which is terminated
778 | * with a zeroed out retro_game_special_info struct.
779 | *
780 | * If a core wants to use this functionality, SET_SUBSYSTEM_INFO
781 | * **MUST** be called from within retro_set_environment().
782 | */
783 | #define RETRO_ENVIRONMENT_SET_CONTROLLER_INFO 35
784 | /* const struct retro_controller_info * --
785 | * This environment call lets a libretro core tell the frontend
786 | * which controller types are recognized in calls to
787 | * retro_set_controller_port_device().
788 | *
789 | * Some emulators such as Super Nintendo
790 | * support multiple lightgun types which must be specifically
791 | * selected from.
792 | * It is therefore sometimes necessary for a frontend to be able
793 | * to tell the core about a special kind of input device which is
794 | * not covered by the libretro input API.
795 | *
796 | * In order for a frontend to understand the workings of an input device,
797 | * it must be a specialized type
798 | * of the generic device types already defined in the libretro API.
799 | *
800 | * Which devices are supported can vary per input port.
801 | * The core must pass an array of const struct retro_controller_info which
802 | * is terminated with a blanked out struct. Each element of the struct
803 | * corresponds to an ascending port index to
804 | * retro_set_controller_port_device().
805 | * Even if special device types are set in the libretro core,
806 | * libretro should only poll input based on the base input device types.
807 | */
808 | #define RETRO_ENVIRONMENT_SET_MEMORY_MAPS (36 | RETRO_ENVIRONMENT_EXPERIMENTAL)
809 | /* const struct retro_memory_map * --
810 | * This environment call lets a libretro core tell the frontend
811 | * about the memory maps this core emulates.
812 | * This can be used to implement, for example, cheats in a core-agnostic way.
813 | *
814 | * Should only be used by emulators; it doesn't make much sense for
815 | * anything else.
816 | * It is recommended to expose all relevant pointers through
817 | * retro_get_memory_* as well.
818 | *
819 | * Can be called from retro_init and retro_load_game.
820 | */
821 | #define RETRO_ENVIRONMENT_SET_GEOMETRY 37
822 | /* const struct retro_game_geometry * --
823 | * This environment call is similar to SET_SYSTEM_AV_INFO for changing
824 | * video parameters, but provides a guarantee that drivers will not be
825 | * reinitialized.
826 | * This can only be called from within retro_run().
827 | *
828 | * The purpose of this call is to allow a core to alter nominal
829 | * width/heights as well as aspect ratios on-the-fly, which can be
830 | * useful for some emulators to change in run-time.
831 | *
832 | * max_width/max_height arguments are ignored and cannot be changed
833 | * with this call as this could potentially require a reinitialization or a
834 | * non-constant time operation.
835 | * If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required.
836 | *
837 | * A frontend must guarantee that this environment call completes in
838 | * constant time.
839 | */
840 | #define RETRO_ENVIRONMENT_GET_USERNAME 38
841 | /* const char **
842 | * Returns the specified username of the frontend, if specified by the user.
843 | * This username can be used as a nickname for a core that has online facilities
844 | * or any other mode where personalization of the user is desirable.
845 | * The returned value can be NULL.
846 | * If this environ callback is used by a core that requires a valid username,
847 | * a default username should be specified by the core.
848 | */
849 | #define RETRO_ENVIRONMENT_GET_LANGUAGE 39
850 | /* unsigned * --
851 | * Returns the specified language of the frontend, if specified by the user.
852 | * It can be used by the core for localization purposes.
853 | */
854 |
855 | #define RETRO_ENVIRONMENT_MAKE_CURRENT_CONTEXT (40 | RETRO_ENVIRONMENT_EXPERIMENTAL)
856 | /* struct retro_hw_make_current_context_callback *
857 | */
858 |
859 | #define RETRO_MEMDESC_CONST (1 << 0) /* The frontend will never change this memory area once retro_load_game has returned. */
860 | #define RETRO_MEMDESC_BIGENDIAN (1 << 1) /* The memory area contains big endian data. Default is little endian. */
861 | #define RETRO_MEMDESC_ALIGN_2 (1 << 16) /* All memory access in this area is aligned to their own size, or 2, whichever is smaller. */
862 | #define RETRO_MEMDESC_ALIGN_4 (2 << 16)
863 | #define RETRO_MEMDESC_ALIGN_8 (3 << 16)
864 | #define RETRO_MEMDESC_MINSIZE_2 (1 << 24) /* All memory in this region is accessed at least 2 bytes at the time. */
865 | #define RETRO_MEMDESC_MINSIZE_4 (2 << 24)
866 | #define RETRO_MEMDESC_MINSIZE_8 (3 << 24)
867 | struct retro_memory_descriptor
868 | {
869 | uint64_t flags;
870 |
871 | /* Pointer to the start of the relevant ROM or RAM chip.
872 | * It's strongly recommended to use 'offset' if possible, rather than
873 | * doing math on the pointer.
874 | *
875 | * If the same byte is mapped my multiple descriptors, their descriptors
876 | * must have the same pointer.
877 | * If 'start' does not point to the first byte in the pointer, put the
878 | * difference in 'offset' instead.
879 | *
880 | * May be NULL if there's nothing usable here (e.g. hardware registers and
881 | * open bus). No flags should be set if the pointer is NULL.
882 | * It's recommended to minimize the number of descriptors if possible,
883 | * but not mandatory. */
884 | void *ptr;
885 | size_t offset;
886 |
887 | /* This is the location in the emulated address space
888 | * where the mapping starts. */
889 | size_t start;
890 |
891 | /* Which bits must be same as in 'start' for this mapping to apply.
892 | * The first memory descriptor to claim a certain byte is the one
893 | * that applies.
894 | * A bit which is set in 'start' must also be set in this.
895 | * Can be zero, in which case each byte is assumed mapped exactly once.
896 | * In this case, 'len' must be a power of two. */
897 | size_t select;
898 |
899 | /* If this is nonzero, the set bits are assumed not connected to the
900 | * memory chip's address pins. */
901 | size_t disconnect;
902 |
903 | /* This one tells the size of the current memory area.
904 | * If, after start+disconnect are applied, the address is higher than
905 | * this, the highest bit of the address is cleared.
906 | *
907 | * If the address is still too high, the next highest bit is cleared.
908 | * Can be zero, in which case it's assumed to be infinite (as limited
909 | * by 'select' and 'disconnect'). */
910 | size_t len;
911 |
912 | /* To go from emulated address to physical address, the following
913 | * order applies:
914 | * Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'.
915 | *
916 | * The address space name must consist of only a-zA-Z0-9_-,
917 | * should be as short as feasible (maximum length is 8 plus the NUL),
918 | * and may not be any other address space plus one or more 0-9A-F
919 | * at the end.
920 | * However, multiple memory descriptors for the same address space is
921 | * allowed, and the address space name can be empty. NULL is treated
922 | * as empty.
923 | *
924 | * Address space names are case sensitive, but avoid lowercase if possible.
925 | * The same pointer may exist in multiple address spaces.
926 | *
927 | * Examples:
928 | * blank+blank - valid (multiple things may be mapped in the same namespace)
929 | * 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace)
930 | * 'A'+'B' - valid (neither is a prefix of each other)
931 | * 'S'+blank - valid ('S' is not in 0-9A-F)
932 | * 'a'+blank - valid ('a' is not in 0-9A-F)
933 | * 'a'+'A' - valid (neither is a prefix of each other)
934 | * 'AR'+blank - valid ('R' is not in 0-9A-F)
935 | * 'ARB'+blank - valid (the B can't be part of the address either, because
936 | * there is no namespace 'AR')
937 | * blank+'B' - not valid, because it's ambigous which address space B1234
938 | * would refer to.
939 | * The length can't be used for that purpose; the frontend may want
940 | * to append arbitrary data to an address, without a separator. */
941 | const char *addrspace;
942 | };
943 |
944 | /* The frontend may use the largest value of 'start'+'select' in a
945 | * certain namespace to infer the size of the address space.
946 | *
947 | * If the address space is larger than that, a mapping with .ptr=NULL
948 | * should be at the end of the array, with .select set to all ones for
949 | * as long as the address space is big.
950 | *
951 | * Sample descriptors (minus .ptr, and RETRO_MEMFLAG_ on the flags):
952 | * SNES WRAM:
953 | * .start=0x7E0000, .len=0x20000
954 | * (Note that this must be mapped before the ROM in most cases; some of the
955 | * ROM mappers
956 | * try to claim $7E0000, or at least $7E8000.)
957 | * SNES SPC700 RAM:
958 | * .addrspace="S", .len=0x10000
959 | * SNES WRAM mirrors:
960 | * .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000
961 | * .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000
962 | * SNES WRAM mirrors, alternate equivalent descriptor:
963 | * .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF
964 | * (Various similar constructions can be created by combining parts of
965 | * the above two.)
966 | * SNES LoROM (512KB, mirrored a couple of times):
967 | * .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024
968 | * .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024
969 | * SNES HiROM (4MB):
970 | * .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024
971 | * .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024
972 | * SNES ExHiROM (8MB):
973 | * .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024
974 | * .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024
975 | * .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024
976 | * .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024
977 | * Clarify the size of the address space:
978 | * .ptr=NULL, .select=0xFFFFFF
979 | * .len can be implied by .select in many of them, but was included for clarity.
980 | */
981 |
982 | struct retro_memory_map
983 | {
984 | const struct retro_memory_descriptor *descriptors;
985 | unsigned num_descriptors;
986 | };
987 |
988 | struct retro_controller_description
989 | {
990 | /* Human-readable description of the controller. Even if using a generic
991 | * input device type, this can be set to the particular device type the
992 | * core uses. */
993 | const char *desc;
994 |
995 | /* Device type passed to retro_set_controller_port_device(). If the device
996 | * type is a sub-class of a generic input device type, use the
997 | * RETRO_DEVICE_SUBCLASS macro to create an ID.
998 | *
999 | * E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1). */
1000 | unsigned id;
1001 | };
1002 |
1003 | struct retro_controller_info
1004 | {
1005 | const struct retro_controller_description *types;
1006 | unsigned num_types;
1007 | };
1008 |
1009 | struct retro_subsystem_memory_info
1010 | {
1011 | /* The extension associated with a memory type, e.g. "psram". */
1012 | const char *extension;
1013 |
1014 | /* The memory type for retro_get_memory(). This should be at
1015 | * least 0x100 to avoid conflict with standardized
1016 | * libretro memory types. */
1017 | unsigned type;
1018 | };
1019 |
1020 | struct retro_subsystem_rom_info
1021 | {
1022 | /* Describes what the content is (SGB BIOS, GB ROM, etc). */
1023 | const char *desc;
1024 |
1025 | /* Same definition as retro_get_system_info(). */
1026 | const char *valid_extensions;
1027 |
1028 | /* Same definition as retro_get_system_info(). */
1029 | bool need_fullpath;
1030 |
1031 | /* Same definition as retro_get_system_info(). */
1032 | bool block_extract;
1033 |
1034 | /* This is set if the content is required to load a game.
1035 | * If this is set to false, a zeroed-out retro_game_info can be passed. */
1036 | bool required;
1037 |
1038 | /* Content can have multiple associated persistent
1039 | * memory types (retro_get_memory()). */
1040 | const struct retro_subsystem_memory_info *memory;
1041 | unsigned num_memory;
1042 | };
1043 |
1044 | struct retro_subsystem_info
1045 | {
1046 | /* Human-readable string of the subsystem type, e.g. "Super GameBoy" */
1047 | const char *desc;
1048 |
1049 | /* A computer friendly short string identifier for the subsystem type.
1050 | * This name must be [a-z].
1051 | * E.g. if desc is "Super GameBoy", this can be "sgb".
1052 | * This identifier can be used for command-line interfaces, etc.
1053 | */
1054 | const char *ident;
1055 |
1056 | /* Infos for each content file. The first entry is assumed to be the
1057 | * "most significant" content for frontend purposes.
1058 | * E.g. with Super GameBoy, the first content should be the GameBoy ROM,
1059 | * as it is the most "significant" content to a user.
1060 | * If a frontend creates new file paths based on the content used
1061 | * (e.g. savestates), it should use the path for the first ROM to do so. */
1062 | const struct retro_subsystem_rom_info *roms;
1063 |
1064 | /* Number of content files associated with a subsystem. */
1065 | unsigned num_roms;
1066 |
1067 | /* The type passed to retro_load_game_special(). */
1068 | unsigned id;
1069 | };
1070 |
1071 | typedef void (*retro_proc_address_t)(void);
1072 |
1073 | /* libretro API extension functions:
1074 | * (None here so far).
1075 | *
1076 | * Get a symbol from a libretro core.
1077 | * Cores should only return symbols which are actual
1078 | * extensions to the libretro API.
1079 | *
1080 | * Frontends should not use this to obtain symbols to standard
1081 | * libretro entry points (static linking or dlsym).
1082 | *
1083 | * The symbol name must be equal to the function name,
1084 | * e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo".
1085 | * The returned function pointer must be cast to the corresponding type.
1086 | */
1087 | typedef retro_proc_address_t (*retro_get_proc_address_t)(const char *sym);
1088 |
1089 | struct retro_get_proc_address_interface
1090 | {
1091 | retro_get_proc_address_t get_proc_address;
1092 | };
1093 |
1094 | enum retro_log_level
1095 | {
1096 | RETRO_LOG_DEBUG = 0,
1097 | RETRO_LOG_INFO,
1098 | RETRO_LOG_WARN,
1099 | RETRO_LOG_ERROR,
1100 |
1101 | RETRO_LOG_DUMMY = INT_MAX
1102 | };
1103 |
1104 | /* Logging function. Takes log level argument as well. */
1105 | typedef void (*retro_log_printf_t)(enum retro_log_level level,
1106 | const char *fmt, ...);
1107 |
1108 | struct retro_log_callback
1109 | {
1110 | retro_log_printf_t log;
1111 | };
1112 |
1113 | /* Performance related functions */
1114 |
1115 | /* ID values for SIMD CPU features */
1116 | #define RETRO_SIMD_SSE (1 << 0)
1117 | #define RETRO_SIMD_SSE2 (1 << 1)
1118 | #define RETRO_SIMD_VMX (1 << 2)
1119 | #define RETRO_SIMD_VMX128 (1 << 3)
1120 | #define RETRO_SIMD_AVX (1 << 4)
1121 | #define RETRO_SIMD_NEON (1 << 5)
1122 | #define RETRO_SIMD_SSE3 (1 << 6)
1123 | #define RETRO_SIMD_SSSE3 (1 << 7)
1124 | #define RETRO_SIMD_MMX (1 << 8)
1125 | #define RETRO_SIMD_MMXEXT (1 << 9)
1126 | #define RETRO_SIMD_SSE4 (1 << 10)
1127 | #define RETRO_SIMD_SSE42 (1 << 11)
1128 | #define RETRO_SIMD_AVX2 (1 << 12)
1129 | #define RETRO_SIMD_VFPU (1 << 13)
1130 | #define RETRO_SIMD_PS (1 << 14)
1131 | #define RETRO_SIMD_AES (1 << 15)
1132 |
1133 | typedef uint64_t retro_perf_tick_t;
1134 | typedef int64_t retro_time_t;
1135 |
1136 | struct retro_perf_counter
1137 | {
1138 | const char *ident;
1139 | retro_perf_tick_t start;
1140 | retro_perf_tick_t total;
1141 | retro_perf_tick_t call_cnt;
1142 |
1143 | bool registered;
1144 | };
1145 |
1146 | /* Returns current time in microseconds.
1147 | * Tries to use the most accurate timer available.
1148 | */
1149 | typedef retro_time_t (*retro_perf_get_time_usec_t)(void);
1150 |
1151 | /* A simple counter. Usually nanoseconds, but can also be CPU cycles.
1152 | * Can be used directly if desired (when creating a more sophisticated
1153 | * performance counter system).
1154 | * */
1155 | typedef retro_perf_tick_t (*retro_perf_get_counter_t)(void);
1156 |
1157 | /* Returns a bit-mask of detected CPU features (RETRO_SIMD_*). */
1158 | typedef uint64_t (*retro_get_cpu_features_t)(void);
1159 |
1160 | /* Asks frontend to log and/or display the state of performance counters.
1161 | * Performance counters can always be poked into manually as well.
1162 | */
1163 | typedef void (*retro_perf_log_t)(void);
1164 |
1165 | /* Register a performance counter.
1166 | * ident field must be set with a discrete value and other values in
1167 | * retro_perf_counter must be 0.
1168 | * Registering can be called multiple times. To avoid calling to
1169 | * frontend redundantly, you can check registered field first. */
1170 | typedef void (*retro_perf_register_t)(struct retro_perf_counter *counter);
1171 |
1172 | /* Starts a registered counter. */
1173 | typedef void (*retro_perf_start_t)(struct retro_perf_counter *counter);
1174 |
1175 | /* Stops a registered counter. */
1176 | typedef void (*retro_perf_stop_t)(struct retro_perf_counter *counter);
1177 |
1178 | /* For convenience it can be useful to wrap register, start and stop in macros.
1179 | * E.g.:
1180 | * #ifdef LOG_PERFORMANCE
1181 | * #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
1182 | * #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
1183 | * #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
1184 | * #else
1185 | * ... Blank macros ...
1186 | * #endif
1187 | *
1188 | * These can then be used mid-functions around code snippets.
1189 | *
1190 | * extern struct retro_perf_callback perf_cb; * Somewhere in the core.
1191 | *
1192 | * void do_some_heavy_work(void)
1193 | * {
1194 | * RETRO_PERFORMANCE_INIT(cb, work_1;
1195 | * RETRO_PERFORMANCE_START(cb, work_1);
1196 | * heavy_work_1();
1197 | * RETRO_PERFORMANCE_STOP(cb, work_1);
1198 | *
1199 | * RETRO_PERFORMANCE_INIT(cb, work_2);
1200 | * RETRO_PERFORMANCE_START(cb, work_2);
1201 | * heavy_work_2();
1202 | * RETRO_PERFORMANCE_STOP(cb, work_2);
1203 | * }
1204 | *
1205 | * void retro_deinit(void)
1206 | * {
1207 | * perf_cb.perf_log(); * Log all perf counters here for example.
1208 | * }
1209 | */
1210 |
1211 | struct retro_perf_callback
1212 | {
1213 | retro_perf_get_time_usec_t get_time_usec;
1214 | retro_get_cpu_features_t get_cpu_features;
1215 |
1216 | retro_perf_get_counter_t get_perf_counter;
1217 | retro_perf_register_t perf_register;
1218 | retro_perf_start_t perf_start;
1219 | retro_perf_stop_t perf_stop;
1220 | retro_perf_log_t perf_log;
1221 | };
1222 |
1223 | /* FIXME: Document the sensor API and work out behavior.
1224 | * It will be marked as experimental until then.
1225 | */
1226 | enum retro_sensor_action
1227 | {
1228 | RETRO_SENSOR_ACCELEROMETER_ENABLE = 0,
1229 | RETRO_SENSOR_ACCELEROMETER_DISABLE,
1230 |
1231 | RETRO_SENSOR_DUMMY = INT_MAX
1232 | };
1233 |
1234 | /* Id values for SENSOR types. */
1235 | #define RETRO_SENSOR_ACCELEROMETER_X 0
1236 | #define RETRO_SENSOR_ACCELEROMETER_Y 1
1237 | #define RETRO_SENSOR_ACCELEROMETER_Z 2
1238 |
1239 | typedef bool (*retro_set_sensor_state_t)(unsigned port,
1240 | enum retro_sensor_action action, unsigned rate);
1241 |
1242 | typedef float (*retro_sensor_get_input_t)(unsigned port, unsigned id);
1243 |
1244 | struct retro_sensor_interface
1245 | {
1246 | retro_set_sensor_state_t set_sensor_state;
1247 | retro_sensor_get_input_t get_sensor_input;
1248 | };
1249 |
1250 | enum retro_camera_buffer
1251 | {
1252 | RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0,
1253 | RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER,
1254 |
1255 | RETRO_CAMERA_BUFFER_DUMMY = INT_MAX
1256 | };
1257 |
1258 | /* Starts the camera driver. Can only be called in retro_run(). */
1259 | typedef bool (*retro_camera_start_t)(void);
1260 |
1261 | /* Stops the camera driver. Can only be called in retro_run(). */
1262 | typedef void (*retro_camera_stop_t)(void);
1263 |
1264 | /* Callback which signals when the camera driver is initialized
1265 | * and/or deinitialized.
1266 | * retro_camera_start_t can be called in initialized callback.
1267 | */
1268 | typedef void (*retro_camera_lifetime_status_t)(void);
1269 |
1270 | /* A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
1271 | * Width, height and pitch are similar to retro_video_refresh_t.
1272 | * First pixel is top-left origin.
1273 | */
1274 | typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer,
1275 | unsigned width, unsigned height, size_t pitch);
1276 |
1277 | /* A callback for when OpenGL textures are used.
1278 | *
1279 | * texture_id is a texture owned by camera driver.
1280 | * Its state or content should be considered immutable, except for things like
1281 | * texture filtering and clamping.
1282 | *
1283 | * texture_target is the texture target for the GL texture.
1284 | * These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly
1285 | * more depending on extensions.
1286 | *
1287 | * affine points to a packed 3x3 column-major matrix used to apply an affine
1288 | * transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
1289 | * After transform, normalized texture coord (0, 0) should be bottom-left
1290 | * and (1, 1) should be top-right (or (width, height) for RECTANGLE).
1291 | *
1292 | * GL-specific typedefs are avoided here to avoid relying on gl.h in
1293 | * the API definition.
1294 | */
1295 | typedef void (*retro_camera_frame_opengl_texture_t)(unsigned texture_id,
1296 | unsigned texture_target, const float *affine);
1297 |
1298 | struct retro_camera_callback
1299 | {
1300 | /* Set by libretro core.
1301 | * Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER).
1302 | */
1303 | uint64_t caps;
1304 |
1305 | unsigned width; /* Desired resolution for camera. Is only used as a hint. */
1306 | unsigned height;
1307 | retro_camera_start_t start; /* Set by frontend. */
1308 | retro_camera_stop_t stop; /* Set by frontend. */
1309 |
1310 | /* Set by libretro core if raw framebuffer callbacks will be used. */
1311 | retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer;
1312 | /* Set by libretro core if OpenGL texture callbacks will be used. */
1313 | retro_camera_frame_opengl_texture_t frame_opengl_texture;
1314 |
1315 | /* Set by libretro core. Called after camera driver is initialized and
1316 | * ready to be started.
1317 | * Can be NULL, in which this callback is not called.
1318 | */
1319 | retro_camera_lifetime_status_t initialized;
1320 |
1321 | /* Set by libretro core. Called right before camera driver is
1322 | * deinitialized.
1323 | * Can be NULL, in which this callback is not called.
1324 | */
1325 | retro_camera_lifetime_status_t deinitialized;
1326 | };
1327 |
1328 | /* Sets the interval of time and/or distance at which to update/poll
1329 | * location-based data.
1330 | *
1331 | * To ensure compatibility with all location-based implementations,
1332 | * values for both interval_ms and interval_distance should be provided.
1333 | *
1334 | * interval_ms is the interval expressed in milliseconds.
1335 | * interval_distance is the distance interval expressed in meters.
1336 | */
1337 | typedef void (*retro_location_set_interval_t)(unsigned interval_ms,
1338 | unsigned interval_distance);
1339 |
1340 | /* Start location services. The device will start listening for changes to the
1341 | * current location at regular intervals (which are defined with
1342 | * retro_location_set_interval_t). */
1343 | typedef bool (*retro_location_start_t)(void);
1344 |
1345 | /* Stop location services. The device will stop listening for changes
1346 | * to the current location. */
1347 | typedef void (*retro_location_stop_t)(void);
1348 |
1349 | /* Get the position of the current location. Will set parameters to
1350 | * 0 if no new location update has happened since the last time. */
1351 | typedef bool (*retro_location_get_position_t)(double *lat, double *lon,
1352 | double *horiz_accuracy, double *vert_accuracy);
1353 |
1354 | /* Callback which signals when the location driver is initialized
1355 | * and/or deinitialized.
1356 | * retro_location_start_t can be called in initialized callback.
1357 | */
1358 | typedef void (*retro_location_lifetime_status_t)(void);
1359 |
1360 | struct retro_location_callback
1361 | {
1362 | retro_location_start_t start;
1363 | retro_location_stop_t stop;
1364 | retro_location_get_position_t get_position;
1365 | retro_location_set_interval_t set_interval;
1366 |
1367 | retro_location_lifetime_status_t initialized;
1368 | retro_location_lifetime_status_t deinitialized;
1369 | };
1370 |
1371 | enum retro_rumble_effect
1372 | {
1373 | RETRO_RUMBLE_STRONG = 0,
1374 | RETRO_RUMBLE_WEAK = 1,
1375 |
1376 | RETRO_RUMBLE_DUMMY = INT_MAX
1377 | };
1378 |
1379 | /* Sets rumble state for joypad plugged in port 'port'.
1380 | * Rumble effects are controlled independently,
1381 | * and setting e.g. strong rumble does not override weak rumble.
1382 | * Strength has a range of [0, 0xffff].
1383 | *
1384 | * Returns true if rumble state request was honored.
1385 | * Calling this before first retro_run() is likely to return false. */
1386 | typedef bool (*retro_set_rumble_state_t)(unsigned port,
1387 | enum retro_rumble_effect effect, uint16_t strength);
1388 |
1389 | struct retro_rumble_interface
1390 | {
1391 | retro_set_rumble_state_t set_rumble_state;
1392 | };
1393 |
1394 | /* Notifies libretro that audio data should be written. */
1395 | typedef void (*retro_audio_callback_t)(void);
1396 |
1397 | /* True: Audio driver in frontend is active, and callback is
1398 | * expected to be called regularily.
1399 | * False: Audio driver in frontend is paused or inactive.
1400 | * Audio callback will not be called until set_state has been
1401 | * called with true.
1402 | * Initial state is false (inactive).
1403 | */
1404 | typedef void (*retro_audio_set_state_callback_t)(bool enabled);
1405 |
1406 | struct retro_audio_callback
1407 | {
1408 | retro_audio_callback_t callback;
1409 | retro_audio_set_state_callback_t set_state;
1410 | };
1411 |
1412 | /* Notifies a libretro core of time spent since last invocation
1413 | * of retro_run() in microseconds.
1414 | *
1415 | * It will be called right before retro_run() every frame.
1416 | * The frontend can tamper with timing to support cases like
1417 | * fast-forward, slow-motion and framestepping.
1418 | *
1419 | * In those scenarios the reference frame time value will be used. */
1420 | typedef int64_t retro_usec_t;
1421 | typedef void (*retro_frame_time_callback_t)(retro_usec_t usec);
1422 | struct retro_frame_time_callback
1423 | {
1424 | retro_frame_time_callback_t callback;
1425 | /* Represents the time of one frame. It is computed as
1426 | * 1000000 / fps, but the implementation will resolve the
1427 | * rounding to ensure that framestepping, etc is exact. */
1428 | retro_usec_t reference;
1429 | };
1430 |
1431 | /* Pass this to retro_video_refresh_t if rendering to hardware.
1432 | * Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
1433 | * */
1434 | #define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)
1435 |
1436 | /* Invalidates the current HW context.
1437 | * Any GL state is lost, and must not be deinitialized explicitly.
1438 | * If explicit deinitialization is desired by the libretro core,
1439 | * it should implement context_destroy callback.
1440 | * If called, all GPU resources must be reinitialized.
1441 | * Usually called when frontend reinits video driver.
1442 | * Also called first time video driver is initialized,
1443 | * allowing libretro core to initialize resources.
1444 | */
1445 | typedef void (*retro_hw_context_reset_t)(void);
1446 |
1447 | /* Gets current framebuffer which is to be rendered to.
1448 | * Could change every frame potentially.
1449 | */
1450 | typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void);
1451 |
1452 | /* Get a symbol from HW context. */
1453 | typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym);
1454 |
1455 | enum retro_hw_context_type
1456 | {
1457 | RETRO_HW_CONTEXT_NONE = 0,
1458 | /* OpenGL 2.x. Driver can choose to use latest compatibility context. */
1459 | RETRO_HW_CONTEXT_OPENGL = 1,
1460 | /* OpenGL ES 2.0. */
1461 | RETRO_HW_CONTEXT_OPENGLES2 = 2,
1462 | /* Modern desktop core GL context. Use version_major/
1463 | * version_minor fields to set GL version. */
1464 | RETRO_HW_CONTEXT_OPENGL_CORE = 3,
1465 | /* OpenGL ES 3.0 */
1466 | RETRO_HW_CONTEXT_OPENGLES3 = 4,
1467 | /* OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3,
1468 | * use the corresponding enums directly. */
1469 | RETRO_HW_CONTEXT_OPENGLES_VERSION = 5,
1470 |
1471 | RETRO_HW_CONTEXT_DUMMY = INT_MAX
1472 | };
1473 |
1474 | /* Call video context driver's 'make current context' function */
1475 | typedef void (*retro_hw_make_current_context)(void);
1476 |
1477 | struct retro_hw_make_current_context_callback
1478 | {
1479 | /* Set by frontend. */
1480 | retro_hw_make_current_context make_current_context;
1481 | };
1482 |
1483 | struct retro_hw_render_callback
1484 | {
1485 | /* Which API to use. Set by libretro core. */
1486 | enum retro_hw_context_type context_type;
1487 |
1488 | /* Called when a context has been created or when it has been reset.
1489 | * An OpenGL context is only valid after context_reset() has been called.
1490 | *
1491 | * When context_reset is called, OpenGL resources in the libretro
1492 | * implementation are guaranteed to be invalid.
1493 | *
1494 | * It is possible that context_reset is called multiple times during an
1495 | * application lifecycle.
1496 | * If context_reset is called without any notification (context_destroy),
1497 | * the OpenGL context was lost and resources should just be recreated
1498 | * without any attempt to "free" old resources.
1499 | */
1500 | retro_hw_context_reset_t context_reset;
1501 |
1502 | /* Set by frontend. */
1503 | retro_hw_get_current_framebuffer_t get_current_framebuffer;
1504 |
1505 | /* Set by frontend. */
1506 | retro_hw_get_proc_address_t get_proc_address;
1507 |
1508 | /* Set if render buffers should have depth component attached. */
1509 | bool depth;
1510 |
1511 | /* Set if stencil buffers should be attached. */
1512 | bool stencil;
1513 |
1514 | /* If depth and stencil are true, a packed 24/8 buffer will be added.
1515 | * Only attaching stencil is invalid and will be ignored. */
1516 |
1517 | /* Use conventional bottom-left origin convention. If false,
1518 | * standard libretro top-left origin semantics are used. */
1519 | bool bottom_left_origin;
1520 |
1521 | /* Major version number for core GL context or GLES 3.1+. */
1522 | unsigned version_major;
1523 |
1524 | /* Minor version number for core GL context or GLES 3.1+. */
1525 | unsigned version_minor;
1526 |
1527 | /* If this is true, the frontend will go very far to avoid
1528 | * resetting context in scenarios like toggling fullscreen, etc.
1529 | */
1530 | bool cache_context;
1531 |
1532 | /* The reset callback might still be called in extreme situations
1533 | * such as if the context is lost beyond recovery.
1534 | *
1535 | * For optimal stability, set this to false, and allow context to be
1536 | * reset at any time.
1537 | */
1538 |
1539 | /* A callback to be called before the context is destroyed in a
1540 | * controlled way by the frontend. */
1541 | retro_hw_context_reset_t context_destroy;
1542 |
1543 | /* OpenGL resources can be deinitialized cleanly at this step.
1544 | * context_destroy can be set to NULL, in which resources will
1545 | * just be destroyed without any notification.
1546 | *
1547 | * Even when context_destroy is non-NULL, it is possible that
1548 | * context_reset is called without any destroy notification.
1549 | * This happens if context is lost by external factors (such as
1550 | * notified by GL_ARB_robustness).
1551 | *
1552 | * In this case, the context is assumed to be already dead,
1553 | * and the libretro implementation must not try to free any OpenGL
1554 | * resources in the subsequent context_reset.
1555 | */
1556 |
1557 | /* Creates a debug context. */
1558 | bool debug_context;
1559 | };
1560 |
1561 | /* Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
1562 | * Called by the frontend in response to keyboard events.
1563 | * down is set if the key is being pressed, or false if it is being released.
1564 | * keycode is the RETROK value of the char.
1565 | * character is the text character of the pressed key. (UTF-32).
1566 | * key_modifiers is a set of RETROKMOD values or'ed together.
1567 | *
1568 | * The pressed/keycode state can be indepedent of the character.
1569 | * It is also possible that multiple characters are generated from a
1570 | * single keypress.
1571 | * Keycode events should be treated separately from character events.
1572 | * However, when possible, the frontend should try to synchronize these.
1573 | * If only a character is posted, keycode should be RETROK_UNKNOWN.
1574 | *
1575 | * Similarily if only a keycode event is generated with no corresponding
1576 | * character, character should be 0.
1577 | */
1578 | typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode,
1579 | uint32_t character, uint16_t key_modifiers);
1580 |
1581 | struct retro_keyboard_callback
1582 | {
1583 | retro_keyboard_event_t callback;
1584 | };
1585 |
1586 | /* Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
1587 | * Should be set for implementations which can swap out multiple disk
1588 | * images in runtime.
1589 | *
1590 | * If the implementation can do this automatically, it should strive to do so.
1591 | * However, there are cases where the user must manually do so.
1592 | *
1593 | * Overview: To swap a disk image, eject the disk image with
1594 | * set_eject_state(true).
1595 | * Set the disk index with set_image_index(index). Insert the disk again
1596 | * with set_eject_state(false).
1597 | */
1598 |
1599 | /* If ejected is true, "ejects" the virtual disk tray.
1600 | * When ejected, the disk image index can be set.
1601 | */
1602 | typedef bool (*retro_set_eject_state_t)(bool ejected);
1603 |
1604 | /* Gets current eject state. The initial state is 'not ejected'. */
1605 | typedef bool (*retro_get_eject_state_t)(void);
1606 |
1607 | /* Gets current disk index. First disk is index 0.
1608 | * If return value is >= get_num_images(), no disk is currently inserted.
1609 | */
1610 | typedef unsigned (*retro_get_image_index_t)(void);
1611 |
1612 | /* Sets image index. Can only be called when disk is ejected.
1613 | * The implementation supports setting "no disk" by using an
1614 | * index >= get_num_images().
1615 | */
1616 | typedef bool (*retro_set_image_index_t)(unsigned index);
1617 |
1618 | /* Gets total number of images which are available to use. */
1619 | typedef unsigned (*retro_get_num_images_t)(void);
1620 |
1621 | struct retro_game_info;
1622 |
1623 | /* Replaces the disk image associated with index.
1624 | * Arguments to pass in info have same requirements as retro_load_game().
1625 | * Virtual disk tray must be ejected when calling this.
1626 | *
1627 | * Replacing a disk image with info = NULL will remove the disk image
1628 | * from the internal list.
1629 | * As a result, calls to get_image_index() can change.
1630 | *
1631 | * E.g. replace_image_index(1, NULL), and previous get_image_index()
1632 | * returned 4 before.
1633 | * Index 1 will be removed, and the new index is 3.
1634 | */
1635 | typedef bool (*retro_replace_image_index_t)(unsigned index,
1636 | const struct retro_game_info *info);
1637 |
1638 | /* Adds a new valid index (get_num_images()) to the internal disk list.
1639 | * This will increment subsequent return values from get_num_images() by 1.
1640 | * This image index cannot be used until a disk image has been set
1641 | * with replace_image_index. */
1642 | typedef bool (*retro_add_image_index_t)(void);
1643 |
1644 | struct retro_disk_control_callback
1645 | {
1646 | retro_set_eject_state_t set_eject_state;
1647 | retro_get_eject_state_t get_eject_state;
1648 |
1649 | retro_get_image_index_t get_image_index;
1650 | retro_set_image_index_t set_image_index;
1651 | retro_get_num_images_t get_num_images;
1652 |
1653 | retro_replace_image_index_t replace_image_index;
1654 | retro_add_image_index_t add_image_index;
1655 | };
1656 |
1657 | enum retro_pixel_format
1658 | {
1659 | /* 0RGB1555, native endian.
1660 | * 0 bit must be set to 0.
1661 | * This pixel format is default for compatibility concerns only.
1662 | * If a 15/16-bit pixel format is desired, consider using RGB565. */
1663 | RETRO_PIXEL_FORMAT_0RGB1555 = 0,
1664 |
1665 | /* XRGB8888, native endian.
1666 | * X bits are ignored. */
1667 | RETRO_PIXEL_FORMAT_XRGB8888 = 1,
1668 |
1669 | /* RGB565, native endian.
1670 | * This pixel format is the recommended format to use if a 15/16-bit
1671 | * format is desired as it is the pixel format that is typically
1672 | * available on a wide range of low-power devices.
1673 | *
1674 | * It is also natively supported in APIs like OpenGL ES. */
1675 | RETRO_PIXEL_FORMAT_RGB565 = 2,
1676 |
1677 | /* Ensure sizeof() == sizeof(int). */
1678 | RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX
1679 | };
1680 |
1681 | struct retro_message
1682 | {
1683 | const char *msg; /* Message to be displayed. */
1684 | unsigned frames; /* Duration in frames of message. */
1685 | };
1686 |
1687 | /* Describes how the libretro implementation maps a libretro input bind
1688 | * to its internal input system through a human readable string.
1689 | * This string can be used to better let a user configure input. */
1690 | struct retro_input_descriptor
1691 | {
1692 | /* Associates given parameters with a description. */
1693 | unsigned port;
1694 | unsigned device;
1695 | unsigned index;
1696 | unsigned id;
1697 |
1698 | /* Human readable description for parameters.
1699 | * The pointer must remain valid until
1700 | * retro_unload_game() is called. */
1701 | const char *description;
1702 | };
1703 |
1704 | struct retro_system_info
1705 | {
1706 | /* All pointers are owned by libretro implementation, and pointers must
1707 | * remain valid until retro_deinit() is called. */
1708 |
1709 | const char *library_name; /* Descriptive name of library. Should not
1710 | * contain any version numbers, etc. */
1711 | const char *library_version; /* Descriptive version of core. */
1712 |
1713 | const char *valid_extensions; /* A string listing probably content
1714 | * extensions the core will be able to
1715 | * load, separated with pipe.
1716 | * I.e. "bin|rom|iso".
1717 | * Typically used for a GUI to filter
1718 | * out extensions. */
1719 |
1720 | /* If true, retro_load_game() is guaranteed to provide a valid pathname
1721 | * in retro_game_info::path.
1722 | * ::data and ::size are both invalid.
1723 | *
1724 | * If false, ::data and ::size are guaranteed to be valid, but ::path
1725 | * might not be valid.
1726 | *
1727 | * This is typically set to true for libretro implementations that must
1728 | * load from file.
1729 | * Implementations should strive for setting this to false, as it allows
1730 | * the frontend to perform patching, etc. */
1731 | bool need_fullpath;
1732 |
1733 | /* If true, the frontend is not allowed to extract any archives before
1734 | * loading the real content.
1735 | * Necessary for certain libretro implementations that load games
1736 | * from zipped archives. */
1737 | bool block_extract;
1738 | };
1739 |
1740 | struct retro_game_geometry
1741 | {
1742 | unsigned base_width; /* Nominal video width of game. */
1743 | unsigned base_height; /* Nominal video height of game. */
1744 | unsigned max_width; /* Maximum possible width of game. */
1745 | unsigned max_height; /* Maximum possible height of game. */
1746 |
1747 | float aspect_ratio; /* Nominal aspect ratio of game. If
1748 | * aspect_ratio is <= 0.0, an aspect ratio
1749 | * of base_width / base_height is assumed.
1750 | * A frontend could override this setting,
1751 | * if desired. */
1752 | };
1753 |
1754 | struct retro_system_timing
1755 | {
1756 | double fps; /* FPS of video content. */
1757 | double sample_rate; /* Sampling rate of audio. */
1758 | };
1759 |
1760 | struct retro_system_av_info
1761 | {
1762 | struct retro_game_geometry geometry;
1763 | struct retro_system_timing timing;
1764 | };
1765 |
1766 | struct retro_variable
1767 | {
1768 | /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.
1769 | * If NULL, obtains the complete environment string if more
1770 | * complex parsing is necessary.
1771 | * The environment string is formatted as key-value pairs
1772 | * delimited by semicolons as so:
1773 | * "key1=value1;key2=value2;..."
1774 | */
1775 | const char *key;
1776 |
1777 | /* Value to be obtained. If key does not exist, it is set to NULL. */
1778 | const char *value;
1779 | };
1780 |
1781 | struct retro_game_info
1782 | {
1783 | const char *path; /* Path to game, UTF-8 encoded.
1784 | * Usually used as a reference.
1785 | * May be NULL if rom was loaded from stdin
1786 | * or similar.
1787 | * retro_system_info::need_fullpath guaranteed
1788 | * that this path is valid. */
1789 | const void *data; /* Memory buffer of loaded game. Will be NULL
1790 | * if need_fullpath was set. */
1791 | size_t size; /* Size of memory buffer. */
1792 | const char *meta; /* String of implementation specific meta-data. */
1793 | };
1794 |
1795 | /* Callbacks */
1796 |
1797 | /* Environment callback. Gives implementations a way of performing
1798 | * uncommon tasks. Extensible. */
1799 | typedef bool (*retro_environment_t)(unsigned cmd, void *data);
1800 |
1801 | /* Render a frame. Pixel format is 15-bit 0RGB1555 native endian
1802 | * unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
1803 | *
1804 | * Width and height specify dimensions of buffer.
1805 | * Pitch specifices length in bytes between two lines in buffer.
1806 | *
1807 | * For performance reasons, it is highly recommended to have a frame
1808 | * that is packed in memory, i.e. pitch == width * byte_per_pixel.
1809 | * Certain graphic APIs, such as OpenGL ES, do not like textures
1810 | * that are not packed in memory.
1811 | */
1812 | typedef void (*retro_video_refresh_t)(const void *data, unsigned width,
1813 | unsigned height, size_t pitch);
1814 |
1815 | /* Renders a single audio frame. Should only be used if implementation
1816 | * generates a single sample at a time.
1817 | * Format is signed 16-bit native endian.
1818 | */
1819 | typedef void (*retro_audio_sample_t)(int16_t left, int16_t right);
1820 |
1821 | /* Renders multiple audio frames in one go.
1822 | *
1823 | * One frame is defined as a sample of left and right channels, interleaved.
1824 | * I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
1825 | * Only one of the audio callbacks must ever be used.
1826 | */
1827 | typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data,
1828 | size_t frames);
1829 |
1830 | /* Polls input. */
1831 | typedef void (*retro_input_poll_t)(void);
1832 |
1833 | /* Queries for input for player 'port'. device will be masked with
1834 | * RETRO_DEVICE_MASK.
1835 | *
1836 | * Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that
1837 | * have been set with retro_set_controller_port_device()
1838 | * will still use the higher level RETRO_DEVICE_JOYPAD to request input.
1839 | */
1840 | typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device,
1841 | unsigned index, unsigned id);
1842 |
1843 | /* Sets callbacks. retro_set_environment() is guaranteed to be called
1844 | * before retro_init().
1845 | *
1846 | * The rest of the set_* functions are guaranteed to have been called
1847 | * before the first call to retro_run() is made. */
1848 | void retro_set_environment(retro_environment_t);
1849 | void retro_set_video_refresh(retro_video_refresh_t);
1850 | void retro_set_audio_sample(retro_audio_sample_t);
1851 | void retro_set_audio_sample_batch(retro_audio_sample_batch_t);
1852 | void retro_set_input_poll(retro_input_poll_t);
1853 | void retro_set_input_state(retro_input_state_t);
1854 |
1855 | /* Library global initialization/deinitialization. */
1856 | void retro_init(void);
1857 | void retro_deinit(void);
1858 |
1859 | /* Must return RETRO_API_VERSION. Used to validate ABI compatibility
1860 | * when the API is revised. */
1861 | unsigned retro_api_version(void);
1862 |
1863 | /* Gets statically known system info. Pointers provided in *info
1864 | * must be statically allocated.
1865 | * Can be called at any time, even before retro_init(). */
1866 | void retro_get_system_info(struct retro_system_info *info);
1867 |
1868 | /* Gets information about system audio/video timings and geometry.
1869 | * Can be called only after retro_load_game() has successfully completed.
1870 | * NOTE: The implementation of this function might not initialize every
1871 | * variable if needed.
1872 | * E.g. geom.aspect_ratio might not be initialized if core doesn't
1873 | * desire a particular aspect ratio. */
1874 | void retro_get_system_av_info(struct retro_system_av_info *info);
1875 |
1876 | /* Sets device to be used for player 'port'.
1877 | * By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all
1878 | * available ports.
1879 | * Setting a particular device type is not a guarantee that libretro cores
1880 | * will only poll input based on that particular device type. It is only a
1881 | * hint to the libretro core when a core cannot automatically detect the
1882 | * appropriate input device type on its own. It is also relevant when a
1883 | * core can change its behavior depending on device type. */
1884 | void retro_set_controller_port_device(unsigned port, unsigned device);
1885 |
1886 | /* Resets the current game. */
1887 | void retro_reset(void);
1888 |
1889 | /* Runs the game for one video frame.
1890 | * During retro_run(), input_poll callback must be called at least once.
1891 | *
1892 | * If a frame is not rendered for reasons where a game "dropped" a frame,
1893 | * this still counts as a frame, and retro_run() should explicitly dupe
1894 | * a frame if GET_CAN_DUPE returns true.
1895 | * In this case, the video callback can take a NULL argument for data.
1896 | */
1897 | void retro_run(void);
1898 |
1899 | /* Returns the amount of data the implementation requires to serialize
1900 | * internal state (save states).
1901 | * Between calls to retro_load_game() and retro_unload_game(), the
1902 | * returned size is never allowed to be larger than a previous returned
1903 | * value, to ensure that the frontend can allocate a save state buffer once.
1904 | */
1905 | size_t retro_serialize_size(void);
1906 |
1907 | /* Serializes internal state. If failed, or size is lower than
1908 | * retro_serialize_size(), it should return false, true otherwise. */
1909 | bool retro_serialize(void *data, size_t size);
1910 | bool retro_unserialize(const void *data, size_t size);
1911 |
1912 | void retro_cheat_reset(void);
1913 | void retro_cheat_set(unsigned index, bool enabled, const char *code);
1914 |
1915 | /* Loads a game. */
1916 | bool retro_load_game(const struct retro_game_info *game);
1917 |
1918 | /* Loads a "special" kind of game. Should not be used,
1919 | * except in extreme cases. */
1920 | bool retro_load_game_special(
1921 | unsigned game_type,
1922 | const struct retro_game_info *info, size_t num_info
1923 | );
1924 |
1925 | /* Unloads a currently loaded game. */
1926 | void retro_unload_game(void);
1927 |
1928 | /* Gets region of game. */
1929 | unsigned retro_get_region(void);
1930 |
1931 | /* Gets region of memory. */
1932 | void *retro_get_memory_data(unsigned id);
1933 | size_t retro_get_memory_size(unsigned id);
1934 |
1935 | #ifdef __cplusplus
1936 | }
1937 | #endif
1938 |
1939 | #endif
1940 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "arch.js",
3 | "description": "Emscripten + Libretro = ♥",
4 | "version": "1.1.0",
5 | "scripts": {
6 | "build": "find . \\( -name 'Makefile.*' -a -not -name 'Makefile.common' \\) -exec emmake make -f {} \\;",
7 | "prepublish": "npm run build",
8 | "gh-pages": "(git checkout gh-pages && git reset --hard master && npm run build && git add -f build && git commit -m gh-pages && git push -f --set-upstream origin gh-pages && git checkout -)"
9 | },
10 | "peerDependencies": {
11 | "virtjs": "^0.3.4"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/sources/bridge_retro.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 |
7 | #include "./bridge_retro.h"
8 | #include "./bridge_virtjs.h"
9 | #include "./input_formats.h"
10 |
11 | void bridge_retro_log(enum retro_log_level level, char const * format, ...)
12 | {
13 | va_list args;
14 | va_start(args, format);
15 | vfprintf(stderr, format, args);
16 | va_end(args);
17 | }
18 |
19 | bool bridge_retro_environment(unsigned command, void * data)
20 | {
21 | switch (command) {
22 |
23 | default:
24 | return false;
25 |
26 | case RETRO_ENVIRONMENT_GET_LOG_INTERFACE: {
27 |
28 | ((struct retro_log_callback *) data)->log = bridge_retro_log;
29 |
30 | return true;
31 |
32 | } break ;
33 |
34 | case RETRO_ENVIRONMENT_GET_CAN_DUPE: {
35 |
36 | *(bool*) data = true;
37 |
38 | return true;
39 |
40 | } break ;
41 |
42 | case RETRO_ENVIRONMENT_SET_PIXEL_FORMAT: {
43 |
44 | enum retro_pixel_format const * retro_pixel_format = (enum retro_pixel_format *) data;
45 | struct input_format const * input_format = get_input_format(*retro_pixel_format);
46 |
47 | if (!input_format || !bridge_virtjs_screen_validate_input_format(input_format->depth, input_format->r_mask, input_format->g_mask, input_format->b_mask, input_format->a_mask))
48 | return false;
49 |
50 | bridge_virtjs_screen_set_input_format(input_format->depth, input_format->r_mask, input_format->g_mask, input_format->b_mask, input_format->a_mask);
51 | return true;
52 |
53 | } break ;
54 |
55 | }
56 | }
57 |
58 | void bridge_retro_video_refresh(void const * data, unsigned width, unsigned height, size_t pitch)
59 | {
60 | bridge_virtjs_screen_set_input_size(width, height, pitch);
61 | bridge_virtjs_screen_set_input_data(data);
62 | }
63 |
64 | void bridge_retro_input_poll(void)
65 | {
66 | bridge_virtjs_input_poll_inputs();
67 | }
68 |
69 | int16_t bridge_retro_input_state(unsigned port, unsigned device, unsigned index, unsigned id)
70 | {
71 | if (device != RETRO_DEVICE_JOYPAD || index != 0)
72 | return 0;
73 |
74 | return bridge_virtjs_input_get_state(port, id);
75 | }
76 |
77 | void bridge_retro_audio_sample(int16_t left, int16_t right)
78 | {
79 | int16_t sample[] = { left, right };
80 |
81 | bridge_virtjs_audio_push_sample_batch(sample, 1);
82 | }
83 |
84 | size_t bridge_retro_audio_sample_batch(int16_t const * samples, size_t count)
85 | {
86 | bridge_virtjs_audio_push_sample_batch(samples, count);
87 |
88 | return count;
89 | }
90 |
--------------------------------------------------------------------------------
/sources/bridge_retro.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include
6 |
7 | void bridge_retro_log(enum retro_log_level level, char const * format, ...);
8 |
9 | bool bridge_retro_environment(unsigned command, void * data);
10 |
11 | void bridge_retro_video_refresh(void const * data, unsigned width, unsigned height, size_t pitch);
12 |
13 | void bridge_retro_input_poll(void);
14 |
15 | int16_t bridge_retro_input_state(unsigned port, unsigned device, unsigned index, unsigned id);
16 |
17 | void bridge_retro_audio_sample(int16_t left, int16_t right);
18 |
19 | size_t bridge_retro_audio_sample_batch(int16_t const * samples, size_t count);
20 |
--------------------------------------------------------------------------------
/sources/bridge_virtjs.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 | #include
7 |
8 | #include "./bridge_virtjs.h"
9 | #include "./frontend.h"
10 | #include "./input_formats.h"
11 |
12 | static void (*g_timer_callback)(void) = NULL;
13 | static bool g_timer_is_running = false;
14 | static bool g_timer_has_parent = false;
15 |
16 | static SDL_Window * g_window = NULL;
17 | static SDL_Surface * g_screen = NULL;
18 | static SDL_Surface * g_pending = NULL;
19 |
20 | static int16_t * g_audio_samples = NULL;
21 | static size_t g_audio_sample_count = 0;
22 |
23 | static unsigned g_input_width = 0;
24 | static unsigned g_input_height = 0;
25 | static unsigned g_input_pitch = 0;
26 |
27 | struct input_format const * g_input_format = NULL;
28 |
29 | static bool g_input_state[ 16 ] = { 0 };
30 |
31 | static unsigned g_input_bindings[ ][ 2 ] = {
32 |
33 | { SDL_SCANCODE_RETURN, RETRO_DEVICE_ID_JOYPAD_START },
34 |
35 | { SDL_SCANCODE_A, RETRO_DEVICE_ID_JOYPAD_A },
36 | { SDL_SCANCODE_Q, RETRO_DEVICE_ID_JOYPAD_A },
37 | { SDL_SCANCODE_Z, RETRO_DEVICE_ID_JOYPAD_B },
38 | { SDL_SCANCODE_W, RETRO_DEVICE_ID_JOYPAD_B },
39 |
40 | { SDL_SCANCODE_LEFT, RETRO_DEVICE_ID_JOYPAD_LEFT },
41 | { SDL_SCANCODE_RIGHT, RETRO_DEVICE_ID_JOYPAD_RIGHT },
42 | { SDL_SCANCODE_UP, RETRO_DEVICE_ID_JOYPAD_UP },
43 | { SDL_SCANCODE_DOWN, RETRO_DEVICE_ID_JOYPAD_DOWN }
44 |
45 | };
46 |
47 | static void timer_iterate(void)
48 | {
49 | Uint32 lastTime = SDL_GetTicks();
50 |
51 | void (*timer_callback)(void) = g_timer_callback;
52 | g_timer_callback = NULL;
53 |
54 | SDL_Event event;
55 |
56 | if (SDL_PollEvent(&event)) {
57 | if (event.type == SDL_QUIT) {
58 | bridge_virtjs_timer_stop(); return;
59 | } else if (event.type == SDL_KEYDOWN) switch (event.key.keysym.scancode) {
60 | case SDL_SCANCODE_ESCAPE: bridge_virtjs_timer_stop(); return;
61 | case SDL_SCANCODE_F1: if (frontend_save_state() < 0) fprintf(stderr, "Save failed\n"); break;
62 | case SDL_SCANCODE_F2: if (frontend_load_state() < 0) fprintf(stderr, "Load failed\n"); break;
63 | default: break;
64 | }
65 | }
66 |
67 | timer_callback();
68 |
69 | Uint32 currentTime = SDL_GetTicks();
70 |
71 | Uint32 obtained = currentTime - lastTime;
72 | Uint32 expected = 1000 / 60;
73 |
74 | if (obtained < expected) {
75 | SDL_Delay(expected - obtained);
76 | }
77 | }
78 |
79 | static void audio_write(int16_t const * samples, size_t count)
80 | {
81 | SDL_LockAudio();
82 |
83 | int16_t * previous_samples = g_audio_samples;
84 | size_t previous_count = g_audio_sample_count;
85 |
86 | g_audio_sample_count = previous_count + count;
87 | g_audio_samples = calloc(g_audio_sample_count * 2, sizeof(int16_t));
88 |
89 | for (size_t index = 0; index < previous_count * 2; ++ index)
90 | g_audio_samples[ index ] = previous_samples[ index ];
91 |
92 | for (size_t index = 0; index < count * 2; ++ index)
93 | g_audio_samples[ previous_count * 2 + index ] = samples[ index ];
94 |
95 | free(previous_samples);
96 |
97 | SDL_UnlockAudio();
98 | }
99 |
100 | static void audio_callback(void * userdata, Uint8 * stream, int length)
101 | {
102 | int16_t * available_samples = g_audio_samples;
103 | size_t available_sample_count = g_audio_sample_count;
104 |
105 | size_t requested_sample_count = length / 2 / 2;
106 | size_t requested_byte_length = requested_sample_count * 2 * 2;
107 |
108 | size_t providen_sample_count = requested_sample_count < available_sample_count ? requested_sample_count : available_sample_count;
109 | size_t providen_byte_length = providen_sample_count * 2 * 2;
110 |
111 | memcpy(stream, available_samples, providen_byte_length);
112 | memset(stream + providen_byte_length, 0, requested_byte_length - providen_byte_length);
113 |
114 | g_audio_samples = NULL;
115 | g_audio_sample_count = 0;
116 |
117 | if (providen_sample_count < available_sample_count)
118 | audio_write(available_samples + providen_sample_count * 2, available_sample_count - providen_sample_count);
119 |
120 | free(available_samples);
121 | }
122 |
123 | void bridge_virtjs_input_poll_inputs(void)
124 | {
125 | uint8_t const * keyboard_state = SDL_GetKeyboardState(NULL);
126 |
127 | for (size_t t = 0, T = sizeof(g_input_bindings) / sizeof(*g_input_bindings); t < T; ++ t) {
128 |
129 | unsigned sdl_key_code = g_input_bindings[ t ][ 0 ];
130 | unsigned retro_key_code = g_input_bindings[ t ][ 1 ];
131 |
132 | g_input_state[ retro_key_code ] = keyboard_state[ sdl_key_code ];
133 |
134 | }
135 | }
136 |
137 | bool bridge_virtjs_input_get_state(unsigned port, unsigned key)
138 | {
139 | if (port != 0)
140 | return 0;
141 |
142 | return g_input_state[ key ];
143 | }
144 |
145 | int bridge_virtjs_timer_next_tick(void (*callback)(void))
146 | {
147 | assert(g_timer_callback == NULL);
148 |
149 | g_timer_callback = callback;
150 |
151 | return 1;
152 | }
153 |
154 | void bridge_virtjs_timer_cancel_tick(int identifier)
155 | {
156 | if (identifier != 1)
157 | return ;
158 |
159 | g_timer_callback = NULL;
160 | }
161 |
162 | void bridge_virtjs_timer_start(void)
163 | {
164 | g_timer_is_running = true;
165 |
166 | if (g_timer_has_parent)
167 | return ;
168 |
169 | g_timer_has_parent = true;
170 |
171 | while (g_timer_is_running)
172 | timer_iterate();
173 |
174 | g_timer_has_parent = false;
175 | }
176 |
177 | void bridge_virtjs_timer_stop(void)
178 | {
179 | g_timer_is_running = false;
180 | }
181 |
182 | bool bridge_virtjs_screen_validate_input_format(unsigned depth, uint32_t r_mask, uint32_t g_mask, uint32_t b_mask, uint32_t a_mask)
183 | {
184 | return true;
185 | }
186 |
187 | void bridge_virtjs_screen_set_input_format(unsigned depth, uint32_t r_mask, uint32_t g_mask, uint32_t b_mask, uint32_t a_mask)
188 | {
189 | static struct input_format input_format;
190 | g_input_format = &input_format;
191 |
192 | input_format.depth = depth;
193 |
194 | input_format.r_mask = r_mask;
195 | input_format.g_mask = g_mask;
196 | input_format.b_mask = b_mask;
197 | input_format.a_mask = a_mask;
198 | }
199 |
200 | void bridge_virtjs_screen_set_input_size(unsigned width, unsigned height, unsigned pitch)
201 | {
202 | if (g_window && g_input_width == width && g_input_height == height && g_input_pitch == pitch)
203 | return ;
204 |
205 | g_input_width = width;
206 | g_input_height = height;
207 | g_input_pitch = pitch;
208 |
209 | if (! g_window) {
210 |
211 | SDL_InitSubSystem(SDL_INIT_VIDEO);
212 | SDL_ClearError();
213 |
214 | g_window = SDL_CreateWindow("archjs", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, g_input_width, g_input_height, SDL_WINDOW_SHOWN);
215 | g_screen = SDL_GetWindowSurface(g_window);
216 |
217 | } else {
218 |
219 | SDL_SetWindowSize(g_window, g_input_width, g_input_height);
220 |
221 | }
222 | }
223 |
224 | void bridge_virtjs_screen_set_input_data(void const * data)
225 | {
226 | if (! data)
227 | return ;
228 |
229 | g_pending = SDL_CreateRGBSurfaceFrom((void*) data, g_input_width, g_input_height, g_input_format->depth, g_input_pitch, g_input_format->r_mask, g_input_format->g_mask, g_input_format->b_mask, 0);
230 | }
231 |
232 | void bridge_virtjs_screen_flush_screen(void)
233 | {
234 | if (! g_pending)
235 | return ;
236 |
237 | SDL_BlitSurface(g_pending, NULL, g_screen, NULL);
238 | SDL_UpdateWindowSurface(g_window);
239 |
240 | SDL_FreeSurface(g_pending);
241 | g_pending = NULL;
242 | }
243 |
244 | bool bridge_virtjs_audio_validate_input_format(unsigned sample_rate)
245 | {
246 | return true;
247 | }
248 |
249 | void bridge_virtjs_audio_set_input_format(unsigned sample_rate)
250 | {
251 | SDL_InitSubSystem(SDL_INIT_AUDIO);
252 |
253 | SDL_AudioSpec desired_spec;
254 | SDL_AudioSpec obtained_spec;
255 |
256 | desired_spec.freq = sample_rate;
257 | desired_spec.format = AUDIO_S16SYS;
258 | desired_spec.channels = 2;
259 | desired_spec.samples = 1024;
260 | desired_spec.callback = audio_callback;
261 | desired_spec.userdata = NULL;
262 |
263 | SDL_OpenAudio(&desired_spec, &obtained_spec);
264 |
265 | SDL_PauseAudio(0);
266 |
267 | }
268 |
269 | void bridge_virtjs_audio_push_sample_batch(int16_t const * samples, unsigned count)
270 | {
271 | audio_write(samples, count);
272 | }
273 |
--------------------------------------------------------------------------------
/sources/bridge_virtjs.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "./input_formats.h"
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | void bridge_virtjs_input_poll_inputs(void);
12 | bool bridge_virtjs_input_get_state(unsigned device, unsigned code);
13 |
14 | void bridge_virtjs_timer_start(void);
15 | void bridge_virtjs_timer_stop(void);
16 | int bridge_virtjs_timer_next_tick(void (*callback)(void));
17 | void bridge_virtjs_timer_cancel_tick(int);
18 |
19 | bool bridge_virtjs_screen_validate_input_format(unsigned depth, uint32_t r_mask, uint32_t g_mask, uint32_t b_mask, uint32_t a_mask);
20 | void bridge_virtjs_screen_set_input_format(unsigned depth, uint32_t r_mask, uint32_t g_mask, uint32_t b_mask, uint32_t a_mask);
21 | void bridge_virtjs_screen_set_input_size(unsigned width, unsigned height, unsigned pitch);
22 | void bridge_virtjs_screen_set_input_data(void const * data);
23 | void bridge_virtjs_screen_flush_screen(void);
24 |
25 | bool bridge_virtjs_audio_validate_input_format(unsigned input_sample_rate);
26 | void bridge_virtjs_audio_set_input_format(unsigned input_sample_rate);
27 | void bridge_virtjs_audio_push_sample_batch(int16_t const * samples, unsigned count);
28 |
29 | #ifdef __cplusplus
30 | }
31 | #endif
32 |
--------------------------------------------------------------------------------
/sources/bridge_virtjs.js:
--------------------------------------------------------------------------------
1 | mergeInto(LibraryManager.library, {
2 |
3 | $VirtjsBridge: {
4 |
5 | audioFormat: function (n) {
6 |
7 | return n / 0x8000;
8 |
9 | },
10 |
11 | getHeapFromDepth: function (depth) { switch (depth) {
12 |
13 | default: throw new Error('Invalid depth (' + depth + ')');
14 |
15 | case 8: return HEAPU8;
16 | case 16: return HEAPU16;
17 | case 32: return HEAPU32;
18 |
19 | } },
20 |
21 | castPointerToData: function (pointer, heap, count) {
22 |
23 | var bytesPerElement = heap.BYTES_PER_ELEMENT;
24 |
25 | var start = pointer / heap.BYTES_PER_ELEMENT;
26 | var end = start + count;
27 |
28 | return heap.subarray(start, end);
29 |
30 | }
31 |
32 | },
33 |
34 | bridge_virtjs_input_poll_inputs: function () {
35 |
36 | Module.input.pollInputs();
37 |
38 | },
39 |
40 | bridge_virtjs_input_get_state: function (port, inputCode) {
41 |
42 | return Module.input.getState(port, inputCode);
43 |
44 | },
45 |
46 | bridge_virtjs_timer_start: function () {
47 |
48 | Module.timer.start();
49 |
50 | },
51 |
52 | bridge_virtjs_timer_stop: function () {
53 |
54 | Module.timer.stop();
55 |
56 | },
57 |
58 | bridge_virtjs_timer_next_tick: function (pointer) {
59 |
60 | return Module.timer.nextTick(function () {
61 | Runtime.dynCall('v', pointer, []);
62 | });
63 |
64 | },
65 |
66 | bridge_virtjs_timer_cancel_tick: function (nextTickId) {
67 |
68 | Module.timer.cancelTick(nextTickId);
69 |
70 | },
71 |
72 | bridge_virtjs_screen_set_input_size: function (width, height, pitch) {
73 |
74 | Module.screen.setInputSize(width, height, pitch);
75 |
76 | },
77 |
78 | bridge_virtjs_screen_validate_input_format: function (depth, rMask, gMask, bMask, aMask) {
79 |
80 | return Module.screen.validateInputFormat({ depth: depth, rMask: rMask, gMask: gMask, bMask: bMask, aMask: aMask });
81 |
82 | },
83 |
84 | bridge_virtjs_screen_set_input_format: function (depth, rMask, gMask, bMask, aMask) {
85 |
86 | Module.screen.setInputFormat({ depth: depth, rMask: rMask, gMask: gMask, bMask: bMask, aMask: aMask });
87 |
88 | },
89 |
90 | bridge_virtjs_screen_set_input_data__deps: [ '$VirtjsBridge' ],
91 | bridge_virtjs_screen_set_input_data: function (dataPointer) {
92 |
93 | var heap = VirtjsBridge.getHeapFromDepth(Module.screen.inputFormat.depth);
94 |
95 | Module.screen.setInputData(VirtjsBridge.castPointerToData(dataPointer, heap, Module.screen.inputHeight * Module.screen.inputPitch));
96 |
97 | },
98 |
99 | bridge_virtjs_screen_flush_screen: function () {
100 |
101 | Module.screen.flushScreen();
102 |
103 | },
104 |
105 | bridge_virtjs_screen_set_input_data__deps: [ '$VirtjsBridge' ],
106 | bridge_virtjs_audio_validate_input_format: function (sampleRate) {
107 |
108 | return Module.audio.validateInputFormat({ sampleRate: sampleRate, channelCount: 2, formatCallback: VirtjsBridge.audioFormat });
109 |
110 | },
111 |
112 | bridge_virtjs_screen_set_input_data__deps: [ '$VirtjsBridge' ],
113 | bridge_virtjs_audio_set_input_format: function (sampleRate) {
114 |
115 | Module.audio.setInputFormat({ sampleRate: sampleRate, channelCount: 2, formatCallback: VirtjsBridge.audioFormat });
116 |
117 | },
118 |
119 | bridge_virtjs_audio_push_sample_batch: function (samplesPointer, count) {
120 |
121 | Module.audio.pushSampleBatch(VirtjsBridge.castPointerToData(samplesPointer, HEAP16, count * 2));
122 |
123 | }
124 |
125 | });
126 |
--------------------------------------------------------------------------------
/sources/epilogue.js:
--------------------------------------------------------------------------------
1 |
2 | return { Module: Module, FS: FS, Runtime: Runtime };
3 |
4 | });
5 |
6 | var Engine = function (options) {
7 |
8 | var devices = options.devices;
9 |
10 | this.defaultFileName = options.defaultFileName || '@(ENGINE_ROM_NAME)';
11 |
12 | this.emscripten = instanciateEmscripten();
13 |
14 | this.emscripten.print = function (message) { console.log(message); };
15 | this.emscripten.printErr = function (message) { console.error(message); };
16 |
17 | this.screen = this.emscripten.Module.screen = devices.screen;
18 | this.timer = this.emscripten.Module.timer = devices.timer;
19 | this.input = this.emscripten.Module.input = devices.input;
20 | this.audio = this.emscripten.Module.audio = devices.audio;
21 |
22 | this.lastCreatedFile = null;
23 |
24 | this.frontendStart = this.emscripten.Module.cwrap('frontend_start', null, []);
25 | this.frontendStatus = this.emscripten.Module.cwrap('frontend_status', 'number', []);
26 | this.frontendStop = this.emscripten.Module.cwrap('frontend_stop', null, []);
27 |
28 | this.frontendLoadGame = this.emscripten.Module.cwrap('frontend_load_game', 'number', [ 'number' ]);
29 | this.frontendUnloadGame = this.emscripten.Module.cwrap('frontend_unload_game', 'number', []);
30 |
31 | this.frontendGetState = this.emscripten.Module.cwrap('frontend_get_state', 'number', [ 'number', 'number' ]);
32 | this.frontendSetState = this.emscripten.Module.cwrap('frontend_set_state', 'number', [ 'number', 'number' ]);
33 | this.frontendResetState = this.emscripten.Module.cwrap('frontend_reset_state', 'number', []);
34 |
35 | this.emscripten.Module.callMain([]);
36 |
37 | };
38 |
39 | Engine.codeMap = { };
40 |
41 | // These values come from the libretro header
42 |
43 | Engine.codeMap.LEFT = 6;
44 | Engine.codeMap.RIGHT = 7;
45 | Engine.codeMap.UP = 4;
46 | Engine.codeMap.DOWN = 5;
47 |
48 | Engine.codeMap.A = 8;
49 | Engine.codeMap.B = 0;
50 |
51 | Engine.codeMap.L = 10;
52 | Engine.codeMap.R = 11;
53 |
54 | Engine.codeMap.SELECT = 2;
55 | Engine.codeMap.START = 3;
56 |
57 | Engine.prototype.loadArrayBuffer = function (arrayBuffer, options) {
58 |
59 | if (!this.stop())
60 | throw new Error('Cannot stop the engine to load a new game');
61 |
62 | if (typeof options === 'undefined')
63 | options = { };
64 |
65 | var autoStart = options.autoStart;
66 | var initialState = options.initialState;
67 |
68 | if (typeof autoStart === 'undefined')
69 | autoStart = true;
70 |
71 | if (this.lastCreatedFile) {
72 | this.frontendUnloadGame();
73 | this.emscripten.FS.unlink(this.lastCreatedFile);
74 | }
75 |
76 | this.lastCreatedFile = '/' + (options.fileName || this.defaultFileName);
77 |
78 | var stackPointer = this.emscripten.Runtime.stackSave();
79 |
80 | var gamePathPointer = this.emscripten.Module.allocate(this.emscripten.Module.intArrayFromString(this.lastCreatedFile), 'i8', this.emscripten.Module.ALLOC_STACK);
81 | this.emscripten.FS.writeFile(this.lastCreatedFile, new Uint8Array(arrayBuffer), { encoding : 'binary' });
82 |
83 | var result = this.frontendLoadGame(gamePathPointer);
84 |
85 | this.emscripten.Runtime.stackRestore(stackPointer);
86 |
87 | if (result < 0)
88 | throw new Error('Game load failed - the emulator returned ' + result);
89 |
90 | if (initialState)
91 | this.setState(initialState);
92 |
93 | if (autoStart) {
94 | this.start();
95 | }
96 |
97 | };
98 |
99 | Engine.prototype.resetState = function () {
100 |
101 | var result = this.frontendResetState();
102 |
103 | if (result < 0)
104 | throw new Error('Cannot reset state at this time - the emulator returned ' + result);
105 |
106 | return this;
107 |
108 | };
109 |
110 | Engine.prototype.setState = function (arrayBuffer) {
111 |
112 | if (!arrayBuffer)
113 | return this.resetState();
114 |
115 | var stackPointer = this.emscripten.Runtime.stackSave();
116 |
117 | var emdata = this.emscripten.Module.allocate(new Uint8Array(arrayBuffer), 'i8', this.emscripten.Module.ALLOC_STACK);
118 | var result = this.frontendSetState(emdata, arrayBuffer.byteLength);
119 |
120 | this.emscripten.Runtime.stackRestore(stackPointer);
121 |
122 | if (result < 0)
123 | throw new Error('Cannot set state at this time - the emulator returned ' + result);
124 |
125 | return this;
126 |
127 | };
128 |
129 | Engine.prototype.getState = function () {
130 |
131 | var stackPointer = this.emscripten.Runtime.stackSave();
132 |
133 | var emDataPtr = this.emscripten.Module.allocate([ 0 ], '*', this.emscripten.Module.ALLOC_STACK);
134 | var emSizePtr = this.emscripten.Module.allocate([ 0 ], 'i32', this.emscripten.Module.ALLOC_STACK);
135 |
136 | var result = this.frontendGetState(emDataPtr, emSizePtr);
137 |
138 | var emdata = this.emscripten.Module.getValue(emDataPtr, '*');
139 | var emsize = this.emscripten.Module.getValue(emSizePtr, 'i32');
140 |
141 | this.emscripten.Runtime.stackRestore(stackPointer);
142 |
143 | if (result < 0)
144 | throw new Error('Cannot get state at this time - the emulator returned ' + result);
145 |
146 | return this.emscripten.Module.HEAPU8.buffer.slice(emdata, emdata + emsize);
147 |
148 | };
149 |
150 | Engine.prototype.start = function () {
151 |
152 | this.frontendStart();
153 |
154 | return this;
155 |
156 | };
157 |
158 | Engine.prototype.isRunning = function () {
159 |
160 | return Boolean(this.frontendStatus());
161 |
162 | };
163 |
164 | Engine.prototype.stop = function () {
165 |
166 | this.frontendStop();
167 |
168 | return this;
169 |
170 | };
171 |
172 | return Engine;
173 |
174 | }));
175 |
--------------------------------------------------------------------------------
/sources/frontend.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include
7 |
8 | #ifdef EMSCRIPTEN
9 | # include
10 | #endif
11 |
12 | #include "./bridge_retro.h"
13 | #include "./bridge_virtjs.h"
14 | #include "./frontend.h"
15 |
16 | #ifndef EMSCRIPTEN_KEEPALIVE
17 | # define EMSCRIPTEN_KEEPALIVE
18 | #endif
19 |
20 | static int g_next_tick_id = 0;
21 |
22 | static char const * g_state_path = NULL;
23 |
24 | static void * g_state = NULL;
25 | static size_t g_state_size = 0;
26 |
27 | static int read_file(char const * path, void ** data, size_t * size)
28 | {
29 | FILE * file = fopen(path, "rb");
30 |
31 | if (! file)
32 | return fprintf(stderr, "Cannot open file %s (%s)\n", path, strerror(errno)), fclose(file), -1;
33 |
34 | fseek(file, 0, SEEK_END);
35 |
36 | *size = ftell(file);
37 | *data = malloc(*size);
38 |
39 | fseek(file, 0, SEEK_SET);
40 |
41 | if (fread(*data, *size, 1, file) != 1)
42 | return fprintf(stderr, "Cannot read file %s (%s)\n", path, strerror(ferror(file))), fclose(file), -2;
43 |
44 | return fclose(file), 0;
45 | }
46 |
47 | static int write_file(char const * path, void const * data, size_t size)
48 | {
49 | FILE * file = fopen(path, "wb+");
50 |
51 | if (! file)
52 | return fprintf(stderr, "Cannot open file %s (%s)\n", path, strerror(errno)), fclose(file), -1;
53 |
54 | if (fwrite(data, size, 1, file) != 1)
55 | return fprintf(stderr, "Cannot write file %s (%s)\n", path, strerror(ferror(file))), fclose(file), -2;
56 |
57 | return fclose(file), 0;
58 | }
59 |
60 | static void iterate(void)
61 | {
62 | g_next_tick_id = bridge_virtjs_timer_next_tick(iterate);
63 |
64 | retro_run();
65 | bridge_virtjs_screen_flush_screen();
66 | }
67 |
68 | void EMSCRIPTEN_KEEPALIVE frontend_start(void)
69 | {
70 | g_next_tick_id = bridge_virtjs_timer_next_tick(iterate);
71 | }
72 |
73 | bool EMSCRIPTEN_KEEPALIVE frontend_status(void)
74 | {
75 | return g_next_tick_id != 0;
76 | }
77 |
78 | void EMSCRIPTEN_KEEPALIVE frontend_stop(void)
79 | {
80 | bridge_virtjs_timer_cancel_tick(g_next_tick_id);
81 | g_next_tick_id = 0;
82 | }
83 |
84 | int EMSCRIPTEN_KEEPALIVE frontend_load_game(char const * path)
85 | {
86 | struct retro_system_info system_info;
87 | retro_get_system_info(&system_info);
88 |
89 | void * data = NULL;
90 | size_t size = 0;
91 |
92 | if (! system_info.need_fullpath)
93 | if (read_file(path, &data, &size) < 0)
94 | return fprintf(stderr, "Cannot launch game %s\n", path), -1;
95 |
96 | struct retro_game_info game_info = { .path = path, .data = data, .size = size };
97 |
98 | if (!retro_load_game(&game_info))
99 | return fprintf(stderr, "Retroarch refused to launch game %s\n", path), -2;
100 |
101 | g_state_size = retro_serialize_size();
102 | g_state = malloc(g_state_size);
103 |
104 | struct retro_system_av_info system_av_info;
105 | retro_get_system_av_info(&system_av_info);
106 |
107 | if (bridge_virtjs_audio_validate_input_format(system_av_info.timing.sample_rate))
108 | bridge_virtjs_audio_set_input_format(system_av_info.timing.sample_rate);
109 |
110 | return 0;
111 | }
112 |
113 | int EMSCRIPTEN_KEEPALIVE frontend_unload_game(void)
114 | {
115 | retro_unload_game();
116 |
117 | return 0;
118 | }
119 |
120 | void EMSCRIPTEN_KEEPALIVE frontend_set_state_path(char const * path)
121 | {
122 | g_state_path = path;
123 | }
124 |
125 | int EMSCRIPTEN_KEEPALIVE frontend_load_state(void)
126 | {
127 | if (!g_state_path)
128 | return fprintf(stderr, "Cannot load state - no path specified\n"), -1;
129 |
130 | void * data = NULL;
131 | size_t size = 0;
132 |
133 | if (read_file(g_state_path, &data, &size) < 0)
134 | return free(data), -2;
135 |
136 | if (frontend_set_state(data, size) < 0)
137 | return free(data), -3;
138 |
139 | return free(data), 0;
140 | }
141 |
142 | int EMSCRIPTEN_KEEPALIVE frontend_save_state(void)
143 | {
144 | if (!g_state_path)
145 | return fprintf(stderr, "Cannot save state - no path specified\n"), -1;
146 |
147 | void const * data = NULL;
148 | size_t size = 0;
149 |
150 | if (frontend_get_state(&data, &size) < 0)
151 | return -2;
152 |
153 | if (write_file(g_state_path, data, size) < 0)
154 | return -3;
155 |
156 | return 0;
157 | }
158 |
159 | int EMSCRIPTEN_KEEPALIVE frontend_set_state(void const * state, size_t size)
160 | {
161 | if (!retro_unserialize(state, size))
162 | return -1;
163 |
164 | return 0;
165 | }
166 |
167 | int EMSCRIPTEN_KEEPALIVE frontend_get_state(void const ** state, size_t * size)
168 | {
169 | if (!retro_serialize(g_state, g_state_size))
170 | return -1;
171 |
172 | *state = g_state;
173 | *size = g_state_size;
174 |
175 | return 0;
176 | }
177 |
178 | int EMSCRIPTEN_KEEPALIVE frontend_reset_state(void)
179 | {
180 | retro_reset();
181 |
182 | return 0;
183 | }
184 |
--------------------------------------------------------------------------------
/sources/frontend.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | void frontend_start(void);
11 | bool frontend_status(void);
12 | void frontend_stop(void);
13 |
14 | int frontend_load_game(char const * path);
15 | int frontend_unload_game(void);
16 |
17 | void frontend_set_state_path(char const * path);
18 |
19 | int frontend_load_state(void);
20 | int frontend_save_state(void);
21 |
22 | int frontend_set_state(void const * state, size_t size);
23 | int frontend_get_state(void const ** state, size_t * size);
24 | int frontend_reset_state(void);
25 |
26 | #ifdef __cplusplus
27 | }
28 | #endif
29 |
--------------------------------------------------------------------------------
/sources/input_formats.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 |
5 | #include "./input_formats.h"
6 |
7 | struct input_format format_0rgb1555 = {
8 | .depth = 16,
9 | .r_mask = 0b0111110000000000,
10 | .g_mask = 0b0000001111100000,
11 | .b_mask = 0b0000000000011111,
12 | .a_mask = 0b0000000000000000
13 | };
14 |
15 | struct input_format format_rgb565 = {
16 | .depth = 16,
17 | .r_mask = 0b1111100000000000,
18 | .g_mask = 0b0000011111100000,
19 | .b_mask = 0b0000000000011111,
20 | .a_mask = 0b0000000000000000
21 | };
22 |
23 | struct input_format format_xrgb8888 = {
24 | .depth = 32,
25 | .r_mask = 0x00FF0000,
26 | .g_mask = 0x0000FF00,
27 | .b_mask = 0x000000FF,
28 | .a_mask = 0x00000000
29 | };
30 |
31 | struct input_format const * get_input_format(enum retro_pixel_format input_format)
32 | {
33 | switch (input_format) {
34 | case RETRO_PIXEL_FORMAT_0RGB1555 : return &format_0rgb1555;
35 | case RETRO_PIXEL_FORMAT_XRGB8888 : return &format_xrgb8888;
36 | case RETRO_PIXEL_FORMAT_RGB565 : return &format_rgb565;
37 | default : return NULL;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/sources/input_formats.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include
6 |
7 | struct input_format {
8 |
9 | unsigned depth;
10 |
11 | uint32_t r_mask;
12 | uint32_t g_mask;
13 | uint32_t b_mask;
14 | uint32_t a_mask;
15 |
16 | };
17 |
18 | struct input_format const * get_input_format(enum retro_pixel_format pixel_format);
19 |
--------------------------------------------------------------------------------
/sources/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 |
6 | #include "./bridge_retro.h"
7 | #include "./bridge_virtjs.h"
8 | #include "./frontend.h"
9 |
10 | static void initialize(void)
11 | {
12 | retro_set_environment(bridge_retro_environment);
13 | retro_set_video_refresh(bridge_retro_video_refresh);
14 | retro_set_input_poll(bridge_retro_input_poll);
15 | retro_set_input_state(bridge_retro_input_state);
16 | retro_set_audio_sample(bridge_retro_audio_sample);
17 | retro_set_audio_sample_batch(bridge_retro_audio_sample_batch);
18 |
19 | retro_init();
20 | }
21 |
22 | #if !defined(EMSCRIPTEN)
23 |
24 | int main(int argc, char const ** argv)
25 | {
26 | if (argc < 2)
27 | return fprintf(stderr, "Usage: %s []\n", argv[0]);
28 |
29 | initialize();
30 |
31 | if (frontend_load_game(argv[1]) < 0)
32 | return fprintf(stderr, "Game load failed\n"), -1;
33 |
34 | if (argc >= 3) {
35 | frontend_set_state_path(argv[2]);
36 | if (access(argv[2], F_OK) == 0 && frontend_load_state() < 0) {
37 | return fprintf(stderr, "Initial state load failed\n"), -1;
38 | }
39 | }
40 |
41 | frontend_start();
42 | bridge_virtjs_timer_start();
43 |
44 | return 0;
45 | }
46 |
47 | #else
48 |
49 | int main(void)
50 | {
51 | initialize();
52 |
53 | return 0;
54 | }
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/sources/prologue.js:
--------------------------------------------------------------------------------
1 | (function (root, factory) {
2 |
3 | if (typeof define === 'function' && define.amd) {
4 |
5 | define([], factory);
6 |
7 | } else if (typeof exports === 'object') {
8 |
9 | module.exports = factory();
10 |
11 | } else {
12 |
13 | if (!root.Archjs)
14 | root.Archjs = { byName: {} };
15 |
16 | root.Archjs.byName['@(ENGINE_NAME)'] = factory(root.$, root._);
17 |
18 | }
19 |
20 | }(this, function () {
21 |
22 | var instanciateEmscripten = (function (Module) {
23 |
--------------------------------------------------------------------------------