
The next step is to find a way to interpret the 16-bit opcode as these more understandable instructions. There are several opcode mnemonics (which are like keywords), such as:Īnd there are several type of operand values, such as: So what are we dealing with here? There's one keyword, ADD, and two arguments, Vx and Vy, which we've established above are registers. So how can I get from nnnn to something like ADD x, y, that is a little more understandable? Well, I'll start by looking at one of the instructions from Chip-8, which is basically the same as the above example: Instruction Each digit position in these sets is a nibble (4-bit). With this instruction set I'll have to store this data in 16-bits, so every instrution ends up being a number from 0x0000 to 0xffff.


(That's 0.002% of the storage space on a floppy disk.) The vast majority of data in the CPU is stored in memory.Ĥkb is 4096 bytes, and JavaScript has some helpful typed arrays, like Uint8Array which is a fixed-size array of a certain element - in this case 8-bits. In this case, it consists of various bits of state, described below, and an instruction cycle with fetch, decode, and execute steps.Ĭhip-8 can access up to 4 kilobytes of memory (RAM).
Javascript mac emulator how to#
I also wrote a CLI snake game in preparation of figuring out how to work with pixels in the terminal for this project.Ī CPU is the main processor of a computer that executes the instructions of a program.
Javascript mac emulator software#
People wrote basic Chip-8 programs that mimicked popular games of the time, such as Pong, Tetris, Space Invaders, and probably other unique games lost to the annuls of time.Ī virtual machine that plays these games is actually a Chip-8 interpreter, not technically an emulator, as an emulator is software that emulates the hardware of a specific machine, and Chip-8 programs aren't tied to any hardware in specific. Chip-8 is a very simple interpreted programming language that was developed in the 1970s for hobbyist computers. I had never heard of Chip-8 before embarking on this project, so I assume most people haven't either unless they're already into emulators.

CLI App - Interfacing with the Terminal.The Instruction Cycle - Fetch, Decode, Execute.As such, this isn't intended to be a how-to guide, but an overview of how I built the emulator, what major concepts I learned, and some JavaScript specifics for making a browser, CLI, or native app. There are plenty of guides on how to make a Chip-8 emulator, such as Mastering Chip8, How to Write an Emulator, and most importantly, Cowgod's Chip-8 Technical Reference, the primary resource used for my own emulator, and a website so old it ends in. You can take a look at the web app demo and the source here:
Javascript mac emulator code#
My Chip8.js code interfaces with not just one but three environments, existing as a web app, a CLI app, and a native app. However, Vanya Sergeev challenged me to write a Chip-8 interpreter to learn some of the basic concepts of lower-level programming languages and how a CPU works, and the end result is a Chip-8 emulator in JavaScript that I wrote with his guidance.Īlthough there are endless implementations of the Chip-8 interpreter in every programming language imaginable, this one is a bit unique. I spent a good portion of my childhood playing emulated NES and SNES games on my computer, but I never imagined I'd write an emulator myself one day.
