The Chip-8 is a simple virtual machine from the mid-1970s designed to make game development easier, featuring a 495-byte memory layout with 16 eight-bit data registers, a 16-element stack for subroutine calls, a 16-bit index register, a program counter, and two 8-bit timers (sound and delay) that decrement at 60 Hz; the display is a 64x32 monochrome grid where sprites are drawn using XOR operations and wrap around screen edges, with a 16-key keyboard for input.
Chip-8 Emulator Basics: Architecture, Memory, and Display Explained
Added:hello and welcome and in this lecture you are going to learn about the basics of the chip eight so what is the chip aid the chip a is an interpreter from the mid 1970s it was originally designed to make the development of games easier essentially chip eight is a virtual machine so think of the java virtual machine of today but something far more basic that was essentially chip a chip eight interpreters can play many classical games such as pong tetris and space invaders chip a makes a great emulation project because it is simple to integrate so what are the chip a internals well the memory layout of the chip eight has four hundred and ninety-five bytes of memory take a look at this image here you can see that the start of the chip a dram is at address Co X zero zero and the bikes between address is 0 X 0 0 and 0 X 1 FF are reserved for the chip 8 inside this memory region we store things such as character sets but more on that later you can see that chip a programs start at address Co X 200 and the the program data and the program itself consumed the rest of memory the chip a also has a stack that is an array of 16 16-bit values used to store the address the chip 8 should return so when you call a subroutine in the chip ape it'll push the return address to this stack and then when you return from that subroutine it'll pop it back off the stack so then it can then carry on executing from where just came so the chip 8 allows up to 16 levels of nested subroutines and don't worry too much of you struggling to follow this is a brief overview and we'll be coming back to this as a reference as we go through the development stages so another note another important note is that the stack is not part of main memory so as I state here it's an array of 16 16-bit values so it is separate from main memory the chip 8 has 16 8-bit data registers you know these are kind of used to store general data such as the score in a game for example in pong you could use these data registers to store how much score each site each team has and and so on right obviously because they are only 8 bit wide they can only hold one byte of information per register so the chip 8 data registers should be implemented as a character array or the size of 16 because of the way the instruction set is designed and we'll get more on the instruction set later but because of the way it's designed it makes sense to use an array for these data registers and you'll see why as we start development so the chip a also has a 16-bit register named I this this register is generally used to store memory addresses so these are separate from the data registers the 8-bit data registers chip 8 has a program counter and basically the job of the program counter is to point to the memory address of the instruction that we're currently executing right when we are ready to go to the next instruction you increment the program counter by 2 bytes and then the next instruction will then be executed in the chip 8 instructions are 2 bytes in size which is the reason why we increment by 2 so the chip 8 also has an 8-bit stack pointer and this points to a location in the stack if you remember earlier on in this lecture I spoke about the main memory and the stack and how they're different and so on while the stack pointer points to a place in that stack right we increment and decrement the stack pointer one we call subroutines and when we return from subroutines so the chip a toss has a sound time and a delay timer and these are eight bits wide and when above zero they decrement at a rate of 60 Hertz so let's first discuss the sound timer chip a plays a beep when the sound timer is not zero and this is implementation Pacific so you pick the frequency of the beep it's literally just any any type of tone essentially but not multiple tones right that's what the standard allows so it can be a beep a bleep you know it can be like any type of sound you like but the sound should be consistent and the sound timer decrements at a rate of 60 Hertz and when it when it's zero again the sound no longer plays so the delay timer works a little similarly to the sound timer apart from instead of playing a tune it delays the program so what will happen is it'll stop executing instructions when the delay time is above zero and then it will decrement the delay time at a rate of 60 Hertz one the delay time is zero again the program resumes execution so essentially the program just doesn't continue running when the delay time is above zero and then it will be decremented at a rate of 60 Hertz as soon as the zero again the program will start carrying on running from where it was I think of it like pausing again right a little like that everything stops right the same sort of thing apart from is based on a delay and not an action ok so the display is probably the most complicated part of the chip 8 mainly because of sprites but we'll get on that soon so the chip 8 has a display size of 64 by 32 pixels it's a monochrome display which means they can only have one color pixels only have one color right they either on or off so the pixels either on or off and that's a monochrome display basically so we can see here the white means this on black means the pixel was off and this is a screenshot from space invaders on the ship eight emulator so drawing to the chip a displays done with sprites as I just said not pixels so when you draw a sprite to the display if it's somehow goes out of the screen bounds what happens is it wraps back around to the other side and starts drawing the pixels that went out of bounds from the start think of pac-man you know you know pac-man when you go through one side missed and Patman comes out the other side right you know when you go all the way to the right the screen and then it comes back to the left it's the same type of thing so sprites are many pixels grouped together that can be drawn to the screen as a whole so think a copy and pasting an image into Microsoft Paint right it doesn't just pace one pixel right it pastes the whole image so that's a good way to think of sprites so these are sprites in the chip eight for the number zero and the number seven so I want you to notice something here right to the right here is hexadecimal in the middle is binary and on the left is just just a little character equivalent that I've drawn just so you can see what's happening right so notice here one means the pixels on 0 means the pixels off right so if we look here we can see one one one one right and then if we look at the character clev we see that asterisk asterisk asterisk asterisk right so the rest is blank because the final four zeros here the final four bits here is zero right if they were all one then we'd see eight characters on this first row and not four again if you look at the second row here you look at the binary equivalent one zero zero one and you see that this one's on this one's not this one's on right so you can see the two bytes here are zero so that's why it gives us a completely empty middle and then finally we end up with one again so I hope that makes sense you can see how that's working right so spikes can be a maximum of eight bits in width you know hence eight bits and a bike right you can clearly see that each row is represented by one byte by looking at the binary equivalent here so they can also be up to 15 bytes in length so that's our y-axis so when I say length I mean row so we can see here this is one row this is one row this is one row this is one row and so on right so again eight bits in width because there's only eight bits and a byte but it can have up to 15 bytes in length okay so that that sprites for you and we know we know how at the length of a sprite because there's a draw instruction in the chip eight instruction set where we specify how many rows to draw so that's how it knows okay well we'll get to that later okay so now let me explain how the drawing procedure works so the sprites get drawn to the chip a display and if the pixels go out of bounds so you know the X is above or equal 64 all the wires above or equal 32 then the breach in pixels wrap back around to the start of the display from x coordinate 0 or y coordinate 0 so if you draw quite a large sprite and I don't know maybe half of it breaches the bounds the other half will be drawn at the start of the display right while the other half will be at the end of the display I hope that makes sense but if it doesn't don't worry because this this lectures just to show you the brief overview will go into much more detail later on when we start implementing this so sprites are also XOR down to the screen if you don't know where an XOR is you really need to research that because this course there's a lot of bitwise logic goes on so it's a bitwise XOR so you can look that up that's not it bitwise operators aren't too complicated but they get basically this rights get X hold onto the display and if this causes any pixels to be erased then the V F register is set so if you remember in this lecture I spoke about the data registers right while the VF data register is set to true or 1 I guess I guess it'll be 1 it's set to 1 if and if when we XOR this sprite to the screen it causes any pixels to be erased otherwise we set the VF register to 0 right so if nothing is erased then V F becomes 0 so the chip 8 has a keyboard with 16 keys from 0 to F and you can represent this in your emulator as a 16 byte array with a true value in the array meaning the key is pressed down and a false value meaning the key is not pressed so chip 8 programs will essentially say it is the F key down or something right or is the a key down or is the one key down you're responsible for interpret interpreting that instruction depending if a key is down or knob so that's why we represent our keyboard as a 16 byte array and obviously what we would do then we would map the real keyboard because you're not playing on this old hardware right we're not we're not making this emulator for this old hardware okay so obviously you're gonna be using your PC keyboard right so we'll need to do some key mapping so you know if they press decimal 0 on on a desktop keyboard for example it would set the chip eights keyboard to 0 because this is virtual hardware remember right but don't worry too much about that all that makes sense soon so this is the actual layout of the chip a keyboard obviously because we don't own this real hardware we can't really represent it like this but essentially this is what it looks like so the instruction set the chip 8 has 36 different instructions that need to be implemented for a successful implementation so these instructions are responsible for mathematical operations drawing and a lot more including like bitwise and bitwise or and so on so we'll explain more about the instruction set as we go through this course but this has been an overview of the chip eight many thanks thank you for watching this part of the course you can find the next part in the video description
Up Next

Build a CHIP-8 Emulator in Zig | Beginner Programming Tutorial
@Iridescence
23.8K views•2023-01-15

Introduction to Secure Multiparty Computation with Yehuda Lindell
@fhe_org
7.7K views•2021-02-04

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science




![02. Двоичная и шестнадцатеричная системы счисления. [Универсальный программист]](https://i.ytimg.com/vi/NWWNbTelHns/maxresdefault.jpg)






















![VOD: LaunchBox Unplugged [24/04/25] - LaunchBox Questions & Hanging Out](https://i.ytimg.com/vi/b5FKLYOn3z8/maxresdefault.jpg)











