Class: CPU

chip8. CPU

new CPU(params)

Creates CPU instance.

Parameters:
Name Type Description
params
Properties
Name Type Description
keyboard chip8.Keyboard

Keyboard which handles input.

screen chip8.Screen

Screen which handles output.

audio chip8.Audio

Audio module which handles emitting sounds.

Source:

Namespaces

IS

Members

quirks :object

Enables/disabled CPU quirks

Type:
  • object
Properties:
Name Type Description
shift boolean

If enabled, VX is shifted and VY remains unchanged (default: false)

loadStore boolean

If enabled, I is not incremented during load/store (default: false)

Source:

Methods

cycle()

Performs one CPU cycle.

Source:

decode(opCode) → {function|undefined}

Decodes given instruction code and returns function which performs that instruction. Throws exception if can't decode code.

Parameters:
Name Type Description
opCode number

instruction code

Source:
Returns:

function performing operation

Type
function | undefined

execute(op)

Executes given operation.

Parameters:
Name Type Description
op function

operation to execute.

Source:

fetch() → {number}

Fetches next instruction code

Source:
Returns:

instruction code

Type
number

halt()

Halts CPU. Halted CPU differs from stopped CPU in a way that halted CPU performs idle loop, and stopped CPU does nothing.

Source:

loadFontSet()

Loads font set into memory.

Source:

loadToMemory(binData, offset)

Loads binary data into memory starting at location 0x0200

Parameters:
Name Type Argument Description
binData ArrayBuffer

data to load

offset number <optional>

offset added to starting address

Source:

reset()

Resets CPU state. Clears memory and loads font set, clears stack, registers and pointers. Resets state of keyboard, screen and audio.

Source:

resume()

Resumes CPU from halted state.

Source:

run()

Runs CPU.

Source:

step()

Performs one CPU step. One step means one fetch-decode-execute cycle.

Source:

stop()

Stops CPU.

Source:

updateTimers()

Updates CPU timers.

Source: