collapseos/recipes/rc2014/ps2
Virgil Dupras 019d05f64c Make the shell a userspace app
That's my mega-commit you've all been waiting for.

The code for the shell share more routines with userspace apps than with kernel
units, because, well, its behavior is that of a userspace app, not a device
driver.

This created a weird situation with libraries and jump tables. Some routine
belonging to the `kernel/` directory felt weird there.

And then comes `apps/basic`, which will likely share even more code with the
shell. I was seeing myself creating huge jump tables to reuse code from the
shell. It didn't feel right.

Moreover, we'll probably want basic-like apps to optionnally replace the shell.

So here I am with this huge change in the project structure. I didn't test all
recipes on hardware yet, I will do later. I might have broken some...

But now, the structure feels better and the line between what belongs to
`kernel` and what belongs to `apps` feels clearer.
2019-11-15 15:37:49 -05:00
..
Makefile Make the shell a userspace app 2019-11-15 15:37:49 -05:00
README.md recipes/sms/kbd: add schematic 2019-07-20 14:51:34 -04:00
glue.asm Make the shell a userspace app 2019-11-15 15:37:49 -05:00
ps2ctl.asm recipes/sms/kbd: PS/2 keyboard adapter for the SMS! 2019-07-20 12:42:55 -04:00
schema-595.png recipes/rc2014/ps2: add schema 2019-06-30 17:37:18 -04:00
schema-ps2.png recipes/rc2014/ps2: add schema 2019-06-30 17:37:18 -04:00
schema-t45.png recipes/rc2014/ps2: add schema 2019-06-30 17:37:18 -04:00
schema-z80.png recipes/rc2014/ps2: add schema 2019-06-30 17:37:18 -04:00

README.md

Interfacing a PS/2 keyboard

Serial connection through ACIA is nice, but you are probably plugging a modern computer on the other side of that ACIA, right? Let's go a step further away from those machines and drive a PS/2 keyboard directly!

Goal

Have a PS/2 keyboard drive the stdio input of the Collapse OS shell instead of the ACIA.

Gathering parts

  • A RC2014 Classic that could install the base recipe
  • A PS/2 keyboard. A USB keyboard + PS/2 adapter should work, but I haven't tried it yet.
  • A PS/2 female connector. Not so readily available, at least not on digikey. I de-soldered mine from an old motherboard I had laying around.
  • ATtiny85/45/25 (main MCU for the device)
  • 74xx595 (shift register)
  • 40106 inverter gates
  • Diodes for A*, IORQ, RO.
  • Proto board, RC2014 header pins, wires, IC sockets, etc.
  • AVRA

Building the PS/2 interface

Let's start with the PS/2 connector, which has two pins:

PS/2 connector

Both are connected to the ATtiny45, CLK being on PB2 to have INT0 on it.

The DATA line is multi-use. That is, PB1 is connected both to the PS/2 data line and to the 595's SER. This saves us a precious pin.

ATtiny45

The ATtiny 45 hooks everything together. CE comes from the z80 bus, see below.

74xx595

This allows us to supply the z80 bus with data within its 375ns limits. SRCLR is hooked to the CE line so that whenever a byte is read, the 595 is zeroed out as fast as possible so that the z80 doesn't read "false doubles".

The 595, to have its SRCLR becoming effective, needs a RCLK trigger, which doesn't happen immediately. It's the ATtiny45, in its PCINT interrupt, that takes care of doing that trigger (as fast as possible).

z80

Our device is read only, on one port. That makes the "Chip Enable" (CE) selection rather simple. In my design, I chose the IO port 8, so I inverted A3. I chose a 40106 inverter to do that, do as you please for your own design.

I wanted to hook CE to a flip flop so that the MCU could relax a bit more w.r.t. reacting to its PB4 pin changes, but I didn't have NAND gates that are fast enough in stock, so I went with this design. But otherwise, I would probably have gone the flip-flop way. Seems more solid.

Using the PS/2 interface

After having built and flashed the glue.asm supplied with this recipe, you end up with a shell driven by the PS/2 keyboard (but it still outputs to ACIA).

There are still a few glitches, especially at initialization or at connect and disconnect, but it otherwise works rather well!