2022-05-10 13:52:06 +00:00
|
|
|
import type { byte, memory, MemberOf, word } from '../types';
|
2021-07-07 00:04:02 +00:00
|
|
|
import type { GamepadConfiguration } from '../ui/types';
|
2022-06-20 02:52:06 +00:00
|
|
|
import { InfoChunk } from './woz';
|
2021-07-07 00:04:02 +00:00
|
|
|
|
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 01:55:01 +00:00
|
|
|
export const SUPPORTED_SECTORS = [13, 16] as const;
|
|
|
|
export type SupportedSectors = MemberOf<typeof SUPPORTED_SECTORS>;
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
export const DRIVE_NUMBERS = [1, 2] as const;
|
|
|
|
export type DriveNumber = MemberOf<typeof DRIVE_NUMBERS>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Arguments for the disk format processors.
|
|
|
|
*/
|
|
|
|
export interface DiskOptions {
|
2022-05-10 15:04:20 +00:00
|
|
|
name: string;
|
2022-05-12 00:20:49 +00:00
|
|
|
side?: string | undefined;
|
2022-05-10 15:04:20 +00:00
|
|
|
volume: byte;
|
|
|
|
readOnly: boolean;
|
|
|
|
data?: memory[][];
|
|
|
|
rawData?: ArrayBuffer;
|
|
|
|
blockVolume?: boolean;
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 13:52:06 +00:00
|
|
|
/**
|
|
|
|
* JSON file entry format
|
|
|
|
*/
|
|
|
|
export interface DiskDescriptor {
|
|
|
|
name: string;
|
|
|
|
disk?: number;
|
|
|
|
filename: string;
|
|
|
|
e?: boolean;
|
|
|
|
category: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON binary image (not used?)
|
|
|
|
*/
|
|
|
|
export interface JSONBinaryImage {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: 'binary';
|
|
|
|
start: word;
|
|
|
|
length: word;
|
|
|
|
data: byte[];
|
|
|
|
gamepad?: GamepadConfiguration;
|
2022-05-10 13:52:06 +00:00
|
|
|
}
|
|
|
|
|
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 01:55:01 +00:00
|
|
|
/**
|
|
|
|
* Information about a disk image not directly related to the
|
|
|
|
* disk contents. For example, the name or even a scan of the
|
|
|
|
* disk label are "metadata", but the volume number is not.
|
|
|
|
*/
|
|
|
|
export interface DiskMetadata {
|
|
|
|
/** Displayed disk name */
|
|
|
|
name: string;
|
|
|
|
/** (Optional) Disk side (Front/Back, A/B) */
|
|
|
|
side?: string | undefined;
|
|
|
|
}
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
/**
|
|
|
|
* Return value from disk format processors. Describes raw disk
|
|
|
|
* data which the DiskII card can process.
|
|
|
|
*/
|
|
|
|
export interface Disk {
|
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 01:55:01 +00:00
|
|
|
metadata: DiskMetadata;
|
2022-05-10 15:04:20 +00:00
|
|
|
readOnly: boolean;
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const ENCODING_NIBBLE = 'nibble';
|
|
|
|
export const ENCODING_BITSTREAM = 'bitstream';
|
|
|
|
export const ENCODING_BLOCK = 'block';
|
|
|
|
|
2021-07-10 00:54:27 +00:00
|
|
|
export interface FloppyDisk extends Disk {
|
2022-05-10 15:04:20 +00:00
|
|
|
tracks: memory[];
|
2021-07-10 00:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface NibbleDisk extends FloppyDisk {
|
2022-05-10 15:04:20 +00:00
|
|
|
encoding: typeof ENCODING_NIBBLE;
|
|
|
|
format: DiskFormat;
|
|
|
|
volume: byte;
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 00:54:27 +00:00
|
|
|
export interface WozDisk extends FloppyDisk {
|
2022-05-10 15:04:20 +00:00
|
|
|
encoding: typeof ENCODING_BITSTREAM;
|
|
|
|
trackMap: number[];
|
|
|
|
rawTracks: Uint8Array[];
|
2022-06-20 02:52:06 +00:00
|
|
|
info: InfoChunk | undefined;
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface BlockDisk extends Disk {
|
2022-05-10 15:04:20 +00:00
|
|
|
encoding: typeof ENCODING_BLOCK;
|
|
|
|
blocks: Uint8Array[];
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File types supported by the disk format processors and
|
|
|
|
* block devices.
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const NIBBLE_FORMATS = [
|
|
|
|
'2mg',
|
|
|
|
'd13',
|
|
|
|
'do',
|
|
|
|
'dsk',
|
|
|
|
'po',
|
|
|
|
'nib',
|
|
|
|
'woz'
|
|
|
|
] as const;
|
|
|
|
|
|
|
|
export const BLOCK_FORMATS = [
|
|
|
|
'2mg',
|
|
|
|
'hdv',
|
|
|
|
'po',
|
|
|
|
] as const;
|
|
|
|
|
2022-07-23 19:00:38 +00:00
|
|
|
export const DISK_FORMATS = [...NIBBLE_FORMATS, ...BLOCK_FORMATS] as const;
|
2021-07-07 00:04:02 +00:00
|
|
|
|
|
|
|
export type NibbleFormat = MemberOf<typeof NIBBLE_FORMATS>;
|
|
|
|
export type BlockFormat = MemberOf<typeof BLOCK_FORMATS>;
|
|
|
|
export type DiskFormat = MemberOf<typeof DISK_FORMATS>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base format for JSON defined disks
|
|
|
|
*/
|
|
|
|
|
|
|
|
export class JSONDiskBase {
|
2021-11-29 00:20:25 +00:00
|
|
|
type: DiskFormat;
|
|
|
|
name: string;
|
|
|
|
disk?: string;
|
|
|
|
category?: string;
|
|
|
|
volume?: byte;
|
|
|
|
readOnly?: boolean;
|
|
|
|
gamepad?: GamepadConfiguration;
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-02 18:45:09 +00:00
|
|
|
* JSON Disk format with base64 encoded tracks with sectors
|
2021-07-07 00:04:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
export interface Base64JSONDisk extends JSONDiskBase {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: Exclude<DiskFormat, 'nib'>;
|
|
|
|
encoding: 'base64';
|
|
|
|
data: string[][];
|
2021-10-02 18:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON Disk format with base64 encoded nibblized tracks
|
|
|
|
*/
|
|
|
|
|
|
|
|
export interface Base64JSONNibbleDisk extends JSONDiskBase {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: 'nib';
|
|
|
|
encoding: 'base64';
|
|
|
|
data: string[];
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON Disk format with byte array tracks
|
|
|
|
*/
|
|
|
|
|
|
|
|
export interface BinaryJSONDisk extends JSONDiskBase {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: DiskFormat;
|
|
|
|
encoding: 'binary';
|
|
|
|
data: memory[][];
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General JSON Disk format
|
|
|
|
*/
|
|
|
|
|
2021-10-02 18:45:09 +00:00
|
|
|
export type JSONDisk = Base64JSONDisk | Base64JSONNibbleDisk | BinaryJSONDisk;
|
2021-07-07 00:04:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process Disk message payloads for worker
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const PROCESS_BINARY = 'PROCESS_BINARY';
|
|
|
|
export const PROCESS_JSON_DISK = 'PROCESS_JSON_DISK';
|
|
|
|
export const PROCESS_JSON = 'PROCESS_JSON';
|
|
|
|
|
|
|
|
/** Binary disk file message */
|
|
|
|
export interface ProcessBinaryMessage {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: typeof PROCESS_BINARY;
|
2021-07-07 00:04:02 +00:00
|
|
|
payload: {
|
2022-05-10 15:04:20 +00:00
|
|
|
drive: DriveNumber;
|
|
|
|
fmt: NibbleFormat;
|
|
|
|
options: DiskOptions;
|
|
|
|
};
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Processed JSON file message (used for localStorage) */
|
|
|
|
export interface ProcessJsonDiskMessage {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: typeof PROCESS_JSON_DISK;
|
2021-07-07 00:04:02 +00:00
|
|
|
payload: {
|
2022-05-10 15:04:20 +00:00
|
|
|
drive: DriveNumber;
|
|
|
|
jsonDisk: JSONDisk;
|
|
|
|
};
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Raw JSON file message */
|
|
|
|
export interface ProcessJsonMessage {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: typeof PROCESS_JSON;
|
2021-07-07 00:04:02 +00:00
|
|
|
payload: {
|
2022-05-10 15:04:20 +00:00
|
|
|
drive: DriveNumber;
|
|
|
|
json: string;
|
|
|
|
};
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type FormatWorkerMessage =
|
|
|
|
ProcessBinaryMessage |
|
|
|
|
ProcessJsonDiskMessage |
|
|
|
|
ProcessJsonMessage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format work result message type
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const DISK_PROCESSED = 'DISK_PROCESSED';
|
|
|
|
|
|
|
|
export interface DiskProcessedResponse {
|
2022-05-10 15:04:20 +00:00
|
|
|
type: typeof DISK_PROCESSED;
|
2021-07-07 00:04:02 +00:00
|
|
|
payload: {
|
2022-05-10 15:04:20 +00:00
|
|
|
drive: DriveNumber;
|
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 01:55:01 +00:00
|
|
|
disk: FloppyDisk | null;
|
2022-05-10 15:04:20 +00:00
|
|
|
};
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type FormatWorkerResponse =
|
2022-05-10 13:52:06 +00:00
|
|
|
DiskProcessedResponse;
|
2021-07-07 00:04:02 +00:00
|
|
|
|
2022-06-19 16:01:44 +00:00
|
|
|
export interface 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 01:55:01 +00:00
|
|
|
metadata: DiskMetadata;
|
2022-06-19 16:01:44 +00:00
|
|
|
ext: string;
|
2022-07-23 19:00:38 +00:00
|
|
|
readOnly: boolean;
|
|
|
|
volume?: byte;
|
2022-06-19 16:01:44 +00:00
|
|
|
data: ArrayBuffer;
|
|
|
|
}
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
/**
|
|
|
|
* Block device common interface
|
|
|
|
*/
|
2022-06-05 17:57:04 +00:00
|
|
|
export interface MassStorage<T> {
|
|
|
|
setBinary(drive: number, name: string, ext: T, data: ArrayBuffer): boolean;
|
2022-07-23 19:00:38 +00:00
|
|
|
getBinary(drive: number, ext?: T): MassStorageData | null;
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|