Programming the Screen Editor: Margins, Tab Stops, Logical Lines and the Text Window

Atari text screen with a table aligned at default and custom tab stops, a paragraph wrapped between columns 10 and 29, and a row of control-code symbols

The Atari's screen editor (device E:) is far more than a place for READY to appear. It offers full-screen editing, logical lines that span up to three screen rows, adjustable margins, programmable tab stops, insert and delete, and a split-screen text window under graphics. Every one of these features is controlled by a byte or two of OS RAM, so a program can use the editor as a simple formatting engine: tabulate a report, confine text to a column, or show control characters in a listing.

What you'll learn: the editor variables and what each does, how to set your own tab stops, how margins and logical lines behave, how to print control codes as symbols, and how the text window has its own cursor.

What you need: Atari BASIC. The examples were tested on revision C. ATASCII and Keyboard Codes lists all the control codes.

1. The variables

Location Name Use
82 ($52) LMARGN Left margin column (default 2)
83 ($53) RMARGN Right margin column (default 39)
84 ($54) ROWCRS Cursor row on the main screen
85–86 ($55) COLCRS Cursor column on the main screen (two bytes)
656 ($290) TXTROW Cursor row in the split-screen text window (0–3)
657–658 ($291) TXTCOL Cursor column in the text window
675–689 ($2A3) TABMAP 15 bytes = 120 tab-stop bits
690–693 ($2B2) LOGMAP Which screen rows start a logical line
703 ($2BF) BOTSCR 24 for a full text screen, 4 in a split screen
752 ($2F0) CRSINH Non-zero hides the cursor
766 ($2FE) DSPFLG Non-zero displays control codes instead of obeying them
767 ($2FF) SSFLAG Start/stop flag toggled by CTRL-1

The default left margin is 2 because, as the Operating System User's Manual explains, the two leftmost columns are not fully visible on many TVs. Setting LMARGN to 0 gives the full 40 columns.

2. Logical lines

The screen is made of 24 physical rows, but the editor works in logical lines of one to three rows (up to 120 characters). When you type past the right margin, the line simply grows onto the next row. When you press RETURN, the whole logical line under the cursor is handed to the program, minus any trailing spaces. LOGMAP keeps one bit per row, set where a logical line begins. Clearing or opening the screen sets all the bits, so every row starts out as a line of its own.

This explains a few everyday behaviours:

  • Atari BASIC program lines can be up to three rows long, because that is the largest logical line.
  • Insert line (SHIFT-INSERT, code 157) and delete line (SHIFT-DELETE, code 156) work on whole logical lines, and inserting a line can split one logical line into two.
  • Insert character and delete character (CTRL-INSERT and CTRL-DELETE) can make a logical line gain or lose a row.
  • When the bottom line ends, the screen scrolls up by a whole logical line, which may be up to three rows.

3. Margins

LMARGN and RMARGN confine the cursor. Text wraps at the right margin and continues at the left margin of the next row. Changing them gives you a narrow column, or the full 40 characters:

100 POKE 82,10:POKE 83,29:?
110 ? "WITH THE MARGINS SET TO COLUMNS 10 AND 29, TEXT WRAPS INSIDE A NARROW COLUMN."
120 POKE 82,2:POKE 83,39:?

Two things to know, both visible in our test:

  • The change takes effect at the next new line. The PRINT at the end of line 100 moves to a fresh row that starts at the new margin. Without it, the first row of the paragraph begins at the old margin.
  • The editor does not word-wrap. Words break wherever the margin falls ("COLUMNS 10 AND 2" / "9, TEXT"). For tidy paragraphs, split the text into words yourself and check the remaining width with COLCRS.

Both margins are reset to 2 and 39 by RESET.

4. Tab stops

The TAB key, or CHR$(127) in a PRINT, moves the cursor to the next tab stop in the current logical line. Stops are kept in TABMAP: 15 bytes, one bit per position in a 120-character logical line. The leftmost bit (128) of the first byte is position 0, and the rightmost bit (1) of the last byte is position 119. Opening the screen fills every byte with 1, giving stops at 7, 15, 23, 31, 39 and so on. Positions count from the start of the logical line, so on the second row of a long line, 47 is column 7 again.

In our test, ? "A";CHR$(127);"B";CHR$(127);"C";CHR$(127);"D" put the letters at columns 2, 7, 15 and 23. To use your own stops, clear the map and set the bits you want. Position p lives in byte 675+INT(p/8), with bit value 2^(7−(p MOD 8)):

