﻿1
00:00:00,180 --> 00:00:01,180
‫Hello and welcome.

2
00:00:01,200 --> 00:00:08,640
‫And in this election year, we're going to further implement the keyboard, we're going to receive keyboard

3
00:00:08,640 --> 00:00:17,370
‫interests from the two keyboard driver, and we are then going to use the keyboard push function to

4
00:00:17,370 --> 00:00:21,990
‫push the keys that will press to the keyboard buffa of the running process.

5
00:00:22,210 --> 00:00:26,580
‫Once this is implemented correctly, it should be pretty simple for us to type keys on the keyboard

6
00:00:26,880 --> 00:00:33,900
‫and they will be pushed into the process as keyboard buffa ready for that process, his task to pop

7
00:00:33,900 --> 00:00:34,170
‫them.

8
00:00:34,690 --> 00:00:45,540
‫OK, so yes, let's begin go to classic stage and we're just going to go define classic keyboard key

9
00:00:45,540 --> 00:00:47,810
‫released zero eight.

10
00:00:47,820 --> 00:00:49,530
‫Now this is a bit massive, OK?

11
00:00:50,190 --> 00:00:54,030
‫The scan code also has a bit mask applied to it.

12
00:00:54,150 --> 00:00:58,590
‫So let us know certain things, such as if the key was released or not and we need to take that into

13
00:00:58,590 --> 00:00:59,100
‫account.

14
00:00:59,430 --> 00:01:05,190
‫So now we go define Finisar keyboard interrupt and that is zero twenty one.

15
00:01:05,460 --> 00:01:12,930
‫OK, back to Classic Tazi and we'll begin implementing our keyboard interop Tandler.

16
00:01:13,590 --> 00:01:19,530
‫OK, so this classic keyboard handle function will be called from our internal handler.

17
00:01:19,530 --> 00:01:26,340
‫We haven't created that yet, but let's just stop filling in this function and we'll do that a bit later.

18
00:01:26,640 --> 00:01:29,490
‫So the very first thing we need to do is switch to the kernel page.

19
00:01:29,910 --> 00:01:33,630
‫So just include kernel that at the top here, guys.

20
00:01:33,810 --> 00:01:39,890
‫OK, we're also going to want to include it, the Hajj as well, guys.

21
00:01:39,900 --> 00:01:43,350
‫OK, scroll back down.

22
00:01:43,350 --> 00:01:45,540
‫We see Colonel Page now works fine.

23
00:01:46,200 --> 00:01:47,760
‫We're going to go unit eighty.

24
00:01:48,000 --> 00:01:49,680
‫Scan code equals zero.

25
00:01:50,280 --> 00:01:59,580
‫Scan code equals Ehnes be keyboard input port and we haven't defined that yet.

26
00:01:59,580 --> 00:02:01,020
‫Will define that shortly.

27
00:02:01,290 --> 00:02:05,250
‫And we can also end up with a rogue IQ also sent to us.

28
00:02:06,030 --> 00:02:07,530
‫So we should just ignore that one.

29
00:02:07,530 --> 00:02:12,810
‫OK, so we ignore that one by just reading from the keyboard part once again.

30
00:02:14,280 --> 00:02:18,510
‫Sometimes it sends other information that we don't really care about so much.

31
00:02:18,840 --> 00:02:21,150
‫So this one reads the scan code.

32
00:02:21,150 --> 00:02:24,500
‫This one ignores the rogue byte sent to us after that.

33
00:02:25,050 --> 00:02:32,430
‫OK, go back, go back to classic Hajj and we're just going to go hashtag define keyboard input part

34
00:02:33,210 --> 00:02:34,380
‫060.

35
00:02:34,830 --> 00:02:39,050
‫OK, now these are parts we can read from on the bus, OK.

36
00:02:39,060 --> 00:02:43,770
‫And 060 is responsible for letting us know which keys were pressed.

