Close

The Keyboard

A project log for Anatomy of a Philips VideoWRITER

I tear down an old Philips VideoWRITER to see how it works

maarten-janssenMaarten Janssen 12/21/2019 at 17:270 Comments

Before I start this log on the keyboard I should mention that I'm in the process of putting all of my writings and software on the Video Writer on a small website. The following is an almost direct copy of what will be the article about the keyboard...

In this section we'll take a look at the VideoWriter's keyboard and how the unit interacts with it. The keyboard is very nicely layed out with a number of function keys specific to the word processor, for example to do spell checks or to get access to contextual help screens. Inside the keyboard we find a NEC D8049HC microcontroller. It has 2KB of program ROM and 128 bytes of RAM. The microcontroller scans the keyboard switches and handles the communication with the VideoWriter. A nice surprice was to find that it also implements a FIFO buffer that can hold up to 20 keystrokes. If this buffer is full then no more keys will be added until one is read out. When holing a key down it will start to repeat after a short delay as you would expect.

The keyboard is connected to J7 on the main board through an RJ-11 style connector on the front of the unit. J7 is a simple 4-pin connector with the following pinout:

  1. GND
  2. /Enable
  3. Data
  4. +5v

Pins 2 and 3 of J7 are connected to the D8156HC IO controller's ports C and A respectively. The software configures port A as an input and port C as an output. Both the /Enable and Data signals are on bit 0 of these ports. To read a key from the keyboard the /Enable line is set low and after a delay of a few uS the keyboard starts to send the data of the first keystroke in its buffer. The data stream is a very familiar 9600 baud 8N1 serial signal, though from the word processor code I could not have worked that out without connecting my scope. That piece of code was extremely confusing... Each time /Enable is pulled low the keyboard will send one keystroke from its buffer. When the buffer is empty, i.e. there was no key pressed, then there will be no data transmitted. In other words when, after pulling /Enable low, there is no start bit received it means that there are no keys to process. The keyboard only sends key presses, there are no key events for a key release.

/Enable                                                     
________    ________________________________________________
        |  |                                                
        |  |                                                
        |__|                                                
                                                            
Data                                                        
_______________     ___     _______     _______     ________
               |   |   |   |   :   |   |   :   |   |   :    
               |   |   |   |   :   |   |   :   |   |   :    
               |___|   |___|   :   |___|   :   |___|   :    
                                                            
               Start 0   1   2   3   4   5   6   7  Stop

In the real world we can't simply assume, however, that this will work at any given time. The keyboard is not always ready to respond to a data request. If we query the keyboard at an inconvenient time, when it is scanning for button presses, it will completely miss our request for data and it will appear as if no keys were pressed, even though the buffer may contain some. Furthermore if our software is deterministic then we're always requesting for key input at an inconvenient time. This is at least my understanding of the keyboard's internal workings after experimenting with it. In order to overcome this problem we can simply retry the data request a number of times until we find a start bit appears after pulling the /Enable line low. If after retrying a few times we still didn't receive a start bit, then we can be quite sure that the key buffer is empty. It seems that the word processor software is also doing something similar.

The key codes that are sent by the keyboard are normal ASCII character codes for the regular keys. For the 'special' keys such as backspace, return and tab these are not the regular ASCII codes, same as for the function keys. A curiousity about the key codes is that every key, also the function keys, has a dedicated lower case and upper case key code that depends on whether the shift key is pressed. This makes it very versatile, but slightly annoying when you have to differentiate between space as 0x20 and shift + space 0x49 for example. The caps-lock key only affects the alphabetical keys on the keyboard by always making them upper case. This means that pressing shift + A when caps-lock is active will not produce a lower case 'a', but 'A'. In software this can be compensated by taking into account the state of caps-lock, since caps-lock sends its own key codes (not affected by shift!). Below you will find the keyboard layout with the key codes in unshifted (on the bottom) and shifted (at the top) state.

