fix saves

This commit is contained in:
seedgou 2018-11-15 01:34:45 +08:00
parent e73176030e
commit e3cb192dd2
3 changed files with 141 additions and 41 deletions

2
app.py
View File

@ -1,5 +1,5 @@
from flask import Flask
from flask import render_template, redirect, url_for
from flask import render_template, redirect, url_for, make_response, request
from game_infos import game_infos, game_infos_with_cover
import json

View File

@ -194,9 +194,22 @@ var Module = null;
.textContent));
} else if (module && module.indexOf("vice") === 0) {
let emulator_start_item = metadata.getElementsByTagName("emulator_start").item(0);
let vice_fliplist = [ metadata.getElementsByTagName("vice_drive_8_fliplist").item(0),
metadata.getElementsByTagName("vice_drive_9_fliplist").item(0),
metadata.getElementsByTagName("vice_drive_10_fliplist").item(0),
metadata.getElementsByTagName("vice_drive_11_fliplist").item(0) ];
if (emulator_start_item) {
config_args.push(cfgr.autoLoad(emulator_start_item.textContent));
}
let fliplists = [];
vice_fliplist.forEach(function (fliplist_meta) {
if(!fliplist_meta) {
fliplists.push(null);
} else {
fliplists.push(fliplist_meta.textContent.split(";"));
}
});
config_args.push(cfgr.fliplist(fliplists));
config_args.push(cfgr.extraArgs(modulecfg.extra_args));
} else if (module && module.indexOf("sae-") === 0) {
config_args.push(cfgr.model(modulecfg.driver),
@ -275,35 +288,34 @@ var Module = null;
});
return files;
}
function get_vice_files(cfgr, metadata, modulecfg, filelist) {
var default_drive = "8",
drives = {}, files = [], wanted_files = []
var default_drive = "8",
drives = {}, files = [], wanted_files = [],
meta = dict_from_xml(metadata);
files_with_ext_from_filelist(filelist, meta.emulator_ext).forEach(function (file, i) {
//drives[default_drive] = file.name;
wanted_files.push(file.name);
});
meta_props_matching(meta, /^vice_drive_([89])$/).forEach(function (result) {
let key = result[0], match = result[1];
drives[match[1]] = meta[key];
});
let key = result[0], match = result[1];
drives[match[1]] = meta[key];
});
var len = wanted_files.length;
wanted_files.forEach(function (file, i) {
var title = "Game File ("+ (i+1) +" of "+ len +")",
filename = file,
url = (filename.includes("/")) ? get_zip_url(filename)
: get_zip_url(filename, get_item_name(game));
console.log("Retrieving URL",url);
if (filename.toLowerCase().endsWith(".zip")&&false) { // TODO: Enable and fix zip support.
files.push(cfgr.mountZip("", // TODO: This is a hack, no drive actually applicable here
cfgr.fetchFile(title, url)));
} else {
//TODO: ensure vice_drive_8 and vice_drive_9 actually function.
files.push(cfgr.mountFile('/'+ filename,
cfgr.fetchFile(title, url)));
}
});
var title = "Game File ("+ (i+1) +" of "+ len +")",
filename = file,
url = (filename.includes("/")) ? get_zip_url(filename)
: get_zip_url(filename, get_item_name(game));
if (filename.toLowerCase().endsWith(".zip") && false) { // TODO: Enable and fix zip support.
files.push(cfgr.mountZip("", // TODO: This is a hack, no drive actually applicable here
cfgr.fetchFile(title, url)));
} else {
//TODO: ensure vice_drive_8 and vice_drive_9 actually function.
files.push(cfgr.mountFile('/'+ filename,
cfgr.fetchFile(title, url)));
}
});
return files;
}
@ -571,6 +583,34 @@ var Module = null;
DosBoxLoader.extraArgs = function (args) {
return { extra_dosbox_args: args };
};
DosBoxLoader.mountZip = function (drive, file, drive_type="hdd") {
// driver type: hdd, floppy, cdrom, img
return { files: [{ drive: drive,
mountpoint: "/" + drive,
file: file,
drive_type: drive_type,
}] };
};
/**
* PC98DosBoxLoader
*/
function PC98DosBoxLoader() {
var config = Array.prototype.reduce.call(arguments, extend);
config.emulator_arguments = build_dosbox_arguments(config.emulatorStart, config.files, config.extra_dosbox_args);
config.runner = PC98DosBoxRunner;
return config;
}
PC98DosBoxLoader.__proto__ = BaseLoader;
PC98DosBoxLoader.startExe = function (path) {
return { emulatorStart: path };
};
PC98DosBoxLoader.extraArgs = function (args) {
return { extra_dosbox_args: args };
};
/**
* MAMELoader
@ -603,24 +643,43 @@ var Module = null;
MAMELoader.extraArgs = function (args) {
return { extra_mame_args: args };
};
/**
* VICELoader
*/
function VICELoader() {
var config = Array.prototype.reduce.call(arguments, extend);
config.emulator_arguments = build_vice_arguments(config.emulatorStart, config.files, config.extra_vice_args);
if (config.fliplist) {
VICELoader._create_fliplist_file(config.files, config.fliplist);
}
config.emulator_arguments = build_vice_arguments(config.emulatorStart, config.files, config.fliplist, config.extra_vice_args);
config.runner = EmscriptenRunner;
return config;
}
VICELoader.__proto__ = BaseLoader;
VICELoader.autoLoad = function (path) {
return { emulatorStart: path };
};
VICELoader.extraArgs = function (args) {
return { extra_vice_args: args };
}
};
VICELoader.fliplist = function(fliplist) {
return { fliplist: fliplist };
};
VICELoader._create_fliplist_file = function(files, fliplists) {
let fliplist = "# Vice fliplist file\n\n";
fliplists.forEach(function(drive_fliplist, i) {
if(drive_fliplist) {
drive_fliplist = drive_fliplist.reverse();
fliplist += "UNIT " + (i + 8).toString() + "\n";
drive_fliplist.forEach(function(disk_image) {
fliplist += "/emulator/" + disk_image + "\n";
});
}
});
files.push(VICELoader.mountFile('/metadata_fliplist.vfl', VICELoader.localFile("Fliplist", fliplist)).files[0]);
};
/**
* SAELoader
@ -712,7 +771,19 @@ var Module = null;
var len = files.length;
for (var i = 0; i < len; i++) {
if ('drive' in files[i]) {
args.push('-c', 'mount '+ files[i].drive +' /emulator'+ files[i].mountpoint);
// See also https://www.dosbox.com/wiki/MOUNT
if(files[i].drive_type==='hdd'){
args.push('-c', 'mount '+ files[i].drive +' /emulator'+ files[i].mountpoint);
}
else if(files[i].drive_type==='floppy'){
args.push('-c', 'mount '+ files[i].drive +' /emulator'+ files[i].mountpoint + ' -t floppy');
}
else if(files[i].drive_type==='cdrom'){
args.push('-c', 'mount '+ files[i].drive +' /emulator'+ files[i].mountpoint + ' -t cdrom');
}
else if(files[i].drive_type==='img'){
args.push('-c', 'mount '+ files[i].drive +' /emulator'+ files[i].mountpoint + ' -t iso');
}
}
}
@ -729,14 +800,17 @@ var Module = null;
return args;
};
var build_vice_arguments = function (emulator_start, files, extra_args) {
var args = emulator_start ? ["-autostart", "/emulator/" + emulator_start] : [];
if(extra_args) {
args = args.concat(extra_args);
}
return args;
}
var build_vice_arguments = function (emulator_start, files, fliplist, extra_args) {
var args = emulator_start ? ["-autostart", "/emulator/" + emulator_start] : [];
if (fliplist[0] || fliplist[1] || fliplist[2] || fliplist[3]) {
args = args.concat(["-flipname", "/emulator/metadata_fliplist.vfl"]);
}
if (extra_args) {
args = args.concat(extra_args);
}
return args;
};
/*
* EmscriptenRunner
@ -815,6 +889,23 @@ var Module = null;
EmscriptenRunner.prototype.requestFullScreen = function () {
};
/*
* PC98DosBoxRunner
*/
function PC98DosBoxRunner() {
return EmscriptenRunner.apply(this, arguments);
}
PC98DosBoxRunner.prototype = Object.create(EmscriptenRunner.prototype);
PC98DosBoxRunner.prototype.start = function () {
FS.symlink('/emulator/y/FONT.ROM', '/FONT.ROM');
FS.symlink('/emulator/y/2608_bd.wav', '/2608_bd.wav');
FS.symlink('/emulator/y/2608_hh.wav', '/2608_hh.wav');
FS.symlink('/emulator/y/2608_sd.wav', '/2608_sd.wav');
FS.symlink('/emulator/y/2608_rim.wav', '/2608_rim.wav');
FS.symlink('/emulator/y/2608_tom.wav', '/2608_tom.wav');
FS.symlink('/emulator/y/2608_top.wav', '/2608_top.wav');
}
/*
* MAMERunner
*/
@ -897,9 +988,11 @@ var Module = null;
this._cfg.memory.extRom.size = this._cfg.memory.extRom.data.length;
}
this._cfg.floppy.drive[0].file.name = game_data.floppy[0];
this._cfg.floppy.drive[0].file.data = game_data.fs.readFileSync('/'+game_data.floppy[0], null, flag_r);
this._cfg.floppy.drive[0].file.size = this._cfg.floppy.drive[0].file.data.length;
for (var i = 0; i < Object.keys(game_data.floppy).length; i++) {
this._cfg.floppy.drive[i].file.name = game_data.floppy[i];
this._cfg.floppy.drive[i].file.data = game_data.fs.readFileSync('/' + game_data.floppy[i], null, flag_r);
this._cfg.floppy.drive[i].file.size = this._cfg.floppy.drive[i].file.data.length;
}
}
SAERunner.prototype.start = function () {
@ -1253,7 +1346,7 @@ var Module = null;
}
if ("runner" in game_data) {
if (game_data.runner == EmscriptenRunner || game_data.runner == MAMERunner) {
if (game_data.runner == EmscriptenRunner || game_data.runner.prototype instanceof EmscriptenRunner) {
// this is a stupid hack. Emscripten-based
// apps currently need the runner to be set
// up first, then we can attach the
@ -1803,11 +1896,13 @@ var Module = null;
window.IALoader = IALoader;
window.DosBoxLoader = DosBoxLoader;
window.PC98DosBoxLoader = PC98DosBoxLoader;
window.JSMESSLoader = MAMELoader; // depreciated; just for backwards compatibility
window.JSMAMELoader = MAMELoader; // ditto
window.MAMELoader = MAMELoader;
window.SAELoader = SAELoader;
window.PCELoader = PCELoader;
window.VICELoader = VICELoader;
window.Emulator = Emulator;
window._SDL_CreateRGBSurfaceFrom = _SDL_CreateRGBSurfaceFrom;
})(typeof Promise === 'undefined' ? ES6Promise.Promise : Promise);

View File

@ -70,10 +70,15 @@
new DosBoxLoader(DosBoxLoader.emulatorJS("{{ url_for('static', filename='emularity/dosbox/dosbox-sync.js') }}"),
DosBoxLoader.locateAdditionalEmulatorJS(locateAdditionalFiles),
DosBoxLoader.nativeResolution(640, 480),
DosBoxLoader.fileSystemKey("{{ game_info["identifier"] }}"),
DosBoxLoader.mountZip("c",
DosBoxLoader.fetchFile("Game File",
"{{ url_for('static', filename="games/bin/{}.zip".format(game_info["identifier"])) }}")),
DosBoxLoader.startExe("{{ game_info["executable"] }}")))
"{{ url_for('static', filename="games/bin/{}.zip".format(game_info["identifier"])) }}"),
{% if game_info["cdrom"] %}"cdrom"{% elif game_info["floppy"] %}"floppy"{% else %}"hdd"{% endif %}
),
DosBoxLoader.startExe("{{ game_info["executable"] }}")
)
);
emulator.start({waitAfterDownloading: true});
function locateAdditionalFiles(filename) {