apple2js/js/roms/cards/disk2.ts
Ian Flanigan 910238bf63
Convert cards/disk2.js to Typescript (#54)
* Convert `cards/disk2.js` to Typescript

This is mostly a straightforward conversion of `cards/disk2.js` to
Typescript, with the following exceptions:

*   `setState()` did not restore the drive light state correctly
    because the callback was called with the old `on` value.

*   `setPhase()` did not work for WOZ images.

*   `getBinary()` did not work for `nib` files.

*   `getBase64()` did not work for `nib` files and maybe didn't work
    right at all.

Even with these fixes, local storage still doesn't work correctly.

I have also added several TODOs where methods don't support WOZ disks.

* Convert most uses of `memory` to `Uint8Array`

There are many places in the existing code where we use `Uint8Array`
directly. This change merely makes the `memory` type equivalent to
`Uint8Array`.

This change also changes most ROM data to be read-only in Typescript
to ensure that it is not modified by mistake. This can't be done just
by applying `as const` to the declaration because `Uint8Array`s are
can not be expressed as literals. Instead, we create a new type,
`ReadonlyUint8Array` that drops the mutation methods and makes indexed
access read-only.

See
https://www.growingwiththeweb.com/2020/10/typescript-readonly-typed-arrays.html
for details.

* Tighten types and document `disk2.ts`

While trying to understand the Disk ][ emulation, I tighted the types
and documented the parts that I could, including references to other
sources, like _Understanding the Apple //e_ by Jim Sather.

The one functional change is the addition of the P6 ROM of DOS 3.2 and
earlier. This is automatically selected if the card is initialized for
13 sector disks.
2021-02-07 20:50:50 -08:00

72 lines
3.0 KiB
TypeScript

import { ReadonlyUint8Array } from '../../types';
export const BOOTSTRAP_ROM_16 = new Uint8Array([
0xa2,0x20,0xa0,0x00,0xa2,0x03,0x86,0x3c,
0x8a,0x0a,0x24,0x3c,0xf0,0x10,0x05,0x3c,
0x49,0xff,0x29,0x7e,0xb0,0x08,0x4a,0xd0,
0xfb,0x98,0x9d,0x56,0x03,0xc8,0xe8,0x10,
0xe5,0x20,0x58,0xff,0xba,0xbd,0x00,0x01,
0x0a,0x0a,0x0a,0x0a,0x85,0x2b,0xaa,0xbd,
0x8e,0xc0,0xbd,0x8c,0xc0,0xbd,0x8a,0xc0,
0xbd,0x89,0xc0,0xa0,0x50,0xbd,0x80,0xc0,
0x98,0x29,0x03,0x0a,0x05,0x2b,0xaa,0xbd,
0x81,0xc0,0xa9,0x56,0x20,0xa8,0xfc,0x88,
0x10,0xeb,0x85,0x26,0x85,0x3d,0x85,0x41,
0xa9,0x08,0x85,0x27,0x18,0x08,0xbd,0x8c,
0xc0,0x10,0xfb,0x49,0xd5,0xd0,0xf7,0xbd,
0x8c,0xc0,0x10,0xfb,0xc9,0xaa,0xd0,0xf3,
0xea,0xbd,0x8c,0xc0,0x10,0xfb,0xc9,0x96,
0xf0,0x09,0x28,0x90,0xdf,0x49,0xad,0xf0,
0x25,0xd0,0xd9,0xa0,0x03,0x85,0x40,0xbd,
0x8c,0xc0,0x10,0xfb,0x2a,0x85,0x3c,0xbd,
0x8c,0xc0,0x10,0xfb,0x25,0x3c,0x88,0xd0,
0xec,0x28,0xc5,0x3d,0xd0,0xbe,0xa5,0x40,
0xc5,0x41,0xd0,0xb8,0xb0,0xb7,0xa0,0x56,
0x84,0x3c,0xbc,0x8c,0xc0,0x10,0xfb,0x59,
0xd6,0x02,0xa4,0x3c,0x88,0x99,0x00,0x03,
0xd0,0xee,0x84,0x3c,0xbc,0x8c,0xc0,0x10,
0xfb,0x59,0xd6,0x02,0xa4,0x3c,0x91,0x26,
0xc8,0xd0,0xef,0xbc,0x8c,0xc0,0x10,0xfb,
0x59,0xd6,0x02,0xd0,0x87,0xa0,0x00,0xa2,
0x56,0xca,0x30,0xfb,0xb1,0x26,0x5e,0x00,
0x03,0x2a,0x5e,0x00,0x03,0x2a,0x91,0x26,
0xc8,0xd0,0xee,0xe6,0x27,0xe6,0x3d,0xa5,
0x3d,0xcd,0x00,0x08,0xa6,0x2b,0x90,0xdb,
0x4c,0x01,0x08,0x00,0x00,0x00,0x00,0x00
]) as ReadonlyUint8Array;
export const BOOTSTRAP_ROM_13 = new Uint8Array([
0xa2,0x20,0xa0,0x00,0xa9,0x03,0x85,0x3c,
0x18,0x88,0x98,0x24,0x3c,0xf0,0xf5,0x26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