Another curiousity about the keyboard is that the keys codes that we receive are for a US layout, while my keyboard resembles a UK keyboard layout. For example where normally you will find the '@' symbol on the '2' key, on my keyboard it shows the '"' symbol. This means that the word processor software must contain a translation table to change the keys from US layout to UK, depending on the locale of the software.

                                                                               )   )                        
                                                                              (   (                         
                                                                               )   )                        
.----------------------------------------------------------------------------------------------------------.
|                                                                                                          |
|         _     _           __    __      _ _                                             +-------+        |
|  /\   /(_) __| | ___  ___/ / /\ \ \_ __(_) |_ ___ _ __                                  |B1     |        |
|  \ \ / / |/ _` |/ _ \/ _ \ \/  \/ / '__| | __/ _ \ '__|                             ____|     B0|____    |
|   \ V /| | (_| |  __/ (_) \  /\  /| |  | | ||  __/ |                               |B5   '.   .' B7  |   |
|    \_/ |_|\__,_|\___|\___/ \/  \/ |_|  |_|\__\___|_|                               |       '.'       |   |
|                                                                                    |  B4  .' '.    B6|   |
|         +-----+-----+-----+   +-----+-----+-----+-----+   +-----+-----+-----+      |____.'     '.____|   |
|         |97   |99   |9B   |   |9D   |9F   |A1   |B9   |   |A3   |A5   |A7   |           |B3     |        |
|         |   96|   98|   9A|   |   9C|   9E|   A0|   B8|   |   A2|   A4|   A6|           |     B2|        |
|         +-----+-----+-----+   +-----+-----+-----+-----+   +-----+-----+-----+           +-------+        |
|                                                                                                          |
|   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--------+     +-----+   |
|   |C1   |21  !|40  @|23  #|24  $|25  %|5E  ¡|26  &|2A  *|28  (|29  )|5F  ¿|2B  +|C5      |     |A9   |   |
|   | Del |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  0  |  -  |  =  | BackSp |     |     |   |
|   |   C0|   31|   32|   33|   34|   35|   36|   37|   38|   39|   30|   2D|   3D|      C4|     |     |   |
|   +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-----+     |   A8|   |
|   |C3      |51   |57   |45   |52   |54   |59   |55   |49   |4F   |50   |7B  {|7D  }|C7   |     +-----+   |
|   |  Tab   |  Q  |  W  |  E  |  R  |  T  |  Y  |  U  |  I  |  O  |  P  |  [  |  ]  |     |     |AB   |   |
|   |      C2|   71|   77|   65|   72|   74|   79|   75|   69|   6F|   70|   5B|   5D|     |     |     |   |
|   +--------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+     |     |     |   |
|   |91         |41   |53   |44   |46   |47   |48   |4A   |4B   |4C   |3A  :|22  "|        |     |   AA|   |
|   | Caps Lock |  A  |  S  |  D  |  F  |  G  |  H  |  J  |  K  |  L  |  ;  |  '  | Return |     +-----+   |
|   |         90|   61|   73|   64|   66|   67|   68|   6A|   6B|   6C|   3B|   27|      C6|     |AD   |   |
|   +-----------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--------+     |     |   |
|   |              |5A   |58   |43   |56   |42   |4E   |4D   |3C  <|3E  >|3F  ?|           |     |     |   |
|   |    Shift     |  Z  |  X  |  C  |  V  |  B  |  N  |  M  |  ,  |  .  |  /  |   Shift   |     |   AC|   |
|   |              |   7A|   78|   63|   76|   62|   6e|   6D|   2C|   2E|   2F|           |     +-----+   |
|   +--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+               |
|            |95      |49                                                   |93      |                     |
|            | Style  |                                                     | Insert |                     |
|            |      94|                                                   20|      92|                     |
|            +--------+-----------------------------------------------------+--------+                     |
|                                                                                                          |
'----------------------------------------------------------------------------------------------------------'

Discussions