apple2js/js/roms/rom.ts

28 lines
716 B
TypeScript
Raw Normal View History

2020-11-24 16:53:43 +00:00
import { PageHandler } from '../cpu6502';
import { byte, memory } from '../types';
export default class ROM implements PageHandler {
2020-11-24 16:53:43 +00:00
constructor(
private readonly startPage: byte,
private readonly endPage: byte,
private readonly rom: memory) {
2020-11-24 16:53:43 +00:00
const expectedLength = (endPage-startPage+1) * 256;
if (rom.length != expectedLength) {
throw Error(`rom does not have the correct length: expected ${expectedLength} was ${rom.length}`);
}
}
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];
}
write() {
}
}