37
00:02:43,770 --> 00:02:51,060
‫OK, now if I just go to Firefox, I can show you this a little better.

38
00:02:53,180 --> 00:02:57,700
‫So I'm just going to go across 60 parts, OK?

39
00:02:59,830 --> 00:03:02,620
‫OK, so it's this article here.

40
00:03:03,220 --> 00:03:10,410
‫We were already on it signing a search for Zywiec 16 here, so you can see the power to control itself,

41
00:03:10,410 --> 00:03:13,620
‫uses iReports CEREC 16 06, six for.

42
00:03:14,630 --> 00:03:19,920
‫OK, so that's why we're reading from zero to 60, because that's the data part.

43
00:03:20,070 --> 00:03:22,630
‫OK, that's why we're doing that.

44
00:03:23,270 --> 00:03:28,580
‫So this part is where those keys to oppressed are sent to us.

45
00:03:28,580 --> 00:03:31,830
‫And so we need to read from that part on the bus.

46
00:03:31,850 --> 00:03:34,130
‫OK, so brilliant.

47
00:03:34,130 --> 00:03:39,320
‫At this point, online 57, we have the scan code that was pressed on the keyboard.

48
00:03:39,680 --> 00:03:40,330
‫Perfect.

49
00:03:40,880 --> 00:03:43,380
‫We now to convert that to a character.

50
00:03:43,610 --> 00:03:46,670
‫Well, we made that function here a few lectures ago.

51
00:03:46,670 --> 00:03:48,170
‫Classic keyboard scan code to.

52
00:03:48,950 --> 00:03:51,920
‫OK, so the first thing we need to do is check if the key was released.

53
00:03:51,940 --> 00:04:01,180
‫So how do we do that is we say if scanned code ampersand, classic keyboard key released.

54
00:04:01,940 --> 00:04:06,460
‫OK, so if this bit is set in the scanned code, then the key was released.

55
00:04:06,470 --> 00:04:11,750
‫OK, and if the key was released, we're just going to return because we don't want to handle any key

56
00:04:11,750 --> 00:04:13,400
‫releases at this point in time.

57
00:04:13,490 --> 00:04:16,840
‫We don't care if they release the key or not.

58
00:04:16,850 --> 00:04:18,400
‫We only care if they press the key.

59
00:04:18,410 --> 00:04:21,470
‫OK, we can worry about key releases another time.

60
00:04:22,220 --> 00:04:25,100
‫But anyway, so yeah, we return if that bit is set.

61
00:04:25,100 --> 00:04:25,930
‫OK, brilliant.

62
00:04:26,260 --> 00:04:35,480
‫So now here we're going to go unit 80 C equals classic keyboard scan code to CHA and we're going to

63
00:04:35,480 --> 00:04:36,800
‫pass in the scan code here.

64
00:04:36,800 --> 00:04:42,740
‫OK, and if the C does not equal zero, then we have a character in the Bufford and if the character

65
00:04:42,740 --> 00:04:49,610
‫is not equal to zero, then we have a valid scan code that that that is being converted to an ASCII

66
00:04:49,610 --> 00:04:50,160
‫character.

67
00:04:50,180 --> 00:04:52,670
‫OK, and we can push that to the keyboard.

68
00:04:52,670 --> 00:04:57,410
‫So we go keyboard push, see, OK, like that.

69
00:04:58,130 --> 00:05:03,360
‫And that will push the character to the keyboard buffer of the current process.

70
00:05:03,830 --> 00:05:11,760
‫OK, we now need to switch back to the task page and that is it for the classic keyboard handle interrupt.

71
00:05:11,960 --> 00:05:15,020
‫So if we scroll down now, it's a classic keyboard in it.

72
00:05:16,200 --> 00:05:17,300
‫Uh, scroll up.

73
00:05:17,300 --> 00:05:27,050
‫I mean by here we now need to register the callback, so we're just going to go ADT register in callback

