Skip to content

Commit

Permalink
Add extra_images config setting for V86Starter, extend test cases wit…
Browse files Browse the repository at this point in the history
…h floppy eject insert
  • Loading branch information
JoeOsborn committed Aug 21, 2023
1 parent ac562c7 commit 7e86ada
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 26 deletions.
29 changes: 28 additions & 1 deletion src/browser/starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
* - `filesystem Object` (No 9p filesystem) - A 9p filesystem, see
* [filesystem.md](filesystem.md).
*
* - `extra_images Object` (No extra images) - An object whose keys
are extra image names and whose values are images to load (see
below). Names used by other images described above are
disallowed.
*
* - `serial_container HTMLTextAreaElement` (No serial terminal) - A textarea
* that will receive and send data to the emulated serial terminal.
* Alternatively the serial terminal can also be accessed programatically,
Expand Down Expand Up @@ -364,7 +369,12 @@ V86Starter.prototype.continue_init = async function(emulator, options)
settings.fs9p_json = buffer;
break;
default:
dbg_assert(false, name);
dbg_assert(name in this.extra_images, name);
if(name in this.extra_images)
{
this.extra_images[name].buffer = buffer;
}
break;
}
}

Expand Down Expand Up @@ -474,6 +484,15 @@ V86Starter.prototype.continue_init = async function(emulator, options)
console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");
}

if("extra_images" in options)
{
this.extra_images = options["extra_images"];
}
else
{
this.extra_images = {};
}

