Type restructuring

This commit is contained in:
Will Scullin 2021-03-06 15:04:13 -08:00
parent 3c5ded7058
commit 87b60d4eb4
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
12 changed files with 49 additions and 59 deletions

View File

@ -23,11 +23,11 @@ import RAM, { RAMState } from './ram';
import { debug } from './util';
import SYMBOLS from './symbols';
import { Restorable, memory } from './types';
import { Restorable, rom } from './types';
import { processGamepad } from './ui/gamepad';
interface Options {
characterRom: memory,
export interface Apple2Options {
characterRom: rom,
enhanced: boolean,
e: boolean,
gl: boolean,
@ -73,7 +73,7 @@ export class Apple2 implements Restorable<State> {
renderedFrames: 0
};
constructor(options: Options) {
constructor(options: Apple2Options) {
const LoresPage = options.gl ? LoresPageGL : LoresPage2D;
const HiresPage = options.gl ? HiresPageGL : HiresPage2D;
const VideoModes = options.gl ? VideoModesGL : VideoModes2D;

View File

@ -9,8 +9,8 @@
* implied warranty.
*/
import CPU6502, { PageHandler } from './cpu6502';
import { Card, Memory, TapeData, byte, Restorable } from './types';
import CPU6502 from './cpu6502';
import { Card, Memory, MemoryPages, TapeData, byte, Restorable } from './types';
import { debug } from './util';
type slot = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
@ -66,7 +66,7 @@ const LOC = {
ACCEL: 0x74, // CPU Speed control
};
export default class Apple2IO implements PageHandler, Restorable<Apple2IOState> {
export default class Apple2IO implements MemoryPages, Restorable<Apple2IOState> {
private _slot: Array<Card | null> = new Array(7).fill(null);
private _auxRom: Memory | null = null;

View File

@ -9,7 +9,7 @@
* implied warranty.
*/
import { byte, memory, Memory } from './types';
import { byte, memory, MemoryPages, rom } from './types';
import { allocMemPages } from './util';
import {
Color,
@ -152,7 +152,7 @@ export class LoresPage2D implements LoresPage {
imageData: ImageData;
constructor(private page: number,
private readonly charset: memory,
private readonly charset: rom,
private readonly e: boolean) {
this.imageData = new ImageData(560, 384);
for (let idx = 0; idx < 560 * 384 * 4; idx++) {
@ -184,8 +184,7 @@ export class LoresPage2D implements LoresPage {
data[nextOff + 2] = c2;
}
bank0(): Memory {
bank0(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),
@ -194,7 +193,7 @@ export class LoresPage2D implements LoresPage {
};
}
bank1(): Memory {
bank1(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),
@ -592,7 +591,7 @@ export class HiresPage2D implements HiresPage {
data[nextOff + 2] = data[nextOff + 6] = data[nextOff + 10] = data[nextOff + 14] = c2;
}
bank0(): Memory {
bank0(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),
@ -601,7 +600,7 @@ export class HiresPage2D implements HiresPage {
};
}
bank1(): Memory {
bank1(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),

View File

@ -10,7 +10,7 @@
*/
import { base64_decode, base64_encode} from '../base64';
import { bit, byte, DiskFormat, MemberOf, memory, nibble, rom } from '../types';
import { bit, byte, Card, DiskFormat, MemberOf, memory, nibble, rom } from '../types';
import { debug, toHex } from '../util';
import { Disk, jsonDecode, jsonEncode, readSector } from '../formats/format_utils';
@ -261,7 +261,7 @@ function setDriveState(state: DriveState) {
/**
* Emulates the 16-sector and 13-sector versions of the Disk ][ drive and controller.
*/
export default class DiskII {
export default class DiskII implements Card {
private drives: Drive[] = [
{ // Drive 1

View File

@ -10,7 +10,7 @@
* implied warranty.
*/
import { byte, word } from './types';
import { Memory, MemoryPages, byte, word } from './types';
import { debug, toHex } from './util';
type symbols = { [key: number]: string };
@ -95,25 +95,15 @@ const loc = {
BRK: 0xFFFE
};
export interface Page {
read(page: byte, offset: byte): byte;
write(page: byte, offset: byte, value: byte): void;
}
export interface PageHandler extends Page {
start(): byte;
end(): byte;
}
interface ResettablePageHandler extends PageHandler {
interface ResettablePageHandler extends MemoryPages {
reset(): void;
}
function isResettablePageHandler(pageHandler: PageHandler | ResettablePageHandler): pageHandler is ResettablePageHandler {
function isResettablePageHandler(pageHandler: MemoryPages | ResettablePageHandler): pageHandler is ResettablePageHandler {
return (pageHandler as ResettablePageHandler).reset !== undefined;
}
const BLANK_PAGE: Page = {
const BLANK_PAGE: Memory = {
read: function () { return 0; },
write: function () { }
};
@ -158,7 +148,7 @@ export default class CPU6502 {
private yr = 0; // Y Register
private sp = 0xff; // Stack Pointer
private memPages: Page[] = new Array(0x100);
private memPages: Memory[] = new Array(0x100);
private resetHandlers: ResettablePageHandler[] = [];
private cycles = 0;
private sync = false;
@ -1129,7 +1119,7 @@ export default class CPU6502 {
}
}
public addPageHandler(pho: (PageHandler | ResettablePageHandler) & Page) {
public addPageHandler(pho: (MemoryPages | ResettablePageHandler)) {
for (let idx = pho.start(); idx <= pho.end(); idx++) {
this.memPages[idx] = pho;
}

View File

@ -9,7 +9,7 @@
* implied warranty.
*/
import { byte, memory, Memory, Restorable } from './types';
import { byte, memory, MemoryPages, rom } from './types';
import { allocMemPages } from './util';
import { screenEmu } from 'apple2shader';
@ -92,7 +92,7 @@ export class LoresPageGL implements LoresPage {
imageData: ImageData;
constructor(private page: number,
private readonly charset: memory,
private readonly charset: rom,
private readonly e: boolean) {
this.imageData = new ImageData(560, 192);
for (let idx = 0; idx < 560 * 192 * 4; idx++) {
@ -116,7 +116,7 @@ export class LoresPageGL implements LoresPage {
data[off + 2] = c2;
}
bank0(): Memory {
bank0(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),
@ -125,7 +125,7 @@ export class LoresPageGL implements LoresPage {
};
}
bank1(): Memory {
bank1(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),
@ -402,7 +402,7 @@ export class LoresPageGL implements LoresPage {
*
***************************************************************************/
export class HiresPageGL implements Memory, Restorable<GraphicsState> {
export class HiresPageGL implements HiresPage {
private _buffer: memory[] = [];
private _refreshing = false;
@ -442,7 +442,7 @@ export class HiresPageGL implements Memory, Restorable<GraphicsState> {
data[off + 2] = c2;
}
bank0(): Memory {
bank0(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),
@ -451,7 +451,7 @@ export class HiresPageGL implements Memory, Restorable<GraphicsState> {
};
}
bank1(): Memory {
bank1(): MemoryPages {
return {
start: () => this._start(),
end: () => this._end(),

View File

@ -9,6 +9,7 @@
* implied warranty.
*/
import { MemoryPages } from './types';
import CPU6502 from './cpu6502';
import RAM, { RAMState } from './ram';
import ROM, { ROMState } from './roms/rom';
@ -94,7 +95,7 @@ const LOC = {
READWRBSR1: 0x8b,
};
class Switches implements Memory {
class Switches implements MemoryPages {
constructor(private mmu: MMU) {}
start() {
@ -114,7 +115,7 @@ class Switches implements Memory {
}
}
class AuxRom implements Memory {
class AuxRom implements MemoryPages {
constructor(
private readonly mmu: MMU,
private readonly rom: ROM) { }

View File

@ -1,9 +1,8 @@
import { PageHandler } from '../cpu6502';
import { Restorable, byte, rom } from '../types';
import { MemoryPages, Restorable, byte, rom } from '../types';
export type ROMState = null;
export default class ROM implements PageHandler, Restorable<ROMState> {
export default class ROM implements MemoryPages, Restorable<ROMState> {
constructor(
private readonly startPage: byte,

View File

@ -29,18 +29,21 @@ export type memory = Uint8Array;
/** A raw region of memory. */
export type rom = ReadonlyUint8Array;
/** 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;
}
/** A mapped region of memory. */
export interface MemoryPages extends Memory {
/** Start page. */
start(): byte;
/** End page, inclusive. */
end(): byte;
}
/* An interface card */
export interface Card extends Memory, Restorable {
/* Reset the card */

View File

@ -1,4 +1,4 @@
import { Memory, Restorable, byte, memory } from './types';
import { MemoryPages, Restorable, byte, memory } from './types';
export type bank = 0 | 1;
export type pageNo = 1 | 2;
@ -34,12 +34,12 @@ export interface VideoModesState {
an3: boolean,
}
export interface VideoPage extends Memory, Restorable<GraphicsState> {
export interface VideoPage extends MemoryPages, Restorable<GraphicsState> {
imageData: ImageData
dirty: Region;
bank0(): Memory
bank1(): Memory
bank0(): MemoryPages
bank1(): MemoryPages
mono: (on: boolean) => void
refresh: () => void

View File

@ -2,10 +2,9 @@
import fs from 'fs';
import path from 'path';
import { PageHandler } from '../../js/cpu6502';
import { byte } from '../../js/types';
import { MemoryPages, byte } from '../../js/types';
export default class Test6502 implements PageHandler {
export default class Test6502 implements MemoryPages {
private data: Buffer
constructor() {

View File

@ -2,10 +2,9 @@
import fs from 'fs';
import path from 'path';
import { PageHandler } from '../../js/cpu6502';
import { byte } from '../../js/types';
import { MemoryPages, byte } from '../../js/types';
export default class Test65C02 implements PageHandler {
export default class Test65C02 implements MemoryPages {
private data: Buffer
constructor() {