Cover of Code by Charles Petzold - Business and Economics Book

From "Code"

Author: Charles Petzold
Publisher: Microsoft Press
Year: 2000
Category: Computers

🎧 Free Preview Complete

You've listened to your free 10-minute preview.
Sign up free to continue listening to the full summary.

🎧 Listen to Summary

Free 10-min Preview
0:00
Speed:
10:00 free remaining
Chapter 22: The Operating System
Key Insight 2 from this chapter

Developing an Interactive Command-Line Interface

Key Insight

To overcome the limitations of the control panel, a keyboard is integrated to provide input through interrupts. When a key is pressed, an interrupt controller causes the microprocessor to execute a Restart (RST) instruction (e.g., RST 1), which jumps to a predefined memory address (e.g., 0008h) containing a 'keyboard handler'. Prior to this, 'initialization code' is executed upon reset. This code sets the stack pointer to a valid memory area, clears the video display by writing the ASCII space character (20h) to all screen memory, positions the cursor, enables interrupts (EI) to respond to keyboard events, and then halts the microprocessor (HLT) until an interrupt occurs.

The keyboard handler, invoked by an interrupt, uses an Input (IN) instruction to identify the pressed key. It processes characters by converting their scan codes (accounting for the Shift key state) into ASCII codes and 'echoing' them to the video display memory at the cursor's current position, subsequently incrementing the cursor. If the Backspace key (08h) is pressed, the last character is erased by writing 20h (space) to its memory location, and the cursor moves back one position. The Return or Enter key (0Dh) signals the end of a typed line, which is then passed to a 'command processor' for interpretation.

The command processor interprets the typed lines as instructions. For example, 'W 1020 35 4F 78 23 9B AC 67' writes specified hexadecimal bytes to memory starting at address 1020h. 'D 1030' displays 11 bytes from memory beginning at 1030h. 'R 1000' executes a program stored starting at address 1000h by loading 1000h into the HL register pair and executing PCHL. This command-line interface significantly improves usability over the control panel. To ensure the command processor and other essential code persist across power cycles, they are stored in read-only memory (ROM), such as PROM or EPROM, with ROM typically occupying the low memory address 0000h, shifting RAM to higher addresses, making the computer interactive.

📚 Continue Your Learning Journey — No Payment Required

Access the complete Code summary with audio narration, key takeaways, and actionable insights from Charles Petzold.