74
00:05:27,650 --> 00:05:33,230
‫and we're going to use the ISO keyboard and SREP, which is Xerox twenty one and we're going to have

75
00:05:33,230 --> 00:05:38,480
‫the function, the classic keyboard handle interrupts.

76
00:05:40,160 --> 00:05:46,850
‫OK, and if we scroll down to that classic keyboard handle and just copy and paste this prototype,

77
00:05:47,730 --> 00:05:51,170
‫OK, just copy and paste it above there so it can resolve it.

78
00:05:52,160 --> 00:05:56,330
‫And you can see a little spelling mistake here, but a second s here.

79
00:05:56,360 --> 00:05:57,830
‫OK, and scroll down.

80
00:06:00,300 --> 00:06:05,830
‫Because we also made the mistake with this function here, so just correct that it should say classic

81
00:06:05,830 --> 00:06:07,230
‫guys like classic.

82
00:06:09,110 --> 00:06:12,510
‫Like that, OK, classic keyboard handle interrupt.

83
00:06:14,120 --> 00:06:15,210
‫OK, perfect.

84
00:06:15,680 --> 00:06:23,630
‫So now that we have registered that intro, Tangela, we should now be able to handle keyboard key presses,

85
00:06:23,630 --> 00:06:29,990
‫OK, when we press a key on the keyboard, that should cause the interruption to be to be invoked 621,

86
00:06:30,500 --> 00:06:35,690
‫which will lead to our classic keyboard handle interop function being run, we should then be able to

87
00:06:35,690 --> 00:06:37,100
‫extract the schang code.

88
00:06:37,700 --> 00:06:43,610
‫And if the key was was not released, i.e. they pressed it, it wasn't just a release.

89
00:06:43,850 --> 00:06:45,970
‫We don't care for release events basically.

90
00:06:45,980 --> 00:06:54,350
‫OK, so if it was only press then it will convert the Chanko to a char and then push that to the buffer.

91
00:06:54,360 --> 00:06:55,510
‫Let's see if this works then.

92
00:06:55,520 --> 00:06:58,790
‫OK, so we're going to go make clean build that S.H..

93
00:07:00,480 --> 00:07:06,540
‫And we can see implicit declaration of TASC Page, that's no big deal, scroll up, we're going to need

94
00:07:06,540 --> 00:07:08,280
‫to include tests Hajj.

95
00:07:08,880 --> 00:07:11,160
‫OK, just like that.

96
00:07:12,270 --> 00:07:13,200
‫We try that now.

97
00:07:15,630 --> 00:07:20,130
‫We can see that compiles absolutely fine, and if we just run that for a second.

98
00:07:23,690 --> 00:07:31,130
‫Yeah, we can see that that is working all OK, so we're about to debug this now and check if the key

99
00:07:31,130 --> 00:07:33,290
‫press is handled correctly.

100
00:07:34,070 --> 00:07:35,670
‫But before we do that, go to Canada.

101
00:07:35,670 --> 00:07:38,550
‫Let's see, because we're going to remove that time in time.

102
00:07:38,630 --> 00:07:44,270
‫Call back we made so you can see here, we said it registered your callback 620 time, but just get

103
00:07:44,270 --> 00:07:45,830
‫rid of that, OK?

104
00:07:46,160 --> 00:07:47,480
‫And scroll up.

105
00:07:47,480 --> 00:07:50,180
‫And you will also notice I passed an interim frame here.

106
00:07:50,510 --> 00:07:52,490
‫This was an unfortunate mistake.

107
00:07:53,330 --> 00:08:01,690
‫If we go to I see that you can see that the prototype takes no arguments for callbacks, OK?

108
00:08:01,950 --> 00:08:07,580
‫Nevertheless, we passed a function with an interim frame and obviously it's not passing as an interim

109
00:08:07,580 --> 00:08:07,940
‫frame.

