Resetting The Cursor X Position on CR

If the next character to display is CR (ASCII value of 13), then cursor X is reset to 0. More formally,

if the following are true:
  • value of cell 27 at time t = 1
  • value of cell (10 + (number of characters read at t)) at time t = 13

then cursor x at time (t + 1) = 0

Recall that the display moves to the next line when the current line is full. Pressing the "Enter" key also causes the display to move to the beginning of the next line. This is not due to some cryptic programming trick; this is simply how text terminal displays are designed. When we press the "Enter" key, the keyboard sets memory cell #8 to 13, which is the "carriage return" or "CR." When the display sees 13 in memory, it will set cursor x to 0.

For example, suppose that the following are true:

  • value of cell 27 at time 71 = 1
  • number of characters read at 71 = 0
  • value of cell 10 at time 71 = 13

Since the display hasn't read any characters yet, the next cell to read from is 10 + 0, or 10. And the value of cell #10 is 13. Thus,

cursor x at time (71 + 1) = 0

see here for the full proof.

Try running the simulator below and click on the "Enter" key to see the cursor x value change to 0.

Time: 0
LW Computer IO Simulator

Comments

Please log in to add comments