Commodore‎ > ‎

Escape Codes

A nice thing about the CBM 8-bit computers is they have a full-screen text editor.  If you "upgraded" from CBM to a 16/32-bit DOS machine, you were probably shocked by the primitive text editing on those "better" machines.  Like many text editors, the CBMs have several control codes for things like cursor movement and font changes (color, underline, flash, reverse, font selection).  These codes are identical in both ASCII-X and PETSCII character sets because they are "non-printing" characters.  Importantly, those are each one character (byte) and except for a few features, like color and flash, they are supported in all the CBM models.  Most of them are entered by pressing two keys simulatiously (for example, hold down Control and press R).
 
Some of the later machines (CBM-II series, TED series, C128) offer more advanced text editing, but since virtually all of the 8-bit control codes were used, these machines used a two character (two-byte) escape sequences for the new features.  They're called ESC codes for short.  They almost always begin with the ESC key and end with a letter of the alphabet.  Unlike control-codes, the escape codes need to be entered by pressing each of the two keys seperately in sequence.  The ESC codes are fairly compatible between machines that actually support ESC codes at all.  They're listed below with differences noted.
 
Key Sequence
Code Bytes
Machines
Function Note(s)
Dec. Hex. CBM-II TED C128
HOME HOME 19 19 13 13 + + + Disable window (access full-screen) 
ESC ESC 27 27 1B 1B + + Clear quote and (manual) insert modes
ESC @ 27 64 1B 40 + Clear to end of screen 
ESC A 27 65 1B 41 + + + Enable Auto-Insert mode
ESC B 27 66 1B 42 + + + Set Bottom-right corner of window
ESC C 27 67 1B 43 + + + Cancel Auto-Insert mode
ESC D 27 68 1B 44 + + + Delete logical line (lines below move up) Logical line may span multiple physical lines
ESC E 27 69 1B 45 + + Disable cursor flashing
ESC F 27 70 1B 46 + + Enable cursor Flashing
ESC G 27 71 1B 47 + + Enable ASCII Bell (Control-G)
ESC H 27 72 1B 48 + + Disable ASCII Bell
ESC I 27 73 1B 49 + + + Insert a blank line (others move down)
ESC J 27 74 1B 4A + + + Move to start of line
ESC K 27 75 1B 4B + + + Move to end of line On C128, moves past last character; others onto last
ESC L 27 76 1B 4C + + + Enable screen scrolling
ESC M 27 77 1B 4D + + + Disable screen scrolling Cursor will move to top row if trying to go past last row
ESC N 27 78 1B 4E + + Normal (non-reverse) video mode On C128, only applies to 80-column (VDC) screen
ESC N 27 78 1B 4E   +   Normal window (access full-screen)  Normal 40x25 window (also clears the screen)
ESC O 27 79 1B 4F + + + Clear quote, reverse, (manual) insert modes On CBM-II series, it also prints an O (bug)
ESC P 27 80 1B 50 + + + Clear to start of line
ESC Q 27 81 1B 51 + + + Clear to end of line
ESC R 27 82 1B 52 +   + Reverse video mode  On C128, only applies to 80-column (VDC) screen 
ESC R 27 82 1B 52   +   Reduced window (for smooth scrolling?)  38x23 window (also clears the screen)
ESC S 27 83 1B 53 + + Solid (block) cursor Normal (the alternate is underline cursor)
ESC T 27 84 1B 54 + + + Set Top-left corner of window
ESC U 27 85 1B 55 + + Underline cursor normal is solid block
ESC V 27 86 1B 56 + + + Scroll window contents up 1 line Physical line; may chop a logical line
ESC W 27 87 1B 57 + + + Scroll window contents down 1 line Physical line; may chop a logical line
ESC X 27 88 1B 58 + Exchange editor Switch between 40 and 80 column screens
ESC Y 27 89 1B 59 + Set default tab stops One every 8 characters
ESC Z 27 90 1B 5A + Clear all tab stops
 
Some interesting things you might notice, or be curious about.  The editor has two forms of insert mode.  Manual insert is when you press Shift+Del (INS) to manually open space for text; this is needed because the editor is (by default) in "overwrite" mode.  Other CBM machines (those without ESC codes) only support manual insert mode.  This mode can be convient for BASIC programmers because it allows control characters (like Control+S to HOME the cursor) to be inserted into text strings.  That is, manual insert mode works very similar to quote mode: most control codes will print a special character in reverse-font video.  However, this also means cursor keys will not function (they print special reverse-characters too).  Manual insert mode can be canceled in a few ways: type enough characters to fill up all the inserted spaces, press (Shift) Return to go to the next line, or (where available) ESC O or ESC ESC.
 
The codes ESC O and ESC ESC perform almost the same action.  They both cancel the pesky quote and manual insert modes.  However ESC O also disables reverse font.  Neither cancels Auto-insert mode.
 
Auto-insert mode is the default for most modern text editors.  It is not the default for any CBM machine.  This is probably because it can be slow.  It works fast when editing inside a line because the editor will look for a "next character" on the same line which is usually only 1 character away (very quick test).  But when the computer wants to print on a blank line (or at the end of line already containing text) it has to check all remaining character on the line to be sure nothing needs to be shifted.  So the first character on a blank line requires 79 tests (most video displays), the second character on a line needs 78 tests, etc.  Thus several hundred tests can be performed to print a single line.  This becomes obviously slow when the computer needs to display many lines (like listing a program or disk directory).  Anyway, the only way the editor can cancel auto-insert mode is ESC C (note that BASIC clears auto-insert mode when you RUN a program).
 
On all CBM machines, the editor can be placed into reverse-text mode with Control+R (or sometimes Control+9).  This makes only the following characters appear in reverse font.  The video chip in the CBM-II series (6548?) and the 80-column display chip of the C128 (8563/8 VDC) feature a reverse screen mode activated with ESC R.  This reverses all characters on the screen; it will even re-reverse characters that were formerly in reverse-font (so they appear 'normal').  I don't know what use this would have on the CBM-II series which lack color, but on the C128 this allows each character to have a different background color (however, all text will now have the same foreground color).  This special reverse-video mode is canceled with ESC N.
 
On the TED series, ESC R and ESC N perform an operation completely incompatible with the CBM-II series and C128.  ESC R sets up a 38x23 text window (one character of padding on all four sides); I'm guessing this is to help with smooth scrolling?  ESC N sets the editor for normal full-screen 40x25 text window.  This action is almost the same as HOME HOME.  The difference is that ESC N (also ESC R) erase all text on the screen.
 
HOME HOME clears any active window and allows full-screen editing.  Yes, CBM does windows!  ESC T will mark the current cursor position as the top-left corner of a window, and ESC B will mark the current cursor position as the bottom-right corner.  This can be useful when editing to keep important information from scrolling off-screen as new lines are entered.  It can also be useful in a program to implement, umm, windows.  The only issue there is you would probably want some way to "memorize" the old/current screen contents before rendering a new window and then some method to restore the screen when you want to "close" the window.
 
Interestingly, the TED series does not support the ASCII Bell (Control-G) even though it has a sound chip.  Not suprisingly, the related ESC G and ESC H do nothing on these machines.

© H2Obsession, 2014
Comments