-
Notifications
You must be signed in to change notification settings - Fork 0
API
Interface to the underlying WebAssembly emulator.
static new(rom: Uint8Array): Promise<Chip8>
This static method returns an emulator instance with the provided ROM loaded into memory, ready to be used. It also handles the necessary WebAssembly initialization and setup, which is why this method is asynchronous and should be used instead of the regular constructor.
The display width in pixels (64).
The display height in pixels (32).
Start or resume emulator execution.
stop(error?: Error): void
Stops emulator execution.
Runs a certain amount of clock cycles depending on the duration that is passed:
-
tick: runs 1 clock cycle (~1/500s) -
cpu: runs 1 CPU cycles (~1/500s) -
timer: runs 1 timer cycle (~1/60s)
input(key: Button, state: boolean): void
Updates the input state with the provided key status.
canvas: HTMLCanvasElement
The canvas the emulator paints to.
error: Error
The current error, if any. It is usually caused by a panic during execution.
logs: Logs
Emulator logs, produced through Rust's log facade.
memory: WebAssembly.Memory
Current WebAssembly instance memory.
debug: Debug
Debug info containing the emulator state, to inspect its inner workings.
audio: Audio
Module responsible for producing and analyzing audio through the Web Audio API.
status: Status
Current emulator status.
performance: Statistics
Measures of browser frame performance.
Interface to the emulator audio.
Enables sound output.
Disables sound output.
Plays oscillator.
Stops oscillator.
Manually update analyzer data.
Contains analyzer data:
-
timeDomain: Uint8Arraytime domain data from getByteTimeDomainData -
frequency: Uint8Arrayfrequency data from getByteFrequencyData
The audio context's sample rate.
get type: OscillatorType
The oscillator's type.
set type: OscillatorType
Sets the oscillator's type.
Sets the output volume, between 0 and 1.
Sets the oscillator frequency in hertz.
Interface to the emulator logs.
All log records so far. They represent a Rust log record (https://docs.rs/log/latest/log/struct.Record.html):
-
text: stringLog message -
level: stringLog verbosity level. One ofTRACE,DEBUG,INFO,WARNorERROR. -
location: stringplace in the original code where this message was logged.
Enable logging (induces performance overhead).
Disables logging.
This class represents the state of the emulator for in-depth debugging purposes. After each cycle, the emulator's debug object is replaced with a new instance to stay up-to-date. For performance reasons, all fields are memoized getters: this way, instead of fetching everything at every frame (which would be very expensive), we only pay for what we actually use.
If we try to access a property while the emulator is in an erroneous state, the getter will warn us about it and return
null.
get cpu: DebugCpu
CPU state.
get disassembly: DebugDisassembly
Disassembly utilities.
get memory: Uint8Array
Memory RAM.
Array of 16 booleans representing each key state.
Master clock.
-
rate: rate at which the clock is ticked -
time: time elapsed so far
CPU clock.
-
rate: rate at which the clock is ticked -
cycles: number of cycles run so far
CPU timers clock.
-
rate: rate at which the clock is ticked -
cycles: number of cycles run so far
Program counter.
Stack pointer.
v: Uint8Array
All 16 V registers.
I register.
stack: Uint16Array
Stack.
Delay timer.
Sound timer.
Total number of instructions in the memory segment.
Returns the instruction at a given address.
-
address: numberaddress at which the instruction was fetched -
opcode: numberraw opcode -
disassembly: stringtextual representation of the instruction
Converts an address to the index of its instruction.
Converts an index to the address of its instruction.
A keypad button. Can be any integer between 0 and 16.
Represents execution status:
-
IDLE: emulator is paused -
RUNNING: emulator is running -
ERROR: emulator encountered an error