‫Hello, everybody, and welcome back.
‫In this lecture, we're going to create the virtual keyboard player.
‫OK, so what we're going to do then just scroll up to the source root directory here in the source directory.
‫We're going to create a new folder keyboard.
‫We're going to call it OK.
‫And in here, we're going to have keyboard dot h.
‫OK, so now we're going to have a tag if and def keyboard Hajj and we're just going to define that,
‫OK?
‫And as you probably gathered, this is going to represent a keyboard because as I said in the presentation,
‫we're having a virtual keyboard layout.
‫OK, we might support Apple keyboard, Logitech keyboards.
‫Yeah, the list goes on.
‫OK, so we need some sort of abstraction for that.
‫As I've explained, we're only going to implement one keyboard in this course.
‫But even so, we want the abstraction layer there so that that's the correct way to do it.
‫OK, so what we're going to do is we're going to go struct keyboard, OK?
‫This will represent a keyboard.
‫Obviously keyboards will have names.
‫We have Logitech, we have Apple.
‫They need names.
‫OK, this will be a link list type of implementations.
‫So we're going to have appointed to the next keyboard, OK?
‫And we're going to have a keyboard and it function, which we haven't created yet.
‫OK, and now we're going to make the TYPEDEF for that.
‫So we're going to go typedef in it.
‫Uh keyboard and function and it'll look like that.
‫So this init function takes no argument and returns an integer that said OK, that's it for the head
‫of file.
‫For now we're going to create a new file keyboard that c and that's going to include keyboard deitsch.
‫OK, so again, this is our virtual keyboard player.
‫OK, so we're going to have a static struct of keyboard and this will be the keyboard less.
‫Ted Kennedy is going to be equal to zero and we're going to have the same for the keyboard less tailed.
‫So we'll just call the keyboard less last.
‫We're going to have a keyboard and function and this will do nothing for now.
‫In the future, it will initialize pre-built well, pre comp..
‫Keyboard drive is OK, but but for now it'll do nothing.
‫And we're just going to copy and paste that.
‫Put it in the header file as well guys.
‫OK, because we want that exported uh well accessible outside.
‫So just like that.
‫OK.
‫And just down here we're going to say in a keyboard insert struct keyboard
‫keyboard and we're going to go and address equals zero.
‫And we're just going to say if the keyboard init function doesn't exist, then there's a mistake here
‫because someone's tried to insert their keyboard, drive it to us, but they don't have an initialization
‫function.
‫How can we possibly allow them?
‫We need to initialize their keyboard and they haven't even defined initialization function.
‫So if a keyboard driver tries to tell us about itself but it doesn't have an initialization function
‫in its keyboard structure, then absolutely we're not dealing with them.
‫We're not dealing with them at all.
‫So we just go rest's equals minus e invalid argument, OK?
‫And we're just going to include status.
‫Start the and also Colonel H up here.
‫And just down here, we're also going to go to our OK and we're going to have an out label down here.
‫We're just going to return.
‫Yes.
‫So remember, just post the video if you guys if I'm too quick for you guys.
‫OK, so now just by here, if the keyboards list last exists, although is not now that we've already
‫inserted a keyboard before, in which case we're going to go keyboard list last next EQUASS keyboard
‫and we're going to change the keyboard list last to ourselves.
‫The keyboard is about to be inserted, which makes sense, right, because we're changing the tail of
‫the linked list and we're also specifying which which keyboard comes next.
‫OK, so we take the last keyboard, we set its next variable to us extending that list, and then we
‫set ourselves to the last element on that list.
‫So it makes complete sense.
‫OK, and then we're just going to go to init keyboard, which we haven't created that label yet, and
‫we could potentially make that a bit cleaner.
‫But for now, that's OK.
‫And here we're going to go.
‫Keyboard less head equals keyboard keyboard less last EQUASS keyboard.
‫OK, now down here we're going to have in a keyboard label and it's just going to go six keyboard in
‫it just like that.
‫OK, see, I won't lie to you guys that that is a bit ugly.
‫As a matter of fact.
‫You know what, let's get rid of the go to here and we're just going to have an else statement.
‫I usually hate al statements, by the way, but sometimes they're perceptible.
‫So I guess else can be quite ugly, I find.
‫So, yeah, we'll just do that.
‫OK, there you go, so that's cleaner now.
‫OK, so if we have a last variable, then we've already inserted to the list before, so we'll just
‫append that to the end.
‫Otherwise, we're creating a fresh new list.
‫OK, so that's how that should look.
‫And then we just initialize the keyboard.
‫OK, perfect, guys.
‫That's very good.
‫OK, so we're now just going to implement the keyboard push function, so we're just going to go Voyt
‫keyboard push Chassy I'm going to go struct process.
‫Process equals process.
‫Curran's now we're just going to scroll up here and we're going to include a task force to start Hajjaj.
‫OK, now, before we continue any of this, we need to actually change the process structure, so if
‫we just hold control and left click on process, it'll take us to a process and we can implement the
‫keyboard buffer here, as I showed you in the presentation.
‫OK, so we're just going to go struct keyboard PAFA and that's going to be called keyboard type variable
‫name.
‫And we're going to go Char Buffa.
‫That's going to be called a picturesque keyboard.
‫But Forsys, which will define later we're going to go in a and it had now explain what all of these
‫do in the presentation.
‫So if you have skipped ahead, go back and watch it because this is important.
‫So we're going to copy and paste this definition into config outrage
‫and the Buffa sizably 1024 bytes.
‫Once you've done that, just head back to keyboard and see and we can continue our keyboard push, so
‫we're just going to go if the process failed.
‫Well, if we couldn't get a process, just return here.
‫We're going to say in it, real index equals keyboard, get tail index and we'll create this function.
‫In a moment here, we're going to say process keyboard buffa.
‫Real index equals C process, keyboard ducktail plus plus.
‫And that's it for the keyboard push function.
‫We now just need to define the keyboard cattail index.
‫So up here we're just going to go start in a keyboard cattail index struct process process and that's
‫just going to return process keyboard.
‫Tateo modulus the size of this keyboard player.
‫Buffa now explained why we use modulus here in the presentation.
‫So if you're still confused, you need to watch the whole presentation.
‫Don't skip the theory of this course because there's a lot of important stuff that I can't just show
‫you encode.
‫I have to break the problem down for you to understand that we're now going to just create a function
‫that is used for backspaces on the keyboard.
‫So we're just going to go a static void keyboard, backspace struct process process and that just makes
‫the backspace in the buffer.
‫OK, we're going to go process keyboard ducktail minus equals one and it real index equals keyboard
‫cattail index process process keyboard dubov real index equals now while zero zero.
‫OK, and we'll make this not static actually.
‫OK, so now just take the keyboard.
‫Backspace put it into the keyboard that had a file and we're going to do this the exact same for keyboard
‫push.
‫I'm going to put them both in the head of the keyboard and see.
‫Of keyboards.
‫I mean, OK, so we're now going to implement keyboard pop, just scroll up and include tests at her
‫age.
‫That's the first thing to test out how much we're going to go cha keyboard pop.
‫Remember, we're only supporting aski in our kernel otherwise would have a wide shot here if we wanted
‫Unicode.
‫OK, so we're going to say if if there's no current task then return zero, OK, because no tasks exist
‫apart from otherwise.
‫We're going to say struct process process equals tasks, current process.
‫And I explain why we're doing all of this in the presentation.
‫So you need to watch that if you're confused, right.
‫We're going to go in it.
‫Real index equals process keyboard dot head modulus size of processed keyboard Dubuffet.
‫Now we're going to go Chassy Eco's process keyboard of real index case that takes from the keyboard
‫buffer.
‫OK, we're going to say that if the char is no and to two there guys, then we have nothing to pop and
‫we should return zero.
‫OK, nothing japa return zero.
‫Otherwise we're going to say process keyboard above real index.
‫Equals zero process.
‫Keyboard I plus plus.
‫OK, and we're going to see down here.
‫OK, so this is a stack we can push to the keyboard for and we can pop from the keyboard buffer.
‫OK, when we push, it takes the current process we are looking at, OK, and it will push to that,
‫that keyboard buffer.
‫When we pop it will take the current tasks, this running process and we'll pop from that keyboard before
‫this makes complete sense, because when we press the key where inputting to what we can see, OK,
‫when we pop that based on whichever task is running, just because we can't see the active task doesn't
‫mean that it isn't that that the process isn't popping from the keyboard buffer, OK?
‫However, when we push to the keyboard, we're looking at what we're pushing too.
‫So keyboard push should use process current.
‫We can't use this kind of keyboard pop because that will mean if a task issues a keyboard pop, it will
‫pop from the keyboard.
‫But for the task we're looking at, the process we're looking at, I should say that's not what we want,
‫OK, because in a multithreaded environment we can have 10 tasks running.
‫They're all going to be popping from the keyboard before, OK, but we're only going to be pushed into
‫one process, OK?
‫And that's the process we're looking at.
‫OK, so that's why we use different ones here.
‫We use process can here and Tasco in here.
‫OK, so we've implemented keyboard part now as well.
‫So just copy and paste keyboard pop and we're going to put that in keyboard dot org.
‫We've now finished implementing our virtual layer for keyboards.
‫All I want us to do now is add keyboards to the Makefile.
‫So just go to the Makefile here.
‫We're going to copy and paste one of the C files here will go for iodized.
‫Oh, I think I copy and paste that we're going to change this to keyboard keyboard tutto.
‫And we will have to make that directory in a moment.
‫Keyboard keyboard that C.
‫Include keyboard, keyboard, keyboard, Taddeo while keyboard, keyboard, I don't see I mean.
‫And by here, we're going to do a keyboard keyboard.
‫OK?
‫We're going to copy and paste this.
‫Into the requirements by here.
‫OK, the five requirements scroll up and in builds, we're going to create a new folder called Keyboard.
‫And I'm just going to create to keep following here, because I have to, well, get git repository
‫here and we're just going to go make clean build that S.H. And we can see there's a few errors here.
‫No problem.
‫So we see struct process declared inside.
‫Parameter lists will not be visible.
‫OK, go to keyboarder.
‫And just off the top here, we're going to go check process, OK, and I will just ensure that it's
‫forward declared OK, so we can try and build that again.
‫OK, we can see only one error now.
‫Line fifty four on that C.
‫Implicit declaration of process current, I guess we well, we have implemented that function, OK,
‫are we exporting it in post to start the Hajj?
‫No, we're not.
‫OK, I want us to copy and paste process current OK.
‫This function and process Stazi and just put it in the header file like that.
‫OK, and do the same for process get so we don't have to come back to this.
‫Just paste it in there.
‫OK, well now going to run the build again.
‫We see that works perfectly, and there's only one last thing to do, go to Canada and see scroll to
‫the top.
‫We're going to include keyboards, keyboards.
‫We're going to go to the colonel Maine.
‫And you guys know what we're going to do next.
‫Just have to be reduced to the commands.
‫We're going to go keyboard and it OK, initialize all the system keyboards.
‫OK, so that's that's what that will do.
‫And just try the research again.
‫Make sure everything's OK.
‫Perfect.
‫We can see everything works.
‫OK.
‫So congratulations guys.
‫You've now implemented the virtual keyboard layer in the next couple of lectures will be implementing
‫the actual keyboard and handling keyboard interrupts.