Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 17:43:48 +01:00
|
|
|
|
|
|
|
/** A byte (0..255). This is not enforced by the compiler. */
|
|
|
|
export type byte = number;
|
|
|
|
|
|
|
|
/** A word (0..65535). This is not enforced by the compiler. */
|
|
|
|
export type word = number;
|
|
|
|
|
2020-11-24 17:48:14 +01:00
|
|
|
/** A raw region of memory. */
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 17:43:48 +01:00
|
|
|
export type memory = number[] | Uint8Array;
|
|
|
|
|
2020-11-24 17:48:14 +01:00
|
|
|
/** A mapped region of memory. */
|
|
|
|
export interface Memory {
|
|
|
|
/** Start page. */
|
|
|
|
start(): byte;
|
|
|
|
/** End page, inclusive. */
|
|
|
|
end(): byte;
|
|
|
|
/** Read a byte. */
|
|
|
|
read(page: byte, offset: byte): byte;
|
|
|
|
/** Write a byte. */
|
|
|
|
write(page: byte, offset: byte, value: byte): void;
|
|
|
|
}
|
|
|
|
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 17:43:48 +01:00
|
|
|
export type DiskFormat = '2mg' | 'd13' | 'do' | 'dsk' | 'hdv' | 'po' | 'nib' | 'woz';
|
|
|
|
|
|
|
|
export interface Drive {
|
|
|
|
format: DiskFormat,
|
|
|
|
volume: number,
|
|
|
|
tracks: Array<byte[] | Uint8Array>,
|
|
|
|
trackMap: unknown,
|
2020-11-07 15:49:05 -08:00
|
|
|
}
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 17:43:48 +01:00
|
|
|
|
|
|
|
export interface DiskIIDrive extends Drive {
|
|
|
|
rawTracks: unknown,
|
|
|
|
track: number,
|
|
|
|
head: number,
|
|
|
|
phase: number,
|
|
|
|
readOnly: boolean,
|
|
|
|
dirty: boolean,
|
2020-11-07 15:49:05 -08:00
|
|
|
}
|
2020-11-24 17:48:14 +01:00
|
|
|
|
|
|
|
export interface Restorable<T> {
|
|
|
|
getState(): T;
|
|
|
|
setState(state: T): void;
|
|
|
|
}
|