Skip to content

UniCHIP8 Programming

Scott Elcomb edited this page Jun 6, 2018 · 15 revisions

Communicating with GameObjects

UniCHIP8 uses the command and message patterns to enable communications between one or more virtual machines and your scene.

  • The UniCHIP8Router component operates as a simple text-based message broker; it maintains a registry of connected nodes
  • The UniCHIP8Node component connects it's attached GameObject to a UniCHIP8Router and processes messages
  • The UniCHIP8 component is the CHIP-8 virtual machine itself; it inherits from UniCHIP8Node and attaches to a router

Conventions

Calling the UniCHIP8 Extensions

UniCHIP8 extended opcodes require that the I register be set to the starting address of a string, the name of a Unity GameObject, prior to being called.

Several UniCHIP8 extended opcodes require values be set in registers V0-V3 prior to be being called.

Strings

UniCHIP8 strings are null-terminated and must not be greater than 32 characters.

Numbers

All numbers (aside from address pointers) in UniCHIP8 are represented by bytes (the set of positive integers from 0 to 255). There are no negative values.

When using the rotate* opcodes, byte value(s) will be scaled such that the value 0xFF (255) represents 360 degrees.

When using the setMaterialColor or setLightColor opcodes, byte value(s) will be normalized to floats in the range of 0f to 1f.

Memory Layout

hex (dec) description
0x0000 (0000) CHIP-8 reserved space starts; interrupt table starts
0x001F (0031) Interrupt table ends
0x0020 (0032) Interrupt data starts
0x005F (0095) Interrupt data ends
...
0x01FF (0511) CHIP-8 reserved space ends
0x0200 (0512) Boot address
...
0x0D50 (3408) Data port starts
0x0D6F (3440) Data port ends
...
0x0D7F (3455) CHIP-8 font data starts
0x0DCF (3535) CHIP-8 font data ends
...
0x0FFF (4095) End of RAM

Interrupts

When not in strict CHIP-8 compatibility mode, the first 96 bytes of RAM are reserved for interrupt processing.

Each entry in the interrupt table is 2 bytes long and contains a pointer to a subroutine, the interrupt handler, that should be executed when the interrupt is triggered.

Interrupt handlers should cache register state on entry and restore on exit.

The interrupt table is followed by 64 bytes of space reserved for data passed from the Unity scene for the interrupt handler to process.

ID Pointer Name
0 0x0000 collision
1 0x0002 data port
2 0x0004
3 0x0006
4 0x0008
5 0x000A
6 0x000C
7 0x000E
8 0x0010
9 0x0012
10 0x0014
11 0x0016
12 0x0018
13 0x001A
14 0x001C
15 0x001E

File Naming

extension file type
filename.ch8 CHIP-8 rom
filename.uc8 UniCHIP8 rom
filename.8o Octo CHIP-8 rom source
filename.u8o Octo UniCHIP8 rom source

Tools