How to write a CHIP-8 interpreter
multigesture.net
multigesture.net
"Basically what happened is that people created their own implementation (clones) of the game Pong. In this case they simulated the looks and game behavior of Pong."
The term "instruction set simulator" has a long tradition especially in the academic circles.
Emulation is the act of fooling something (software) to think that something actually exists (processor executing an instruction set). Emulation can be achieved by simulation (that is, looking at the structure and operation of the thing being emulated and replicating that to a necessary level of detail by the process of simulation) or by other means (e.g. translation).
An emulator therefore can be a simulator. But it doesn't necessarily have to be.
I wrote one[1] some time ago and it's very rewarding to pop in random games and see how badly they perform on your faulty/incomplete "machine" (ex: tetrominoes not dropping in tetris because the hardware timer was not implemented).
[1]: http://adrianton3.github.io/chip8/src/assembler/assembler.ht...
It's really interesting, but I found some bits of the "end game" frustrating, I didn't finish mine because I was never sure how keyboard events had to be handled in the face of cycles coalescing (the emulator's rendering loop works at 60fps and the timers are 60Hz, but IIRC most programs which are are written assuming 500~1000Hz, this causes issues when a key is pressed over an entire frame — or more — and the program uses SKP or SKNP rather than the better-behaved LDxK).
Then there's the weird stuff like the SYS opcode which kinda exists but should not be implemented but has two sub-opcodes which should be.
I wonder if there's a "test harness" for chip8 emulators somewhere (hook in a chip8 emulator somehow and it tells you what you fucked up).
The source is extensively documented and unit-tested, so hopefully it can help out anyone else who's working on building one :) e.g. https://gitlab.com/greysonp/chip8-js/blob/master/src/Cpu.js
* Cowgod's technical reference: http://devernay.free.fr/hacks/chip8/C8TECH10.HTM
* SVision-8, an emulator (CHIP8 and SCHIP), various links (possibly dead) and a few chip8 and schip games for testing: http://devernay.free.fr/hacks/chip8/
* Petr Kratina's notes about their emulator writing (in HaXe), has a clear explanation of the oft opaque "store BCD" opcode which is nice: https://github.com/AfBu/haxe-CHIP-8-emulator/wiki/(Super)CHI...
This GitHub repository contains extensive original research regarding pedantic SCHIP compatibility: https://github.com/Chromatophore/HP48-Superchip
I'm still a newbie to Virtual Machines but I would highly recommend anyone to try their hand at writing a Chip8 VM.