Z80 Space-Time Productions Single Board Computer
Technical Support Information

Using ANSI color and cursor controls with your S-T Z80 Computer

Most of you are probably using Hyperterminal in Windows for connecting your Z80 to the world, you are probably pretty well used to seeing black text against a white background. You can change this to include a little color if you like, but it requires some code to reside on your Z80.

Back in the TTY data-terminal days, (there are still a few systems and applications that have these hanging on), some brilliant mind came up with the idea that if we could send some codes to the data terminal or emulating program that would be invisible to the user, changes in cursor position and colors could be sent to the VDT, and some factors about the VDT could be returned to the hosting computer. These were standardized for any data terminals or programs wishing to adhere to the new standard. These codes became part of the American National Standards Institute. In fact, many early PC's CONFIG.SYS files included the line device=ANSI.SYS without ever utilizing it's function. Eventually a few idle minds devised some interesting sequences that would turn your DOS cursor into a Texas flag, blinking this or that, and so forth, but by and large the ANSI sequences were not understood by the masses.

Interestingly enough, the people who created Hyperterminal realized that some people would be using this program to dial into various old mainframes and other such electronic feldergarb, and might actually NEED these ANSI controls in order to correctly connect up. So there are settings to emulate various VT models of terminal, as well as some good old generic ANSI and ANSI/W emulations. You will need to set your program to handle ANSI if you dare wander further into this forrest.

The primary entry portion of these ANSI sequences is something called the Control Sequence Introducer or CSI for short. This is a sequence of characters sent by the host to the VDT and could then be followed by other characters as needed to control things on the screen. The CSI consists of the two characters ESC ($1B) followed by a left bracket "[" ($5B). This would proceed parameters and would sometimes be followed by a terminating character, like "m" ($6D).

In order to use these codes, you will need to create Z80 assembly routines that send these sequences from the Z80 to the host program.

Here is the basic ANSI table of codes:
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; ANSI ESCAPE SEQUENCES
; USED TO CONTROL CURSOR MOVEMENTS AND TO ALTER
; THE FOREGROUND AND BACKGROUND COLORS ON THE
; TERMINAL EMULATOR PROGRAM
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; ESC[yy;xxH - Sets cursor position at xx (0-79) and yy (0-23)
; ESC[H - Homes the cursor (no x or y params sent.
; ESC[nnA - Moves cursor up nn rows
; ESC[nnB - Moves cursor down nn rows
; ESC[nnC - Moves cursor forward nn columns
; ESC[nnD - Moves cursor backward nn columns
; ESC[2J - Clears screen and homes cursor
; ESC[6n - Command for VDT to report its cursor position.
; ESC[row;columnR - The terminal's reply to previous command.
; ESC[K - Erases from cursor to end of current line.
; ESC[1K - Erases from cursor to start of current line.
; ESC[2K - Erases the entire line.
; ESC[J - Erase from current line thru end of screen.
; ESC[2J - Erase from current line thru top of screen.

; ESC[xx;xxm - Where xx is parameters according to:
; 0 - All attributes off
; 1 - Bold on
; 4 - Underscore on
; 5 - Blink on
; 7 - Reverse video on
; Text color $30 BLK, $31 RED, $32 GRN, $33 YEL, $34 BLU, $35 VIO, $36 CYN, $37 WHT
; Bkgd color $40 BLK, $41 RED, $42 GRN, $43 YEL, $44 BLU, $45 VIO, $46 CYN, $47 WHT
;------------------------------------------------------------------------------

These are only the primary codes, there are a large number of other ones out there; a little internet research on your part will reveal a bunch. Here is a link to some more VT / ANSI controls:
VT-100 Terminal Controls
Please let me know if this link goes dead at some point. [Thanks!]

Here is the test program I wrote for using these codes:
ANSI.ASM You may modify this any way you like or just run calls from your existing program to these various color codes, etc.

IMPORTANT: If you execute a CR,LF after a color change command, and don't print any characters in the new desired color first (before the end-of-line terminators), the colors won't change from the previous setting.

Here's a screen shot after the program has run:

I left the screen with this blue background and white text. Something you will notice in the code is that I first command the color settings to BRIGHT. If you don't they will look sickly, especially the yellow. Using the Bright and Dim controls you can effectively achieve 16 different foreground and background colors in Hyperterminal.

I am fumbling with the idea of incorporating these into my new monitor ROM, I think they would look a good deal better with some good colors in the mix. Just out of curiosity sake, I tried some 'undefined' color codes i.e. $39, $3A, $3B, etc. - they simply don't work, evidently no "Easter Eggs" in the software here to exploit. Just stick with the basic colors, I'm sure you'll be happy.

If you have BASIC (either mine or some variant) on your Z80 board, you can use it to send the ANSI CSI and control codes as well.
10 PRINT CHR$(27);CHR$(91);"32m""Hello!"

and so forth. Try experimenting. There are a ton of things you can do with this to spruce up the program output!

Good luck!


Click HERE if you do not see a menu frame to the left.