home *** CD-ROM | disk | FTP | other *** search
- zavt - enhanced MS-DOS ansi/avatar console driver
-
- SYNOPSIS
- Include in \config.sys the line
- device=zavt.sys
-
- DESCRIPTION
- Zavt.sys is a console driver which understands ANSI control sequences
- as well as Avatar level 0. It has several advantages over most other
- drivers.
-
- 1. It supports any display mode the BIOS can set up (see below)
- 2. It can be addressed by two different names so the default
- output can be left in raw mode (see below)
- 3. The blasted bell is now 1/9 second
-
- 4. Any DOS console entry may make use of a full-screen editor
-
- One trivial advantage is the allowing of backspaces across the left
- margin. I don't know what problems this may create, but it is nice
- for the command line.
-
- COMPATABILITY
- -------------
-
- Zavt gets all its information about the console from the BIOS data
- area - nothing is assumed other than that modes 0-3 and 7 are text
- modes. Other drivers assume your screen is 25 lines long, and that
- the video card is always left on page 0. This is a safe assumption
- most of the time, but bad practice. AutoCAD 2.5 for example is more
- efficient in switching between graphics and text when you configure
- it to write text on page one and use page 0 for its graphics, but
- will not give a usable text page with other drivers. Nansi has code
- in it to switch an EGA to 43 line mode, or an AT&T display to 50 line
- mode, but if you switch back by any means other than Nansi's own
- facilities, Nansi continues to assume 43 lines. Zavt responds to
- changes in display size very well. If you switch to a mode with more
- lines on screen (not by means of the driver - system specifics I
- leave to other software), Zavt will use them immediately. If you
- switch to a mode with fewer lines and the cursor is off the new
- screen, the next scroll will bring it along with the screen region
- around it into view. The best way to get a feel for this if you have
- an EGA is to play with the xxLINE.COM programs included. The names
- are for EGA, and will work for VGA, but will give you more lines than
- advertised.
-
-
- DEVICE DRIVERS
- --------------
-
- When you, for example, type
- C:> type foo.txt
- COMMAND.COM opens the file foo.txt, reads it, and writes it to
- the console driver, which puts it up on the screen. DOS has
- two ways of writing to the console driver:
-
- raw/binary mode: where the device driver is called once for
- a group of characters letting the device driver
- handle them all at once, or
-
- cooked/ASCII mode: where DOS calls the device driver once for each
- character to be sent, expanding any tabs.
-
- Raw mode is much faster as the device driver is called fewer
- times requiring less overhead all together. However, you lose
- the ability to abort in the middle of output. If you TYPE a large
- file, COMMAND.COM sends it to the console driver 32K at a time, so
- if you Ctrl-Break, you'll have to wait until the first 32K have been
- displayed. DOS also no longer expands tabs, but this is easily
- handled by the device driver. Run RAW.COM then type
- C:> dir /w
- and rather than tabs between filenames, the tab character is displayed.
- Run COOKED.COM before continuing.
- When DOS wants input from the console (such as when reading input
- for a filter such as MORE), raw and cooked mode also apply. In
- cooked mode, DOS will echo each character you enter, and interpret
- the cursor keys and f-keys allowing you to edit what you enter. DOS
- will also end entry when you hit CR, returning what you typed up
- to that point, even if more characters were requested. To demonstrate
- this, type
- C:> more
- and type some gibberish. DOS is requesting 4096 characters, but as soon
- as you type <enter>, entry ends and more prints out what you typed.
- Press f6 and enter to end.
-
- When the console is in raw mode however, DOS does not echo
- characters, check for ^C, ^S, or ^P, and asks of the driver however
- many characters the calling program wants. The driver has no choice
- but to oblige, and without feedback, the computer seems frozen. Run
- RAW.COM included in this archive, then try MORE. Unless you type 4096
- characters, with a ^Z included to flag end of file, the computer is
- for all intents and purposes crashed.
-
- So while setting the console to raw mode lets you display text
- *MUCH* faster, you have a potential trap if you run into software
- which requests data from the default input. The solution would seem
- to be to write in raw mode, and read on cooked mode, but DOS will
- speak to a device driver in only one way at a time. The solution?
- Use a second device driver. The console is normally addressed as
- CON, but Zavt has a secondary handler which allows it to be addressed
- as KEYB as well. The problem is how to change the default input to
- KEYB. CTTY will change both the default input, but it will change
- the default output and error output as well. In DOS versions up to
- 3.3, CTTY has a bug which will allow you to
- C:> CTTY <KEYB
- DOS will say 'Invalid Device' but otherwise acts as expected. DOS
- 4.0 users will have to live with the risk (it's not that great).
-
- Once the default input is set to the alternate handler, you can
- go ahead and set the default output (and with it, the error output)
- to raw mode.
-
- ANSI (taken from documentation for NANSI 2.4)
- ----
-
- While putting text up on the screen, zavt.sys keeps a lookout for
- the escape character (chr(27), known as ESC); this character signals
- the start of a terminal control sequence.
- Terminal control sequences follow the format
- ESC [ param; param; ...; param cmd
- where
- ESC is the escape character chr$(27).
- [ is the left bracket character.
- param is an ASCII decimal number, or a string in quotes.
- cmd is a case-specific letter identifying the command.
- Usually, zero, one, or two parameters are given. If parameters
- are omitted, they usually default to 1. Spaces are not allowed
- between parameters.
-
- For example, both ESC[1;1H and ESC[H send the cursor to the home
- position (1,1), which is the upper left.
-
- Either single or double quotes may be used to quote a string.
- Each character inside a quoted string is equivalent to one numeric
- parameter. Quoted strings are normally used only for the Keyboard
- Key Reassignment command.
-
- ESCAPE.COM from PC-Magazine is included as an easy way to send
- these control sequences, sending the ESC and [ followed immediately
- by whatever is given to it on the command line.
-
- Control Sequences
- The following table lists the sequences understood by nansi.sys.
- Differences between nansi.sys and the standard ansi.sys are marked
- with a vertical bar (|).
-
- Cursor Positioning
- Short Long name Format Notes
- CUP cursor position ESC[y;xH Sets cursor position.
- HVP cursor position ESC[y;xf Same as CUP; not recommended.
- CUU cursor up ESC[nA n = # of lines to move
- CUD cursor down ESC[nB
- CUF cursor forward ESC[nC n = # of columns to move
- CUB cursor backward ESC[nD
- DSR Device Status, Report! ESC[6n Find out cursor position.
- CPR Cursor Position report ESC[y;xR<CR> Response to DSR, as if typed.
- SCP Save Cursor Position ESC[s Not nestable.
- RCP Restore Cursor Position ESC[u
-
- Editing
- EID Erase in Display ESC[J Clears screen to cursor
- EID Erase in Display ESC[1J Clears screen from cursor.
- EID Erase in Display ESC[2J Clears screen.
- EIL Erase in Line ESC[K Clears to end of line.
- EIL Erase in Line ESC[1K Clears line up to cursor.
- EIL Erase in Line ESC[2K Clears entire line.
-
- IL Insert Lines ESC[nL Inserts n blank lines at cursor line.
- DL Delete Lines ESC[nM Deletes n lines, including cursor line.
- IC Insert Characters ESC[n@ Inserts n blank chars at cursor.
- DC Delete Characters ESC[nP Deletes n chars, including cursor char.
-
-
- Mode-Setting
- SGR Set Graphics Rendition ESC[n;n;...nm See character attribute table.
- SM Set Mode ESC[=nh See screen mode table.
- RM Reset Mode ESC[=nl See screen mode table.
-
- IBMKKR Keyboard Key Reass. ESC["string"p
- The first char of the string gives the key to redefine; the rest
- of the string is the key's new value.
- To specify unprintable chars, give the ASCII value of the char
- outside of quotes, as a normal parameter.
- IBM function keys are two byte strings; see the IBM Basic manual.
- For instance, ESC[0;59;"dir a:";13;p redefines function key 1 to
- have the value "dir a:" followed by the ENTER key.
- If no parameters given, all keys are reset to their default values.
-
- Character Attributes
- The Set Graphics Rendition command is used to select foreground
- and background colors or attributes.
- When you use multiple parameters, they are executed in sequence, and
- the effects are cumulative.
- Attrib code Value
- 0 All attributes off (normal white on black)
- 1 Bold
- 2 Bold off
- 4 Underline
- 5 Blink
- 7 Reverse Video
- 8 Invisible (but why?)
- 30-37 foregnd blk/red/grn/yel/blu/magenta/cyan/white
- 40-47 background (no effect in graphics modes)
-
- Screen Modes
- The Set Mode and Reset Mode sequences both accept one parameter,
- with the following values:
- Mode Code Value (same for Set and for Reset)
- 0 text 40x25 Black & White
- 1 text 40x25 Color
- 2 text 80x25 Black & White
- 3 text 80x25 Color
- 4 bitmap 320x200 4 bits/pixel
- 5 bitmap 320x200 1 bit/pixel
- 6 bitmap 640x200 1 bit/pixel
- 13 EGA graphics 320x200 4 bits/pixel
- 14 EGA graphics 640x200 4 bits/pixel
- 15 EGA [ IBM Monochrome display 640x350 2 bits/pixel?]
- 16 EGA graphics 640x350 4 bits/pixel [with full 256K]
-
- Mode Code Set Reset
- 7 *Wrap at end of line No wrap at EOL
- 45 *Graphics Cursor No simulated graphics cursor
-
- Note: Modes other than the two set codes are BIOS display modes
- and modes not listed which may be supported by new cards
- (VGA for example) can also be selected by these functions.
-
- [ * = default ]
-
- Little Dead Blobs
- If you are using a graphics mode, and the cursor leaves little
- dead blobs behind when it moves, you are probably using a program
- which bypasses DOS (naughty, naughty). It might help to tell
- Nansi to turn off its graphics cursor by sending the string
- ESC [ = 45 l
- (The last character in that string is a lowercase "L".)
-
-
- AVATAR
- ------
-
- While putting text up on the screen, Zavt.sys also looks out for
- ^V, ^Y, ^L and ^P. The following is taken from documentation for
- OANSI.
-
-
- ALIASING
-
- In an Avatar sequence, the DLE character is "escaped."
-
- That's a scheme to let you use characters normally not available
- to an editor.
-
- DLE Hex=10 Decimal=16
-
-
- Here are some examples of character aliases:
-
- Hex Decimal Real character
- ----------------------------------
- 10 83 16 131 3 (^c)
- 10 9a 16 154 1a (^z)
- 10 90 16 144 10 (^p)
- 10 10 16 16 10 (^p)
-
-
- When an Avatar terminal runs into a DLE character, it grabs the next
- available byte and strips off the high-order bit.
-
-
-
- CONTROL CODES
-
-
- Command Description
- -----------------------------------------------
-
- ^v ^a <a> attribute
- The "<a>" is a single
- byte. The value of this
- attribute byte corresponds
- to the video attributes
- used by IBM on their CGA
- monitors. (Intense video
- is supported, black-on-black
- is not.)
-
- ^v ^b blinking on
- blinking is turned off
- by the next "^v^a"
- command
-
- ^v ^c move cursor up a line
-
- ^v ^d move cursor down a line
-
- ^v ^e move cursor left a line
-
- ^v ^f move cursor right a line
-
- ^v ^g clear to end of line
-
- ^v ^h <r> <c> set cursor position
- These are 1-based numbers
- with the "Y" (row) coordinate
- first. The upper left of the
- display is "1,1." The start
- of the second line would be
- "2,1."
-
- ^l set current attribute to cyan
- on black, home cursor and
- clear screen
-
-
- Avatar is a binary based protocol while ANSI is ASCII based.
- As a result, control codes which may have other meanins may
- end up part of an Avatar control sequnce. This is not a problem
- except when something tries to interpret a control code without
- realizing it is to be preserved. The only situation where this
- occurs that is of any concern is with DOS. If the console is in
- cooked mode, any ^i will become some number of spaces as DOS
- considers it to be a tab. This will corrupt any Avatar code with
- a ^i in it. The solution is to set the console to raw mode, which
- is the reccommended setup for speed as well.
-
-
- Full-Screen input
- -----------------
-
- Code for the full-screen editor was mostly taken from PC-Magazine's
- DOS-EDIT and thus the mechanics are virtually identical. Being part
- of the console handler rather than a TSR however allows the editor
- to be used for any DOS input rather than only the command line.
-
- For those not familiar, pressing cursor-up on the command line
- with DOS-EDIT loaded would move the cursor up one line and put
- you into the full-screen editor. From there, the special keys are
-
- Escape leave the fullscreen routine
- Cursor keys move the cursor accordingly
- Home move the cursor to the left margin
- End leave the full-screen routine, putting what is
- on the screen under and following the cursor
- into a buffer to be read as keyboard input
- PgUp move the cursor to its original column
- PgDn delete all characters on and following the cursor
- Insert toggle insert/delete mode
- Delete delete character to left of cursor and move text
- under and to the right of the cursor one space left
- Enter same as End but adds a CR to the end of the data
-
- The alpha-numeric keys print to screen while control codes
- may or may not depending on whether or not they have other purposes.
- Alt-<num> input always prints however, so it is possible to queue
- a sequence of strings by putting typing them on one line and typing
- 13 on the numeric keypad while holding Alt in between each string.
-
- Since ZAVT treats all console input the same, using cursor-up
- as the full-screen key may preclude software such as 4DOS which
- uses the key for its own purposes. In ZAVT without keyboard remapping
- Ctrl-PgUp is used in its place as it is reasonably obscure but
- still accessible. In ZAVT with keyboard mapping, there is no default.
- When a key maps a double-null, that is taken as the hotkey. Thus
- to define Ctrl-PgUp as the hotkey with ESCAPE.COM, type
- c:>ESCAPE 0;132;0;0p
-
- BUGS
- The Set Mode and Reset Mode code 45 was chosen to match what
- was used in NANSI 2.4 which in turn was chosen without even
- looking to see if there were established codes for those functions.
-
- Insert and delete character do not work in graphics modes
- because BIOS does not include a scroll left/right function.
-
- Cursor Position Report has a carriage return in it, which is what
- ansi.sys does, but is nonstandard.
-
- Avatar RLE doesn't handle control characters - it assumes whatever
- you give it to repeat is printable and prints it, also assuming
- the repeat will not result in wrapping past the right margin.
-
- Wrap around left margin is nice, but nonstandard.
-
- NOTE
- While I polished off this code and added some of my own, the bulk
- of it was written by Daniel Kegel, and Thomas Hanlin III to
- whom credit is due. My distribution policy is the same as for the
- formentioned authors' drivers, which is as follows as taken from
- the documentation for NANSI24.
-
- This program and all files associated with it are hereby placed
- in the public domain, and thus may be freely copied and distributed.
-
- If you really like this program, either
- (a) improve it, and place your improvements in the public domain,
- (b) write a neat program which uses Zavt's unique speed, and
- place your program in the public domain,
- (c) tip the author (Tip; contraction for "To Inspire Programmer";
- traditionally, a contribution of $5 per copy), or
- (d) resolve to become a better human being in the future.
-
- Any problems or suggestions can be made to the 'author', Luns Tee
- 32 Thyra Ave.
- Toronto, Ontario, M4C-5G5
- Canada
-
-
- FOR PROGRAMMERS
-
- If the code seems to be a mess, that's because it is. Code from ZANSI
- has been juggled around so as to minimize the number of JMPs that are
- not JMP SHORT. Just a few hints:
- Search for "90" in the .LST files. If any follow a JMP
- instruction, make the JMP a JMP SHORT as these are NOPs to pad
- the size difference between the two variants of this instruction.
- When writing anything which writes to the console, use
- an IOCTL call to get the driver's attributes, save them, and set
- the console to raw mode. Do not write to the console by calling
- Int 21h function 2 once for each character (it's not that uncommon)
- but rather function 40h for each string. Buffering strings larger
- than about 10 characters starts diminishing returns. Just remember
- to return the console to its original state before exiting.
-
- The file ZAVT.MAK has switches for Turbo Assembler and not
- Microsoft MASM which NANSI was compiled under. The .MAK file itself
- is for Microsoft's MAKE utility however.
-
- FILES
-
- ZAVT*.ASM - console driver source files
- ZAVT.MAK - make file for ZAVT.SYS
- ZAVT.SYS - full-featured driver
- ZAVTNK.SYS - driver with keyboard remapping disabled
- FONTS.ZIP - assortment of ega/vga fonts
- RAW.COM - program to set console to raw
- COOKED.COM - and cooked mode
- ESCAPE.COM - program to send escape sequences to console
- ZAVT.DOC - this file
-