Skip to content

Commit

Permalink
Restart: Repackaged some APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMo1 committed Aug 15, 2023
1 parent f034fe7 commit d1587b0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 48 deletions.
8 changes: 4 additions & 4 deletions keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function Keyboard(Zeal, PIO) {
*
* Returns true if the key is valid, false else.
*/
function key_released(keycode) {
function key_released(keycode) {
/* Get the PS/2 code for the key pressed */
const list = get_ps2_code(keycode);

Expand Down Expand Up @@ -313,7 +313,7 @@ function Keyboard(Zeal, PIO) {
transfer_active = false;
} else {
/* Schedule the next key in 1ms */
zeal.tstatesutils.registerTstateCallback(() => {
zeal.registerTstateCallback(() => {
transfer_active = false;
send_next_keypress();
}, us_to_tstates(1000));
Expand All @@ -330,14 +330,14 @@ function Keyboard(Zeal, PIO) {

for (var i = 0; i < scancodes.length; i++) {
const index = i;
zeal.tstatesutils.registerTstateCallback(() => {
zeal.registerTstateCallback(() => {
/* Prepare the next scancode */
shift_register = scancodes[index];
/* Assert the keyboard signal */
pio.pio_set_b_pin(IO_KEYBOARD_PIN, 0);
} , i * PS2_KEY_TIMING + delay);

zeal.tstatesutils.registerTstateCallback(() => {
zeal.registerTstateCallback(() => {
/* Reset the keyboard signal */
pio.pio_set_b_pin(IO_KEYBOARD_PIN, 1);
/* Disable the flag too */
Expand Down
33 changes: 24 additions & 9 deletions machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ function Zeal8bitComputer() {
}
},

interrupt: function(interrupt_vector) {
zpu.interrupt(false, interrupt_vector);
step_cpu();
},

adjustTStatesWhenHalted: function(end) {
const earliest = tstatesutils.getEarliestCallback();
if (earliest == null || earliest.tstates > end) {
Expand All @@ -126,7 +121,13 @@ function Zeal8bitComputer() {
}
}

this.tstatesutils = tstatesutils;
this.getTstates = tstatesutils.getTstates;
this.addTstates = tstatesutils.addTstates;
this.getEarliestCallback = tstatesutils.getEarliestCallback;
this.registerTstateCallback = tstatesutils.registerTstateCallback;
this.registerTstateInterval = tstatesutils.registerTstateInterval;
this.removeTstateCallback = tstatesutils.removeTstateCallback;
this.adjustTStatesWhenHalted = tstatesutils.adjustTStatesWhenHalted;

/* Check which scale to use for the video */
var scale = 1;
Expand Down Expand Up @@ -158,9 +159,7 @@ function Zeal8bitComputer() {
this.eeprom = eeprom;
this.devices = devices;
this.zpu = zpu;

var registers = zpu.getState();
this.registers = registers;
this.getCPUState = zpu.getState

function mem_read(address) {
var rd = 0;
Expand Down Expand Up @@ -314,12 +313,25 @@ function Zeal8bitComputer() {
step_cpu();
}

function interrupt(interrupt_vector) {
zpu.interrupt(false, interrupt_vector);
step_cpu();
}

function destroy() {
clearInterval(interval);
interval = null;
running = false;
}

function KeyboardKeyPressed(keycode) {
return keyboard.key_pressed(keycode);
}

function KeyboardKeyReleased(keycode) {
return keyboard.key_released(keycode);
}

this.mem_read = mem_read;
this.mem_write = mem_write;

Expand All @@ -333,5 +345,8 @@ function Zeal8bitComputer() {
this.stop = stop;
this.restart = restart;
this.reset = reset;
this.interrupt = interrupt;
this.destroy = destroy;
this.KeyboardKeyPressed = KeyboardKeyPressed;
this.KeyboardKeyReleased = KeyboardKeyReleased;
}
2 changes: 1 addition & 1 deletion pio.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function PIO(Zeal) {
port.mode != MODE_OUTPUT &&
(port.mode != MODE_BITCTRL || pio_check_bitctrl_interrupt(port, pin, value)))
{
zeal.tstatesutils.interrupt(port.int_vector);
zeal.interrupt(port.int_vector);
}
}

Expand Down
4 changes: 2 additions & 2 deletions rom.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
erasing = true;
console.log("Erasing FLASH");
/* Erasing a sector takes 25ms on real hardware, register a callback to actually reflect this */
zeal.tstatesutils.registerTstateCallback(() => {
zeal.registerTstateCallback(() => {
for (var i = 0 ; i< 4096; i++)
data[i + sector] = 0xff;
erasing = false;
Expand Down Expand Up @@ -156,7 +156,7 @@
writing = true;
console.log("Writing byte to FLASH");
/* Writing a byte takes 20us on real hardware, register a callback to actually reflect this */
zeal.tstatesutils.registerTstateCallback(() => {
zeal.registerTstateCallback(() => {
data[address] = value;
writing = false;
writing_byte = 0;
Expand Down
4 changes: 2 additions & 2 deletions screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ function VideoChip(Zeal, PIO, scale) {
/* We don't need to add a listener on the PIO, as they are mainly for OUTPUT pins.
* But let's keep in mind that this may change in the future */
/* Start the V_Blank signal generation */
const vblank_interval = zeal.tstatesutils.registerTstateInterval(() => {
const vblank_interval = zeal.registerTstateInterval(() => {
/* Clear VBLANK bit in the PIO state */
pio.pio_set_b_pin(IO_VBLANK_PIN, 0);
}, VBLANK_TSTATES_PERIOD);

/* Register the same interval but for disabling the signal
* So the period is the same as the one above, but we need to start it
* a bit later (after 63us) */
const vblank_interval_end = zeal.tstatesutils.registerTstateInterval(() => {
const vblank_interval_end = zeal.registerTstateInterval(() => {
pio.pio_set_b_pin(IO_VBLANK_PIN, 1);
}, VBLANK_TSTATES_PERIOD, VBLANK_TSTATES_PERIOD_END);

Expand Down
6 changes: 3 additions & 3 deletions uart.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ function UART(Zeal, PIO) {
return;
}

const tstates = zeal.tstatesutils.getTstates();
const tstates = zeal.getTstates();
/* Ignore the case where a transfer hasn't been started and the line is set to 1 */
if (bit == 1 && tx_fifo.length == 0) {
/* Nothing to do */
} else if (bit == 0 && tx_fifo.length == 0) {
/* Register a callback in 10 UART bits */
zeal.tstatesutils.registerTstateCallback(transferComplete, Math.floor(9.1 * bit_tstates));
zeal.registerTstateCallback(transferComplete, Math.floor(9.1 * bit_tstates));
tx_fifo.push({ tstates, bit });
} else {
tx_fifo.push({ tstates, bit });
Expand Down Expand Up @@ -104,7 +104,7 @@ function UART(Zeal, PIO) {

/* If we have to register a callback, do it now */
if (callback) {
zeal.tstatesutils.registerTstateCallback(start_shifting, bit_tstates - 1);
zeal.registerTstateCallback(start_shifting, bit_tstates - 1);
}
}

Expand Down
54 changes: 27 additions & 27 deletions zeal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ function dumpRamContent(virtaddr, physaddr, lines) {
}

function setASMView() {

let regs = zealcom.getCPUState();
/* Get the PC, which is a virtual address */
const pc = zealcom.registers != null ? (zealcom.registers.pc) : 0;
const pc = regs != null ? (regs.pc) : 0;

/* Set the number of instructions we need to disassemble and show */
const instructions = 20;
Expand Down Expand Up @@ -124,30 +124,30 @@ function updateAndShowRAM () {
}

function updateRegistersHTML() {
let reg = zealcom.registers;
$("#rega").text(hex8(reg.a));
$("#regb").text(hex8(reg.b));
$("#regc").text(hex8(reg.c));
$("#regd").text(hex8(reg.d));
$("#rege").text(hex8(reg.e));
$("#regh").text(hex8(reg.h));
$("#regl").text(hex8(reg.l));
$("#regix").text(hex(reg.ix));
$("#regiy").text(hex(reg.iy));
$("#regbc").text(hex16(reg.b, reg.c));
$("#regde").text(hex16(reg.d, reg.e));
$("#reghl").text(hex16(reg.h, reg.l));
$("#regpc").text(hex(reg.pc));
$("#regsp").text(hex(reg.sp));
let regs = zealcom.getCPUState();
$("#rega").text(hex8(regs.a));
$("#regb").text(hex8(regs.b));
$("#regc").text(hex8(regs.c));
$("#regd").text(hex8(regs.d));
$("#rege").text(hex8(regs.e));
$("#regh").text(hex8(regs.h));
$("#regl").text(hex8(regs.l));
$("#regix").text(hex(regs.ix));
$("#regiy").text(hex(regs.iy));
$("#regbc").text(hex16(regs.b, regs.c));
$("#regde").text(hex16(regs.d, regs.e));
$("#reghl").text(hex16(regs.h, regs.l));
$("#regpc").text(hex(regs.pc));
$("#regsp").text(hex(regs.sp));
/* Special treatment for the flags */
var flags = (reg.flags.S == 1 ? "S" : "") +
(reg.flags.Z == 1 ? "Z" : "") +
(reg.flags.Y == 1 ? "Y" : "") +
(reg.flags.H == 1 ? "H" : "") +
(reg.flags.X == 1 ? "X" : "") +
(reg.flags.P == 1 ? "P" : "") +
(reg.flags.N == 1 ? "N" : "") +
(reg.flags.C == 1 ? "C" : "");
var flags = (regs.flags.S == 1 ? "S" : "") +
(regs.flags.Z == 1 ? "Z" : "") +
(regs.flags.Y == 1 ? "Y" : "") +
(regs.flags.H == 1 ? "H" : "") +
(regs.flags.X == 1 ? "X" : "") +
(regs.flags.P == 1 ? "P" : "") +
(regs.flags.N == 1 ? "N" : "") +
(regs.flags.C == 1 ? "C" : "");

$("#flags").text(flags);

Expand Down Expand Up @@ -203,15 +203,15 @@ $("#read-button").on('click', function() {
});

$("#screen").on("keydown", function(e) {
const handled = zealcom.keyboard.key_pressed(e.keyCode);
const handled = zealcom.KeyboardKeyPressed(e.keyCode);

if (handled) {
e.preventDefault();
}
});

$("#screen").on("keyup", function(e) {
const handled = zealcom.keyboard.key_released(e.keyCode);
const handled = zealcom.KeyboardKeyReleased(e.keyCode);

if (handled) {
e.preventDefault();
Expand Down

0 comments on commit d1587b0

Please sign in to comment.