2019-08-22 02:55:32 +00:00
|
|
|
|
2019-08-23 14:37:30 +00:00
|
|
|
export interface SavesState<S> {
|
2023-11-10 16:38:30 +00:00
|
|
|
saveState(): S;
|
|
|
|
loadState(state: S): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Bus {
|
2023-11-10 16:38:30 +00:00
|
|
|
read(a: number): number;
|
|
|
|
write(a: number, v: number): void;
|
|
|
|
readConst?(a: number): number;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 20:24:42 +00:00
|
|
|
export interface Bus32 {
|
|
|
|
read32(a: number): number;
|
|
|
|
write32(a: number, v: number): void;
|
|
|
|
readConst32?(a: number): number;
|
|
|
|
}
|
|
|
|
|
2019-08-22 02:55:32 +00:00
|
|
|
export interface ClockBased {
|
2023-11-10 16:38:30 +00:00
|
|
|
advanceClock(): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface InstructionBased {
|
2023-11-10 16:38:30 +00:00
|
|
|
advanceInsn(): number;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 20:10:15 +00:00
|
|
|
export type TrapCondition = () => boolean;
|
|
|
|
|
2019-08-22 02:55:32 +00:00
|
|
|
export interface FrameBased {
|
2023-11-10 16:38:30 +00:00
|
|
|
advanceFrame(trap: TrapCondition): number;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 20:10:15 +00:00
|
|
|
export interface VideoSource {
|
2023-11-10 16:38:30 +00:00
|
|
|
getVideoParams(): VideoParams;
|
|
|
|
connectVideo(pixels: Uint32Array): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 20:10:15 +00:00
|
|
|
export interface RasterFrameBased extends FrameBased, VideoSource {
|
2023-11-10 16:38:30 +00:00
|
|
|
getRasterY(): number;
|
|
|
|
getRasterX(): number;
|
|
|
|
getRasterCanvasPosition?(): { x: number, y: number };
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface VideoParams {
|
2023-11-10 16:38:30 +00:00
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
overscan?: boolean;
|
|
|
|
rotate?: number;
|
|
|
|
videoFrequency?: number; // default = 60
|
|
|
|
aspect?: number;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: frame buffer optimization (apple2, etc)
|
|
|
|
|
|
|
|
export interface SampledAudioParams {
|
2023-11-10 16:38:30 +00:00
|
|
|
sampleRate: number;
|
|
|
|
stereo: boolean;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 20:10:15 +00:00
|
|
|
export interface SampledAudioSink {
|
2023-11-10 16:38:30 +00:00
|
|
|
feedSample(value: number, count: number): void;
|
|
|
|
//sendAudioFrame(samples:Uint16Array) : void;
|
2019-08-22 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface SampledAudioSource {
|
2023-11-10 16:38:30 +00:00
|
|
|
getAudioParams(): SampledAudioParams;
|
|
|
|
connectAudio(audio: SampledAudioSink): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface AcceptsROM {
|
2023-11-10 16:38:30 +00:00
|
|
|
loadROM(data: Uint8Array, title?: string): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-18 20:38:39 +00:00
|
|
|
export interface AcceptsBIOS {
|
2023-11-10 16:38:30 +00:00
|
|
|
loadBIOS(data: Uint8Array, title?: string): void;
|
2020-07-18 20:38:39 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 02:55:32 +00:00
|
|
|
export interface Resettable {
|
2023-11-10 16:38:30 +00:00
|
|
|
reset(): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface MemoryBusConnected {
|
2023-11-10 16:38:30 +00:00
|
|
|
connectMemoryBus(bus: Bus): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 02:01:05 +00:00
|
|
|
export interface IOBusConnected {
|
2023-11-10 16:38:30 +00:00
|
|
|
connectIOBus(bus: Bus): void;
|
2019-08-23 02:01:05 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 14:37:30 +00:00
|
|
|
export interface CPU extends MemoryBusConnected, Resettable, SavesState<any> {
|
2023-11-10 16:38:30 +00:00
|
|
|
getPC(): number;
|
|
|
|
getSP(): number;
|
|
|
|
isStable(): boolean;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 19:05:12 +00:00
|
|
|
export interface HasCPU extends Resettable {
|
2023-11-10 16:38:30 +00:00
|
|
|
cpu: CPU;
|
2019-08-23 14:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Interruptable<IT> {
|
2023-11-10 16:38:30 +00:00
|
|
|
interrupt(type: IT): void;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 22:52:59 +00:00
|
|
|
export interface SavesInputState<CS> {
|
2023-11-10 16:38:30 +00:00
|
|
|
loadControlsState(cs: CS): void;
|
|
|
|
saveControlsState(): CS;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 22:52:59 +00:00
|
|
|
export interface AcceptsKeyInput {
|
2023-11-10 16:38:30 +00:00
|
|
|
setKeyInput(key: number, code: number, flags: number): void;
|
2019-08-23 22:52:59 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 16:58:42 +00:00
|
|
|
export interface AcceptsPaddleInput {
|
2023-11-10 16:38:30 +00:00
|
|
|
setPaddleInput(controller: number, value: number): void;
|
2019-08-26 16:58:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-25 02:45:55 +00:00
|
|
|
// TODO: interface not yet used (setKeyInput() handles joystick)
|
|
|
|
export interface AcceptsJoyInput {
|
2023-11-10 16:38:30 +00:00
|
|
|
setJoyInput(joy: number, bitmask: number): void;
|
2021-07-25 02:45:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 19:34:08 +00:00
|
|
|
// SERIAL I/O
|
|
|
|
|
2021-06-14 19:38:51 +00:00
|
|
|
export interface SerialEvent {
|
|
|
|
op: 'read' | 'write';
|
|
|
|
value: number;
|
|
|
|
nbits: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: all these needed?
|
2020-10-17 19:34:08 +00:00
|
|
|
export interface SerialIOInterface {
|
|
|
|
// from machine to platform
|
2023-11-10 16:38:30 +00:00
|
|
|
clearToSend(): boolean;
|
|
|
|
sendByte(b: number);
|
2020-10-17 19:34:08 +00:00
|
|
|
// from platform to machine
|
2023-11-10 16:38:30 +00:00
|
|
|
byteAvailable(): boolean;
|
|
|
|
recvByte(): number;
|
2020-10-17 19:34:08 +00:00
|
|
|
// implement these too
|
2023-11-10 16:38:30 +00:00
|
|
|
reset(): void;
|
|
|
|
advance(clocks: number): void;
|
|
|
|
// refresh() : void;
|
2020-10-17 19:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface HasSerialIO {
|
|
|
|
connectSerialIO(serial: SerialIOInterface);
|
2021-06-14 19:38:51 +00:00
|
|
|
serialOut?: SerialEvent[]; // outgoing event log
|
|
|
|
serialIn?: SerialEvent[]; // incoming queue
|
2020-10-17 19:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// PROFILER
|
|
|
|
|
2019-08-24 02:32:10 +00:00
|
|
|
export interface Probeable {
|
2023-11-10 16:38:30 +00:00
|
|
|
connectProbe(probe: ProbeAll): void;
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
export interface ProbeTime {
|
2023-11-10 16:38:30 +00:00
|
|
|
logClocks(clocks: number);
|
2019-08-24 15:28:04 +00:00
|
|
|
logNewScanline();
|
|
|
|
logNewFrame();
|
|
|
|
}
|
|
|
|
|
2019-08-24 02:32:10 +00:00
|
|
|
export interface ProbeCPU {
|
2023-11-10 16:38:30 +00:00
|
|
|
logExecute(address: number, SP: number);
|
|
|
|
logInterrupt(type: number);
|
|
|
|
logIllegal(address: number);
|
|
|
|
logWait(address: number);
|
2019-08-22 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 02:32:10 +00:00
|
|
|
export interface ProbeBus {
|
2023-11-10 16:38:30 +00:00
|
|
|
logRead(address: number, value: number);
|
|
|
|
logWrite(address: number, value: number);
|
|
|
|
logDMARead(address: number, value: number);
|
|
|
|
logDMAWrite(address: number, value: number);
|
2019-08-22 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 02:32:10 +00:00
|
|
|
export interface ProbeIO {
|
2023-11-10 16:38:30 +00:00
|
|
|
logIORead(address: number, value: number);
|
|
|
|
logIOWrite(address: number, value: number);
|
2019-08-22 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 03:17:07 +00:00
|
|
|
export interface ProbeVRAM {
|
2023-11-10 16:38:30 +00:00
|
|
|
logVRAMRead(address: number, value: number);
|
|
|
|
logVRAMWrite(address: number, value: number);
|
2019-08-27 03:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ProbeAll extends ProbeTime, ProbeCPU, ProbeBus, ProbeIO, ProbeVRAM {
|
2023-11-10 16:38:30 +00:00
|
|
|
logData(data: number); // entire 32 bits
|
2020-07-16 19:47:28 +00:00
|
|
|
addLogBuffer(src: Uint32Array);
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class NullProbe implements ProbeAll {
|
2023-11-10 16:38:30 +00:00
|
|
|
logClocks() { }
|
|
|
|
logNewScanline() { }
|
|
|
|
logNewFrame() { }
|
|
|
|
logExecute() { }
|
|
|
|
logInterrupt() { }
|
|
|
|
logRead() { }
|
|
|
|
logWrite() { }
|
|
|
|
logIORead() { }
|
|
|
|
logIOWrite() { }
|
|
|
|
logVRAMRead() { }
|
|
|
|
logVRAMWrite() { }
|
|
|
|
logIllegal() { }
|
|
|
|
logWait() { }
|
|
|
|
logDMARead() { }
|
|
|
|
logDMAWrite() { }
|
|
|
|
logData() { }
|
|
|
|
addLogBuffer(src: Uint32Array) { }
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 02:32:10 +00:00
|
|
|
/// CONVENIENCE
|
|
|
|
|
|
|
|
export interface BasicMachineControlsState {
|
2019-08-24 15:28:04 +00:00
|
|
|
inputs: Uint8Array;
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
2019-08-22 02:55:32 +00:00
|
|
|
|
2019-08-24 02:32:10 +00:00
|
|
|
export interface BasicMachineState extends BasicMachineControlsState {
|
|
|
|
c: any; // TODO
|
2019-08-24 15:28:04 +00:00
|
|
|
ram: Uint8Array;
|
2019-08-22 02:55:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-08 15:39:54 +00:00
|
|
|
export abstract class BasicHeadlessMachine implements HasCPU, Bus, AcceptsROM, Probeable,
|
2019-08-24 02:32:10 +00:00
|
|
|
SavesState<BasicMachineState>, SavesInputState<BasicMachineControlsState> {
|
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
abstract cpuFrequency: number;
|
|
|
|
abstract defaultROMSize: number;
|
2019-09-08 15:39:54 +00:00
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
abstract cpu: CPU;
|
|
|
|
abstract ram: Uint8Array;
|
2019-09-08 15:39:54 +00:00
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
rom: Uint8Array;
|
|
|
|
inputs: Uint8Array = new Uint8Array(32);
|
|
|
|
handler: (key, code, flags) => void; // keyboard handler
|
2019-08-24 02:32:10 +00:00
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
nullProbe = new NullProbe();
|
2023-11-10 16:38:30 +00:00
|
|
|
probe: ProbeAll = this.nullProbe;
|
2019-08-24 02:32:10 +00:00
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
abstract read(a: number): number;
|
|
|
|
abstract write(a: number, v: number): void;
|
|
|
|
|
|
|
|
setKeyInput(key: number, code: number, flags: number): void {
|
|
|
|
this.handler && this.handler(key, code, flags);
|
2019-08-26 17:44:06 +00:00
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
connectProbe(probe: ProbeAll): void {
|
2019-08-24 15:28:04 +00:00
|
|
|
this.probe = probe || this.nullProbe;
|
|
|
|
}
|
2019-08-24 02:32:10 +00:00
|
|
|
reset() {
|
|
|
|
this.cpu.reset();
|
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
loadROM(data: Uint8Array, title?: string): void {
|
2019-08-24 02:32:10 +00:00
|
|
|
if (!this.rom) this.rom = new Uint8Array(this.defaultROMSize);
|
2023-11-21 21:06:13 +00:00
|
|
|
if (data.length > this.rom.length)
|
|
|
|
throw new Error(`ROM too big: ${data.length} > ${this.rom.length}}`);
|
2019-08-24 02:32:10 +00:00
|
|
|
this.rom.set(data);
|
|
|
|
}
|
|
|
|
loadState(state) {
|
|
|
|
this.cpu.loadState(state.c);
|
2019-08-24 15:28:04 +00:00
|
|
|
this.ram.set(state.ram);
|
|
|
|
this.inputs.set(state.inputs);
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
|
|
|
saveState() {
|
|
|
|
return {
|
2023-11-10 16:38:30 +00:00
|
|
|
c: this.cpu.saveState(),
|
|
|
|
ram: this.ram.slice(0),
|
|
|
|
inputs: this.inputs.slice(0),
|
2019-08-24 02:32:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
loadControlsState(state) {
|
2019-08-24 15:28:04 +00:00
|
|
|
this.inputs.set(state.inputs);
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
|
|
|
saveControlsState() {
|
|
|
|
return {
|
2023-11-10 16:38:30 +00:00
|
|
|
inputs: this.inputs.slice(0)
|
2019-08-24 02:32:10 +00:00
|
|
|
};
|
|
|
|
}
|
2019-08-25 13:25:26 +00:00
|
|
|
advanceCPU() {
|
2019-08-24 02:32:10 +00:00
|
|
|
var c = this.cpu as any;
|
2019-08-24 15:28:04 +00:00
|
|
|
var n = 1;
|
2019-10-16 20:06:56 +00:00
|
|
|
if (this.cpu.isStable()) { this.probe.logExecute(this.cpu.getPC(), this.cpu.getSP()); }
|
2019-08-25 14:45:36 +00:00
|
|
|
if (c.advanceClock) { c.advanceClock(); }
|
|
|
|
else if (c.advanceInsn) { n = c.advanceInsn(1); }
|
2019-08-24 15:28:04 +00:00
|
|
|
this.probe.logClocks(n);
|
|
|
|
return n;
|
|
|
|
}
|
2023-12-27 20:24:42 +00:00
|
|
|
probeMemoryBus(membus: Bus & Partial<Bus32>): Bus & Partial<Bus32> {
|
2019-08-26 23:00:01 +00:00
|
|
|
return {
|
2019-08-24 15:28:04 +00:00
|
|
|
read: (a) => {
|
|
|
|
let val = membus.read(a);
|
2023-11-10 16:38:30 +00:00
|
|
|
this.probe.logRead(a, val);
|
2019-08-24 15:28:04 +00:00
|
|
|
return val;
|
|
|
|
},
|
2023-11-10 16:38:30 +00:00
|
|
|
write: (a, v) => {
|
|
|
|
this.probe.logWrite(a, v);
|
|
|
|
membus.write(a, v);
|
2023-12-27 20:24:42 +00:00
|
|
|
},
|
|
|
|
read32: (a) => {
|
|
|
|
let val = membus.read32(a);
|
|
|
|
this.probe.logRead(a, val);
|
|
|
|
return val;
|
|
|
|
},
|
|
|
|
write32: (a, v) => {
|
|
|
|
this.probe.logWrite(a, v);
|
|
|
|
membus.write32(a, v);
|
2019-08-24 15:28:04 +00:00
|
|
|
}
|
2019-08-26 23:00:01 +00:00
|
|
|
};
|
2019-08-24 15:28:04 +00:00
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
connectCPUMemoryBus(membus: Bus): void {
|
2023-12-27 20:24:42 +00:00
|
|
|
this.cpu.connectMemoryBus(this.probeMemoryBus(membus as Bus&Bus32));
|
2019-08-26 23:00:01 +00:00
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
probeIOBus(iobus: Bus): Bus {
|
2019-08-26 23:00:01 +00:00
|
|
|
return {
|
2019-08-24 15:28:04 +00:00
|
|
|
read: (a) => {
|
|
|
|
let val = iobus.read(a);
|
2023-11-10 16:38:30 +00:00
|
|
|
this.probe.logIORead(a, val);
|
2019-08-24 15:28:04 +00:00
|
|
|
return val;
|
|
|
|
},
|
2023-11-10 16:38:30 +00:00
|
|
|
write: (a, v) => {
|
|
|
|
this.probe.logIOWrite(a, v);
|
|
|
|
iobus.write(a, v);
|
2023-12-27 20:24:42 +00:00
|
|
|
},
|
2019-08-26 23:00:01 +00:00
|
|
|
};
|
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
probeDMABus(iobus: Bus): Bus {
|
2022-09-03 20:00:43 +00:00
|
|
|
return {
|
|
|
|
read: (a) => {
|
|
|
|
let val = iobus.read(a);
|
2023-11-10 16:38:30 +00:00
|
|
|
this.probe.logDMARead(a, val);
|
2022-09-03 20:00:43 +00:00
|
|
|
return val;
|
|
|
|
},
|
2023-11-10 16:38:30 +00:00
|
|
|
write: (a, v) => {
|
|
|
|
this.probe.logDMAWrite(a, v);
|
|
|
|
iobus.write(a, v);
|
2022-09-03 20:00:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
connectCPUIOBus(iobus: Bus): void {
|
2019-08-26 23:00:01 +00:00
|
|
|
this.cpu['connectIOBus'](this.probeIOBus(iobus));
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 15:39:54 +00:00
|
|
|
export abstract class BasicMachine extends BasicHeadlessMachine implements SampledAudioSource {
|
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
abstract canvasWidth: number;
|
|
|
|
abstract numVisibleScanlines: number;
|
|
|
|
abstract sampleRate: number;
|
|
|
|
overscan: boolean = false;
|
|
|
|
rotate: number = 0;
|
|
|
|
aspectRatio: number;
|
|
|
|
|
|
|
|
pixels: Uint32Array;
|
|
|
|
audio: SampledAudioSink;
|
|
|
|
|
|
|
|
scanline: number;
|
|
|
|
|
|
|
|
getAudioParams(): SampledAudioParams {
|
|
|
|
return { sampleRate: this.sampleRate, stereo: false };
|
2019-09-08 15:39:54 +00:00
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
connectAudio(audio: SampledAudioSink): void {
|
2019-09-08 15:39:54 +00:00
|
|
|
this.audio = audio;
|
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
getVideoParams(): VideoParams {
|
|
|
|
return {
|
|
|
|
width: this.canvasWidth,
|
|
|
|
height: this.numVisibleScanlines,
|
|
|
|
aspect: this.aspectRatio,
|
|
|
|
overscan: this.overscan,
|
|
|
|
rotate: this.rotate
|
|
|
|
};
|
2019-09-08 15:39:54 +00:00
|
|
|
}
|
2023-11-10 16:38:30 +00:00
|
|
|
connectVideo(pixels: Uint32Array): void {
|
2019-09-08 15:39:54 +00:00
|
|
|
this.pixels = pixels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 02:32:10 +00:00
|
|
|
export abstract class BasicScanlineMachine extends BasicMachine implements RasterFrameBased {
|
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
abstract numTotalScanlines: number;
|
|
|
|
abstract cpuCyclesPerLine: number;
|
|
|
|
|
|
|
|
abstract startScanline(): void;
|
|
|
|
abstract drawScanline(): void;
|
2019-08-24 02:32:10 +00:00
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
frameCycles: number;
|
2019-09-08 15:39:54 +00:00
|
|
|
|
2023-11-10 16:38:30 +00:00
|
|
|
advanceFrame(trap: TrapCondition): number {
|
2019-08-25 13:25:26 +00:00
|
|
|
this.preFrame();
|
2019-08-24 02:32:10 +00:00
|
|
|
var endLineClock = 0;
|
2020-07-04 14:16:45 +00:00
|
|
|
var steps = 0;
|
2019-08-24 15:28:04 +00:00
|
|
|
this.probe.logNewFrame();
|
2020-07-24 02:52:53 +00:00
|
|
|
this.frameCycles = 0;
|
2023-11-10 16:38:30 +00:00
|
|
|
for (var sl = 0; sl < this.numTotalScanlines; sl++) {
|
2020-07-11 17:26:37 +00:00
|
|
|
endLineClock += this.cpuCyclesPerLine; // could be fractional
|
2019-08-24 02:32:10 +00:00
|
|
|
this.scanline = sl;
|
|
|
|
this.startScanline();
|
2020-07-24 02:52:53 +00:00
|
|
|
while (this.frameCycles < endLineClock) {
|
2019-08-24 02:32:10 +00:00
|
|
|
if (trap && trap()) {
|
|
|
|
sl = 999;
|
|
|
|
break;
|
|
|
|
}
|
2020-07-24 02:52:53 +00:00
|
|
|
this.frameCycles += this.advanceCPU();
|
2020-07-04 14:16:45 +00:00
|
|
|
steps++;
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
|
|
|
this.drawScanline();
|
2019-08-24 15:28:04 +00:00
|
|
|
this.probe.logNewScanline();
|
2020-07-24 02:52:53 +00:00
|
|
|
this.probe.logClocks(Math.floor(this.frameCycles - endLineClock)); // remainder of prev. line
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
2019-08-25 13:25:26 +00:00
|
|
|
this.postFrame();
|
2020-07-04 14:16:45 +00:00
|
|
|
return steps; // TODO: return steps, not clock? for recorder
|
2019-08-24 02:32:10 +00:00
|
|
|
}
|
2019-08-25 13:25:26 +00:00
|
|
|
preFrame() { }
|
|
|
|
postFrame() { }
|
2019-08-24 02:32:10 +00:00
|
|
|
getRasterY() { return this.scanline; }
|
|
|
|
getRasterX() { return this.frameCycles % this.cpuCyclesPerLine; }
|
|
|
|
}
|