110
00:08:08,240 --> 00:08:11,450
‫So this is an initialized point one one.

111
00:08:11,720 --> 00:08:14,480
‫The interim calls pick a time a callback.

112
00:08:14,480 --> 00:08:17,480
‫OK, so what it should have been is that OK?

113
00:08:17,480 --> 00:08:21,860
‫Just to let you know that it's no big deal because it was just for testing purposes.

114
00:08:22,310 --> 00:08:25,600
‫But yeah, minor mistake that that's all.

115
00:08:26,180 --> 00:08:31,460
‫Just delete this function because we don't need that anymore because we've removed the the actual callback,

116
00:08:32,870 --> 00:08:36,050
‫the registration of the callback, we've removed that.

117
00:08:36,060 --> 00:08:37,330
‫So just go to that function.

118
00:08:37,690 --> 00:08:40,190
‫OK, now we have a nice blank slate to work with.

119
00:08:40,820 --> 00:08:45,320
‫Let's just build again and then we will go to GDB.

120
00:08:46,940 --> 00:08:57,200
‫So now we're just going to go CDB and GDB, add Simbo file build kind of 4.0 06 one one, two, three,

121
00:08:57,200 --> 00:08:58,010
‫four, five.

122
00:09:00,350 --> 00:09:08,060
‫And we're just going to scroll up to Classic Tazi and we're going to put a breakpoint on classic keyboard

123
00:09:08,060 --> 00:09:09,700
‫handle interrupts to just go break.

124
00:09:10,190 --> 00:09:16,640
‫Classic keyboard handle interrupt and we're going to now stop the emulator.

125
00:09:24,860 --> 00:09:31,220
‫And I would just kind see to continue and we can see here there was a little bug launch in the emulator

126
00:09:32,120 --> 00:09:33,260
‫since the program started running.

127
00:09:33,270 --> 00:09:37,820
‫So just close the emulator if that happened to you, and just run that command again.

128
00:09:38,630 --> 00:09:39,950
‫And that we are we can see that works.

129
00:09:39,950 --> 00:09:40,540
‫OK, now.

130
00:09:40,910 --> 00:09:42,920
‫So now just pressie to continue.

131
00:09:43,910 --> 00:09:48,590
‫OK, press any key whilst you're on kumu and there we go.

132
00:09:48,600 --> 00:09:56,090
‫I pressed a and you can see the classic keyboard handles interrupt routine was called if I just go next

133
00:09:56,600 --> 00:09:58,670
‫next next next.

134
00:09:59,420 --> 00:10:01,160
‫If I print the scan code here.

135
00:10:05,020 --> 00:10:11,140
‫And we can see we lost our way here, that's because in speeches, an assembly instruction and because

136
00:10:11,140 --> 00:10:17,530
‫it doesn't have line information, it's caused our emulator here debugger, I should say, to make a

137
00:10:17,530 --> 00:10:18,430
‫little mistake here.

138
00:10:18,440 --> 00:10:26,470
‫So we're going to have to go layaways and just just go step by step by step by step by step by until

139
00:10:26,470 --> 00:10:27,940
‫we're back and now we're back.

140
00:10:27,940 --> 00:10:32,790
‫We can go layo prev like that, which will take us back to the CAVU.

141
00:10:33,490 --> 00:10:38,590
‫OK, so we're going to go next and we scan code now we can see that's 30.

142
00:10:39,100 --> 00:10:41,730
‫OK, because I pressed a it might be something different for you.

143
00:10:41,740 --> 00:10:53,140
‫OK, now I'm going to go break source keyboard classic dot c line sixty nine.

144
00:10:54,250 --> 00:10:55,060
‫I see.

145
00:10:56,420 --> 00:11:00,590
‫And I go next, I have to go princi and what do we see, we see a.

146
00:11:01,330 --> 00:11:07,670
‫So the colonel completely knows that I pressed the character a so well done.

