home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / CPEditText 1.2 / CPEditText.asm < prev    next >
Encoding:
Assembly Source File  |  1993-10-03  |  6.1 KB  |  199 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CPEditText.asm
  3.         
  4.                 Assembly language routines for CPEditText 1.2
  5.     
  6.     These routines are only necessary if you are compiling the TCL
  7.     with the Symantec C++ compiler.  If you are using THINK C, you
  8.     do not need to include this file in your project.
  9.     
  10.     Copyright © 1993 Christopher R. Wysocki.  All rights reserved.
  11.     
  12.  ******************************************************************************/
  13.  
  14. #include "CPEditTextX.h"
  15.  
  16.  
  17. /******************************************************************************
  18.  AsmDrawLineRange
  19.  
  20.         Assembly-language routine used by CPEditText::DrawLineRange.
  21.  ******************************************************************************/
  22.  
  23. void    AsmDrawLineRange(
  24.     register Ptr    textP,
  25.     register short    numChars,
  26.     short            tabWidth,
  27.     register Ptr    gapP,
  28.     long            gapLength,
  29.     Point            startPt,
  30.     Boolean            showInvisibles)
  31. {
  32.     register char    tab;
  33.     register short    index;
  34.     Point            penPt;
  35.     
  36.     asm {
  37.         clr.w    index                    ; reset index
  38.         move.b    #kTab,tab                ; keep tab character in register for speed
  39.         
  40.     @Loop:
  41.         cmp.w    numChars,index            ; have we drawn all the text?
  42.         bge.s    @Done                    ; branch if we have
  43.         cmpa.l    gapP,textP                ; are we at the gap?
  44.         bne.s    @NotAtGap                ; branch if not
  45.         
  46.     @AtGap:
  47.         bsr.s    @DrawText                ; else draw the text to the left of the gap
  48.         adda.l    gapLength,textP            ; and skip over the gap
  49.         
  50.     @NotAtGap:
  51.         addq.w    #1,index                ; else bump the index        
  52.         cmp.b    (textP)+,tab            ; is character from text a tab?
  53.         bne.s    @Loop                    ; loop if not
  54.         
  55.     @IsTab:
  56.         moveq    #1,d0                    ; stick 1 in d0 for a little extra speed
  57.         sub.w    d0,textP                ; decrement ptr to text
  58.         sub.w    d0,index                ; decrement # of characters to draw
  59.         bsr.s    @DrawText                ; draw the text to the left of the tab
  60.         
  61.         movea.l    thePort,a0                ; get current GrafPtr
  62.         move.l    OFFSET(GrafPort,pnLoc)(a0),penPt ; get pen location
  63.         
  64.         tst.b    showInvisibles            ; are we displaying invisible characters?
  65.         beq.s    @NoInvis1                ; branch if not
  66.         move.w    #kInvisTab,-(a7)        ; else push invisible tab character
  67.         _DrawChar                        ; and draw it
  68.         
  69.     @NoInvis1:
  70.         moveq    #0,d0                    ; clear out all of D0
  71.         move.w    penPt.h,d0                ; get horiz pen location
  72.         sub.w    startPt.h,d0            ; subtract starting location
  73.         divu.w    tabWidth,d0                ; divide by tab width
  74.         addq.w    #1,d0                    ; add one to tab width
  75.         mulu.w    tabWidth,d0                ; get pixel offset
  76.         add.w    startPt.h,d0            ; add starting location
  77.         
  78.         move.w    d0,-(a7)                ; push horiz coordinate
  79.         move.w    penPt.v,-(a7)            ; push vert coordinate
  80.         _MoveTo                            ; move pen location
  81.         
  82.         moveq    #1,d0                    ; stick 1 in d0 for a little extra speed
  83.         adda.w    d0,textP                ; bump ptr to text
  84.         sub.w    d0,numChars                ; subtract 1 from length of text
  85.         bra.s    @Loop                    ; and loop
  86.  
  87.     @DrawText:
  88.         tst.w    index                    ; any text to draw?
  89.         beq.s    @NoText                    ; skip if not
  90.         
  91.         movea.l    textP,a0                ; get ptr to next character
  92.         suba.w    index,a0                ; subtract index
  93.         move.l    a0,-(a7)                ; push ptr to text
  94.         clr.w    -(a7)                    ; push offset into text
  95.         move.w    index,-(a7)                ; push length of text to draw
  96.         _DrawText                        ; call DrawText
  97.         
  98.         sub.w    index,numChars            ; subtract from length of text
  99.         clr.w    index                    ; reset index to 0
  100.     @NoText:
  101.         rts
  102.         
  103.     @Done:
  104.         bsr.s    @DrawText                ; draw rest of text
  105.     }
  106. }
  107.  
  108.  
  109. /******************************************************************************
  110.  AsmMeasureTextWidths
  111.  
  112.         Assembly-language routine used by CPEditText::MeasureTextWidths.
  113.  ******************************************************************************/
  114.  
  115. void    AsmMeasureTextWidths(
  116.     register Ptr    textP,
  117.     register short    numChars,
  118.     short            tabWidth,
  119.     register Ptr    gapP,
  120.     long            gapLength,
  121.     register short    *widthsP,
  122.     register short    maxWidth)
  123. {
  124.     register short    index;
  125.     register short    lastWidth;
  126.     register char    tab;
  127.         
  128.     asm {
  129.         clr.w    index                    ; reset index
  130.         clr.w    lastWidth                ; set lastWidth to zero
  131.         move.b    #kTab,tab                ; keep tab character in register for speed
  132.         
  133.     @Loop:
  134.         cmp.w    numChars,index            ; have we measured all the text?
  135.         bge.s    @Done                    ; branch if we have
  136.         cmpa.l    gapP,textP                ; are we at the gap?
  137.         bne.s    @NotAtGap                ; branch if not
  138.         
  139.     @AtGap:
  140.         bsr.s    @MeasTxt                ; else measure the text to the left of the gap
  141.         adda.l    gapLength,textP            ; and skip over the gap
  142.         
  143.         cmp.w    maxWidth,lastWidth        ; have we exceeded the maximum width?
  144.         bge.s    @OverMaxWidth            ; branch if so
  145.         
  146.     @NotAtGap:
  147.         addq.w    #1,index                ; else bump the index        
  148.         cmp.b    (textP)+,tab            ; is character from text a tab?
  149.         bne.s    @Loop                    ; loop if not
  150.         
  151.     @IsTab:
  152.         moveq    #1,d0                    ; stick 1 in d0 for a little extra speed
  153.         sub.w    d0,textP                ; decrement ptr to text
  154.         sub.w    d0,index                ; decrement # of characters to measure
  155.         bsr.s    @MeasTxt                ; measure the text to the left
  156.         
  157.         cmp.w    maxWidth,lastWidth        ; have we exceeded the maximum width?
  158.         bge.s    @OverMaxWidth            ; branch if so
  159.         
  160.         moveq    #0,d0                    ; clear out all of d0
  161.         move.w    lastWidth,d0            ; get total width of text so far
  162.         divu.w    tabWidth,d0                ; divide by tab width
  163.         addq.w    #1,d0                    ; add one to tab width
  164.         mulu.w    tabWidth,d0                ; compute width at next tab stop
  165.         addq.w    #2,widthsP                ; bump widthsP
  166.         move.w    d0,(widthsP)            ; save width of tab in widths array
  167.         move.w    d0,lastWidth            ; remember new total width
  168.         
  169.         moveq    #1,d0                    ; stick 1 in d0 for a little extra speed
  170.         adda.w    d0,textP                ; bump ptr to text
  171.         sub.w    d0,numChars                ; decrement length of text
  172.         bra.s    @Loop                    ; and loop
  173.             
  174.     @MeasTxt:
  175.         move.w    index,-(a7)                ; push number of characters to measure
  176.         movea.l    textP,a0                ; get ptr to next character in text
  177.         suba.w    index,a0                ; subtract index
  178.         move.l    a0,-(a7)                ; push ptr to text to measure
  179.         move.l    widthsP,-(a7)            ; push ptr to current position in widths array
  180.         _MeasureText                    ; measure the text
  181.         
  182.         move.w    lastWidth,d0            ; keep lastWidth in d0
  183.         move.w    index,d1                ; loop index in d1
  184.     @WidthLoop:
  185.         add.w    d0,(widthsP)+            ; add lastWidth to element of widths array
  186.         dbra    d1,@WidthLoop            ; and loop
  187.         
  188.         move.w    -(widthsP),lastWidth    ; save width of last character
  189.         sub.w    index,numChars            ; decrement length of text
  190.         clr.w    index                    ; reset character count
  191.         rts                                ; and return to caller
  192.  
  193.     @Done:
  194.         bsr.s    @MeasTxt                ; measure the rest of the text
  195.  
  196.     @OverMaxWidth:
  197.     }
  198. }
  199.