home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / tde221.zip / TDEASM.C < prev    next >
C/C++ Source or Header  |  1993-04-01  |  7KB  |  204 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.  *
  24.  * This modification of Douglas Thomson's code is released into the
  25.  * public domain, Frank Davis.  You may distribute it freely.
  26.  */
  27.  
  28. #include "tdestr.h"
  29. #include "common.h"
  30. #include "tdefunc.h"
  31.  
  32.  
  33. /*
  34.  * Name:    ptoul - pointer to unsigned long
  35.  * Purpose: convert a far pointer to unsigned long integer
  36.  * Date:    June 5, 1991
  37.  * Passed:  s:  a far pointer
  38.  * Notes:   combine the offset and segment like so:
  39.  *                offset       0000
  40.  *                segment   + 0000
  41.  *                          =======
  42.  *                            00000
  43.  *          result is returned in dx:ax
  44.  */
  45. unsigned long ptoul( void far *s )
  46. {
  47.    ASSEMBLE {
  48.         mov     ax, WORD PTR s          /* ax = OFFSET of s */
  49.         mov     dx, WORD PTR s+2        /* dx = SEGMENT of s */
  50.         mov     bx, dx          /* put copy of segment in bx */
  51.         mov     cl, 12          /* cl = decimal 12 - shift hi word 3 hex digits */
  52.         shr     dx, cl          /* convert to 'real segment' */
  53.         mov     cl, 4           /* cl = 4  - shift hi word 1 hex digit left */
  54.         shl     bx, cl          /* shift bx - to add 3 digits of seg to 4 of off */
  55.         add     ax, bx          /* add low part of segment to offset */
  56.         adc     dx, 0           /* if carry, bump to next 'real' segment */
  57.    }
  58. }
  59.  
  60.  
  61. /*
  62.  * Name:    tabout
  63.  * Purpose: Expand tabs in display line
  64.  * Date:    October 31, 1992
  65.  * Passed:  s:  string pointer
  66.  *          len:  pointer to current length of string
  67.  * Notes:   Expand tabs in the display line according to current tab.
  68.  *          If eol display is on, let's display tabs, too.
  69.  */
  70. text_ptr tabout( text_ptr s, int *len )
  71. {
  72. text_ptr to;
  73. int space;
  74. int col;
  75. int i;
  76. int tab_size;
  77. int show_tab;
  78. int tab_len;
  79.  
  80.  
  81.    tab_size = mode.ptab_size;
  82.    show_tab = mode.show_eol;
  83.    to  = (text_ptr)g_status.tabout_buff;
  84.    i = tab_len  = *len;
  85.  
  86.    ASSEMBLE {
  87.         push    si
  88.         push    di
  89.         push    ds
  90.         push    es
  91.  
  92.         mov     bx, WORD PTR tab_size   /* keep tab_size in bx */
  93.         xor     cx, cx                  /* keep col in cx */
  94.  
  95.         mov     di, WORD PTR to
  96.         mov     ax, WORD PTR to+2
  97.         mov     es, ax                  /* es:di == to or the destination */
  98.         mov     si, WORD PTR s
  99.         mov     ax, WORD PTR s+2
  100.         mov     ds, ax                  /* ds:si == s or the source */
  101.    }
  102. top:
  103.  
  104.    ASSEMBLE {
  105.         cmp     cx, MAX_LINE_LENGTH     /* are at end of tabout buffer? */
  106.         jge     get_out
  107.  
  108.         cmp     WORD PTR i, 0           /* are at end of string? */
  109.         jle     get_out
  110.  
  111.         lodsb                           /* al == BYTE PTR ds:si */
  112.         cmp     al, 0x09                /* is this a tab character? */
  113.         je      expand_tab
  114.  
  115.         stosb                           /* store character in es:di inc di */
  116.         inc     cx                      /* increment col counter */
  117.         dec     WORD PTR i              /* decrement string counter */
  118.         jmp     SHORT top
  119.    }
  120. expand_tab:
  121.  
  122.    ASSEMBLE {
  123.         mov     ax, cx
  124.         xor     dx, dx                  /* set up dx:ax for IDIV */
  125.         IDIV    bx                      /* col % tab_size */
  126.         mov     ax, bx                  /* put tab_size in bx */
  127.         sub     ax, dx                  /* ax = tab_size - (col % tab_size) */
  128.         mov     dx, ax                  /* put ax in dx */
  129.         add     cx, ax                  /* col += space */
  130.         cmp     cx, MAX_LINE_LENGTH     /* is col > MAX_LINE_LENGTH? */
  131.         jge     get_out                 /* yes, get out */
  132.         mov     ax, ' '                 /* save blank character in ax */
  133.         cmp     WORD PTR show_tab, 0    /* was show_tab flag set? */
  134.         je      do_the_tab
  135.         mov     ax, 0x09                /* put tab character in ax */
  136.    }
  137. do_the_tab:
  138.  
  139.    ASSEMBLE {
  140.         stosb                           /* store in es:di and incr di */
  141.         dec     dx
  142.         cmp     dx, 0                   /* any spaces left to fill? */
  143.         jle     end_of_space            /* no, get another character */
  144.         add     WORD PTR tab_len, dx    /* add spaces to string length */
  145.         mov     ax, ' '                 /* save blank character in ax */
  146.    }
  147. space_fill:
  148.  
  149.    ASSEMBLE {
  150.         cmp     dx, 0                   /* any spaces left to fill? */
  151.         jle     end_of_space            /* no, get another character */
  152.         stosb                           /* store ' ' in es:di and incr di */
  153.         dec     dx                      /* space-- */
  154.         jmp     SHORT space_fill        /* fill space */
  155.   }
  156. end_of_space:
  157.  
  158.    ASSEMBLE {
  159.         dec     WORD PTR i
  160.         jmp     SHORT top
  161.    }
  162. get_out:
  163.  
  164.    ASSEMBLE {
  165.         pop     es
  166.         pop     ds
  167.         pop     di
  168.         pop     si
  169.    }
  170.    if (tab_len > MAX_LINE_LENGTH)
  171.       tab_len = MAX_LINE_LENGTH;
  172.    *len = g_status.tabout_buff_len = tab_len;
  173.    return( (text_ptr)g_status.tabout_buff );
  174.  
  175. /*
  176.    tab_size = mode.ptab_size;
  177.    show_tab = mode.show_eol;
  178.    to  = g_status.tabout_buff;
  179.    i = tab_len  = *len;
  180.    for (col=0; col < (MAX_LINE_LENGTH - (tab_size+1)) &&  i > 0; s++, i--) {
  181.       if (*s != '\t') {
  182.          *to++ = *s;
  183.          ++col;
  184.       } else {
  185.          space = tab_size - (col % tab_size);
  186.          col += space;
  187.          space--;
  188.          if (space > 0)
  189.             tab_len += space;
  190.          if (show_tab)
  191.             *to++ = '\t';
  192.          else
  193.             *to++ = ' ';
  194.          for (; space > 0; space--)
  195.             *to++ = ' ';
  196.       }
  197.    }
  198.    if (tab_len > MAX_LINE_LENGTH)
  199.       tab_len = MAX_LINE_LENGTH;
  200.    *len = g_status.tabout_buff_len = tab_len;
  201.    return( (text_ptr)g_status.tabout_buff );
  202. */
  203. }
  204.