You are browsing as a guest. Sign up (or log in) to start making projects!

Chip8-Emulator

  • 6 Devlogs
  • 16 Total hours

Chip 8 Emulator, that lets you run early computer software originally designed for chip 8 on modern computers

Super Star

As a prize for your great work, look out for a bonus prize in the mail :)

Ship #1

# Chip-8 Emulator
I built a cross-platform CHIP-8 Emulator from the ground up using C++ and Raylib. It accurately emulates the original 1970s hardware, from the display rendering (60Hz) for authentic gameplay, complete with automated CI & releases for Windows, Mac, and Linux.

Emulator Comes with some preloaded .ch8 binaries and you can import your own custom or internet downloaded binaries as well.

## Coming from High Level programing (Web Development), this low level project was new and i am now in love with low level concepts.

# What was challenging?
Fighting the operating systems to actually let people play it!
- The C++ emulation logic was fun, but building the CI/CD pipeline to statically link Raylib from source to escape Windows "DLL Hell" was a nightmare.
- I also spent way too much time trying to hide the developer console to make it look "professional," only to realize keeping the console is the only way to stop Windows Defender and Apple Gatekeeper from immediately flagging a statically-linked .exe as a virus.
- Other then just coding, a lot of time was invested in reading references, making the application actullay Runnable on different platforms

# Proud?
- Creating a GUI in c++, and actually implementing something in C++, not just doing Data Structure and Algorithm, but actually implemented something in C++.
- Leanrnign all these low level concepts about cpu, register, display screen, complier & linker, building cross platforn applications.
- The fully automated, zero-touch CI/CD pipeline. Right now, I can type git push origin v1.0, and GitHub Actions automatically spins up Mac, Windows, and Linux servers, clones the pure Raylib source code, compiles it from scratch, statically links it to my emulator, and spits out three perfectly zipped, ready-to-play release files. It feels like production ready.

  • 5 devlogs
  • 14h
Try project → See source code →
Open comments for this post

3h 28m 34s logged

Devlog 5: Making it Beep

Last time, I talked about how Continuous Integration was eating my time, Windows was demanding my soul with missing DLLs, and Apple Gatekeeper was holding my app hostage for $99.
This time, I fought back. The emulator is now completely polished, actually sounds like a retro console, and distributes like a real, professional application.

Here is what went down.

It Beeps now

The CHIP-8 doesn’t have a sound card. It basically has a timer attached to a buzzer. If the soundTimer register is greater than 0, it beeps. It ticks down at exactly 60Hz.

I basically wrote some code in c++ to generate a square wave, and used raylib’s audioPlayer to support classic beep sound of chip 8.

Production (The Illusion of Polish)

Originally, I hated that a black developer console popped up behind the Emulator. It screamed unfinished project.
So, I spent hours engineering it out. On Windows, I added the -mwindows flag to the compiler to change it from a Console App to a pure GUI App. On Mac, I completely rewrote my CI pipeline to generate a standard Apple .app folder structure so it would look like a commercial application.

the result? Total disaster. Because my newly polished Windows .exe was a standalone GUI application without a digital signature, Windows Defender immediately flagged it as a virus. Meanwhile, Apple’s Gatekeeper still blocked the .app bundle because I refuse to pay Tim Cook $99 a year.

The Real Solution: I reverted it all. I am keeping the console.

Git always has one more feature (Isn’t god’s another name linus?)

This was my first time actually using the tag feature of git in practical life, i after git push v1.1.0 i was wondering the new releases are created, code editor says everything is uptpdate with remote, but why the hell my gihub does not shows new code, and guess waht branch and tags need to be updated seperately.

Checkout latest release

0
0
20
Open comments for this post

4h 25m 14s logged

Devlog - Almost completed this time (almostt)

This time my goal was to convert this basic chip8 emulator in to something any user can use

coming from web development background, creating ui in C++ raylib was completely new.

No concept of ui elements here, cant just attach event listeners to button like we do in javascriot

What happens here is -

  • you create a rectangle, put some text in it, this becomes your button
  • then there is a constant loop running, which erases and redraws everything on the screen 60 times per second, just like a game loop.
  • now to detect mouse hover, or click, we need to constantly tract the mouse position 60 times a second, and check if it overlaps the coordinates of a button

But

  • i found an interesting piece of code raygui, written by the original creator of the raylib
  • it basically removes the manual need of tracking the cursor position and checking them with the coordinates of the ui elements, it handles click and hovers.

custom ROM import support

  • I wanted users to be able to run any .ch8 program they wanted to run.
  • I simply opened up a native dialog to select a .ch8 file and run it on the emulator.
  • I used AppleScript on Mac to trigger the file picker, but on Windows, I had to pull up a shell in the background

The Final Boss: CI and distribution

  • This is actually a big time eater, while implementing Continuous Integration i did countless iterations solving dumb errors, adjusting platform depended configs and so on…
  • but results are just as fin, now automatic releases are created for every tag.

distribution

  • macos blocks applications from unknown developer (i need to pay $99/yr to get verified, Best of luck with that Tim Cook), to fix this i am thinking to create standard .app structure not sure but it might tame the apple gatekeeper.

Apple wanted my money ($99), Windows won’t be happy without taking my soul

  • Like hell, every here and there windows throws some error be it missing dll or path problems or linker issue.
  • the biggest hurdle was that I don’t have access to a windows machine, I had to ping my non-tech friend with new .exe file each time. (aah friends are a blessing, aren’t they, my friend? huh?)

Checkout lateset release (supports mac and windows, can’t say about linux for sure)

running on mac

  1. open the executbale file inside the zip (i wont run, but it is required to open at least once)
  2. Open System Settings go to privacy and security scroll down there you will se option to open anyway
  3. each time you will have to run the application this way in mac (sorry i dont really have $99)

