apple2js/js/main2e.ts
Will Scullin 8087294456
Lazy load ROMs (#81)
* Switch modules to `esnext` to allow `webpack` to see import statements
* Pass rom names into Apple2 class
* Move ROMs into `system` and `character` directories to allow webpack bundle appropriate ROMs.
* Wait for ROMs to load before completing initialization.
2021-06-13 17:06:16 -07:00

67 lines
1.7 KiB
TypeScript

import Prefs from './prefs';
import { driveLights, initUI, updateUI } from './ui/apple2';
import Printer from './ui/printer';
import DiskII from './cards/disk2';
import Parallel from './cards/parallel';
import RAMFactor from './cards/ramfactor';
import SmartPort from './cards/smartport';
import Thunderclock from './cards/thunderclock';
import { Apple2 } from './apple2';
const prefs = new Prefs();
const romVersion = prefs.readPref('computer_type2e');
let enhanced = false;
let rom: string;
let characterRom: string;
switch (romVersion) {
case 'apple2e':
rom = 'apple2e';
characterRom = 'apple2e_char';
break;
case 'apple2rm':
rom = 'apple2e';
characterRom = 'rmfont_char';
enhanced = true;
break;
default:
rom = 'apple2enh';
characterRom = 'apple2enh_char';
enhanced = true;
}
const options = {
gl: prefs.readPref('gl_canvas', 'true') === 'true',
canvas: document.querySelector<HTMLCanvasElement>('#screen')!,
rom,
characterRom,
e: true,
enhanced,
tick: updateUI
};
export const apple2 = new Apple2(options);
apple2.ready.then(() => {
const io = apple2.getIO();
const cpu = apple2.getCPU();
const printer = new Printer('#printer-modal .paper');
const parallel = new Parallel(printer);
const slinky = new RAMFactor(1024 * 1024);
const disk2 = new DiskII(io, driveLights);
const clock = new Thunderclock();
const smartport = new SmartPort(cpu, { block: !enhanced });
io.setSlot(1, parallel);
io.setSlot(2, slinky);
io.setSlot(5, clock);
io.setSlot(6, disk2);
io.setSlot(7, smartport);
initUI(apple2, disk2, smartport, printer, options.e);
}).catch(console.error);