home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CPEditText.asm
-
- Assembly language routines for CPEditText 1.2
-
- These routines are only necessary if you are compiling the TCL
- with the Symantec C++ compiler. If you are using THINK C, you
- do not need to include this file in your project.
-
- Copyright © 1993 Christopher R. Wysocki. All rights reserved.
-
- ******************************************************************************/
-
- #include "CPEditTextX.h"
-
-
- /******************************************************************************
- AsmDrawLineRange
-
- Assembly-language routine used by CPEditText::DrawLineRange.
- ******************************************************************************/
-
- void AsmDrawLineRange(
- register Ptr textP,
- register short numChars,
- short tabWidth,
- register Ptr gapP,
- long gapLength,
- Point startPt,
- Boolean showInvisibles)
- {
- register char tab;
- register short index;
- Point penPt;
-
- asm {
- clr.w index ; reset index
- move.b #kTab,tab ; keep tab character in register for speed
-
- @Loop:
- cmp.w numChars,index ; have we drawn all the text?
- bge.s @Done ; branch if we have
- cmpa.l gapP,textP ; are we at the gap?
- bne.s @NotAtGap ; branch if not
-
- @AtGap:
- bsr.s @DrawText ; else draw the text to the left of the gap
- adda.l gapLength,textP ; and skip over the gap
-
- @NotAtGap:
- addq.w #1,index ; else bump the index
- cmp.b (textP)+,tab ; is character from text a tab?
- bne.s @Loop ; loop if not
-
- @IsTab:
- moveq #1,d0 ; stick 1 in d0 for a little extra speed
- sub.w d0,textP ; decrement ptr to text
- sub.w d0,index ; decrement # of characters to draw
- bsr.s @DrawText ; draw the text to the left of the tab
-
- movea.l thePort,a0 ; get current GrafPtr
- move.l OFFSET(GrafPort,pnLoc)(a0),penPt ; get pen location
-
- tst.b showInvisibles ; are we displaying invisible characters?
- beq.s @NoInvis1 ; branch if not
- move.w #kInvisTab,-(a7) ; else push invisible tab character
- _DrawChar ; and draw it
-
- @NoInvis1:
- moveq #0,d0 ; clear out all of D0
- move.w penPt.h,d0 ; get horiz pen location
- sub.w startPt.h,d0 ; subtract starting location
- divu.w tabWidth,d0 ; divide by tab width
- addq.w #1,d0 ; add one to tab width
- mulu.w tabWidth,d0 ; get pixel offset
- add.w startPt.h,d0 ; add starting location
-
- move.w d0,-(a7) ; push horiz coordinate
- move.w penPt.v,-(a7) ; push vert coordinate
- _MoveTo ; move pen location
-
- moveq #1,d0 ; stick 1 in d0 for a little extra speed
- adda.w d0,textP ; bump ptr to text
- sub.w d0,numChars ; subtract 1 from length of text
- bra.s @Loop ; and loop
-
- @DrawText:
- tst.w index ; any text to draw?
- beq.s @NoText ; skip if not
-
- movea.l textP,a0 ; get ptr to next character
- suba.w index,a0 ; subtract index
- move.l a0,-(a7) ; push ptr to text
- clr.w -(a7) ; push offset into text
- move.w index,-(a7) ; push length of text to draw
- _DrawText ; call DrawText
-
- sub.w index,numChars ; subtract from length of text
- clr.w index ; reset index to 0
- @NoText:
- rts
-
- @Done:
- bsr.s @DrawText ; draw rest of text
- }
- }
-
-
- /******************************************************************************
- AsmMeasureTextWidths
-
- Assembly-language routine used by CPEditText::MeasureTextWidths.
- ******************************************************************************/
-
- void AsmMeasureTextWidths(
- register Ptr textP,
- register short numChars,
- short tabWidth,
- register Ptr gapP,
- long gapLength,
- register short *widthsP,
- register short maxWidth)
- {
- register short index;
- register short lastWidth;
- register char tab;
-
- asm {
- clr.w index ; reset index
- clr.w lastWidth ; set lastWidth to zero
- move.b #kTab,tab ; keep tab character in register for speed
-
- @Loop:
- cmp.w numChars,index ; have we measured all the text?
- bge.s @Done ; branch if we have
- cmpa.l gapP,textP ; are we at the gap?
- bne.s @NotAtGap ; branch if not
-
- @AtGap:
- bsr.s @MeasTxt ; else measure the text to the left of the gap
- adda.l gapLength,textP ; and skip over the gap
-
- cmp.w maxWidth,lastWidth ; have we exceeded the maximum width?
- bge.s @OverMaxWidth ; branch if so
-
- @NotAtGap:
- addq.w #1,index ; else bump the index
- cmp.b (textP)+,tab ; is character from text a tab?
- bne.s @Loop ; loop if not
-
- @IsTab:
- moveq #1,d0 ; stick 1 in d0 for a little extra speed
- sub.w d0,textP ; decrement ptr to text
- sub.w d0,index ; decrement # of characters to measure
- bsr.s @MeasTxt ; measure the text to the left
-
- cmp.w maxWidth,lastWidth ; have we exceeded the maximum width?
- bge.s @OverMaxWidth ; branch if so
-
- moveq #0,d0 ; clear out all of d0
- move.w lastWidth,d0 ; get total width of text so far
- divu.w tabWidth,d0 ; divide by tab width
- addq.w #1,d0 ; add one to tab width
- mulu.w tabWidth,d0 ; compute width at next tab stop
- addq.w #2,widthsP ; bump widthsP
- move.w d0,(widthsP) ; save width of tab in widths array
- move.w d0,lastWidth ; remember new total width
-
- moveq #1,d0 ; stick 1 in d0 for a little extra speed
- adda.w d0,textP ; bump ptr to text
- sub.w d0,numChars ; decrement length of text
- bra.s @Loop ; and loop
-
- @MeasTxt:
- move.w index,-(a7) ; push number of characters to measure
- movea.l textP,a0 ; get ptr to next character in text
- suba.w index,a0 ; subtract index
- move.l a0,-(a7) ; push ptr to text to measure
- move.l widthsP,-(a7) ; push ptr to current position in widths array
- _MeasureText ; measure the text
-
- move.w lastWidth,d0 ; keep lastWidth in d0
- move.w index,d1 ; loop index in d1
- @WidthLoop:
- add.w d0,(widthsP)+ ; add lastWidth to element of widths array
- dbra d1,@WidthLoop ; and loop
-
- move.w -(widthsP),lastWidth ; save width of last character
- sub.w index,numChars ; decrement length of text
- clr.w index ; reset character count
- rts ; and return to caller
-
- @Done:
- bsr.s @MeasTxt ; measure the rest of the text
-
- @OverMaxWidth:
- }
- }
-