Can anyone with linux please let me know if it works (i am to lazy to install VMWare)

one more thing supported keys are (inspired from original chip-8 keys)

1 2 3 4
q w e r 
a s d f
z x c v

use thses keys to give input, nothing else will work (other keys only work in launcher interface like backspace to get back to menu form emulator)

0
0
22
Open comments for this post

3h 32m 26s logged

Devlog 3.

The emulator is almost completed and and can run .ch8 binaries

not fully complete it still requires some polishing like right now the graphics is flickering a bit, probably due to a bug in graphics engine logic or I might need to change how fast cycles are being executed.

Checkout my previous devlogs to know what is chip8?

What this time?

This time I felt like nobody in the world can explain the logic to translate those opCodes. Coming from high level low level is absolute new, i thought I might find some resemblance (guess what?? I was wrong)

I still can’t say in understand it 100%, but the struggle is on

Here’s what I learnt and built.

we load the ch8 binary file -> Save instruction in the RAM -> a continuous while loop which executes each instruction code

How does the program even runs?

  • Basically there is a while loop, which keeps on running unless user closes the program or program ends
  • This is where we write logic to
  • find which instruction code to execute next
  • Control the execution speed (clock speed of cpu)
  • Map keyboard events (more on this below)

How do we know what code to run next?

  • There is a function executeCycle, inside this funciotn we have -
  • A variable programCounter which tracks the current instruction code position and calculates next one too.
  • Then we have a huge switch case flow, which basically maps all the 35 standard instruction codes form chip8 to modern computer.
  • Then based upon the code, we perform tasks like painting a pixel or change some data in RAM.

To keep this short, I will not get into the details about translating the chip8 instruction.

Biggest man in the room - Graphics Engine (XOR)

  • we basically have black and white screen, 64px length and 32px height (we use multiplier so the size is not exactly 64x32, as that will be two small)
  • we then have 1s, 0s to represent black and white pixels
  • the engine basically deleted every pixel and re draws it again, this causes a flashing effect as moder screens are faster and also show the transition.

Collision detection

  • the value of a pixel is set to 1 (white) and 0 (black)
  • We take XOR of the Current value of the pixel and the to be updated value
  • if two pixels are white (1) the xor will be 0, and when this happens we set the Vf to 1, indicating a collision has occured.
  • Vf is the 16th register which is left empty and use only to show collision.

Keypad

keypad

The original chip8 keypad was like this

Chip8                                             Modern keyboard
1   2   3   C					1    2   3   4
4  5   6   D	        ---> 	        Q  W  E   R
7  8   9   E					A   S   D   F
A  0   B   F					Z   X   C   V

What’s left

  1. implement UI to control chip 8 settings like speed, screen size etc.
  2. Add a list of software that user can run, as well as option to run his own
0
0
7
Open comments for this post

2h 2m logged

Decades old Low level concepts are still haunting.. (Chip 8 Interpreter)

  • This is my first time building a proper low level project.(Strong Man Crying 😭)
  • its tough i had to study new architechures, understand memory bottlenecks, i spent aout 10% time writing code and rest learing , reading Chip8 technical references, banging head to AI to explain the low level memory concepts (So Exciting its an Automatic All-Nighter puller)

And .. heres what i learnt

waht is chip 8?

chip 8 basically a a interpreted programing language of ancient times (70s). It kind of mimics a small computer (8 bit), limiting its max memory to 4KB. But the special thing is, its not just a language, it mimics a CPU architecture, making it like a different computer system which doesnt exists phycally, but uses other physical computer to run its own acrhitecture.

What is Emulator

Well think of emulator as a extra added layer between the software and low level computer systems. which does some magic to run a software which is not ment to run on that system.

Windows Application –> macOS (Won’t Run)

Windows Application –> Emulator –> macOS (Will Run)

Flow

  • Lets say we have a software S, designed to run on System of type C1, but now we want to run the same software on a different system lets say C2,
  • S –> C1 RUNs properly
  • S –> C2 Fails as C2 cant understand the instruction that software S is trying to give to C2

Emulator in the picture

  • Software S (instruction codes for C1 ) –> Emulator (Translates Instruction code for C1 to C2) –> now C2 can run (Translated instructions).

Now Chip8 Emulator

Lets say you have a program which was designed in and for Chip8, but now you dont have a chip8 system, how do you run this program?

We basically use an emulator to trick the software to thing that its running in the old Chip8 system but its acctually running on moder computers.

Howwwwww? well Chip8 has 35 standard instructions and only 4096 bytes of memory, so its faily easy to map each and every of its instruction and instead do it in the modern langauges (like i have used C++).

We store the data in modern C++ Data Structures, but we trick the target software to thing that it has dorect acces to the RAM of the computer.

Current Status

  • implemnted the basic template to mimic real RAM for chip 8, which is basicaly an array of size 4096, weher first 200 are reserved for the chip8 system use, rest is opent to softwares running on it.
  • I have translated some basic codes, more on this in next devlog
  • A black window with raylib for now
1
0
31
Open comments for this post

56m 35s logged

Building an Chip 8 Emulator

This is like my first proper project in low level programing

I wanted to take on the low level for a long time, took the chance this time

I know only the basics of chip 8 interpreter , I read cowgod’s chip8 technical reference last night

this is gonna be a very learning and building like thing,

been into the high level for over 5 (Full Stack) years now, hope I can find some similarities and help from my past experiences in to the low level

is anyone of you guys (gods) know about low level or specifically chip8 , please drop a comment because I thing I am too going to need babysitting 😭

0
0
43

Followers

Loading…