147
00:11:07,690 --> 00:11:13,810
‫You've now actually created your very first keyboard driver and we can see if we go next.

148
00:11:14,920 --> 00:11:19,260
‫That pushes the character was press to our processes keyboard.

149
00:11:19,630 --> 00:11:27,130
‫So we step into that next, next, next we can see the processes there.

150
00:11:28,090 --> 00:11:31,120
‫OK, perfect.

151
00:11:31,730 --> 00:11:41,650
‫And if we now go next, next we can see that the keyboard buffer now contains a do print process.

152
00:11:41,650 --> 00:11:48,250
‫We can see two ways because we printed one in kernel that C which I forgot to remove a good candidate

153
00:11:48,250 --> 00:11:51,280
‫c c the key will push the example.

154
00:11:51,280 --> 00:11:52,260
‫We did get rid of it.

155
00:11:52,840 --> 00:12:00,230
‫OK, we don't want that because that's pushing characters that were never pressed to the keyboard before.

156
00:12:00,400 --> 00:12:01,690
‫Emulating a key press.

157
00:12:01,690 --> 00:12:02,920
‫I suppose so.

158
00:12:02,920 --> 00:12:03,070
‫Yeah.

159
00:12:03,070 --> 00:12:05,020
‫We can see the buffer contains two ways.

160
00:12:05,290 --> 00:12:10,630
‫Well because the kernel that c we push there and also because they pressed A on the keyboard.

161
00:12:11,170 --> 00:12:12,640
‫So that's really, really good guys.

162
00:12:12,640 --> 00:12:13,210
‫Well done.

163
00:12:13,210 --> 00:12:19,020
‫And if we now go C to continue again, go back to commute press, any other key will go for Z.

164
00:12:19,030 --> 00:12:21,760
‫I'm going to go for Z and I'll press C to continue.

165
00:12:22,180 --> 00:12:26,410
‫I'm going to go next princi and what we see there Z was press.

166
00:12:26,800 --> 00:12:28,390
‫OK, so congratulations.

167
00:12:28,390 --> 00:12:30,430
‫You've just implemented the keyboard.

168
00:12:31,210 --> 00:12:35,320
‫Now how do we get the user process to interact with the keyboard.

169
00:12:35,980 --> 00:12:37,660
‫OK, well this is fairly simple.

170
00:12:37,660 --> 00:12:38,110
‫All right.

171
00:12:38,830 --> 00:12:42,310
‫We create a kernel command for popping from the keyboard, OK?

172
00:12:42,850 --> 00:12:48,820
‫And then in a user program we'll have a while loop where it's constantly popping from the keyboard.

173
00:12:49,120 --> 00:12:51,580
‫And if it's not zero, then a key was pressed.

174
00:12:51,940 --> 00:12:55,150
‫If a key was pressed, it can output it to the terminal for us.

175
00:12:55,870 --> 00:13:02,890
‫So in the next few lectures, we'll be creating the ability to push to push characters to the terminal

176
00:13:02,890 --> 00:13:07,780
‫and also popping from the keyboard, OK, which will allow people to enter text.

177
00:13:08,530 --> 00:13:10,450
‫So thanks so much for watching this lecture.

178
00:13:10,450 --> 00:13:13,180
‫You now have the keyboard drive implemented.

179
00:13:14,050 --> 00:13:17,140
‫Granted, it doesn't support caps lock or anything like that.

180
00:13:17,380 --> 00:13:19,480
‫Everything you type will be in uppercase.

181
00:13:20,320 --> 00:13:26,500
‫We can worry about implementing case sensitivity later on and listening to the caps lock and so on.

182
00:13:27,160 --> 00:13:28,870
‫These things can come later.

183
00:13:29,080 --> 00:13:32,410
‫Let's just get it so you can actually type something on the terminal first.

184
00:13:32,710 --> 00:13:34,030
‫So thanks so much for watching.

