‫Hello, everybody, and welcome, and in this lecture, we are going to implement the ability to read
‫lines from the terminal so someone will come along, they'll type something in the terminal, they'll
‫press enter, and that will be read into a buffer what they typed.
‫So the very first thing that we need to do is we need to go to PTW Hajj and you'll see get key.
‫We want to rename this to Peatross, Get Key and now go to Peatross Diesem because we need to change
‫that here as well.
‫So we're going to go picturesque at key.
‫OK, and before we go any further, we need to make it so this command is blocking, so essentially
‫it will not leave until we get a key prest, OK?
‫Now, this is pretty important and we do need it.
‫So we will be implementing that, but we won't do that in assembly language.
‫OK, so once you got Petroskey and Petrofsky here, you've changed them.
‫Make sure you've also changed it in the global export.
‫Guys, once you've got all of that, I want you to create a new file called Petro Stazi and in this
‫file will include of the Hajj and we're now going to go in it.
‫Peatross get key block.
‫OK, so this will get the key and it will block.
‫So it will wait.
‫OK, so how that works we go in it vao equals picturesque get key ok.
‫And we say well Val
‫is equal to zero then carry on and then we'll go Petrofsky again.
‫OK, now this could probably be a two while so let's change this to a do while.
‫OK, seven to zero here, so we'll basically say Valley because Petrofsky, while the value is zero,
‫then loop back around.
‫So this will this will block until a value is pressed.
‫OK, until a key is pressed, I should say, and we return value here as well.
‫OK, guys, now put that impetuousness out ahead of time.
‫OK, so we're now going to just quickly test that and see if that works.
‫OK, so go to Blanchot C and inside here, we're going to get rid of this while loop get key thing,
‫just keep a blank while loop.
‫And just by here we're going to say Peatross, get key block, OK, and we're just going to print underneath
‫this so we shouldn't see hello world.
‫And so we press the key.
‫OK, so we're going to test this, go to the makefile in the lab for Peatross.
‫And inside here, we're just going to change this picture w o to picosecond assembled.
‫Oh, we're going to change this one to start assuming that oh we're going to change this one to has
‫assembled.
‫Oh OK.
‫And let's just check that bales', ok.
‫Yes, that works fine, we can just see the undefined reference because we haven't yet linked with Peatross
‫Stazi, see we haven't compiled it.
‫So once you've done that, I want you to copy and paste still typed up.
‫Oh, I'm going to paste it on the post today.
‫Assembled, OK, and we're going to change this to us.
‫Dot o p e c p e c p tostado.
‫And then we're just going to add that to the make file by here guys, OK, to the actual file requirements.
‫So the all label depends on all of those files we specified here.
‫So if we now do a make clean and a filter S.H. all should Ken Pollack which does excellent.
‫So if we now go Khedive in Kumu.
‫And just type of key we can now see says hello, world, so we now have the ability to block and and
‫Rikki's, which is what we wanted.
‫OK then.
‫So we're now ready to start making the actual reading line function now that we have a function that
‫gets the key and blocks.
‫So we're going to do then we're going to go void Peatross terminal red line
‫and this is inside.
‫You start to see, OK, we're going to go out at Max Bule output while typing.
‫So essentially when we call this function, it's going to wait until you press the key.
‫It's going to fill a buffer, OK?
‫The buffer will be out buffer when you press and then it leaves the routine because the buffer is being
‫filled successfully.
‫The max variable is the max total characters you can store in the buffer.
‫You've provided an out by here.
‫The output, while typing is an interesting one.
‫If you type on a Linux terminal, for example, this one, you can see the keys, right?
‫You can see the keys.
‫I'm pressing.
‫But if I was to enter a password, you wouldn't see the keys I'm typing.
‫So if you pass true in here when they're typing, you'll see it being written.
‫If you pass false when you're typing, you won't see it being written, but the buffer still be getting
‫filled.
‫So obviously if someone's typing a password, you would put false in here so that they doesn't show
‫what they're typing.
‫OK, so that's what's going on there.
‫And we're going to program all of this now.
‫So let's begin.
‫We go in Schaikewitz zero four I equals zero I below max minus one I plus plus Chalkie equals ptw get
‫key block.
‫If the key is equal to thirteen then that's a carriage return.
‫OK, carriage return means we have read the line because what happens when you press enter on a computer,
‫you go to the next line.
‫OK, so it's the same thing here.
‫OK, so essentially when they press enter we've done the command successfully so we just break and leave,
‫OK, because the buffer is being felt correctly at this point.
‫So now we're going to say if output while typing, then we need to output to the screen.
‫Well, the key that they just pressed so we do as percha, OK, and we're going to pass in the key that
‫they pressed.
‫OK, so that takes care of that bit that this so far we're at the stage where it reads the line, it
‫reads what they're typing and outputs it to the terminal.
‫We don't, however, store the results in the buffer they've provided.
‫So we're going to do that bit now.
‫And we also don't have the backspaces.
‫So what we're going to do then, we're going to do comment backspace.
‫We're going to go if the key is equal to zero eight, which is the backspace key and AI is in bounds,
‫then out I minus one equals zero zero.
‫Now Terminator basically when I now going to go I minus equals two and continue.
‫And the reason minus two is required is because what we do continue.
‫I will be plus one.
‫OK, so that's why we do that.
‫So minus two.
‫Because we will plus one when we go to the continue.
‫Now granted this could probably be written a little bit better guys.
‫OK, I'm not going to tell you, I'm not going to pretend that this is perfect design, but it will
‫work.
‫So here we're going to go out I equals QI.
‫So what we do now is we just add the nail Terminator, OK?
‫And as you know, in C strings are ended with no Terminator's.
‫So this is perfect.
‫Let's test this function, copy and paste it into PTW Hajj.
‫Go to blanked out, see our way, go back to pizza, start Hajj was that is complaining that ball is
‫undefined, so just include acidy ball.
‫Inside PTW.
‫OK, cool, go back to Blankfort, see that and we're going to try this now, so we're just going to
‫go chop off one thousand twenty four and we're going to say Peatross terminal red line.
‫We're going to read it.
‫It's above the max is the size of Buffer and we want to output what we're typing.
‫So we'll pass through in there and now we're now going to go print buffs.
‫So.
‫Well, I put the message they typed, OK, let's test that now.
‫We're going to go make clean build that S.H..
‫And then we're going to go KDDI bin and we're going to run Kumu, the kumu emulator now just type something
‫so we can see that's working press center and we can see what we just typed out, put it to us.
‫So that's amazing.
‫Guys, let's try that again.
‫How are how are you doing?
‫Press center.
‫How are you doing?
‫So it puts it to us.
‫That's really, really good.
‫And you'll notice we can't do uppercase, lowercase.
‫It's stuck on uppercase.
‫That's because we don't care about caps, lock or shift.
‫OK, we haven't programmed any of that in.
‫So that's why we're stuck with uppercase characters here.
‫But anyway, the point is it works quite well and we can use this to receive commands from from the
‫shell, OK, and then start programs essentially.
‫So congratulations.
‫You've now implemented the ability to read lines from the terminal.