‫Hello and welcome, and in this lecture, we're going to output characters to the screen and print Hello,
‫World.
‫So if you remember in the last lecture, I explained how if we write to address you XP eight zero zero
‫zero, we can actually output ASCII characters to the screen.
‫So we are now going to demonstrate that.
‫So if we just go Char, so we're making a char pointer right now and we're just going to say video mem
‫equals char.
‫So Castanza char zero x be eight zero zero zero.
‫OK, so we're just creating a pointer to this absolute address in memory.
‫And if we now go video meme zero equals a video meme one equals one.
‫OK, and now if we now compile and run that I'm going to go make clean forward slash build that S.H.
‫Cribben and then we're just going to run Kumu.
‫We can see at the top left corner, you can see a blue, a anoush of you can see that, but let's try
‫that again.
‫So let's change the color to this time.
‫And we're going to run that Dallasites again.
‫Yes, so now we see we see a green a do you see that?
‫So that's what's going on there, right?
‫Change it to three.
‫And we can try that again, and now we see a blue a yes, you can see that the top left corner of the
‫screen.
‫So that's pretty impressive.
‫So what we've now done is we've implemented in practice what I discussed in theory in the last lecture.
‫So here we change Rosero column zero and we set it to a let's change Rosero column one.
‫So to do that video meme two equals C video.
‫Meme three equals three.
‫So if we now recompile that and we run that again, we now see A and C.
‫At the top left, so you can see how that's working, right, so we write our ASCII character for the
‫first byte and then the next byte is the color.
‫So that's how that's how it works.
‫OK, so before we go any further, we're going to change this to an unsigned short because we know that
‫these take up to Bitts.
‫So why complicated?
‫So to do that, we're going to say include acidy in it.
‫That's the first thing I hear.
‫We're going to go you in it, 16 t video.
‫Mm hmm.
‫We're going to make sure we cast that to that as well.
‫So now here, when we go video meme zero equals A instead we would go something like this would firstly
‫would figure out what the A character is in Hex A is 65 decimal.
‫Right.
‫Cessford 41 hex.
‫So if we go equals zero X forty one and we can just go zero three by here and now if we now compile
‫that.
‫We can see that is printed out a really weird character.
‫Now, why is that?
‫That's because of ending this.
‫So I wanted you guys to see that.
‫So what it should be instead is zero three, Hex 41.
‫And that's because of ending this.
‫Right.
‫So I hope you guys know what that is.
‫If you don't, you need to research by that stuff.
‫We now know that we can see a appears as expected, whereas before we saw some weird character because
‫of Indianness.
‫So the process of flip these back around so we have zero x forty one zero three.
‫Right.
‫Because essentially when we do video zero equals this, it will store 41 zero x 41 in the first byte
‫and zero zero three in the second by OK X.
‫And so now that we've done that, let's make it a little easier to work with.
‫We don't want to work with hexadecimal numbers doing OK.
‫So to do that you just go unit 16 T and we're just going to say terminal, make sure that's what we're
‫there.
‫And while this will take, it'll take a char for the character and it will take a char for the color.
‫And all that we do is we go return Kulla shifted to the left by Apitz and then we saw it with the Shah,
‫OK, and that should work absolutely fine.
‫And now now what we can do is here we can go equals terminal.
‫Make sure we can just pass in B or whatever and we'll pass in the color.
‫And now if we now compile and run that.
‫We can see BP is outputted, and this time it is much easier and clear what's going on.
‫We don't have to work with hex numbers anymore, so we change that to four.
‫It'll change the color to right.
‫Try that again.
‫And there we go.
‫Now we see it in red now.
‫c.B in red.
‫So you get the idea then, what we're basically doing is we shift the color to the to the left by Apitz,
‫we orit with the char provided to us.
‫So it basically returns us, the unsigned integer that we need in the correct ending this so that when
‫we set the video memory, it is set correctly.
‫OK, so our acidy in it we've included here.
‫That's all fine.
‫But let's put it in the kernel head.
‫Instead, we're going to go to the kernel chheda now and we're going to we're going to actually have
‫to create some definitions here for the VGA width and height.
‫So we go hash tag defying Vuit and it's 80, by the way, the default defying VGA heights and it's 20
‫the default.
‫And now if we now go to Canada, I'd see we're going to now create an initialization function.
‫So just go void, terminal initialize, OK?
‫And this is basically going to just loop through the terminal and essentially clear it all for us so
‫that all of that sehbai or stuff that we see there is all blank.
‫OK, so what we're going to do then we're going to copy video memory here.
‫We're going to post it at the top by here and we're going to copy this and we're just going to change
‫this to zero.
‫OK, now in Terminal Initialise, we're going to say video equals and then we'll paste that there,
‫OK?
‫And here we're going to go four inch Y equals zero Y below VGA height Y plus plus four inch X equals
‫zero explo VGA width x plus plus.
‫And now we're going to go video men and here we're going to calculate the index now.
‫So we go Y multiplied by Vuit plus X.
‫So you see this type of thing in game dev a lot when working with 2D grades.
‫Right.
‫So essentially this is the equation here to convert an X and Y coordinates into an index to pass into
‫a one dimensional array, which is basically what our video memory is being treated as here.
‫So we're now going to move terminal, make char above terminal, initialize because we're about to call
‫it and we just go video mem and in the index equals terminal make char.
‫And we're just going to spacebar here because we're clear in the display right now.
‫Right.
‫And here the color will be zero for black and now Inconel Main Jasco terminal initialize and we're now
‫going to test that.
‫So we're going to compile that, run it.
‫And there we go.
‫We now see a blank display with our character being displayed in red right by there.
‫And you know what?
‫I'm going to change the color to 15 here, which I think is White says, let's clear the see.
‫Yeah, there we are, so you can see the character, be there nice and nice and clean.
‫OK, so now that we've done that, let's make it so we can print messages out.
‫So the first thing we're going to need to know to do is count how many characters there are on a string.
‫So as you know, in C, when you declare a string like this, for example, the C compiler will always
‫put another Terminator at the end.
‫So that's how we know the string is done.
‫So what we can do then we're going to create a string line function.
‫So we're going to go sist starlin const char star and then we're simply just going to go sist Len equals
‫zero while starland.
‫OK, so basically while we're not zero Lannes plus plus.
‫And I was just going to return Lenn just like that and now you'll notice is complaining.
‫So we need to include S.G. The Def Age and I know we put in it here last time.
‫We're actually going to move that now, so copy that and paste it in Canada and see back where it was
‫originally because we just want to, we want to keep that abstracted out.
‫You know, unless we're exporting some functions here, it makes sense to just keep them here.
‫Right.
‫OK, so this is our string length.
‫And so congratulations are so good now that we know that we can create our print routine.
‫So before making our print routine, we're going to create a nether function now.
‫Terminal Patkar void terminal Pusha and we're going to accept.
‫A X coordinate, a Y coordinate.
‫A character.
‫And the color.
‫And, you know, this is going to be fairly simple, we just got video meme y multiplied by Viðga wit,
‫just as we did in the initialization plus X equals terminal Make, Char C and Inch'Allah.
‫OK, very simple.
‫If you now wanted to make this cleaner, we can replace this initialization with Terminal Pusha.
‫So, yeah, we'll do that, we'll go terminal pucher, you see, so we want to keep things as clean
‫as possible this entire time, X Y, space zero.
‫There we go.
‫So now we've now we've actually also improved our terminal initialize function.
‫OK, now, before we test this, we're going to copy this function and we're going to paste it just
‫above terminal initialize.
‫So terminal initialize can see it.
‫And if we now compile that, run it.
‫And there we go, we can see it has the same result.
‫Nice.
‫So now we're now we're finally ready to actually create our print function, which will take the string
‫and it will basically turn or put on hold until the end of the strings reached.
‫OK, so we're now ready to start creating our printing routine, which will print a string.
‫So we just scroll up underneath terminal picture.
‫We're going to create a new function called terminal, right, Char?
‫And this is just going to take a chance on a color.
‫It won't take an X and Y, so that's what makes it different.
‫Terminal Pachon terminal.
‫Right.
‫Terminal right now we'll just take a character and a color and the right to the terminal and then it
‫will increment a position like column or row which will ensure that the next time you call terminal.
‫Right.
‫So the different column, whereas terminal Pusha takes the X and Y, it doesn't keep track of which
‫column a row, but terminal.
‫Right.
‫Well, OK, so the next step then is to create a new variable at the top here.
‫Terminal row, another one here, terminal.
‫Call now an initialise.
‫We're going to set those to zero as well.
‫Now, in Ritcher, we're simply going to say terminal Pusha, terminal call terminal row C and color.
‫OK, so Right said to the screen using the pucher.
‫OK, so the next step now is to go terminal call plus equals one.
‫So that ensures the column is incremented by one.
‫Each time we call this so that it goes A, B, C, D rather than overwriting the same character each
‫time.
‫Right.
‫Because we adjust the column.
‫But if we get to the end of the row, we have to loop back around.
‫So to do that, we say if terminal column is above our equal vigor with terminal column equals zero,
‫terminal row plus equals one.
‫And now that should allow us to write to it like a piece of paper.
‫So we get to the end of the right and then it starts in the next slide and so on.
‫OK, let's scroll down now and we're going to change this to terminal right here and we're going to
‫put a M 15 terminal, right.
‫Char B and 15.
‫And now if we now compile that.
‫And we run it and we see a B excellent, so we're now ready to create our print routine.
‫OK, so to create our print routine, then we just underneath here, we just go void print, const string
‫and now we're just going to go sist Len equals string len SCCA.
‫And now we just go for I equals zero eight below, then I plus plus and then we just simply say terminal,
‫right, char star I and we'll just do 15 for the color.
‫And now if you now go here and you go print Hello world.
‫OK, and we now run that again.
‫You see hello, world, so congratulations, you just printed to the screen for the very first time.
‫Now what happens if we use a new line character and put something else like slash and test?
‫Let's test for that, shall we?
‫Oh, there's no new line.
‫Well, I knew that was going to happen.
‫That's why I showed you.
‫So we're going to implement the new line character now, which is easy enough inside right here where
‫we're basically going to say is if C equals new line, then terminal row plus equals one, terminal
‫column equals zero.
‫And then we're just going to return.
‫OK, I hate using L statements.
‫I think they're very ugly.
‫Some people will disagree, but I don't like using else.
‫I think else F is fine.
‫I don't enjoy using ours else at all, but I will agree to disagree.
‫So here we go.
‫Make clean bill that I suggested Ben Kumu and there we go.
‫Hello.
‫Will test.
‫So now we've just implemented the new line character.
‫So congratulations guys.
‫You've now implemented printing.
‫So your colonel.
‫Welldone.