So how does a PS/2 keyboard interface work?
Vložit
- čas přidán 4. 09. 2024
- Check out eater.net for more computer engineering stuff!
List of scancodes from the video: docs.google.co...
Support these videos on Patreon: / beneater or eater.net/support for other ways to support.
------------------
Social media:
Website: www.eater.net
Twitter: / ben_eater
Patreon: / beneater
Reddit: / beneater
Special thanks to these supporters for making this video possible:
Aleksey Smolenchuk, Alexander Wendland, Andrew C. Young, Anson VanDoren, Anthanasius, Armin Brauns, Ben Cochran, Ben Dyson, Ben Kamens, Ben Williams, Bill Cooksey, Binh Tran, Bouke Groenescheij, Bradley Pirtle, Bradley Stach, Brent Reusing, Brian T Hoover, Bryan Brickman, Bryan Glezerson, CaffeinatedClockmaker, Carlos Ambrozak, Christopher Blackmon, Dale Andrew Darling, Daniel Jeppsson, Daniel Tang, Dave Burley, Dave Walter, David Brown, David Clark, David Cox, David House, David Sastre Medina, David Turner, David Worsham, Dean Winger, Dissy, dko, Dmitry Guyvoronsky, dstensnes, Dušan Dželebdžić, Dzevad Trumic, Emilio Mendoza, Eric Busalacchi, Eric Dynowski, Erik Broeders, Eugene Bulkin, George Foot, George Miroshnykov, Harry McDow, Ingo Eble, Ivan Sorokin, james schaefer, Jared Dziedzic, Jason DeStefano, Jason Specland, JavaXP, Jay Binks, Jayne Gabriele, Jeffery Springs, Jeremy A., Jim Kelly, Jim Knowler, Jim Van Meggelen, Joe Beda, Joe OConnor, Joe Pregracke, Joel Jakobsson, Joel Miller, John Fenwick, John Meade, Jon Dugan, Joseph Portaro, Joshua King, Kai Wells, Kefen, Kenneth Christensen, Kent Collins, Koreo, Lambda GPU Workstations, Larry, László Bácsi, Lukasz Pacholik, Marcus Classon, Martin Roth, Mats Fredriksson, Matt Krueger, Matthäus Pawelczyk, melvin2001, Michael Garland, Michael Tedder, Michael Timbrook, Michael Weitman, Miguel Ríos, mikebad, Mikel Lindsaar, Miles Macchiaroli, moi n, Nicholas Counts, Nicholas Moresco, Nick, Örn Arnarson, Paul Pluzhnikov, Paul Randal, Pete Dietl, Phil Dennis, Philip Hofstetter, Phillip Glau, PixelSergey, ProgrammerDor, Randal Masutani, Randy True, Raoul van Prooijen, Renaldas Zioma, Ric King, Rob Bruno, Robert Comyn, Robert Diaz, Roland Bobek, sam raza, Sergey Kruk, SonOfSofaman, Stefan Nesinger, Stefanus Du Toit, Stephen, Stephen Riley, Stephen Smithstone, Steve Jones, Tayler Porter, TheWebMachine, Tom, Tyler Latham, Vincent Bernat, Vladimir Solomatin, Walter Montalvo, Warren Miller, xisente, Yee Lam Wan, דויד אללוף
The reason the Pause/Break key has such a weird scan code is because old 84-key keyboards didn't have that key and used Ctrl+Num Lock for Pause/Break. If you look at the scancode it's actually a make sequence for control and num lock, followed by a break sequence for both-so it acts like you quickly presesed and released control+num lock even if you hold it down.
That's really cool!
Does that mean that, for keyboards/laptops that do not have a pause/break key (nowadays), that they can use Ctrl+Num Lock for that same function? For Windows OS's, in my job, I frequently give people the hotkey of Win Key + Pause/Break key to give me the info I need, and sometimes I hear that they don't have a Pause/Break key. In those situations, would Win Key + Ctrl + Num Lock work?
@@Mike.Kachar I think if a keyboard is cut down enough to not have a pause/break key, it probably doesn't have a number pad either
@@owenvogelgesang7314 My laptop actually has most of numpad and no pause/break. I don't think the Num Lock is a normal num lock though, I think it switches the keys in hardware, because the numpad doesn't have any nav keys on it. BUT, I'm sure somewhere out there these is a keyboard with a numpad but no pause/break, especially if you consider the world of custom mechanical keyboards, although that's a whole other can of worms....
Same thing for Print Screen, on old keyboards you would press shift-numpad *, and other then the extended code (probably because to indicate it's a multibyte code) it's still that.
"I've got about 8 of 'em here, at least as far as you know" LOL
i counted a sliver of one off screen
he used ctrl+c and ctrl+v ... how many scan codes?
@@waldolemmer gotta be at least 12?
This killed me too.
That made me laugh,
"I've got about eight of them here; at least as far as you know..." Should we send someone to check on you?
i counted a sliver of one offscreen
😂
Choked on my coffee when he said that.
The serial output of the bottom-most visible board didn't have any wires headed further down, so 8 was how many he had...
@@nickvoncloft4566 It's breadboards all the way down.
To anyone reading...
Ben's website under credentials says "I went to school for computer science, but failed out after the first year and have no degree"
Why I bring this to attention is because with such a deep understanding, I assumed this guy had several PhDs. The fact that one of these videos is more informative than some of the most rigorous 4 year programs is a true testament to self education. This is the golden corner of CZcams, please never stop.
seems like those who value knowledge dont value degrees nearly as much, dont they
That's because computer science degrees don't teach digital logic. Not like this, anyway. Modern computer science is all about high level languages, because they want you as divorced from the metal as they can get. I actually had 2 semesters of digital logic, and we hand built everything on breadboards, just like Ben does. But i was not in computer science, i was in electronics, which is different. Because digital logic is a very useful tool when you are building electronic devices, you often end up with "digilog" circuitry, where you have some analog and some digital working together to accomplish a function.
@@dandan7884 It really, really depends. Undergraduate work is stuff you can usually teach yourself to greater or lesser effect. Graduate work is more about synthesizing ideas and research while doctoral level work tends to be almost pure theory. I am wildly over-simplifying. I would argue that this level of deep dive is easily graduate level presentation. The second he makes his own die, you send someone to check on him and I'll see if we can find him an honorary doctorate. ;)
That being said, yes, a degree is not an education, but if you try hard enough, you can become educated while earning a degree.
@@dandan7884 I got a degree just for social contract with my family. So they would stop bothering me. I was already well into the profession since 14yo.
Entirely self-learned.
Also me: I wonder if one day I could design my own CMOS chip, that's why I went to Uni, not to get the basics.
Well, think:
Thomas Edison was expelled from the second grade.
Albert Einstein was considered dumb in high school.
Micheal Faraday never went to school and was illiterate.
Winston Churchill failed English and Latin class in high school.
Self-education is more effective than most education systems out there.
Everybody gangsta' until he slides in 8 identical copies of the shift register. (At least as far as we know)
And I though cook shows were crazy with their tricks of pulling 2 of the thing already made from under the table.
This guy turns a KEYBOARD PROTOCOL into binge-worthy content. That’s one of those things about 2021 that I didn’t see coming.
After watching his VGA interface video, I could watch this man cobble together *any* IO protocol, in discrete logic circuits, all day. And I’d be captivated the whole time.
Well put !
Wish I understood. I don't even know what ground and shield mean.
@@LeoStaley In a real computer the shield is connected to the mains ground which is the same protective ground that is in the chassis of the computer. The ground is the 0 VDC on the +5 VDC voltage supply.
Morgan Freeman narrating the epilogue of this series: "...and as far we know, Ben is still out there, happily building scancode decoders 'til this day...".
When he said, "...for all you know," I imagined a five foot mound of breadboards behind him.
samuel l jackson would make it better by throwing in cursewords
Yes changes, UTC +9 hours all of the period
He had 256 breadboards, wired together to make a word processor. The next episode is going to be a doozy!
@@khatharrmalkavian3306 Slices of breadboards?
Something to clarify: The two pins Ben said were unused only applies to keyboards. Mice use them and leave the ones used by a keyboard unused. If you've got a PS/2 keyboard with a trackball in it that still only uses one plug, the trackball will be using those pins while the main keyboard uses the other two.
Ah, that explains how some systems have a single ps/2 port and you can use an adaptor to hook both keyboard and mouse in.
Thanks! I was reading the comments hoping to learn what the other 2 pins are for. (And also the reason for the strange bit-mapping of the keys.)
That also explains how "dual personality" PS/2 ports on modern mainboards (probably) work. The board/chipset/cpu knows if a keyboard or mouse is plugged in by which data/clock pin is used.
so now ben needs to build a mouse interface
@@solhsa And it explains why they moved from the 5-pin connector to the 6-pin connector.
"8 of them as far you know" LMAO. This and the zooming out on the data the HOME key was sending was so funny to me. It's like watching the old commercials "But wait there's more!"
call now and get another 11 bits absolutely free, plus shipping and handling
Or those cooking shows where the host/chef says "Here's one i made earlier"
"If you release the key *now* , you'll get an "F-Zero" byte *along with* your regular scancode!
And if you use an extended key, you'll get *three* bytes when you let go!"
"But wait, there's *yet more* ! I haven't started talking about PrintScreen and Pause/Break! Get yout uber-load of bytes RIGHT NOW!"
22:20
Man, this really hits home
this is the greatest dad joke ever
Scan codes are based on a matrix of vertical and horizontal lines, at least for the main section of the keyboard.
That is why key "1" and "2" start with Hex1 (same matrix vertical), and similar for "3","4","5" starting with Hex2 and "6","7","8" starting with Hex3, ... they belong to the same keyboard matrix vertical scan line. The right Hex digit is the horizontal matrix scan line.
The other special keys, like: "F"unction , Insert, Home, PageUp, Delete, End, PageUp, System/PrintScreen, Scroll Lock, Break/Pause, ... depend on how they were mapped on the Matrix of the first keyboard that added them.
For example, F1 to F6, where originally listed vertically on the left side of the keyboard, hence all their codes start with Hex0.
The IBM standard evolved with each successive keyboard, with new keys, that were usually mapped to the closest vertical and horizontal lines of the scan matrix. Basically to make it as simple as possible to route the matrix circuit onto the keyboard PCB, since any pattern can be easily handled by the software layer.
Yes. The first keyboard to use those codes didn't send a byte, it sent two nibbles for the row and column. But when the first PC came around, they already needed a microcontroller to map row/col onto those backwards compatible scancodes. And so they started a tradition that still lives on today...
I remember reading that the original K/B interface had the driver program in the CPU send the column number to the keyboard, and the keyboard would send back a byte containing a 1 bit for each key in that column that was pressed. The driver had to maintain a map of which keys were pressed by rotating through the columns and saving the bits many times per second, and detecting when one or more changed from its previous value. Needless to say, the second time around was much more efficient.
"5v is black"
Okay, now what? Next you're gonna tell me data is red?
"data is red"
oh no.
Your channel is worth more than gold. This stuff you are making is timeless.
I totally agree with your statement. Ben's way of teaching is, in my opinion, the best way for me to learn. I love every single video this man makes because he presents his massive knowledge one step at a time, sequentially explained, so even slow people, like myself, can follow his thinking, as he progresses, and actually Understand his thinking. A master teacher, Ben is. Fred
somehow this stuff is gonna save a space mission someday because finally this info is being passed cross generations properly. This is an amazingly clear presentation. Thank you.
@@red_ford23 Welcome to interplanetary mechanic school, this is your holographic AI driven teacher Ben Eater recorded from the year 2021.
@@electronicengineer
I made 4 bit RAM ckt using only D FLIP FLOPS And Basic gates:czcams.com/video/q7bZs2Nhi4Ez/video.html
@@To-mos
I made 4 bit RAM ckt using only D FLIP FLOPS And Basic gates:czcams.com/video/q7bZs2Nhi4Ez/video.html
My breadboards look like rotten spaghetti, while yours look like works of art.
I usually take a twist tie or spare piece of single-core wire, and tie the buses together. If possible, I'll also colour code them, such as green being data, blue being address, etc, but I don't use pre-formed jumpers except for power/ground, otherwise you keep needing to cut and form them, which slows things down.
You should play Factorio and make 10 rockets per launch using belts only that will teach you how to route anything. LOL.
@@jozefbania To be fair though. If i remember correctly he has pre bent cables
@@foty8679 pre-bent by himself :)
Well, it could be worse. I just bought a house and decided to take a look at how the central heating boiler is wired to the thermostats. I mean, the boiler only has two wires as input. Short them, and it turns on. How bad could it be?
Turns out it look like a bowl of spaghetti, with a bunch of unterminated brown wires sticking out. And if there is one thing I remember from that introductory course to home wiring in high school: "brown is the color your pants will be when you touch it".
I promptly closed the box, and checked the batteries on the smoke alarm. I guess I'll figure this out in summer... Note to self, also buy a new CO alarm. That thing expired 3 years ago.
“Black is 5v, figures” lololol love these videos. I need to quit everything and just do these videos all day
Quite Informitive!
In automotive wiring, black is usually 12v, and white is ground.
@@BlackEpyon and all my life my instinct tells me every black is ground and red is postive V
@@omniyambot9876 IKR? That's where you get in trouble. And then in the US/Canada, mains AC, black is hot, and white is neutral, and you could potentially have a VERY bad time if you get those mixed up.
@@BlackEpyon yeah man that's why I try not to touch high power lines until I'm very very sure what is going on
Ben busted out that ready-made second shift register breadboard like a Food Network chef
Exactly! 😂
I'm a little disappointed he didn't use the phrase "here's one I prepared earlier".
It's 2030 and Ben is building a Quantum computer on breadboard.
I'd very much like to see that happen! Such advancements in quantum computing over the next decade that it can be done on regular copper, aluminum, and steel components!
Great video, man, it took me right back to my early hacker days : )
We used to swap out PS/2 keyboards in target sites, with a modified one that could install malware and act as a bidirectional radio link to the attacker. Nobody ever suspected that the keyboard was an attack (and communication) vector.
Call centres were one of our favourite targets as they had access to the targets customer systems and the high turnover of call staff made employee positioning ridiculously easy.
Basically, you'd put your foot on the keyboard cable and make a visible show of trying to pull the keyboard forwards to a comfortable position at the front of the desk. Of course, because you're resting a foot on the cable, the cable would appear too short. Then, you'd look under the desk and sigh ... disconnect the keyboard and pass it under the desk (as though trying to free the cabling) ... once under the desk we'd quickly swap the keyboard with one in our bag... and then bring it back up. Done correctly it's a fast and smooth way to switch keyboards undetected.
Now, there were a few things that most people don't consider...
1. Like the video said, a keyboard isn't an input device - it's a bidirectional input/output device
2. The keyboard can act as external media - installing malware and communicating with it once installed
3. A modified keyboard can act as a simple RF node, bypassing network security and backdooring standalones
4. Keyboards are (or, rather, were) never investigated or suspected to be vectors for persistent malware.
We used a slow, low power PIC chip between the keyboard IC and the PS/2, powered from the PS/2 line itself.
Malware once installed on the PC could send a sequence to the KB to let it know that the malware was available... but, if the KB didn't get the sequence after a few minutes, it would wait till a suitable moment _(a timeout after last keystroke)_ and then buffer any new keystrokes temporarily - whilst installing the malware!
The malware installation was easy. Rapidly injected keystrokes opened the console via hotkey, dropped to black foreground and used the 'debug' command, to create and execute a tiny .com program in memory (the chain-loader) as hex. This tiny chain-loader program would then stream the real malware image from the keyboard using a faster more efficient method (binary data) that didn't echo into the console window. The malware would then execute via debug, closing the console and installing into the filesystem. After the KB has sent the last byte of the malware to the chain-loader it would then release any keystrokes in the buffer as normal and return to regular working.
The user just saw a brief console window flash, if they were paying attention. This would never be seen again, as once the malware was installed, the periodic PS/2 'malware available' sequence kept the keyboard happy.
We also experimented with a system that would identify logins (by comparing first keystrokes after boot) ... then wait till it had been on more than 12 hours AND more than 4 hours since last keypress. It would then assume that the machine had been left on overnight, and would log-in using the stolen credentials and install : ) Our agent could then swap keyboards with another machine they didn't have credentials for... under the guise of "stealing a nicer keyboard" ... in call centres nobody cares... they find it funny if you steal the managers keyboard. Scavenging nicer headsets, ear foam, voice tubes, mice and keyboards is quite common in call centre environments ; )
The malware was pretty sweet, and could be updated wirelessly.
The malware on the PC communicated with the PS/2 keyboard, which stored user passwords, web passwords, and other data - and released it via short range wireless on the hour every hour. Every hour the RF module would listen for 10 seconds for a short binary "hello" sequence before going back to sleep. If it heard a "hello sequence" it would stream out all of its saved data. It would then listen for another 10 seconds before going to sleep again. A similar "thanks" sequence would cause the CPU to clear any stored data (successful transmission)
You can do the same today in USB keyboards, using an ISM, GSM or WiFi module and any microcontroller with an integrated USB receiver (or emulator) ... a couple of IO pins and some onboard (or i2c) SRAM. These days they can also act as an AP with hidden SSID as the chips are cheap and low power... or, employ mobile data, a SIM and a 3G/4G module. The latter is particularly nice as it allows an attacker to remotely use the PC as a remote node into the LAN (for further penetrations) without having to negotiate the perimeter security.
In the old days, fetching data off the poisoned device was as simple as walking past it at the appropriate time, with a similarly modified device set to capture information over RF. We used to use a modified walkman or portable radio in our pocket - as, again, these were never suspected as being malevolent.
Back in the day, we didn't have the ISM band, GSM modules or cheap digital RF modules with good shaping... we used very simple bead-like devices that were carrier only, and we used checksums to validate message reception : ) These days it's a LOT more dangerous to allow a modded KB into an organisation.
Yep, PS2 keyboards really bring back some great memories of misspent youth : )
Thanks for taking the time to make this video. Tinkering is it's own reward.
Bad ass.
Very enjoyable reads, every line of it. In fact I read it twice man! Purely scifi, espionage stuffs... 😂😂😂
I did some research on the scancode origin when self-building a keyboard. I was not able to find anything authoritative, so the best guess I have for its strange pattern is the ye olde connection matrix they chose originally for the buttons. In other words, in the old days they connected the buttons with a reasonable (cheap to produce) row/col network, then the internal chip scans the rows and gets which column is connected to identify which key is pressed. So what you might get in the original, basic set, is simply the encoded row/column position of the button _according_ to the wiring matrix (not the visual layout). But I might be wrong.
I think you're on to it. We tore an old Hazeltine 1500 'dumb' terminal apart and found the 'scan' chip that interfaced the row/col switch matrix to ASCII. Sent the ASCII to RS-232 interface and that was about all there was on the 'output' side of the terminal. Of course the 'input' side to the screen was more complicated. :)
I would be extraordinarily unsurprised by this. Today we can just throw an arduino (or even a full raspberry pi!) into a keyboard and do a bunch of processing in the keeb itself, but back in the day you probly had to build all the functionality out of nand/nor gates, I dunno, maybe as many as four gates per IC 0.o
Yeah I was thinking along the same lines as I watched the video, so that does seem quite likely.
@@okuno54 As far as I know, when IBM introduced the original PC Model 5150, the keyboard had an Intel 8048 microcontroller built in, and all subsequent keyboards have had either that chip, a clone, or some modern derivative, for backwards compatibility.
Yes break code!
You know he is professional when he strip wires with finger nails
I used to use my teeth when I was a kid.
@@BlackEpyon I use teeth now too
Never seen that before
@@BlackEpyon Can't use my teeth anymore for that. It feels weird. Metal on teeth is awful.
@@nagasaipurvaz4251 Your own?
Two shift registers on a single board?
Don't worry, I have another similar board.
Wait, there's three actually!
So, how many boards does Ben have? All of them.
it's boards all the way down! (not elephants!)
It's almost AVGN 64-32-16-8-4-2-1-½-¼-bit meme material.
i'm fairly convinced he has a replicator.
I cannot state enough,the fact that your channel is one of the few channels concerning computer science/engineering that is WHOLLY bingable.
Every video makes you ask for more,bravo!
He’s alive!
I'm pretty sure these videos take a long time to make.
I was worried he’d Ben Eaten!
He's been making an army of these modules lol
11:45 omg he just fixed a timing problem by effectively adding a redstone repeater
Yup. Not exactly (then again, you said "effectively" so you know it yourself), but you're right. If you know the redstone trick with making a redstone clock without using repeaters (just redstone torches and redstone dust and any block), it's basically two of these things together.
That type of redstone clock is basically several NOT-gates in series, the delay happening because of minecraft ticks. So what he did is put two NOT-gates in series.
But yeah, you're pretty much right overall. That's more or less what he did.
The original repeaters (before repeaters existed) was just a couple of NOT gates (redstone torches)
The repeater's recipe reflects this too :P
@@thizthizzydizzy That's like a little easter egg. That's cool.
Dog
when he said that wanted some delay i thought 'just connect to 2 inverters" not clearly with minecraft in mind but now i realize that minecraft may have influenced me to think that way
The scan codes make a lot more sense if you arrange them on an IBM Model F keyboard, which is probably where they originated. It looks like the scan codes come from each key's position on the Model F keyboard matrix, with the low 3 bits representing the key's row from bottom to top, and the high 5 bits representing the column. This doesn't exactly correspond to each key's physical row and column but each column in the keyboard matrix instead corresponds to a cluster of keys on the keyboard. For example F4, F6, F8, F10, Tab, and Alt are assigned to column 1 of the keyboard matrix and are all physically adjacent to each other on the keyboard. F9 is the bottom-left key so it makes sense that it's assigned code 0x01.
There are a couple of oddities that stand out. F7 must surely have originally been assigned code 0x02 but has changed to 0x83 for some reason. Backtick appears to be in a cluster with Alt and Tab but was at the other end of the keyboard on the Model F. Perhaps it has been reassigned a spare code to correspond to its modern physical location. Some other weird codes such as F11 are easily explained as keys that didn't exist on the Model F and have simply been assigned spare codes. Similarly the keys with extended codes didn't exist on Model F either.
Watching you cut the cable at one end instead of in the middle thereby having the DIN pigtail for later triggered my OCD.
Yes same !
Some of my favourite comedians have an odd parody bit.
Ouch.
Great video. So basically, the PS/2 keyboard uses a UART protocol, but with an extra clock signal (USART). Maybe you could use a 8250 or 16550 UART chip to interface the keyboard to the 6502 computer, if you can find a matching baud rate. The 16550 even has a FIFO buffer for storing up to 16 bytes coming from the keyboard. The chip could be connected to the shared address and data busses you already have in the computer. An interrupt could be generated each time a new byte arrives. Also, it would be great to add serial communication capabilities to the 6502 computer.
Games used to have issues with cursor keys filling up the buffer, because they sent more data. So if you played against a friend on the same keyboard, give them the cursors.
I'd totally forgotten about that. I often used to try and fill the keyboard buffer before the machine posted. :)
@@Spedley_2142 those beeps
@@ELYESSS Oh, that's what that was
I always wondered why mashing the keyboard on startup made the computer beep
These DOS multi-user games were fun, especially the ones that let you customize the controls. I once watched two friends, one used the insert, delete, home etc. and the other used the very left side with Alt and Ctrl. Guess what happened. :-)
@@nothingTVatYT Haha! Yes. Buffer overflow.
CZcams finally decided it is time for me to find your channel, Ben. Amazing work!
You making my childhold dreams come true, next thing I wonder how mouse is working with same interface, waiting so much for future videos like this
exactly !!!
*childhood
SP/2 mice use the unused pins, pins 2 and 6 in the diagram he used. This is how you can have both keyboards and mice on the same input.
Is there an award for break board wiring neatness? Because if there is, it DEFINITELY goes to Ben.
Ben, I just wanted to thank you for all the work you do in these videos. They really helped me find my passion for computer engineering.
Brilliant. The story got even more interesting as it went on. 10/10 for effort!
What if you didn't invert the latch clock and just fed it a falling edge clock, so that when it rises it would trigger the latch?
That's what I was thinking too. This is probably latching faster though, so you can use the falling edge clock to do some other processing of the latched data.
I always look the comments before writing what I think and most of the time one other guy already wrote exactly what I think. How is that possible? By the way, this time there are two.
Or just use the clock from before the inverter
@@pv2b Exactly what I was thinking while watching, you get a delay of half a clock cycle and it ends on a rising edge so the data is going to be latched by the end
@@burakyildiz8921 It's the power of collective thinking. ;)
this man puts so much effort in his projects, it's bone chillingly good.
5V Black, Orange Ground, Red Data, totally obvious color choices :'D
Red, orange and brown - or as we colour-blind folks say, brown, brown and brown.
Same with my 3D printer that's a chinese original. Guess now we know where this cable comes from.
"China's been treating us very unfair!" (D.J.T.) Like he ever knew the meaning of a cable color... LMAO
@@diydad7704 in cheap products they use colors which are availabel, got an cat5 cabel once with 3 green/white pairs :D
@@lexus4tw were they connected properly???
I'm guessing that adapter was made from spare ribbon cable, and that's why Ben happened to have cables of the same color, because they are all next to each other on rainbow colored ribbon cables. Whatever factory that made that adapter probably assumed that no one would ever need to open it, so no need to have standardized colors, so they just the next four wires.
Me, a nail biter, seeing someone strip wires by hand:
Pure sorcery.
I can't even imagine how much work this video must've taken. The research, the testing, the scripting, the setup, the filming, the editing. many hours I'm sure. But it was worth it, such an interesting video
I would actually really be interested in seeing you build a circuit that puts the letters to asci, singles out the F-keys and maybe cause interrupts, and singles out the other special keys. Maybe if ctrl or alt is pressed that a key does not go to the letters register but to the commands register. Things like that would be really cool to see.
One way of converting the 16 bit output to ascii is to use a 16 address line eprom, the output from the shift registers are connected to the address lines of the eprom, ascii comes out of the data lines. This converts the scan code “address” into an equivalent byte. It’s wasteful on space as most of the eprom is blank. This was how northgate (if anyone is old enough to remember their excellent keyboards) handled multi language keyboards. They used a larger eprom where the upper 4 address lines are linked to a dip switch that sets the appropriate language. A key cap puller was supplied to swap round the key cap.
The scan codes are a direct result of the key matrix rows/columns. Some manufacturers use different matrix layouts and then added a converter to produce compatible scan codes.
Mindblowing Explanation man
You Nailed it
30:35 Actually, it is not that crazy "to have LEDs everywhere" because at the times these CPUs and other chips came to the market first, there weren't fancy oscilloscopes available which could "one-shot a signal" and then "show it to you indefinitely" so when you wanted to debug some hardware, you needed to create visible "debug outputs" and you use LEDs for that. The red LEDs are actually pretty old and I remember having a LED based calculator when I was 8 (in 1981) so yes, LEDs are common "hardware debugger", even today. It takes just 1 resistor to hook one to a TTL output to be able to see what is in there and once you are no longer interested in what is there, you can just pull the two components out and be done.
There are many HW enthusiasts who "like the lights". And, also when you watch old sci-fi movies, you will see these "flashing light panels" in their spaceships and other system. That is actually based on real-world use of LEDs in that era - these debugging lights for signals that changed not that often (e.g. machine inputs in some manufacturing process) were left there permanently and rearranged into a matrix so that when something went wrong (a cable fell off, a chip burned out, a rat came in and ate a cable or two), the personnel operating the device could look at the panel and immediately see (from the changes of the patterns on it) that something went wrong and where. These also can serve as some sort of "poor man's status display" where the computer needs to just emit a single bit of data to tell that something is happening or "all is well" versus "something went wrong" (disk activity LEDs anyone?).
Thanks for this info. I was working on a old 8/16 computer and trying to build something to give me a monitor out and input for a keyboard. I managed to get a RGB TTL out and now a PS/2 keyboard to work thanks to your videos. I was about to give up. I work at a recycling place and we get in all kinds of 74 series logic. as well as old computers. now that I have this stuff at my disposal, I started building computers from the ground up. and with the help of your videos and others, things are getting better. I think everyone that is getting into computing and design should look into the older ways of doing things first. then they can improve and create things with a better knowledge and understanding on how things work. Maybe one day someone will redo the way computes work making them faster and better. If I decide to start a CZcams channel . it will be all thanks to you and the amazing people that I have talked with.
27:10 "I've got 8, as far as you know..." that's a golden moment. Love this channel.
(Looks at my breadboard) It may have been assembled by bird preparing for spring.
Hint: There are scan codes for POWER, SLEEP, and WAKE. If you send those scan codes through a PS/2 interface on any modern PC (that still has PS/2 interfaces), you can make it instantly interrupt power or go to sleep. When I say instantly, I mean ungracefully turn off without question or delay.
Some recent enterprise motherboards with ps/2 interface do not comply with those scancodes, they simply do not react!
I had a keyboard with a Power button in place of the Print Screen key. I had to remove it and cover the slot with tape.
it acts like 98 power button, which is controlled by BIOS (UEFI in modern scenario)
I can't believe I didn't know how to convert 8-bit hex to binary by splitting it into two 4-bit chunks. That's so simple!
It's why hex became so popular actually! If you read up on older computers, you'll find that octal was also quite popular for a while, because 9-, 12-, 24-, and 36-bit machines were fairly common (all of which have word sizes that break apart easily into three bits). Now that industry has standardized on 8-bit bytes, it's a little strange to see every programming language that support octal number literal, but they're there as legacy.
@@okuno54 partially because of posix permission bits, which you might still consider legacy 😋
But honestly it's so easy and safe to add them if you already have other base number forms you basically need a reason not to.
Youngsters ;-)
that's what we call "tetrady" (tetrads?) in Russian, from the word "tetra"-four (in greek)
upd: yeah, you can call that a nibble, but who really uses nibbles in 21st century
When my brain isn't working, I like to use the little calculator built into Windows for it's "programming" mode.
When this computer is completed, it's going to be the size of a refrigerator. We have indeed come full-circle.
Nah, his next project will probably involve vacuum tubes and hand woven core memory. And it will fill up his garage.
@@villesyrjala3354 Great, now I expect his I/O to be punch cards.
Check out my new computer, it's literally a room full of people computing.
When he talked about adding a delay, I tought about Minecraft's redstone repeater and then the solution was exact what one could do in Minecraft withou a repeater: invert the signal twice
Redstone engineering is entirely legit.
You could probably just pump the scan codes into an eeprom, and have it output ASCII (or some control codes), and maybe check for E0/F0 in hardware if you needed them
The 6522 has an integrated shift register with automatic IRQ dispatching!
So my solution would be to have some logic to only shift in those 8 data bits into the VIA chip and write a small routine reads from the Shift Register.
Additionally you can have use a bit on port B to indicate the status if the key was valid.
Some 8-bit 6502 based computers used a 6522 for the keyboard. I know for a fact that BBC Micro series of computers used one and I should imagine others did as well.
bump
@@MultiMidden Yeah, but there the 6522 interfaced the keyboard matrix directly (through porta and portb), not throug a serial interface.
@@canaDavid1 The 6526 if the C64 also did the same, a 8x8 matrix for keyboard using PA and PB
You’ve explained the “is my PC locked up?” test of toggling the CapsLock key! If the PC cannot “talk” to the keyboard to turn on/off the CapsLock light, it’s locked up. Thanks!
Fundamentally knowing & understanding those fundamentals !
You could perhaps use a RS-232 to TTL convertor and connect an old computer terminal like the DEC VT100 to the breadboard computer. Then you'll need no keyboard interface and no video card and you'll see why terminals used to be so popular when these ICs were still expensive.
Correct, and that is why I still have mine - the wife always complains about lugging the DEC VT320 with us when we’ve moved house. I’m never parting with it. Plus the orange text is beautiful.
I just repaired my old AT Keyboard (DIN plug, electrically the same protocol) last week and I'm now using it again after 15 years. Thanks to this excellent demonstration and explanation I now think I understand a bit better what it's doing :-)
I had a feeling throughout the video that something will explode, after watching ElectroBoom for 2 hours.
Hats off to you, Sir. The way you arranged everything on the breadboard without any clumsiness. Awesome
“please add another one...please add another one”
>25:52
“YES!”
>video continues
“YOOOOOOO”
Wow, my first visit and I'm "SUBSCRIBED". I'm pretty sure I just followed all of that and it's deffo not down to my ability...amazingly well presented!
This guy is truly amazing
I hope one day he could explain sophesticated subjects such as DMA
I cannot speak for Ben, of course, but i do suspect that he will make a video about it in due course.
32:33 yup, dedicated hardware to read and hold state for the keyboard!
Great video on interfacing!
When you think he reached a top with the VGA graphics card he comes up with this. Just magnificent.
WoW you just taught us how to reverse engineer, fundamentally any signal from any device. I always had the same intuition but never tested my theory. Thanks for the amazing video.
28:55 On the keyboard of the original IBM PC (IBM 5150) the scan codes were straightforwardly assigned based on each key's physical location (what they now call "set 1"): Starting from the top of the main keyboard area (ESC key, 01), left-to-right and top-to-bottom; then the original function keys F1-F10; then the numeric keypad area. Extended scan codes were eventually added for newer keys like F11-F12, multimedia keys, etc. However modern keyboards use a different "set 2" by default (I believed introduced with the IBM AT Keyboard) which is what you describe in the video. I have no idea why the chaotic "set 2" assignments were chosen - someone please tell!
The bewildering thing is that - for software compatibility reasons - the keyboard controller on the motherboard maps the scan codes back to "set 1" before handing them over to the keyboard interrupt handler (be it BIOS, Linux or Windows). So whatever the reasoning behind "set 2", it became moot! "Set 2" only matters if (like here) you need to interact with the keyboard hardware directly.
There's also set 3 which imo is a much better design, but hardly ever used. Naturally ;)
This part when Ben explains how NumPad numbers correspond with “E0” keys blew my mind! I just sat there thinking about how much work & engineering went into this small part of an input device like 30 years ago. And as Ben fully explained this to me (international relations & linguistics student, English being my second language) I felt shook to the core for some reason.
Thank you, Ben Eater, for your great content & making it breathtaking at least for me!
Lots of IBM development history there! Those ps/2 keyboards had a great feel though.
lasted forever, as well as the silk screening on the keys lasted too.. I have a 2 year old logitech and I've worn through all the silk screen and I'm working my way down the plastic (especially on the backspace key :P)
Heavy duty stuff!
They were great. I even still have one somewhere, because I found it, personally, to be a "gold standard" for keyboard input devices. Fred
I know.. I was jealous of the ownership of the keyboard itself!! :-)
@@Rx7man The key caps are dye sublimed, the dye is actually embedded into the plastic. They're also made of PBT so they don't yellow over time.
8:40 You don't actually want to "invert the clock" because on the falling edge the data signal is changing and thus you may get into timing issues. On the rising edge of the clock the data signal is stable so that is when you want to pick up the bit. I believe that this was done exactly to ease interfacing these keyboards with this type of shift register. On the other hand you want to trigger the latch with the inverted clock so you don't try to latch stuff while the chip is shifting (and getting something like "half-shifted data").
to people who try matching the oscilloscope-output to the lights: read the lights from right to left, while reading the oscilloscope from left to right. I recommend 17:51 for that. :) That may help with the occasional confusion as was the case for me. :D But great video!
It is a gift to take a very dry subject and make it, not just interesting but awesome. Throw in a bunch of educated comments and its a tutorial. I love this channel.
This is one of the coolest videos I watched. You just kept pulling out circuit boards
That was tremendous fun to watch. I understood what you were doing even though I haven't built any digital circuits since college in the early '80s.
I think a lot of us would find it very useful if you put a basic breadboard kit on your website as well. For example, it would contain a. Few breadboards, capacitors, resistors, wires, jumpers, buttons, LEDs, and maybe a 7 segment display or something cool, as well as some other components. It would give us a place to start, and the components could be used in any circuit we want to make.
Adafruit sells great little starter kits just like what you describe!
“You can see i have about 8 of them here, as far as you know”. Lol. I like to imagine that there are more. Just keeps going. Able to keep track of hundreds of key presses will all the breadboards you have lined up.
Those codes seem to originate from the IBM 3270 PC's 122-key keyboard (www.seasip.info/VintagePC/ibm_6110344.html) layout, which I've amended a little:
live.staticflickr.com/65535/51017310028_3cc2b1fd1f_o.png
I've put the codes from that model in decimal and made a connection of consecutive numbers. The effect looks like effective packing from left to right columns of 16 columns x 8 rows matrix. And I've also found a photo gallery of the actual circuitry, which collaborates that:
deskthority.net/viewtopic.php?p=205760#p205760
So the keys are numbered from left bottom to top, to right. That includes 5 keys not exposed externally (yellowish in the picture), maybe planned for layouts different from the US one. The numbers are not actual scan codes, although close, but continuous numbers starting with 1, given to the keys along the path of the matrix. The relation to physical scan codes is relatively simple, as if one decreases codes from 1 to 80 by 1, i.e. resulting in 0 to 79 and keep the rest as they are (this is because the numbering scheme skips TEST connection, which is present in the matrix, not in the keys, and makes the keyboard fail self-test if it is "pressed"), we get binary numbers in the form:
0 CCCC RRR
where:
RRR - row from bottom to top, 0 to 7
CCCC - column from left to right, 0 to 15
But note two exceptions: the key number 2 is encoded as 131, and the key number 127 as 132. So far I haven't been able to find the reason for that.
The keyboard above had function keys at the top, however, the keyboard that actually grown into the standard Ben observed in the video is the IBM PC AT keyboard, having 84 keys, and it looks like:
www.seasip.info/VintagePC/ibm_6450225.html
And it is just the previous one with some sections missing, but leaving the encoding of the rest exactly the same. And that's the encoding of physical positions of the keys, so F-keys on that model are encoded differently than that big section on the 122-key one. I've labeled them on my picture, according to the AT keyboard.
So if you look at Ben's codes list for the F1-F10 keys there's a 1:1 relation. F11 is passed as 120, which was hidden in the original keyboard, at least in the US version, and for F12 the actual function key of the 122-key model is used. Also, we can observe where did the Esc key get its high number - it was originally a part of the keypad. And e.g. Caps Lock key corresponds to the right Alt on 122-key one, but at the exact same spot, the 84-key actually had the Caps Lock. So look at the keycaps of the latter for comparison with the list. I may prepare an update of the image to have all the AT labels and maybe hexadecimal values as well.
The story of E0 is related to the actual AT keyboard, as what the 3270 is sending is now called "set 3", and the 84-key AT keyboard established standard known now as "set 2", in which keys not present on the original AT keyboard, i.e. unknown to older computers, would still produce some sensible results (E0 would be just ignored). So e.g. right Alt is understood as left Alt or separate arrow keys as their numeric keypad counterparts. And the Print Screen was just Shift + numpad "*", so that's exactly what Ben's keyboard produces.
And no, I haven't known this before today. Watching Ben's video, missing his explanation of the codes, I felt motivated to learn where did those numbers come from, so I've spent a few hours researching, looking thru technical references, learning about the three scan codes sets, the fact that the set 2 came from AT keyboard, trying to find keyboards released at the same time, photos of the matrices, etc. Not being able to find the clear answer I've started connecting buttons in order, knowing that the way simpler encoding, XT one, called now "set 1", IBM given just continuous numbering for blocks of the keyboard, attempting to see the pattern. As a side note, the set 1 scheme is not based on the matrix, just on the order of keys visible outside: www.seasip.info/VintagePC/ibm_1501105.html. Human friendly!
The John Elliot's site, www.seasip.info/VintagePC/index.html, has been the most helpful resource in my investigations. And thank you, Ben, for your great videos!
Thank you for this write-up. Very interesting and saved me a couple of hours of research :) You ever found why 131 and 132 are special? I'm not sure I understand it fully, but it seems there is a translation from Set 2 to Set 1 happening and 0x83 and 0x84 have some special meaning: www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html
0x7F, aka 127 is unavailable for keypresses, because its break sequence would be 0xFF which is reserved code for keyboard error.
This is really cool man, I'm an electrical engineer and I never had this explanation as a student.
11:45 couldn't you just hook the non-inverted clock to the latch clock? That would trigger it on the rising edge of the keyboard clock/falling edge of the shift register clock.
I don't have any sources for this, but I'd imagine the shift register chip doesn't like having its latch clock turned on indefinitely. Might heat up a transistor or smth
Sure, I had a same thought. I is more reliable than relying on propagation delay. Only problem that comes to mind are power spikes, but they won't disrupt the circuit, because data has been already latched.
@@kiefac No, you have to distinguish enable from clock. Enable is active, as long as it receives an active state. Clock on the other hand is active only at the rising edge of its input. Sequential logic is immune to static states on their clock pins, so that won't hurt anything
@@teslakovalaborator I wasn't referring to errors in logic, but more that the actual transistors used on that part of the silicon might not tolerate having power sent to them all the time. I don't know much about the actual circuits used in ICs though, so there's probably something I don't understand, like maybe the rising edge circuitry essentially cuts off power once it goes high? (Also, I suppose the latch outputs are designed to be left on for any length of time, and they would probably use the same one or two transistors throughout the whole chip?)
No.
I am so excited when I see a new video from Ben. I guess I'm not alone.
Your channel should be mandatory learning for all human beings starting at age 12. Thank you very much, this was extremely valuable. Im building a firmware/driver combo almost from scratch for an open source periphery ecosystem and this is my first step on the electronic/software part of my project!
Wait you're telling me that the scancode for Backspace is 66? that really gives Order 66 a whole new meaning!
Easter egg ;-)
Wouldn't it be safer to stay on the rising edge of the clock? It looks like the rising edge is in the stable region of the data, while the falling edge is close to the transition time.
This! Indeed, when I first saw the scope-trace, i thought - "Lucky, the data is stable on the rising clock-edge - and the shifter too is positive edge-triggered".. Guess we'll find out :)
Yep. Data changes with clock high, and is valid with clock low, I think it works thanks to the extra delay of the inverting gate, but shifting on rising edge should be more robust.
Well data is valid on clock-low. So a short delay after falling edge (whatever minimum time for data to stabilize) is probably best. Using rising edge, you're depending on the data not changing while the clock rises and that is probably 'undefined'. I suppose ideally you would sample 'data' half-way through the clock-low period, but that would require some more sophisticated delay timing.
Presumably there is some built-in window to de-bounce the keypress.
Well, I stand corrected.
I've done a quick search and apparently the host is meant to read on falling edges (and peripheral reads on rising edge when transmission happens the other way around).
Also spec requires that data changes 5-25us before falling edge so there is plenty of time.
Ben, thank you so much for your videos. They are awesome. You make an intimidating subject seem so simple. Thank you for all that you’re doing. Would love to see you sometime building a fully functional keyboard controller the same way you built the video card. I don’t know if it’s feasible. If not from discrete logic, (would be cool though), maybe built around an existing IO chip. Also would be great , at some point, to learn how to interface it with 6502 or a Breadboard project. Thank you again. You are amazing.
Good to see the technology to facilitate a “half a press” existed even all the way back then
An A press is an A press, you can't say it's a half
I'm just glad SRM was discovered. Half-A-presses are useful ig, but nothing has been more important than ACE and SRM.
Hey I'm a student from Germany. I build this circuit for a project in school. It was my final project of my High School i guess, as you would say. Afterall it's a relatively big deal here in germany. I used you Circuit and plugged it into a custom pcb from my school and displayed the Keys pressed in a LCD Display. I wanned to thank you very much, because i got an A for my project. It wouldn't have been possible without your help. Thanks. Keep it up!
The Printscreen sequence looks like a Macro for a Mortal Kombat Finisher / Fatality Combo 🤣🤣
I'm really blown away by the effort Ben is taking for such videos. It's one thing and already quite an effort to build a single stage of the shift register on a breadboard, with all the tiny cut-to-length-and-bent wiring. But it's totally off my head to build 7 more, while it would have been so much easier to show all of that in a Logic Analyzer or with an Arduino. Can't think of any other channel going through this.
I like your EEVBlog multimeter ;)
A lot of the computer hobby CZcams channels I watch have them. I'd like to get one myself, but there's other things on my hobby list that come as higher priority.
David, Aussie Downunder Represent! Great Chanel subscribe to David's Chanel, Mr Carlsons Lab and Jan Beta if you love electronics.
@@azzajohnson2123 I like daves content but not some of his personal views like siding with that "thunderf00t" troll guy
How you don’t have more subscribers is beyond me, quality stuff with humor can’t be beat. Keep up the good work !
I've been looking forward to this video. Thanks!
It’s always a good day when Ben Eater uploads
I love this. I've always wanted to have some insight into these kind of things. Outstanding content. Keep'em coming!
Initially, scancodes were arranged in the order of the keys - row by row - on the IBM XT keyboard (so called set 1). Interestingly, non-QWERTY keyboards (such as French AZERTY) still generate the codes according to keys order, e.g. code 0x10 for A, 0x11 - for Z, etc.
Nowadays, compliant keyboards can be ordered to use one of the three sets of scancodes - IBM XT (set 1), IBM 3270 (set 3) and IBM AT (set 2). Windows software, however, translate all those codes to set 1 by default.
Ayo! That's what I needed! Thanks 😊
You explain everything in the way that no one does. Your videos are perfect!
I graduated in 09 and I had some interesting teachers. One was Eaton, another was Bacon, and then there was Lamb. Eaton was kind of a seminar teacher, but for those of us who had a disability. i have autism and OCD. Eaton was well known for serving snacks in her room. Bacon was a couple. One was an art teacher and his wife was a math, english, and seminar teacher. Lamb was an art teacher. I thought this would be pretty funny since its Ben Eater who is doing these series. Have ya been a good eater? Also this is only to be a good friendly humor. I am a big fan of these videos and with luck I will get a career out of my studies here. Currently I have one Computer Tech interested in training me. I just have to study up on Client work with companies such as writing programs for a whoevers Domain and whoevers company.
IIRC, PS/2 keyboards work off of interrupts. So if you were to interface with the 6502 computer, I'd say push the scancodes directly, trigger an interrupt, store the scancode in RAM, and flip the latch clock of the shift register to read the next byte.
You can then read that data from your primitive kernel, and display what was typed onto the LCD screen.
That would require the clock of the 6502 to be fast enough to react to the first part of the keycode, read it from the register, and store it in ram, before the next part arrives. Of course it normally would be - but not if you were single-stepping, or had other code blocking interrupts for a short time. There would have to be some hardware keyboard-buffer to handle the multibyte codes.
All keyboards work off of interrupts
@@jacoburick9794 usb keyboards use polling instead of interrupts
@@peterlinddk I was thinking of using the stop bit connected to an interrupt on the CPU to tell it there's valid data, perhaps through a SR latch so that once the data is read the CPU unsets it once it's read, and it would only take a few and/or gates to choose to ignore following scan codes if the CPU hasn't had time to read it yet.. You would actually be able to read in the 2nd scan code as soon as the first is latched, be a little harder to figure out the logic on the latch clock to delay it until the first has been read though
You are a master of explaining things! Thanks a lot. Erik
If you want to interface with a 6502 you’d traditionally use a 6522 or 6526. You could do it from scratch too but you’d have to build a counter and some error logic to fix your latch and add a buffer.
I know next to nothing about electronics, yet these videos make me believe I could build the Apollo Guidance Computer.
Oh look. It's the breadboard Bob Ross back with another video.
Lets put some happy LEDs here ! I like that !
To answer your prompt at the end of the video for an interface between the computer and the ps/2 port, my first thought is that you could take the output of the shift register and use it as an index into ROM that the cpu can read from. Of course, it isn't a robust solution as it doesn't allow for more than one key to be pressed, and would not handle the pause or print screen buttons. But as a quick and dirty way to have something that gets the job done that's what I'd do.
"eight of them, as far as you know" ...I love it.
Hi Ben. I'm also working on a homebrew microcomputer and I decided to use a µC to take care of the PS2 keyboard, and also one joystick and 2 paddles. The µC is interfaced with the main CPU via SPI interface. About the keyboard, I also converted a IBM to USB, using a microchip microcontroller and redesigning a new board. For what I discover in those 2 projects, the scan codes beginning with E0 are because of the added keys between the IBM XT keyboard and the IBM AT keyboard. The key codes follow an order relative to the grip mapping of the keyboard, 8x16 allowing 128 keys, although not all of them are wired.