40 FOR I=675 TO 689:POKE I,0:NEXT I
50 POKE 676,8:POKE 678,128
60 ? :? "CUSTOM STOPS AT 12 AND 24:"
70 ? "NAME";CHR$(127);"SCORE";CHR$(127);"LEVEL"
80 ? "ALICE";CHR$(127);"1200";CHR$(127);"3"
90 ? "BOB";CHR$(127);"850";CHR$(127);"2"

Position 12 is byte 676, value 8 (12 MOD 8 = 4, so bit 3). Position 24 is byte 678, value 128. The three rows came out in perfect columns at 2, 12 and 24. From the keyboard, SHIFT-TAB sets a stop at the cursor (code 159) and CTRL-TAB clears one (code 158). There is no "clear all" key, but the FOR loop does the job. If no stop is left on the line, TAB moves to the start of the next line. Stops are reset whenever the screen is reopened, for example by GRAPHICS 0.

Compare the comma in PRINT: BASIC's comma uses fixed print zones of PTABW (location 201) columns and ignores TABMAP entirely.

5. Showing control codes: DSPFLG

Normally, PRINTing code 125 clears the screen and 28 moves the cursor up. With DSPFLG (766) set to any non-zero value, the editor displays every control code except RETURN as its symbol:

130 POKE 766,1:? "CONTROL CODES SHOWN: ";CHR$(125);CHR$(28);CHR$(30);CHR$(253):POKE 766,0

That is how a program can LIST code containing cursor or clear-screen characters without the listing wrecking the display. For a single character, CHR$(27) (ESC) in front does the same job.

6. The cursor

CRSINH (752) set to 1 hides the cursor and 0 shows it. The Operating System User's Manual points out two catches:

  • The change only appears at the next output to the screen. To make it immediate, print something harmless such as a cursor-up then cursor-down (? CHR$(28);CHR$(29);).
  • CRSINH is cleared by RESET, by BREAK, and by every OPEN of the screen, including each GRAPHICS statement. Set it again after GRAPHICS.

You can move the cursor directly by POKEing ROWCRS and COLCRS, which is what POSITION does. A POKE to 85 that leaves the row alone is a quick TAB substitute (see Converting Microsoft BASIC and Applesoft Listings to Atari BASIC).

7. The split-screen text window

In GRAPHICS 1 to 8 without the +16, the bottom four rows are a text window run by the editor, while the upper area belongs to the display handler (S:). The two have separate cursors:

  • ROWCRS and COLCRS position the graphics cursor (PLOT, DRAWTO, PRINT #6, LOCATE).
  • TXTROW (656) and TXTCOL (657) position the text window cursor, with row 0 at the top of the window.
  • BOTSCR (703) reads 4 in a split screen and 24 in full-screen text.

So POSITION in a graphics mode moves the graphics cursor, not where PRINT will appear. To print at a particular place in the window, POKE TXTROW and TXTCOL:

10 GRAPHICS 3:COLOR 1:PLOT 0,0:DRAWTO 39,19
20 POKE 656,2:POKE 657,10:? "ROW 2, COLUMN 10";
30 GOTO 30

Note the semicolon at the end of the PRINT. A RETURN on the bottom row of the window scrolls it.

Troubleshooting

  • Margins seem to be ignored: you changed them mid-line. Print a RETURN after the POKEs.
  • TAB jumps to the next line: there is no stop left on the current line. Check TABMAP, or note that GRAPHICS 0 reset it.
  • Hidden cursor reappears: a GRAPHICS statement, BREAK or RESET cleared CRSINH. Set it again.
  • Text window output appears in the wrong place: you set ROWCRS/COLCRS (the graphics cursor). Use 656–658.
  • Output pauses for no reason: CTRL-1 was pressed, setting SSFLAG. Press CTRL-1 again, or POKE 767,0.

Further reading

  • Atari, Inc., Operating System User's Manual (1982): Screen Editor (E:) and the display data-base variables (B1–B16, B27).
  • Ian Chadwick, Mapping the Atari: locations 82–86, 656–658, 675–693, 703, 752 and 766–767.
  • On this site: ATASCII and Keyboard Codes, Self-Modifying Atari BASIC (the editor's forced-read mode), CIO and IOCBs.

Credits