

This works, but what if we’re “too late” and wrote after the CPU is already done accessing the keyboard? Ok, here’s a thing: the keyboard RAM is just a register. Here’s the solution I came up with: when the CPU is about to access the keyboard data, we write the updated keyboard data to RAM. We can use the copying scheme from before for the screen, but what about the keyboard? So we can have both a single RAM chip for the CPU to access, and two separate RAM chips (the screen and the keyboard) for the screen and the keyboard to access.

So we can copy RAM when the clock “tocks” (goes from high to low)).īut wait, what about the keyboard? It turns out that only the CPU needs to access the entire RAM, the screen and the keyboard only need to access a few parts of it. The CPU and the screen only do things when the clock “ticks” (goes from low to high). So I came up with the idea to use a copy RAM that would alternate between copying RAM and letting the screen access it (the CPU has a clock, which alternates between a “low” voltage, and a “high” voltage, at a steady rate.

It only allows reading from one address at a time. The reason this doesn’t work is that the three parties might want to read three different addresses of RAM, and (unless you use dual/triple port ram) the RAM doesn’t like that. One RAM chip only has one address but will have to be connected to three other parties. Reading on in the From NAND to Tetris textbook.
