Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nepx/halfix
Browse files Browse the repository at this point in the history
  • Loading branch information
pgodwin committed Dec 26, 2020
2 parents f764d52 + 3bdca5f commit a84b8e1
Show file tree
Hide file tree
Showing 14 changed files with 391 additions and 64 deletions.
2 changes: 2 additions & 0 deletions include/cpuapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct cpu_config
char *vendor_name;
int level;

int cpuid_limit_winnt;

struct cpuid_level_info features[FEATURE_SIZE_MAX];
};

Expand Down
53 changes: 38 additions & 15 deletions include/pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#define PC_H

#include "drive.h"
#include "cpuapi.h" // for struct cpu_config
#include <stdint.h>

struct loaded_file
{
struct loaded_file {
uint32_t length;
void *data;
void* data;
};

enum
{
enum {
DRIVE_TYPE_NONE = 0,
DRIVE_TYPE_DISK,
DRIVE_TYPE_CDROM
Expand All @@ -25,18 +24,33 @@ enum {
CPU_TYPE_CORE_DUO
};

struct ne2000_settings
{
int enabled;
enum {
VIRTIO_9P
};

struct ne2000_settings {
int enabled;
int port_base;
int pci;
int irq;
uint8_t mac_address[6];
};

#define MAX_VIRTIO_DEVICES 2
struct virtio_9p_cfg {
char* path;
int ro;
};

struct virtio_cfg {
int type;
union {
struct virtio_9p_cfg fs9p;
};
};

// Important: do not free this struct or modify values in it after passing it to pc_init
struct pc_settings
{
struct pc_settings {
uint32_t memory_size, vga_memory_size;
struct loaded_file bios, vgabios;

Expand All @@ -63,26 +77,35 @@ struct pc_settings

// Set to 1 if floppy should be enabled
int floppy_enabled;

struct {
// If the image is write-protected (note: has nothing to do with the drive_info write-protected bit)
int write_protected;
} floppy_settings[2];

struct ne2000_settings ne2000;
struct ne2000_settings ne2000;

struct drive_info floppy_drives[2];

struct cpu_config cpu;

struct virtio_cfg virtio[MAX_VIRTIO_DEVICES];

int boot_kernel;

// Kernel loading options
char *kernel_cmdline, *kernel_img;
// The kernel itself must be (properly) loaded to 0x100000 by whatever method you see fit.
};

enum
{
enum {
BOOT_NONE = 0,
BOOT_FLOPPY = 1,
BOOT_DISK = 2,
BOOT_CDROM = 3
};

int pc_init(struct pc_settings *pc);
int pc_init(struct pc_settings* pc);
int pc_execute(void);
uint32_t pc_run(void);
void pc_set_a20(int state);
Expand Down
61 changes: 56 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<style>
.progress {
text-align: center;
}

.progress-value {
position: absolute;
right: 0;
left: 0;
}
</style>
</head>

<body>
Expand Down Expand Up @@ -48,6 +59,11 @@ <h5 class="mb-0">
<button type="button" class="btn btn-outline-primary btn-sm btn-block" id="btn_fullscreen">Fullscreen</button>
</td>
</tr>
<tr>
<td>
<button type="button" class="btn btn-outline-primary btn-sm btn-block" id="btn_ctrlaltdel" disabled>Send CTRL+ALT+DEL</button>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -117,6 +133,9 @@ <h5 class="mb-0">
<div class="text-center">
<canvas id="canvas" height="480" width="640">Your browser does not support canvas</canvas>
</div>
<div class="text-center">
<span>Downloading <code id="pbt">nothing</code><progress id="pb" max="100" value="0"></progress>
</div>
</main>
</div>
</div>
Expand Down Expand Up @@ -144,9 +163,9 @@ <h5 class="modal-title">Memory</h5>
<small id="hlp_vmemsz" class="form-text text-muted">Megabytes of video memory</small>
</div>
</div>
</div>
</div>
</div>
</div>

<!-- BIOS modal -->
<div class="modal" tabindex="-1" id="mdl_rom">
Expand Down Expand Up @@ -295,6 +314,13 @@ <h5 class="modal-title">Other Settings</h5>
</label>
<small id="hlp_fast" class="form-text text-muted">If checked, the emulator runs as fast as possible, causing time to become desynchronized.</small>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="inp_winnt" />
<label class="form-check-label" for="inp_winnt" aria-describedby="hlp_winnt">
Work around Windows NT CPUID bug
</label>
<small id="hlp_winnt" class="form-text text-muted">If checked, the reported CPUID level is set to 2. Other functionality isn't compromised. </small>
</div>
</div>
</div>
</div>
Expand All @@ -316,7 +342,8 @@ <h5 class="modal-title">Other Settings</h5>
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

var halfix, savestate = null;
var halfix, savestate = null,
alreadyRunning = false;

function pause() {
$("#btn_pause").attr("disabled", "disabled").blur();
Expand All @@ -325,8 +352,17 @@ <h5 class="modal-title">Other Settings</h5>
}

function run(options) {
if (alreadyRunning) {
$("#btn_start").attr("disabled", "disabled").blur();
$("#btn_pause").removeAttr("disabled").blur();
halfix.pause(false);
halfix.run();
return;
}
alreadyRunning = true;
$("#btn_start").attr("disabled", "disabled").blur();
$("#btn_pause").removeAttr("disabled").blur();
$("#btn_ctrlaltdel").removeAttr("disabled");
if (!halfix) {
halfix = new Halfix(options);

Expand Down Expand Up @@ -359,6 +395,14 @@ <h5 class="modal-title">Other Settings</h5>
opts.pci = $("#inp_pci")[0].checked;
opts.pcivga = $("#inp_pcivga")[0].checked;
opts.floppy = $("#inp_floppy")[0].checked;
opts.winnt_hack = getParameterByName("winnt") ? true : $("#inp_winnt")[0].checked;

var pbt = $("#pbt"),
pb = $("#pb")[0];
opts.onprogress = function(file, cur, tot) {
pbt.html(file);
pb.setAttribute("value", (cur / tot * 100) | 0);
};

var letters = ["a", "b", "c", "d"];
for (var i = 0; i < 4; i++) {
Expand Down Expand Up @@ -474,10 +518,14 @@ <h5 class="modal-title">Other Settings</h5>
speed.innerHTML = s;
}
};

// Emscripten may override our "run"
var run = window.run;
$("#btn_start").on("click", function() {
if (opts) {
mkConfig(opts);
}
if (!alreadyRunning)
if (opts) {
mkConfig(opts);
}
run(opts);
opts = null;
});
Expand All @@ -490,6 +538,9 @@ <h5 class="modal-title">Other Settings</h5>
$("#btn_fullscreen").on("click", function() {
fullScreen();
});
$("#btn_ctrlaltdel").on("click", function() {
halfix.send_ctrlaltdel();
});

if (getParameterByName("autostart")) {
mkConfig(opts);
Expand Down
29 changes: 21 additions & 8 deletions libhalfix.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

this.total_memory = 256;

this.config = this.buildConfiguration();

this.fast = options["fast"] || false;
this.winnt_hack = options["winnt_hack"] || false;

this.reportSpeed = options["reportSpeed"] || function (n) { };
console.log(options.reportSpeed);
Expand All @@ -22,6 +21,10 @@

/** @type {ImageData} */
this.image_data = null;

this.config = this.buildConfiguration();

this.onprogress = options["onprogress"] || function (a, b, c) { };
}

var _cache = [];
Expand Down Expand Up @@ -107,10 +110,12 @@
};

/**
* @param {number} progress Fraction of completion * 100
* @param {string} f name of file
* @param {number} a current position
* @param {number} b end
*/
Halfix.prototype.updateNetworkProgress = function (progress) {

Halfix.prototype.updateNetworkProgress = function (f, a, b) {
this.onprogress(f, a, b);
};
/**
* @param {number} total Total bytes loaded
Expand Down Expand Up @@ -199,8 +204,16 @@
config.push("b=" + bootOrder[1] + "d");
config.push("c=" + bootOrder[2] + "d");

config.push("[cpu]");
config.push("cpuid_limit_winnt=" + (this.winnt_hack ? "1" : "0"));
config.push(""); // Trailing empty line

return config.join("\n");
}
Halfix.prototype["send_ctrlaltdel"] = function () {
send_ctrlaltdel(1);
send_ctrlaltdel(0);
};

function loadFiles(paths, cb, gz) {
var resultCounter = paths.length | 0,
Expand All @@ -218,8 +231,7 @@

xhr.onprogress = function (e) {
if (e.lengthComputable) {
var now = e.loaded / e.total * 100 | 0;
_halfix.updateNetworkProgress(now - lastProgress | 0);
_halfix.updateNetworkProgress(path, e.loaded, e.total);
lastProgress = now;
}
};
Expand Down Expand Up @@ -382,7 +394,7 @@
// Emscripten support code
// ========================================================================

var dynCall_vii;
var dynCall_vii, send_ctrlaltdel;
var cycles, now;
function run_wrapper2() {
wrap("emscripten_init")();
Expand All @@ -392,6 +404,7 @@
get_now = wrap("emscripten_get_now");
dynCall_vii = wrap("emscripten_dyncall_vii");
run = wrap("emscripten_run");
send_ctrlaltdel = wrap("display_send_ctrl_alt_del");

wrap("emscripten_set_fast")(_halfix.fast);
init_cb();
Expand Down
8 changes: 6 additions & 2 deletions makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var end_flags = [], fincc_flags = [];
// "));
end_flags = "-lSDL -lSDLmain -lm -lz".split(" ");

if(os.endianness() === "BE"){
if (os.endianness() === "BE") {
console.warn("WARNING: This emulator has not been tested on big-endian platforms and may not work.");
flags.push("-DCFG_BIG_ENDIAN");
}
Expand Down Expand Up @@ -153,6 +153,9 @@ for (var i = 0; i < argv.length; i++) {
case "--cc":
cc = fincc = argv[++i];
break;
case "--fincc":
fincc = argv[++i];
break;
case "--disable-debug":
flags.splice(flags.indexOf("-g3"), 1);
break;
Expand Down Expand Up @@ -525,7 +528,8 @@ function done_compiling() {
for (var i = 0; i < all_files.length; i++) {
cmdstring += find_object_file_name(all_files[i]) + " ";
}
cmdstring += end_flags.join(" ");
if (fincc !== "ar")
cmdstring += end_flags.join(" ");
// if (build_type !== "emscripten") { // apparently, emscripten has it built
// in! how nice of them
// cmdstring += ["", "-lSDL", "-lSDLmain", "-I/usr/include/SDL"].join("
Expand Down
7 changes: 0 additions & 7 deletions src/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ int cpu_add_rom(int addr, int size, void* data)
return 0;
}

// Sets CPUID information. Currently unimplemented
int cpu_set_cpuid(struct cpu_config* x)
{
UNUSED(x);
return 0;
}

int cpu_get_exit_reason(void)
{
return cpu.exit_reason;
Expand Down
2 changes: 2 additions & 0 deletions src/cpu/fpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
*/
// There are no read-modify-write operations, thank god.

#ifndef LIBCPU
#define FPU_DEBUG
#ifdef FPU_DEBUG
#include <math.h>
#endif
#endif

#include "cpu/cpu.h"
#include "cpu/instrument.h"
Expand Down
Loading

0 comments on commit a84b8e1

Please sign in to comment.