2024-09-05 19:09:40 +02:00
|
|
|
|
//ISOTerminal.prototype.exec(cmd_array,stdin){
|
|
|
|
|
// // exec(['lua'] "print \"hello\") ---> cat /dev/browser/js/stdin | lua > /dev/browser/js/stdout
|
|
|
|
|
//}
|
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
|
ISOTerminal.prototype.serial_input = undefined; // can be set to 0,1,2,3 to define stdinput tty (xterm plugin)
|
|
|
|
|
|
|
|
|
|
ISOTerminal.prototype.exec = function(shellscript){
|
|
|
|
|
//let ts = String(Date.now())+".job"
|
|
|
|
|
//this.emulator.create_file(ts, this.toUint8Array(shellscript) )
|
|
|
|
|
this.send(shellscript+"\n",1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISOTerminal.prototype.send = function(str, ttyNr){
|
|
|
|
|
if( !ttyNr ) ttyNr = this.serial_input
|
|
|
|
|
if( !ttyNr ){
|
|
|
|
|
if( this.emulator.serial_adapter ){
|
|
|
|
|
this.emulator.serial_adapter.term.paste(str)
|
|
|
|
|
}else this.emulator.keyboard_send_text(str) // vga screen
|
|
|
|
|
}else{
|
2024-09-23 16:59:29 +02:00
|
|
|
|
this.convert.toUint8Array( str ).map( (c) => this.emulator.bus.send(`serial${ttyNr}-input`, c ) )
|
2024-09-16 13:28:28 +02:00
|
|
|
|
}
|
2024-09-05 19:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 16:59:29 +02:00
|
|
|
|
ISOTerminal.prototype.convert = {
|
|
|
|
|
|
|
|
|
|
arrayBufferToBase64: function(buffer){
|
|
|
|
|
let binary = '';
|
|
|
|
|
const bytes = new Uint8Array(buffer);
|
|
|
|
|
const len = bytes.byteLength;
|
|
|
|
|
for (let i = 0; i < len; i++) binary += String.fromCharCode(bytes[i]);
|
|
|
|
|
return window.btoa(binary);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
base64ToArrayBuffer: function(base64) {
|
|
|
|
|
const binaryString = window.atob(base64);
|
|
|
|
|
const len = binaryString.length;
|
|
|
|
|
const bytes = new Uint8Array(len);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
|
bytes[i] = binaryString.charCodeAt(i);
|
|
|
|
|
}
|
|
|
|
|
return bytes.buffer;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
toUint8Array: function(str) {
|
|
|
|
|
str = String(str) || String("")
|
|
|
|
|
// Create a new Uint8Array with the same length as the input string
|
|
|
|
|
const uint8Array = new Uint8Array(str.length);
|
|
|
|
|
|
|
|
|
|
// Iterate over the string and populate the Uint8Array
|
|
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
|
|
uint8Array[i] = str.charCodeAt(i);
|
|
|
|
|
}
|
|
|
|
|
return uint8Array;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Uint8ArrayToString: function(arr){
|
|
|
|
|
const decoder = new TextDecoder('utf-8'); // Specify encoding
|
|
|
|
|
return decoder.decode(arr);
|
2024-09-03 18:33:35 +02:00
|
|
|
|
}
|
2024-09-23 16:59:29 +02:00
|
|
|
|
}
|
2024-09-03 18:33:35 +02:00
|
|
|
|
|
|
|
|
|
ISOTerminal.prototype.runISO = function(opts){
|
2024-09-16 13:28:28 +02:00
|
|
|
|
|
|
|
|
|
let me = this
|
|
|
|
|
this.opts = {...this.opts, ...opts}
|
2024-09-03 18:33:35 +02:00
|
|
|
|
let image = {}
|
|
|
|
|
if( opts.iso.match(/\.iso$/) ) image.cdrom = { url: opts.iso }
|
|
|
|
|
if( opts.iso.match(/\.bin$/) ) image.bzimage = { url: opts.iso }
|
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
|
opts = { ...image,
|
2024-09-05 19:09:40 +02:00
|
|
|
|
uart1:true, // /dev/ttyS1
|
|
|
|
|
uart2:true, // /dev/ttyS2
|
|
|
|
|
uart3:true, // /dev/ttyS3
|
2024-09-03 18:33:35 +02:00
|
|
|
|
wasm_path: "com/isoterminal/v86.wasm",
|
2024-09-16 13:28:28 +02:00
|
|
|
|
memory_size: opts.memory * 1024 * 1024,
|
2024-09-17 18:59:38 +02:00
|
|
|
|
vga_memory_size: 2 * 1024 * 1024,
|
2024-09-16 13:28:28 +02:00
|
|
|
|
screen_container: opts.dom,
|
|
|
|
|
//serial_container: opts.dom,
|
2024-09-03 18:33:35 +02:00
|
|
|
|
bios: {
|
|
|
|
|
url: "com/isoterminal/bios/seabios.bin",
|
|
|
|
|
},
|
|
|
|
|
vga_bios: {
|
|
|
|
|
url: "com/isoterminal/bios/vgabios.bin",
|
2024-09-16 13:28:28 +02:00
|
|
|
|
//urg|: "com/isoterminal/bios/VGABIOS-lgpl-latest.bin",
|
2024-09-03 18:33:35 +02:00
|
|
|
|
},
|
|
|
|
|
network_relay_url: "wss://relay.widgetry.org/",
|
2024-09-16 13:28:28 +02:00
|
|
|
|
cmdline: "rw root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose modules=virtio_pci tsc=reliable init_on_freg|=on vga=ask", //vga=0x122",
|
2024-09-03 18:33:35 +02:00
|
|
|
|
//bzimage_initrd_from_filesystem: true,
|
|
|
|
|
//filesystem: {
|
|
|
|
|
// baseurl: "com/isoterminal/v86/images/alpine-rootfs-flat",
|
|
|
|
|
// basefs: "com/isoterminal/v86/images/alpine-fs.json",
|
|
|
|
|
// },
|
|
|
|
|
//screen_dummy: true,
|
|
|
|
|
//disable_jit: false,
|
|
|
|
|
filesystem: {},
|
|
|
|
|
autostart: true,
|
2024-09-16 13:28:28 +02:00
|
|
|
|
};
|
|
|
|
|
this.emit('runISO',opts)
|
|
|
|
|
let emulator = this.emulator = new V86(opts)
|
2024-09-03 18:33:35 +02:00
|
|
|
|
|
|
|
|
|
const loading = [
|
|
|
|
|
'loading quantum bits and bytes',
|
|
|
|
|
'preparing quantum flux capacitors',
|
|
|
|
|
'crunching peanuts and chakras',
|
|
|
|
|
'preparing parallel universe',
|
|
|
|
|
'loading quantum state fluctuations',
|
|
|
|
|
'preparing godmode',
|
|
|
|
|
'loading cat pawns and cuteness',
|
|
|
|
|
'beaming up scotty',
|
|
|
|
|
'still faster than Windows update',
|
|
|
|
|
'loading a microlinux',
|
|
|
|
|
'figuring out meaning of life',
|
|
|
|
|
'Aligning your chakras now',
|
|
|
|
|
'Breathing in good vibes',
|
|
|
|
|
'Finding inner peace soon',
|
|
|
|
|
'Centering your Zen energy',
|
|
|
|
|
'Awakening third eye powers',
|
|
|
|
|
'Tuning into the universe',
|
|
|
|
|
'Balancing your cosmic karma',
|
|
|
|
|
'Stretching time and space',
|
|
|
|
|
'Recharging your soul battery',
|
|
|
|
|
'Transcending earthly limits'
|
|
|
|
|
]
|
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
|
let loadmsg = loading[ Math.floor(Math.random()*1000) % loading.length ]
|
2024-09-03 18:33:35 +02:00
|
|
|
|
this.emit('status',loadmsg)
|
|
|
|
|
|
2024-09-06 18:02:54 +02:00
|
|
|
|
// replace welcome message https://github.com/copy/v86/blob/3c77b98bc4bc7a5d51a2056ea73d7666ca50fc9d/src/browser/serial.js#L231
|
|
|
|
|
let welcome = "This is the serial console. Whatever you type or paste here will be sent to COM1"
|
|
|
|
|
let motd = "\r[38;5;129m"
|
|
|
|
|
let msg = `${loadmsg}, please wait..`
|
|
|
|
|
while( msg.length < welcome.length ) msg += " "
|
|
|
|
|
msg += "\n"
|
2024-09-16 13:28:28 +02:00
|
|
|
|
motd += msg+"\033[0m"
|
2024-09-03 18:33:35 +02:00
|
|
|
|
|
|
|
|
|
emulator.bus.register("emulator-started", async (e) => {
|
|
|
|
|
this.emit('emulator-started',e)
|
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
|
if( emulator.serial_adapter ){
|
|
|
|
|
emulator.serial_adapter.term.clear()
|
|
|
|
|
emulator.serial_adapter.term.write(motd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( me.opts.overlayfs ){
|
|
|
|
|
fetch(me.opts.overlayfs)
|
|
|
|
|
.then( (f) => {
|
2024-09-03 18:33:35 +02:00
|
|
|
|
f.arrayBuffer().then( (buf) => {
|
2024-09-16 13:28:28 +02:00
|
|
|
|
emulator.create_file('overlayfs.zip', new Uint8Array(buf) )
|
2024-09-03 18:33:35 +02:00
|
|
|
|
})
|
|
|
|
|
})
|
2024-09-16 13:28:28 +02:00
|
|
|
|
}
|
2024-09-03 18:33:35 +02:00
|
|
|
|
|
|
|
|
|
let line = ''
|
|
|
|
|
let ready = false
|
2024-09-16 13:28:28 +02:00
|
|
|
|
emulator.add_listener(`serial0-output-byte`, async (byte) => {
|
|
|
|
|
this.emit('${this.serial}-output-byte',byte)
|
2024-09-03 18:33:35 +02:00
|
|
|
|
var chr = String.fromCharCode(byte);
|
|
|
|
|
if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(chr === "\n")
|
|
|
|
|
{
|
|
|
|
|
var new_line = line;
|
|
|
|
|
line = "";
|
|
|
|
|
}
|
|
|
|
|
else if(chr >= " " && chr <= "~")
|
|
|
|
|
{
|
|
|
|
|
line += chr;
|
|
|
|
|
}
|
2024-09-16 13:28:28 +02:00
|
|
|
|
if( !ready && line.match(/^(\/ #|~%|\[.*\]>)/) ){
|
2024-09-17 18:59:38 +02:00
|
|
|
|
this.emit('postReady',e)
|
|
|
|
|
setTimeout( () => this.emit('ready',e), 500 )
|
2024-09-03 18:33:35 +02:00
|
|
|
|
ready = true
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISOTerminal.prototype.readFromPipe = function(filename,cb){
|
|
|
|
|
|
|
|
|
|
this.emulator.add_listener("9p-write-end", async (opts) => {
|
|
|
|
|
if ( opts[0] == filename.replace(/.*\//,'') ){
|
|
|
|
|
const buf = await this.emulator.read_file("console.tty")
|
2024-09-23 16:59:29 +02:00
|
|
|
|
cb( this.convert.Uint8ArrayToString(buf) )
|
2024-09-03 18:33:35 +02:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|