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

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
7

Comments 0

No comments yet. Be the first!