Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./src/nes";
export * from "./src/controller";
18 changes: 18 additions & 0 deletions src/controller.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type ControllerKey = 1 | 2;

export type ButtonKey = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;

export class Controller {
state: number[];
buttonDown: (key: ControllerKey) => void;
buttonUp: (key: ControllerKey) => void;

static readonly BUTTON_A = 0;
static readonly BUTTON_B = 1;
static readonly BUTTON_SELECT = 2;
static readonly BUTTON_START = 3;
static readonly BUTTON_UP = 4;
static readonly BUTTON_DOWN = 5;
static readonly BUTTON_LEFT = 6;
static readonly BUTTON_RIGHT = 7;
}
36 changes: 36 additions & 0 deletions src/nes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ControllerKey, ButtonKey } from "./controller";

export interface EmulatorData {
cpu: string;
mmap: string;
ppu: string;
papu: string;
}

export interface NESOptions {
onFrame?: (buffer: Buffer) => void;
onAudioSample?: (left: number, right: number) => void;
onStatusUpdate?: (status: string) => void;
onBatteryRamWrite?: (address: number, value: number) => void;
preferredFrameRate?: number;
emulateSound?: boolean;
sampleRate?: number;
}

export class NES {
constructor(opts: NESOptions);
stop: () => void;
reset: () => void;
frame: () => void;
buttonDown: (controller: ControllerKey, button: ButtonKey) => void;
buttonUp: (controller: ControllerKey, button: ButtonKey) => void;
zapperMove: (x: number, y: number) => void;
zapperFireDown: () => void;
zapperFireUp: () => void;
getFPS: () => number;
reloadROM: () => void;
loadROM: (data: string | Buffer) => void;
setFramerate: (rate: number) => void;
toJSON: () => EmulatorData;
fromJSON: (data: EmulatorData) => void;
}