mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
badc2fdb74
A test data set was published at https://github.com/TomHarte/ProcessorTests which contain cycle traces of instructions for various versions of the 6502. This adds a test harness that reads those data files, and adjusts the CPU6502 behavior to match the behavior of the vanilla and WDC 65C02 test data. Also converts the existing CPU tests to Typescript, and fixes any inconsistencies that came up from the new behaviors.
62 lines
1.2 KiB
TypeScript
62 lines
1.2 KiB
TypeScript
import { MemoryPages, byte, word } from 'js/types';
|
|
import { assertByte } from './asserts';
|
|
|
|
export type Log = [address: word, value: byte, types: 'read'|'write']
|
|
export class TestMemory implements MemoryPages {
|
|
private data: Buffer;
|
|
private logging: boolean = false;
|
|
private log: Log[] = [];
|
|
|
|
constructor(private size: number) {
|
|
this.data = Buffer.alloc(size << 8);
|
|
}
|
|
|
|
start() {
|
|
return 0;
|
|
}
|
|
|
|
end() {
|
|
return this.size - 1;
|
|
}
|
|
|
|
read(page: byte, off: byte) {
|
|
assertByte(page);
|
|
assertByte(off);
|
|
|
|
const val = this.data[(page << 8) | off];
|
|
if (this.logging) {
|
|
this.log.push([page << 8 | off, val, 'read']);
|
|
}
|
|
return val;
|
|
}
|
|
|
|
write(page: byte, off: byte, val: byte) {
|
|
assertByte(page);
|
|
assertByte(off);
|
|
assertByte(val);
|
|
|
|
if (this.logging) {
|
|
this.log.push([page << 8 | off, val, 'write']);
|
|
}
|
|
this.data[(page << 8) | off] = val;
|
|
}
|
|
|
|
reset() {
|
|
this.log = [];
|
|
}
|
|
|
|
logStart() {
|
|
this.log = [];
|
|
this.logging = true;
|
|
}
|
|
|
|
logStop() {
|
|
this.logging = false;
|
|
}
|
|
|
|
getLog() {
|
|
return this.log;
|
|
}
|
|
}
|
|
|