Is there a way to read and write X86 ports? #1184
-
Hi all, I have some old DOS software that communicates through DOS I/O ports ("inp" and "out"). I'd like to emulate this software in V86 and communicate with it from a Javascript function. Is there an exposed API to read and write the emulated V86 ports? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Something like this should work: YourApplication.Prototype.start_v86 = function()
{
this.vm = new V86({ ... });
// Example: Fictional I/O port 0x28
let port_0x28 = undefined;
this.vm.bus.register('emulator-started', () => {
if(port_0x28 === undefined) { // make sure to register our 0x28 I/O handler only once
const io = this.vm.v86.cpu.io; // instance of class IO
port_0x28 = 0; // set initial port value
io.register_read(0x28, this, function() {
// handle read-access (inp) to port 0x28
console.log(`inp 0x28: ${port_0x28}`);
return port_0x28;
});
io.register_write(0x28, this, function(out_byte) {
// handle write-access (out) to port 0x28
port_0x28 = out_byte;
console.log(`out 0x28: ${port_0x28}`);
});
}
});
} I just tested this function with guest FreeDOS and QBasic, you will have to see how you weave that into your code. Note that after creating your V86 instance you have to wait a bit until Take a good look at the API of class IO for the choices you have there, and for usage examples at the source of any emulated hardware subsystem (like UART or PS2 to name a few), class IO is used all over the place. |
Beta Was this translation helpful? Give feedback.
Something like this should work: