2024-10-01 19:07:03 +02:00
|
|
|
importScripts("libv86.js");
|
|
|
|
importScripts("ISOTerminal.js") // we don't instance it again here (just use its functions)
|
|
|
|
|
|
|
|
this.runISO = function(opts){
|
2024-10-15 12:32:16 +02:00
|
|
|
this.opts = opts
|
|
|
|
if( opts.debug ) console.dir(opts)
|
|
|
|
|
2024-10-02 21:03:04 +02:00
|
|
|
if( opts.cdrom && !opts.cdrom.url.match(/^http/) ) opts.cdrom.url = "../../"+opts.cdrom.url
|
|
|
|
if( opts.bzimage && !opts.cdrom.url.match(/^http/) ) opts.bzimage.url = "../../"+opts.bzimage.url
|
|
|
|
|
2024-10-01 19:07:03 +02:00
|
|
|
let emulator = this.emulator = new V86(opts);
|
2024-10-15 12:32:16 +02:00
|
|
|
console.log("[worker.js] started emulator")
|
2024-10-01 19:07:03 +02:00
|
|
|
|
|
|
|
// event forwarding
|
2024-10-02 21:03:04 +02:00
|
|
|
|
2024-10-01 19:07:03 +02:00
|
|
|
emulator.add_listener("serial0-output-byte", function(byte){
|
2024-10-04 11:08:39 +02:00
|
|
|
ISOTerminal.prototype.bufferOutput(byte, (str) => { // we buffer to prevent framerate dropping
|
|
|
|
if( !str ) return
|
|
|
|
this.postMessage({event:"serial0-output-string",data:str});
|
|
|
|
}, opts.bufferLatency )
|
2024-10-01 19:07:03 +02:00
|
|
|
}.bind(this));
|
|
|
|
|
2024-10-02 21:03:04 +02:00
|
|
|
emulator.add_listener("serial1-output-byte", function(byte){
|
2024-10-04 11:08:39 +02:00
|
|
|
ISOTerminal.prototype.bufferOutput(byte, (str) => { // we buffer to prevent framerate dropping
|
|
|
|
if( !str ) return
|
|
|
|
this.postMessage({event:"serial1-output-string",data:str});
|
|
|
|
}, opts.bufferLatency )
|
2024-10-02 21:03:04 +02:00
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
emulator.add_listener("serial2-output-byte", function(byte){
|
2024-10-04 11:08:39 +02:00
|
|
|
ISOTerminal.prototype.bufferOutput(byte, (str) => { // we buffer to prevent framerate dropping
|
|
|
|
if( !str ) return
|
|
|
|
this.postMessage({event:"serial2-output-string",data:str});
|
|
|
|
}, opts.bufferLatency )
|
2024-10-02 21:03:04 +02:00
|
|
|
}.bind(this));
|
|
|
|
|
2024-10-01 19:07:03 +02:00
|
|
|
emulator.add_listener("emulator-started", function(){
|
|
|
|
importScripts("feat/9pfs_utils.js")
|
|
|
|
this.postMessage({event:"emulator-started",data:false});
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* forward events/functions so non-worker world can reach them
|
|
|
|
*/
|
2024-11-01 17:39:56 +01:00
|
|
|
this.create_file = async function(){ return emulator.create_file.apply(emulator, arguments[0]) }
|
|
|
|
this.read_file = async function(){ return emulator.read_file.apply(emulator, arguments[0]) }
|
|
|
|
this.append_file = async function(){ emulator.fs9p.append_file.apply(emulator.fs9p, arguments[0]) }
|
|
|
|
this.update_file = async function(){ emulator.fs9p.update_file.apply(emulator.fs9p, arguments[0]) }
|
2024-10-01 19:07:03 +02:00
|
|
|
|
|
|
|
// filename will be read from 9pfs: "/mnt/"+filename
|
|
|
|
emulator.readFromPipe = function(filename,cb){
|
|
|
|
emulator.add_listener("9p-write-end", async (opts) => {
|
|
|
|
if ( opts[0] == filename.replace(/.*\//,'') ){
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-10-03 12:41:53 +02:00
|
|
|
importScripts("feat/javascript.js")
|
|
|
|
importScripts("feat/index.html.js")
|
2024-10-04 11:08:39 +02:00
|
|
|
importScripts("feat/autorestore.js")
|
2024-10-01 19:07:03 +02:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* forward events/functions so non-worker world can reach them
|
|
|
|
*/
|
|
|
|
|
2024-10-18 13:50:56 +02:00
|
|
|
this['serial0-input'] = function(c){ emulator.bus.send( 'serial0-input', c) } // to /dev/ttyS0
|
|
|
|
this['serial1-input'] = function(c){ emulator.bus.send( 'serial1-input', c) } // to /dev/ttyS1
|
|
|
|
this['serial2-input'] = function(c){ emulator.bus.send( 'serial2-input', c) } // to /dev/ttyS2
|
2024-10-01 19:07:03 +02:00
|
|
|
|
2024-10-15 12:32:16 +02:00
|
|
|
this.onmessage = async function(e){
|
2024-10-01 19:07:03 +02:00
|
|
|
let {event,data} = e.data
|
2024-10-15 12:32:16 +02:00
|
|
|
if( this[event] ){
|
|
|
|
if( this.opts?.debug ) console.log(`[worker.js] this.${event}(${JSON.stringify(data).substr(0,60)})`)
|
|
|
|
try{
|
|
|
|
let result = await this[event](data)
|
|
|
|
if( data.promiseId ){ // auto-callback to ISOTerminal.worker.promise(...)
|
|
|
|
this.postMessage({event,data: {...data,result}})
|
|
|
|
}
|
|
|
|
}catch(e){
|
|
|
|
if( data.promiseId ){ // auto-callback to ISOTerminal.worker.promise(...)
|
|
|
|
this.postMessage({event,data: {...data,error:e}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-01 19:07:03 +02:00
|
|
|
}
|