Online Book Reader

Home Category

Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [133]

By Root 1653 0
echoing the key to the display. The cursor position is then incremented so that the cursor appears in the space after the character just displayed. In this way, someone can type a bunch of characters on the keyboard and they'll be displayed on the screen.

If the key pressed is the Backspace key (corresponding to ASCII code 08h), the keyboard handler erases the character that was last written to the video display memory. (Erasing the character is simply a matter of writing ASCII code 20h—the space character—in that memory location.) It then moves the cursor backward one space.

Usually a person typing at the keyboard types in a line of characters—using the Backspace key when necessary to correct mistakes—and then presses the Return key, often labeled Enter on computer keyboards. In the same way that pressing the Return key on an electric typewriter indicates that the typist is ready to go to the beginning of the next line, pressing the Enter key indicates that the typist is finished typing a line of text.

When the keyboard handler processes the Return or Enter key (corresponding to ASCII code 0Dh), the line of text in the video display memory is interpreted as a command to the computer, that is, something for the keyboard handler to do. The keyboard handler includes a command processor that understands (for example) three commands: W, D, and R.

If the line of text begins with a W, the command means Write some bytes into memory. The line you type on the screen looks something like this:

W 1020 35 4F 78 23 9B AC 67

This command instructs the command processor to write the hexadecimal bytes 35, 4F, and so on into the memory addresses beginning at address 1020h. For this job, the keyboard handler needs to convert ASCII codes to bytes—a reversal of the conversion I demonstrated earlier.

If the line of text begins with a D, the command means Display some bytes in memory. The line you type on the screen looks like this:

D 1030

The command processor responds by displaying the 11 bytes stored beginning at location 1030h. (I say 11 bytes because that's how many will fit on a 40-characterwide display on the same line following the address.) You can use the Display command to examine the contents of memory.

If the line of text begins with an R, the command means Run. Such a command looks like this:

R 1000

and means "Run the program that's stored beginning at address 1000h." The command processor stores 1000h in the register pair HL and then executes the instruction PCHL, which loads the program counter from register pair HL, effectively jumping to that address.

Getting this keyboard handler and command processor working is an important milestone. Once you have it, you no longer need suffer the indignity of the control panel. Typing bytes in from the keyboard is easier, faster, and classier.

Of course, you still have the problem of all the code you've entered disappearing when you turn off the power. For that reason, you'll probably want to store all this new code in read-only memory, or ROM. In the last chapter, we obtained a ROM chip that contained all the dot patterns necessary for displaying ASCII characters on the video display. We assumed our chip was configured with this data during manufacture. You can also program ROM chips in the privacy of your home. Programmable read-only memory (PROM) chips are programmable only once. Erasable programmable read-only memory (EPROM) chips can be programmed and reprogrammed after being entirely erased by exposure to ultraviolet light.

As you'll recall, we wired our RAM boards with a DIP switch that allows us to specify the starting address of the board. If you're working with an 8080 system, initially one of your RAM boards will be set for address 0000h. After you create a ROM, that ROM will occupy address 0000h and the RAM board can be switched to a higher address.

The creation of the command processor is an important milestone not only because it provides a faster means to enter bytes into memory but also because the computer is now interactive. When you type something

Return Main Page Previous Page Next Page

®Online Book Reader