Electronic – Simplest possible I/O for Homebrew 8-bit CPU


I am working on designing an 8 bit cpu as a personal project for no real reason. I am using mostly 74HC series chips and am generally focusing on ease of programming over performance.

I am using various projects on the internet as inspiration, and I feel I have a pretty good grasp on how the basics will work, including the alu, registers, and the basic memory path.

The one thing I don't have a clue about is Input and output. I am not really interested in anything super fancy, like tcp/ip or uarts, but I would like to have a keyboard and a basic text output to a monitor of some kind. I really have no idea what hardware to use, or what instructions to make to use it.

I could squeeze a few more specialized instructions out of my ISA to access specialized hardware, but if I could do it all with some kind of memory mapping scheme that could be even better. I am planning on using a 64K ram chip, but maybe certain addresses could get diverted to other hardware or something.

I don't really want to implement interrupts, but I don't want to lose keyboard data either. Does that means I need some kind of queuing buffer chip for my keyboard? I don't even know where to start looking for a video chip, or how I would interface with it.

Any tips would be greatly appreciated. Again, I don't need anything fancy, a simple getChar and putChar would suffice. Pixel level control of graphics could be cool, but not absolutely required. I think I just need to be pointed in the right direction.

Best Answer

The "simplest possible I/O" depends on what your I/O requirements are. It would be very simple, if you're in control of the CPU design, to implement a couple of special instructions to input and output a few bits of parallel I/O.

But since you mention keyboard and video, it seems that your requirement is to be able to interact with your system that way - and the dead simplest way to do that is to incorporate a fixed baud-rate serial port, and use a PC & terminal program to supply the keyboard and video. Using 9600 bps is fine for human console purposes, or if you expect to transfer binary, 115200 could handle 64K bytes in around 6 seconds.

An off-the-shelf UART chip like the 6850 or 8250 (well, out of the junk-box anyway) will need only 2 to 8 registers for a complete stdin/stdout solution. This is a tiny footprint compared to trying to implement a keyboard and video interface directly. You can probably drive a keyboard matrix with just a single 8-bit output port and a single 8-bit input port, but video will need 2K addresses just to supply the frame buffer for an 80x25 character display. If you consider so-called LSI solutions like the 8250 to be cheating, I would counter that constructing a UART from 74xx would probably be easier than constructing a video generator from the same technology.

That said, the down-side of the UART is that you are likely to lose input unless you either (a) poll it frequently enough, or (b) implement interrupts. For a simple proof-of-concept for your CPU, just polling should suffice - unless you're also trying to prove out interrupt capabilities of your CPU (if/when it has them), in which case, keeping up with serial input by using UART interrupts would be a fine test case.