No hanging promises, remove window.e

This commit is contained in:
Will Scullin 2021-06-05 16:57:31 -07:00
parent ca2f609279
commit cfe20ad56a
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
9 changed files with 88 additions and 79 deletions

View File

@ -25,6 +25,7 @@
"always"
],
"no-use-before-define": "off",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-use-before-define": [
"error",
{
@ -59,7 +60,8 @@
"es6": true
},
"parserOptions": {
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"extends": "eslint:recommended",
"overrides": [
@ -109,5 +111,6 @@
"commonjs": true
}
}
]
],
"ignorePatterns": ["coverage/**/*"]
}

View File

@ -50,8 +50,6 @@ interface State {
ram?: RAMState[],
}
type ROMConstructor = { new(): ROM ;}
export class Apple2 implements Restorable<State>, DebuggerContainer {
private paused = false;
@ -80,56 +78,59 @@ export class Apple2 implements Restorable<State>, DebuggerContainer {
renderedFrames: 0
};
public ready: Promise<[{ default: ROMConstructor }, { default: rom }, void]>;
public ready: Promise<void>
constructor(options: Apple2Options) {
this.ready = this.init(options);
}
async init(options: Apple2Options) {
const romImportPromise = import(`./roms/system/${options.rom}`);
const characterRomImportPromise = import(`./roms/character/${options.characterRom}`);
const LoresPage = options.gl ? LoresPageGL : LoresPage2D;
const HiresPage = options.gl ? HiresPageGL : HiresPage2D;
const VideoModes = options.gl ? VideoModesGL : VideoModes2D;
const romImportPromise = import(`./roms/system/${options.rom}`);
const characterRomImportPromise = import(`./roms/character/${options.characterRom}`);
this.cpu = new CPU6502({ '65C02': options.enhanced });
this.vm = new VideoModes(options.canvas, options.e);
this.ready = Promise.all([
const [{ default: Apple2ROM }, { default: characterRom }] = await Promise.all([
romImportPromise,
characterRomImportPromise,
this.vm.ready,
]);
this.ready.then(([{ default: Apple2ROM }, { default: characterRom }]) => {
this.rom = new Apple2ROM();
this.characterRom = characterRom;
this.rom = new Apple2ROM();
this.characterRom = characterRom;
this.gr = new LoresPage(this.vm, 1, this.characterRom, options.e);
this.gr2 = new LoresPage(this.vm, 2, this.characterRom, options.e);
this.hgr = new HiresPage(this.vm, 1);
this.hgr2 = new HiresPage(this.vm, 2);
this.io = new Apple2IO(this.cpu, this.vm);
this.tick = options.tick;
this.gr = new LoresPage(this.vm, 1, this.characterRom, options.e);
this.gr2 = new LoresPage(this.vm, 2, this.characterRom, options.e);
this.hgr = new HiresPage(this.vm, 1);
this.hgr2 = new HiresPage(this.vm, 2);
this.io = new Apple2IO(this.cpu, this.vm);
this.tick = options.tick;
if (options.e) {
this.mmu = new MMU(this.cpu, this.vm, this.gr, this.gr2, this.hgr, this.hgr2, this.io, this.rom);
this.cpu.addPageHandler(this.mmu);
} else {
this.ram = [
new RAM(0x00, 0x03),
new RAM(0x0C, 0x1F),
new RAM(0x60, 0xBF)
];
if (options.e) {
this.mmu = new MMU(this.cpu, this.vm, this.gr, this.gr2, this.hgr, this.hgr2, this.io, this.rom);
this.cpu.addPageHandler(this.mmu);
} else {
this.ram = [
new RAM(0x00, 0x03),
new RAM(0x0C, 0x1F),
new RAM(0x60, 0xBF)
];
this.cpu.addPageHandler(this.ram[0]);
this.cpu.addPageHandler(this.gr);
this.cpu.addPageHandler(this.gr2);
this.cpu.addPageHandler(this.ram[1]);
this.cpu.addPageHandler(this.hgr);
this.cpu.addPageHandler(this.hgr2);
this.cpu.addPageHandler(this.ram[2]);
this.cpu.addPageHandler(this.io);
this.cpu.addPageHandler(this.rom);
}
});
this.cpu.addPageHandler(this.ram[0]);
this.cpu.addPageHandler(this.gr);
this.cpu.addPageHandler(this.gr2);
this.cpu.addPageHandler(this.ram[1]);
this.cpu.addPageHandler(this.hgr);
this.cpu.addPageHandler(this.hgr2);
this.cpu.addPageHandler(this.ram[2]);
this.cpu.addPageHandler(this.io);
this.cpu.addPageHandler(this.rom);
}
}
/**

View File

@ -1,6 +1,4 @@
import { apple2 } from './main2e';
import * as UI from './ui/apple2';
window.e = true;
export const Apple2 = { ...UI, apple2 };

View File

@ -86,4 +86,4 @@ apple2.ready.then(() => {
cpu.addPageHandler(lc);
initUI(apple2, disk2, smartport, printer, false);
});
}).catch(console.error);

View File

@ -63,4 +63,4 @@ apple2.ready.then(() => {
io.setSlot(7, smartport);
initUI(apple2, disk2, smartport, printer, options.e);
});
}).catch(console.error);

View File

@ -80,6 +80,7 @@ let system: System;
let keyboard: KeyBoard;
let io: Apple2IO;
let _currentDrive: DriveNumber = 1;
let _e: boolean;
export const driveLights = new DriveLights();
@ -214,7 +215,7 @@ function loadingStop() {
if (!paused) {
_apple2.ready.then(() => {
_apple2.run();
});
}).catch(console.error);
}
}
@ -686,38 +687,40 @@ declare global {
}
}
let oldCat = '';
let option;
for (let idx = 0; idx < window.disk_index.length; idx++) {
const file = window.disk_index[idx];
const cat = file.category;
const name = file.name;
const disk = file.disk;
if (file.e && !window.e) {
continue;
}
if (cat != oldCat) {
option = document.createElement('option');
option.value = cat;
option.innerText = cat;
categorySelect.append(option);
disk_categories[cat] = [];
oldCat = cat;
}
disk_categories[cat].push(file);
if (disk) {
if (!disk_sets[name]) {
disk_sets[name] = [];
function buildDiskIndex() {
let oldCat = '';
let option;
for (let idx = 0; idx < window.disk_index.length; idx++) {
const file = window.disk_index[idx];
const cat = file.category;
const name = file.name;
const disk = file.disk;
if (file.e && !_e) {
continue;
}
disk_sets[name].push(file);
}
}
option = document.createElement('option');
option.innerText = 'Local Saves';
categorySelect.append(option);
if (cat != oldCat) {
option = document.createElement('option');
option.value = cat;
option.innerText = cat;
categorySelect.append(option);
updateLocalStorage();
disk_categories[cat] = [];
oldCat = cat;
}
disk_categories[cat].push(file);
if (disk) {
if (!disk_sets[name]) {
disk_sets[name] = [];
}
disk_sets[name].push(file);
}
}
option = document.createElement('option');
option.innerText = 'Local Saves';
categorySelect.append(option);
updateLocalStorage();
}
/**
* Processes the URL fragment. It is expected to be of the form:
@ -756,12 +759,12 @@ export function updateUI() {
}
}
export function pauseRun() {
export async function pauseRun() {
const label = document.querySelector<HTMLElement>('#pause-run i')!;
if (paused) {
_apple2.ready.then(() => {
_apple2.run();
});
}).catch(console.error);
label.classList.remove('fa-play');
label.classList.add('fa-pause');
} else {
@ -813,6 +816,7 @@ function onLoaded(apple2: Apple2, disk2: DiskII, smartPort: SmartPort, printer:
_disk2 = disk2;
_smartPort = smartPort;
_printer = printer;
_e = e;
system = new System(io, e);
optionsModal.addOptions(system);
@ -843,6 +847,8 @@ function onLoaded(apple2: Apple2, disk2: DiskII, smartPort: SmartPort, printer:
}
});
buildDiskIndex();
/*
* Input Handling
*/
@ -875,7 +881,7 @@ function onLoaded(apple2: Apple2, disk2: DiskII, smartPort: SmartPort, printer:
} else {
_apple2.ready.then(() => {
_apple2.run();
});
}).catch(console.error);
}
document.querySelector<HTMLInputElement>('#local_file')?.addEventListener(

View File

@ -89,7 +89,7 @@ export class Audio implements OptionHandler {
autoStart = () => {
if (this.audioContext && !this.started) {
this.samples = [];
this.audioContext.resume();
void this.audioContext.resume();
this.started = true;
}
}
@ -97,7 +97,7 @@ export class Audio implements OptionHandler {
start = () => {
if (this.audioContext) {
this.samples = [];
this.audioContext.resume();
void this.audioContext.resume();
}
}

View File

@ -36,7 +36,7 @@ export default class Tape {
fileReader.onload = (ev: ProgressEvent) => {
const target: FileReader = ev.target as FileReader;
const result: ArrayBuffer = target.result as ArrayBuffer;
context.decodeAudioData(result, (buffer) => {
context.decodeAudioData(result).then((buffer) => {
const buf: TapeData = [];
const data = buffer.getChannelData(0);
let datum = data[0];

View File

@ -30,5 +30,6 @@
"include": [
"js/**/*",
"test/**/*",
"*.config.js"
]
}