From abb1c3fb3eb7e100788113a4b783bb9359b7617d Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 7 Jun 2020 15:23:31 -0500 Subject: [PATCH] c64: reset() fixed for ROM cart --- doc/notes.txt | 3 ++- src/machine/c64.ts | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/doc/notes.txt b/doc/notes.txt index b6cb3c3a..1f3b449e 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -196,13 +196,14 @@ TODO: - emu doesn't reset properly (after gotoxy() BIOS call) - disk image support - https://github.com/cc65/cc65/issues/946 - - sample buffer skips + - sample buffer skips (need to sync w/ vsync) - upgrade to ES2020? - https://github.com/microsoft/TypeScript/issues/16577 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules - need Edge 79+ - no import in workers + - copy to gen/ directory (allowJs is weird) WEB WORKER FORMAT diff --git a/src/machine/c64.ts b/src/machine/c64.ts index 2cec82ce..580aeb7d 100644 --- a/src/machine/c64.ts +++ b/src/machine/c64.ts @@ -586,9 +586,10 @@ export class C64_WASMMachine extends BaseWASMMachine implements Machine { for (var ch=0; ch<128; ch++) { this.setKeyInput(ch, 0, KeyFlags.KeyUp); } - if (this.prgstart) { - // advance BIOS - super.advanceFrameClock(null, 180000); + // is program loaded into RAM? + if (this.prgstart < 0x8000) { + // advance BIOS a few frames + this.exports.machine_exec(this.sys, 150000); // set IRQ routine @ 0x314 var old0x314 = this.read(0x314) + this.read(0x315) * 256; this.write(0x314, 0x0d); @@ -600,6 +601,15 @@ export class C64_WASMMachine extends BaseWASMMachine implements Machine { // reset 0x314 to old value this.write(0x314, old0x314 & 0xff); this.write(0x315, old0x314 >> 8); + } else { + // get out of reset + this.exports.machine_exec(this.sys, 100); + // wait until cartridge start + // TODO: detect ROM cartridge + var warmstart = this.romarr[0x4] + this.romarr[0x5]*256; + for (var i=0; i<150000 && this.getPC() != warmstart; i++) { + this.exports.machine_tick(this.sys); + } } } advanceFrame(trap: TrapCondition) : number {