home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / AVATAR.ZIP / avatar0 < prev   
Encoding:
Text File  |  1995-04-25  |  23.3 KB  |  589 lines

  1. [This is actually FSC-0025 and FSC-0037 combined into one file describing
  2.  the Avatar level 0+ terminal.  level 0 alone is obsolete, so be sure to
  3.  read the second half of this document describing level 0+'s features    ]
  4.  
  5. /*   FSC-0025
  6.  
  7.  
  8.  
  9.                                                         Pittsburgh, PA
  10.                                                         23 August 1988
  11.  
  12.  
  13.  
  14.                              A V A T A R
  15.  
  16.       Advanced Video Attribute Terminal Assembler and Recreator
  17.  
  18.                           George A. Stanislav
  19.  
  20.                                  129/39
  21.  
  22.  
  23.  
  24.                           Historical Overview
  25.  
  26.  
  27. Wynn Wagner III, the author of Opus-CBCS, developed a method of storing
  28. video control codes in a file sent to the Opus caller which was meant as
  29. a replacement of ANSI escape codes. Its main advantages were:
  30.  
  31.         o  The codes are smaller than ANSI, thus needing less disk
  32.            storage space.
  33.  
  34.         o  The codes are in the binary form easily interpreted by the
  35.            computer (ANSI sequences use ASCII).
  36.  
  37.         o  The same file can be sent to callers who do or do not have
  38.            the ability of interpreting ANSI codes - in the former case
  39.            the codes are first translated to ANSI, in the latter they
  40.            are ignored.
  41.  
  42. Because of lack of an appropriate name, Wynn temporarily named the codes
  43. oANSI with the understanding that a better name was needed.
  44.  
  45. When I started working on my TinyTerm communications program, I had the
  46. idea that if Opus-CBCS could send the "oANSI" codes directly over the phone
  47. lines, it would speed up the communications considerably. A typical ANSI
  48. sequence contains 4 times as many bytes as the codes developed by Wynn
  49. Wagner.
  50.  
  51. A phone call to Wynn resulted in two things:
  52.  
  53.         o  TinyTerm can interpret the "oANSI" codes and translate
  54.            them to ANSI, then send them to stdout where they are
  55.            converted to colors by ANSI.SYS.
  56.  
  57.         o  Opus-CBCS, starting with gamma version 1.10.iii, will
  58.            send the codes without converting them to ANSI sequences.
  59.            (It will still send ANSI codes to users without the proper
  60.            terminal software.)
  61.  
  62. I took over the coding of the part of Opus handling the video codes. I
  63. realized the codes were offering us much more power than just translating
  64. them to ANSI escape sequences. I proposed to call the codes AVATAR, the
  65. Advanced Video Attribute Terminal Assembler and Recreator. Wynn readily
  66. accepted the new name.
  67.  
  68.  
  69.  
  70.                      The Two Levels of Avatar
  71.  
  72. Avatar is more than a video attribute controller. It is a protocol which,
  73. if need be, can totally eliminate the interference of line noise. However,
  74. this document is not concerned with the advanced topics of Avatar (which
  75. no program is using as of this writing).
  76.  
  77. A full Avatar session with all its advanced features starts by exchanging
  78. the AVINIT packets. The caller sends a packet which describes the video
  79. capabilities of his/her system. It also contains the caller's name, password
  80. and some other optional information. It also tells the BBS if the user is
  81. calling in person or just emulating a BBS session with an Avatar terminal
  82. program.
  83.  
  84. The called system (the BBS) replies to the AVINIT packet with a packet that
  85. informs the user of his current status, e.g. you can stay till 16:30 GMT,
  86. or you are denied access, or I am processing mail now but you can call back
  87. at 10:43 GMT, etc.
  88.  
  89. Until such AVINIT packets are exchanged, only the Avatar commands that were
  90. part of the original oANSI codes can be sent from the BBS to the caller.
  91. The caller's term program should send no Avatar commands, with the exception
  92. of function key codes, before the AVINIT packets are exchanged. This assures
  93. that a BBS program which does not support full Avatar can still take
  94. advantage of the faster transfer of video codes using Avatar as opposed to
  95. ANSI escape sequences. It also permits the caller whose term program does
  96. not support full Avatar but can interpret the basic codes to take advantage
  97. of the term program's abilities.
  98.  
  99. The two levels of Avatar then are: a full session and a basic session. This
  100. document is concerned with the BASIC Avatar session only. The full session
  101. will be defined in a separate document.
  102.  
  103.  
  104.  
  105.  
  106.                        Basic Avatar Commands
  107.  
  108.  
  109. Before the AVINIT packets are exchanged, the BBS can send the basic Avatar
  110. commands if so permitted by the user's choice, typically recorded in the
  111. user datafile (e.g. USER.BBS). Because Avatar is window oriented, in a
  112. basic session the full screen is considered the default window. Further,
  113. the default color of the window is assumed to be 3 (cyan text on a black
  114. background). All bytes are taken at their face value without escaping.
  115. However, save for one exception described below, no basic Avatar code will
  116. have the high bit set. Therefore, the term program should reset the high
  117. bit of all bytes except as described below.
  118.  
  119. The basic commands are:
  120.  
  121.         <^L>    -       clear the current window and set current attribute
  122.                         to default. In the basic session this means:
  123.                         Clear the screen and set its attribute to 3.
  124.  
  125.         <^Y>    -       Read two bytes from the modem. Send the first one
  126.                         to the screen as many times as the binary value
  127.                         of the second one. This is the exception where
  128.                         the two bytes may have their high bit set. Do
  129.                         not reset it here!
  130.  
  131.         <^V> <^A> <attr> - Set the color attribute to <attr>. The default
  132.                         attribute remains unchanged. However, all text
  133.                         will be displayed in <attr> until the next ^V^A,
  134.                         ^V^B, or ^L.
  135.  
  136.         <^V> <^B>   -   Turn the high bit of current attribute on. In
  137.                         other words, turn blink on.
  138.  
  139.         <^V> <^C>   -   Move the cursor one line up. Do nothing, if you
  140.                         already are at the top line of the current
  141.                         window.
  142.  
  143.         <^V> <^D>   -   Move the cursor one line down. Do nothing if you
  144.                         already are at the bottom line of the current
  145.                         window.
  146.  
  147.         <^V> <^E>   -   Move the cursor one column to the left. Do nothing
  148.                         if you already are at the leftmost column of the
  149.                         current window.
  150.  
  151.         <^V> <^F>   -   Move the cursor one column to the right. Do nothing
  152.                         if you already are at the rightmost column of the
  153.                         current window.
  154.  
  155.         <^V> <^G>   -   Clear the rest of the line in the current window
  156.                         using the current attribute (not to be confused
  157.                         with the default attribute).
  158.  
  159.         <^V> <^H> <row> <col>   -   Move the cursor to the <row> <col>
  160.                         position within the current window.
  161.  
  162.  
  163. Comments:
  164.  
  165. Current attribute and default atribute are not necessarily the same.
  166. Whenever the window is cleared by the <^L> command, the current attribute
  167. is made equal to the default attribute. There is also another command to
  168. make the current attribute equal to the default attribute. However, this
  169. command is not a part of the basic Avatar command set and therefore cannot
  170. be used before the AVINIT packets are exchanged.
  171.  
  172. Whatever characters are sent to the screen, they should be displayed using
  173. the CURRENT attribute. There is an exception to this, but only after the
  174. AVINIT packets have been exchanged.
  175.  
  176. The attribute byte is an eight-bit value. As basic Avatar can only transfer
  177. 7-bit commands, the high bit of the attribute byte can be set only by the
  178. <^V> <^B> command. The <attr> byte of the <^V> <^A> <attr> command should
  179. be AND-ed with 7F (hexadecimal). The colors set by the attribute byte are
  180. the same as are the colors of the text mode of an IMB color graphics adapter.
  181.  
  182. That means the bits of the attribute byte have the following meaning:
  183.  
  184.      bit:         7   6   5   4   3   2   1   0
  185.                   -   -   -   -   -   -   -   -
  186.                   |   |       |   |           |
  187.                   |   |       |   |           |
  188.                   |   +---+---+   +-----+-----+
  189.                   |       |             |
  190.                   |       |             |
  191.                   |       |
  192.                   |       |         text color
  193.                   |       |
  194.                   |
  195.                   |    background color
  196.                   |
  197.  
  198.                 blink
  199.  
  200. If the blink bit is set, the text is blinking, else it is not blinking.
  201.  
  202. The bits of background color can have values 0 - 7, the bits of the text
  203. color can have values 0 - 15. The value indicates the following colors:
  204.  
  205.                  0      black
  206.                  1      blue
  207.                  2      green
  208.                  3      cyan
  209.                  4      red
  210.                  5      magenta
  211.                  6      brown
  212.                  7      gray  (i.e. non-itense white)
  213.                  8      dark gray
  214.                  9      light blue
  215.                 10      light green
  216.                 11      light cyan
  217.                 12      light red
  218.                 13      light magenta
  219.                 14      yellow
  220.                 15      white (intense)
  221.  
  222. Colors 8 - 15 are the same as 0 - 7 but with high intensity.
  223.  
  224. Please note that these values are different from the numbers used by ANSI
  225. escape codes.
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.                      The Function Key Codes
  233.  
  234.  
  235.  
  236. An Avatar capable BBS can accept function keys from the remote caller.
  237. This feature is optional (for the term program) but highly recommended.
  238.  
  239. On an IBM (compatible) computer this means that if a caller hits a function
  240. key (e.g., left arrow, page up, F7, insert, alt-H, etc.), the term program
  241. should send two bytes to the Avatar capable BBS: A binary zero followed by
  242. the keyboard scancode. Please note that control keys (^A, ^B, etc.) are not
  243. function keys but have an ASCII value which is the only byte that should be
  244. transfered.
  245.  
  246. There are two keys on the IBM keyboard that do have an ASCII value but also
  247. offer a separate scan code. These are the gray-plus and the gray-minus. If
  248. one of these keys is hit, treat it as a function key - send the binary zero
  249. followed by the scan code. This way if the BBS treats them differently from a
  250. regular plus and minus keys, the caller can take advantage of the keys.
  251. On the other hand, BBS writers who do not want to assign the gray keys
  252. a special value, should watch for their codes and treat them as a regular
  253. plus and minus.
  254.  
  255. Systems that use a different keyboard layout (and scan codes) than IBM can
  256. emulate IBM by declaring which keys are considered the arrows, f-keys, etc.
  257. If you have the arrow keys, for example, but their scan codes are different,
  258. still send the binary zero and the scan code that an IBM keyboard would
  259. assign to that particular key. This should be transparent to the user.
  260.  
  261. There is an obvious problem here. All terminal programs I have seen use
  262. function keys internally. A switch is needed so the user can decide whether
  263. a function key is meant for the internal use of the term program or it
  264. should be transfered to the BBS. Most but not all IBM clones have a scroll
  265. lock key, some even have an LED indicator on it. The IBM programs could use
  266. that as a switch to know what the user means by hitting a function key.
  267. Since some compatibles do not have a scroll lock key (e.g. Tandy 1000), the
  268. Avatar capable BBS should never expect the <shift> <F1> combination to be
  269. transfered. That way the term program can use <shift> <F1> to switch between
  270. the local and remote use of function keys if the scroll lock key is not
  271. available.
  272.  
  273.  
  274.  
  275.  
  276.                               Conclusion
  277.  
  278.  
  279. This should about summarize the basic Avatar commands. I have written this
  280. document one day before leaving for Fidocon '88 realizing it would be nice
  281. to give the software developers (both of BBS's and term programs) something
  282. before releasing the specs of the full Avatar implementation.
  283.  
  284. Here is also some sample C code. It assumes you have some low level
  285. communications functions of your own. For the screen output it uses Turbo C
  286. library, but you can use anything you want.
  287. */
  288.  
  289.  
  290. #include <conio.h>
  291.  
  292. int def_attr = 3;
  293. int cur_attr = 3;
  294. int lastline = 25;
  295. int lastrow  = 80;
  296.  
  297. /* WARNING: This code has not been tested. It is just meant as an example  */
  298.  
  299. void pascal avatar()
  300. {
  301.  int c,i,j;
  302.  
  303.  switch (mgetchar())            /* Read a char from the modem */
  304.   {
  305.         case 12 :       textattr(cur_attr = def_attr);  /* ^L */
  306.                         clrscr();
  307.                         break;
  308.  
  309.         case 25 :       c = mgetchar();                 /* ^Y */
  310.                         j = mgetchar();
  311.                         for (i = 0; i < j; i++)
  312.                                 cprintf("%c",c);        /* print in color */
  313.                         break;
  314.  
  315.         case 22 :       switch(mgetchar())              /* ^V */
  316.                         {
  317.                          case 1 : cur_attr = mgetchar() & 0x7f;
  318.                                   textattr(cur_attr);
  319.                                   break;
  320.  
  321.                          case 2 : cur_attr |= 0x80;
  322.                                   textattr(cur_attr);
  323.                                   break;
  324.  
  325.                          case 3 : if ((i = wherey()) > 1)
  326.                                         gotoxy(wherex(),i - 1);
  327.                                   break;
  328.  
  329.                          case 4 : if ((i = wherey()) < lastline)
  330.                                         gotoxy(wherex(), i + 1);
  331.                                   break;
  332.  
  333.                          case 5 : if ((i = wherex()) > 1)
  334.                                         gotoxy(i - 1,wherey());
  335.                                   break;
  336.  
  337.                          case 6 : if ((i = wherex()) < lastrow)
  338.                                         gotoxy(i + 1,wherey());
  339.                                   break;
  340.  
  341.                          case 7 : cleol();
  342.                                   break;
  343.  
  344.                          case 8 : i = mgetchar();
  345.                                   gotoxy(mgetchar(),i);
  346.                         }
  347.   }
  348. }
  349.  
  350. FSC-0037
  351. Updates: FSC-0025
  352.  
  353.  
  354.  
  355.                                                 Pittsburgh, PA
  356.                                                 1 May 1989
  357.  
  358.  
  359.                           A   V   A   T   A   R
  360.  
  361.         Advanced Video Attribute Terminal Assembler and Recreator
  362.  
  363.                            George A. Stanislav
  364.  
  365.                             Fidonet 1:129/39.0
  366.  
  367.  
  368.  
  369.  
  370.  
  371.          Information
  372.  
  373.             This FSC is being distributed to members of the FidoNet
  374.             community in order to solicit their reactions to the
  375.             proposals contained in it.  While the issues discussed may
  376.             not be directly relevant to FidoNet standards,  they may be
  377.             interesting to implementers.  Distribution of this document
  378.             is unlimited.
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.    Revised on 25 November 1989
  391.  
  392.  
  393.  
  394.                                Definitions
  395.  
  396.  
  397. Avatar, level 0 - The Avatar protocol as presented at Fidocon '88 and
  398.         described in AVATAR0.C, dated 23 August 1989, plus extensions
  399.         defined in this document.
  400.  
  401. AVT/0   -  An abbreviation for Avatar, level 0, suggested by Joaquim
  402.         Homrighausen.
  403.  
  404. Current attribute - Video attribute defined by the last ^V^A, ^V^L, ^V^M or ^L
  405.         AVT/0 command whichever happened last. In AVT/0, ^L sets the value
  406.         of current attribute to 3, ^V^L, ^V^M and ^V^A to an explicit value.
  407.         In addition, ^V^B turns blink on.
  408.  
  409.  
  410.  
  411.                             Extending AVT/0
  412.  
  413.  
  414. It has become clear some of the Avatar commands originally reserved for
  415. AVT/1 would be very useful in AVT/0. I was hesitant to add them for one
  416. simple reason: Any addition on level 0 will break all existing Avatar
  417. emulating software.
  418.  
  419. However, at present there are only three programs I know of that have
  420. implemented Avatar emulation: My own TinyTerm, Joaquim Homrighausen's
  421. FrontDoor and Jason Galanter's Jterm.
  422.  
  423. Both Joaquim and Jason have assured me they would put the new commands in
  424. their programs, thus nothing will be broken. With that assurance in mind,
  425. I feel confident no chaos will result from adding these new commands.
  426.  
  427.  
  428.                 New Commands (brief definitions)
  429.  
  430.         <^V><^I>  -  Turn insert mode ON. It stays on until any other AVT/0
  431.                      command except <^Y> and <^V><^Y> is encountered after
  432.                      which it is turned off;
  433.  
  434.         <^V><^J><numlines><upper><left><lower><right> - scroll area up;
  435.  
  436.         <^V><^K><numlines><upper><left><lower><right> - scroll area down;
  437.  
  438.         <^V><^L><attr><lines><columns>  - clear area, set attribute;
  439.  
  440.         <^V><^M><attr><char><lines><columns>  - initialize area, set attribute;
  441.  
  442.         <^V><^N>        -  delete character, scroll rest of line left;
  443.  
  444.         <^V><^Y><numchars><char>[...]<count>  -  repeat pattern.
  445.  
  446.  
  447.  
  448.                       Detailed Description
  449.  
  450.  
  451. Insert mode: Insert mode controls the way characters are printed on the
  452.         screen. Insert mode is always assumed OFF unless explicitly set ON
  453.         by the ^V^I command after which it stays on until another AVT/0
  454.         command except for ^Y or ^V^Y is encountered. Then it reverses back
  455.         to off.
  456.  
  457.         Whenever insert mode is OFF, characters are printed on the screen
  458.         like this:
  459.  
  460.         1. Print character at current cursor position using current attribute,
  461.            overwriting whatever was previously displayed at current cursor
  462.            position;
  463.  
  464.         2. Move cursor to next position, usually one character to the right.
  465.            At end of the line, move the cursor to next line (possibly
  466.            scrolling the display or current window if in AVT/1).
  467.  
  468.         Whenever insert mode is ON, characters are printed on the screen
  469.         as follows:
  470.  
  471.         1. Starting at current cursor position and going all the way to the
  472.            second last character on current line, scroll the text one
  473.            character to the right;
  474.  
  475.         2. Discard the character previously at the end of the line, do NOT
  476.            move it at the beginning of the next line;
  477.  
  478.         3. Print character at current cursor position using current attribute;
  479.  
  480.         4. Move cursor to next position, precisely as in par. 2 of insert
  481.            mode off.
  482.  
  483. If ^Y or ^V^Y are encountered, the string of characters they compress is
  484. first expanded, then treated as an ordinary stream of characters printed
  485. according to the above rules.
  486.  
  487. Any other AVT/0 command turns insert mode back off. Please note that in
  488. either case the cursor is moved to its next position in an identical manner.
  489. The mere fact the cursor is moved to next line, or even scrolls the screen
  490. a line up, does NOT turn insert mode off. Only an AVT/0 except as mentioned
  491. above can change insert mode on or off.
  492.  
  493. If control characters are a part of the text stream, they are interpreted
  494. indentically in insert mode on and off as follows:
  495.  
  496.         Carriage return  -  move cursor at the beginning of the same line;
  497.  
  498.         Line feed        -  move cursor one line down (scroll screen or
  499.                             window [in AVT/1] if necessary), do not change
  500.                             cursor column;
  501.  
  502.         Back space       -  move cursor one position to the left. Do NOT
  503.                             overwrite the character at that position.
  504.                             Do nothing if already at the leftmost position;
  505.  
  506.         Tab              -  move cursor to next tab position without
  507.                             overwriting anything. Tab positions are
  508.                             multiples of 8. Do nothing if already at the
  509.                             rightmost position.
  510.  
  511. A space is treated as a character, not as a control character.
  512.  
  513.  
  514. Scrolling an area (^V^J and ^V^K): The area defined by its upper, left, lower
  515.         and right coordinates is scrolled up <^V^J) or down (^V^K) by
  516.         <numlines> lines filling the gap with blank spaces using current
  517.         attribute. If the value of <numlines> is zero or exceeds the actual
  518.         number of lines within the scrolled area, the area is filled with
  519.         blanks using current attribute.
  520.  
  521.         These two commands do NOT change the position of the cursor, nor
  522.         do they define the scrolled area as the default window.
  523.  
  524.         The coordinates are relative to the upper left corner of the screen
  525.         (or current window in AVT/1). The coordinates of upper left corner
  526.         are 1,1. If a coordinate contains 0, it is to be changed to 1.
  527.  
  528. Initializing an area (^V^M): This command contains several steps:
  529.  
  530.         1. Set current attribute to <attr>;
  531.  
  532.         2. Starting at current cursor position (inclusively), ending
  533.            at current cursor position plus number of <lines> and <columns>,
  534.            print <char> at all position inside the defined area. Do not
  535.            move the cursor. If the number of columns or lines exceeds whatever
  536.            is available to the right and below current cursor position,
  537.            truncate the dimensions to fit within the limits of the screen
  538.            (or current window in AVT/1).
  539.  
  540. Clearing an area (^V^L): This is a shortcut version of the ^V^M command.
  541.         The character to be used to initialize the area of the screen is
  542.         assumed to be a blank space. In other words, it sets current
  543.         attribute and clears an area of the screen starting at current
  544.         cursor position (which remains unchanged).
  545.  
  546. Please note that the usual 7-bit restriction applies to ^V^L  That means
  547. that the attribute byte should be anded with 7f hex before applying. If
  548. blinking is desired, ^V^B should be used next.
  549.  
  550. On the other hand, requiring to ignore the high bit in ^V^M would make it
  551. impossible to fill the area of the screen with a blinking pattern (something
  552. I have seen used very creatively by Chris Gaal of PittNet). Therefore, if
  553. bit 7 of attr is set in ^V^M, current attribute is set to <attr> AND 7f hex
  554. and blink is turned on before filling the area with a character.
  555.  
  556. Deleting a character (^V^N): Starting at the column one character to the right
  557.         of current cursor position all the way to end of the line, scroll
  558.         the text one character position to the left. This effectively
  559.         deletes the character at current cursor position. Print a blank space
  560.         using current attribute at the rightmost end of the line to fill the
  561.         gap. Do not change current cursor position. If the cursor is at the
  562.         end of the line, simply overwrite the last character with a blank
  563.         space using current attribute.
  564.  
  565. Repeat pattern: This is an extension of the ^Y command which allows a group
  566.         of characters to form a repetititious pattern. <numchars> determines
  567.         the number of characters in the pattern, <count> the number of times
  568.         the pattern is to be printed out. The pattern may contain AVT/0 codes.
  569.  
  570. For example, <^V><^Y><#3>ABC<#4> expands to "ABCABCABCABC".
  571.  
  572.  
  573.                         Scrolling Philosophy
  574.  
  575.  
  576. An important philosophical question has not been answered yet: When scrolling
  577. the contents of an area (in the scrolling commands ^V^J and ^V^J, in insert
  578. mode ON and in deleting characters ^V^N) should only the text be scrolled
  579. and the attribute of the scrolled areas remain where they are or should the
  580. attributes move as well.
  581.  
  582. A case can be made for either approach. Obviously, the gaps created by
  583. scrolling are filled with current attribute, therefore, it seems more logical
  584. to scroll the attributes along with the text (else there would be no need
  585. to fill the gaps). Thus we follow a consistent principle of video attributes
  586. belonging to a character (be it a blank, a digit, or a true character), not
  587. to a location. Whenever a character is scrolled to a different location, it
  588. takes its attribute along.
  589.