TextFile.a

;
;   File:       TextFile.a
;
;   Contains:   utility routines for SimpleText
;
; Copyright 1995-1996 Apple Computer. All rights reserved.
;
;   You may incorporate this sample code into your applications without
;   restriction, though the sample code has been provided "AS IS" and the
;   responsibility for its operation is 100% yours.  However, what you are
;   not permitted to do is to redistribute the source as "DSC Sample Code"
;   after having made changes. If you're going to re-distribute the source,
;   we require that you make it clear in the source that the code was
;   descended from Apple Sample Code, but that you've made changes.
 
;   AsmClikLoop
;
;   This routine gets called by the TextEdit Manager from TEClick.
;   It calls the old, default click loop routine that scrolls the
;   text, and then calls our own Pascal routine that handles
;   tracking the scroll bars to follow along.  It doesn't bother
;   with saving registers A0 and D0, because they are trashed
;   anyway by TextEdit.
;
 
AsmClikLoop PROC        EXPORT
 
            IMPORT      GETOLDCLICKLOOP
            IMPORT      TEXTCLICKLOOP
            
            MOVEM.L     D1-D2/A1,-(SP)      ; D0 and A0 need not be saved
            CLR.L       -(SP)               ; make space for procedure pointer
            JSR         GETOLDCLICKLOOP     ; get the old clikLoop
            MOVEA.L     (SP)+,A0            ; into A0
            MOVEM.L     (SP)+,D1-D2/A1      ; restore the world as it was
            
            JSR         (A0)                ; and execute old clikLoop
 
            MOVEM.L     D1-D2/A1,-(SP)      ; D0 and A0 need not be saved
            JSR         TEXTCLICKLOOP       ; do our clikLoop
            MOVEM.L     (SP)+,D1-D2/A1      ; restore the world as it was
            MOVEQ       #1,D0               ; clear the zero flag so TextEdit keeps going
            RTS
 
;-----------------------------------------------------------------
; Glue routine for TextEdit's DrawHook
;-----------------------------------------------------------------
 
MyDrawGlue  proc export
    
    import  MyDrawHook:code
    
    ; We must save registers which are used in external C procedure.
    ; Note that MPW C uses a0-a1 and d0-d2 registers without presavation
    ; because these registers need not to be preserved in usual traps.
    ; But in this draw hook routine, all registers should be preserved.
    ; (See IM-6 15-25)
    
    movem.l a0-a1/d0-d2, -(sp)      ; save registers
    
    move.l  a4, -(sp)               ; push locked TEHandle (1st param)
    move.l  a3, -(sp)               ; push TEPtr
    move.l  a0, -(sp)               ; push pointer to text to draw
    move.w  d1, -(sp)               ; push length of text to draw
    move.w  d0, -(sp)               ; push offset into text (last param)
    
    lea     MyDrawHook, a0          ; get routine pointer
    jsr     (a0)                    ; jump to it
    
    movem.l (sp)+, a0-a1/d0-d2      ; restore registers
    
    ; We can use rts instruction to return to caller because
    ; this procedure doesn't have any parameters on the stack.
    
    rts                             ; return to caller
    
    endp
    
    END