Skip to content

Commit

Permalink
Update to newest jsbeeb (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgodbolt authored Nov 2, 2024
1 parent d549e70 commit 1f123d5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 44 deletions.
63 changes: 43 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"glob": "^11.0.0",
"html-webpack-partials-plugin": "^0.8.0",
"jquery": "^3.7.1",
"jsbeeb": "github:mattgodbolt/jsbeeb#636f0b9e7668e2a1eaf45b7b1967ff9a045f66cc",
"jsbeeb": "github:mattgodbolt/jsbeeb#4e5f3666cbce0613bc9e7006d4aceddcb1095dc4",
"monaco-editor": "^0.52.0",
"promise": "^8.3.0",
"resize-observer-polyfill": "^1.5.1",
Expand Down
60 changes: 38 additions & 22 deletions src/emulator.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import _ from "underscore";
import Cpu6502 from "jsbeeb/6502";
import canvasLib from "jsbeeb/canvas";
import Video from "jsbeeb/video";
import Debugger from "jsbeeb/debug";
import SoundChip from "jsbeeb/soundchip";
import DdNoise from "jsbeeb/ddnoise";
import models from "jsbeeb/models";
import Cmos from "jsbeeb/cmos";
import utils from "jsbeeb/utils";
import {Cpu6502} from "jsbeeb/6502";
import * as canvasLib from "jsbeeb/canvas";
import {Video} from "jsbeeb/video";
import {Debugger} from "jsbeeb/web/debug";
import {FakeSoundChip} from "jsbeeb/soundchip";
import {FakeDdNoise} from "jsbeeb/ddnoise";
import * as models from "jsbeeb/models";
import {Cmos} from "jsbeeb/cmos";
import * as utils from "jsbeeb/utils";
import Promise from "promise";
import ResizeObserver from "resize-observer-polyfill";
import Snapshot from "snapshot";
Expand Down Expand Up @@ -49,6 +49,30 @@ class ScreenResizer {
}
}

class Emulator6502 extends Cpu6502 {
constructor(model, dbgr, video, soundChip, ddNoise, cmos, config) {
super(
model,
dbgr,
video,
soundChip,
ddNoise,
null, // Music5000
cmos,
config,
null, // econet
);
}

execute(numCyclesToRun) {
// Patch to stop it resetting cycle count on execute.
// Number.MAX_SAFE_INTEGER should gives us plenty of headroom
this.halted = false;
this.targetCycles += numCyclesToRun;
return this.executeInternalFast();
}
}

export class Emulator {
constructor(root) {
this.root = root;
Expand All @@ -72,10 +96,10 @@ export class Emulator {

window.theEmulator = this;

this.video = new Video.Video(Model.isMaster, this.canvas.fb32, _.bind(this.paint, this));
this.video = new Video(Model.isMaster, this.canvas.fb32, _.bind(this.paint, this));

this.soundChip = new SoundChip.FakeSoundChip();
this.ddNoise = new DdNoise.FakeDdNoise();
this.soundChip = new FakeSoundChip();
this.ddNoise = new FakeDdNoise();

this.dbgr = new Debugger(this.video);
const cmos = new Cmos({
Expand All @@ -90,7 +114,7 @@ export class Emulator {
},
});
const config = {};
this.cpu = new Cpu6502(
this.cpu = new Emulator6502(
Model,
this.dbgr,
this.video,
Expand All @@ -100,14 +124,6 @@ export class Emulator {
config,
);

// Patch this version of JSbeeb to stop it reseting cycle count.
// Number.MAX_SAFE_INTEGER should gives us plenty of headroom
this.cpu.execute = function (numCyclesToRun) {
this.halted = false;
this.targetCycles += numCyclesToRun;
return this.executeInternalFast();
};

screen.mousemove(event => this.mouseMove(event));
screen.mouseleave(() => this.mouseLeave());
screen.keyup(event => this.keyUp(event));
Expand Down Expand Up @@ -158,6 +174,7 @@ export class Emulator {
this.emuStatus.innerHTML += ".";
if (this.emuStatus.innerHTML.length > 18) this.emuStatus.innerHTML = "Calling beebjit";
}

this.emuStatus.innerHTML = "Calling beebjit";
const counterInterval = setInterval(myCounter.bind(this), 200);
const basic = btoa(tokenised).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
Expand Down Expand Up @@ -191,7 +208,6 @@ export class Emulator {

async runProgram(tokenised) {
if (!this.ready) return;
console.log(this.cpu.currentCycles);
this.cpu.reset(true);
const processor = this.cpu;
await processor.execute(BotStartCycles); // match bbcmicrobot
Expand Down
2 changes: 1 addition & 1 deletion src/owlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Emulator} from "./emulator";
import Examples from "./examples.yaml";
import {expandCode, partialDetokenise} from "./tokens";
import {encode} from "base2048";
import tokenise from "jsbeeb/basic-tokenise";
import * as tokenise from "jsbeeb/basic-tokenise";
import "./owlet-editor.less";
import {getWarnings} from "./bbcbasic";
import {makeUEF} from "./UEF";
Expand Down

0 comments on commit 1f123d5

Please sign in to comment.