1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-05-28 08:41:30 +00:00

file#_post: ignore/force params

This commit is contained in:
Steven Hugg 2020-10-14 17:33:15 -05:00
parent e475dfe38e
commit 0600ab3b9f
5 changed files with 75 additions and 16 deletions

View File

@ -57,7 +57,8 @@
"test-platforms": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 test/cli/testplatforms.js", "test-platforms": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 test/cli/testplatforms.js",
"test-profile": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 --prof test/cli", "test-profile": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 --prof test/cli",
"start": "electron .", "start": "electron .",
"fuzzbasic": "jsfuzz gen/common/basic/fuzz.js ~/basic/corpus/ --versifier false" "fuzzbasic": "jsfuzz gen/common/basic/fuzz.js ~/basic/corpus/ --versifier false",
"machine": "node gen/tools/runmachine.js"
}, },
"main": "electron.js", "main": "electron.js",
"keywords": [ "keywords": [

View File

@ -1029,25 +1029,25 @@ import { ProbeRecorder } from "./recorder";
export interface Machine extends Bus, Resettable, FrameBased, AcceptsROM, HasCPU, SavesState<EmuState>, SavesInputState<any> { export interface Machine extends Bus, Resettable, FrameBased, AcceptsROM, HasCPU, SavesState<EmuState>, SavesInputState<any> {
} }
function hasVideo(arg:any): arg is VideoSource { export function hasVideo(arg:any): arg is VideoSource {
return typeof arg.connectVideo === 'function'; return typeof arg.connectVideo === 'function';
} }
function hasAudio(arg:any): arg is SampledAudioSource { export function hasAudio(arg:any): arg is SampledAudioSource {
return typeof arg.connectAudio === 'function'; return typeof arg.connectAudio === 'function';
} }
function hasKeyInput(arg:any): arg is AcceptsKeyInput { export function hasKeyInput(arg:any): arg is AcceptsKeyInput {
return typeof arg.setKeyInput === 'function'; return typeof arg.setKeyInput === 'function';
} }
function hasPaddleInput(arg:any): arg is AcceptsPaddleInput { export function hasPaddleInput(arg:any): arg is AcceptsPaddleInput {
return typeof arg.setPaddleInput === 'function'; return typeof arg.setPaddleInput === 'function';
} }
function isRaster(arg:any): arg is RasterFrameBased { export function isRaster(arg:any): arg is RasterFrameBased {
return typeof arg.getRasterY === 'function'; return typeof arg.getRasterY === 'function';
} }
function hasProbe(arg:any): arg is Probeable { export function hasProbe(arg:any): arg is Probeable {
return typeof arg.connectProbe == 'function'; return typeof arg.connectProbe == 'function';
} }
function hasBIOS(arg:any): arg is AcceptsBIOS { export function hasBIOS(arg:any): arg is AcceptsBIOS {
return typeof arg.loadBIOS == 'function'; return typeof arg.loadBIOS == 'function';
} }

View File

@ -2129,24 +2129,30 @@ function loadImportedURL(url : string) {
} }
async function loadFormDataUpload() { async function loadFormDataUpload() {
var ignore = !!qs['ignore'];
var force = !!qs['force'];
setWaitDialog(true); setWaitDialog(true);
for (var i=0; i<20; i++) { for (var i=0; i<20; i++) {
let path = qs['file'+i+'_name']; let path = qs['file'+i+'_name'];
let dataenc = qs['file'+i+'_data']; let dataenc = qs['file'+i+'_data'];
if (path == null || dataenc == null) break; if (path == null || dataenc == null) break;
let value = dataenc;
if (qs['file'+i+'_type'] == 'binary') {
value = stringToByteArray(atob(value));
}
var olddata = await store.getItem(path); var olddata = await store.getItem(path);
if (!olddata || confirm("Replace existing file '" + path + "'?")) { if (!(ignore && olddata)) {
await store.setItem(path, value); // TODO: alert when replacing? let value = dataenc;
if (i == 0) { qs['file'] = path; } // set main filename if (qs['file'+i+'_type'] == 'binary') {
value = stringToByteArray(atob(value));
}
if (!olddata || force || confirm("Replace existing file '" + path + "'?")) {
await store.setItem(path, value);
}
} }
if (i == 0) { qs['file'] = path; } // set main filename
delete qs['file'+i+'_name']; delete qs['file'+i+'_name'];
delete qs['file'+i+'_data']; delete qs['file'+i+'_data'];
delete qs['file'+i+'_type']; delete qs['file'+i+'_type'];
} }
delete qs['ignore'];
delete qs['force'];
setWaitDialog(false); setWaitDialog(false);
replaceURLState(); replaceURLState();
} }

51
src/tools/runmachine.ts Normal file
View File

@ -0,0 +1,51 @@
import { hasAudio, hasVideo, Machine } from "../common/baseplatform";
import { SampledAudioSink } from "../common/devices";
class NullAudio implements SampledAudioSink {
feedSample(value: number, count: number): void {
}
}
class MachineRunner {
machine: Machine;
pixels: Uint32Array;
constructor(machine: Machine) {
this.machine = machine;
}
setup() {
if (hasVideo(this.machine)) {
var vid = this.machine.getVideoParams();
this.pixels = new Uint32Array(vid.width * vid.height);
this.machine.connectVideo(this.pixels);
}
if (hasAudio(this.machine)) {
this.machine.connectAudio(new NullAudio());
}
this.machine.reset();
}
run() {
this.machine.advanceFrame(null);
}
}
async function loadMachine(modname: string, clsname: string) : Promise<Machine> {
var mod = await import('../machine/'+modname);
var cls = mod[clsname];
var machine = new cls();
return machine;
}
async function runMachine() {
var machine = await loadMachine(process.argv[2], process.argv[3]);
var runner = new MachineRunner(machine);
runner.setup();
runner.run();
console.log(runner.machine.saveState());
}
global.atob = require('atob');
global.btoa = require('btoa');
runMachine();

View File

@ -5,7 +5,8 @@
"outDir": "../../gen/tools" "outDir": "../../gen/tools"
}, },
"references": [ "references": [
{ "path": "../common" } { "path": "../common" },
{ "path": "../machine" }
], ],
"include": [ "include": [
"**/*.ts" "**/*.ts"