0.0.9 • Published 9 years ago

chipjs v0.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
9 years ago

ChipJS

This is a description of what ChipJS is and various notes on its development.

CHIP-8 is an old game development language from the 1970s, based entirely on hexadecimal instructions known as "opcodes" to manipulate data in memory. ChipJS is an implementation of a CHIP-8-like machine and interpreter, kept entirely separate from any sort of opinion on graphics rendering (libraries, etc.).

Components

A typical CHIP-8 machine has memory structure as such:

[...] a 64x32 pixel monochrome display, a little less than 4k of shared program/data space (some of the VIP's low memory is reserved for the interpreter), a 16-level return stack, 16 general-purpose 8-bit registers (the 16th is used as a status flag by some instructions), a 16-button hex keypad (with a really goofy layout) and a "buzzer" which can make some unspecified noise.

The CHIP-8 language also has particular behavior:

The thirty-one instructions comprising the original CHIP-8 instruction set provide utilities for primitive audio and monochrome video output, user input, and data manipulation. CHIP-8 enjoyed relative success during the late 1970s and early 1980s as a popular language for the development of simple video games, and even spawned a multitude of dialects providing additional features.

ChipJS will emulate a CHIP-8 machine and the CHIP-8 language via state and behavior, which implies object-oriented programming. Therefore, it is necessary to elaborate what ChipJS is and what ChipJS does.

  • ChipJS has:
    • 4096 bytes of RAM
      • in classic machines, addresses 0x000 through 0x1FF are taken up by the language interpreter, but that will not be the case in ChipJS
      • regardless, ChipJS will assume all programs begin at 0x200 in memory
    • 16 8-bit registers, V0 through VF
      • hold numbers between 0 and 255, or 0x00 and 0xFF
      • VF is commonly used as a "status" flag
    • a 12-bit address register, I
      • used for keeping track of an address in memory
      • e.g. 0x200, 0x3FF
    • a 16-level return stack
      • essentially a stack of 12-bit addresses like I
      • allows for subroutines
    • a program counter
      • keeps track of where in memory the program is currently executing
    • a pixel display, implemented as a 2D array
      • 64x32 pixels, potentially other sizes as well
    • an 8-bit sound timer register
    • an 8-bit delay timer register
  • ChipJS does:
    • 35 different commands known as opcodes

Opcode Table (via Mastering CHIP-8)

OpcodeOperation
0NNNExecute machine language subroutine at address NNN (more or less deprecated)
00E0Clear the screen
00EEReturn from a subroutine
1NNNJump to address NNN
2NNNExecute subroutine starting at address NNN
3XNNSkip the following instruction if the value of register VX equals NN
4XNNSkip the following instruction if the value of register VX is not equal to NN
5XY0Skip the following instruction if the value of register VX is equal to the value of register VY
6XNNStore number NN in register VX
7XNNAdd the value NN to register VX
8XY0Store the value of register VY in register VX
8XY1Set VX to VX OR VY
8XY2Set VX to VX AND VY
8XY3Set VX to VX XOR VY
8XY4Add the value of register VY to register VX; Set VF to 01 if a carry occurs; Set VF to 00 if a carry does not occur
8XY5Subtract the value of register VY from register VX; Set VF to 00 if a borrow occurs; Set VF to 01 if a borrow does not occur
8XY6Store the value of register VY shifted right one bit in register VX; Set register VF to the least significant bit prior to the shift
8XY7Set register VX to the value of VY minus VX; Set VF to 00 if a borrow occurs; Set VF to 01 if a borrow does not occur
8XYEStore the value of register VY shifted left one bit in register VX; Set register VF to the most significant bit prior to the shift
9XY0Skip the following instruction if the value of register VX is not equal to the value of register VY
ANNNStore memory address NNN in register I
BNNNJump to address NNN + V0
CXNNSet VX to a random number with a mask of NN
DXYNDraw a sprite at position VX, VY with N bytes of sprite data starting at the address stored in I; Set VF to 01 if any set pixels are changed to unset, and 00 otherwise
EX9ESkip the following instruction if the key corresponding to the hex value currently stored in register VX is pressed
EXA1Skip the following instruction if the key corresponding to the hex value currently stored in register VX is not pressed
FX07Store the current value of the delay timer in register VX
FX0AWait for a keypress and store the result in register VX
FX15Set the delay timer to the value of register VX
FX18Set the sound timer to the value of register VX
FX1EAdd the value stored in register VX to register I
FX29Set I to the memory address of the sprite data corresponding to the hexadecimal digit stored in register VX
FX33Store the binary-coded decimal equivalent of the value stored in register VX at addresses I, I+1, and I+2
FX55Store the values of registers V0 to VX inclusive in memory starting at address I; I is set to I + X + 1 after operation
FX65Fill registers V0 to VX inclusive with the values stored in memory starting at address I; I is set to I + X + 1 after operation

Resources

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago