diff --git a/pkg/emscripten/libretro/index.html b/pkg/emscripten/libretro/index.html
index bc2bf6ce02..d61c92bff6 100644
--- a/pkg/emscripten/libretro/index.html
+++ b/pkg/emscripten/libretro/index.html
@@ -109,7 +109,7 @@
VICE xscpu4
VICE xVIC
Vita Quake2
- Vita Quake2 (rogue)
+ Vita Quake2 (rogue)
Vita Quake2 (xatrix)
Vita Quake2 (zaero)
Virtual Jaguar
diff --git a/pkg/emscripten/libretro/libretro.js b/pkg/emscripten/libretro/libretro.js
index 00eeaab0c1..a4bb5620f4 100644
--- a/pkg/emscripten/libretro/libretro.js
+++ b/pkg/emscripten/libretro/libretro.js
@@ -125,7 +125,6 @@ function idbfsInit()
//fallback to imfs
afs = new BrowserFS.FileSystem.InMemory();
console.log("WEBPLAYER: error: " + e + " falling back to in-memory filesystem");
- setupFileSystem("browser");
appInitialized();
}
else
@@ -137,7 +136,6 @@ function idbfsInit()
{
afs = new BrowserFS.FileSystem.InMemory();
console.log("WEBPLAYER: error: " + e + " falling back to in-memory filesystem");
- setupFileSystem("browser");
appInitialized();
}
else
@@ -157,17 +155,17 @@ function idbfsSyncComplete()
$('#icnLocal').addClass('fa-check');
console.log("WEBPLAYER: idbfs setup successful");
- setupFileSystem("browser");
appInitialized();
}
function appInitialized()
{
- /* Need to wait for both the file system and the wasm runtime
+ /* Need to wait for the file system, the wasm runtime, and the zip download
to complete before enabling the Run button. */
initializationCount++;
- if (initializationCount == 2)
+ if (initializationCount == 3)
{
+ setupFileSystem("browser");
preLoadingComplete();
}
}
@@ -183,6 +181,34 @@ function preLoadingComplete()
$('#btnRun').removeClass('disabled');
}
+var zipTOC;
+
+function zipfsInit() {
+ // 256 MB max bundle size
+ let buffer = new ArrayBuffer(256*1024*1024);
+ let bufferView = new Uint8Array(buffer);
+ let idx = 0;
+ // bundle should be in four parts (this can be changed later)
+ Promise.all([fetch("assets/frontend/bundle.zip.aa"),
+ fetch("assets/frontend/bundle.zip.ab"),
+ fetch("assets/frontend/bundle.zip.ac"),
+ fetch("assets/frontend/bundle.zip.ad")
+ ]).then(function(resps) {
+ Promise.all(resps.map((r) => r.arrayBuffer())).then(function(buffers) {
+ for (let buf of buffers) {
+ if (idx+buf.byteLength > buffer.maxByteLength) {
+ console.log("WEBPLAYER: error: bundle.zip is too large");
+ }
+ bufferView.set(new Uint8Array(buf), idx, buf.byteLength);
+ idx += buf.byteLength;
+ }
+ BrowserFS.FileSystem.ZipFS.computeIndex(BrowserFS.BFSRequire('buffer').Buffer(new Uint8Array(buffer, 0, idx)), function(toc) {
+ zipTOC = toc;
+ appInitialized();
+ });
+ })
+ });
+}
function setupFileSystem(backend)
{
/* create a mountable filesystem that will server as a root
@@ -190,8 +216,7 @@ function setupFileSystem(backend)
var mfs = new BrowserFS.FileSystem.MountableFileSystem();
/* create an XmlHttpRequest filesystem for the bundled data */
- var xfs1 = new BrowserFS.FileSystem.XmlHttpRequest
- (".index-xhr", "assets/frontend/bundle/");
+ var xfs1 = new BrowserFS.FileSystem.ZipFS(zipTOC);
/* create an XmlHttpRequest filesystem for core assets */
var xfs2 = new BrowserFS.FileSystem.XmlHttpRequest
(".index-xhr", "assets/cores/");
@@ -199,7 +224,7 @@ function setupFileSystem(backend)
console.log("WEBPLAYER: initializing filesystem: " + backend);
mfs.mount('/home/web_user/retroarch/userdata', afs);
- mfs.mount('/home/web_user/retroarch/bundle', xfs1);
+ mfs.mount('/home/web_user/retroarch/', xfs1);
mfs.mount('/home/web_user/retroarch/userdata/content/downloads', xfs2);
BrowserFS.initialize(mfs);
var BFS = new BrowserFS.EmscriptenFS(Module.FS, Module.PATH, Module.ERRNO_CODES);
@@ -363,6 +388,7 @@ function loadCore(core) {
$('#lblDrop').removeClass('active');
$('#lblLocal').addClass('active');
idbfsInit();
+ zipfsInit();
}).catch(err => { console.error("Couldn't instantiate module",err); throw err; });
}).catch(err => { console.error("Couldn't load script",err); throw err; });
}