Skip to content

Valulz/jschip8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JS-Chip8

A Chip8 emulator written in Javascript

Start the emulator

//TODO

Chip8 Functions

Chip8.getDisplayWidth

Return the Width of the Chip8 (64)

Chip8.getDisplayHeight

Return the Height of the CHip8 (32)

Chip8.setRenderer(render)

Set a renderer to the Chip8 (see Renderer below)

Chip8.setKey(key)

Set the pressed key by the user (see Keyboard below)

Chip8.unsetKey(key)

Remove the key, not pressed anymore by the user (see Keyboard below)

Chip8.loadProgram(program)

Load the rom in the memory of the Chip8

Chip8.reset()

Reset the Chip8

Chip8.start(canvas)

Start/Restart the Chip 8. The canvas is an optional parameters (see Renderer)

Chip8.stop()

Stop the Chip8

Chip8.emulateCycle()

Emulate an execution of the current opcode in the memory

Renderer

Be careful, an error will be raised if you do not provide a renderer to the emulator, and try to start it.

It exists two ways to render the emulator :

Chip8.start(canvas)

The simplest, just provide a canvas for the method start. The program will create a renderer using the canvas provide, and the default value.

    Chip8Renderer(#canvas, 64, 32, 10, #f00, #fff)

Chip8.setRenderer(renderer)

This method allows you to provide a complete object renderer you have create.

You have two ways to create a Renderer.

Chip8Renderer(canvas, width, height, cellSize, fgColor, bgColor)

  • canvas : the canvas use to render the emulator
  • widht : width of the Chip8 (default : 64)
  • height : height of the Chip8 (default : 32)
  • cellSize : the size of a pixel (default : 10)
  • fgColor : Foreground Color (default : #f00)
  • bgColor : Background Color (default : #fff)

Create a "duck" Renderer

The emulator use 3 functions from the renderer :

  • clear : clear the canvas
  • render(display) : render the given array
    • the display is a one dimension array (64 * 32) fill with bits (0 or 1)
  • beep : the sound of the CHip8

Keyboard

Here is the keypad used by Chip8

1 2 3 C
4 5 6 D
7 8 9 E
A 0 B F

For AZERTY keyboard

1 2 3 4
A Z E R
Q S D F
W X C V

For QWERTY keyboard :

1 2 3 4
Q W E R
A S D F
Z X C V

About

Chip8 emulator in Javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published