2022-07-23 12:00:38 -07:00
|
|
|
import { h, Fragment } from 'preact';
|
|
|
|
import { useMemo } from 'preact/hooks';
|
|
|
|
import cs from 'classnames';
|
|
|
|
import { Apple2 as Apple2Impl } from 'js/apple2';
|
Split disk data out into its own record (#158)
* Harmonize drive and disk type hierarchies
Before, the `XXXDrive` and `XXXDisk` type hierarchies were similar,
but not exactly the same. For example, `encoding` and `format` were
missing on some `XXXDisk` types where they existed on the `XXXDrive`
type. This change attempts to bring the hierarchies closer together.
However, the biggest visible consequence is the introduction of the
`FLOPPY_FORMATS` array and its associated `FloppyFormat` type. This
replaces `NIBBLE_FORMATS` in most places. A couple of new type guards
for disk formats and disks have been added as well.
All tests pass, everything compiles with no errors, and both WOZ and
nibble format disks load in the emulator.
* Move disk data to a `disk` field in the drive
Before, disk data was mixed in with state about the drive itself (like
track, motor phase, etc.). This made it hard to know exactly what data
was necessary for different image formats.
Now, the disk data is in a `disk` field whose type depends on the
drive type. This makes responisbility a bit easier.
One oddity, though, is that the `Drive` has metadata _and_ the `Disk`
has metadata. When a disk is in the drive, these should be `===`, but
when there is no disk in the drive, obviously only the drive metadata
is set.
All tests pass, everything compiles, and both WOZ and nibble disks
work in the emulator (both preact and classic).
* Squash the `Drive` type hierarchy
Before, the type of the drive depended on the type of the disk in the
drive. Thus, `NibbleDrive` contained a `NibbleDisk` and a `WozDrive`
contained a `WozDisk`. With the extraction of the disk data to a
single field, this type hierarchy makes no sense. Instead, it
suffices to check the type of the disk.
This change removes the `NibbleDrive` and `WozDrive` types and type
guards, checking the disk type where necessary. This change also
introduces the `NoFloppyDisk` type to represent the lack of a
disk. This allows the drive to have metadata, for one.
All tests pass, everything compiles, and both WOZ and nibble disks
work locally.
* Use more destructuring assignment
Now, more places use constructs like:
```TypeScript
const { metadata, readOnly, track, head, phase, dirty } = drive;
return {
disk: getDiskState(drive.disk),
metadata: {...metadata},
readOnly,
track,
head,
phase,
dirty,
};
```
* Remove the `Disk` object from the `Drive` object
This change splits out the disk objects into a record parallel to the
drive objects. The idea is that the `Drive` structure becomes a
representation of the state of the drive that is separate from the
disk image actually in the drive. This helps in an upcoming
refactoring.
This also changes the default empty disks to be writable. While odd,
the write protect switch should be in the "off" position since there
is no disk pressing on it.
Finally, `insertDisk` now resets the head position to 0 since there is
no way of preserving the head position across disks. (Even in the real
world, the motor-off delay plus spindle spin-down would make it
impossible to know the disk head position with any accuracy.)
2022-09-17 15:41:35 +02:00
|
|
|
import { BlockDisk, DiskFormat, DriveNumber, FloppyDisk, isBlockDiskFormat, isNibbleDisk, MassStorage } from 'js/formats/types';
|
2022-07-23 12:00:38 -07:00
|
|
|
import { slot } from 'js/apple2io';
|
|
|
|
import DiskII from 'js/cards/disk2';
|
|
|
|
import SmartPort from 'js/cards/smartport';
|
|
|
|
import createDiskFrom2MG from 'js/formats/2mg';
|
|
|
|
import createBlockDisk from 'js/formats/block';
|
|
|
|
import { ProDOSVolume } from 'js/formats/prodos';
|
|
|
|
import { FILE_TYPES, STORAGE_TYPES } from 'js/formats/prodos/constants';
|
|
|
|
import { Directory } from 'js/formats/prodos/directory';
|
|
|
|
import { FileEntry } from 'js/formats/prodos/file_entry';
|
|
|
|
import { VDH } from 'js/formats/prodos/vdh';
|
|
|
|
import { toHex } from 'js/util';
|
|
|
|
|
2023-01-11 18:14:44 -08:00
|
|
|
import styles from './css/Disks.module.scss';
|
|
|
|
import debuggerStyles from './css/Debugger.module.scss';
|
2022-07-23 12:00:38 -07:00
|
|
|
import { useCallback, useState } from 'preact/hooks';
|
|
|
|
import { DOS33, FileEntry as DOSEntry, isMaybeDOS33 } from 'js/formats/dos/dos33';
|
|
|
|
import createDiskFromDOS from 'js/formats/do';
|
|
|
|
import { FileData, FileViewer } from './FileViewer';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a short date string
|
|
|
|
*
|
|
|
|
* @param date Data object
|
|
|
|
* @returns Short string date
|
|
|
|
*/
|
|
|
|
const formatDate = (date: Date) => {
|
|
|
|
return date.toLocaleString(undefined, { dateStyle: 'short', timeStyle: 'short' });
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Guard for determining whether a disk is a nibble or block based disk
|
|
|
|
*
|
|
|
|
* @param disk NibbleDisk or BlockDisk
|
|
|
|
* @returns true if is BlockDisk
|
|
|
|
*/
|
Split disk data out into its own record (#158)
* Harmonize drive and disk type hierarchies
Before, the `XXXDrive` and `XXXDisk` type hierarchies were similar,
but not exactly the same. For example, `encoding` and `format` were
missing on some `XXXDisk` types where they existed on the `XXXDrive`
type. This change attempts to bring the hierarchies closer together.
However, the biggest visible consequence is the introduction of the
`FLOPPY_FORMATS` array and its associated `FloppyFormat` type. This
replaces `NIBBLE_FORMATS` in most places. A couple of new type guards
for disk formats and disks have been added as well.
All tests pass, everything compiles with no errors, and both WOZ and
nibble format disks load in the emulator.
* Move disk data to a `disk` field in the drive
Before, disk data was mixed in with state about the drive itself (like
track, motor phase, etc.). This made it hard to know exactly what data
was necessary for different image formats.
Now, the disk data is in a `disk` field whose type depends on the
drive type. This makes responisbility a bit easier.
One oddity, though, is that the `Drive` has metadata _and_ the `Disk`
has metadata. When a disk is in the drive, these should be `===`, but
when there is no disk in the drive, obviously only the drive metadata
is set.
All tests pass, everything compiles, and both WOZ and nibble disks
work in the emulator (both preact and classic).
* Squash the `Drive` type hierarchy
Before, the type of the drive depended on the type of the disk in the
drive. Thus, `NibbleDrive` contained a `NibbleDisk` and a `WozDrive`
contained a `WozDisk`. With the extraction of the disk data to a
single field, this type hierarchy makes no sense. Instead, it
suffices to check the type of the disk.
This change removes the `NibbleDrive` and `WozDrive` types and type
guards, checking the disk type where necessary. This change also
introduces the `NoFloppyDisk` type to represent the lack of a
disk. This allows the drive to have metadata, for one.
All tests pass, everything compiles, and both WOZ and nibble disks
work locally.
* Use more destructuring assignment
Now, more places use constructs like:
```TypeScript
const { metadata, readOnly, track, head, phase, dirty } = drive;
return {
disk: getDiskState(drive.disk),
metadata: {...metadata},
readOnly,
track,
head,
phase,
dirty,
};
```
* Remove the `Disk` object from the `Drive` object
This change splits out the disk objects into a record parallel to the
drive objects. The idea is that the `Drive` structure becomes a
representation of the state of the drive that is separate from the
disk image actually in the drive. This helps in an upcoming
refactoring.
This also changes the default empty disks to be writable. While odd,
the write protect switch should be in the "off" position since there
is no disk pressing on it.
Finally, `insertDisk` now resets the head position to 0 since there is
no way of preserving the head position across disks. (Even in the real
world, the motor-off delay plus spindle spin-down would make it
impossible to know the disk head position with any accuracy.)
2022-09-17 15:41:35 +02:00
|
|
|
function isBlockDisk(disk: FloppyDisk | BlockDisk): disk is BlockDisk {
|
2022-07-23 12:00:38 -07:00
|
|
|
return !!((disk as BlockDisk).blocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Props for FileListing component
|
|
|
|
*/
|
|
|
|
interface FileListingProps {
|
|
|
|
volume: ProDOSVolume;
|
|
|
|
fileEntry: FileEntry;
|
|
|
|
depth: number;
|
|
|
|
setFileData: (fileData: FileData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a ProDOS file entry.
|
|
|
|
*
|
|
|
|
* @param depth Depth of listing from root
|
|
|
|
* @param fileEntry ProDOS file entry to display
|
|
|
|
* @returns FileListing component
|
|
|
|
*/
|
|
|
|
const FileListing = ({ depth, fileEntry, setFileData }: FileListingProps) => {
|
|
|
|
const deleted = fileEntry.storageType === STORAGE_TYPES.DELETED;
|
|
|
|
const doSetFileData = useCallback(() => {
|
|
|
|
const binary = fileEntry.getFileData();
|
|
|
|
const text = fileEntry.getFileText();
|
|
|
|
if (binary && text) {
|
|
|
|
setFileData({
|
|
|
|
binary,
|
|
|
|
text,
|
|
|
|
fileName: fileEntry.name,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [fileEntry, setFileData]);
|
|
|
|
return (
|
|
|
|
<tr>
|
|
|
|
<td
|
|
|
|
className={cs(styles.filename, { [styles.deleted]: deleted })}
|
|
|
|
title={fileEntry.name}
|
|
|
|
onClick={doSetFileData}
|
|
|
|
>
|
|
|
|
{'| '.repeat(depth)}
|
|
|
|
{deleted ?
|
|
|
|
<i className="fas fa-file-circle-xmark" /> :
|
|
|
|
<i className="fas fa-file" />
|
|
|
|
}
|
|
|
|
{' '}
|
|
|
|
{fileEntry.name}
|
|
|
|
</td>
|
|
|
|
<td>{FILE_TYPES[fileEntry.fileType] ?? `$${toHex(fileEntry.fileType)}`}</td>
|
|
|
|
<td>{`$${toHex(fileEntry.auxType, 4)}`}</td>
|
|
|
|
<td>{fileEntry.blocksUsed}</td>
|
|
|
|
<td>{formatDate(fileEntry.creation)}</td>
|
|
|
|
<td>{formatDate(fileEntry.lastMod)}</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Props for DirectoryListing Component.
|
|
|
|
*/
|
|
|
|
interface DirectoryListingProps {
|
|
|
|
volume: ProDOSVolume;
|
|
|
|
dirEntry: VDH | Directory;
|
|
|
|
depth: number;
|
|
|
|
setFileData: (fileData: FileData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays information about a ProDOS directory, recursing through child
|
|
|
|
* directories.
|
|
|
|
*
|
|
|
|
* @param volume ProDOS volume
|
|
|
|
* @param depth Current directory depth
|
|
|
|
* @param dirEntry Current directory entry to display
|
|
|
|
* @returns DirectoryListing component
|
|
|
|
*/
|
|
|
|
const DirectoryListing = ({ volume, depth, dirEntry, setFileData }: DirectoryListingProps) => {
|
|
|
|
const [open, setOpen] = useState(depth === 0);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<tr>
|
|
|
|
<td
|
|
|
|
className={styles.filename}
|
|
|
|
onClick={() => setOpen((open) => !open)}
|
|
|
|
title={dirEntry.name}
|
|
|
|
>
|
|
|
|
{'| '.repeat(depth)}
|
|
|
|
<i className={cs('fas', { 'fa-folder-open': open, 'fa-folder-closed': !open })} />
|
|
|
|
{' '}
|
|
|
|
{dirEntry.name}
|
|
|
|
</td>
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
<td>{formatDate(dirEntry.creation)}</td>
|
|
|
|
<td></td>
|
|
|
|
</tr>
|
|
|
|
{open && dirEntry.entries.map((fileEntry, idx) => {
|
|
|
|
if (fileEntry.storageType === STORAGE_TYPES.DIRECTORY) {
|
|
|
|
const dirEntry = new Directory(volume, fileEntry);
|
|
|
|
return <DirectoryListing
|
|
|
|
key={idx}
|
|
|
|
depth={depth + 1}
|
|
|
|
volume={volume}
|
|
|
|
dirEntry={dirEntry}
|
|
|
|
setFileData={setFileData}
|
|
|
|
/>;
|
|
|
|
} else {
|
|
|
|
return <FileListing
|
|
|
|
key={idx}
|
|
|
|
depth={depth + 1}
|
|
|
|
volume={volume}
|
|
|
|
fileEntry={fileEntry}
|
|
|
|
setFileData={setFileData}
|
|
|
|
/>;
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Props for CatalogEntry component
|
|
|
|
*/
|
|
|
|
interface CatalogEntryProps {
|
|
|
|
dos: DOS33;
|
|
|
|
fileEntry: DOSEntry;
|
|
|
|
setFileData: (fileData: FileData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component for a single DOS 3.x catalog entry
|
|
|
|
*
|
|
|
|
* @param entry Catalog entry to display
|
|
|
|
* @returns CatalogEntry component
|
|
|
|
*/
|
|
|
|
const CatalogEntry = ({ dos, fileEntry, setFileData }: CatalogEntryProps) => {
|
|
|
|
const doSetFileData = useCallback(() => {
|
|
|
|
const { data } = dos.readFile(fileEntry);
|
|
|
|
setFileData({
|
|
|
|
binary: data,
|
|
|
|
text: dos.dumpFile(fileEntry),
|
|
|
|
fileName: fileEntry.name,
|
|
|
|
});
|
|
|
|
}, [dos, fileEntry, setFileData]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tr onClick={doSetFileData}>
|
|
|
|
<td className={cs(styles.filename, { [styles.deleted]: fileEntry.deleted })}>
|
|
|
|
{fileEntry.locked && <i className="fas fa-lock" />}
|
|
|
|
{' '}
|
|
|
|
{fileEntry.name}
|
|
|
|
</td>
|
|
|
|
<td>{fileEntry.type}</td>
|
|
|
|
<td>{fileEntry.size}</td>
|
|
|
|
<td></td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Catalog component props
|
|
|
|
*/
|
|
|
|
interface CatalogProps {
|
|
|
|
dos: DOS33;
|
|
|
|
setFileData: (fileData: FileData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOS 3.3 disk catalog component
|
|
|
|
*
|
|
|
|
* @param dos DOS 3.3 disk object
|
|
|
|
* @returns Catalog component
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Catalog = ({ dos, setFileData }: CatalogProps) => {
|
|
|
|
const catalog = useMemo(() => dos.readCatalog(), [dos]);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{catalog.map((fileEntry, idx) => (
|
|
|
|
<CatalogEntry
|
|
|
|
key={idx}
|
|
|
|
dos={dos}
|
|
|
|
fileEntry={fileEntry}
|
|
|
|
setFileData={setFileData}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Props for DiskInfo component
|
|
|
|
*/
|
|
|
|
interface DiskInfoProps {
|
|
|
|
massStorage: MassStorage<DiskFormat>;
|
2022-09-19 09:07:27 +02:00
|
|
|
driveNo: DriveNumber;
|
2022-07-23 12:00:38 -07:00
|
|
|
setFileData: (fileData: FileData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Top level disk info component, handles determining what sort of disk
|
|
|
|
* is present and using the appropriate sub-component depending on whether
|
|
|
|
* it's a ProDOS block disk or a DOS 3.3 disk.
|
|
|
|
*
|
|
|
|
* TODO(whscullin): Does not handle woz or 13 sector.
|
|
|
|
*
|
|
|
|
* @param massStorage The storage device
|
|
|
|
* @param drive The drive number
|
|
|
|
* @returns DiskInfo component
|
|
|
|
*/
|
2022-09-19 09:07:27 +02:00
|
|
|
const DiskInfo = ({ massStorage, driveNo, setFileData }: DiskInfoProps) => {
|
2022-07-23 12:00:38 -07:00
|
|
|
const disk = useMemo(() => {
|
2022-09-19 09:07:27 +02:00
|
|
|
const massStorageData = massStorage.getBinary(driveNo, 'po');
|
2022-07-23 12:00:38 -07:00
|
|
|
if (massStorageData) {
|
Floppy controller refactorings 1 (#155)
* Add `DiskMetada` to the `Disk` interface
Before, metadata about the image, such as name, side, etc. was mixed
in with actual disk image information. This change breaks that
information into a separate structure called `DiskMetadata`.
Currently, the only two fields are `name` and `side`, but the idea is
that more fields could be added as necessary, like a description, a
scan of the disk or label, etc. In a follow-on change, the default
write-protection status will come from the metadata as well.
The current implementation copies the metadata when saving/restoring
state, loading disk images, etc. In the future, the metadata should
passed around until the format is required to change (like saving one
disk image format as another). Likewise, in the future, in may be
desirable to be able to override the disk image metadata with
user-supplied metadata. This could be use, for example, to
temporarily add or remove write-protection from a disk image.
All existing tests pass and the emulator builds with no errors.
* Rename `writeMode` to `q7`
Before, nibble disk emulation used the `writeMode` field to keep track
of whether the drive should be read from or written to, but the WOZ
emulation used `q7` to keep track of the same state.
This change renames `writeMode` to `q7` because it more accurately
reflects the state of the Disk II controller as specified in the
manuals, DOS source, and, especially, _Understanding the Apple //e_ by
Jim Sather.
* Remove the coil state
Before, `q` captured the state of the coils. But it was never read.
This change just deletes it.
* Use the bootstrap and sequencer ROMs with indirection
Before, the contents of the bootstrap ROM and sequencer ROM were set
directly on fields of the controller. These were not saved or
restored with the state in `getState` and `setState`. (It would have
been very space inefficient if they had).
Now, these ROMs are used from constants indexed by the number of
sectors the card supports. This, in turn, means that if the number of
sectors is saved with the state, it can be easily restored.
* Split out the Disk II controller state
This change factors the emulated hardware state into a separate
structure in the Disk II controller. The idea is that this hardware
state will be able to be shared with the WOZ and nibble disk code
instead of sharing _all_ of the controller state (like callbacks and
so forth).
* Factor out disk insertion
Before, several places in the code essentially inserted a new disk
image into the drive, which similar—but not always exactly the
same—code. Now there is an `insertDisk` method that is responsible
for inserting a new `FloppyDisk`.
All tests pass, everything compiles, manually tested nibble disks and
WOZ disks.
2022-09-01 03:55:01 +02:00
|
|
|
const { data, readOnly, ext } = massStorageData;
|
|
|
|
const { name } = massStorageData.metadata;
|
Split disk data out into its own record (#158)
* Harmonize drive and disk type hierarchies
Before, the `XXXDrive` and `XXXDisk` type hierarchies were similar,
but not exactly the same. For example, `encoding` and `format` were
missing on some `XXXDisk` types where they existed on the `XXXDrive`
type. This change attempts to bring the hierarchies closer together.
However, the biggest visible consequence is the introduction of the
`FLOPPY_FORMATS` array and its associated `FloppyFormat` type. This
replaces `NIBBLE_FORMATS` in most places. A couple of new type guards
for disk formats and disks have been added as well.
All tests pass, everything compiles with no errors, and both WOZ and
nibble format disks load in the emulator.
* Move disk data to a `disk` field in the drive
Before, disk data was mixed in with state about the drive itself (like
track, motor phase, etc.). This made it hard to know exactly what data
was necessary for different image formats.
Now, the disk data is in a `disk` field whose type depends on the
drive type. This makes responisbility a bit easier.
One oddity, though, is that the `Drive` has metadata _and_ the `Disk`
has metadata. When a disk is in the drive, these should be `===`, but
when there is no disk in the drive, obviously only the drive metadata
is set.
All tests pass, everything compiles, and both WOZ and nibble disks
work in the emulator (both preact and classic).
* Squash the `Drive` type hierarchy
Before, the type of the drive depended on the type of the disk in the
drive. Thus, `NibbleDrive` contained a `NibbleDisk` and a `WozDrive`
contained a `WozDisk`. With the extraction of the disk data to a
single field, this type hierarchy makes no sense. Instead, it
suffices to check the type of the disk.
This change removes the `NibbleDrive` and `WozDrive` types and type
guards, checking the disk type where necessary. This change also
introduces the `NoFloppyDisk` type to represent the lack of a
disk. This allows the drive to have metadata, for one.
All tests pass, everything compiles, and both WOZ and nibble disks
work locally.
* Use more destructuring assignment
Now, more places use constructs like:
```TypeScript
const { metadata, readOnly, track, head, phase, dirty } = drive;
return {
disk: getDiskState(drive.disk),
metadata: {...metadata},
readOnly,
track,
head,
phase,
dirty,
};
```
* Remove the `Disk` object from the `Drive` object
This change splits out the disk objects into a record parallel to the
drive objects. The idea is that the `Drive` structure becomes a
representation of the state of the drive that is separate from the
disk image actually in the drive. This helps in an upcoming
refactoring.
This also changes the default empty disks to be writable. While odd,
the write protect switch should be in the "off" position since there
is no disk pressing on it.
Finally, `insertDisk` now resets the head position to 0 since there is
no way of preserving the head position across disks. (Even in the real
world, the motor-off delay plus spindle spin-down would make it
impossible to know the disk head position with any accuracy.)
2022-09-17 15:41:35 +02:00
|
|
|
let disk: BlockDisk | FloppyDisk | null = null;
|
2022-07-23 12:00:38 -07:00
|
|
|
if (ext === '2mg') {
|
|
|
|
disk = createDiskFrom2MG({
|
|
|
|
name,
|
|
|
|
rawData: data,
|
|
|
|
readOnly,
|
|
|
|
volume: 254,
|
|
|
|
});
|
|
|
|
} else if (data.byteLength < 800 * 1024) {
|
2022-09-19 09:07:27 +02:00
|
|
|
const doData = massStorage.getBinary(driveNo, 'do');
|
2022-07-23 12:00:38 -07:00
|
|
|
if (doData) {
|
|
|
|
if (isMaybeDOS33(doData)) {
|
|
|
|
disk = createDiskFromDOS({
|
|
|
|
name,
|
|
|
|
rawData: doData.data,
|
|
|
|
readOnly,
|
|
|
|
volume: 254,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Split disk data out into its own record (#158)
* Harmonize drive and disk type hierarchies
Before, the `XXXDrive` and `XXXDisk` type hierarchies were similar,
but not exactly the same. For example, `encoding` and `format` were
missing on some `XXXDisk` types where they existed on the `XXXDrive`
type. This change attempts to bring the hierarchies closer together.
However, the biggest visible consequence is the introduction of the
`FLOPPY_FORMATS` array and its associated `FloppyFormat` type. This
replaces `NIBBLE_FORMATS` in most places. A couple of new type guards
for disk formats and disks have been added as well.
All tests pass, everything compiles with no errors, and both WOZ and
nibble format disks load in the emulator.
* Move disk data to a `disk` field in the drive
Before, disk data was mixed in with state about the drive itself (like
track, motor phase, etc.). This made it hard to know exactly what data
was necessary for different image formats.
Now, the disk data is in a `disk` field whose type depends on the
drive type. This makes responisbility a bit easier.
One oddity, though, is that the `Drive` has metadata _and_ the `Disk`
has metadata. When a disk is in the drive, these should be `===`, but
when there is no disk in the drive, obviously only the drive metadata
is set.
All tests pass, everything compiles, and both WOZ and nibble disks
work in the emulator (both preact and classic).
* Squash the `Drive` type hierarchy
Before, the type of the drive depended on the type of the disk in the
drive. Thus, `NibbleDrive` contained a `NibbleDisk` and a `WozDrive`
contained a `WozDisk`. With the extraction of the disk data to a
single field, this type hierarchy makes no sense. Instead, it
suffices to check the type of the disk.
This change removes the `NibbleDrive` and `WozDrive` types and type
guards, checking the disk type where necessary. This change also
introduces the `NoFloppyDisk` type to represent the lack of a
disk. This allows the drive to have metadata, for one.
All tests pass, everything compiles, and both WOZ and nibble disks
work locally.
* Use more destructuring assignment
Now, more places use constructs like:
```TypeScript
const { metadata, readOnly, track, head, phase, dirty } = drive;
return {
disk: getDiskState(drive.disk),
metadata: {...metadata},
readOnly,
track,
head,
phase,
dirty,
};
```
* Remove the `Disk` object from the `Drive` object
This change splits out the disk objects into a record parallel to the
drive objects. The idea is that the `Drive` structure becomes a
representation of the state of the drive that is separate from the
disk image actually in the drive. This helps in an upcoming
refactoring.
This also changes the default empty disks to be writable. While odd,
the write protect switch should be in the "off" position since there
is no disk pressing on it.
Finally, `insertDisk` now resets the head position to 0 since there is
no way of preserving the head position across disks. (Even in the real
world, the motor-off delay plus spindle spin-down would make it
impossible to know the disk head position with any accuracy.)
2022-09-17 15:41:35 +02:00
|
|
|
if (!disk && isBlockDiskFormat(ext)) {
|
|
|
|
disk = createBlockDisk(ext, {
|
2022-07-23 12:00:38 -07:00
|
|
|
name,
|
|
|
|
rawData: data,
|
|
|
|
readOnly,
|
|
|
|
volume: 254,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return disk;
|
|
|
|
}
|
|
|
|
return null;
|
2022-09-19 09:07:27 +02:00
|
|
|
}, [massStorage, driveNo]);
|
2022-07-23 12:00:38 -07:00
|
|
|
|
|
|
|
if (disk) {
|
|
|
|
try {
|
|
|
|
if (isBlockDisk(disk)) {
|
|
|
|
if (disk.blocks.length) {
|
|
|
|
const prodos = new ProDOSVolume(disk);
|
|
|
|
const { totalBlocks } = prodos.vdh();
|
|
|
|
const freeCount = prodos.bitMap().freeBlocks().length;
|
|
|
|
const usedCount = totalBlocks - freeCount;
|
|
|
|
return (
|
|
|
|
<div className={styles.volume}>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className={styles.filename}>Filename</th>
|
|
|
|
<th className={styles.type}>Type</th>
|
|
|
|
<th className={styles.aux}>Aux</th>
|
|
|
|
<th className={styles.blocks}>Blocks</th>
|
|
|
|
<th className={styles.created}>Created</th>
|
|
|
|
<th className={styles.modified}>Modified</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<DirectoryListing
|
|
|
|
depth={0}
|
|
|
|
volume={prodos}
|
|
|
|
dirEntry={prodos.vdh()}
|
|
|
|
setFileData={setFileData}
|
|
|
|
/>
|
|
|
|
</tbody>
|
|
|
|
<tfoot>
|
|
|
|
<tr>
|
|
|
|
<td colSpan={1}>Blocks Free: {freeCount}</td>
|
|
|
|
<td colSpan={3}>Used: {usedCount}</td>
|
|
|
|
<td colSpan={2}>Total: {totalBlocks}</td>
|
|
|
|
</tr>
|
|
|
|
</tfoot>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
Split disk data out into its own record (#158)
* Harmonize drive and disk type hierarchies
Before, the `XXXDrive` and `XXXDisk` type hierarchies were similar,
but not exactly the same. For example, `encoding` and `format` were
missing on some `XXXDisk` types where they existed on the `XXXDrive`
type. This change attempts to bring the hierarchies closer together.
However, the biggest visible consequence is the introduction of the
`FLOPPY_FORMATS` array and its associated `FloppyFormat` type. This
replaces `NIBBLE_FORMATS` in most places. A couple of new type guards
for disk formats and disks have been added as well.
All tests pass, everything compiles with no errors, and both WOZ and
nibble format disks load in the emulator.
* Move disk data to a `disk` field in the drive
Before, disk data was mixed in with state about the drive itself (like
track, motor phase, etc.). This made it hard to know exactly what data
was necessary for different image formats.
Now, the disk data is in a `disk` field whose type depends on the
drive type. This makes responisbility a bit easier.
One oddity, though, is that the `Drive` has metadata _and_ the `Disk`
has metadata. When a disk is in the drive, these should be `===`, but
when there is no disk in the drive, obviously only the drive metadata
is set.
All tests pass, everything compiles, and both WOZ and nibble disks
work in the emulator (both preact and classic).
* Squash the `Drive` type hierarchy
Before, the type of the drive depended on the type of the disk in the
drive. Thus, `NibbleDrive` contained a `NibbleDisk` and a `WozDrive`
contained a `WozDisk`. With the extraction of the disk data to a
single field, this type hierarchy makes no sense. Instead, it
suffices to check the type of the disk.
This change removes the `NibbleDrive` and `WozDrive` types and type
guards, checking the disk type where necessary. This change also
introduces the `NoFloppyDisk` type to represent the lack of a
disk. This allows the drive to have metadata, for one.
All tests pass, everything compiles, and both WOZ and nibble disks
work locally.
* Use more destructuring assignment
Now, more places use constructs like:
```TypeScript
const { metadata, readOnly, track, head, phase, dirty } = drive;
return {
disk: getDiskState(drive.disk),
metadata: {...metadata},
readOnly,
track,
head,
phase,
dirty,
};
```
* Remove the `Disk` object from the `Drive` object
This change splits out the disk objects into a record parallel to the
drive objects. The idea is that the `Drive` structure becomes a
representation of the state of the drive that is separate from the
disk image actually in the drive. This helps in an upcoming
refactoring.
This also changes the default empty disks to be writable. While odd,
the write protect switch should be in the "off" position since there
is no disk pressing on it.
Finally, `insertDisk` now resets the head position to 0 since there is
no way of preserving the head position across disks. (Even in the real
world, the motor-off delay plus spindle spin-down would make it
impossible to know the disk head position with any accuracy.)
2022-09-17 15:41:35 +02:00
|
|
|
} else if (isNibbleDisk(disk)) {
|
2022-07-23 12:00:38 -07:00
|
|
|
const dos = new DOS33(disk);
|
|
|
|
return (
|
|
|
|
<div className={styles.volume}>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className={styles.filename}>Filename</th>
|
|
|
|
<th className={styles.type}>Type</th>
|
|
|
|
<th className={styles.sectors}>Sectors</th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<Catalog dos={dos} setFileData={setFileData} />
|
|
|
|
</tbody>
|
|
|
|
<tfoot>
|
|
|
|
<tr>
|
|
|
|
<td>Volume Number:</td>
|
|
|
|
<td colSpan={3}>{dos.getVolumeNumber()}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Used Sectors:</td>
|
|
|
|
<td colSpan={3}>{dos.usedSectorCount()}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Free Sectors:</td>
|
|
|
|
<td colSpan={3}>{dos.freeSectorCount()}</td>
|
|
|
|
</tr>
|
|
|
|
</tfoot>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
return <pre>Unknown volume</pre>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return <pre>No disk</pre>;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disks component props
|
|
|
|
*/
|
|
|
|
export interface DisksProps {
|
|
|
|
apple2: Apple2Impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A debugger panel that displays information about currently mounted
|
|
|
|
* disks.
|
|
|
|
*
|
|
|
|
* @param apple2 The apple2 object
|
|
|
|
* @returns Disks component
|
|
|
|
*/
|
|
|
|
export const Disks = ({ apple2 }: DisksProps) => {
|
|
|
|
const [fileData, setFileData] = useState<FileData | null>(null);
|
|
|
|
const io = apple2.getIO();
|
|
|
|
const cards: MassStorage<DiskFormat>[] = [];
|
|
|
|
|
|
|
|
const onClose = useCallback(() => {
|
|
|
|
setFileData(null);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
for (let idx = 0; idx <= 7; idx++) {
|
|
|
|
const card = io.getSlot(idx as slot);
|
|
|
|
if (card instanceof DiskII || card instanceof SmartPort) {
|
|
|
|
cards.push(card);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{cards.map((card, idx) => (
|
|
|
|
<div key={idx}>
|
|
|
|
<div className={debuggerStyles.subHeading}>
|
|
|
|
{card.constructor.name} - 1
|
|
|
|
</div>
|
2022-09-19 09:07:27 +02:00
|
|
|
<DiskInfo massStorage={card} driveNo={1} setFileData={setFileData} />
|
2022-07-23 12:00:38 -07:00
|
|
|
<div className={debuggerStyles.subHeading}>
|
|
|
|
{card.constructor.name} - 2
|
|
|
|
</div>
|
2022-09-19 09:07:27 +02:00
|
|
|
<DiskInfo massStorage={card} driveNo={2} setFileData={setFileData} />
|
2022-07-23 12:00:38 -07:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
<FileViewer fileData={fileData} onClose={onClose} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|