mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
worker type cleanup
This commit is contained in:
parent
d050e637d1
commit
f1ed363621
|
@ -110,6 +110,14 @@
|
|||
"env": {
|
||||
"commonjs": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"workers/*"
|
||||
],
|
||||
"parserOptions": {
|
||||
"project": "workers/tsconfig.json"
|
||||
}
|
||||
}
|
||||
],
|
||||
"ignorePatterns": ["coverage/**/*"]
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
|
||||
import type { bit, byte, memory, MemberOf } from '../types';
|
||||
import type { GamepadConfiguration } from '../ui/gamepad';
|
||||
import type { GamepadConfiguration } from '../ui/types';
|
||||
|
||||
export const DRIVE_NUMBERS = [1, 2] as const;
|
||||
export type DriveNumber = MemberOf<typeof DRIVE_NUMBERS>;
|
||||
|
|
|
@ -11,14 +11,15 @@ import {
|
|||
DRIVE_NUMBERS,
|
||||
JSONDisk
|
||||
} from '../formats/types';
|
||||
import { initGamepad, GamepadConfiguration } from './gamepad';
|
||||
import { initGamepad } from './gamepad';
|
||||
import KeyBoard from './keyboard';
|
||||
import Tape, { TAPE_TYPES } from './tape';
|
||||
import type { GamepadConfiguration } from './types';
|
||||
|
||||
import ApplesoftDump from '../applesoft/decompiler';
|
||||
import ApplesoftCompiler from '../applesoft/compiler';
|
||||
|
||||
import { debug, gup, hup } from '../util';
|
||||
import { debug } from '../util';
|
||||
import { Apple2, Stats } from '../apple2';
|
||||
import DiskII from '../cards/disk2';
|
||||
import CPU6502 from '../cpu6502';
|
||||
|
@ -828,6 +829,28 @@ declare global {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a query parameter or the empty string if it does not
|
||||
* exist.
|
||||
* @param name the parameter name. Note that `name` must not have any RegExp
|
||||
* meta-characters except '[' and ']' or it will fail.
|
||||
*/
|
||||
|
||||
function gup(name: string) {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
return params.get(name);
|
||||
}
|
||||
|
||||
/** Returns the URL fragment. */
|
||||
function hup() {
|
||||
const regex = new RegExp('#(.*)');
|
||||
const results = regex.exec(window.location.hash);
|
||||
if (!results)
|
||||
return '';
|
||||
else
|
||||
return results[1];
|
||||
}
|
||||
|
||||
function onLoaded(apple2: Apple2, disk2: DiskII, massStorage: MassStorage, printer: Printer, e: boolean) {
|
||||
_apple2 = apple2;
|
||||
cpu = _apple2.getCPU();
|
||||
|
|
|
@ -10,50 +10,10 @@
|
|||
*/
|
||||
|
||||
import Apple2IO from '../apple2io';
|
||||
import { KnownKeys } from '../types';
|
||||
import { BUTTON, ButtonType, GamepadConfiguration } from './types';
|
||||
|
||||
export let gamepad: Gamepad | null = null;
|
||||
|
||||
const BUTTON = {
|
||||
// Buttons
|
||||
'A': 0,
|
||||
'B': 1,
|
||||
'X': 2,
|
||||
'Y': 3,
|
||||
|
||||
// Triggers
|
||||
'L1': 4,
|
||||
'R1': 5,
|
||||
|
||||
// Analog stick buttons
|
||||
'L3': 6,
|
||||
'R3': 7,
|
||||
|
||||
// Special
|
||||
'START': 8,
|
||||
'SELECT': 9,
|
||||
'LOGO': 10,
|
||||
|
||||
// D pad
|
||||
'UP': 11,
|
||||
'DOWN': 12,
|
||||
'LEFT': 13,
|
||||
'RIGHT': 14
|
||||
} as const;
|
||||
|
||||
type ButtonType = KnownKeys<typeof BUTTON>;
|
||||
|
||||
/**
|
||||
* A `GamepadConfiguration` maps buttons on the controller to Apple Paddle
|
||||
* buttons or keys on the keyboard. If the value is a number, it must be
|
||||
* 0 | 1 | 2 and will map to the corresponding paddle button. If the value
|
||||
* is a string, the _first_ character of the string is used as a key to
|
||||
* press on the keyboard.
|
||||
*/
|
||||
export type GamepadConfiguration = {
|
||||
[K in ButtonType]?: 0 | 1 | 2 | string;
|
||||
};
|
||||
|
||||
const DEFAULT_GAMEPAD: GamepadConfiguration = {
|
||||
'A': 0,
|
||||
'B': 1,
|
||||
|
@ -64,7 +24,7 @@ const DEFAULT_GAMEPAD: GamepadConfiguration = {
|
|||
|
||||
/**
|
||||
* An array with 16 entries. For each entry _e_:
|
||||
*
|
||||
*
|
||||
* * if _e_ <= 0, then _-e_ is 0 | 1 | 2 and represents a joystick button;
|
||||
* * if _e_ > 0, then _e_ is a key on the keyboard that is pressed;
|
||||
* * if _e_ is undefined, nothing happens.
|
||||
|
|
52
js/ui/types.ts
Normal file
52
js/ui/types.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* Copyright 2010-2021 Will Scullin <scullin@scullinsteel.com>
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation. No representations are made about the suitability of this
|
||||
* software for any purpose. It is provided "as is" without express or
|
||||
* implied warranty.
|
||||
*/
|
||||
|
||||
import type { KnownKeys } from '../types';
|
||||
|
||||
export const BUTTON = {
|
||||
// Buttons
|
||||
'A': 0,
|
||||
'B': 1,
|
||||
'X': 2,
|
||||
'Y': 3,
|
||||
|
||||
// Triggers
|
||||
'L1': 4,
|
||||
'R1': 5,
|
||||
|
||||
// Analog stick buttons
|
||||
'L3': 6,
|
||||
'R3': 7,
|
||||
|
||||
// Special
|
||||
'START': 8,
|
||||
'SELECT': 9,
|
||||
'LOGO': 10,
|
||||
|
||||
// D pad
|
||||
'UP': 11,
|
||||
'DOWN': 12,
|
||||
'LEFT': 13,
|
||||
'RIGHT': 14
|
||||
} as const;
|
||||
|
||||
export type ButtonType = KnownKeys<typeof BUTTON>;
|
||||
|
||||
/**
|
||||
* A `GamepadConfiguration` maps buttons on the controller to Apple Paddle
|
||||
* buttons or keys on the keyboard. If the value is a number, it must be
|
||||
* 0 | 1 | 2 and will map to the corresponding paddle button. If the value
|
||||
* is a string, the _first_ character of the string is used as a key to
|
||||
* press on the keyboard.
|
||||
*/
|
||||
export type GamepadConfiguration = {
|
||||
[K in ButtonType]?: 0 | 1 | 2 | string;
|
||||
};
|
21
js/util.ts
21
js/util.ts
|
@ -91,27 +91,6 @@ export function toBinary(v: byte) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a query parameter or the empty string if it does not
|
||||
* exist.
|
||||
* @param name the parameter name. Note that `name` must not have any RegExp
|
||||
* meta-characters except '[' and ']' or it will fail.
|
||||
*/
|
||||
export function gup(name: string) {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
return params.get(name);
|
||||
}
|
||||
|
||||
/** Returns the URL fragment. */
|
||||
export function hup() {
|
||||
const regex = new RegExp('#(.*)');
|
||||
const results = regex.exec(window.location.hash);
|
||||
if (!results)
|
||||
return '';
|
||||
else
|
||||
return results[1];
|
||||
}
|
||||
|
||||
/** Packs a 32-bit integer into a string in little-endian order. */
|
||||
export function numToString(num: number) {
|
||||
let result = '';
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es6",
|
||||
"lib": ["DOM", "ES2017", "WebWorker"],
|
||||
"lib": ["DOM", "ES6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const path = require('path');
|
||||
const { merge } = require('webpack-merge');
|
||||
|
||||
const baseConfig = {
|
||||
devtool: 'source-map',
|
||||
|
@ -16,22 +17,24 @@ const baseConfig = {
|
|||
},
|
||||
],
|
||||
},
|
||||
output: {
|
||||
publicPath: '/dist/',
|
||||
path: path.resolve('dist/'),
|
||||
filename: '[name].bundle.js',
|
||||
chunkFilename: '[name].bundle.js',
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js'],
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = [
|
||||
const appConfig = merge(baseConfig,
|
||||
{
|
||||
...baseConfig,
|
||||
entry: {
|
||||
main2: path.resolve('js/entry2.js'),
|
||||
main2e: path.resolve('js/entry2e.js')
|
||||
},
|
||||
output: {
|
||||
path: path.resolve('dist/'),
|
||||
filename: '[name].bundle.js',
|
||||
chunkFilename: '[name].bundle.js',
|
||||
library: {
|
||||
name: 'Apple2',
|
||||
type: 'umd',
|
||||
|
@ -50,20 +53,32 @@ module.exports = [
|
|||
publicPath: '/dist/',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const workletConfig = merge(baseConfig,
|
||||
{
|
||||
...baseConfig,
|
||||
target: false,
|
||||
entry: {
|
||||
audio_worker: path.resolve('js/ui/audio_worker.ts'),
|
||||
format_worker: path.resolve('js/formats/worker.ts')
|
||||
audio_worker: path.resolve('js/ui/audio_worker.ts')
|
||||
},
|
||||
output: {
|
||||
globalObject: 'globalThis',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const workerConfig = merge(baseConfig,
|
||||
{
|
||||
target: false,
|
||||
entry: {
|
||||
format_worker: path.resolve('workers/format.worker.ts')
|
||||
},
|
||||
output: {
|
||||
publicPath: '/dist/',
|
||||
path: path.resolve('dist/'),
|
||||
filename: '[name].bundle.js',
|
||||
globalObject: 'globalThis',
|
||||
clean: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
);
|
||||
|
||||
exports.default = [appConfig, workletConfig, workerConfig];
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
* implied warranty.
|
||||
*/
|
||||
|
||||
import { debug } from '../util';
|
||||
import { jsonDecode } from './format_utils';
|
||||
import { debug } from '../js/util';
|
||||
import { jsonDecode } from '../js/formats/format_utils';
|
||||
import {
|
||||
createDisk,
|
||||
createDiskFromJsonDisk,
|
||||
} from './create_disk';
|
||||
} from '../js/formats/create_disk';
|
||||
import {
|
||||
FormatWorkerMessage,
|
||||
Disk,
|
||||
|
@ -23,7 +23,7 @@ import {
|
|||
PROCESS_BINARY,
|
||||
PROCESS_JSON_DISK,
|
||||
PROCESS_JSON,
|
||||
} from './types';
|
||||
} from '../js/formats/types';
|
||||
|
||||
debug('Worker loaded');
|
||||
|
9
workers/tsconfig.json
Normal file
9
workers/tsconfig.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ES6", "WebWorker"]
|
||||
},
|
||||
"include": [
|
||||
"./**/*"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user