var image_names = [
"bios", "vga_bios",
"cdrom", "hda", "hdb", "fda", "fdb",
Expand All @@ -485,6 +504,14 @@ V86Starter.prototype.continue_init = async function(emulator, options)
{
add_file(image_names[i], options[image_names[i]]);
}
for(let other_image in this.extra_images)
{
if(other_image in image_names)
{
throw new Error("Extra image name "+other_image+" overlaps with built-in image");
}
add_file(other_image, this.extra_images[other_image])
}

if(options["filesystem"])
{
Expand Down
52 changes: 33 additions & 19 deletions src/floppy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"use strict";

const DIR_DOOR = 0x80;
const ST1_NID = 1 << 0;
const ST1_NDAT = 1 << 2;

/**
* @constructor
*
Expand Down Expand Up @@ -49,7 +53,6 @@ function FloppyController(cpu, fda_image, fdb_image)
{
this.floppy_type = this.insert_fda(fda_image);
}
this.dir = 0x0;
cpu.devices.rtc.cmos_write(CMOS_FLOPPY_DRIVE_TYPE, this.floppy_type.type << 4);

dbg_assert(!fdb_image, "FDB not supported");
Expand All @@ -64,15 +67,17 @@ function FloppyController(cpu, fda_image, fdb_image)
this.io.register_write(0x3F5, this, this.port3F5_write);
}

FloppyController.prototype.eject_fda = function() {
FloppyController.prototype.eject_fda = function()
{
this.fda_image = null;
this.sectors_per_track = 0;
this.number_of_heads = 0;
this.number_of_cylinders = 0;
this.dir = 0x80;
this.dir = DIR_DOOR;
};

FloppyController.prototype.insert_fda = function(fda_image) {
FloppyController.prototype.insert_fda = function(fda_image)
{
var floppy_types = {
[160 * 1024]: { type: 1, tracks: 40, sectors: 8, heads: 1 },
[180 * 1024]: { type: 1, tracks: 40, sectors: 9, heads: 1 },
Expand All @@ -97,7 +102,8 @@ FloppyController.prototype.insert_fda = function(fda_image) {
number_of_heads,
floppy_type = floppy_types[floppy_size];

if (!floppy_type) {
if (!floppy_type)
{
floppy_size = fda_image.byteLength > 1440 * 1024 ? 2880 * 1024 : 1440 * 1024;
floppy_type = floppy_types[floppy_size];

Expand All @@ -112,7 +118,7 @@ FloppyController.prototype.insert_fda = function(fda_image) {
this.number_of_heads = number_of_heads;
this.number_of_cylinders = number_of_cylinders;
this.fda_image = fda_image;
this.dir = 0x80;
this.dir = DIR_DOOR;
return floppy_type;
};

Expand Down Expand Up @@ -318,7 +324,7 @@ FloppyController.prototype.port3F2_write = function(value)
dbg_log("enable dma/irq: " + !!(value & 8), LOG_FLOPPY);
dbg_log("reset fdc: " + !!(value & 4), LOG_FLOPPY);
dbg_log("drive select: " + (value & 3), LOG_FLOPPY);
if((value & 3) != 0)
if((value & 3) !== 0)
{
dbg_log("guest: fdb not implemented");
}
Expand All @@ -331,11 +337,14 @@ FloppyController.prototype.check_drive_status = function(args)
{
dbg_log("check drive status", LOG_FLOPPY);
// do nothing if no fda
if (this.fda_image) {
if (this.fda_image)
{
this.status_reg1 = 0;
} else {
}
else
{
// TODO: is this right?
this.status_reg1 = (1 << 2) | 1;
this.status_reg1 = ST1_NDAT | ST1_NID;
}

this.response_index = 0;
Expand All @@ -346,7 +355,8 @@ FloppyController.prototype.check_drive_status = function(args)
FloppyController.prototype.seek = function(args)
{
dbg_log("seek", LOG_FLOPPY);
if((args[0] & 3) !== 0) {
if((args[0] & 3) !== 0)
{
dbg_log("seek on fdb");
this.raise_irq();
return;
Expand All @@ -356,16 +366,19 @@ FloppyController.prototype.seek = function(args)
let new_head = args[0] >> 2 & 1;

// clear eject flag if seek takes us to a new cylinder
if(new_cylinder != this.last_cylinder)
if(new_cylinder !== this.last_cylinder)
{
this.dir = 0x80;
this.dir = 0x0;
}
// do nothing if no fda
if (this.fda_image) {
if (this.fda_image)
{
this.status_reg1 = 0;
} else {
}
else
{
// TODO: is this right?
this.status_reg1 = (1 << 2) | 1;
this.status_reg1 = ST1_NDAT | ST1_NID;
}

this.status_reg0 = 0x20;
Expand Down Expand Up @@ -415,7 +428,7 @@ FloppyController.prototype.do_sector = function(is_write, args)

if(!this.fda_image)
{
this.status_reg1 = (1 << 2) | 1;
this.status_reg1 = ST1_NDAT | ST1_NID;
return;
}
this.status_reg1 = 0;
Expand Down Expand Up @@ -453,8 +466,9 @@ FloppyController.prototype.done = function(args, cylinder, head, sector, error)
}

// clear eject flag if seek or write has taken us to a new cylinder
if(cylinder != this.last_cylinder) {
this.dir = 0x80;
if(cylinder !== this.last_cylinder)
{
this.dir = 0x0;
}

this.status_reg0 = 0x20;
Expand Down
71 changes: 65 additions & 6 deletions tests/full/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var TEST_NAME = process.env.TEST_NAME;
const TEST_RELEASE_BUILD = +process.env.TEST_RELEASE_BUILD;
const RUN_SLOW_TESTS = +process.env.RUN_SLOW_TESTS;

const VERBOSE = false;
const VERBOSE = +process.env.VERBOSE || false;
const LOG_SCREEN = false;

try
Expand Down Expand Up @@ -79,6 +79,44 @@ function send_work_to_worker(worker, message)
}
}

function do_action(test, emulator, run_step)
{
if(Array.isArray(run_step))
{
for(let step of run_step)
{
do_action(test, emulator, step);
}
}
else if(typeof run_step == "string")
{
if(VERBOSE) console.error("Sending '%s'", run_step);
emulator.keyboard_send_text(run_step);
}
else if(typeof run_step == "function")
{
if(VERBOSE) console.error("Run fn ", run_step);
run_step(test, emulator);
}
else if(typeof run_step == "object")
{
if(VERBOSE) console.error("Trigger ", run_step);
switch(run_step.action)
{
case "eject_fda":
{
emulator.v86.cpu.devices.fdc.eject_fda();
break;
}
case "insert_fda":
{
emulator.v86.cpu.devices.fdc.insert_fda(emulator.extra_images[run_step.image].buffer);
break;
}
}
}
}

if(cluster.isMaster)
{
var tests = [
Expand Down Expand Up @@ -305,6 +343,29 @@ if(cluster.isMaster)
"A:\\>",
],
},
{
name: "MS-DOS (hard disk + floppy disk + eject + insert)",
skip_if_disk_image_missing: true,
hda: root_path + "/images/msdos.img",
fda: root_path + "/images/kolibri.img",
extra_images:
{
fdc: { url: root_path + "/images/kolibri.img" },
},
boot_order: 0x132,
timeout: 90,
actions: [
{ on_text: "C:\\>", run:[{action:"eject_fda"}, "a:\n"] },
{ on_text: "Abort, Retry, Fail?", run: "f"},
{ on_text: "Current drive is no longer valid>", run: [ "c:\n", { action:"insert_fda", image:"fdc" } ] },
{ on_text: "C:\\>", run: "a:\n" },
],
expected_texts: [
"Abort, Retry, Fail?",
"C:\\>",
"A:\\>",
],
},
{
name: "Linux 4",
skip_if_disk_image_missing: true,
Expand Down Expand Up @@ -993,6 +1054,7 @@ function run_test(test, done)
settings.acpi = test.acpi;
settings.boot_order = test.boot_order;
settings.cpuid_level = test.cpuid_level;
settings.extra_images = test.extra_images;

if(test.expected_texts)
{
Expand All @@ -1007,7 +1069,6 @@ function run_test(test, done)
{
test.expected_serial_text = [];
}

var emulator = new V86(settings);
var screen = new Uint8Array(SCREEN_WIDTH * 25);

Expand Down Expand Up @@ -1185,8 +1246,7 @@ function run_test(test, done)

timeouts.push(
setTimeout(() => {
if(VERBOSE) console.error("Sending '%s'", action.run);
emulator.keyboard_send_text(action.run);
do_action(test, emulator, action.run);
}, action.after || 0)
);
}
Expand Down Expand Up @@ -1239,8 +1299,7 @@ function run_test(test, done)
{
timeouts.push(
setTimeout(() => {
if(VERBOSE) console.error("Sending '%s'", action.run);
emulator.keyboard_send_text(action.run);
do_action(test, emulator, action.run);
}, action.after || 0)
);
}
Expand Down

0 comments on commit 7e86ada

Please sign in to comment.