home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / NNANS593.ZIP / HOWTO.DOC < prev    next >
Text File  |  1993-01-15  |  9KB  |  198 lines

  1.              How To Write to the Display
  2.  
  3.  
  4.                A quick NNANSI tutorial
  5.  
  6.  
  7. The purpose of this tutorial is to illustrate the various ways
  8. programs can write to the display. There are several parts to this
  9. puzzle: 
  10.  
  11.     DISPLAY MEMORY -- memory mapped video, can be accessed
  12.     directly by applications, but there are drawbacks.
  13.  
  14.     VIDEO BIOS -- "Low level" access to write characters,
  15.     position the cursor, change display modes.
  16.  
  17.     DOS INT 21H SERVICES -- Access display in a device
  18.     independent manner. The display (and keyboard) are device
  19.     "CON". Devices can be accessed in "Cooked" mode, in which the
  20.     keyboard is monitored for ^C and other control characters and
  21.     certain character translations may occur, or in "Raw", or
  22.     binary, mode, which does no translation and is potentially
  23.     much faster. In Cooked mode when the output device is the
  24.     display, single characters are written using calls to INT
  25.     29H. In Raw mode, or for other devices, DOS calls the driver,
  26.     which is a cumbersome process, but allows writing of multiple
  27.     characters.
  28.  
  29.     INT 29H HANDLER -- writes a single character to the display.
  30.     By default (no ANSI driver) it is a simple call to the video
  31.     BIOS.
  32.  
  33.     CON DRIVER -- The console device. Called by DOS and in turn
  34.     calls the video BIOS to write characters.
  35.  
  36.     ANSI DRIVER -- A replacement for the default CON driver which
  37.     provides interpretation of ANSI control codes.     Also
  38.     overrides the "INT 29H" handler to interpret ANSI codes. The
  39.     driver typically calls the VIDEO BIOS for all functions, but
  40.     fast drivers like NNANSI do most of the low level operations
  41.     internally.
  42.  
  43.  
  44. NNANSI has additional features which will be discussed throughout
  45. this tutorial.
  46.  
  47.  
  48. *************Writing Direct to Display***********************
  49.  
  50. Most program originally used DOS calls to write to the display. But
  51. poor performance of DOS and the ANSI.SYS driver led many programmers
  52. to bypass the operating system and write directly to the display. The
  53. standardization of displays hastened the change, and made
  54. "PC-Compatible" the important issue rather than just "MS-DOS
  55. operating system".
  56.  
  57. Programs that use this technique typically (but not always) use the
  58. video BIOS for moving the cursor and clearing the display.
  59.  
  60. This is potentially the fastest technique, and is employed by high
  61. level languages which provide a fast console output. There are
  62. several problems with direct output, however.
  63.  
  64. The video BIOS maintains information about the display in low memory.
  65. This information includes the number of rows and columns, as well as
  66. the display memory start address. Many programs using direct display
  67. writing ignore the row and column information. This typically means
  68. only the top of the display is utilized (typically 43/50 line modes)
  69. or the display is garbled (typically 132 column modes).
  70.  
  71. Most programs ignore the display start address. This can cause
  72. problems in two ways. Some applications use "display pages". When
  73. display pages are in use, the display memory gets divided into
  74. several screens that can be switched back and forth by a single BIOS
  75. command. Programs that ignore the start address always write to page
  76. 0, possibly clobering the display. 
  77.  
  78. NNANSI modifies the start address to implement FAST scrolling. It
  79. attempts to accomodate direct to display programs by reseting the
  80. offset when a program calls the BIOS to either clear the screen or
  81. get the display mode. Programs that do neither of these, or write to
  82. the display after the display has scrolled, will not work with NNANSI
  83. in FAST mode.
  84.  
  85. There is another problem with writing the display directly -- you
  86. cannot redirect output to a file, or more important, to a serial port
  87. for remote operation. The program is locked into the display and is
  88. not portable to other computers or even other PC operating systems.
  89.  
  90.  
  91.  
  92.  
  93. ************Using the Video BIOS*******************
  94.  
  95.  
  96. Again, standardization of the video BIOS made it possible to write
  97. programs using BIOS calls to write to the display. Because of the
  98. cumbersome interface, few programs actually use BIOS calls to write
  99. to the display. But in the absence of an ANSI driver, BIOS calls are
  100. necessary to read or position the cursor or clear the display in
  101. programs that otherwise use the DOS INT 21H interface.
  102.  
  103. The BIOS provides a "TTY Write" function which allows writing
  104. character strings, but does not allow controling the color, and does
  105. not expand tab characters. NNANSI has an option to do ANSI processing
  106. of this BIOS call which will allow setting the color and expanding
  107. tabs. To set the colors using BIOS calls is a messy process because
  108. the only call that writes the character attribute information does
  109. not advance the cursor!
  110.  
  111. One advantage of using the Video BIOS for writing is that the BIOS
  112. always know how to handle the various display modes the video adapter
  113. is capable of handling. It will always correctly write in 132 column
  114. or 50 line modes, for example.
  115.  
  116.  
  117.  
  118.  
  119. **********DOS INT 21H Services**********************
  120.  
  121.  
  122. DOS provides numerious functions for accessing the display (and
  123. keyboard) without much difference in functionality. Most of the
  124. functions are for compatibility with the archaic CP/M operating
  125. system. 
  126.  
  127. We will only consider the "handle" interface, which allows treating
  128. the console (keyboard and display) as a file. You can open, read,
  129. write, and close the console "file". All programs start execution
  130. with three appropriate handles. Handle 0 (corresponding to the C
  131. language stdin) and Handle 1 (corresponding to the C language stdout)
  132. are the console unless redirected on the command line with the "<" or
  133. ">" operators. Handle 2 (corresponding to the C language stderr) is
  134. always (well, almost always) the console. Unless redirection is in
  135. effect, any of the three handles can be used interchangably.
  136.  
  137. Normally, the console device is in "cooked" mode. In cooked mode, tab
  138. characters are expanded, and the keyboard is checked with each
  139. character written for control-C, control-S, and control-P keystrokes.
  140. On input, these keystrokes are not readable, nor is control-Z which
  141. forces the end of file condition.
  142.  
  143. Programs using cooked mode DOS INT 21H services to write to the
  144. display are very portable, but slow. In fact this is the slowest way
  145. to write to the display. In addition, without an ANSI driver loaded,
  146. there is no way to enquire or set the cursor position, change colors
  147. or other display attributes, or clear the display.
  148.  
  149.  
  150. *********ANSI Drivers********************************
  151.  
  152. To make using DOS INT 21H services more palatable, an ANSI driver can
  153. be loaded. With an ANSI driver the program gains the following
  154. abilities: 
  155.  
  156. 1. Change display mode (some drivers allow extended modes)
  157. 2. Clear screen (some drivers allow line clearing, and
  158.     inserting/deleting characters and lines)
  159. 3. Set cursor position
  160. 4. Get cursor position -- cumbersome to use, and not available with some
  161.     drivers such as ANSI.COM and NNANSI as limited function TSR
  162. 5. Change character attributes
  163.  
  164.  
  165. When an ANSI driver is used, the program is portable to any system
  166. that supports ANSI display codes, including DEC VT-100 and later
  167. terminals, and most programs can be run remotely out the COM port
  168. using the CTTY command.
  169.  
  170.  
  171. *********Using INT 29H*******************************
  172.  
  173. This interrupt will always write the character in register AL to the
  174. display. The DOS INT 21H services use this interrupt to write
  175. characters when the console is in Cooked mode. Since the keyboard
  176. check is bypassed, INT 29H is a significantly faster way to write to
  177. the display. When an ANSI driver is loaded, ANSI processing will
  178. occur, but tabs will not be expanded unless NNANSI or some other
  179. extended ANSI driver is used.
  180.  
  181.  
  182. *********Using RAW Mode******************************
  183.  
  184.  
  185. All the previous techniques only write a single character at a time.
  186. A major speed advantage can be gained by using DOS INT21H services
  187. with the console in Raw mode, and by buffering up the characters to
  188. write. In this manner, the ANSI driver gets all the characters to
  189. write at once and overhead is vastly reduced. The NANSI driver, and
  190. its derivatives, such as NNANSI, are particularly enhanced this way,
  191. and will often outperform high level language's "console" drivers.
  192.  
  193. Using raw mode will also prevent DOS from intercepting typed control
  194. characters during printing, which is often an advantage. Note however
  195. that tab expansion will not occur with standard ANSI drivers. The
  196. application needs to expand tabs unless it can be assured the system
  197. is using an enhanced ANSI driver, such as NNANSI.
  198.