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.
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?
@@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.
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 UA-cam, please never stop.
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.
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...".
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.
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.
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.
"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!"
"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!"
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.
@@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.
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.
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!
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.
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.
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.
@@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.
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!
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.
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
@@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.
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.
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 UA-cam channel . it will be all thanks to you and the amazing people that I have talked with.
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.
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").
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
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.
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!
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!
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!
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 :-)
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!
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.
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?).
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.
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.
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!
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.
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. :-)
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.
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
21:41 well we only have 8 bits and keyboards sometimes send 16 bits... That's the moment when I said to myself: thanks for the fun ride Ben. But oh boy, this is Bean Eater!!! There's no such a thing as: better luck next time. He has another 8-bit circuit that will add in order to be able to get every key code!!!! Thanks Ben for your dedication, commitment and high quality of your videos. That's why your content stands out!!!
Love seeing an old school IBM PS/2 keyboard. I'm typing these comments on one now. Have a couple of NOS in case this one ever dies. I've had to tough it out without the benefit of the Windows key. Back in the 1990s I was at NEC Tech and got drafted to write PC KBC (keyboard controller) code. At the time PCs used an Intel 8041 as the smart keyboard interface. This started with the IBM AT (Intel 286) and a second serial interface was added to it when mice became popular. The 8041 was basically an 8048 with the 8-bit bus interface. It was also responsible for managing the dreaded GateA20 feature and resetting the 286 from protected mode. Debugging was fun, no in circuit emulator but I had a nifty firmware emulator to sortofkindof get the code working. Then had to resort to breakpoints and writing to shared memory. Keyboards and mice use the same electrical interface and connector pinout. Most KBC firmware only knew how to process the device it expected on the specific port. Later there was some effort to improve the PS/2 interface to accept multiple devices but the popularity of USB killed that. I was not aware of trackballs using the two spare pins but that may have happened later. I'd hate to post of picture of what my breadboards look like.
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.
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!
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.
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.
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
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.
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.
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.
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.
@@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
Seems to be a timing mandate, if you shift on the rising edge you can be sure the data is stable. This would be similar to the reason why in asynchronous data reception you delay shifting the data by half the bit length
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.
Absolutely magic how all the jumper wires are just the right length and shape! Musta taken a lot of practice builds. This is the clearest explanation of the PS2 interface that I have even seen. Well done
“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.
Excellent material. You can see the smart use of the clock to send several different signals through one wire. It would be nice, if you do a part 2 showing the matrix under the keyboard and how the keyboard generates the binary codes for each key.
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?)
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
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.
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 UA-cam, 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.
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.
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.
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.
"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!"
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.
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:ua-cam.com/video/q7bZs2Nhi4Ez/v-deo.html
@@To-mos
I made 4 bit RAM ckt using only D FLIP FLOPS And Basic gates:ua-cam.com/video/q7bZs2Nhi4Ez/v-deo.html
22:20
Man, this really hits home
this is the greatest dad joke ever
UA-cam finally decided it is time for me to find your channel, Ben. Amazing work!
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!
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.
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... 😂😂😂
“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
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!
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".
"5v is black"
Okay, now what? Next you're gonna tell me data is red?
"data is red"
oh no.
Is there an award for break board wiring neatness? Because if there is, it DEFINITELY goes to Ben.
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
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.
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!
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.
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.
this man puts so much effort in his projects, it's bone chillingly good.
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 UA-cam channel . it will be all thanks to you and the amazing people that I have talked with.
Brilliant. The story got even more interesting as it went on. 10/10 for effort!
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.
27:10 "I've got 8, as far as you know..." that's a golden moment. Love this channel.
Mindblowing Explanation man
You Nailed it
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").
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
How you don’t have more subscribers is beyond me, quality stuff with humor can’t be beat. Keep up the good 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.
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.
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 !
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?
This is one of the coolest videos I watched. You just kept pulling out circuit boards
Hats off to you, Sir. The way you arranged everything on the breadboard without any clumsiness. Awesome
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 !
32:33 yup, dedicated hardware to read and hold state for the keyboard!
Great video on interfacing!
Me, a nail biter, seeing someone strip wires by hand:
Pure sorcery.
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!
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!
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 :-)
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!
Ohhh i am in love with these channel
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)
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?).
“please add another one...please add another one”
>25:52
“YES!”
>video continues
“YOOOOOOO”
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.
I've been looking forward to this video. Thanks!
Love this channel. I could sit, watch and listen all day long.
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.
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!
Some of my favourite comedians have an odd parody bit.
Ouch.
Ben Eater is back clearing up confusion again!
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.
I adore this content. Not only informative, but compellingly informative. The more I learn, the more I need to know!
When you think he reached a top with the VGA graphics card he comes up with this. Just magnificent.
I saw the title on this and before I had another thought I am here. Thank you Ben!
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.
As always with your videos this is a great tutorial
I love this. I've always wanted to have some insight into these kind of things. Outstanding content. Keep'em coming!
It’s always a good day when Ben Eater uploads
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
This is really cool man, I'm an electrical engineer and I never had this explanation as a student.
(Looks at my breadboard) It may have been assembled by bird preparing for spring.
Loved this video! Instant subscription!
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
21:41 well we only have 8 bits and keyboards sometimes send 16 bits...
That's the moment when I said to myself: thanks for the fun ride Ben. But oh boy, this is Bean Eater!!! There's no such a thing as: better luck next time. He has another 8-bit circuit that will add in order to be able to get every key code!!!! Thanks Ben for your dedication, commitment and high quality of your videos. That's why your content stands out!!!
I had a feeling throughout the video that something will explode, after watching ElectroBoom for 2 hours.
Love seeing an old school IBM PS/2 keyboard. I'm typing these comments on one now. Have a couple of NOS in case this one ever dies. I've had to tough it out without the benefit of the Windows key.
Back in the 1990s I was at NEC Tech and got drafted to write PC KBC (keyboard controller) code. At the time PCs used an Intel 8041 as the smart keyboard interface. This started with the IBM AT (Intel 286) and a second serial interface was added to it when mice became popular. The 8041 was basically an 8048 with the 8-bit bus interface. It was also responsible for managing the dreaded GateA20 feature and resetting the 286 from protected mode.
Debugging was fun, no in circuit emulator but I had a nifty firmware emulator to sortofkindof get the code working. Then had to resort to breakpoints and writing to shared memory.
Keyboards and mice use the same electrical interface and connector pinout. Most KBC firmware only knew how to process the device it expected on the specific port. Later there was some effort to improve the PS/2 interface to accept multiple devices but the popularity of USB killed that. I was not aware of trackballs using the two spare pins but that may have happened later.
I'd hate to post of picture of what my breadboards look like.
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.
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!
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!
I am so excited when I see a new video from Ben. I guess I'm not alone.
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.
@@ville_syrjala 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.
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.
Ayo! That's what I needed! Thanks 😊
You explain everything in the way that no one does. Your videos are perfect!
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.
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.
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.
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 ;)
I watch your videos mainly because I find your voice soothing: D
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?
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. ;)
Seems to be a timing mandate, if you shift on the rising edge you can be sure the data is stable. This would be similar to the reason why in asynchronous data reception you delay shifting the data by half the bit length
Wonderful Video, for something that ive used to years but didnt know how it worked.
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.
Absolutely magic how all the jumper wires are just the right length and shape! Musta taken a lot of practice builds. This is the clearest explanation of the PS2 interface that I have even seen. Well done
He actually has a video about how he makes the jumper wires. Definitely worth watching!
“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.
Excellent material. You can see the smart use of the clock to send several different signals through one wire. It would be nice, if you do a part 2 showing the matrix under the keyboard and how the keyboard generates the binary codes for each key.
Ben posted today. Today is a good day.
Explaining complex stuff in a clear, easy to understand way. Brilliant!
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.
Fascinating, as always. Thank you.
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.
That was the best video I've seen in a while. You put a lot of thought into it and it was very clear and informative.
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.