apple2js/js/ui
Ian Flanigan 2793c25c9f
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 06:41:35 -07:00
..
apple2.ts Split disk data out into its own record (#158) 2022-09-17 06:41:35 -07:00
audio_worker.ts Add the recommended eslint plugins for TypeScript (#121) 2022-05-31 08:38:40 -07:00
audio.ts Make errors in the disk and audio workers not block the emulator (#150) 2022-08-21 12:41:19 -07:00
drive_lights.ts Simple Preact download (#134) 2022-06-19 09:01:44 -07:00
gamepad.ts Add the recommended eslint plugins for TypeScript (#121) 2022-05-31 08:38:40 -07:00
joystick.ts Use CSS modules (#123) 2022-06-03 15:30:39 -07:00
keyboard.ts Preact mass storage (#125) 2022-06-05 10:57:04 -07:00
mouse.ts Add touch screen handling (#113) 2022-05-13 06:55:03 -07:00
options_modal.ts Preact UI (#106) 2022-05-10 06:52:06 -07:00
printer.ts Clean up copyright notices (#93) 2021-12-21 12:35:26 -08:00
screen.ts Prohibit any 2022-05-17 19:08:28 -07:00
system.ts Preact UI (#106) 2022-05-10 06:52:06 -07:00
tape.ts Add the recommended eslint plugins for TypeScript (#121) 2022-05-31 08:38:40 -07:00
types.ts Clean up copyright notices (#93) 2021-12-21 12:35:26 -08:00