This video demonstrates how to build a CHIP-8 emulator in C, focusing on implementing the clear display instruction and sprite rendering. The key concepts include: (1) The CHIP-8 display is a 64x32 pixel monochrome screen where each pixel is represented by a single bit in a 2048-element array; (2) Sprites are 8x15 pixel binary images stored in memory that are XORed onto the display, with collision detection setting the VF register when pixels overlap; (3) The emulator must implement 35 instructions, with the clear display (opcode 0xE0) clearing all pixels to zero; (4) Proper memory initialization using memset is critical to avoid garbage values; (5) Bitwise operations like masking and shifting are essential for extracting individual bits from sprite bytes to determine which pixels to draw. The project demonstrates how low-level programming concepts like memory management, bitwise operations, and instruction interpretation work together to create a functional emulator.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Building a CHIP-8 Emulator in C
Added:Okay, we are back. We are so back.
Uh, shift what? W. No, shift T. Let's do tab.
Back, baby. We're so back.
[snorts] All right, so our Puritan, hey, good to see you. It's been a minute. How you been? [snorts] How's life?
Hopefully it's treating you Hopefully it's treating you well.
Um, okay. We need to organize ourselves here again.
Bottom.
Rename this to be I guess Neoim. We'll put in this window.
We'll put our terminal over here.
We will put our what our I guess our spec over here.
Sounds reasonable.
Okay.
Chip confirm.
Close that. We don't need that open.
All right. So, MPX live server.
Fire up our specification.
Okay.
Well, when last we left our hero, [laughter] he was making his way through the dangerous world of manual memory management.
ETI, which is a ETF version of VTSAX, which is Vanguard's total stock market index fund. Now, this is not financial advice, okay? So, don't don't treat it as such.
But I think that would make your life a lot easier if you also used index funds.
Yeah, I'm pretty close to aligning Vu.
Oh, Vu. Okay. Yeah. Isn't Isn't VU like a triple leveraged version of the top 10?
It's a leveraged ETF, right?
Or am I making that up?
Uh, twothirds is in the S&P already. Yeah.
Two. So, yeah. Okay. So, I guess you're not they're not that dog water. Uh, let's see. Boo prospectus.
I guess there's actually a a big issue with leveraged with leveraged um I think it's leveraged ETFs in South Korea because guess their their stock market had a Uh let's see in let's see product summary invest in the stocks in the S&P S&P index representing 500 largest US company's goal is to closely track their index returns which is considered a gauge.
I thought I thought VU I thought VU had some leverage involved in it. Uh leveraged ETF.
VU is just the day trading S&P 500. Is it is it just the ETF of the the 500?
Yeah, I I must be making this up then.
Yeah. Okay. Yeah, it's just Yeah, it is.
It's just uh looks like it's a complete Vanguard S&P 500. That's where my money's at. My money's in uh I have I have the John Hancock equivalent of this basically and then the rest of it's in VTI. So, yeah, we're we're on the same page.
Uh, a VTI is total is the total stock market. So that's the only diff I guess that would be the only difference between VTI and VU is VU just tracks the top 500 and then VTI tracks all publicly traded stocks. So you get you just get exposure to the small caps. But I mean they're all cap weighted. So even if you're in VTI, most of your money is going into those top 500 companies anyways, right?
Someone went into the quant subreddit and asked all the quants what they do for investing. [music] Apparently they all just all in VU, which was kind of funny, but it's the it's the truth. It's because they're smart and the data shows that over a long time horizon, nobody consistently outperforms the market.
People might out people every year might outperform it, you know, a handful, but it's never the same handful and never the same handful for, you know, decade after decade. I mean, if if Warren Buffett says that his recommendation to his heirs is to put their money into an S&P 500 index fund, it's it's probably good enough for us normies, right? Like uh so yeah, that's that's where all my money is at, too.
I'm still in indexes. Socks. What's I've never heard of socks before. Good morning, Cyberlanka. Nice to see you.
Trying to ride the microchip train a little. Nice. Nice. I just I just dollar cost average invest every every paycheck. And uh this this year's goal is to max out my 401k and to max out my Roth IRA. That'll be this will be the first year that I've been able to do that, which will be a huge accomplishment. It's the first year that we're completely debtree, which has been awesome. So hopefully we can keep this trend going.
Uh I don't even remember where we were.
Uh we were handling we were printing everything out to a CSV. Yes. So we printed everything out to a CSV. I went through yesterday and basically just collected all the op codes that are in this file that we need to implement and then we're going to try to implement them and go from there. I think I'm going to leave I think I'm going to leave the ability to Do I want to leave it? I don't think so.
I don't think I want to leave it. I'm going to remove the CSV printing. We don't need it.
Uh, let's go ahead and clean this up. We don't need to do that.
Don't need to do this.
We don't need to do this.
I won't pay off my house till 65, unfortunately. Yeah, I don't I un I unfortunately don't even have a house.
We We still rent. um the cost the the place we live is pretty high cost of living and so it seems like every year the amount of money we need for a down payment just outpaces the amount we're able to save for said down payment.
Uh, so I think eventually we'll probably buy, but I don't know if it'll be any time.
I don't know. It It's definitely more of a long-term goal than a short-term goal at this point. So, we just rent right now.
one of these days.
So, okay.
[snorts] My purchase of the house made no financial sense. Well, I can't say that every decision I've made personally regarding finances has made since. So, no shade, man. No shade.
Am I done with bootdev? No. So, the thing we're working on is for boot.dev.
So, this is going to be my my first portfolio project, Cyberlanca. Um, it's just taking me probably longer than it should cuz I talk to people on the internet while I try to do it. and then and I'm only working on it in the mornings while streaming, so it's it's taking me longer than it probably should, but I'm having fun.
So, we need to add basically a massive switch statement right here.
And for now, we'll just make the default case The default cases will just print something and we will say unhandled op code and I'm going to actually make this be percent x or no how do we print yeah x's then we'll do our first case so our first instruction is going to be to-dos we're going to implement clear display so this is the op code we're looking for and hopefully we can make this happen.
Make it happen. Captain Rent was easily half as much and I didn't have any maintenance work to do.
I mean, it's it's kind of a crapshoot, man. Which way you go on it, right? Is it I mean I feel like some people get lucky and they buy a great house and you know the maintenance is relatively minimal and the appreciation's wonderful and they're building equity and it the the you know it's it's all rosy and then I you know I have friends or family who bought a house and it's just it's a it's a nightmare. they're, you know, they're 50 60 $70,000 into it before, you know, before basically they even sign the paperwork. And yeah, I I think it's hard. I think it's I think houses is is one of those things that too many times is looked at as a or owning a home is too much too many times looked at as a requirement and a necessity. And it's probably more of a luxury or at least you should approach the purchase in more with more of a it's a luxury mindset rather than it's an investment or a financial asset on my balance sheet.
And that's just my opinion, right? It's I think I think home ownership has far more to do with like your lifestyle and what you want for your family than it does like am I making a smart financial decision? Again though, that's just one guy on the internet's opinion.
Steven needs to make some YouTube money and start his own terminal. Coffee.
Dude, I would love to have a coffee company. So, when I was 20, like this would have been 2018, I actually had emailed a emailed a company. I wonder if I can actually find these emails. That was actually one of my ideas was I'm going to start a dropshipping coffee company.
And I went as far as like having some initial sales calls with the company, but I ultimately didn't go through with it just cuz I got nervous about having to do uh minimum what do you call it? Minimum minimum quantity order. I got nervous about the minimum quantity order. I never actually went through with it, but I did I remember having a couple phone calls with the guy.
Yeah, this is it.
Is it okay to dock somebody on the internet? This was it. This was back in uh November 26th. It's kind of hard to see there.
November November November 6 of 2017.
I guess I was looking at a company called joe'sg coffee.com and I I wanted to name it I wanted what did I want to name it? I wanted to name it Yeah, this was the name I have or this is this was the name of the co the coffee company on the hustle coffee company. [laughter] Why? Why that? I don't know. Uh I was watching a lot of Gary Vee I think at the time. Um but what are you going to do?
Maybe maybe it's time to pursue that dream again.
I tell you what though, the Terminal Coffee guys, their thing is just wicked cool. The SSH store, the merch is great.
The design of the bags is great. I've never had any of their coffee.
That's good stuff.
You were still in high school back then?
Yeah. I would have been see 2017 I would have been 20 7.
No, 25. I'd have been 25. It was about a year after having my first kid. A couple years after having my first kid.
God, that seems like a lifetime ago.
Hey, what's up, Gosser? How's the emulator going? The emulator is going.
It's going well. Sounds peaceful to start a coffee company. I think it would I think it would be a lot of fun. I don't know about peaceful. I think any company's probably a little little stressful just because you got money on the line.
Don't do it. YouTube will remove your stream now. Oh no, I violated the ultimate.
Let's see. Houses here are like 400k to 600k for a bungalow. If they were more, wouldn't have been able to afford it.
Yeah, it's it's uh that's about the median price of a home where we live.
And last time I looked, rates were like in the five to six range for most mortgages here, 30-year fixed mortgages.
So, what what are you going to do, man?
Housing, it's a necessity. You got to you got to you got to deal with it some one in one way or another. But it's a pain it's a painful thing, man. I think our rent is 2,000 500.
It's unbelievable.
It's unbelievable.
Rent was 14. Yeah. So, we we were at last year before we moved here, we were at six like 1645 or something like that, I think, at our apartment. And then we moved to this single family house in September.
And the rent here is 25, which is just un unbelievable, but it is what it is.
All right. So, we need to uh let's see hexadesimal converter. We basically need to mask the cuz we only care about the first what is it? First four the specification say we only care about this is 12 bit memory address.
The lowest eight bits of the instruction. No, the four lowest four bits of the instruction.
I think we we basically need to get we need to get uh So, we need um hexadesimal to decimal inverter.
We need this value. We need F 0 0.
Oh, my computer's kind of moving slowly on me.
Yeah. So we need this value.
Yeah, that's 16 bits, two bytes, and we're going to mask the first four bits.
So, this would be 6,440.
and then we need to switch on it. So can we define our switching uh switching it as uh cases I wonder So this would be let's see hex is hex is 000 e zero.
So this would be 224.
Oops.
Print line.
Clear the screen.
Clear.
Oh, clear display, I think, is what we called it.
Clear the display.
I don't want to print all that out anymore.
So, those are all the unhandled op codes. So, for now, let's just skip.
There was a message though at the top of the What was that?
Unused var Oh, those are unused variable warnings. We do have unused variables.
So, this says there are no clear display instructions, but that's not true.
That's not true.
So, what have I done wrong?
I guess let's print the op code before we enter.
I think the very first uh instruction is actually a clear display instruction.
So that's op code 202.
So, what? Oh, whoops. No, it's not.
I printed the wrong thing.
Probably don't need to keep doing this over and over. This is probably a very inefficient way to go about doing this.
So, we should be looking for E0.
And why is that? Why are we looking for E0?
I thought I just put this into the Did I just put the wrong number in? X to decimal 224. Did I just put the wrong No, that's the right value. So, what am I doing wrong here?
Am I masking the wrong decimal to binary?
I've done something wrong.
Please hold.
>> [snorts] >> Please hold.
No, that's the right. Okay. So, what have I done wrong?
I'm stuck.
So what does this that what's what does the switch statement represent? Um, it represents So, this represents me grabbing the furthest left, right?
So, let's print this.
So, my I think I think the case I think the case is wrong. I think I'm looking at the whole hex value there. And I think I need to be looking at the last the last um the last digit or the la last hex place. So last, let's go ahead and per uh parentheses x.
We're doing a little print f debugging this morning.
Hey, what's up Arvin? Nice to see you, sir. Hope you're doing well.
Hope life is treating you treating you good.
Okay. Does that make sense?
Yes. So, actually what we're doing is we just are looking at the last the last place which I think makes sense with what the right so we're looking for this one this one now we will have to add I guess some additional checks to check to see if it's like in this case we need to know is it return or is it clear and we'll have to do some of the same some of the other things the same way.
Okay, so this actually should be checking for the presence of zero.
And then once we're in here, we should also be saying, okay, if uh op code equals I'm going to take these magic numbers and I'm going to stick them into um I think a an enum So we need to look for if that is equal to this guy which is what in hex or I'm sorry that is what in decimal form 224. So then we can do if op codes 224 then we know it's clear the display.
Now, let's see if we get a Let's remove that mast and let's remove that.
Now, let's see if we get a clear display message, Brennan.
So, we have four clear display commands.
Wonderful.
So, what we need to do now is we need to figure out how we actually model the display.
So the display is here we go display. The original implementation of the chip 8 language used a 64x 32 pixel monochrome display with this format.
Some other interpreters, most notably the one on the ETI 660, also had a 64x 48 and 64x 64 modes. To my knowledge, no current interpreter supports these modes. More recently, Super Chip 48, an interpreter for the HP48 calculator, added 128x 64 pixel mode. This mode is now supported by most of the interpreters on other platforms.
Chip 8 draws graphics on a screen through the use of sprites. A sprite is a group of bytes which are by which are a binary representation of the desired picture. Chip eight sprites may be up to 15 bytes for a possible sprite size of 8 by 15. Programs may also refer to a group of sprites rep sprites representing the hexadimal digits 0 through F. These sprites are five bytes long or 8x5 pixels. The data should be stored in the interpreter area of chip 8 memory. Below is a listing of each character's bytes in binary decimal.
Okay.
Interesting. So what do how will we represent that?
We need some way to represent the display on our chip. Hey, what's up sub Idra? I think I said your name correctly. Hello Justin. Good to see you. Morning. Good morning. You off to the gym.
Why people fight regarding C verse rust?
Any idea? I think it's just human beings are inherently very tribal in the way we operate. And so we like to we like to turn it into I belong to this thing, right? Or you belong to this thing, right? We we're very in-group outgroup. That's just how we are. So if there's a way to form kind of tribal lines or party lines on something, we will. So you know there there's a good example C versus R, right? You have both communities both like to write low-level high performant code and instead of embracing one another, right? It's uh it's I'm a part of this team and you're a part of that team and we must we must destroy one another. Why? That's our human instinct, I don't know. But it exists everywhere. It's not just a computer developer software engineering thing, you know.
I like the vid cuz this video, not going to lie, deserved it. Oh, thank you very much. I appreciate you liking liking the live stream. It's very kind of you. Not no gym today. At least not right now.
Maybe later today. Working on something.
Oh, very cool. All right, man. Well, I'll be over here working and I hope you uh I hope you make some progress.
Or are you talking about the bunig bun zig drama? I guess that could be it.
C verse rust. Who wins? I don't know. I don't know enough C and I'm not good at good enough at Rust to be able to really have an opinion on that. [laughter] Uh I think right now I'm finding Rust to be easier to learn and easier to work with at the moment than C. But that's it's not really a fair comparison because I have more time under my belt with one than the other.
So I guess talk to me if we ever get to the end of this project. Maybe I'll have a a different opinion.
The Zig author attacked the founder of Bun. He threw a tantrum basically. He Yeah, he wrote a he wrote a blog post that was uh it reminded me of the internet of old [music] that you know it was it was very uh [snorts] I don't even know what the word is. Uh opinionated. [laughter] Opinionated. That's what I'll say.
Although I don't I don't understand why everyone I mean the crazy thing to me is just like how worked up everybody gets about [ __ ] like that. It's like guys it's just two nerds fighting on the internet. Everyone just needs to chill the [ __ ] out. Like there's people starving in the world.
There's kids dying of cancer. It's gonna be fine. Okay. It's gonna be fine. Who cares what Andrew Kelly says about the other dude, right? Who cares what that dude said about Andrew Kelly? Who cares what they say about each other's product? Like, just chill out. Like, Theo Theo posted a video and he was so angry over it and I was I was like, man, it's not that deep. All right, it's not that deep. You need to go unplug for a little bit, you know? [snorts] Just laugh at it and move on with your life.
It does It's not I I don't know. I don't understand people getting so emotional on the internet about [ __ ] I always tell people tech introverts are drama queens. Oh my gosh, dude. Drama.
Drama 100%.
I'm working on net signal API that powers a web GPU simulation. Wow, that does sound like interesting stuff. It also sounds way more complex than what I'm working on over here.
I'm working in C++ to create a BF interpreter. What's a BF interpreter?
Binary. Is that a binary format interpreter? God, that website was blinding me. Unplug is right. Yeah.
Got to go hit a nice lake in a beautiful state. Exactly. like go go go out touch some grass stand in front of a big a big mountain or a big body of water and just remember how small you are and how insignificant everything is and enjoy your life.
So how does this emulator work? So essentially the way it works is there's a defined set of instructions that they tell you that you need to implement and then you implement them and some of those instructions have to do with clearing the display. Some of them have to do with setting registers.
And your job is basically to implement the instructions and model the different pieces of the chip so that you have a place to stick instructions to track the current uh state of the program. And then at some point we're going to try to figure out how to print the state of the display to the screen which I don't know how to do. I think we're gonna try to use Ray Lib to do that, but I don't I don't really know.
This is a way uh cool way to learn. Can you leak the source? Yes, this is uh this is called this is what this was the best resource I found on the internet for this or appar I I shouldn't say I found it. A lot of other people have recommended it.
It's called cow cow's chip 8 cow's chip 8 spec.
I guess it's like super well known. I had never heard of it before, but I guess this is what everybody swears by if they try to try to do this project.
Here's the specification for reference for chip 8 emulator.
And please take everything I say with a grain of salt because honestly this is all this is all far beyond my comfort zone.
And then I'm keeping my code here if you guys want to look at my code. There's also there are there are I will let you know there are done for you implementations of this. So if you ask an LLM about it, it will likely oneshot it because lots of people have built it before. So, just be mindful of that in case you want to avoid the LLM giving you the answer.
There we go.
So, it's like your own assembly language. Well, it's more of I'm writing an interpreter for an existing set of of it's yeah, it's basically there's a chip 8 language that people author programs in and I'm basically building an interpreter for that. Um, that's probably the better the more accurate description cuz we're going to take like existing files that other people have imple implemented. Like this one that we're trying to do right now is a it prints the IBM logo and somebody else wrote that program in the chip 8 instruction set or language and we're just going to parse it and do what it says in our program.
or we're or we're we're gonna try to do we're going to try to do it. So, we're going to try to do it. [snorts] So, we need we need to figure out how to model our display. That's what we need to do. So, I don't know what this needs to be, but we need to have something here.
Model display.
And um I'm thinking it needs to be some sort of an array, right? Cuz we're modeling a 64x 32 screen, I think.
Hey, what's up, Kale? How you doing, man? Thanks for being a member. Nice. Of course. Yeah, of course. Although it's what you're what you're working on, Justin, sounds equally as interesting.
Okay. So, it doesn't explicitly tell me.
It does not explicitly tell me how to model that. But we have 64 by 32 pixels.
So, what we So, I'm not really sure how to how to do that. I'm going to Google. [snorts] Let's see. Uh if we're going to use Ray Lib, see Ray Lib, how to model 64x 32 pixel display.
>> [music] >> Ray examples.
Oh man, there's a lot of documentation on Rayb. That must it must be super popular library.
>> [snorts] >> If you want to define them, you can do it that way. See, define screen width as constants. Window scale 10 scales the window to 640 by 32 for visibility. So, will that fall into RayB or SDL2? I don't know what SDL2 is.
I've only ever heard of Rayib, but I'm open to suggestions. Whatever people think is the easiest for me to work with.
I've not worked with I've not worked with any of them. I'm on the Ray I think this is this is called Ray Extra GitHub. First off, what a cool GitHub readme. They've got all these like visual gift examples, but I was more of just trying to make sure that I model this data in a way that is compatible with what they expect.
Um, but maybe that's not the right approach.
I mean, I need 64 by 32. So, I know I know I need at least an array of that size, right?
I have not used Emacs. I have not used the e Emac. There's a um there's a creator that I like. Her name's Bash Bunny. She uses Emacs and every time I watch her stream or program, I always think that looks like it could be fun or equally as fun as Neov, but I've never actually tried.
Let's see. Ray Lib can be easier. It's a game library though, and SDL2 is purely a graphic. So maybe SDL2 is what I need because I just I don't need a game library, right? Okay. I want I need I need like the simplest the simplest stuff.
Um so we're going to need So a pixel is three values, right?
But it's monochromatic.
So does that still make sense?
I guess. How big how big should the values in the I guess I'll just go with uint 32 display and this will be the or I guess 64 is it 64 by 32 is the size of the display.
And then I guess I can define these as constants like Kale said. So we could say define screen height to be 64.
define screen width.
It's 32.
SDL is used is by Valve and stuff. Super complicated, but allows for total controlled revulcan and OpenGL. SDL2 has a higher learning curve. Okay. Well, maybe Rayb then. I don't I don't know.
May maybe that's one where we consult Gemini. I I don't know. I just I don't want to get so lost in the weeds on like the actual rendering of the stuff to the screen. I'd rather just I'd rather just uh be able to like give it here's my data. Please make a window.
[snorts] Ray lib is what? Okay, then then we'll do that. We'll plan on that.
So, how would we then clear this? So, if we're going to clear it from the screen, where's our code here? So, what would be the action we would take here? I guess we just reset the re reset the array.
Graphics is annoying. It's a whole can of worms.
It seems like everything and sees a whole can of worms.
None of it seems none of it seems easy or simple, but it is what it is.
It is what it is.
>> [snorts] >> Okay. So, best way, let's see, uh be best way to reset [snorts] array in C.
Reset inter array to zero.
How to clear all the elements of array and C reset C.
Oh, we can use mim set. So automatically allocated arrays heap allocated arrays where n is the number of elements. I think we can just do this mess set pass in this and pass in the size.
So C documentation MIM set give this a perusing [snorts] copies the value into each of the first oh this is in string.h is that what I want string.h H mim set int array using mim set for integer array.
So it comes from string.h but we can use it on our array our in array.
Okay. God, dude. This uh Where's dark?
Where's Hold on. Let's turn on dark reader mode on.
Dude, these websites are just like flat flashbang. Flashbang.
Another flashbang.
>> [snorts] >> Okay.
So, that's what I This is how I'm going to clear the display essentially.
Let's do mim set.
And we need to bring in include what was it? Include string. Include string.h. H control O remember my good Vim my good Vim skills. Then we will do chip display zero size of chip display.
I think that's I think that's it.
I think that's it.
You do need string.h because the C standard library historically treats block of raw memory as bite strings or character arrays.
Well, what that's what we're going to use it.
We're going to use it. So, there we go.
Now, the question is, will the program run? I'm hoping so.
error display unexpected specifier qualifier list before display.
Is that because I didn't use screen height, screen width. I guess I should use this was down here.
screen height.
Ice cream.
[music] Oh, we don't need this. I had it declared twice.
Okay. Go back to the spec real quick.
I don't really understand this though.
Do you guys understand this? What is this? What is this telling me?
Is this telling me top left of the screen is zero?
We print all the way to the other corner which is the 60.
Oh, I think I have these. Do I have these inverted?
I think I have them inverted.
I think this should be screen width is 64 and screen height is the that's the chords of the canvas you're drawing. That's I think I have it inverted though, don't I?
Cuz based on their coordinate system, I think it's 64 width.
All right. If I If I'm doing this wrong, just just yell at me.
Yeah. With time. Okay. Yeah. So, I got I add it wrong. I had it wrong. That's my fault.
Screen width times. I know this doesn't make a difference, but just from a reading perspective, it helps me.
All right. So then let's try in the loop. Let's try to print our display as a grid in the terminal and then we'll process our instructions.
So let's print the loop to the terminal.
So how do we print this? So this will be uh for int i equals z and i is less than [music] the screen width.
How do we go? I actually I actually think I want to go I think I So I want to print each row just like we would in admin of code.
So, I actually think maybe I want to do height first screen height and then we'll do four int J equals Z I is less than screen width I ++ S+ and then we're going to want to do so the last um [snorts] uh let's see I know in here what I want to do is I just want to print uh print f Oh, so this should be J.
Just make sure I have this right. And then up here we should print or down here we should print f new line.
Right. So basically for every or for every row we're going to print a series of stars and then once we print that series of stars we'll print a new line next series of stars. So let's see what this looks like.
Okay, we didn't didn't do anything.
Why did we not do any Did I not write the file out? Didn't write the file out.
Whoopsies.
Unexpected error.
Oh, I'm missing a parenthesis.
I I also don't want to do it I don't want to do it a bajillion times. So let me actually let me just for the for the sake of visual let me do that here.
We don't have any matching language servers.
do that here.
And I'll just print it right before we clear it each time.
Yeah. So that's our display.
That looks correct.
Now let's actually print what's in there. So instead of printing I, we will print whatever the outer is plus the inner.
So we will print um chip display at i + j.
Right? So I + J would be 0 0 then 0 1.
Yeah, I think that's what we want.
Error called object is not a function or a function pointer.
I'm an idiot. My bad.
So percent dus.
Oh, I did. I did. I did. I called it like a function. I'm sorry. I'm sorry.
The compiler is right. I just need to listen to it.
Who needs Ray when you got a two chip eight? [laughter] I know, right? Okay. So then, so everything's set to zeros, right? That's good.
Uh aside from the fact that there seems to be something going on here.
Okay, that's interesting. Not what I expected.
So, where is that coming from?
It's only on the first loop.
Interesting.
I don't know where those values are coming from.
Good to see you, Gunheis. Thanks for being a member, man. Good to see you.
God, good. God damn it. Isn't that that my favorite stream? Well, thanks for stopping by.
I appreciate it.
Okay, I just printed I printed this, but I don't know where those other numbers came from.
Is it the same numbers every time?
No, it's different.
So something I've done.
So I initialize the array when I initialize the chip.
Hm.
H.
I should have a Minecraft coffee mug.
That would be great. I don't have a Minecraft coffee mug. I did get a new shirt, though. This is my newest This is my newest shirt that I made for my store. I don't know if you can see what it says. It's kind of hard to see in front of my microphone.
I I think I'm going to wear it to KCDC.
See how many people notice. [laughter] Let's see. Your uninitialized memory holds bite values like 56 42 179. Print f squashes them together making it look like a massive integer string instead of individual pixels.
Oh, so my array is uninitialized. So I need to initialize it. Okay, I can initialize an array.
But I thought it uh let's see uh Awesome shirt. Thank you very much.
Yeah, I I like I like having the ability to just make t-shirts that I I want to make.
Oh, so it is uninitialized because I allocated the memory with Malik.
So what if I use Okay, so what if I use So I I guess I can do one of two things, right? I can just initialize it here or I guess I can initialize the struck differently.
told you calic calic for you did tell me that actually you did tell me that okay so let me just I'm just gonna do it this way but maybe we revisit it so if I want to initialize the array would I just do a similar mim set me mim set operation cuz the memory's allocated It just needs to be uh initialized, right? So, wherever we're clearing the display, we can basically do the same operation.
Dude, I've got to refactor this at some point cuz there's just [ __ ] everywhere.
So this would be Mim set.
Yes. Now, now we are not getting all of that. What did you call it? What did you call it?
You said residual RAM garbage.
We are getting no residual RAM garbage.
Can you just manly null it? Can you just manually null it then initialized it via for loop?
Uh I don't actually know. Maybe maybe I'm going to try this approach for now.
So I'm just I'm basically just like initializing the state right now up here. So I just added it and I think that's what we need to do.
So let's assume let's assume just for just for the sake of the program let's assume we set it to one. So we initialize everything on. So every pixel of the screen is on.
Okay. Something just happened.
We have a bunch of crap in there. So why are why am I seeing that and not numbers?
Okay, me set doesn't do what I think it does.
Me set MIMS set allows you to fill individual bytes as memory and you are trying to set integer values maybe four I'm reading a stack overflow post your approach will only work on the number zero and negative 1 as these are both represented as binary the for loop isn't too much bother There.
Yeah, I I basically just want to see it changing, you know? I want to see I want to print it changing.
So, I guess let's just do the for loop.
So we'll do uh I is less than size screen width times screen height is less than uh sorry I ++ and then we'll just say chip display at i + one.
Cool. It works.
It works. C is the culture. [laughter] Cal may be best because it's contiguous allocation will avoid this.
Cal always with dynamic buffers.
My watch is telling me I need to stand up. Well, have I really been here for already two hours? That's crazy. We've done very little.
Print numbers to a screen.
Just doing some kettle bell presses real quick.
Okay, I say we have officially implemented the clear display instruction.
10 squats, 10 cal raises, 10 hip circles.
Uh, I did my movement break. I did uh kettle bell rows and kettle bell presses.
I say we get to mark something off our to-do list.
Now we get to jump to an address.
So what we want to do now is we'd like to say case what was the number one.
So we need to add the number one here.
And if the op code equals well actually I don't think I need to even check that because I don't think there's overlap between Yeah, I don't think there's overlap. I think it's just Where did my Yeah, there's no other there's no other instruction that shares that. So if it's one, then we have the 12 bit memory address, right? That's what NN is. Yeah, 12 bit value, the lowest 12 bits of the instructions.
And the 12 bits represent There's also a 16 bit register called I.
This register is generally used to store memory addresses. So only the lowest rightmost 12 bits are used.
Yeah. So it's a 12 bit memory address and we need to set it some to something.
Jump to location in we have in.
So that's pretty straightforward, right?
Coffee time. Almost coffee time. I'm still working on my first cup actually.
So Sock Sock Nanccock Sock Nanccock I don't know how to pronounce that. I don't know how to pronounce that username. how many language you have messing with. So mostly I've written C and TypeScript in my life. Um after that it would be probably Python or Go is kind of the third most and then after that would be Rust which is what I've been writing the most of lately in my free time. I write a lot of TypeScript and C for work and I've been writing lately a lot of Rust in my free time.
But I'm I'm not very dogmatic about like what language like I'm my position on all this stuff is like if it's if it's workrelated you got to do what whatever work's telling you to do you got to do like you got to make money right if it's your own personal projects or your own personal workflows or software you're building for yourself I say use whatever tools and tech stack and whatever thing gets you fired up and ready to build and makes you excited. That's what I would use.
Today I used 5k tokens out of my increased 100,000. I don't know if they'll be mad. Are you on a are you on a token quota plan or they just allocate you a certain amount and you can use them however you want?
was busy. Didn't have time to [ __ ] with AI prompts. I didn't need to ask questions. Well, sometimes it's nice to feel competent. You You know what you're doing and you just do it.
Yeah. They want me to use them. Ah, well, I I Hey, man. I can do some loop engineering for you. I I [clears throat] know I know how to write a loop that prompts an AI.
Uh let's see. Break.
So then we'll do CPU. No, chip. Sorry, chip.
So we do have a what's it called? PC. So PC is our uh program counter.
So that represents where we currently are at.
So I'm going to set PC to PC equals N inn.
So, I'm going to delete this and I'm going to add a little print statement here that says jump to address percent D jump to address. Lot of jump to address zeros.
That seems sus, doesn't it?
That seems sus.
Don't want to get fired. No, you do not want to get fired. No, man. And you got to keep the job. You know your your job, your jo o is your number one wealth building asset. You must maintain it.
Steve, where stream in portrait mode?
Uh, so portrait mode is somewhere. I have I've been streaming horizontally to YouTube and Twitch and I've been doing YouTube's new dual format mode.
And supposedly, this is what YouTube tells you is they take your stream and they basically section the middle of the video off and then put it in the the vertical feed or the shorts feed, I guess it would be on YouTube. I have no idea how to get to it directly, though.
I have no idea.
So, I'm just kind of taking their word for it that that's what's happening. Um, I got I got kind of burnt out having to work on only half of my half of my screen. So, I'm just now I'm just streaming horizontally.
W one print f. You are my AI slop cannon. Exactly. I think it would be funny if people really tokamaxed. I I think it would be funny to just set up two AIs talking to each other. Just let it run. You want me to use my tokens?
That's fine. I'm just going to generate an AI conversation between I'm going to tell one AI to pretend to be one famous character and another AI to be another famous character. And I'm just going to produce a transcript.
I just broke Gemini.
Uh, it just sent back system halt.
Hardware watchdog timer tripped. Thread user input killed to prevent RTS starvation.
Just cuz you put that little bit of C code into the prompt, it reacted that way.
Or did you add other stuff?
[snorts] Why? I'm I'm interested to see why one Print F.
You are my AI slop cannon.
Analyzing the slop cannon. [laughter] Oh man, my my response wasn't as wasn't as good as yours. It sounds like my my Gemini did not break.
That's pretty funny.
Damn, mine broke. Yeah, I would have liked to see mine break as well.
All right, so supposedly there's a bunch Oh my god, this is still running. [ __ ] So apparently there's a bunch of jump twos in here.
Okay. So, I wonder if jump two is is uh causing some level up because we're not processing all the instructions. I'm wondering if that's causing some sort of infinite draw sprite. [snorts] Okay.
All right. Let's say jump two is done. I think it's done.
Skip next. If vx equals kk.
So vx is our x register, right? And k is a part of our op code.
So case what what was the case?
I'm actually going to open that in a split.
Don't like this song.
Okay. So we have case three print line Skip.
Skipping. Next.
Then we need a check here that basically says if if CPU at the X register equals KK.
We have to do something which I think just means I think it just means that we have to take PC and advance at one is I think what we need to do to skip over the the next one.
So we'll print another line that says skipping else line not skipping.
Now I don't have an X register declared yet. I don't think so. So, if we go to chip 8, I don't remember what this should be though.
The X register X.
That's not a register.
So chip A has 16 generalpurpose 8-bit registers usually referred to as VX where X is a hessaimal digit 0 through F. There's also a 16- bit register called I. This register is usually used to store memory addresses. So only the lowest 12 bits are actually used. The VF register should not be used by any program as it is used as a flag by some instructions.
[snorts] Chip 8 has also two special bit register. We already have those.
We have the program counter.
And then we have a stack pointer which we haven't had to deal with yet.
So I guess here I just need um a an array of unsigned 8 bit integers and I need 16 of them.
So let's do u int 8 t like that.
I think that's what I think that's what they were describing.
Okay, the problem is X is an array, so I can't really just compare it to KK.
That doesn't make any sense.
load register. Sorry. Uh skip next. If vx equals kk. So what is vx?
Vx is the register.
But how do I know what place in the register if there's 16 of them?
That's the question.
That is the question, good sir.
Also, this needs to be not one, this needs to be two because we need to skip the next, right? So, we got to go, we want to move the program counter from where we are over this one and onto the next one.
We want to break I don't understand. I don't understand what X is, though.
Does anybody else understand?
I don't understand.
Oh, X is X is a value. We do have we do have a X value cuz that's what we're getting. That's what this V this what this is here. That's telling us what we should get.
But I thought VX referred to the register.
Am I crazy, bro? Am I crazy?
The interpreter compares register Vx to KK.
So I guess X is the index of the register.
by op code skip if equal.
So I think I think what's happening I think I think this value is the index of our register.
So I think what we need to do is I think we need to do this.
Not that that makes a lot of sense, but where this x is our register array and this is our vx.
I think I mean we'll only know if we run it, but I'm pretty sure I'm pretty sure that's what they're wanting. I'm almost I'm almost so confident that it's not going to work. But I think also we need to add a break here.
The X refers to a 4bit value.
Yeah. And I'm getting that four bit value, but the [snorts] Yeah, which makes sense. Yes. Okay. So, that makes sense. So it is it is the index because we can only have 16 we can only have 16 in entries into our uh our X register right so every value we get in X is going to be 0 to 16 right because it's a four bit it's a four bit thing so it can only have 16 so I think that is the index All right, let's run it and see what happens. It's going to blow up and die, but should be fun to watch.
Should be fun to watch.
air CPU. Oh man, I keep I feel like I just need to make the chip thing. I keep referring to the chip as a CPU and [snorts] I feel like I just need to just if that's what my brain wants to call it, that's what my brain wants to call it.
All right. So, now we're running infinitely. Oh, no. We finished. Okay.
Okay, so we finished the program, but there was not any skipping, which I think makes sense because this is never going to be set currently, but I would think I would see one of these in there somewhere.
>> [snorts] >> Let's see what happens if I comment out this guy.
So it does eventually run.
What's h what's happening here?
Something's not right. Cuz I was getting jump twos earlier.
Hey, what's up, Mark? Nice to see you.
Hope you're doing well.
Ah, there we go. Okay, so chip 8 has 16 generalurpose 8bit registers usually referred to as VX where X is a hexadimal digit 0 through X. They're also a 16- bit register called I. Uh so I this actually should be called this actually should be called V, shouldn't it?
Hey, holding it down on YouTube and Twitch. That's what we appreciate about appreciate about you, Mark. You're so supportive.
So, this should be V. There we go. That makes more sense.
So, you're telling me that we never we never see 0, one, or three? I just don't I just don't believe that.
Don't believe it.
So then what the hell are we what the hell are we getting?
Unhandled op code.
Well, there's three right there.
So, what are you talking about, bro?
>> [snorts] >> That's the hex representation.
What's the decimal representation?
Huh?
What happened to the file you're working last morning/n night? This is the same one.
I hope I can help you, but I can't. You don't need to help. You could just I mean, we you're just welcome to hang out, you know, work on your own project.
Well, you can kind of use this almost like a shared a shared co-working space.
You know, you can listen to me ramble on about why I can't figure things out and hopefully accomplish some work in your own time.
All right. I'm I'm starting to I'm I'm starting to think maybe I just need to embrace using hexadesimal instead of trying to use decimal or base instead of trying to use base 10 numbers to manipulate this stuff cuz I thought I was doing it right here, but I'm not doing it right.
I mean, it really shouldn't matter, right? I mean, whether I honestly don't know, actually You have to bit shift right.
Why though? Why do I have to bit shift right Oh, I Oh, that makes so much more sense.
Yeah, that makes so much more sense now, too, because So, basically, I can keep it the way I have it. I just have to change how I'm looking at the number. So like for example, obviously zero is always going to be zero. Doesn't matter what base you're working in, right? But in the case of the this function or this instruction like three, right?
When I mask it, to your point, what I'm getting is the those last four bits with the ve with the furthest most bit or with the furthest most value being three and I'm checking for literally three, right?
That's not going to work. So either I need to check for the decimal value of this hexadimal number or to your point apply shift.
Yeah, that makes more sense.
So what do I want to do?
Um I don't know what I want to do.
I need to go I need to use the restroom, put some coffee on to brew. So let me do that first and then we'll we'll come back and sort well let's sort this out first before we do that.
So this is not actually one.
It's this number in hexadimal.
So, I'm just going to I'm going to stick with hex for now. And then if we want to shift like you recommended, Kale, we can in later.
So, this would actually be 496, right?
And then three would be this.
So now I would hope I would just see some more print statements that actually match.
So now we're actually hitting the jump to address.
But I think that causes because we're not handling all the instructions. I think that causes basically a forever a forever thing. But we are hitting it so that's good.
So there we have skip next, not skipping. We have a jump to and we have a clean display again. Kale for the win.
[laughter] Dude, this this is going to be I'm gonna I'm gonna add you uh in my read me. say, uh, please [gasps] please go and thank this guy cuz, [snorts] uh, the project would have taken 10 times longer if it wasn't for him. Uh, okay. So, let's go ahead and try then to implement load register with immediate. I don't know what that is. Load register with immediate. What does that mean?
Load register.
six.
Is that the right instruction?
Load register with immediate set X to KK. Interpreter puts the value KK into register VX.
Okay. So, going back to our hex our hex lessons here.
I think I'm actually going to do what Kale recommended because I think that makes more sense. We can also then use an enum too for it. That makes a little bit more sense to read. So this would be case print line load register with immediate which basically just means we do uh chip vx equals kk Okay for the win. See is fun. I I I'm I've yet to reach that experience. I hope to I hope to find it but I've yet to reach it.
Load register with the media. Okay, so we are capturing the right Hey, it just works. Okay, Stephen, would you potentially be later interested in making your own programming language?
I don't know, man. I I'm interested in doing this stuff right now because I'm boot doing boot.dev. If it wasn't for boot.dev, I probably wouldn't have ever considered taking a shot at learning C.
Um, I mean I'm happy that now that it has happened, but a lot of this a lot of this stuff has never really been a huge interest to me like building compilers or interpreters or linkers or parsers or any of the lexers.
None of that stuff has really like jumped out at me and been like you must go and find out about it because it a lot of times to me it just feels like I'm spending a lot of time reinventing a wheel that other people have already invented.
If it's for if it's for learning obviously like that's a that's a very you know that's a very specific reason to go and do it.
I guess to answer your question, not at the moment. Like when somebody says, "Hey, you should build a programming language." I think, "Uh, that sounds hard and difficult and like one person in the world will ever actually use the language, you know.
[laughter] Uh, [snorts] but who knows? Who knows? I won't rule out anything. I've got I still need to fill about 20 years of time before I can retire. So maybe that's how I fill some of that time is by building a programming language.
Oh, no. You got the ads. I'm sorry.
Well, when you get back from the ads, just let me know. I'm happy to answer that question again. But basically, in short, I think it's very interesting.
Would I want to do it? I don't know, Kale. But yeah, then you can reinvent your own wheel after you've made a lot of wheels. [laughter] Uh, I'm not at that stage. Yeah, I yeah, I don't think I honestly one I think it would take me a long time and a lot of effort to build my own programming language, you know, and that's to me that's where I'm having to like I that's where I have to kind of make a decision because I only have so much time in the day. So I have to pick and kind of pick and choose like what I want to allocate time to. So I've allocated like three or four hours to streaming every day and so I can fill that time with with projects and programming. Then I have my family and my work and my kids and all that stuff.
I need to work out, right? I need to cook food. I need to take care of all the household chores. So like I have this like very minimal amount of time and every day to spend on my own per personal side projects and work. And so I sort of have to be picky and choosy, right, about what it is I what I do.
Build an operating system.
Let's rebuild the whole entire kernel. I mean, you could. I mean, you could. I mean, the thing is I know that some people I know that for some developers, that's what they want to do for a career. Like, they want to go work on OSS, they want to go work on compilers, they want to be part of a programming language tool chain tool chain team, right? So I think if that's your aspirations, like if that's the stuff you really care about and really love and are super interested in, then you should pro you should probably build your own programming lang like you should do all those things. But I think because my interests don't lie there, investing the time and effort and energy it would take isn't necessarily worth it. Now, obviously things can always change, but I think that's where I think that's where I'm at personally. It's just I don't want to work on compilers. I don't necessarily want to [music] be that far deep down on the stack myself.
So, spending a ton of extra time down there is sort of there's an opportunity cost to it, right?
Me who is a dev who just wants to be happy, I just don't want to hate my life. Okay?
That's why I don't want to build my own programming language because I want to enjoy life.
Uh I don't know how long much longer I can hold. I need to go to the bathroom.
Uh so we did that. Add immediate to vx. Can we do that?
So seven would be what?
convert copy.
Oh, this needs a break statement too by the way. Case add immediate to vx. So is that just uh chip vx plus kk? Hey. Is that what that is?
I think that's what that is.
Yes.
Okay, now we're doing a 000 this value.
Set index register. What is that? Set index register.
Anybody know what that is?
stores the value of register VY in register V6.
Vy in V6. So Vy is what? That's this value right here.
performs a bitwise or on the values of vx then stores the result in vx.
So I kind of feel like what this is saying is it's just saying swap the location of something. So take what's at register y and put it in register x.
That's that's how I'm reading that. So I'm I'm reading that as this uh v y sorry vx equals chip at v y that's how I read that now set index. So now jump to V 0 plus the adder.
Which one was that? Nine.
No. BB B.
The program counter is set to inn plus the value of v 0 which I guess v 0 is the first integer or the first element in our register.
So this would be um E 0 So this says jump jump to V 0. Uh so this is set PC equal to NN plus the value at V0 like that.
Okay.
And then the last one is dxy in draw sprite.
Don't like that song.
So what does it mean to draw a sprite?
The interpreter reads in bytes from memory starting at the address stored in I. These bytes are then displayed as sprites on screen at coordinates vx and vy. sprites are exorded onto the existing screen. If this causes any pixels to be erased, VF is set to one. Otherwise, it is set to zero.
If the sprite is positioned so part of it is outside the coordinates of the display, it wraps around to the opposite side of the screen. See instruction 8xy3 for more information on exor and section 2.4 display for more information on the chip 8 screen. So I don't understand half of what I just read, but I'm I'm going to go use the restroom and put some hot water on and uh then we'll come back and see if we can't stumble our way through this.
>> [snorts] >> I am having fun. Kale said earlier that C is fun and and I said I haven't reached that point.
And what I mean by that is that I don't think I've reached a point where the language feels fluid or natural or familiar, but I'm having a ton of fun stumbling and learning and and enjoying myself in the process. But I would love to get to a point where I can write some C without having to like think about every character and you know what I mean? Have to look up every single function. So I haven't got to that point yet. So and I don't think I'm going to get there in this project. So I need to probably find some other excuses to write C.
It kind of reminds me of that question that um I can't remember who asked it yesterday. Somebody asked it yesterday if they are better off getting a job in the language that they want to actually be good in. And it does beg the question that it it becomes difficult to become very good in a lot of different languages if you're not getting presented with a [music] bunch of different problems to solve in all those different languages.
Like you're you're at some you're in some ways your capacity to get better at a language is sort of limited by the number of opportunities that you give yourself.
And it's harder, I think, to give yourself more opportunities when you're just doing things by yourself.
Kale, me, too, though. I kid. I remember some things. Not all things. Mainly remember something you did before, and you can Google it again. Yeah, that's I'm at that stage in my sea journey.
[laughter] Yeah, probably even a little bit further down the totem pole.
All right, I'll be right back. I don't think I started my coffee cam today.
Uh, Droid. Yeah, I don't think I started my coffee cam.
One sec.
Okay, I'll be right back.
[snorts] Did we just become best friends?
Okay. Well, if anybody stuck around, thank you for sticking around. I appreciate that.
If you bad be, if you are weak be, if you are tired, just if you're not smart be, I like that short you clip. Oh, thanks, man. Yeah, it's a funny clip, huh? Just be, you know, just be rich, you know?
I don't know why you guys are so still stuck poor to, you know, you just you just get rich. It's that easy.
Also, I forgot to switch off the coffee camera. I'm back. Sorry.
>> [snorts] >> Let's add some print statements here so we know what we're doing. This one's called um add immediate.
This one is set index register.
This is called um jump two.
And this one down here is draw sprite.
But I have no idea how to draw a sprite.
And I think I need a screen to be able to do it.
draw a sprite. But let's just see if we see all of these codes be printed.
Okay, that's the thing that has me the most concerned is for some reason the jump too just seems to send me in a loop.
I wonder if that's though what what we should expect.
Like should it just draw because this is just a picture. Should it just draw it and then it just sits there and runs endlessly?
I honestly don't know.
I guess we'll never know unless we unless we figure out how to draw it.
Um, let me think about this.
I don't know why I don't know all coding languages. Just get good. Yeah, just get good, man. Just uh Why can't you write C? Well, just write just write good C. It's that easy.
>> [sighs and panting] >> That's hot.
That's hot.
I'd say, sir, it seems to be working.
Yeah, I I honestly don't um I don't know what to do next. I guess I'm kind of torn between worrying about setting up a See, I'm a password here at You need a jump a jump statement at the end cuz it will run then jump. But you did.
So I think it's good. You think it's good? I Yeah. Yeah. I mean, I guess we got to figure out how to print it to the screen to see if we're actually doing anything, right?
That's the part that I don't I don't really know what to do next. I guess figure out how to It would be nice if I could just draw it on the terminal.
Um, that's kind of that's kind of really what I want to do.
Uh, let's see. I'm going to look for Ray Lib stuff real quick.
Yeah, ignore my rambling. Yeah, I'm going to look for No, I don't I don't think you're rambling at all. Uh you're also you're being super helpful and I really appreciate that, Kale.
Uh, let's see. Ray lib.
Ray li I'm trying to ask I'm Okay. Ray liib draw [snorts] 64 by 32 pixel window.
How about How about How about this? How about we just do I guess we could even do this in a separate a separate function or not not a separate function but a separate file and we could just work on hey how in ray do you open a window right like the ba the very basics Um, ray lib draw or yeah create window tutorial [music] core examples basic window.
Congrats. You created your first window.
Ray core basic window example complexity. Welcome to ray. To text examples just press F6. So you say include ray h.
Oh, this is this is everything I need right here. So window should close.
Begin drawing. Clear draw text. Okay.
How do I get um work in a header file I guess and call ray liib lib to your current file with compiler. So kale, how do you how do you get the ray? Do you have to like download ray install ray or is just just you literally just say include raylib.h and the compiler knows what to do. How's that work?
Ray li you need to install the library and add to path for Windows. Okay. So I guess I'll look up. So okay now I'll say how to install ray install libraries the okay this is the process of learning every question leads you to another question [laughter] uh you probably need make or something okay I don't know if I have Take download W64 devkit or MW.
I think I might have that. So, how would you how would you know if you have how would you know if you have Ray Libs?
Check for Ray Lib.
Look in your path.
You mean like it'll be Are you saying like if I mean I know I have look I Hey, what's up guns? Uh Ray li check path. I don't know how to do that.
All right. Crazy idea. Crazy idea. I know. I know. Hey, I'm glad I'm not giving him [ __ ] answers. Let me know if any other ceps have better. No, you guys are doing great. It's I'm telling you, nine times out of 10, the teacher is not the problem. It's the student in this case.
Okay.
So, we're going to do a little test here. Include ray lib.h init main init window. I'm just copying a snippet on stack overflow.
array lib test close window here then gcc test no not test window c r lib I don't know what all these flags are I hope they don't blow up my computer.
You should always just type terminal commands randomly from the internet. Input file test is the same as output O.
Fatal re ray.h.
No such file or directory.
Okay. So it's not here.
Okay, crazy idea.
Crazy idea. What if we just go back to trying to do this in the terminal?
Uh, I I I do want to figure Ray Lib out.
I do want to figure Ray Lib out, but I have about an hour and some change to go before I have to go to work. So, what if what if we just try to do that? Uh, crazy idea. No, I don't think it's crazy. I think it's the right idea cuz that this is going to take me down a rabbit hole I'm not ready to go on quite yet. So, we need to modify the ability to uh essentially instead of drawing to a screen, we want to draw to the terminal.
So, we're going to need some special.
We're going to need some We're going to need some uh terminal magic to make this happen, I think.
Let's see. Let's go back to the chip 8 spec. So the interpreter, I'm going to pull this off to the side so I can read it and also see my code. So the interpreter reads in bytes from memory starting at the address stored in I. I do not have an I. So I need to add an I.
I is our immediate register.
I think what is I? Does anybody remember? I've read this spec half a dozen times now and I I I still don't know what I is. I I I I I and then maybe then maybe today my homework for tonight can be to make sure I have Ray Lib installed on the machine and then tomorrow morning we can um get that fixed. Next, there is also a 16 bit register called I. Okay, let's add that. The register is generally used to store memory addresses. So only the Okay, so let's add that. That's a 16 bit.
So we have U int 16T I.
Now does anybody use I? That's the question. Who uses I?
Which instructions use I?
Does anybody? I mean, nobody does yet because I I just added it. 40 40 set index register. That must be what I is for.
Which instruction is that? That's um set index is this is why I should have done what Kale said and I should have bit shifted so that I could just reference things by normal decimal.
So the value of register I is set to inn.
So that's this one actually. So this actually should be that should be this.
Yeah. And I'm getting that literally from the spec. I literally typed it wrong. So this is set value to register I set to inn.
So this is setting our index register.
We're jumping. We're draw. Now we need to figure out how to draw the sprite.
We're adding the immediate. We're loading register with immediate.
We're deciding if we should skip.
Okay. So, so [laughter] I say that like I know exactly what to do next. So, what we need to do is we essentially need a loop.
And that loop is what I guess that loop needs to draw something. So let's define a separate function instead of just adding to our already massively and ever growing main function.
And we'll call it uh draw.
And all draw is going to do is it's basically going to do the same loop that we did earlier where we were printing out the that loop be looping. Boy, that function be functioning.
[laughter] What's your function do? It functions.
You all do that loop engineering. Yeah, you just you just you engineer a loop.
Uh so let's do let's go back to what we were doing earlier today where we were printing the display out. So let's do that same thing again. So we'll say uh let's do int z uh int z in i equals z i is less than our screen height.
That function be functioning boy. Not for that code review. The function functions. Exactly.
So can So hey man, I I saw your PR.
Could you um could you explain what this function does? It functions.
That's probably how modern code reviews will go in the future.
Oh, I saw the funniest tweet.
Okay, hold on. I got to show you guys this tweet. This tweet is so funny.
I mean, it's funny. It's also kind of sad. It's also It also really could be our future.
Uh, let me see if I can find it.
Gosh, I I need to do a better job bookmarking this stuff. One sec. Uh, what's the guy who built who built Bun's name? Jared Summer.
This one. Okay, check this out. This is Okay, this is the guy that's the he's the host of the Pragmatic Engineer.
It's a podcast. It's a good podcast.
It's on YouTube. Uh so he was basically sharing these screenshots of I think this is the bun repo and he was basically pointing out the fact that it's he was basically saying it's fascinating. Can you guys see this? Hold on.
Did I put that in a good spot? I think you guys can see that. Yeah, you can see that. So he's basically pointing out that the fact that if you look at PRs on the bun repo, it's AI reviewers talking with AI essentially coders, which one sounds like a dystopian nightmare. Two is really funny. Three, if this is the future that we're going for, I Yeah, I don't know, man. I Huh.
Uh, I don't know. There's like like software development is just going to be large language models throwing tokens back and forth at each other till they come up with something that they think is correct.
That's That's crazy.
That's crazy. You can go read the replies are pretty funny, too. Or I'll copy this and share it if you guys want to go look at it.
Just absolutely no humans. I asked Claude to tell Grock to build a better prompt for chat GP and it didn't work. Exact. [laughter] Exactly.
Uh see this is our this is this is our future apparently.
Yeah. I don't know. I don't I don't think I'm long for this industry. I definitely gonna remain I'm always going to remain a hobby hobbyist programmer and developer for forever and I'll keep making YouTube content and stuff, but [laughter] [gasps] uh maybe maybe it's not. Maybe professionally it's just it's outgrown me, you know? I don't know.
I mean, I'm not saying it's I'm not saying code review tools like that can't be super helpful cuz they really can. I just think it's funny to imagine a world where it's basically what Kale just said, which is I don't know, man. Claude talked to Grock and Grock seemed to agree, but Chad GBT said, "Fuck off."
So, I don't know. We're currently blocked until Gemini gets back to us.
[laughter] [snorts] I like to laugh at my own jokes.
Bro, I work in operations and compliance and [snorts] IT on the side because I long not reading 390 page legislation and would rather read code docs.
[laughter] Dude, you you are doing the Lord's work.
You're doing the Lord's work. Okay, so for now, let's just print something that's useful to the screen. Yeah. So we'll do print f new line and I guess we'll just go back to printing star, right? So we're drawing we're drawing. So then let's come down to our command where we say display or draw sprite and we'll we'll call draw here.
And this will be where we handle kind of the update logic I think.
Oh, you know one problem?
Well, it's not really a problem.
Draw. Is that the name of the function?
I just got done.
What did I just do?
Oh, I I did control Z, not control O.
Yeah, draw.
Okay, let's run that and see what happens.
Uh, what have I done?
I've forgotten to add semicolons.
Okay, it it drew it draw something. to draw something, but then it printed a bunch of stuff. So, I think I need to actually clear the screen. So, how do you clear the screen with there's the these are the magical characters that nobody remembers.
There's an escape codes that you can use, right?
Yeah. Antsy clear screen. Any Well, we want to clear the screen, but we also want to put our cursor back where it was. Any clear screen and set cursor to the top left.
Oh [ __ ] Did you Did you remember that at the top of your head? That's really impressive.
Holy [ __ ] Is that Hold on. Let me I'm just going to double check you. But that's really impressive.
This is something I'd have to normally probably use LLMs to do.
Uh anc screen escape codes, I think. Isn't it? Yes, I believe you're right. Yeah. I I honestly don't know.
So, I was just going to look at the cheat sheet.
Move cursor.
Move cursor to the home position.
No, that's not what I want.
Erase in display.
Yes.
So is back slash 0 33 escape.
Yeah.
And H.
Yep. That's it. That was it.
You the man again.
I don't even need an LM. I have Kale.
So, we print uh we This is going to clear the terminal and reset cursor top left.
Oh, I think it needs to be flipped. I think we want to clear and then we want to clear then reset our position. I think it needs to be JH.
There we go.
Oh, erase. So, I want to erase the entire. So, looks like there's erase in display or there is erase entire screen.
There's also erase from cursor to beginning of screen. So, I'm just going to do erase entire screen.
Yes, exactly what you exactly what you just put. Your last message. That's what it is. Okay.
So, I think I this is going to look weird, I think, because we're going to remove some of our print statements. I think.
Yeah, we've got other we've got other output going to the screen which is causing also we're not printing in the right height width something something's funky funky. Um, let's comment out the I'm going to comment out the other print that print statements that we have going on.
So, we're just drawing the sprite.
Okay. I don't think there should be anything being printed other than that.
Something [snorts] Something's off with my Something's off.
How many rows are you printing right now? We are printing all of them.
Something is off.
Oh, it's this. This is in the wrong place. This should be here.
It isn't redrawing though.
I guess I thought that it would just keep drawing in the same place, but I guess we are looping, aren't we?
That is the right. I put the right.
Yeah. Escape.
JH. That's what the cheat sheet says.
[snorts] [snorts] H. You need logic to display ch. Yeah.
Yeah. Yeah.
This is correct. But I guess I don't understand why it's printing.
I just I guess I thought that would redraw the screen.
It doesn't seem like it's redrawing it.
All right, let's try to implement the um let's try to implement the the logic for manipulating the display because right now your loop is making a canvas. Uh, I don't know. I guess my or the way I was thinking of the execution was that every time we hit this draw function, it should just wipe the whatever's on the screen. But maybe that's not maybe I'm not thinking about it clearly.
Okay, let's manipulate the chip and then we can sort that out. So, let's get our spec. Where's our speck at? Speck is over here somewhere. We can get rid of that. We don't need to talk about Twitter anymore.
Okay, so we have what do we have? We need to go to the draw sprite.
Draw. Where is it? Draw sprite.
Okay.
So what we do is the interpreter reads in bytes from memory starting at the address stored in I. These bytes then display uh as sprites on screen at coordinates vx vy. sprites are exorded onto the existing screen. If this causes any pixels to be erased, VF is set to one.
Otherwise, it is set to zero. If sprite is positioned so part, so we need to wrap around part of it is outside the coordinates of the display.
It wraps around to the opposite side of the screen.
Okay. So, we need a little bit of uh a little bit of modulo action there.
Yeah.
Okay.
Oh, now I understand what this is for. I don't You guys probably don't have I mean, you're probably not paying attention as closely as I am, which is totally fine. Not expected. I'm more of just rubber ducking out loud. There's a part in the spec where it says it says the VF register should not be used by any program as it is a flag by it as it as it is used as a flag by some instructions.
uh VF meaning the last register.
Uh so that would be down here why in the instructions for the draw function it says um if this causes any pixels to be erased VF is set to one otherwise it is set to zero. So, it's basically doing like a collision detection almost essentially and it's using that register to flag it.
That's interesting. Okay, that makes sense. Now, I wondered what that was about. Um, it's all it's all connecting.
No, it's really not. [laughter] It's [snorts] really not.
Okay. So, first things first, we need to get the coordinate. Yeah, we need to get the coordinate. So, we will do uh u int 8 t. This is going to be our x coordinate.
And then we'll just go ahead and say this zero for now. And then we have uint 8t. That's going to be our ycoordinate.
Uh, we'll do zero for now. Yeah.
And what do we actually want to do?
Well, we want to retrieve.
[sighs] We want to retrieve.
We want to retrieve from us. screen height or screen width. Uh X is width.
Remove the two to see if it works. Okay, hold on. Uh let's comment this out then.
You've been off doing some research for me.
Remove to two from two. Oh, right here.
This one. 2J program was still running.
Yeah, that worked. Yep.
Whatever you just did worked. The cursor moved around. Kind of odd, but it worked.
So, explain that one.
What's the difference there?
Make it an H or make it a It's a J right now. Make it a H. So you're saying You're saying make this an H and the other one a J?
Whoa. What is all that? That's a That is so much flashing.
If it's H, it will work without a flicker. Why is there so much flicker, man?
[clears throat] So, what's the difference in those codes? I know I'm getting completely distracted, but I want to understand what the uh let's see J I had JH how do you hide the how do you hide the um the cursor?
Uh, antsy hide and hunh high cursor cursor cursor controls move cursor to home.
Save cursor position restores the cursor to the last saved position.
Cursor hide. Hide.
I don't I've been playing with it. Uh is move to top left and clear everything below.
So you're you're doing move to top left then clearing and I'm doing clear, move top left, which probably doesn't matter what order you do if you hide the cursor.
See my terminal pressure.
This is supposedly according to Stack Overflow that hides it and this shows it.
Well, that didn't work.
Well, that didn't work.
You know you're doing things right whenever you find yourself on MS and MSDN. And this API has a virtual terminal equivalent in the cursor visibility section.
Cursor visibility. Cursor visibility.
The following commands control the visibility.
to enable sequences in a lowercase H character.
To enable sequences end and the disable end in a lowercase L.
Okay. Trying to see if we can figure that out.
Let's see. Before loop.
Yeah, that's what I think is correct.
You said before or before loop is 25 L.
That's what I have.
Now why?
Oh, do I need escape?
I know this is not I know this is not really the point of the exercise, but now I'm now I'm hung up on it.
Okay. It seems like if you're on Windows, you have to do something really crazy to make this work.
According to Stack Overflow, according to Stack Overflow, you have to do something like this.
Uh, I don't understand why though.
Let's see if it Let's see if it works, though. Let's just We're going to do a little [laughter] We're going to do a little copy pasta. Okay, it's going to be fine.
Nothing bad's going to happen.
This is going to be So, we already have Windows.h. So, let's just uh let's add a function. Let's copy paste that function. This is called hide cursor.
And so, then this would be Uh, I'm guessing we could just do this and then we can say show or it's not show uh true maybe What? Flush the standard out after your escape.
You think? Did it work for you?
I'm I'm just doing a little copy paste and magic with Stack Overflow here.
So, this would be hide for sure.
This would be No, it's still that doesn't work either.
So, is it something about maybe my terminal or something? Or is it because the loop is happening so fast?
You said flush standard out after your escape. So I guess let's try your idea.
You said I have no Okay, I'm just gonna add a note because now now now I feel like I've lost the plot. Um, forget about it. Forget about it. Uh, we're here. We'll say to do damn cursor flashes.
Ain't no why. [snorts] Ain't no why it flashes like that. Okay.
So now what we knew is you think race condition. Okay.
Combine it. Uh let's com Okay. Let's combine it. Hell yeah. Let's do it. Hell yeah, brother.
Well, that was that was a different effect. I didn't see the cursor flash as much, but it it was more flash flickery overall.
Oh, that's perfect. That's perfect.
I think that was perfect.
It's working.
[laughter] I forgot to download that Anakin clip.
Jesus, I keep forgetting to do my homework. Anakin clip download. Your stream My stream did a weird thing. Did it really?
Did I break something?
Am I still live? Am I here?
Yeah, it looks like I'm still here. No, it could it could have been. It I blame my internet. My internet is so so not reliable on me.
Okay, back to doing what we're supposed to be doing, which is uh setting the is manipulating the display so that we have the right data to print.
So, back down here, this Okay, so what we want to do is we want to go into the display.
Uh, no. We want to go into the register.
Yeah. So, we want to be at chip uh v at x, right? And then we also want chip at y. So, they those come from our coordinate the register coordinates.
And then we're going to mod each of them by this will be by the width.
And this will be by the height. And the reason is this is so that we can accommodate wrapping, right? That's like you're just wrapping around just like you would if you were like iterate iterating over uh an array, right? And you want to just continue to go back to the to the beginning of the array once you get to the end of it.
Uh so we're wrapping around and then we need to set uh chip V at 15.
And you might say what is 15? So 15 is our F register. So this is the final this is where basically it's doing collision detection. is basically if this is if this uh value in the register is set it means when we were drawing pixels were uh colliding because we had to actually uh change the pixel value or I guess not yeah we had to we had to erase the pixel and that's what we're setting this to. All right. Now, we need to actually loop over loop over our Steve.
It says read in bytes from memory.
So, how do I do that? Read in bytes from memory.
starting at the address stored in X. So read in bytes.
So this is I guess this we'll call this our sprite display in byte sprite. So let's say this is u int8 of t and this is a sprite bite which is going to equal our chip and our chip's memory and we want to start at i but we need to add something to it.
What do we need to add to it?
Sprites are exorded onto the existing screen.
So, I need to I need to loop over the screen, right?
Or am I just out of my mind?
The interpreter reads in bytes from memory.
Oh, in bytes in bytes is the there you go. Uh a four byte value. So, this tells us this tells us how much to read. I think that's not totally clear from what we wrote, what the spec has. That's actually kind of confusing.
So, interpreter reads in bytes from memory starting at the address stored in I. These bites are then displayed as sprites. So what we can do is we can say we still want that but what we can do is we can say for uh int row equals z row is less than n will increment n.
And so n is our oh no n's already taken.
So no n is not taken. n is taken but we want row anyways. So we don't want to increment in we want to increment row.
So what we do here is we then say okay we're going to start at i but we're always going to add the next right the next bite to it. So we do n.
So that's our sprite bite at that particular location.
And then we just run this till we get to the end.
So if y coordinate is equal to greater than not the same as uh so this is our starting coordinate. So if coordinate plus row let's add some extra pars is greater than the screen height, then we know we've basically drawn it all the way out and we can break.
Right? If the screen is, let's say the screen is three pixels tall and the coordinate started at zero and we're on this second row, right? The next time we come around, it'll be on the third row, which is going to be more or it's going to be that's that seems like a off by one thing.
I think I either have to do greater than or equal or I have to subtract one off the screen height.
So, I'm going to do greater than or equal cuz minus one on things is confusing and it always leaves you wondering why did I subtract one off this thing.
Now, we can loop over our bite. So, we'll say for uh each individual bit each individual bit.
So for column uh column is less than 8 and why 8? Because there's eight bits in our bite. That's why.
Oh, thank you. You caught the bug. Oh, dude. That's That was a bad bug. That would have been that that would have left me staring at the screen for a while wondering why >> [snorts] >> uh why my life had gone so poorly.
Um, okay. Then we're going to have to do some What's up, Fox on main? How you doing? Nice username. I I appreciate usernames like yours. It's clever. And then we want the same kind of check here, but we want it for the x coordinate. So, we'll do x plus column is greater than screen width.
You should rewrite this in Python. I I think it would be fun to rewrite it in uh in C. I think I I think I would understand it all even better if I read if I redid it in in C or Rust. We could rewrite it in Rust.
How about that?
[snorts] Can rewrite it in Rust in C# but an unsafe block? Uh yeah.
Could we I mean would it need to be in an unsafe unsafe block?
We could do it in Go. That'd be fun.
Yeah, I think it would be fun to do it in multiple. I think I think if you were to do it in a language you know really well, this would probably take you a day or less, you know, to do it.
Next stream, Steven assembles. Dude, there's no way I did Did you guys Did you guys see the Primagen do a stream where he learned assembly in like an entire stream? That was crazy impressive.
Let's see. Yeah, I had to go with Maine since they had the whole debacle with master branches. No, I'm not making that up.
Oh my goodness. I forgot about that. I forgot about the master main thing.
I was just getting into programming, I think, when that all was kicking off.
Was that like 2020 when that all when they changed the default uh ma master to main controversy?
It was like 2020, wasn't it? I was just getting into I don't know. I could be off, too.
GitHub CEO Nat Freriedman.
God, where is Nat Freeman now?
Yeah, that was 2020. June 15th, 2020. I was like just getting into programming.
I had been working at my I had just started working at the company I work at now. I just I started in August actually. So, that article actually predates me working in tech.
That's crazy.
So Nat Freeman's at Meta Super Intelligence Labs, huh?
Wonder where he was.
That was crazy. Crazy times, man. Now you're Fox on main. It's still called master in the old repo like Linux uh forjo and other git clients. You can choose between the defaults. Yeah. So I think my default's main, but I I have repos that have master on them.
Have you guys Have any of you guys tried um JJ the the newer Source Control? Have any of you guys tried that? It's made by um the company's name is kind of an interesting name.
JJ Source Control. I think it stands for jiu-jitsu, right? Or something like that. Ju. Now I enjoy. So what is forjo?
I've never heard that before. Forjo forjo and gy.
So is forjo a fork of git ty or something?
Forjo is no longer guaranteed to be compatible with git ty but upgrades should usually be oh I just got started with gy and you're telling me I made the wrong choice. I should have used this gosh. Guys, where were you?
Where were you? The one I was thinking of was uh I was thinking of this one. Jiujitsu aversion control system. This is the one a lot of people have told me is good, but I've never gotten into it.
It's the back end of Codeberg. Okay, interesting. It's like get t but a fork and has actions. Uh I get Git Ty has actions too. Uh although it has some rough edges around it since I've been using it. I'm finding rough edges around using it. But it's it had Yeah, it has it has actions. GT has actions. It it's basically GitHub actions compliant. It actually it's actually using um if you guys have ever used act ne it's ne nectos act this thing so that you can run github actions locally. I'm pretty sure the gt actions is backed by this thing forjo is looking into federated which is hella neat. So, it's federated where you can basically take it anywhere like you could take it to any compatible kind of like um uh what would be uh like what am I thinking of like the app protocol that kind of thing also nice emoji there I don't think I understand what that means federated It means you can browse other instances from your instances. Ah yeah that is cool. Okay that is that would be very cool. So everybody could have their own instance but then we could look at each other's instance via that would be very cool.
Yeah cuz on my I'm kind of on my own little git server isolated away from the world.
It's like email. You can email others outside your proton or Okay, that makes sense. Very cool.
That's more like uh I guess that's more like the Fedverse, right? That's more like Mastadon, right? Where you a lot of people can set up different instances.
That's why it's called being federated.
[laughter] Duh, Idiot.
[laughter] I'm just kidding.
Uh, all right. We got We got to figure out our logic here. I think we're close.
I think we're really close. So, uh, we need to now get the current bit, right?
So, we're going to have to do some bitwise math.
And then we want to get the the pixel.
And then we have to determine if the screen pixel is already on.
Or if we just e or then we exor it.
If this causes any pixels to be sprites are exorded onto the existing screen.
Okay. Check if the current bit is a one.
So how do we do that? We need to check if the current bit is a one.
Right?
uh check if current bit is a one. So at this point we have a what we have a unsigned 8 bit integer. So we have an unsigned 8bit integer.
So we would do u int8 equals sprite pixel and some some sort of bitwise bitwise math.
Okay. Uh unsigned unsigned 8bit int.
It's been so weird using a search engine like a search engine the last few days.
The Google AI overviews really had have had my brain trained to look at the top and not look at the blue links.
So the bits are represented by column, right? So if we're looking at the individual, let's let's pseudo code this. If we're looking at it, we're looking at a bite.
We have these bits, right?
And we're basically wanting to check if if the current bit is on or off. So we basically need to move from left to right, right? This bit, this bit, this bit. And each one represents a single pixel.
So the bitwise math we do here needs to isolate each one.
So we need to we need to both mask and we need to then shift.
Uh so eight or we need to actually what we need to do is we need to shift then mask right. So if we say we're going to start masking here what number is that? So, let's say we're going to start there.
I think that's What is that? Is that uh binary to decimal?
I need to get better at this.
So, here's our binary number. It's 128.
Why is it one? Oh, because it's un Is it because it's unsigned? Right.
I guess I was thinking this should be 255, but Man, this is the most I've dealt with binary and converting back and forth in in ever and ever. My whole life.
Okay. So, max signed value is 127. Max unsigned value is 255.
[snorts] Huh?
Oh, I'm an idiot. It's because all the other bits aren't flipped yet. Okay.
Yeah. So, it I'm an idiot. It is It is indeed 128, but it's because the rest of our If we did set all the other bits, then it would be I'm an idiot. Uh, okay. So then what we want to do is we want to shift this. So the way we'll do that is we'll say um we will do 128 shift right whatever number the column is right. So this will initially be zero. So we won't shift any. This will initially be then it'll be one. We'll shift one, right? So on and so forth.
And we'll just keep moving the mask from here to here to here to here to here to here to here. Then we'll move the mask again, right? So on and so forth.
And we'll do this so that we can check.
I need to learn how to crypto soon, which is annoying. You're going to do crypto like web 3 type of stuff.
cryptography type stuff like crypto in type of c- crypto in the sense of web 3, crypto in the sense of like cryptocurrency, crypto in the sense of like doing like cry cryptography type of things.
Which one? Those are all beyond me. But then we do this by the in the sense of currency. Oh, okay. So, yeah, blockchain type type work. That's all over my head, but sounds sounds like it could be fun. Sounds like it could be hard. Sounds like it could be fun. Um, okay. [snorts] Oh, it's already eight. [ __ ] I think I'm really close, though. Let me see if I can finish this. So once we have this we can actually perform the necessary uh reading from the chip right I think.
Yeah, we need to we need to basically read the Hey Bolivian, what's up?
Mlewad has shown their hand. I don't want to play with them anymore. The next option only offers crypto as their only anonymous payment option. I don't know what Molewad is. Good to see you, Oblivion. We are having a good day. We are slowly struggling through some Bitwise math stuff and trying to figure out now trying to trying to figure out.
So if I have the if I have the sprite pixel, can I just So the instructions say the instructions say this.
Um, display invite sprite starting at memory location. So, if the sprite is positioned, we've already done that.
Sprites are exor on the existing screen.
This we have not done. This is one we haven't done yet. So, this is what we're in the middle of doing.
I'm not sure.
[snorts] So, I guess the thing I'm the thing I'm stumped the thing I think I'm stumped on is We need the actual.
So we have a we have our memory, right?
So we have chip display and if we go up chip display, whoops, chip display is 32.
You went 32.
Uh yeah. So this so basically you int 32 t right.
Uh no not equals. This is going to be sprite something. Sprite. Uh what do you want to call it? Um I don't know something something I don't know find ind. Yeah. See the find index part is the part that I'm have because we're dealing with a we're just dealing with a one we're dealing with two dimensions but we have a onedimensional array right so we basically need to take the coordinates and I guess flatten them.
Yeah, I guess flatnim I guess.
Uh, so I'm going to say like sprite index and we're going to need to do some math here.
We're going to need to basically do the current coordinate or the the beginning coordinate.
uh offset by whatever row we're currently on.
And then that's going to need then we're also going to need to do that with the x coordinate.
And then we also have to take into do you want my ID? I don't want to take away from your Let me Let me keep going.
If I keep getting stuck though, you can save me.
Let's see. I just experienced a basic gotcha of LMS. It got stuck. So, it got stuck, so chose to get restore and lost thousands of lines of code both I and it had written. Oh, [ __ ] Luckily, I have automatic snapshotting on my home. Oh, dude.
Yeah, that would have made my uh if it was something I really cared about, which it probably sounds like it was.
Yeah, that would have made my um that would have made my stomach drop.
I thought I I thought I uh deleted I thought I rmmed a a directory.
Um, I mean, granted it was all version controlled, but it's crazy how scary that feeling is if you're on the command line and you run RF and you mistype something or don't type everything you intended to type, you know, like prematurely hit enter and you're like [laughter] is a one-way operation.
[laughter] Um, so we basically need to flatten this, right? That's what we're doing. We're flattening. So, uh, I'm going to try multiplying this by the width, right?
And then we're going to multiply the other. No, this should be by the height.
by the height or [music] the width.
Yeah, it's been weeks of work sort of on me for not committing everything each time. So, some thousands of lines were just gone forever. I I am really I'm really sorry that that happened.
Yeah, that's that's awful.
[snorts] Oh, no. This should be No, I had it right. This should be screen width because basically what we're doing here is uh we're basically doing the necessary math, you know, if we're looking if we're actually looking at our grid, right?
We're doing the basically the necessary math to go okay whatever the whatever the where is my code be easier to do in here. So if we have a grid like this and if we're at this position right that's basically what we're trying to do is we're trying to take this and flatten it. So we would say ycoordinate uh which would be I guess in this case let's say we started at zero and we're on the first row so that would be one times the screen width which would be four. So we get four.
Then we're going to add to that the x coordinate plus x.
So let's say we're on so 4 + 3 and that would put us at seven 1 0 1 0 1 2 3 4 5 6 Oh no that put us at six because we'd be on the first row.
0 1 2.
So 2 + 4 that's six. So we land where we need to be. So this needs to be plus uh x coordinate plus column I think is what we need. So y coordinate plus row times that by the screen width add the coordinate with the column and I think that lands us at the right index.
Then we have to actually get the index.
So this will be uh I don't know what I want to call this. Sprite uh actually this no this is not sprite pixel. This is screen pixel.
So this would be equal to this.
like that.
You should try suicide Linux. It's a good way to get real comfortable with the terminal rather than blank is not a valid command. The system will just rm-rf.
Oh my goodness, that's crazy. Who came up with that idea? Suicide Linux. That's awful.
Oh, sorry about the ads. Thank you for watching them though. Hopefully one day I'll make some some money from all this from all this streaming.
Oh, okay. So we actually okay so little little important distinction here. We don't actually just want the value right of the screen pixel. We want an address. We want a pointer because we want to be able to change that specific value. So this is actually needs to be a pointer and this needs to be address. Look at me. Look at me using pointers. Holy [ __ ] I'm a real developer now. Holy [ __ ] So if the sprite pixel is on, so remember this is this is a bit at this point.
Um so this is either on or off. This is either one one or zero, right?
So if it is, then we're going to turn it or we're going to set the collision thing.
[snorts] Fast forward two weeks and your little program memory leaks and overwrites the kernel.
You know, what can you say? What I mean, are you a real developer if you're not if you're not leaking memory, you know?
Okay. So then we'll do uh if that's the case and screen pixel is what do we want to check here? We basically want to check if screen pixel equals one. Right?
So basically we're we're basically saying, hey, if screen pixel's already on and the sprite pixel wants to go there, we need to um this is some this actually can be and so sprite pixel equals 1 and screen pixel equals 1. That means we have a collision. That's where we get to use our collision detection.
We don't need you anymore.
So, we get to basically do this. So, instead of flipping this to zero, now you get flipped to one.
Okay. And then the last thing we do is now we can actually do the exor.
So we do uh screen pixel uh exor is that a a thing in C? Can you redo an exor reassignment?
I can kick back knowing Steven is using pointers and now coding and see. Ah finally finally Steven has finally arrived in the in the holy land of sea.
[laughter] I've been eyeing new monitors lately, but my dream one is not out yet. Ben Q gets close, though. So, did you see there last year they released BenQ released like a monitor that was specifically aimed at programmers? I guess it was very expensive. Very, very expensive. Um, but I saw there was a bunch of people I follow on YouTube who I guess either got their monitor as a sponsorship thing or purchased it outright. It looked really nice. Um, just very expensive.
It's not good enough. Oh, wow. Okay. But I I figure I figure something's better than what you got, right? It's got to be better than what you got if you're in the if you're in the if you're in the market for a monitor.
All programmers need is a small vertical panel. I want all the monitors. Like right now on my desk, I've got three.
So, I have a 32 I have a 32 in ultrawide over here on the left and then I have two 27 in over here. And honestly, if I could I wish I could have like six monitors. I want like I want monitors everywhere.
Laugh my ass off. Steven's bot taking the lead. Oh, that's hilarious. Is the bot does the bot look like it's the biggest chatter? That's so funny.
Yeah, you can ex. Okay, cool.
All right, I think we done it. I think we done it. Should we try to run it?
You know, I was thinking actually just a second ago, we don't need to we don't need to clear the skurine when we draw because there's a clear screen instruction.
So, we can actually say void clear screen.
Uh, I think my sister-in-law's blocked out.
Hello.
Never. No, I'm coming right there. All right, I'll be right back.
I'll be right back. I got to go unlock the door.
Okay, I'm back. [clears throat] It's time for the sweet, sweet moment of truth.
My current displays are not accurate, but they do hit the bare minimum. Well, that's good. I will unlock the door if you come with pizza. Well, she's a nurse, so you know, you got to treat you got to treat your healthcare workers with the utmost respect.
Where are we doing that?
Where is it?
Monitor hoarding. I like that. I'm a monitor hoarder.
So I think we can do clear screen here or just draw or should we just I'm trying to think.
Should we just should we clear the screen or should we just redraw it?
I guess we should just call draw. We should actually do the I think we should just draw it again.
like that.
Oh, it's not going to it's not going to change because I'm not passing the chip.
All right. All right.
All All right. I've got to pass the chip in here, don't I? So, we need to go up to the back to the draw function. We're so close, man. I need to stop streaming, but I'm We are so close.
We are so freaking close, bro.
>> Fox and Maine is telling you to drink some coffee.
>> Thank you very much, Fox and Main. I appreciate that.
So, we need a pointer to a chip 8T.
And then the all we're going to do is now inside of here we'll basically say okay if pixel is on.
So we'll say if um I'm actually going to do you int 32t.
So, this will be screen pixel equals uh chip HDR ruins my screenshots, but it's good for games. Yeah, I've never really understood the HDR thing.
Never really never really understood it.
It's supposed to make your photos look better, but they end up looking worse, which seems not seems not cool.
screen [snorts] plus X, right? That's what we did down below, isn't it?
Oh, not X. This should be J. Sorry.
J.
Hey, Kale. Someone I don't know if you can see him, but someone from Twitch said if you uh are on Windows, uh the snipping tool hides the HDR toggle inside its settings. Flick that and tone maps correctly. I'm just passing the message from from Chip to or from from Twitch to YouTube.
[snorts] Okay. So, we'll do print f empty space.
Otherwise, we'll do print f star.
All right.
Shall we? I'm still I'm still kind of suspicious I did this wrong.
I times width.
No, that's right. That's right.
This is number of rows. We should change this. We should change these to be more descriptive. All right. All right. We'll never know unless we try.
Moment of truth.
Ah.
What's it? What's going on here?
Unexpected expression.
Oh, I put the pointer in the wrong place.
I have an unused index and I'm not passing the chip.
Okay.
So this would be address of chip.
address of chip.
And this says we have an unused. This should be out here. This should be over here.
And then this should be sprite screen index.
Nope, that's correct. Okay.
Will it run? Oh, [ __ ] Passing argument one of draw from incompatible pointer type.
Oh, is Chip already a pointer? Chip is already a pointer, isn't it?
Yeah, chip is already a pointer, so I don't need to.
You missed a clo, did I?
I undeclared.
Oh, yep. So, this should be chip.
Oh, my Slack messages are going off.
I [snorts] I got to go to work. Um, chip I Dude, we're so close. I just I just need to see it working.
I think I missed one after column in the long mass statement for the index. Uh did I did I mean that's something it's something.
[laughter] It's not the IBM logo, but it's it's something. All right. So, hold on.
What you saying? You're saying uh yeah, it's progress. It's progress. [laughter] I think I missed an after the column in the long. Okay, let me see.
Um, so coordinate row time screen column. No, I think I got it. No, that's that should be okay, I think.
Uh so the output I mean the out it's outputting stuff.
[snorts] So we just I guess I mean I mean [snorts] I mean That was so antilimactic. I just I'm a little bummed about it. [laughter] Uh, damn, bro. Damn.
[laughter] So, I'm just I'm just looking back at the I'm just looking at the uh [laughter] disappointment. Yeah, I'm looking at the instructions to make sure sprites are exor onto the screen. If this causes any pixels to be erased, VF is set to one.
Otherwise, it is set to zero. If the sprite is positioned so part of it outside the coordinates of the sprite, it wraps around. We should be taking care of that.
H.
Huh.
Something something off. Something off.
I don't know what though. I think I implemented the drawing right. So, it's got to be something else. Whoop. Sorry.
I didn't mean to hit the mic.
What could it be?
Oh, hold on, hold on, hold on, hold on.
We're filling the display still.
That was from pre that was from the previous the [snorts] previous work.
Hold on.
Uh, I mean the eye is that that could be the eye, right?
[snorts] That could be the eye.
[laughter] Exor the screen P. I keep reading this drawing section over and over again, thinking maybe that's what's Huh?
Okay, let's go through the code real quick and just make sure it is what it is. Um, where's the draw? Draw draw.
Okay. U in 8t xcoordinate equals chip register v or register at vx.
Okay, that's a mistake. That should be vy, right?
That's a mistake, rows, columns.
Okay. Should we be exoring every single pixel?
Sprites are exorded onto the existing screen.
Put screen inside the check.
Oh, yep. I think I think actually you're right cuz I don't think I'm supposed to be exoring it, right? I don't think I'm supposed to be exoring it.
Well, what if I do this? What if I do What if we twist this a little bit and we say if So, we only want to set the collision detection.
We only want to exor if sprite. If sprite pixel is sprite pixel does not equal zero, right? Meaning we need to do something with it.
Then we can say if screen pixel equals one, right? Because now we got we know it's on.
And if it's on, that's where we do the collision setting. So we could do chip V. Oops.
Uh F15. Sorry, not FB equals what does this equal? We set this to one.
Then like you said, what you just said is we need to move the exoring inside this check or basically we need to make sure that we're only exoring when the sprite pixel is actually one. Right? So screen pixel equals one like that.
I think that's better.
were the same. I don't know. We definitely fixed a bug up on the up up above because we were grabbing the wrong coordinate.
Yeah, I [snorts] think I think I think that what you think is correct.
I [ __ ] can't spell.
And I cannot blame lack of coffee at this point, bro.
It's so close.
There's There's so close.
So close. [laughter] Oh [ __ ] I was going to say too much. No, no, you're you're on it, man. I think we're close. That to me looks something like I I don't see the B as much, nor do I see the M as much. I definitely see the I, right? That's That's clearly That's clearly an eye.
This is something is going on here.
There's definitely a shape here, but it's still still slightly off.
And I I think I've run out of time to fiddle with it, but it's still there's still something. And we're just a little little off on little little little but we made lots of progress.
I will try to set up uh I'll try to set up Ray Lib on the computer tonight. At least get it make sure it works and I can render a window and stuff. I'll try to do that tonight and then maybe tomorrow we can move this out of the terminal drawing step and into the um I'm surprised that this is so much further below. I think that's the thing that I would expect all this to be on the same line, you know.
Yeah.
It makes me think it makes me think there's actually something wrong with our bitwise math.
And I and it makes me think that the XY are not getting properly translated from the instructions into what they should be.
That's my current That's my current thinking.
I think it's to do with ycoordinate v equals chip x because it's not sticking to the y-coordinate. Well, that's why I think I think it's I think it's right, but I think I think this Y and X value are not getting properly ingested.
I think there's something off with how we're calculating this.
Is it just me?
Yeah, there's something there's something off about how how you think I think there's something off about it.
So, we shift eight bits to the right.
What? Something about it strikes me as odd, but I don't know what Um, well, I guess here's what here's what I'm thinking in my head.
What? There's mouse support.
When did Neoim add this?
Has that always been there?
[laughter] I guess I've never rightcicked in Neoen before. That's hilarious. Uh [snorts] I guess what I'm thinking is is does this does this need a mask like that? Can we just mask four bits?
Can we just mask four bits here?
That's the IBM logo. Tell me that's not the IBM logo. That's the IBM logo.
Tell me I'm wrong.
That's awesome. Okay, bro. [laughter] Yes. Okay, so the problem is is that we're shifting and we only care about a four bit value. So we only need to mask by by four bits. If we mask by if we basically if we apply a 16 bit mask, which is I think what we were doing originally, right?
Yeah, I think that's what was happening. What were these values?
240, but we only care about a 4bit value. So, I don't think that's necessary.
Okay.
Oops. Sorry. Put that back. Put that back.
We've got an IBM logo.
All right, one more time before we go for the day.
Ready for my masterpiece?
IBM logo. Chip eight.
Voila.
Oh my goodness. That's hilarious.
Yeah. I think what was happening is that basically the mass that I was applying was resulting in this always being zero, right? So x was always zero every time.
So [snorts] what if we just inverted this? What if we just inverted it? What if we did uh what if we mast then shift? Would that basically get us to the same place?
Why does that look weird? Oh, the 240.
I I knew the bitwise math was going to screw me up. I just knew it.
Yeah. So, I could have I that I messed it up basically. I'm guessing when me and Kale were talking through this the other day, I'm guessing 100% that because we were going through this one by one by one using the example and I probably just flipped it.
So, we should mask and then shift.
Yep. This was a cool It is that it was This is a cool program. It's a cool project. Um, it's actually I think I'm learning much more about how how code and data in my code maps down onto um memory, right? Which I think is the whole point, right? This was the whole point of learning C was for this reason to better understand because I think this is the first time I've ever like this is definitely this drawing function down here. I've never done this before. This is the first time I've ever used um unsigned eight uh ins like that to represent individual bits and loop over them. I've never really done this before.
It's cool though. I'm learning. I feel like I'm getting more comfortable.
Yeah, great project for memory. Yeah, 100%.
Okay, so tomorrow what should we do tomorrow? I guess we should try to implement the rest of the instructions.
Yeah.
So, let's do implement remaining or how about tomorrow we do ray. We figure out the ray piece. So we can go from drawing IBM in the terminal. Yeah. Eventually you can make Halo.
Yeah. Yeah. Let's just break out some Halo. Uh so let's do migrate drawing to uh Ray window and then implement remaining instructions.
Uh, we need to still need to handle keyboard input.
Handle keyboard input, which we haven't done. So, we still have quite a bit to do. But, man, I feel so accomplished.
[snorts] I feel so accomplished. I appreciate anybody who I think it might just be Kale that hung around to see the the final work. Can you guys even see that?
It's kind of hard to see, isn't it?
Let me outline it for you.
I Oh, actually, I wonder if I used a different character. It'd probably look better if I used like a block character.
Let me Let me copy a block character real quick.
block character unic code.
Let's do full block.
So instead of printing this, let's print that. That will probably look better.
Okay.
Yes. Yes. That's it. Dude, I've never been so excited about drawing something onto the screen in my entire life, [laughter] dude. That's awesome.
That's just fantastic. Now, if I could just like center it.
That's [snorts] about as good as it's gonna get. I present to you IBM.
control shift or I'm going to save that desktop IBM logo drawn by my chip 8 emulator.
Oh goodness.
All right, folks. Well, I better go to work before I get yelled at for playing hookie.
I am going to share my creation with the world, though.
Okay, [snorts] I'm out of here. Kale, have a great day. Thanks for hanging out, man. I appreciate you uh giving me all the necessary pointers and hints and leading me in the right direction. Thank you very much.
All right, I'm out of here. Hope you guys have a great rest of your Thursday and I'll see you hopefully tomorrow morning. We'll try to do some ray living. Okay, bye bye. PC guys.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23