Make JavaScript core work like the API

This commit is contained in:
2023-03-12 10:59:37 -05:00
parent 1cc268e5d0
commit 386f4a904f
5 changed files with 127 additions and 135 deletions
+33 -43
View File
@@ -1,6 +1,30 @@
// Interface between application and WebAssembly worker thread
class Core {
//////////////////////////////// Constants ////////////////////////////////
/* Register types */
static VB_PROGRAM = 0;
static VB_SYSTEM = 1;
static VB_OTHER = 2;
/* System registers */
static VB_ADTRE = 25;
static VB_CHCW = 24;
static VB_ECR = 4;
static VB_EIPC = 0;
static VB_EIPSW = 1;
static VB_FEPC = 2;
static VB_FEPSW = 3;
static VB_PIR = 6;
static VB_PSW = 5;
static VB_TKCW = 7;
/* Other registers */
static VB_PC = 0;
///////////////////////// Initialization Methods //////////////////////////
constructor() {
@@ -138,29 +162,13 @@ class Core {
}, [], options);
}
// Retrieve the value of PC
getProgramCounter(sim, options) {
// Retrieve the value of a register
getRegister(sim, type, id, options) {
return this.message({
command: "getProgramCounter",
sim : sim.pointer
}, [], options);
}
// Retrieve the value of a program register
getProgramRegister(sim, id, options) {
return this.message({
command: "getProgramRegister",
command: "getRegister",
id : id,
sim : sim.pointer
}, [], options);
}
// Retrieve the value of a system register
getSystemRegister(sim, id, options) {
return this.message({
command: "getSystemRegister",
id : id,
sim : sim.pointer
sim : sim.pointer,
type : type
}, [], options);
}
@@ -199,21 +207,13 @@ class Core {
}, [], options);
}
// Specify a value for the program counter
setProgramCounter(sim, value, options) {
// Specify a value for a register
setRegister(sim, type, id, value, options) {
return this.message({
command: "setProgramCounter",
sim : sim.pointer,
value : value
}, [], options);
}
// Specify a value for a program register
setProgramRegister(sim, id, value, options) {
return this.message({
command: "setProgramRegister",
command: "setRegister",
id : id,
sim : sim.pointer,
type : type,
value : value
}, [], options);
}
@@ -229,16 +229,6 @@ class Core {
}, [data.buffer], options);
}
// Specify a value for a system register
setSystemRegister(sim, id, value, options) {
return this.message({
command: "setSystemRegister",
id : id,
sim : sim.pointer,
value : value
}, [], options);
}
// Execute the current instruction
singleStep(sims, options) {
return this.message({
+34 -31
View File
@@ -1,5 +1,25 @@
"use strict";
/* Register types */
const VB_PROGRAM = 0;
const VB_SYSTEM = 1;
const VB_OTHER = 2;
/* System registers */
const VB_ADTRE = 25;
const VB_CHCW = 24;
const VB_ECR = 4;
const VB_EIPC = 0;
const VB_EIPSW = 1;
const VB_FEPC = 2;
const VB_FEPSW = 3;
const VB_PIR = 6;
const VB_PSW = 5;
const VB_TKCW = 7;
/* Other registers */
const VB_PC = 0;
// Dedicated emulation thread
class CoreThread {
@@ -130,19 +150,12 @@ class CoreThread {
};
}
// Retrieve the value of PC
getProgramCounter(msg) {
return { value: this.vbGetRegister(msg.sim, 2, 0) >>> 0 };
}
// Retrieve the value of a program register
getProgramRegister(msg) {
return { value: this.vbGetRegister(msg.sim, 0, msg.id) };
}
// Retrieve the value of a system register
getSystemRegister(msg) {
return { value: this.vbGetRegister(msg.sim, 1, msg.id) >>> 0 };
// Retrieve the value of a register
getRegister(msg) {
let value = this.vbGetRegister(msg.sim, msg.type, msg.id);
if (msg.type != VB_PROGRAM)
value >>>= 0;
return { value: value };
}
// Read multiple bytes from memory
@@ -193,13 +206,10 @@ class CoreThread {
delete rep.transfers;
}
// Do not send a reply
if (subscriptions.length == 0 && !msg.reply)
return;
// Send the response to the main thread
if (subscriptions.length == 0)
return;
this.main.postMessage({
isReply : !!msg.reply,
subscriptions: subscriptions.sort(CoreThread.REFRESH_ORDER)
}, transfers);
}
@@ -224,14 +234,12 @@ class CoreThread {
return { pcs: pcs };
}
// Specify a value for the program counter
setProgramCounter(msg) {
return { value: this.vbSetRegister(msg.sim, 2, 0, msg.value) >>> 0 };
}
// Specify a value for a program register
setProgramRegister(msg) {
return { value: this.vbSetRegister(msg.sim, 0, msg.id, msg.value) };
// Specify a value for a register
setRegister(msg) {
let value = this.vbSetRegister(msg.sim, msg.type, msg.id, msg.value);
if (msg.type != VB_PROGRAM)
value >>>= 0;
return { value: value };
}
// Specify a cartridge ROM buffer
@@ -261,11 +269,6 @@ class CoreThread {
return { success: success };
}
// Specify a value for a system register
setSystemRegister(msg) {
return {value:this.vbSetRegister(msg.sim, 1, msg.id, msg.value)>>>0};
}
// Execute the current instruction
singleStep(msg) {
let sims = this.malloc(msg.sims.length, true);