(2023-05-09) CHIP-8 revisited
-----------------------------
The first human-scale VM for home computers in history, CHIP-8, is something
I am a bit familiar with. To the extent of development of my own CHIP-8
emulation engine for KaiOS, which I obviously had called DALE-8. I have
always been sticking to the original specs and not quite liking all those
extensions like SuperCHIP, XO-CHIP and so on. The most basic original specs
- 4096 bytes of RAM, purely monochrome 64x32 bitmap graphics with 8xN
sprites, 35 opcodes, 16 keys and a beeper - are perfect for implementing it
on the most exotic hardware available. No wonder that even a Rockbox version
for Sansa Clip players has a built-in CHIP-8 emulator (although, obviously,
not all 16 keys are supported there).

It is remarkable how CHIP-8 was initially called not a VM, not an emulation
engine, but an interpreter. Even Wikipedia refers to it as an "interpreted
programming language". Well, in 1977 when it was first introduced on a
COSMAC VIP that had nothing but a 16-key keypad and a reset switch, it was
your pretty much only alternative to direct machine language programmming,
and yes, it was much simpler than the RCA 1802 machine language despite also
being fully binary. Especially if you understand how expensive in 1977 were
any expansions (pun intended) that would allow to run any Tiny BASIC or
Forth or other "real" interpreters, and these expansions would at least
include more RAM and, obviously, a full-size alphanumeric keyboard. What's
even more interesting (and what I didn't know until this very day) is that
RCA Studio II cartridges also contained games created for a VM with an
instruction set similar (although not identical) to CHIP-8 as opposed to the
machine language. Sic!

So, what's so remarkable about this VM, besides being the first of its kind?
Well, at least two things. First, every single VM instruction is exactly two
bytes long. No more, no less. This makes decoding them as easy as possible.
Second, with sprites being first-class citizens in CHIP-8 graphics, XORing
them on top of each other is a very clever trick one can pull off to
interact with so little memory, considering the VF register is also set
automatically on any collision of the active pixels. So, CHIP-8
architecturally has collision detection out of the box, which is just great
in my opinion.

When it comes to the original CHIP-8 variant support, I guess I have a lot to
improve and reimplement. Of course, it's going to be done in POSIX AWK. If
my algos work fine there, they will work fine everywhere else. So, as
always, stay tuned!

--- Luxferre ---