mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
4a188a9a5c
First pass at a Preact UI, still short some major features but full proof of concept.
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;
|
|
}
|
|
}
|
|
|