From e1772f2565b2d219e55403fb03a6a62adb9ccfa0 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Mon, 6 Jan 2020 12:16:00 -0600 Subject: [PATCH] refactored into BaseWASMMachine/C64 --- src/common/baseplatform.ts | 151 +++++++++---------------------------- src/machine/c64.ts | 97 ++++++++++++++++++++++++ src/platform/c64.ts | 8 +- 3 files changed, 136 insertions(+), 120 deletions(-) diff --git a/src/common/baseplatform.ts b/src/common/baseplatform.ts index d61798f4..35e15d50 100644 --- a/src/common/baseplatform.ts +++ b/src/common/baseplatform.ts @@ -954,7 +954,7 @@ import { Probeable, RasterFrameBased, AcceptsPaddleInput, SampledAudioSink } fro import { SampledAudio } from "./audio"; import { ProbeRecorder } from "./recorder"; -interface Machine extends Bus, Resettable, FrameBased, AcceptsROM, HasCPU, SavesState, SavesInputState { +export interface Machine extends Bus, Resettable, FrameBased, AcceptsROM, HasCPU, SavesState, SavesInputState { } function hasVideo(arg:any): arg is VideoSource { @@ -1154,28 +1154,25 @@ export abstract class BaseZ80MachinePlatform extends BaseMach // WASM Support // TODO: detangle from c64 -export class WASMMachine implements Machine { - +export abstract class BaseWASMMachine { prefix : string; instance : WebAssembly.Instance; exports : any; sys : number; pixel_dest : Uint32Array; pixel_src : Uint32Array; - romptr : number; - romlen : number; - romarr : Uint8Array; stateptr : number; statearr : Uint8Array; cpustateptr : number; cpustatearr : Uint8Array; cpu : CPU; + romptr : number; + romlen : number; + romarr : Uint8Array; audio : SampledAudioSink; audioarr : Float32Array; - prgstart : number; - initstring : string; - initindex : number; - joymask0 = 0; + + abstract getCPUState() : CpuState; constructor(prefix: string) { this.prefix = prefix; @@ -1228,21 +1225,6 @@ export class WASMMachine implements Machine { // enable c64 joystick map to arrow keys (TODO) //this.exports.c64_set_joystick_type(this.sys, 1); } - reset() { - this.exports.machine_reset(this.sys); - // load rom - if (this.romptr && this.romlen) { - this.exports.machine_load_rom(this.sys, this.romptr, this.romlen); - this.prgstart = this.romarr[0] + (this.romarr[1]<<8); // TODO: get starting address - if (this.prgstart == 0x801) this.prgstart = 0x80d; - } - // set init string - // TODO: sometimes gets hung up - if (this.prgstart) { - this.initstring = "\r\r\r\r\r\r\r\r\r\r\rSYS " + this.prgstart + "\r"; - this.initindex = 0; - } - } getPC() : number { return this.exports.machine_cpu_get_pc(this.sys); } @@ -1261,31 +1243,8 @@ export class WASMMachine implements Machine { this.romlen = rom.length; this.reset(); } - advanceFrame(trap: TrapCondition) : number { - var i : number; - var cpf = 19656; // TODO: pal, const - if (trap) { - for (i=0; i> 1); - this.setKeyInput(ch, 0, (this.initindex&1) ? KeyFlags.KeyUp : KeyFlags.KeyDown); - if (++this.initindex >= this.initstring.length*2) this.initstring = null; - } + reset() { + this.exports.machine_reset(this.sys); } read(address: number) : number { return this.exports.machine_mem_read(this.sys, address & 0xffff); @@ -1296,53 +1255,6 @@ export class WASMMachine implements Machine { write(address: number, value: number) : void { this.exports.machine_mem_write(this.sys, address & 0xffff, value & 0xff); } - getCPUState() { - this.exports.machine_save_cpu_state(this.sys, this.cpustateptr); - var s = this.cpustatearr; - var pc = s[2] + (s[3]<<8); - return { - PC:pc, - SP:s[9], - A:s[6], - X:s[7], - Y:s[8], - C:s[10] & 1, - Z:s[10] & 2, - I:s[10] & 4, - D:s[10] & 8, - V:s[10] & 64, - N:s[10] & 128, - o:this.readConst(pc), - } - } - saveState() { - this.exports.machine_save_state(this.sys, this.stateptr); - /* - for (var i=0; i> 1); + this.setKeyInput(ch, 0, (this.initindex&1) ? KeyFlags.KeyUp : KeyFlags.KeyDown); + if (++this.initindex >= this.initstring.length*2) this.initstring = null; + } + } + getCPUState() { + this.exports.machine_save_cpu_state(this.sys, this.cpustateptr); + var s = this.cpustatearr; + var pc = s[2] + (s[3]<<8); + return { + PC:pc, + SP:s[9], + A:s[6], + X:s[7], + Y:s[8], + C:s[10] & 1, + Z:s[10] & 2, + I:s[10] & 4, + D:s[10] & 8, + V:s[10] & 64, + N:s[10] & 128, + o:this.readConst(pc), + } + } + saveState() { + this.exports.machine_save_state(this.sys, this.stateptr); + /* + for (var i=0; i implements Platform { getMemoryMap() { return C64_MEMORY_MAP; } } -class C64WASMPlatform extends Base6502MachinePlatform implements Platform { +class C64WASMPlatform extends Base6502MachinePlatform implements Platform { - newMachine() { return new WASMMachine('c64'); } + newMachine() { return new C64_WASMMachine('c64'); } async start() { // TODO: start() needs to block