Handling I/O - Nand2Tetris
The computer senses your touch but how does it realize it?
Some of the quotes and information are part of the Nand2Tetris course available on Coursera.
I/O in a computer is handled by the device drivers. But how? The devices, when working, put a value into a memory location, say the mouse will continuously write its change in location value to the memory at address 7345, the driver will continuously look into that location and get the value to work with and changes the location of the pointer on the screen accordingly.
The computer that I am building as a part of the course takes input from the keyboard and outputs it to a virtual screen of dimensions 512x256. So there are 512 pixels horizontally and 256 rows of those 512 pixels.
For each pixel, we store the value to be displayed in the memory using bits in memory. For a black and white screen, we can consider the pixel as black if the value is set to
1 and white if it is set to
The set of bits that define the pixel values of the screen is called the Screen Memory Map or VRAM (Video RAM). In real-life computers, it is defined somewhere from 64 to 128 MB. If the computer has a dedicated Graphics Processing Unit (GPU) this number will usually be much higher.
Similar to this, the keyboard also writes to a memory location and it is called the Keyboard Memory Map. In the computer that I am building, this is a 16-bit register and is more than enough to represent the ASCII coded values on the keys and can also support Unicode values if necessary.