home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR8 / TDE32.ZIP / TDEASM.C < prev    next >
C/C++ Source or Header  |  1993-11-13  |  8KB  |  253 lines

  1. /*
  2.  * The DTE 5.1 editor used a big text buffer for editing a file.  The big
  3.  * text buffer holds an image of a file pretty much as it appears on
  4.  * disk.  In that big buffer, '\0' was used to delimit the files.  In TDE
  5.  * versions 2.10 and less, a big text buffer was also used, but ^Z was used
  6.  * instead of '\0' to delimit files.  A double linked list is used in TDE 2.2
  7.  * to hold text.
  8.  *
  9.  * With these functions written in assembly, this editor is fairly fast.
  10.  * I feel the need for speed.
  11.  *
  12.  * New editor name:  TDE, the Thomson-Davis Editor.
  13.  * Author:           Frank Davis
  14.  * Date:             June 5, 1991, version 1.0
  15.  * Date:             July 29, 1991, version 1.1
  16.  * Date:             October 5, 1991, version 1.2
  17.  * Date:             January 20, 1992, version 1.3
  18.  * Date:             February 17, 1992, version 1.4
  19.  * Date:             April 1, 1992, version 1.5
  20.  * Date:             June 5, 1992, version 2.0
  21.  * Date:             October 31, 1992, version 2.1
  22.  * Date:             April 1, 1993, version 2.2
  23.  * Date:             June 5, 1993, version 3.0
  24.  * Date:             August 29, 1993, version 3.1
  25.  * Date:             November 13, 1993, version 3.2
  26.  *
  27.  * This modification of Douglas Thomson's code is released into the
  28.  * public domain, Frank Davis.  You may distribute it freely.
  29.  */
  30.  
  31. #include "tdestr.h"
  32. #include "common.h"
  33. #include "tdefunc.h"
  34.  
  35.  
  36. /*
  37.  * Name:    ptoul - pointer to unsigned long
  38.  * Purpose: convert a FAR pointer to unsigned long integer
  39.  * Date:    June 5, 1991
  40.  * Passed:  s:  a FAR pointer
  41.  * Notes:   combine the offset and segment like so:
  42.  *                offset       0000
  43.  *                segment   + 0000
  44.  *                          =======
  45.  *                            00000
  46.  *          result is returned in dx:ax
  47.  */
  48.  
  49. #if defined( __UNIX__ )
  50.  void *ptoul( void *s )
  51.  {
  52.     return( s );
  53.  }
  54. #else
  55.  unsigned long ptoul( void FAR *s )
  56.  {
  57.    ASSEMBLE {
  58.         mov     ax, WORD PTR s          /* ax = OFFSET of s */
  59.         mov     dx, WORD PTR s+2        /* dx = SEGMENT of s */
  60.         mov     bx, dx          /* put copy of segment in bx */
  61.         mov     cl, 12          /* cl = decimal 12 - shift hi word 3 hex digits */
  62.         shr     dx, cl          /* convert to 'real segment' */
  63.         mov     cl, 4           /* cl = 4  - shift hi word 1 hex digit left */
  64.         shl     bx, cl          /* shift bx - to add 3 digits of seg to 4 of off */
  65.         add     ax, bx          /* add low part of segment to offset */
  66.         adc     dx, 0           /* if carry, bump to next 'real' segment */
  67.    }
  68.  }
  69. #endif
  70.  
  71.  
  72. /*
  73.  * Name:    tabout
  74.  * Purpose: Expand tabs in display line
  75.  * Date:    October 31, 1992
  76.  * Passed:  s:  string pointer
  77.  *          len:  pointer to current length of string
  78.  * Notes:   Expand tabs in the display line according to current tab.
  79.  *          If eol display is on, let's display tabs, too.
  80.  */
  81. text_ptr tabout( text_ptr s, int *len )
  82. {
  83. text_ptr to;
  84. int space;
  85. int col;
  86. int i;
  87. int tab_size;
  88. int show_tab;
  89. int tab_len;
  90.  
  91. #if defined( __UNIX__ )
  92.  
  93.    /*
  94.     * for right now, no assembly in unix
  95.     */
  96.    tab_size = mode.ptab_size;
  97.    show_tab = mode.show_eol;
  98.    to  = (text_ptr)g_status.tabout_buff;
  99.    i = tab_len  = *len;
  100.    tab_size = mode.ptab_size;
  101.    show_tab = mode.show_eol;
  102.    to  = g_status.tabout_buff;
  103.    i = tab_len  = *len;
  104.    for (col=0; col < (MAX_LINE_LENGTH - (tab_size+1)) &&  i > 0; s++, i--) {
  105.       if (*s != '\t') {
  106.          *to++ = *s;
  107.          ++col;
  108.       } else {
  109.          space = tab_size - (col % tab_size);
  110.          col += space;
  111.          space--;
  112.          if (space > 0)
  113.             tab_len += space;
  114.          if (show_tab)
  115.             *to++ = '\t';
  116.          else
  117.             *to++ = ' ';
  118.          for (; space > 0; space--)
  119.             *to++ = ' ';
  120.       }
  121.    }
  122.    if (tab_len > MAX_LINE_LENGTH)
  123.       tab_len = MAX_LINE_LENGTH;
  124.    *len = g_status.tabout_buff_len = tab_len;
  125.    return( (text_ptr)g_status.tabout_buff );
  126.  
  127. #else
  128.  
  129.    tab_size = mode.ptab_size;
  130.    show_tab = mode.show_eol;
  131.    to  = (text_ptr)g_status.tabout_buff;
  132.    i = tab_len  = *len;
  133.  
  134.    ASSEMBLE {
  135.         push    si
  136.         push    di
  137.         push    ds
  138.         push    es
  139.  
  140.         mov     bx, WORD PTR tab_size   /* keep tab_size in bx */
  141.         xor     cx, cx                  /* keep col in cx */
  142.  
  143.         mov     di, WORD PTR to
  144.         mov     ax, WORD PTR to+2
  145.         mov     es, ax                  /* es:di == to or the destination */
  146.         mov     si, WORD PTR s
  147.         mov     ax, WORD PTR s+2
  148.         mov     ds, ax                  /* ds:si == s or the source */
  149.    }
  150. top:
  151.  
  152.    ASSEMBLE {
  153.         cmp     cx, MAX_LINE_LENGTH     /* are at end of tabout buffer? */
  154.         jge     get_out
  155.  
  156.         cmp     WORD PTR i, 0           /* are at end of string? */
  157.         jle     get_out
  158.  
  159.         lodsb                           /* al == BYTE PTR ds:si */
  160.         cmp     al, 0x09                /* is this a tab character? */
  161.         je      expand_tab
  162.  
  163.         stosb                           /* store character in es:di inc di */
  164.         inc     cx                      /* increment col counter */
  165.         dec     WORD PTR i              /* decrement string counter */
  166.         jmp     SHORT top
  167.    }
  168. expand_tab:
  169.  
  170.    ASSEMBLE {
  171.         mov     ax, cx
  172.         xor     dx, dx                  /* set up dx:ax for IDIV */
  173.         IDIV    bx                      /* col % tab_size */
  174.         mov     ax, bx                  /* put tab_size in bx */
  175.         sub     ax, dx                  /* ax = tab_size - (col % tab_size) */
  176.         mov     dx, ax                  /* put ax in dx */
  177.         add     cx, ax                  /* col += space */
  178.         cmp     cx, MAX_LINE_LENGTH     /* is col > MAX_LINE_LENGTH? */
  179.         jge     get_out                 /* yes, get out */
  180.         mov     ax, ' '                 /* save blank character in ax */
  181.         cmp     WORD PTR show_tab, 0    /* was show_tab flag set? */
  182.         je      do_the_tab
  183.         mov     ax, 0x09                /* put tab character in ax */
  184.    }
  185. do_the_tab:
  186.  
  187.    ASSEMBLE {
  188.         stosb                           /* store in es:di and incr di */
  189.         dec     dx
  190.         cmp     dx, 0                   /* any spaces left to fill? */
  191.         jle     end_of_space            /* no, get another character */
  192.         add     WORD PTR tab_len, dx    /* add spaces to string length */
  193.         mov     ax, ' '                 /* save blank character in ax */
  194.    }
  195. space_fill:
  196.  
  197.    ASSEMBLE {
  198.         cmp     dx, 0                   /* any spaces left to fill? */
  199.         jle     end_of_space            /* no, get another character */
  200.         stosb                           /* store ' ' in es:di and incr di */
  201.         dec     dx                      /* space-- */
  202.         jmp     SHORT space_fill        /* fill space */
  203.   }
  204. end_of_space:
  205.  
  206.    ASSEMBLE {
  207.         dec     WORD PTR i
  208.         jmp     SHORT top
  209.    }
  210. get_out:
  211.  
  212.    ASSEMBLE {
  213.         pop     es
  214.         pop     ds
  215.         pop     di
  216.         pop     si
  217.    }
  218.    if (tab_len > MAX_LINE_LENGTH)
  219.       tab_len = MAX_LINE_LENGTH;
  220.    *len = g_status.tabout_buff_len = tab_len;
  221.    return( (text_ptr)g_status.tabout_buff );
  222.  
  223. /*
  224.    tab_size = mode.ptab_size;
  225.    show_tab = mode.show_eol;
  226.    to  = g_status.tabout_buff;
  227.    i = tab_len  = *len;
  228.    for (col=0; col < (MAX_LINE_LENGTH - (tab_size+1)) &&  i > 0; s++, i--) {
  229.       if (*s != '\t') {
  230.          *to++ = *s;
  231.          ++col;
  232.       } else {
  233.          space = tab_size - (col % tab_size);
  234.          col += space;
  235.          space--;
  236.          if (space > 0)
  237.             tab_len += space;
  238.          if (show_tab)
  239.             *to++ = TAB_CHAR;
  240.          else
  241.             *to++ = ' ';
  242.          for (; space > 0; space--)
  243.             *to++ = ' ';
  244.       }
  245.    }
  246.    if (tab_len > MAX_LINE_LENGTH)
  247.       tab_len = MAX_LINE_LENGTH;
  248.    *len = g_status.tabout_buff_len = tab_len;
  249.    return( (text_ptr)g_status.tabout_buff );
  250. */
  251. #endif
  252. }
  253.