Skip to content

Commit 125eb3c

Browse files
committed
Speed up the tests significantly by not outputting when unecessary, use some variables to only output when PC is at the part we care about
1 parent bc2d256 commit 125eb3c

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

test/test.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ const ram = new TestRam(ramData);
88
const processor = new Processor(ram);
99
processor.setPC(0x0400);
1010

11-
const startTime = Date.now();
12-
let cyclesSinceStart = 0;
13-
let hz = 1000000;
14-
const interval = setInterval(() => {
15-
const secondsElapsed = (Date.now() - startTime) / 1000;
16-
const totalExpectedCycles = secondsElapsed * hz;
17-
while (cyclesSinceStart < totalExpectedCycles) {
18-
const pcBefore = processor.getPC();
19-
cyclesSinceStart += processor.tick(true);
20-
if (processor.getPC() === pcBefore) {
21-
console.log("TRAPPED");
22-
const stack = ramData.subarray(0x100, 0x200);
23-
console.log(stack.toString("hex").match(/../g)?.join(" "));
24-
process.exit();
25-
}
26-
}
27-
}, 1);
11+
//output debug data when the PC is between these values
12+
const traceStart = 0x346f;
13+
const traceEnd = 0x3500;
2814

29-
process.on("beforeExit", () => {});
15+
let cycles = 0;
16+
const start = Date.now();
17+
while (true) {
18+
const pcBefore = processor.getPC();
19+
cycles += processor.tick(pcBefore >= traceStart && pcBefore < traceEnd);
20+
if (processor.getPC() === pcBefore) {
21+
const timeSpent = Date.now() - start;
22+
const equivalentMhz = Math.floor(cycles / (timeSpent / 1000) / 1000) / 1000;
23+
console.log(
24+
`TRAPPED at ${pcBefore.toString(16)} after ${cycles} cycles and ${timeSpent}ms (${equivalentMhz}Mhz)`
25+
);
26+
const stack = ramData.subarray(0x100, 0x200);
27+
console.log(stack.toString("hex").match(/../g)?.join(" "));
28+
process.exit();
29+
}
30+
}

0 commit comments

Comments
 (0)