‫Hello and welcome.
‫And in this lecture, we're going to implement the two keyboard, so if you remember the old classical
‫machines back before USB was more popular, you'll notice they had these parts on your computer for
‫the microphone and the keyboard.
‫They were particularly for the microphone and keyboard.
‫You couldn't plug anything else into it.
‫Well, we're going to write a driver for those parts today so that we can implement the keyboard driver
‫for that part.
‫OK, so back in the day, you would plug in your keyboard into that pasta pot and it would essentially
‫allow you to type.
‫So we're going to create a driver for that part today.
‫As I just said, we need to implement schang code sets.
‫Remember, I explained to you how when someone presses a key on the keyboard, we don't get the key?
‫They pressed, we get the scan code.
‫We need to basically implement a table of some kind scan scan code, set table, essentially, so that
‫we can associate the scan code pressed with the key that was pressed.
‫So if we choose scan code set one, we can see that if scanned code zero one is provided to us, then
‫this means they press the escape key.
‫OK, and you know, this table's quite large.
‫We'll need to go through this and implement this entire table.
‫I've done this before, so if you copy exactly as I do throughout this lecture, you shouldn't have
‫any problems.
‫Just make sure when you're copying me you don't make any mistakes, otherwise your keyboard won't work
‫properly.
‫But the work I'm going to be doing in this lecture that you're going to be copying will be based on
‫these scan code sets.
‫So we're going to create an array that essentially binds these values to these codes, to the ASCII
‫equivalents so we can see if we receive a scanned code.
‫Is X10 that means Q is pressed.
‫OK, so there's a few scanned code sets in here.
‫If we go to scan scan code said to you can see this represents the scan code to however this is for
‫us keyboard's now I do need to let you know we will be doing it for scan code set one.
‫So just bear that in mind because the keyboard settings you have in your computer when you run the emulator
‫might impact the keys to the press.
‫So just just bear that in mind.
‫We're going to be implementing only scan code, said one one once.
‫I've taught you how to create scan scan code set one.
‫You should have no problem implementing the other scan codes if you wanted to.
‫However, we will only be focusing on scan code, set one for these for this lecture, so the two keyboards
‫has many different types of commands.
‫So you can see we can send commands to these things.
‫We won't have to worry too much about sending commands.
‫We more care about what they send us.
‫The keys that they press, for example.
‫That's what we care about.
‫However, we can send our very own commands to the keyboard as well.
‫But we're not going to worry about that.
‫We're only going to worry about receiving commands to our colonel and dealing with those correctly.
‫OK, guys, so I want to go to our keyboard directory and we're going to create a new Philco classic
‫Dot C, and this will represent the two keyboard.
‫We just call it classic because it's easier to remember.
‫So in here, we're just going to include keyboard dot Hajj.
‫Once you've done that, we're going to go struct keyboard classic keyboard equals dot name equals and
‫we're just going to call the name Classic.
‫This will represent our classic keyboard driver, the true driver.
‫And here we're just going to go in.
‫It equals classic keyboard in it and we haven't created that function yet.
‫So this represents our classical keyboard, OK, and now we're just going to courier in it functions.
‫So we're going to go in a classic keyboard in it and it's just going to return zero copy and paste that
‫prototype and put it above here so that the structure can resolve it.
‫Perfect.
‫So that's it for the basic driver implementation.
‫For the classic keyboard, it's able to identify itself.
‫We, however, just need to register the keyboard with the with the keyboard function out of here now
‫by going keyboard insert and then the system will recognize our classic keyboard.
‫Obviously we don't we haven't written the driver yet.
‫It's just a skeleton.
‫But we're going to now insert the classic keyboard so the system can recognize us.
‫OK, so how do we do that?
‫Well, because this is going to be statically linked.
‫We will create a function for getting the keyboard instance.
‫So we're just going to go Stracke keyboard classic in its OK and it will return as a classical keyboard.
‫So we're just going to go return classic keyboard, we're going to return the address of that.
‫OK, and um yeah.
‫If we just go and copy and paste this and put this in classic dot.
‫Hey so we're going to need to create that file.
‫Uh if indef classic find classic and it should be keyboard classic keyboard.
‫Hey guys, uh hashtag indef and we're just going to post that in there like that.
‫OK, and now and keyboard and see if we scroll up and here your keyboard in it.
‫OK, now that should insert the keyboard.
‫So here we're just going to go include classic Dot Hajjaj and we're just going to go keyboard insert
‫classic in it.
‫OK, so that's perfect.
‫So well that is literally going to do, it's going to initialize the classic keyboard and inserted into
‫the, into the known keyboards, into the known keyboards of the system.
‫OK, and then at any moment we could loop through the entire keyboard less and know exactly how many
‫keyboard drivers we have installed, what ones to watch and so on.
‫But yeah, you can see why this abstraction is important.
‫Right?
‫So now we have a basic classic keyboard skeleton driver implemented.
‫Obviously, it doesn't do anything.
‫It doesn't handle any keys or anything like that.
‫There's still a long way to go with that.
‫Uh, we're now going to implement the scan code.
‫Said that I showed you on Firefox here.
‫Scan code step one, you can see we're going to implement this.
‫OK, so as I've said countless times, we need to map the scan codes to the ASCII characters.
‫So we're going to do that by creating a giant array with the index being the scan code and the value
‫being the ASCII equivalent.
‫OK, now I've already created this array, so I'm going to just rewrite it here now and you just copy
‫exactly what I'm doing.
‫If you make a mistake, your keyboard is not going to work, so make sure you pay very close attention.
‫It is quite a lot to write.
‫Alternatively, you could write your own array by looking at the scan code, step one and going through
‫them all manually.
‫But that does take a little longer because you have to cross-reference everything with yourself to make
‫sure it's right.
‫If you copy exactly what I'm about to do.
‫You won't have any problems.
‫OK, so we're just going to include as an adult.
‫Hey, and just by here, we're just going to go static unit eighty keyboard scan set one equals OK.
‫And now this is our array.
‫We're now initializing it.
‫So we're going to go zero zero zero zero x one.
‫Oh no, not six one zero zero one B I should say.
‫And now we're going to go ASCII one ASCII to ASCII, three ASCII for ASCII five.
‫ASCII six.
‫Ask seven Baskett asking nine Askey zero.
‫So these represent the keys that the press took, the ASCII equivalent of the key that was pressed.
‫The index in this array is the scanned code, index one, index to index three and so on.
‫And now we're going to go minus equals zero eight and then this will be tab.
‫So these values I'm using are just the values that I've gone through manually in my own time and I've
‫gone through the table and manually created an array.
‫OK, so that's how I know what these are.
‫It's based on this table that I sent you here.
‫OK, as I've said, we go up here and you can see 002 is one.
‫OK, you can see zero zero two.
‫Here is one zero one.
‫So OK, so now we're going to a q w e r t and I tell you, if this is one of your passwords, you need
‫to change that.
‫Y you I o p left bracket right bracket zero zero zero zero zero a.
‫S.
‫D e f g.
‫Hey, j k l semicolon quotes and remember, we do the quote by using the slash here to ignore the because
‫otherwise without the slash, you know, it'll think that we are ending the D.
‫D statement here, the quotes.
‫So make sure you use the this this symbol here.
‫OK guys, the backslash.
‫So now we have told.
‫And for those of you that don't know where the turkey is on a laptop, it's the key under escape.
‫So now we go 060.
‫Now, this one is backslash.
‫OK, so do two of them to ignore the first one, I hear we're going to go Z, X, C, V, B and M,
‫comma.
‫Full stop.
‫Forward slash zero zero zero.
‫Asterisk.
‫Zero zero zero zero 20 zero zero zero zero zero zero.
‫And now we need another nine zero zero zero.
‫So one.
‫Two, three, four, five, six, seven, eight, nine, and if you're wondering what all these numbers
‫mean, just check the scan code table guys that I've shown you up here.
‫OK, I'm showing you this so that you have something to compare against when we put zero zero zero.
‫It's because I wish to ignore those particular keys because there's no ASCII equivalent or something
‫like that.
‫OK, so now we're going to go seven, eight, nine.
‫And I know exactly what you're thinking.
‫Why are we repeating the numbers?
‫We've already defined them up here because this is the numpad.
‫We're implementing the numpad scan code to ask equivalent now.
‫And a numpad seven is no different than a keyboard seven.
‫So that's why they're the same.
‫OK, so these are the ASCII equivalents, remember?
‫So now we're going to go negative four, five, six.
‫Plus, one, two, three, finally zero and full stop again.
‫Wow, well done on get in that table then.
‫I know that was a mouthful, but it had to be done.
‫We now have a table we can use to translate scan codes into ASCII characters.
‫Now inside our classic keyboard in a function, we just need to go outby zero 64 680.
‫Now, I'll explain that in a moment.
‫And I just want you to include Io Io that Hajj, which should resolve that.
‫Yes, it does.
‫Could go to Firefox or whatever your browser is.
‫And we're just going to go back here and we're just going to search for.
‫OK, step in it, 066 fall apart, I mean parts zero six four.
‫And you'll see the two controller.
‫OK, so give this a bit of a read.
‫Essentially, what we do here is, is we're enabling a particular part.
‫OK, so if we just search for this six six four in here.
‫You can see that this is the command register.
‫OK, if we write to that pod, the command register for the two controller iReports as we search for
‫the command we're sending Zaidee, you will see that that command enables the first stewpot.
‫Now, obviously, if someone's plugged in a keyboard into the PSU port, it needs to be enabled.
‫OK, so that's why we issue this command here, because that enables the first part on the actual computer.
‫OK, so that's why we do that.
‫You will also see there is a load of different commands here as well.
‫And you can enable the second part if you wish.
‫But we will only enable the first because remember, this is where the keyboard gets plugged into.
‫OK, let me just show you that actually on Google Images.
‫Yes, so you can see this, this is what I'm talking about.
‫All right, guys, so you have keyboard and mouse and keyboard and mouse.
‫So these are the two parts that I'm referring to when I talk about the two parts.
‫OK, so this is what we're enabling right now.
‫We're enabling this now.
‫Nobody likes magic numbers.
‫OK, so we're going to take these numbers we made and we're going to give them names.
‫So go to Classic to the Hajj.
‫We're just going to go to find two part zero six four to find Pierce to command enable first part xox.
‫Uh, a.e.
‫OK, now go to Class C, we're going to change this to port and we're going to change this to two command,
‫uh, what was it called?
‫Enable first port.
‫OK, so like that, and we're going to have to include classic dot hate shapir as well, guys, OK,
‫just do that before anything else.
‫Perfect.
‫And there we are.
‫That's a lot more clear what's going on now, right?
‫So if we go here, we can see 063 enable the first piece to part and we know that 066 four is the power
‫to control the parts.
‫OK, so there we are.
‫That's much more cleaner now.
‫So that just enables our keyboard.
‫OK, that the part for our keyboard.
‫And now we're just going to make a function that is responsible for going into our scan khodary and
‫pulling out the correct ASCII character.
‫OK, so let's just do that now.
‫We're going to go Unit 80,
‫classic keyboard scan code to char unit eighty scan code.
‫OK, now we're going to go a size teh size of a keyboard, said one equal size of keyboard scan set,
‫one divided by the size of Unit 80.
‫OK, now I know because it's a array of eight bits, we don't actually have to divide it like this.
‫But this is how you would calculate how many elements were in the array if you weren't using eggbeater.
‫Right.
‫So by doing it like this, it just makes it more clear what's going on, even though it gains no benefit
‫by doing this division here.
‫So now we're going to say if the scan code provided is above the size of keyboard, set one.
‫Then return zero, and we need to resolve this SIST as well.
‫So just scroll up and we're going to include Chad Def SRH.
‫And now we have syste, we're going to go Chaussy equals keyboard's gansett one scan code.
‫Now here we would usually check if the caps lock is down or if shift is down.
‫And the reason for that is because only if the caps locks down should we be returning capital characters.
‫OK, now the keyboard has no concept of a lower case, A or an uppercase A. It just passes its scan
‫codes.
‫OK, so we need to keep an internal state of whether the caps lock is down or not.
‫And then we will decide if to give it a lowercase A or an uppercase A. We will implement capital letters
‫and stuff like that later on.
‫It's not needed right now.
‫Let's just get a working keyboard first.
‫So here we are going to say return C and it's as simple as that, OK?
‫And this function can now be used to convert any schang code from SCAN's set one to its ASCII value,
‫which is incredible because the two keyboards only going to be sending us scan codes.
‫It's not going to send us ASCII characters.
‫And I just by here, we're going to go void.
‫Classic keyboard handal interrupt.
‫And we haven't created this.
‫We haven't Bindiya dysfunction with the handler or anything yet.
‫However, that will come later.
‫We're going to basically make a interrupt handler for when when there's key presses.
‫Remember you looked at the Internet service routines in the keyboard lecture and I show you the table
‫and we're going to be binding to Xerox.
‫Twenty one.
‫OK, well, that's what I mean.
‫All right.
‫Because Xerox 21 is the actual keyboard.
‫Interrupts OK, that's the keyboard interrupt.
‫OK, so let's just get this compiling and this will conclude part one of implementing the keyboard.
‫So we're just going to scroll down here.
‫We're going to go to the Makefile, OK?
‫We're going to scroll all the way to the bottom here.
‫Well, just search for keyboard auto, actually.
‫OK, we see that.
‫We're going to copy and paste it.
‫OK, so we're going to compile to keyboard classic Dotto keyboard, classic see keyboard classic dot
‫see and keyboard classic Dotto.
‫You guys know the drill and we're just going to copy and paste this now and you know where we're going
‫to put it.
‫We're going to put it at the top here just by the keyboard.
‫Dotto OK, and that's the files.
‫The dependencies, OK, so now we're going to go make a clean bill to that stage.
‫We know there might be a few compulsories.
‫Yes.
‫Keyboard insert in declaration.
‫Well, you are all confident C program is.
‫You know what that is?
‫We need to go to class C, we've included keyboarder.
‫Oh, OK.
‫So check keyboarder Hajj and we can see that the insert keyboard we have and put it in the header file,
‫sergo the keyboard that c copy and paste keyboard insert and we're just going to put it in the header
‫file by here.
‫OK, in keyboard Hajj.
‫Because remember this is responsible for all the keyboard functionality, inserting the drivers and
‫all that or inserting all the keyboard drivers and so on.
‫And now we're going to build the stage and we can see that that compiles absolutely fine without any
‫issues at all.
‫Excellent.
‫OK, guys, so congratulations on completing part one.
‫This this will be broken into a few parts because obviously it's a bit of a complicated subject.
‫So hopefully you implemented part one correctly and see you for part two.
‫And I should note, before we implement part two, we need to implement some stuff for the interrupt
‫handlers by here in table.
‫We need to make more of an abstraction here before continuing on to part two of the keyboard driver,
‫because the keyboard driver kind of depends on that.
‫And it's fairly important that we we get this right first time to avoid you guys having any problems.
‫So we're going to need to first.
‫Implement some more functionality in the detoxified, and then we'll be able to go to part two of creating
‫the keyboard, OK, and then finally on part three, we will implement the caps lock.
‫OK, so thanks for watching this lecture.