1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2025-02-03 22:31:42 +00:00

probe recorder test, fixes

This commit is contained in:
Steven Hugg 2020-07-11 12:26:37 -05:00
parent df4b35ed6a
commit 842f256931
4 changed files with 55 additions and 17 deletions

View File

@ -1109,7 +1109,7 @@ export abstract class BaseMachinePlatform<T extends Machine> extends BaseDebugPl
// so probe views stick around
runToVsync() {
if (this.probeRecorder) {
this.probeRecorder.reset();
this.probeRecorder.clear();
this.probeRecorder.singleFrame = false;
}
super.runToVsync();

View File

@ -311,7 +311,7 @@ export abstract class BasicScanlineMachine extends BasicMachine implements Raste
var steps = 0;
this.probe.logNewFrame();
for (var sl=0; sl<this.numTotalScanlines; sl++) {
endLineClock += this.cpuCyclesPerLine;
endLineClock += this.cpuCyclesPerLine; // could be fractional
this.scanline = sl;
this.frameCycles = clock;
this.startScanline();
@ -325,7 +325,7 @@ export abstract class BasicScanlineMachine extends BasicMachine implements Raste
}
this.drawScanline();
this.probe.logNewScanline();
this.probe.logClocks(clock-endLineClock);
this.probe.logClocks(Math.floor(clock-endLineClock)); //remainder
}
this.postFrame();
return steps; // TODO: return steps, not clock? for recorder

View File

@ -32,6 +32,7 @@ export class StateRecorderImpl implements EmuRecorder {
this.frameCount = 0;
this.lastSeekFrame = 0;
this.lastSeekStep = 0;
this.lastStepCount = 0;
if (this.callbackStateChanged) this.callbackStateChanged();
}
@ -165,16 +166,17 @@ class ProbeFrame {
export class ProbeRecorder implements ProbeAll {
buf = new Uint32Array(0x100000);
idx = 0;
fclk = 0;
sl = 0;
cur_sp = -1;
m : Probeable;
singleFrame : boolean = true;
m : Probeable; // machine to probe
buf : Uint32Array; // buffer
idx : number = 0; // index into buffer
fclk : number = 0; // clock cycle
sl : number = 0; // scanline
cur_sp = -1; // last stack pointer
singleFrame : boolean = true; // clear between frames
constructor(m:Probeable) {
constructor(m:Probeable, buflen?:number) {
this.m = m;
this.reset(buflen || 0x100000);
}
start() {
this.m.connectProbe(this);
@ -182,7 +184,14 @@ export class ProbeRecorder implements ProbeAll {
stop() {
this.m.connectProbe(null);
}
reset() {
reset(newbuflen? : number) {
if (newbuflen) this.buf = new Uint32Array(newbuflen);
this.sl = 0;
this.fclk = 0;
this.cur_sp = -1;
this.clear();
}
clear() {
this.idx = 0;
}
log(a:number) {
@ -206,6 +215,7 @@ export class ProbeRecorder implements ProbeAll {
return -1;
}
logClocks(clocks:number) {
clocks |= 0;
if (clocks > 0) {
this.fclk += clocks;
if (this.lastOp() == ProbeFlags.CLOCKS)
@ -221,7 +231,7 @@ export class ProbeRecorder implements ProbeAll {
logNewFrame() {
this.log(ProbeFlags.FRAME);
this.sl = 0;
if (this.singleFrame) this.reset();
if (this.singleFrame) this.clear();
}
logExecute(address:number, SP:number) {
// record stack pushes/pops (from last instruction)
@ -263,8 +273,21 @@ export class ProbeRecorder implements ProbeAll {
logIllegal(address:number) {
this.log(address | ProbeFlags.ILLEGAL);
}
countEvents(op : number) : number {
var count = 0;
for (var i=0; i<this.idx; i++) {
if ((this.buf[i] & 0xff000000) == op)
count++;
}
return count;
}
countClocks() : number {
var count = 0;
for (var i=0; i<this.idx; i++) {
if ((this.buf[i] & 0xff000000) == ProbeFlags.CLOCKS)
count += this.buf[i] & 0xffff;
}
return count;
}
}
// TODO: handle runToVsync() without erasing entire frame

View File

@ -140,7 +140,6 @@ async function testPlatform(platid, romname, maxframes, callback) {
platform.reset(); // reset again
var state0b = platform.saveState();
//TODO: vcs fails assert.deepEqual(state0a, state0b);
//if (platform.startProbing) platform.startProbing();
platform.resume(); // so that recorder works
platform.setRecorder(rec);
for (var i=0; i<maxframes; i++) {
@ -178,6 +177,7 @@ async function testPlatform(platid, romname, maxframes, callback) {
assert.ok(dinfo.indexOf('undefined') < 0, dcat + " undefined");
assert.ok(dinfo.indexOf('Display On: false') < 0, dcat + " display off");
}
// record video to file
if (lastrastervideo) {
var png = new PNG({width:lastrastervideo.width, height:lastrastervideo.height});
png.data = lastrastervideo.getImageData().data;
@ -189,9 +189,24 @@ async function testPlatform(platid, romname, maxframes, callback) {
fs.writeFileSync("./test/output/"+platid+"-"+romname+".png", pngbuffer);
} catch (e) { console.log(e) }
}
// probe
var proberec = platform.startProbing && platform.startProbing();
if (proberec) {
proberec.reset(0x100000);
proberec.singleFrame = false;
var lastclk = 0;
for (var i=0; i<5; i++) {
platform.nextFrame(true);
console.log(proberec.idx, proberec.fclk - lastclk, proberec.sl);
lastclk = proberec.fclk;
}
assert.equal(proberec.fclk, proberec.countClocks());
}
// misc
assert.ok(platform.getDefaultExtension().startsWith('.'));
if (platform.getROMExtension) assert.ok(platform.getROMExtension().startsWith("."));
// load state again
platform.loadState(state3);
return platform;
}