‫Hello and welcome, guys.
‫So we've now set up the keyboard drive as successfully we need to be able to write in our user program
‫some code to be able to access the keys that were pressed, the keys there in that buffer.
‫So how this will work is we're going to create a command that will allow the user program to do a keyboard
‫pop and basically take one of the keys out of the buffer.
‫Right.
‫One of the keys that were pressed.
‫Now, let's just look over this key will pop function for a moment so you can understand how we're going
‫to do this.
‫Now, here we want when we when we call Kibo Pop, we first check here.
‫Right.
‫If the buffer of the keyboard in the process, if that index has a value of zero.
‫Now, if it does, then there's no key to pop.
‫OK, there's no key to pop because it's now it means it means that we've reached the end of the buffer,
‫OK?
‫So what we do in that situation, nothing.
‫We just return.
‫That said, that's all we do.
‫We just return, OK, because null is not a valid value to push.
‫OK, and as a matter of fact, to avoid a potential situation where we are no longer able to pop from
‫the keyboard, let's just do one more checking keyboard pushier.
‫We're just going to say if the character is null, then return, OK?
‫We're not going to allow them to push no characters to us.
‫OK, as simple as that.
‫So, yes, simply put, I use a program.
‫All it needs to do is it needs to call Keibel Pop.
‫It can't call it directly, obviously, because it's a kernel function.
‫We need to create command that allows it keyboard pop and it needs to be on a loop.
‫OK, and one, the C is no longer zero.
‫It's successfully waited for a key press.
‫OK, so it will loop and loop and it will do Keibel pop one C is no longer zero.
‫Then the user program has successfully waited and there's now a key return to it.
‫OK, and when it has that key it can then push it to the terminal or whatever to just show you what
‫key was pressed.
‫OK, so it's not so difficult.
‫Just remember to make that change on keyboard push.
‫OK guys, because, uh, it might not happen, but if somebody does push zero, it's going to break
‫the buffer.
‫So check for that.
‫Uh, OK.
‫So what we're going to do then we're going to go to our programs here in blank, Dadaism, and we're
‫going to modify our little program here now so that it can get a key.
‫OK, so simply what we're going to do is we're going to say get key.
‫This is going to be a little assembly routine.
‫OK, so the first thing we're going to do is we're going to say movie acts to OK, come on, two will
‫be forget key.
‫We haven't created that command yet, but it will be created soon.
‫Come on, get key.
‫OK, we're going to call in and see you outside and it will return the key that was pressed in the register.
‫OK, so what we say now is, is we say compare X to zero, OK?
‫If it's not zero, then we jump back to get key, jump not equal, get key.
‫OK, now otherwise we'll have the key stored in X at this point.
‫So now we can just Duret to return.
‫OK, so this simple routine should work.
‫OK, so we go in here, we set the command to get key, we invoke the colonel.
‫The Colonel will now return the next key in the buffer or it will or it will return zero if there was
‫no key left in the buffer.
‫OK, so if we return zero, that means there's no key in the buffer.
‫So we want to wait, OK, because we wanted to block basically until there's a key press.
‫OK, so we want to wait.
‫So because it's zero we just jump back to get key, OK, and we run that again and then this will go
‫on and on and on and on and on until there's a key press return to us.
‫A key in the buffer return to us.
‫OK, so perfect.
‫Now that we have a key in us in our little assembly routine, we can finally test that out.
‫So what we're going to do just by here, we're going to say, cool, get key, OK?
‫And now by here, we'll go push message, move one, and it's the exact ad, ESP four.
‫So what this will do is this a way for key press?
‫And one, there's a key press output.
‫The message again.
‫So we in fact, we can get rid of this first one here.
‫We don't need that anymore.
‫So that's what it'll do.
‫OK, it'll wait for key press and then will put a message to us.
‫And yes, the key to his press would be stored in the register before we override it on line 10.
‫Of course.
‫OK, so just go to Isaw, engage in the source file, not the build and go to iodized see and hear.
‫We're just going to say void asterisk ISIS command to get key and that's going to accept an interim
‫frame, as you know, and simply be.
‫We're just going to say keyboard pop and we're going to need to include keyboard as well guys.
‫So just go include keyboard, keyboard, dot Hage.
‫And we're just going to put that on the task because it looks better so that we have keyboard pop now.
‫OK, so this will be Chaussy Eco's keyboard pop, OK, and we just return C and we're going to need
‫to cast that to avoid pointer as well guys.
‫And there we go.
‫That is a key function, nice and simple.
‫I copy and paste the prototype into Ayoade Hajj and in Isaw ADHD.
‫See we're just going to go inside the Hajj register command system.
‫Come on to get ke i saidy Hajj command to get ke nice and simple.
‫Now go to Isaw Hajj Don Hajj and we're going to need to add that command here in the system commands
‫in a system command to get key.
‫OK, perfect.
‫So now that's linked up all correctly and we should be able to now get keys because when we issue a
‫command to any in the X register, it will invoker isolated command to get key function, which will
‫then pop from the keyboard and return the result.
‫Perfect.
‫So we're just going to go make a clean build that I say.
‫And we can see a minor problem here, a casts appointed from industry of different size.
‫OK, that's no big deal.
‫What I wanted to do is I want you to cast it to an integer and then we'll cast it to avoid just like
‫that.
‫OK, so now we're going to try that again and we can see that works perfectly fine.
‫So just first cast it to an integer and then cast it to avoid pointer and then that way it solves the
‫size difference.
‫So, guys, let's just check over this code, make sure everything's right before we do anything else.
‫Go do.
‫I saw Eddie start see and we can see we've done register commands.
‫That was a mistake that should be registered to command all not commands command.
‫Let's take a look in our blank, Dadaism.
‫This shouldn't be jump, not equal, they should be jumping equal.
‫All right, if X is equal to zero, we should jump to the Geikie, not if it's not equal, because if
‫it's not equal, then it's it's going to be fine as long as there is not anything in the buffer.
‫And that's not what we want.
‫So, yeah, just make sure.
‫Let's jump equal.
‫OK, so now we're going to go make a clean bill that S.H..
‫Everything works fine, keeping kumu.
‫Now it's waiting for a key press press F and we can see I can talk with the colonel and you can press
‫any key you like and it will resume.
‫OK, that's pretty good, right.
‫Let's launch GDB here so we can examine the output.
‫So we're going to go target remote kumu system I 386 stop in capital s gdb studio and we're going to
‫break on askaris 400000, just press three to continue and go to Leo s.m.
‫So we're going to step through this.
‫This is our use program and we can see it's about to invoke the colonel to get the key.
‫So what we're going to do is we're going to break on on as Chris Cox for four thousand and one D and
‫we're going to proceed to continue.
‫OK, now we've just called the function to get the key.
‫OK, so now we say print X, we can see that Cyro up because we haven't pressed the key yet.
‫So I'll tell you what we'll do instead.
‫We'll make a break point somewhere else to just do delete.
‫So it deletes all the breakpoints and we're going to go break asterisk zero x 40000 and a OK, now just
‫press C to continue and now press any key and kumu.
‫I pressed a and I if I go print X, we can see 65 and if we if we cast that to a char, we can see that
‫someone 65 is Cappotelli.
‫So the keyboard's now working guys.
‫We've now created a little routine for ourselves that can get keys from the keyboard.
‫So obviously we want to show the user what they're typing so we can we can create another command for
‫putting to the terminal, OK, and then that will put what they've typed to the terminals.
‫So, yeah, congratulations, guys.
‫You've now implemented the keyboard.