C-128 Screen Editor Escape and Control Sequences C-128 Programming Secrets McGraw/Hill The C-128's screen editor system is much more comprehensive than that of previous PET/CBM computers. Whereas the older screen editors provided only minimal operations, the C-128's screen editor has over 30 special functions that make editing a program (or text, for that matter) a breeze. Through the use of the ESC key in combination with another character, a user can execute such complex screen-editing operations as line insertion or deletion, partial line or screen erasures, cursor selection, and tab settings. Most of these functions, except where noted, apply to both the 80- and 40-column text screens. Screen editor escape sequences save programming time for BASIC 7.0 and machine language programmers, too. The escape code --CHR$(27) in BASIC 7.0-- can be included along with another character within a string; when the string is printed to the screen, the desired editing action occurs. For example, the simple string CHR$(27) + "@" ($1B$40 in hexadecimal) erases the screen, starting at the current cursor position. It is much quicker, and shorter than a BASIC loop like FOR I=S TO 2023: POKE I,0: NEXT. Such simplifications make the C-128's BASIC 7.0 a very effective programming language, because the screen editor routines do much of the programmer's work. C-128 programs therefore don't necessarily require the rigor and tedium of machine-code programming. Besides these escape functions, the C-128 screen editors also use several control characters that engage special functions. The descriptions of these screen editor codes often refer to logical and physical screen lines. A physical screen line is simply one actual line, 40 or 80 columns, depending on which editor is currently being used. In contrast, a logical line refers primarily to lines displayed by the BASIC LIST command. These lines can be either one or two physical lines long in 80-column mode, or up to four physical lines long in 40-column mode. Many editor escape sequences operate on logical lines and may actually affect several physical lines, especially when dealing with lines of BASIC 7.0 text. However, text printed to the screen can usually be regarded solely in terms of physical lines. Editor Escape Sequences ESC-A decimal 27,65 hex $1B,$41 : The ESC-A sequence enables auto-insert mode. When auto-insert is enabled, every time a character is entered in the middle of a screen line all characters are moved to the right one position. This mode is disabled by ESC-C. ESC-B decimal 27,66 hex $1B,$42 : The ESC-B sequence sets the bottom of the current screen window at the current cursor position. When defining a screen window using ESC sequences, an ESC-B sequence sets the current cursor position as the lower right corner of the desired window. If the cursor position is not in the proper column when an ESC-B is generated, the window will not be of the proper width. ESC-C decimal 27,67 hex $1B,$43 : The ESC-C sequence merely turns off the auto-insert mode enabled by ESC-A. ESC-D decimal 27,68 hex $1B,$44 : The ESC-D sequence deletes the line on which the cursor is currently positioned. When a BASIC listing is being edited, ESC-D keystrokes will delete a complete line of BASIC text from the screen. The ESC-D does not delete the line from the program resident in memory, but merely removes it from the current screen display. ESC-E decimal 27,69 hex $1B,$45 : The ESC-E sequence disables cursor flashing. The cursor then appears as a solid block. ESC-F decimal 27,70 hex $1B,$46 : The ESC-F sequence enables cursor flashing. ESC-G decimal 27,71 hex $1B,$47 : The ESC-G sequence allows a "bell" tone to be generated whenever ESC-G is encountered. The tone emanates from the monitor or television, as the C-128 has no internal sound producing device. ESC-H decimal 27,72 hex $1B,$48 : The ESC-H sequence disables the production of a bell tone whenever an ESC-G is encountered. ESC-I decimal 27,73 hex $1B,$49 : The ESC-I sequence inserts a blank line. The screen line containing the cursor is blanked, while the text of that line is copied to the next screen line. ESC-J decimal 27,74 hex $1B,$4A : The ESC-J sequence moves the cursor to the start of the current logical screen line. ESC-K decimal 27,75 hex $1B,$4B : The ESC-K sequence moves the cursor to the end of the current logical screen line. ESC-L decimal 27,76 hex $1B,$4C : The ESC-L sequence enables text to be scrolled off the screen. ESC-M decimal 27,77 hex $1B, $4D : The ESC-M sequence prevents text from scrolling off the screen. When this non-scroll mode is enabled, a line that normally "pushes up" the rest of the text screen is instead displayed on the top screen line. ESC-N decimal 27,78 hex $1B,$4E : The ESC-N sequence only applies to the 80-column screen. It returns the screen to normal, disabling the reverse-video screen display. ESC-O decimal 27,79 hex $1B,$4F : The ESC-O sequence cancels quote mode (where cursor movements show up as special graphics characters within strings), insert mode, and reverse-character mode. ESC-P decimal 27,80 hex $1B,$50 : The ESC-P sequence erases text from the current cursor position to the beginning of the logical (not physical) screen line. ESC-Q decimal 27,81 hex $1B,$51 : The ESC-Q sequence erases text from the current cursor position to the end of the current logical line. ESC-R decimal 27,82 hex $1B,$52 : The ESC-R sequence applies only to 80-column screens. This function "flips" the screen colors, exchanging the background color for the character color. ESC-N restores the screen to its normal color sequence. ESC-S decimal 27,83 hex $1B,$53 : The ESC-S sequence applies to 80-column screens. This function causes the block cursor to be displayed. The block cursor can be changed to an underline cursor by using the ESC-U sequence. ESC-T decimal 27,84 hex $1B,$54 : The ESC-T sequence sets the top of the current screen window at the current cursor position. When a screen window is being defined using ESC sequences, an ESC-T sequence defines the current cursor position as the upper left corner of the desired window. ESC-U decimal 27,85 hex $1B,$55 : The ESC-U sequence causes the underline cursor to be displayed; it applies only to 80-column screen. The ESC-S function will switch the cursor to a block. ESC-V decimal 27,86 hex $1B,$56 : The ESC-V sequence scrolls the screen up one line. Text scrolling off the top line of the screen is not recoverable by executing the scroll-down function. ESC-W decimal 27,87 hex $1B,$57 : The ESC-W sequence scrolls the screen down one line. Text scrolling off the bottom of the screen is not recoverable by executing the scroll-up function. ESC-X decimal 27,88 hex $1B,$58 : The ESC-X sequence toggles between 40- and 80-column video output. It exchanges local screen editor variables at $E0-$F9 with those saved at $0A40 ; the TAB stop and line-wrap bit maps at $0354-$0361 are exchanged with those saved at $0A60. ESC-Y decimal 27,89 hex $1B,$59 : The ESC-Y sequence sets the default TAB stops. Each TAB is eight spaces. ESC-Z decimal 27,90 hex $1B,$5A : The ESC-Z sequence clears all TAB stops. When the TAB key is pressed after an ESC-Z sequence has been generated, one TAB keystroke will move the cursor to the end of the physical screen line. Editor Control Characters CTRL-B decimal 2 hex $02 : The CTRL-B character applies only to the 80-column screen and turns on the 8563 underline attribute. This underlining can be disabled by a CHR$(130)(hex $82) character. CTRL-G decimal 7 hex $07 : The CTRL-G character corresponds to the ASCII BEL character and produces a bell tone in the monitor's speaker when output is enabled by the ESC-G sequence. The bell tone output can be disabled using the ESC-H sequence. CTRL-I decimal 9 hex $09 : The CTRL-I character TABs a preset number of spaces to the right. TABing will not overwrite lines of BASIC text with spaces; each TAB stop can be set or cleared with the CTRL-X character. The ESC-Y sequence sets default TAB stops every eight spaces, while the ESC-Z sequence clears all TAB stops. CTRL-J decimal 10 hex $0A : The CTRL-J character corresponds to the ASCII LF line-feed character; text output occurs on the next screen line after a CTRL-J character is encountered. CTRL-K decimal 11 hex $0B : The CTRL-K character disables character-set switching using the SHIFT/COMMODORE key combination. This code replaces the CHR$(9) code used on previous PET/CBM machines to disable case switching. CTRL-L decimal 12 hex $0C : The CTRL-L character enables character-set switching using the SHIFT/COMMODORE key combination. This code replaces the CHR$(8) code used on previous PET/CBM machines to enable case switching. CTRL-O decimal 15 hex $0F : The CTRL-O character enables the character-flash attribute; it applies solely to the 80-column screen. This attribute can be displayed by a CHR$(143)(hex $8F) character. CTRL-[ decimal 27 hex $1B : The CTRL-[ character is merely the escape character. This control combination and the escape key both produce the same PETASCII character. CHR$(130) hex $82 : CHR$(130) has no corresponding control-key character. It disables the underline atrribute in 80-column mode that was enabled by CTRL-B. CHR$(143) hex $8F : CHR$(143) has no corresponding control-key character. It disables the character-flash attribute in 80-column mode that was enabled by CTRL-O. Dave Kline 07/01/00