/bag-of-chips

2020 CHIP-8 Emulator Summer Project

bag-of-chips

CHIP-8

Especificación hardware

  • Memoria: Acceso directo hasta 4KiB de RAM.
  • Display: Pantalla monocroma de 64 x 32 píxeles (128 x 64 para SUPER-CHIP).
  • Registros:
RegResoluciónFunción
PC16 bitContador de programa
I16 bitRegistro índice
V0-F8 bitRegistros de propósito general
VF8 bitRegistro de flags
  • Pila con direccionamiento de 16 bits.
  • Temporizador de 8 bits que se decrementa 60 veces por segundo hasta que llega a 0.
  • Temporizador de 8 bits que funciona como el anterior, pero si distinto de 0 pita.
  • Keypad de 16 botones (4 x 4).

Opcodes

(from https://github.com/trapexit/chip-8_documentation)

OpcodeMnemonicOrigin/VersionDescription
001NEXIT NCHIP-8From Peter Miller’s chip8run. Exit emulator with a return value of `N`.
00BNSCU NSCHIP-8Scroll display `N` lines up.
00CNSCD NSCHIP-8Scroll display `N` lines down.
00E0CLSCHIP-8Clears the display. Sets all pixels to `off`.
00EERETCHIP-8Return from subroutine. Set the `PC` to the address at the top of the stack and subtract `1` from the `SP`.
00FACOMPATCHIP-8Non-standard. Toggles changing of the `I` register by `save (FX55)` and `restore (FX65)` opcodes.
00FBSCRSCHIP-8Scroll display `4` pixels to the right.
00FCSCLSCHIP-8Scroll display `4` pixels to the left.
00FDEXITSCHIP-8Exit the interpreter.
00FELOWSCHIP-8Enable low res (64x32) mode.
00FFHIGHSCHIP-8Enable high res (128x64) mode.
0NNNCALL NNNCHIP-8Call machine language subroutine at address `NNN`.
02A0STEPCOLCHIP-8XSteps background 1 color (-> blue -> black -> green -> red ->)
1NNNJMP NNNCHIP-8Set `PC` to `NNN`.
2NNNCALL NNNCHIP-8Call subroutine a `NNN`. Increment the `SP` and put the current `PC` value on the top of the stack. Then set the `PC` to `NNN`. Generally there is a limit of 16 successive calls.
3XNNSE VX, NNCHIP-8Skip the next instruction if register `VX` is equal to `NN`.
4XNNSNE VX, NNCHIP-8Skip the next instruction if register `VX` is **not** equal to `NN`.
5XY0SE VX, VYCHIP-8Skip the next instruction if register `VX` equals `VY`.
5XY1SGT VX, VYCHIP-8ESkip the next instruction if register `VX` is greater than `VY`.
5XY1ADD VX, VYCHIP-8XLet `VX = VX + VY` (hex digits 00 to 77) (useful for manipulating the `NH, NV` parameters for low resolution color.)
5XY2SLT VX, VYCHIP-8ESkip the next instruction if register `VX` is less than `VY`.
5XY3SNE VX, VYCHIP-8ESkip the next instruction if register `VX` does not equal `VY`.
6XNNLD VX, NNCHIP-8Load immediate value `NN` into register `VX`.
7XNNADD VX, NNCHIP-8Add immediate value `NN` to register VX. Does **not** effect `VF`.
8XY0LD VX, VYCHIP-8Copy the value in register `VY` into `VX`
8XY1OR VX, VYCHIP-8Set `VX` equal to the bitwise `or` of the values in `VX` and `VY`.
8XY2AND VX, VYCHIP-8Set `VX` equal to the bitwise `and` of the values in `VX` and `VY`.
8XY3XOR VX, VYCHIP-8Set `VX` equal to the bitwise `xor` of the values in `VX` and `VY`. **Note:** This instruction was originally undocumented but functional due to how the 8XXX instructions were implemented on teh COSMAC VIP.
8XY4ADD VX, VYCHIP-8Set `VX` equal to `VX` plus `VY`. In the case of an overflow `VF` is set to `1`. Otherwise `0`.
8XY5SUB VX, VYCHIP-8Set `VX` equal to `VX` minus `VY`. In the case of an underflow `VF` is set `0`. Otherwise `1`. (`VF = VX > VY`)
8XY6SHR VX, VYCHIP-8Set `VX` equal to `VX` bitshifted right `1`. `VF` is set to the least significant bit of `VX` prior to the shift. Originally this opcode meant set `VX` equal to `VY` bitshifted right `1` but emulators and software seem to ignore `VY` now. **Note:** This instruction was originally undocumented but functional due to how the 8XXX instructions were implemented on teh COSMAC VIP.
8XY7SUBN VX, VYCHIP-8Set `VX` equal to `VY` minus `VX`. `VF` is set to `1` if `VY` > `VX`. Otherwise `0`. **Note:** This instruction was originally undocumented but functional due to how the 8XXX instructions were implemented on teh COSMAC VIP.
8XYESHL VX, VYCHIP-8Set `VX` equal to `VX` bitshifted left `1`. `VF` is set to the most significant bit of `VX` prior to the shift. Originally this opcode meant set `VX` equal to `VY` bitshifted left `1` but emulators and software seem to ignore `VY` now. **Note:** This instruction was originally undocumented but functional due to how the 8XXX instructions were implemented on teh COSMAC VIP.
9XY0SNE VX, VYCHIP-8Skip the next instruction if `VX` does **not** equal `VY`.
9XY1MUL VX, VYCHIP-8ESet `VF`, `VX` equal to `VX` multipled by `VY` where `VF` is the most significant byte of a 16bit word.
9XY2DIV VX, VYCHIP-8ESet `VX` equal to `VX` divided by `VY`. `VF` is set to the remainder.
9XY3BCD VX, VYCHIP-8ELet `VX`, `VY` be treated as a 16bit word with `VX` the most significant part. Convert that word to BCD and store the 5 digits at memory location `I` through `I+4`. `I` does not change.
ANNNLD I, NNNCHIP-8Set `I` equal to `NNN`.
BNNNJMP V0, NNNCHIP-8Set the `PC` to `NNN` plus the value in `V0`.
B0NNOUT NNCHIP-8IOutput `NN` to port.
B1X0OUT VXCHIP-8IOutput contents of `VX` to port.
B1X1IN VXCHIP-8IRead input from port and palce in `VX`.
BXY0COL VX, VYCHIP-8XSet `VY` color @ `VX(NH)`, `VX+1(NV)` (provides low resolution color 8x8.)
BXYNCOL VX, VY, NCHIP-8X`N != 0`, set `VY` color @ `VX`, `VX+1` byte `N` bytes vertically (provides high resolution 8x32.)
CXNNRND VX, NNCHIP-8Set `VX` equal to a random number ranging from `0` to `255` which is logically `and`ed with `NN`.
DXY0DRW VX, VX, 0SCHIP-8When in high res mode show a `16x16` sprite at `(VX, VY)`.
DXYNDRW VX, VY, NCHIP-8Display `N`-byte sprite starting at memory location `I` at `(VX, VY)`. Each set bit of `xor`ed with what’s already drawn. `VF` is set to `1` if a collision occurs. `0` otherwise.
EX9ESKP VXCHIP-8Skip the following instruction if the key represented by the value in `VX` is pressed.
EXA1SKNP VXCHIP-8Skip the following instruction if the key represented by the value in `VX` is **not** pressed.
EXF2SKP2 VXCHIP-8XSkip the following instruction if the key represented by the value in `VX` is pressed on hex keyboard 2.
EXF5SKNP2 VXCHIP-8XSkip the following instruction the the key represented by the value in `VX` is **not** pressed on hex keyboard 2.
FX07LD VX, DTCHIP-8Set `VX` equal to the `delay timer`.
FX0ALD VX, KEYCHIP-8Wait for a key press and store the value of the key into `VX`.
FX15LD DT, VXCHIP-8Set the delay timer `DT` to `VX`.
FX18LD ST, VXCHIP-8Set the sound timer `ST` to `VX`.
FX1EADD I, VXCHIP-8Add `VX` to `I`. `VF` is set to `1` if `I > 0x0FFF`. Otherwise set to `0`.
FX29LD I, FONT(VX)CHIP-8Set `I` to the address of the CHIP-8 8x5 font sprite representing the value in `VX`.
FX30LD I, FONT(VX)SCHIP-8Set `I` to the address of the SCHIP-8 16x10 font sprite representing the value in `VX`.
FX33BCD VXCHIP-8Convert that word to BCD and store the 3 digits at memory location `I` through `I+2`. `I` does not change.
FX55LD [I], VXCHIP-8Store registers `V0` through `VX` in memory starting at location `I`. `I` does not change. ’
FX65LD VX, [I]CHIP-8Copy values from memory location `I` through `I + X` into registers `V0` through `VX`. `I` does not change.
FX75DISP VXCHIP-8EDisplay the value of `VX` on the COSMAC Elf hex display.
FX75LD R, VXSCHIP-8Store `V0` through `VX` to HP-48 RPL user flags (X <= 7).
FX85LD VX, RSCHIP-8Read `V0` through `VX` to HP-48 RPL user flags (X <= 7)
FX94LD I, VXCHIP-8ELoad `I` with the address of the font sprite of the `ASCII` value found in `VX`.
FXFBIN VXCHIP-8XCopy contents from `input port` to `VX`. (Waits for EF4=1)
FXF8OUT VXCHIP-8XOutput contents of `VX` to `output port`. Used to program simple sound.

Documentación de apoyo

Iré actualizando esto a la que vaya viendo artículos nuevos: