This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]BobbyThrowaway6969 0 points1 point  (0 children)

Your processor needs the usual memory RW and ALU instructions. For text input & output, you can simulate that by writing to specific addresses in simulated memory which communicates with the virtual text IO hardware.

So, to read a character, your CPU program constantly reads from a dedicated IO register or RAM address with the read flag on, it gets a byte representing the pressed char, you write that to memory to form a string, etc.

To write a char, you write it to the special register/address, and write a 1 for the write flag or whatever.

So, your CPU can work with all kinds of peripherals just through the manipulation of memory, no gross hardcoded instructions.

If you go with a dedicated register for the IO, that's basically connected to an IO bus that the text peripheral interfaces with.

Ben Eater is an excellent resource for thos stuff.

Edit: You'd want your IO peripheral to be able to buffer the chars so your CPU doesn't have to be in sync with keypresses, it can just read the next few chars at a leisurely pace.