apple2js/js/roms/rom.ts
Ian Flanigan 04ae0327c2
Add the recommended eslint plugins for TypeScript (#121)
This adds both the recommended TypeScript checks, plus the recommended
TypeScript checks that require type checking.  This latter addition
means that eslint essentially has to compile all of the TypeScript in
the project, causing it to be slower. This isn't much of a problem in
VS Code because there's a lot of caching being done, but it's clearly
slower when run on the commandline.

All of the errors are either fixed or suppressed.  Some errors are
suppressed because fixing them would be too laborious for the little
value gained.

The eslint config is also slightly refactored to separate the strictly
TypeScript checks from the JavaScript checks.
2022-05-31 08:38:40 -07:00

36 lines
894 B
TypeScript

import { MemoryPages, Restorable, byte, rom } from '../types';
export type ROMState = null;
export default class ROM implements MemoryPages, Restorable<ROMState> {
constructor(
private readonly startPage: byte,
private readonly endPage: byte,
private readonly rom: rom) {
const expectedLength = (endPage - startPage + 1) * 256;
if (rom.length !== expectedLength) {
throw Error(`rom does not have the correct length: expected ${expectedLength} was ${rom.length}`);
}
}
start() {
return this.startPage;
}
end() {
return this.endPage;
}
read(page: byte, off: byte) {
return this.rom[(page - this.startPage) << 8 | off];
}
write() {
// not writable
}
getState() {
return null;
}
setState(_state: ROMState) {
// not restorable
}
}