mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Minor cleanup (#162)
* Split handling of nibble disks and WOZ disks into separate drivers Before, the `DiskII` object took care of both nibble disks and WOZ disks at the same time. This made it hard to see which code affected which disks. Now, nibble disks are handled by the `NibbleDiskDriver` and WOZ disks are handled by the `WozDiskDriver`. This separation of code should lead to easeir testing and, perhaps, faster evolution of disk handling. An upcoming change will move the `NibbleDiskDriver` and the `WozDiskDriver` to separate files. This passes all tests, compiles, and runs both nibble disks and WOZ disks. * Rename drive number fields/variables/parameters to `driveNo` Before, the naming of fields, variables, and parameters that took `DriveNumber` was very inconsistent. This changes them all to `driveNo`. * Organize imports in `disk2.ts` The imports were automatically organized using VS Code's organize imports action.
This commit is contained in:
parent
e280c3d7b8
commit
8c2299e43e
File diff suppressed because it is too large
Load Diff
@ -18,9 +18,9 @@ export interface SmartPortOptions {
|
||||
}
|
||||
|
||||
export interface Callbacks {
|
||||
driveLight: (drive: DriveNumber, on: boolean) => void;
|
||||
dirty: (drive: DriveNumber, dirty: boolean) => void;
|
||||
label: (drive: DriveNumber, name?: string, side?: string) => void;
|
||||
driveLight: (driveNo: DriveNumber, on: boolean) => void;
|
||||
dirty: (driveNo: DriveNumber, dirty: boolean) => void;
|
||||
label: (driveNo: DriveNumber, name?: string, side?: string) => void;
|
||||
}
|
||||
|
||||
class Address {
|
||||
@ -152,15 +152,15 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
// debug.apply(this, arguments);
|
||||
}
|
||||
|
||||
private driveLight(drive: DriveNumber) {
|
||||
if (!this.busy[drive]) {
|
||||
this.busy[drive] = true;
|
||||
this.callbacks?.driveLight(drive, true);
|
||||
private driveLight(driveNo: DriveNumber) {
|
||||
if (!this.busy[driveNo]) {
|
||||
this.busy[driveNo] = true;
|
||||
this.callbacks?.driveLight(driveNo, true);
|
||||
}
|
||||
clearTimeout(this.busyTimeout[drive]);
|
||||
this.busyTimeout[drive] = setTimeout(() => {
|
||||
this.busy[drive] = false;
|
||||
this.callbacks?.driveLight(drive, false);
|
||||
clearTimeout(this.busyTimeout[driveNo]);
|
||||
this.busyTimeout[driveNo] = setTimeout(() => {
|
||||
this.busy[driveNo] = false;
|
||||
this.callbacks?.driveLight(driveNo, false);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
* dumpBlock
|
||||
*/
|
||||
|
||||
dumpBlock(drive: DriveNumber, block: number) {
|
||||
dumpBlock(driveNo: DriveNumber, block: number) {
|
||||
let result = '';
|
||||
let b;
|
||||
let jdx;
|
||||
@ -176,7 +176,7 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
for (let idx = 0; idx < 32; idx++) {
|
||||
result += toHex(idx << 4, 4) + ': ';
|
||||
for (jdx = 0; jdx < 16; jdx++) {
|
||||
b = this.disks[drive].blocks[block][idx * 16 + jdx];
|
||||
b = this.disks[driveNo].blocks[block][idx * 16 + jdx];
|
||||
if (jdx === 8) {
|
||||
result += ' ';
|
||||
}
|
||||
@ -184,7 +184,7 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
}
|
||||
result += ' ';
|
||||
for (jdx = 0; jdx < 16; jdx++) {
|
||||
b = this.disks[drive].blocks[block][idx * 16 + jdx] & 0x7f;
|
||||
b = this.disks[driveNo].blocks[block][idx * 16 + jdx] & 0x7f;
|
||||
if (jdx === 8) {
|
||||
result += ' ';
|
||||
}
|
||||
@ -203,9 +203,9 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
* getDeviceInfo
|
||||
*/
|
||||
|
||||
getDeviceInfo(state: CpuState, drive: DriveNumber) {
|
||||
if (this.disks[drive]) {
|
||||
const blocks = this.disks[drive].blocks.length;
|
||||
getDeviceInfo(state: CpuState, driveNo: DriveNumber) {
|
||||
if (this.disks[driveNo]) {
|
||||
const blocks = this.disks[driveNo].blocks.length;
|
||||
state.x = blocks & 0xff;
|
||||
state.y = blocks >> 8;
|
||||
|
||||
@ -221,23 +221,23 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
* readBlock
|
||||
*/
|
||||
|
||||
readBlock(state: CpuState, drive: DriveNumber, block: number, buffer: Address) {
|
||||
this.debug(`read drive=${drive}`);
|
||||
readBlock(state: CpuState, driveNo: DriveNumber, block: number, buffer: Address) {
|
||||
this.debug(`read drive=${driveNo}`);
|
||||
this.debug(`read buffer=${buffer.toString()}`);
|
||||
this.debug(`read block=$${toHex(block)}`);
|
||||
|
||||
if (!this.disks[drive]?.blocks.length) {
|
||||
debug('Drive', drive, 'is empty');
|
||||
if (!this.disks[driveNo]?.blocks.length) {
|
||||
debug('Drive', driveNo, 'is empty');
|
||||
state.a = DEVICE_OFFLINE;
|
||||
state.s |= flags.C;
|
||||
return;
|
||||
}
|
||||
|
||||
// debug('read', '\n' + dumpBlock(drive, block));
|
||||
this.driveLight(drive);
|
||||
this.driveLight(driveNo);
|
||||
|
||||
for (let idx = 0; idx < 512; idx++) {
|
||||
buffer.writeByte(this.disks[drive].blocks[block][idx]);
|
||||
buffer.writeByte(this.disks[driveNo].blocks[block][idx]);
|
||||
buffer = buffer.inc(1);
|
||||
}
|
||||
|
||||
@ -249,30 +249,30 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
* writeBlock
|
||||
*/
|
||||
|
||||
writeBlock(state: CpuState, drive: DriveNumber, block: number, buffer: Address) {
|
||||
this.debug(`write drive=${drive}`);
|
||||
writeBlock(state: CpuState, driveNo: DriveNumber, block: number, buffer: Address) {
|
||||
this.debug(`write drive=${driveNo}`);
|
||||
this.debug(`write buffer=${buffer.toString()}`);
|
||||
this.debug(`write block=$${toHex(block)}`);
|
||||
|
||||
if (!this.disks[drive]?.blocks.length) {
|
||||
debug('Drive', drive, 'is empty');
|
||||
if (!this.disks[driveNo]?.blocks.length) {
|
||||
debug('Drive', driveNo, 'is empty');
|
||||
state.a = DEVICE_OFFLINE;
|
||||
state.s |= flags.C;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.disks[drive].readOnly) {
|
||||
debug('Drive', drive, 'is write protected');
|
||||
if (this.disks[driveNo].readOnly) {
|
||||
debug('Drive', driveNo, 'is write protected');
|
||||
state.a = WRITE_PROTECTED;
|
||||
state.s |= flags.C;
|
||||
return;
|
||||
}
|
||||
|
||||
// debug('write', '\n' + dumpBlock(drive, block));
|
||||
this.driveLight(drive);
|
||||
this.driveLight(driveNo);
|
||||
|
||||
for (let idx = 0; idx < 512; idx++) {
|
||||
this.disks[drive].blocks[block][idx] = buffer.readByte();
|
||||
this.disks[driveNo].blocks[block][idx] = buffer.readByte();
|
||||
buffer = buffer.inc(1);
|
||||
}
|
||||
state.a = 0;
|
||||
@ -283,25 +283,25 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
* formatDevice
|
||||
*/
|
||||
|
||||
formatDevice(state: CpuState, drive: DriveNumber) {
|
||||
if (!this.disks[drive]?.blocks.length) {
|
||||
debug('Drive', drive, 'is empty');
|
||||
formatDevice(state: CpuState, driveNo: DriveNumber) {
|
||||
if (!this.disks[driveNo]?.blocks.length) {
|
||||
debug('Drive', driveNo, 'is empty');
|
||||
state.a = DEVICE_OFFLINE;
|
||||
state.s |= flags.C;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.disks[drive].readOnly) {
|
||||
debug('Drive', drive, 'is write protected');
|
||||
if (this.disks[driveNo].readOnly) {
|
||||
debug('Drive', driveNo, 'is write protected');
|
||||
state.a = WRITE_PROTECTED;
|
||||
state.s |= flags.C;
|
||||
return;
|
||||
}
|
||||
|
||||
for (let idx = 0; idx < this.disks[drive].blocks.length; idx++) {
|
||||
this.disks[drive].blocks[idx] = new Uint8Array();
|
||||
for (let idx = 0; idx < this.disks[driveNo].blocks.length; idx++) {
|
||||
this.disks[driveNo].blocks[idx] = new Uint8Array();
|
||||
for (let jdx = 0; jdx < 512; jdx++) {
|
||||
this.disks[drive].blocks[idx][jdx] = 0;
|
||||
this.disks[driveNo].blocks[idx][jdx] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -549,18 +549,18 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
);
|
||||
}
|
||||
|
||||
setBinary(drive: DriveNumber, name: string, fmt: BlockFormat, rawData: ArrayBuffer) {
|
||||
setBinary(driveNo: DriveNumber, name: string, fmt: BlockFormat, rawData: ArrayBuffer) {
|
||||
let volume = 254;
|
||||
let readOnly = false;
|
||||
if (fmt === '2mg') {
|
||||
const header = read2MGHeader(rawData);
|
||||
this.metadata[drive] = header;
|
||||
this.metadata[driveNo] = header;
|
||||
const { bytes, offset } = header;
|
||||
volume = header.volume;
|
||||
readOnly = header.readOnly;
|
||||
rawData = rawData.slice(offset, offset + bytes);
|
||||
} else {
|
||||
this.metadata[drive] = null;
|
||||
this.metadata[driveNo] = null;
|
||||
}
|
||||
const options = {
|
||||
rawData,
|
||||
@ -569,9 +569,9 @@ export default class SmartPort implements Card, MassStorage<BlockFormat>, Restor
|
||||
volume,
|
||||
};
|
||||
|
||||
this.ext[drive] = fmt;
|
||||
this.disks[drive] = createBlockDisk(fmt, options);
|
||||
this.callbacks?.label(drive, name);
|
||||
this.ext[driveNo] = fmt;
|
||||
this.disks[driveNo] = createBlockDisk(fmt, options);
|
||||
this.callbacks?.label(driveNo, name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -63,19 +63,19 @@ export const BlockDisk = ({ smartPort, number, on, name }: BlockDiskProps) => {
|
||||
<DiskDragTarget
|
||||
className={styles.disk}
|
||||
storage={smartPort}
|
||||
drive={number}
|
||||
driveNo={number}
|
||||
formats={BLOCK_FORMATS}
|
||||
onError={setError}
|
||||
>
|
||||
<ErrorModal error={error} setError={setError} />
|
||||
<BlockFileModal
|
||||
smartPort={smartPort}
|
||||
number={number}
|
||||
driveNo={number}
|
||||
onClose={doClose}
|
||||
isOpen={modalOpen}
|
||||
/>
|
||||
<DownloadModal
|
||||
number={number}
|
||||
driveNo={number}
|
||||
massStorage={smartPort}
|
||||
isOpen={downloadModalOpen}
|
||||
onClose={doCloseDownload}
|
||||
|
@ -21,11 +21,11 @@ const DISK_TYPES: FilePickerAcceptType[] = [
|
||||
interface BlockFileModalProps {
|
||||
isOpen: boolean;
|
||||
smartPort: SmartPort;
|
||||
number: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
onClose: (closeBox?: boolean) => void;
|
||||
}
|
||||
|
||||
export const BlockFileModal = ({ smartPort, number, onClose, isOpen } : BlockFileModalProps) => {
|
||||
export const BlockFileModal = ({ smartPort, driveNo: number, onClose, isOpen } : BlockFileModalProps) => {
|
||||
const [handles, setHandles] = useState<FileSystemFileHandle[]>();
|
||||
const [busy, setBusy] = useState<boolean>(false);
|
||||
const [empty, setEmpty] = useState<boolean>(true);
|
||||
|
@ -6,7 +6,7 @@ import { spawn } from './util/promises';
|
||||
|
||||
export interface DiskDragTargetProps<T> extends JSX.HTMLAttributes<HTMLDivElement> {
|
||||
storage: MassStorage<T> | undefined;
|
||||
drive?: DriveNumber;
|
||||
driveNo?: DriveNumber;
|
||||
formats: typeof FLOPPY_FORMATS
|
||||
| typeof BLOCK_FORMATS
|
||||
| typeof DISK_FORMATS;
|
||||
@ -16,7 +16,7 @@ export interface DiskDragTargetProps<T> extends JSX.HTMLAttributes<HTMLDivElemen
|
||||
|
||||
export const DiskDragTarget = ({
|
||||
storage,
|
||||
drive,
|
||||
driveNo,
|
||||
dropRef,
|
||||
formats,
|
||||
onError,
|
||||
@ -54,7 +54,7 @@ export const DiskDragTarget = ({
|
||||
const onDrop = (event: DragEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const targetDrive = drive ?? 1; //TODO(whscullin) Maybe pick available drive
|
||||
const targetDrive = driveNo ?? 1; //TODO(whscullin) Maybe pick available drive
|
||||
|
||||
const dt = event.dataTransfer;
|
||||
if (dt?.files.length === 1 && storage) {
|
||||
@ -87,7 +87,7 @@ export const DiskDragTarget = ({
|
||||
div.removeEventListener('drop', onDrop);
|
||||
};
|
||||
}
|
||||
}, [drive, dropRef, formats, onError, storage]);
|
||||
}, [driveNo, dropRef, formats, onError, storage]);
|
||||
|
||||
return (
|
||||
<div ref={ref} {...props}>
|
||||
|
@ -65,13 +65,13 @@ export const DiskII = ({ disk2, number, on, name, side }: DiskIIProps) => {
|
||||
<DiskDragTarget
|
||||
className={styles.disk}
|
||||
storage={disk2}
|
||||
drive={number}
|
||||
driveNo={number}
|
||||
formats={FLOPPY_FORMATS}
|
||||
onError={setError}
|
||||
>
|
||||
<FileModal disk2={disk2} number={number} onClose={doClose} isOpen={modalOpen} />
|
||||
<FileModal disk2={disk2} driveNo={number} onClose={doClose} isOpen={modalOpen} />
|
||||
<DownloadModal
|
||||
number={number}
|
||||
driveNo={number}
|
||||
massStorage={disk2}
|
||||
isOpen={downloadModalOpen}
|
||||
onClose={doCloseDownload}
|
||||
|
@ -8,18 +8,18 @@ import styles from './css/DownloadModal.module.css';
|
||||
interface DownloadModalProps {
|
||||
isOpen: boolean;
|
||||
massStorage: MassStorage<unknown>;
|
||||
number: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
onClose: (closeBox?: boolean) => void;
|
||||
}
|
||||
|
||||
export const DownloadModal = ({ massStorage, number, onClose, isOpen } : DownloadModalProps) => {
|
||||
export const DownloadModal = ({ massStorage, driveNo, onClose, isOpen } : DownloadModalProps) => {
|
||||
const [href, setHref] = useState('');
|
||||
const [downloadName, setDownloadName] = useState('');
|
||||
const doCancel = useCallback(() => onClose(true), [onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
const storageData = massStorage.getBinary(number);
|
||||
const storageData = massStorage.getBinary(driveNo);
|
||||
if (storageData) {
|
||||
const { ext, data } = storageData;
|
||||
const { name } = storageData.metadata;
|
||||
@ -37,7 +37,7 @@ export const DownloadModal = ({ massStorage, number, onClose, isOpen } : Downloa
|
||||
setHref('');
|
||||
setDownloadName('');
|
||||
}
|
||||
}, [isOpen, number, massStorage]);
|
||||
}, [isOpen, driveNo, massStorage]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -10,7 +10,7 @@ import { ErrorModal } from './ErrorModal';
|
||||
import { ProgressModal } from './ProgressModal';
|
||||
import { loadHttpUnknownFile, getHashParts, loadJSON, SmartStorageBroker } from './util/files';
|
||||
import { useHash } from './hooks/useHash';
|
||||
import { DISK_FORMATS, DriveNumber, SupportedSectors } from 'js/formats/types';
|
||||
import { DISK_FORMATS, DRIVE_NUMBERS, SupportedSectors } from 'js/formats/types';
|
||||
import { spawn, Ready } from './util/promises';
|
||||
|
||||
import styles from './css/Drives.module.css';
|
||||
@ -90,9 +90,9 @@ export const Drives = ({ cpu, io, sectors, enhanced, ready }: DrivesProps) => {
|
||||
const hashParts = getHashParts(hash);
|
||||
const controllers: AbortController[] = [];
|
||||
let loading = 0;
|
||||
for (const drive of [1, 2] as DriveNumber[]) {
|
||||
if (hashParts && hashParts[drive]) {
|
||||
const hashPart = decodeURIComponent(hashParts[drive]);
|
||||
for (const driveNo of DRIVE_NUMBERS) {
|
||||
if (hashParts && hashParts[driveNo]) {
|
||||
const hashPart = decodeURIComponent(hashParts[driveNo]);
|
||||
const isHttp = hashPart.match(/^https?:/i);
|
||||
const isJson = hashPart.match(/\.json$/i);
|
||||
if (isHttp && !isJson) {
|
||||
@ -101,7 +101,7 @@ export const Drives = ({ cpu, io, sectors, enhanced, ready }: DrivesProps) => {
|
||||
try {
|
||||
await loadHttpUnknownFile(
|
||||
smartStorageBroker,
|
||||
drive,
|
||||
driveNo,
|
||||
hashPart,
|
||||
signal,
|
||||
onProgress);
|
||||
@ -116,7 +116,7 @@ export const Drives = ({ cpu, io, sectors, enhanced, ready }: DrivesProps) => {
|
||||
}));
|
||||
} else {
|
||||
const url = isHttp ? hashPart : `json/disks/${hashPart}.json`;
|
||||
loadJSON(disk2, drive, url).catch((e) => setError(e));
|
||||
loadJSON(disk2, driveNo, url).catch((e) => setError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export type NibbleFileCallback = (
|
||||
interface FileModalProps {
|
||||
isOpen: boolean;
|
||||
disk2: DiskII;
|
||||
number: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
onClose: (closeBox?: boolean) => void;
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ interface IndexEntry {
|
||||
category: string;
|
||||
}
|
||||
|
||||
export const FileModal = ({ disk2, number, onClose, isOpen }: FileModalProps) => {
|
||||
export const FileModal = ({ disk2, driveNo, onClose, isOpen }: FileModalProps) => {
|
||||
const [busy, setBusy] = useState<boolean>(false);
|
||||
const [empty, setEmpty] = useState<boolean>(true);
|
||||
const [category, setCategory] = useState<string>();
|
||||
@ -69,13 +69,13 @@ export const FileModal = ({ disk2, number, onClose, isOpen }: FileModalProps) =>
|
||||
|
||||
try {
|
||||
if (handles?.length === 1) {
|
||||
hashParts[number] = '';
|
||||
await loadLocalNibbleFile(disk2, number, await handles[0].getFile());
|
||||
hashParts[driveNo] = '';
|
||||
await loadLocalNibbleFile(disk2, driveNo, await handles[0].getFile());
|
||||
}
|
||||
if (filename) {
|
||||
const name = filename.match(/\/([^/]+).json$/) || ['', ''];
|
||||
hashParts[number] = name[1];
|
||||
await loadJSON(disk2, number, filename);
|
||||
hashParts[driveNo] = name[1];
|
||||
await loadJSON(disk2, driveNo, filename);
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e);
|
||||
@ -86,7 +86,7 @@ export const FileModal = ({ disk2, number, onClose, isOpen }: FileModalProps) =>
|
||||
}
|
||||
|
||||
setHashParts(hashParts);
|
||||
}, [disk2, filename, number, onClose, handles, hash]);
|
||||
}, [disk2, filename, driveNo, onClose, handles, hash]);
|
||||
|
||||
const onChange = useCallback((handles: FileSystemFileHandle[]) => {
|
||||
setEmpty(handles.length === 0);
|
||||
|
@ -235,7 +235,7 @@ const Catalog = ({ dos, setFileData }: CatalogProps) => {
|
||||
*/
|
||||
interface DiskInfoProps {
|
||||
massStorage: MassStorage<DiskFormat>;
|
||||
drive: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
setFileData: (fileData: FileData) => void;
|
||||
}
|
||||
|
||||
@ -250,9 +250,9 @@ interface DiskInfoProps {
|
||||
* @param drive The drive number
|
||||
* @returns DiskInfo component
|
||||
*/
|
||||
const DiskInfo = ({ massStorage, drive, setFileData }: DiskInfoProps) => {
|
||||
const DiskInfo = ({ massStorage, driveNo, setFileData }: DiskInfoProps) => {
|
||||
const disk = useMemo(() => {
|
||||
const massStorageData = massStorage.getBinary(drive, 'po');
|
||||
const massStorageData = massStorage.getBinary(driveNo, 'po');
|
||||
if (massStorageData) {
|
||||
const { data, readOnly, ext } = massStorageData;
|
||||
const { name } = massStorageData.metadata;
|
||||
@ -265,7 +265,7 @@ const DiskInfo = ({ massStorage, drive, setFileData }: DiskInfoProps) => {
|
||||
volume: 254,
|
||||
});
|
||||
} else if (data.byteLength < 800 * 1024) {
|
||||
const doData = massStorage.getBinary(drive, 'do');
|
||||
const doData = massStorage.getBinary(driveNo, 'do');
|
||||
if (doData) {
|
||||
if (isMaybeDOS33(doData)) {
|
||||
disk = createDiskFromDOS({
|
||||
@ -288,7 +288,7 @@ const DiskInfo = ({ massStorage, drive, setFileData }: DiskInfoProps) => {
|
||||
return disk;
|
||||
}
|
||||
return null;
|
||||
}, [massStorage, drive]);
|
||||
}, [massStorage, driveNo]);
|
||||
|
||||
if (disk) {
|
||||
try {
|
||||
@ -409,11 +409,11 @@ export const Disks = ({ apple2 }: DisksProps) => {
|
||||
<div className={debuggerStyles.subHeading}>
|
||||
{card.constructor.name} - 1
|
||||
</div>
|
||||
<DiskInfo massStorage={card} drive={1} setFileData={setFileData} />
|
||||
<DiskInfo massStorage={card} driveNo={1} setFileData={setFileData} />
|
||||
<div className={debuggerStyles.subHeading}>
|
||||
{card.constructor.name} - 2
|
||||
</div>
|
||||
<DiskInfo massStorage={card} drive={2} setFileData={setFileData} />
|
||||
<DiskInfo massStorage={card} driveNo={2} setFileData={setFileData} />
|
||||
</div>
|
||||
))}
|
||||
<FileViewer fileData={fileData} onClose={onClose} />
|
||||
|
@ -48,7 +48,7 @@ export const getNameAndExtension = (url: string) => {
|
||||
export const loadLocalFile = (
|
||||
storage: MassStorage<FloppyFormat|BlockFormat>,
|
||||
formats: typeof FLOPPY_FORMATS | typeof BLOCK_FORMATS | typeof DISK_FORMATS,
|
||||
number: DriveNumber,
|
||||
driveNo: DriveNumber,
|
||||
file: File,
|
||||
) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -58,7 +58,7 @@ export const loadLocalFile = (
|
||||
const { name, ext } = getNameAndExtension(file.name);
|
||||
if (includes(formats, ext)) {
|
||||
initGamepad();
|
||||
if (storage.setBinary(number, name, ext, result)) {
|
||||
if (storage.setBinary(driveNo, name, ext, result)) {
|
||||
resolve(true);
|
||||
} else {
|
||||
reject(`Unable to load ${name}`);
|
||||
@ -76,12 +76,12 @@ export const loadLocalFile = (
|
||||
* selection form element to be loaded.
|
||||
*
|
||||
* @param smartPort SmartPort object
|
||||
* @param number Drive number
|
||||
* @param driveNo Drive number
|
||||
* @param file Browser File object to load
|
||||
* @returns true if successful
|
||||
*/
|
||||
export const loadLocalBlockFile = (smartPort: SmartPort, number: DriveNumber, file: File) => {
|
||||
return loadLocalFile(smartPort, BLOCK_FORMATS, number, file);
|
||||
export const loadLocalBlockFile = (smartPort: SmartPort, driveNo: DriveNumber, file: File) => {
|
||||
return loadLocalFile(smartPort, BLOCK_FORMATS, driveNo, file);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -89,12 +89,12 @@ export const loadLocalBlockFile = (smartPort: SmartPort, number: DriveNumber, fi
|
||||
* selection form element to be loaded.
|
||||
*
|
||||
* @param disk2 Disk2 object
|
||||
* @param number Drive number
|
||||
* @param driveNo Drive number
|
||||
* @param file Browser File object to load
|
||||
* @returns true if successful
|
||||
*/
|
||||
export const loadLocalNibbleFile = (disk2: Disk2, number: DriveNumber, file: File) => {
|
||||
return loadLocalFile(disk2, FLOPPY_FORMATS, number, file);
|
||||
export const loadLocalNibbleFile = (disk2: Disk2, driveNo: DriveNumber, file: File) => {
|
||||
return loadLocalFile(disk2, FLOPPY_FORMATS, driveNo, file);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -103,13 +103,13 @@ export const loadLocalNibbleFile = (disk2: Disk2, number: DriveNumber, file: Fil
|
||||
* as the emulator.
|
||||
*
|
||||
* @param disk2 Disk2 object
|
||||
* @param number Drive number
|
||||
* @param driveNo Drive number
|
||||
* @param url URL, relative or absolute to JSON file
|
||||
* @returns true if successful
|
||||
*/
|
||||
export const loadJSON = async (
|
||||
disk2: Disk2,
|
||||
number: DriveNumber,
|
||||
driveNo: DriveNumber,
|
||||
url: string,
|
||||
) => {
|
||||
const response = await fetch(url);
|
||||
@ -120,7 +120,7 @@ export const loadJSON = async (
|
||||
if (!includes(FLOPPY_FORMATS, data.type)) {
|
||||
throw new Error(`Type "${data.type}" not recognized.`);
|
||||
}
|
||||
disk2.setDisk(number, data);
|
||||
disk2.setDisk(driveNo, data);
|
||||
initGamepad(data.gamepad);
|
||||
};
|
||||
|
||||
@ -166,13 +166,13 @@ export const loadHttpFile = async (
|
||||
* as the emulator.
|
||||
*
|
||||
* @param smartPort SmartPort object
|
||||
* @param number Drive number
|
||||
* @param driveNo Drive number
|
||||
* @param url URL, relative or absolute to JSON file
|
||||
* @returns true if successful
|
||||
*/
|
||||
export const loadHttpBlockFile = async (
|
||||
smartPort: SmartPort,
|
||||
number: DriveNumber,
|
||||
driveNo: DriveNumber,
|
||||
url: string,
|
||||
signal?: AbortSignal,
|
||||
onProgress?: ProgressCallback
|
||||
@ -182,7 +182,7 @@ export const loadHttpBlockFile = async (
|
||||
throw new Error(`Extension "${ext}" not recognized.`);
|
||||
}
|
||||
const data = await loadHttpFile(url, signal, onProgress);
|
||||
smartPort.setBinary(number, name, ext, data);
|
||||
smartPort.setBinary(driveNo, name, ext, data);
|
||||
initGamepad();
|
||||
|
||||
return true;
|
||||
@ -194,55 +194,55 @@ export const loadHttpBlockFile = async (
|
||||
* as the emulator.
|
||||
*
|
||||
* @param disk2 Disk2 object
|
||||
* @param number Drive number
|
||||
* @param driveNo Drive number
|
||||
* @param url URL, relative or absolute to JSON file
|
||||
* @returns true if successful
|
||||
*/
|
||||
export const loadHttpNibbleFile = async (
|
||||
disk2: Disk2,
|
||||
number: DriveNumber,
|
||||
driveNo: DriveNumber,
|
||||
url: string,
|
||||
signal?: AbortSignal,
|
||||
onProgress?: ProgressCallback
|
||||
) => {
|
||||
if (url.endsWith('.json')) {
|
||||
return loadJSON(disk2, number, url);
|
||||
return loadJSON(disk2, driveNo, url);
|
||||
}
|
||||
const { name, ext } = getNameAndExtension(url);
|
||||
if (!includes(FLOPPY_FORMATS, ext)) {
|
||||
throw new Error(`Extension "${ext}" not recognized.`);
|
||||
}
|
||||
const data = await loadHttpFile(url, signal, onProgress);
|
||||
disk2.setBinary(number, name, ext, data);
|
||||
disk2.setBinary(driveNo, name, ext, data);
|
||||
initGamepad();
|
||||
return loadHttpFile(url, signal, onProgress);
|
||||
};
|
||||
|
||||
export const loadHttpUnknownFile = async (
|
||||
smartStorageBroker: SmartStorageBroker,
|
||||
number: DriveNumber,
|
||||
driveNo: DriveNumber,
|
||||
url: string,
|
||||
signal?: AbortSignal,
|
||||
onProgress?: ProgressCallback,
|
||||
) => {
|
||||
const data = await loadHttpFile(url, signal, onProgress);
|
||||
const { name, ext } = getNameAndExtension(url);
|
||||
smartStorageBroker.setBinary(number, name, ext, data);
|
||||
smartStorageBroker.setBinary(driveNo, name, ext, data);
|
||||
};
|
||||
|
||||
export class SmartStorageBroker implements MassStorage<unknown> {
|
||||
constructor(private disk2: Disk2, private smartPort: SmartPort) {}
|
||||
|
||||
setBinary(drive: DriveNumber, name: string, ext: string, data: ArrayBuffer): boolean {
|
||||
setBinary(driveNo: DriveNumber, name: string, ext: string, data: ArrayBuffer): boolean {
|
||||
if (includes(DISK_FORMATS, ext)) {
|
||||
if (data.byteLength >= 800 * 1024) {
|
||||
if (includes(BLOCK_FORMATS, ext)) {
|
||||
this.smartPort.setBinary(drive, name, ext, data);
|
||||
this.smartPort.setBinary(driveNo, name, ext, data);
|
||||
} else {
|
||||
throw new Error(`Unable to load "${name}"`);
|
||||
}
|
||||
} else if (includes(FLOPPY_FORMATS, ext)) {
|
||||
this.disk2.setBinary(drive, name, ext, data);
|
||||
this.disk2.setBinary(driveNo, name, ext, data);
|
||||
} else {
|
||||
throw new Error(`Unable to load "${name}"`);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ export const PROCESS_JSON = 'PROCESS_JSON';
|
||||
export interface ProcessBinaryMessage {
|
||||
type: typeof PROCESS_BINARY;
|
||||
payload: {
|
||||
drive: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
fmt: FloppyFormat;
|
||||
options: DiskOptions;
|
||||
};
|
||||
@ -244,7 +244,7 @@ export interface ProcessBinaryMessage {
|
||||
export interface ProcessJsonDiskMessage {
|
||||
type: typeof PROCESS_JSON_DISK;
|
||||
payload: {
|
||||
drive: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
jsonDisk: JSONDisk;
|
||||
};
|
||||
}
|
||||
@ -253,7 +253,7 @@ export interface ProcessJsonDiskMessage {
|
||||
export interface ProcessJsonMessage {
|
||||
type: typeof PROCESS_JSON;
|
||||
payload: {
|
||||
drive: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
json: string;
|
||||
};
|
||||
}
|
||||
@ -272,7 +272,7 @@ export const DISK_PROCESSED = 'DISK_PROCESSED';
|
||||
export interface DiskProcessedResponse {
|
||||
type: typeof DISK_PROCESSED;
|
||||
payload: {
|
||||
drive: DriveNumber;
|
||||
driveNo: DriveNumber;
|
||||
disk: FloppyDisk | null;
|
||||
};
|
||||
}
|
||||
|
103
js/ui/apple2.ts
103
js/ui/apple2.ts
@ -84,7 +84,7 @@ let joystick: JoyStick;
|
||||
let system: System;
|
||||
let keyboard: KeyBoard;
|
||||
let io: Apple2IO;
|
||||
let _currentDrive: DriveNumber = 1;
|
||||
let driveNo: DriveNumber = 1;
|
||||
let _e: boolean;
|
||||
|
||||
let ready: Promise<[void, void]>;
|
||||
@ -103,14 +103,13 @@ export function compileApplesoftProgram(program: string) {
|
||||
}
|
||||
|
||||
export function openLoad(driveString: string, event: MouseEvent) {
|
||||
const drive = parseInt(driveString, 10) as DriveNumber;
|
||||
_currentDrive = drive;
|
||||
if (event.metaKey && includes(DRIVE_NUMBERS, drive)) {
|
||||
driveNo = parseInt(driveString, 10) as DriveNumber;
|
||||
if (event.metaKey && includes(DRIVE_NUMBERS, driveNo)) {
|
||||
openLoadHTTP();
|
||||
} else {
|
||||
if (disk_cur_cat[drive]) {
|
||||
if (disk_cur_cat[driveNo]) {
|
||||
const element = document.querySelector<HTMLSelectElement>('#category_select')!;
|
||||
element.value = disk_cur_cat[drive];
|
||||
element.value = disk_cur_cat[driveNo];
|
||||
selectCategory();
|
||||
}
|
||||
MicroModal.show('load-modal');
|
||||
@ -118,27 +117,27 @@ export function openLoad(driveString: string, event: MouseEvent) {
|
||||
}
|
||||
|
||||
export function openSave(driveString: string, event: MouseEvent) {
|
||||
const drive = parseInt(driveString, 10) as DriveNumber;
|
||||
const driveNo = parseInt(driveString, 10) as DriveNumber;
|
||||
|
||||
const mimeType = 'application/octet-stream';
|
||||
const storageData = _disk2.getBinary(drive);
|
||||
const storageData = _disk2.getBinary(driveNo);
|
||||
const a = document.querySelector<HTMLAnchorElement>('#local_save_link')!;
|
||||
|
||||
if (!storageData) {
|
||||
alert(`No data from drive ${drive}`);
|
||||
alert(`No data from drive ${driveNo}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = storageData;
|
||||
const blob = new Blob([data], { 'type': mimeType });
|
||||
a.href = window.URL.createObjectURL(blob);
|
||||
a.download = driveLights.label(drive) + '.dsk';
|
||||
a.download = driveLights.label(driveNo) + '.dsk';
|
||||
|
||||
if (event.metaKey) {
|
||||
dumpDisk(drive);
|
||||
dumpDisk(driveNo);
|
||||
} else {
|
||||
const saveName = document.querySelector<HTMLInputElement>('#save_name')!;
|
||||
saveName.value = driveLights.label(drive);
|
||||
saveName.value = driveLights.label(driveNo);
|
||||
MicroModal.show('save-modal');
|
||||
}
|
||||
}
|
||||
@ -154,12 +153,12 @@ export function openAlert(msg: string) {
|
||||
* Drag and Drop
|
||||
*/
|
||||
|
||||
export function handleDragOver(_drive: number, event: DragEvent) {
|
||||
export function handleDragOver(_driveNo: number, event: DragEvent) {
|
||||
event.preventDefault();
|
||||
event.dataTransfer!.dropEffect = 'copy';
|
||||
}
|
||||
|
||||
export function handleDragEnd(_drive: number, event: DragEvent) {
|
||||
export function handleDragEnd(_driveNo: number, event: DragEvent) {
|
||||
const dt = event.dataTransfer!;
|
||||
if (dt.items) {
|
||||
for (let i = 0; i < dt.items.length; i++) {
|
||||
@ -170,23 +169,23 @@ export function handleDragEnd(_drive: number, event: DragEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
export function handleDrop(drive: number, event: DragEvent) {
|
||||
export function handleDrop(driveNo: number, event: DragEvent) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if (drive < 1) {
|
||||
if (driveNo < 1) {
|
||||
if (!_disk2.getMetadata(1)) {
|
||||
drive = 1;
|
||||
driveNo = 1;
|
||||
} else if (!_disk2.getMetadata(2)) {
|
||||
drive = 2;
|
||||
driveNo = 2;
|
||||
} else {
|
||||
drive = 1;
|
||||
driveNo = 1;
|
||||
}
|
||||
}
|
||||
const dt = event.dataTransfer!;
|
||||
if (dt.files.length === 1) {
|
||||
const runOnLoad = event.shiftKey;
|
||||
doLoadLocal(drive as DriveNumber, dt.files[0], { runOnLoad });
|
||||
doLoadLocal(driveNo as DriveNumber, dt.files[0], { runOnLoad });
|
||||
} else if (dt.files.length === 2) {
|
||||
doLoadLocal(1, dt.files[0]);
|
||||
doLoadLocal(2, dt.files[1]);
|
||||
@ -195,7 +194,7 @@ export function handleDrop(drive: number, event: DragEvent) {
|
||||
if (dt.items[idx].type === 'text/uri-list') {
|
||||
dt.items[idx].getAsString(function (url) {
|
||||
const parts = hup().split('|');
|
||||
parts[drive - 1] = url;
|
||||
parts[driveNo - 1] = url;
|
||||
document.location.hash = parts.join('|');
|
||||
});
|
||||
}
|
||||
@ -228,7 +227,7 @@ function loadingStop() {
|
||||
}
|
||||
}
|
||||
|
||||
export function loadAjax(drive: DriveNumber, url: string) {
|
||||
export function loadAjax(driveNo: DriveNumber, url: string) {
|
||||
loadingStart();
|
||||
|
||||
fetch(url).then(function (response: Response) {
|
||||
@ -241,7 +240,7 @@ export function loadAjax(drive: DriveNumber, url: string) {
|
||||
if (data.type === 'binary') {
|
||||
loadBinary(data );
|
||||
} else if (includes(DISK_FORMATS, data.type)) {
|
||||
loadDisk(drive, data);
|
||||
loadDisk(driveNo, data);
|
||||
}
|
||||
initGamepad(data.gamepad);
|
||||
loadingStop();
|
||||
@ -269,7 +268,7 @@ export function doLoad(event: MouseEvent|KeyboardEvent) {
|
||||
const files = localFile.files;
|
||||
if (files && files.length === 1) {
|
||||
const runOnLoad = event.shiftKey;
|
||||
doLoadLocal(_currentDrive, files[0], { runOnLoad });
|
||||
doLoadLocal(driveNo, files[0], { runOnLoad });
|
||||
} else if (url) {
|
||||
let filename;
|
||||
MicroModal.close('load-modal');
|
||||
@ -278,7 +277,7 @@ export function doLoad(event: MouseEvent|KeyboardEvent) {
|
||||
if (filename === '__manage') {
|
||||
openManage();
|
||||
} else {
|
||||
loadLocalStorage(_currentDrive, filename);
|
||||
loadLocalStorage(driveNo, filename);
|
||||
}
|
||||
} else {
|
||||
const r1 = /json\/disks\/(.*).json$/.exec(url);
|
||||
@ -288,7 +287,7 @@ export function doLoad(event: MouseEvent|KeyboardEvent) {
|
||||
filename = url;
|
||||
}
|
||||
const parts = hup().split('|');
|
||||
parts[_currentDrive - 1] = filename;
|
||||
parts[driveNo - 1] = filename;
|
||||
document.location.hash = parts.join('|');
|
||||
}
|
||||
}
|
||||
@ -297,7 +296,7 @@ export function doLoad(event: MouseEvent|KeyboardEvent) {
|
||||
export function doSave() {
|
||||
const saveName = document.querySelector<HTMLInputElement>('#save_name')!;
|
||||
const name = saveName.value;
|
||||
saveLocalStorage(_currentDrive, name);
|
||||
saveLocalStorage(driveNo, name);
|
||||
MicroModal.close('save-modal');
|
||||
window.setTimeout(() => openAlert('Saved'), 0);
|
||||
}
|
||||
@ -313,7 +312,7 @@ interface LoadOptions {
|
||||
runOnLoad?: boolean;
|
||||
}
|
||||
|
||||
function doLoadLocal(drive: DriveNumber, file: File, options: Partial<LoadOptions> = {}) {
|
||||
function doLoadLocal(driveNo: DriveNumber, file: File, options: Partial<LoadOptions> = {}) {
|
||||
const parts = file.name.split('.');
|
||||
const ext = parts[parts.length - 1].toLowerCase();
|
||||
const matches = file.name.match(CIDERPRESS_EXTENSION);
|
||||
@ -322,7 +321,7 @@ function doLoadLocal(drive: DriveNumber, file: File, options: Partial<LoadOption
|
||||
[, type, aux] = matches;
|
||||
}
|
||||
if (includes(DISK_FORMATS, ext)) {
|
||||
doLoadLocalDisk(drive, file);
|
||||
doLoadLocalDisk(driveNo, file);
|
||||
} else if (includes(TAPE_TYPES, ext)) {
|
||||
tape.doLoadLocalTape(file);
|
||||
} else if (BIN_TYPES.includes(ext) || type === '06' || options.address) {
|
||||
@ -366,7 +365,7 @@ function doLoadBinary(file: File, options: LoadOptions) {
|
||||
fileReader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
function doLoadLocalDisk(drive: DriveNumber, file: File) {
|
||||
function doLoadLocalDisk(driveNo: DriveNumber, file: File) {
|
||||
loadingStart();
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = function () {
|
||||
@ -377,14 +376,14 @@ function doLoadLocalDisk(drive: DriveNumber, file: File) {
|
||||
|
||||
// Remove any json file reference
|
||||
const files = hup().split('|');
|
||||
files[drive - 1] = '';
|
||||
files[driveNo - 1] = '';
|
||||
document.location.hash = files.join('|');
|
||||
|
||||
if (includes(DISK_FORMATS, ext)) {
|
||||
if (result.byteLength >= 800 * 1024) {
|
||||
if (
|
||||
includes(BLOCK_FORMATS, ext) &&
|
||||
_massStorage.setBinary(drive, name, ext, result)
|
||||
_massStorage.setBinary(driveNo, name, ext, result)
|
||||
) {
|
||||
initGamepad();
|
||||
} else {
|
||||
@ -393,7 +392,7 @@ function doLoadLocalDisk(drive: DriveNumber, file: File) {
|
||||
} else {
|
||||
if (
|
||||
includes(FLOPPY_FORMATS, ext) &&
|
||||
_disk2.setBinary(drive, name, ext, result)
|
||||
_disk2.setBinary(driveNo, name, ext, result)
|
||||
) {
|
||||
initGamepad();
|
||||
} else {
|
||||
@ -406,7 +405,7 @@ function doLoadLocalDisk(drive: DriveNumber, file: File) {
|
||||
fileReader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
export function doLoadHTTP(drive: DriveNumber, url?: string) {
|
||||
export function doLoadHTTP(driveNo: DriveNumber, url?: string) {
|
||||
if (!url) {
|
||||
MicroModal.close('http-modal');
|
||||
}
|
||||
@ -454,13 +453,13 @@ export function doLoadHTTP(drive: DriveNumber, url?: string) {
|
||||
if (includes(DISK_FORMATS, ext)) {
|
||||
if (data.byteLength >= 800 * 1024) {
|
||||
if (includes(BLOCK_FORMATS, ext)) {
|
||||
_massStorage.setBinary(drive, name, ext, data);
|
||||
_massStorage.setBinary(driveNo, name, ext, data);
|
||||
initGamepad();
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
includes(FLOPPY_FORMATS, ext) &&
|
||||
_disk2.setBinary(drive, name, ext, data)
|
||||
_disk2.setBinary(driveNo, name, ext, data)
|
||||
) {
|
||||
initGamepad();
|
||||
}
|
||||
@ -547,11 +546,11 @@ function updateSoundButton(on: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
function dumpDisk(drive: DriveNumber) {
|
||||
function dumpDisk(driveNo: DriveNumber) {
|
||||
const wind = window.open('', '_blank')!;
|
||||
wind.document.title = driveLights.label(drive);
|
||||
wind.document.title = driveLights.label(driveNo);
|
||||
wind.document.write('<pre>');
|
||||
wind.document.write(_disk2.getJSON(drive, true));
|
||||
wind.document.write(_disk2.getJSON(driveNo, true));
|
||||
wind.document.write('</pre>');
|
||||
wind.document.close();
|
||||
}
|
||||
@ -586,7 +585,7 @@ export function selectCategory() {
|
||||
option.value = file.filename;
|
||||
option.innerText = name;
|
||||
diskSelect.append(option);
|
||||
if (disk_cur_name[_currentDrive] === name) {
|
||||
if (disk_cur_name[driveNo] === name) {
|
||||
option.selected = true;
|
||||
}
|
||||
}
|
||||
@ -603,7 +602,7 @@ export function clickDisk(event: MouseEvent|KeyboardEvent) {
|
||||
}
|
||||
|
||||
/** Called to load disks from the local catalog. */
|
||||
function loadDisk(drive: DriveNumber, disk: JSONDisk) {
|
||||
function loadDisk(driveNo: DriveNumber, disk: JSONDisk) {
|
||||
let name = disk.name;
|
||||
const category = disk.category!; // all disks in the local catalog have a category
|
||||
|
||||
@ -611,10 +610,10 @@ function loadDisk(drive: DriveNumber, disk: JSONDisk) {
|
||||
name += ' - ' + disk.disk;
|
||||
}
|
||||
|
||||
disk_cur_cat[drive] = category;
|
||||
disk_cur_name[drive] = name;
|
||||
disk_cur_cat[driveNo] = category;
|
||||
disk_cur_name[driveNo] = name;
|
||||
|
||||
_disk2.setDisk(drive, disk);
|
||||
_disk2.setDisk(driveNo, disk);
|
||||
initGamepad(disk.gamepad);
|
||||
}
|
||||
|
||||
@ -654,16 +653,16 @@ type LocalDiskIndex = {
|
||||
[name: string]: string;
|
||||
};
|
||||
|
||||
function saveLocalStorage(drive: DriveNumber, name: string) {
|
||||
function saveLocalStorage(driveNo: DriveNumber, name: string) {
|
||||
const diskIndex = JSON.parse(window.localStorage.getItem('diskIndex') || '{}') as LocalDiskIndex;
|
||||
|
||||
const json = _disk2.getJSON(drive);
|
||||
const json = _disk2.getJSON(driveNo);
|
||||
diskIndex[name] = json;
|
||||
|
||||
window.localStorage.setItem('diskIndex', JSON.stringify(diskIndex));
|
||||
|
||||
driveLights.label(drive, name);
|
||||
driveLights.dirty(drive, false);
|
||||
driveLights.label(driveNo, name);
|
||||
driveLights.dirty(driveNo, false);
|
||||
updateLocalStorage();
|
||||
}
|
||||
|
||||
@ -677,12 +676,12 @@ function deleteLocalStorage(name: string) {
|
||||
updateLocalStorage();
|
||||
}
|
||||
|
||||
function loadLocalStorage(drive: DriveNumber, name: string) {
|
||||
function loadLocalStorage(driveNo: DriveNumber, name: string) {
|
||||
const diskIndex = JSON.parse(window.localStorage.getItem('diskIndex') || '{}') as LocalDiskIndex;
|
||||
if (diskIndex[name]) {
|
||||
_disk2.setJSON(drive, diskIndex[name]);
|
||||
driveLights.label(drive, name);
|
||||
driveLights.dirty(drive, false);
|
||||
_disk2.setJSON(driveNo, diskIndex[name]);
|
||||
driveLights.label(driveNo, name);
|
||||
driveLights.dirty(driveNo, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ import { Callbacks } from '../cards/disk2';
|
||||
import type { DriveNumber } from '../formats/types';
|
||||
|
||||
export default class DriveLights implements Callbacks {
|
||||
public driveLight(drive: DriveNumber, on: boolean) {
|
||||
const disk = document.querySelector<HTMLElement>(`#disk${drive}`);
|
||||
public driveLight(driveNo: DriveNumber, on: boolean) {
|
||||
const disk = document.querySelector<HTMLElement>(`#disk${driveNo}`);
|
||||
if (disk) {
|
||||
disk.style.backgroundImage =
|
||||
on ? 'url(css/red-on-16.png)' :
|
||||
@ -11,12 +11,12 @@ export default class DriveLights implements Callbacks {
|
||||
}
|
||||
}
|
||||
|
||||
public dirty(_drive: DriveNumber, _dirty: boolean) {
|
||||
public dirty(_driveNo: DriveNumber, _dirty: boolean) {
|
||||
// document.querySelector('#disksave' + drive).disabled = !dirty;
|
||||
}
|
||||
|
||||
public label(drive: DriveNumber, label?: string, side?: string) {
|
||||
const labelElement = document.querySelector<HTMLElement>(`#disk-label${drive}`);
|
||||
public label(driveNo: DriveNumber, label?: string, side?: string) {
|
||||
const labelElement = document.querySelector<HTMLElement>(`#disk-label${driveNo}`);
|
||||
let labelText = '';
|
||||
if (labelElement) {
|
||||
labelText = labelElement.innerText;
|
||||
|
@ -66,8 +66,8 @@ describe('DiskII', () => {
|
||||
|
||||
const state = diskII.getState();
|
||||
// These are just arbitrary changes, not an exhaustive list of fields.
|
||||
state.skip = 1;
|
||||
state.controllerState.drive = 2;
|
||||
(state.drives[1].driver as {skip:number}).skip = 1;
|
||||
state.controllerState.driveNo = 2;
|
||||
state.controllerState.latch = 0x42;
|
||||
state.controllerState.on = true;
|
||||
state.controllerState.q7 = true;
|
||||
@ -97,7 +97,7 @@ describe('DiskII', () => {
|
||||
expect(callbacks.label).toHaveBeenCalledWith(2, 'Disk 2', undefined);
|
||||
|
||||
expect(callbacks.dirty).toHaveBeenCalledTimes(2);
|
||||
expect(callbacks.dirty).toHaveBeenCalledWith(1, true);
|
||||
expect(callbacks.dirty).toHaveBeenCalledWith(1, false);
|
||||
expect(callbacks.dirty).toHaveBeenCalledWith(2, false);
|
||||
});
|
||||
|
||||
@ -760,11 +760,11 @@ class TestDiskReader {
|
||||
nibbles = 0;
|
||||
diskII: DiskII;
|
||||
|
||||
constructor(drive: DriveNumber, label: string, image: ArrayBufferLike, apple2IO: Apple2IO, callbacks: Callbacks) {
|
||||
constructor(driveNo: DriveNumber, label: string, image: ArrayBufferLike, apple2IO: Apple2IO, callbacks: Callbacks) {
|
||||
mocked(apple2IO).cycles.mockImplementation(() => this.cycles);
|
||||
|
||||
this.diskII = new DiskII(apple2IO, callbacks);
|
||||
this.diskII.setBinary(drive, label, 'woz', image);
|
||||
this.diskII.setBinary(driveNo, label, 'woz', image);
|
||||
}
|
||||
|
||||
readNibble(): byte {
|
||||
@ -824,7 +824,7 @@ class TestDiskReader {
|
||||
|
||||
rawTracks() {
|
||||
// NOTE(flan): Hack to access private properties.
|
||||
const disk = (this.diskII as unknown as { curDisk: WozDisk }).curDisk;
|
||||
const disk = (this.diskII as unknown as { disks: WozDisk[] }).disks[1];
|
||||
const result: Uint8Array[] = [];
|
||||
for (let i = 0; i < disk.rawTracks.length; i++) {
|
||||
result[i] = disk.rawTracks[i].slice(0);
|
||||
|
@ -19,7 +19,7 @@ debug('Worker loaded');
|
||||
addEventListener('message', (message: MessageEvent<FormatWorkerMessage>) => {
|
||||
debug('Worker started', message.type);
|
||||
const data = message.data;
|
||||
const { drive } = data.payload;
|
||||
const { driveNo } = data.payload;
|
||||
let disk: FloppyDisk | null = null;
|
||||
|
||||
switch (data.type) {
|
||||
@ -45,7 +45,7 @@ addEventListener('message', (message: MessageEvent<FormatWorkerMessage>) => {
|
||||
const response: DiskProcessedResponse = {
|
||||
type: DISK_PROCESSED,
|
||||
payload: {
|
||||
drive,
|
||||
driveNo,
|
||||
disk
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user