2021-03-06 23:04:13 +00:00
|
|
|
import { MemoryPages, Restorable, byte, rom } from '../types';
|
2020-11-24 16:48:14 +00:00
|
|
|
|
2021-02-28 03:17:36 +00:00
|
|
|
export type ROMState = null;
|
|
|
|
|
2021-03-06 23:04:13 +00:00
|
|
|
export default class ROM implements MemoryPages, Restorable<ROMState> {
|
2020-11-24 16:48:14 +00:00
|
|
|
|
2020-11-24 16:53:43 +00:00
|
|
|
constructor(
|
2022-05-31 15:38:40 +00:00
|
|
|
private readonly startPage: byte,
|
|
|
|
private readonly endPage: byte,
|
|
|
|
private readonly rom: rom) {
|
|
|
|
const expectedLength = (endPage - startPage + 1) * 256;
|
2022-05-18 15:19:45 +00:00
|
|
|
if (rom.length !== expectedLength) {
|
2020-11-24 16:53:43 +00:00
|
|
|
throw Error(`rom does not have the correct length: expected ${expectedLength} was ${rom.length}`);
|
|
|
|
}
|
2020-11-24 16:48:14 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 16:53:43 +00:00
|
|
|
start() {
|
|
|
|
return this.startPage;
|
|
|
|
}
|
|
|
|
end() {
|
|
|
|
return this.endPage;
|
|
|
|
}
|
|
|
|
read(page: byte, off: byte) {
|
|
|
|
return this.rom[(page - this.startPage) << 8 | off];
|
|
|
|
}
|
2021-02-28 03:17:36 +00:00
|
|
|
write() {
|
2022-05-31 15:38:40 +00:00
|
|
|
// not writable
|
2021-02-28 03:17:36 +00:00
|
|
|
}
|
|
|
|
getState() {
|
|
|
|
return null;
|
|
|
|
}
|
2022-05-31 15:38:40 +00:00
|
|
|
setState(_state: ROMState) {
|
|
|
|
// not restorable
|
2020-11-24 16:53:43 +00:00
|
|
|
}
|
2020-11-24 16:48:14 +00:00
|
|
|
}
|