5PH r^X{{w;ToolTraps.Text
;--------------------------------------------------------------------
;
;   ToolTraps is the Pascal/QuickDraw-ToolBox trap interface.
;   It defines all the names declared external in the interface
;   code, and implements them by trapping with the "auto-pop" bit
;   set to remove the extra return address on the stack
;   before dispatching.  Most of this file was generated by the
;   program "MakeTTraps".
;
;         "written" by Andy Hertzfeld    31-Oct-82
;
;   MODIFICATION HISTORY:
;
;     21-Nov-82  AJH  regenerated for ROM 1.8
;     01-Dec-82  AJH  changes for ROM 1.9
;     13-Feb-83  AJH  regenerated for ROM 2.0
;     16-Mar-83  AJH  updated for ROM 2.4
;     20-Apr-83  BLH  Changed dialog proc names for ROM 3.0
;      4-May-83  BLH  Added new resource procs for ROM 3.0
;     28-May-83  SC   Added text edit stuff and changed dialog
;     03-Jun-83  AJH  Regenerated for ROM 4.0
;     08-Jun-83  SC   Changed AlertSound to ErrorSound
;     13-Jun-83  AJH  Added InsertResMenu, OpenDeskAcc
;     04-Aug-83  SC   Added TEInsert, TEGetText, TESetJust
;     04-Aug-83  SC   Added SystemBeep, DrawGrow
;     06-Aug-83  SC   Added HandAndHand, PtrAndHand
;     06-Aug-83  BLH  Removed EndSubResource.  Changed BeginSubResource to
;                      HomeResFile.  Added GetFinderInfo, SetFinderInfo
;                      at the end.
;     12-Aug-83  AJH  Added DragGrayRgn
;     16-Aug-83  SC   Added scrap stuff
;     18-Aug-83  BLH  Removed GetFinderInfo, SetFinderInfo.
;      2-Sep-83  SC   Removed Bytes stuff (It should be an OS).
;     21-Nov-83  RS   changed .DEFs to .PROC and .FUNC so linker could know to
;                     remove those procedures not used by the pascal program
;
;     30-Dec-83  RS&AH   Added SizeResource
;
;     14-Feb-84  RTM  Ripped out stuff for inline traps
;
;--------------------------------------------------------------------
                .NoList
                .INCLUDE tlasm/ToolMacs.Text
                .INCLUDE tlasm/ToolEqu.Text
                .INCLUDE tlasm/SysMacs.Text
                .INCLUDE tlasm/SysEqu.Text
                .List

;

; Important note- The Pascal compiler requires at least one procedure or function
;       reference in the implementation section of a unit. For Quickdraw, we
;       leave InitGraf in the implementation section. (RTM)

                .PROC   InitGraf
                .WORD   $AC6E

                .PROC   PackBits
                .WORD   $ACCF

                .PROC   UnpackBi
                .WORD   $ACD0

; .PROC is used below for both procedures and functions since the linker does
; not check proc vs. func and it was just easier to replace .DEFs globally - RS

                .PROC   DragGrayRgn                     ; ??
                .WORD   $AD05

;                .PROC    LBin2Dec
;                .WORD   $ADC4

;                .PROC    LDec2Bin
;                .WORD   $ADC5

                .PROC   SystemEr
                .WORD   $ADC9

                .PROC   PutIcon
                .WORD   $ADCA

                .PROC   Pack0
                .WORD   $ADE7

                .PROC   Pack1
                .WORD   $ADE8

                .PROC   Pack2
                .WORD   $ADE9

                .PROC   Pack3
                .WORD   $ADEA

                .PROC   FP68K
                .WORD   $ADEB

                .PROC   Pack4
                .WORD   $ADEB

                .PROC   Pack5
                .WORD   $ADEC

                .PROC   Pack6
                .WORD   $ADED

                .PROC   Pack7
                .WORD   $ADEE

                .PROC   Launch
                .WORD   $ADF2

                .PROC   Chain
                .WORD   $ADF3

;
;FUNCTION HandToHand(VAR theHndl: Handle): OsErr;
;
; clones handle in A0 returning the new handle in A0

                .PROC   HandToHand

                MOVE.L  4(SP),A0                ;ptr to handle
                MOVE.L  (A0),A0                 ;the Handle
                _HandToHa
                MOVE.L  4(SP),A1                ;ptr to handle to be returned
                MOVE.L  A0,(A1)                 ;return the new handle
                MOVE    D0,8(SP)                ;return error
                MOVE.L  (SP)+,(SP)              ;pop off the return addr
                RTS


;
;FUNCTION PtrToXHand(srcPtr: Ptr; dstHndl: Handle; size: LongInt): OsErr;
;
; copies size bytes from the srcPtr into the existing handle

                .PROC   PtrToXHand

                MOVE.L  (SP)+,D1                ;save return address
                MOVE.L  (SP)+,D0                ;the size
                MOVE.L  (SP)+,A1                ;existing handle
                MOVE.L  (SP)+,A1                ;srcPtr
                MOVE.L  D1,-(SP)                ;restore return address
                _PtrToXHa
                MOVE.W  D0,4(SP)                ;error code
                RTS                             ;return
;
;FUNCTION PtrToHand(srcPtr: Ptr; VAR dstHndl: Handle; size: LongInt): OsErr;
;
; makes a handle and copies size bytes of the handle into it

                .PROC   PtrToHand

                MOVE.L  12(SP),A0               ;src pointer
                MOVE.L  4(SP),D0                ;size
                _PtrToHan                       ;make a new handle and copy ptr in
                MOVE.W  D0,16(SP)               ;error code
                MOVE.L  8(SP),A1                ;address of handle
                MOVE.L  A0,(A1)                 ;return new handle
                MOVE.L  (SP)+,A0                ;return addr
                ADD     #12,SP                  ;pop off args
                JMP     (A0)                    ;return
;
;FUNCTION HandAndHand(hand1,hand2: Handle): OsErr;
;
; concatenates hand1 onto the end of hand2

                .PROC   HandAndHand

                MOVE.L  8(SP),A0                ;source handle
                MOVE.L  4(SP),A1                ;other source handle
                _HandAndH                       ;concats hndl in A0 to H in A1
                MOVE    D0,12(SP)
                MOVE.L  (SP)+,A0                ;return addr
                ADDQ    #8,SP                   ;pop off args
                JMP     (A0)                    ;return
;
;FUNCTION PtrAndHand(ptr1: Ptr; hand2: Handle; size: LongInt): OsErr;
;
; concatenates ptr1 onto the end of hand2

                .PROC   PtrAndHand

                MOVE.L  4(SP),D0                ;length of ptr
                MOVE.L  8(SP),A1                ;handle
                MOVE.L  12(SP),A0               ;ptr
                _PtrAndHa                       ;concat ptr to handle
                MOVE    D0,16(SP)               ;return error
                MOVE.L  (SP)+,A0                ;return addr
                ADD     #12,SP
                JMP     (A0)

;
;FUNCTION GetAlrtStage: INTEGER;             {returns aCount}
;

                .PROC   GetAlrtStage

                MOVE.W  ACount,4(SP)            ;return the alertCount
                RTS


;
;PROCEDURE ResetAlrtStage;
;

                .PROC   ResetAlrtStage

                MOVE.W  #0,ACount
                RTS

;
;PROCEDURE DlgCut(dialog: DialogPtr);
;PROCEDURE DlgPaste(dialog: DialogPtr);
;PROCEDURE DlgCopy(dialog: DialogPtr);
;PROCEDURE DlgDelete(dialog: DialogPtr);
;

        .PROC   DlgPaste
        .DEF    DlgCut
        .DEF    DlgCopy
        .DEF    DlgDelete

                BSR.S   StdCheck
                _TEPaste

adios           MOVE.L  (SP)+,(SP)              ;pop return/argument
                RTS

DlgCut          BSR.S   StdCheck
                _TECut
                BRA.S   adios

DlgCopy         BSR.S   StdCheck
                _TECopy
                BRA.S   adios

DlgDelete       BSR.S StdCheck
                _TEDelete
                BRA.S   adios

StdCheck        MOVE.L  8(SP),A0                ;get dialog ptr
                TST     EditField(A0)           ;see if edit is open
                BMI.S   noDice
                MOVE.L  (SP)+,A1                ;pop return for stdcheck
                MOVE.L  TEHandle(A0),-(SP)      ;pass text edit handle
                JMP     (A1)

noDice          MOVEM.L (SP)+,D0/A0-A1          ;get real return addr
                JMP     (A0)                    ;return

;
;PROCEDURE SetDAFont(fontNum: INTEGER);
;

                .PROC   SetDAFont

                MOVE.L  (SP)+,A0                ;return addr
                MOVE.W  (SP)+,dlgFont           ;set new dlg font
                JMP     (A0)


;
;FUNCTION TEScrapHndl: Handle;

                .PROC TEScrapHndl

                MOVE.L  TEScrpHandle,4(SP)
                RTS

;
; FUNCTION TEGetScrapLen: LongInt;

                .PROC TEGetScrapLen

                CLR.L   4(SP)
                MOVE.W  TEScrpLength,6(SP)
                RTS

;
; FUNCTION TESetScrapLen(length: LongInt);

                .PROC TESetScrapLen

                MOVE.W  6(SP),TEScrpLength      ;low order word of longInt is len
                MOVE.L  (SP)+,(SP)              ;pop arg
                RTS

;
; FUNCTION GetDblTime: LongInt;

                .FUNC GetDblTime

                MOVE.L doubleTime,4(SP)
                RTS

;
; FUNCTION GetCaretTime: LongInt;

                .FUNC GetCaretTime

                MOVE.L  caretTime,4(SP)
                RTS

;PROCEDURE GetIndString(VAR theString: str255; strListID: INTEGER;
;                       index: INTEGER);
;
;gets the STR# resource with ID strListID and returns in theString the index-th
;string in the string list.

                .PROC GetIndString

                LINK    A6,#0

                ;get the string list
                SUBQ    #4,SP                   ;room for result handle
                MOVE.L  #'STR#',-(SP)           ;theType
                MOVE.W  10(A6),-(SP)            ;strListID
                _GetResource
                MOVE.L  12(A6),A1               ;ptr to where to return the str
                CLR.B   (A1)                    ;assume empty
                MOVE.L  (SP)+,D0                ;handle to string list
                BEQ.S   gsret                   ;if empty, just quit
                MOVE.L  D0,A0                   ;get handle in A0
                MOVE.L  (A0),A0                 ;deref it
                MOVE.W  (A0)+,D0                ;get the number of strings
                MOVE.W  8(A6),D1                ;the index
                CMP.W   D0,D1                   ;is index larger than count?
                BGT.S   gsret                   ;yes, just quit
                MOVEQ   #0,D0                   ;will keep track of length of strs

gsLoop          SUBQ.W  #1,D1                   ;decrement the index
                BEQ.S   gsCopy                  ;found the one we are looking for
                MOVE.B  (A0)+,D0                ;get length of this one
                ADD.L   D0,A0                   ;skip over this string
                BRA.S   gsLoop                  ;and go on to next

gsCopy          MOVE.B  (A0),D0                 ;get the length of this string
                ADDQ    #1,D0                   ;add one for the length byte
                _BlockMove                      ;copy it into the string

gsret           UNLK    A6
                MOVE.L  (SP)+,A0                ;return addr
                ADDQ.L  #8,SP                   ;pop off parms
                JMP     (A0)                    ;return


;PROCEDURE GetIndPattern(VAR thePat: Pattern; patListID: INTEGER;index: INTEGER)
;
;gets PAT# resource with ID patListID and stuffs into thePat the index-th
;pattern in the list.

                .PROC GetIndPattern

                LINK    A6,#0

                ;get the string list
                SUBQ    #4,SP                   ;room for result handle
                MOVE.L  #'PAT#',-(SP)           ;theType
                MOVE.W  10(A6),-(SP)            ;patListID
                _GetResource
                MOVE.L  12(A6),A1               ;ptr to where to return the pat
                MOVE.L  (SP)+,D0                ;handle to string list
                BEQ.S   gpret                   ;if empty, just quit
                MOVE.L  D0,A0                   ;get handle in A0
                MOVE.L  (A0),A0                 ;deref it
                MOVE.W  (A0)+,D0                ;get the number of patterns
                MOVE.W  8(A6),D1                ;the index
                BLE.S   gpret                   ;no such thing as negative index
                CMP.W   D0,D1                   ;is index larger than count?
                BGT.S   gpret                   ;yes, just quit

gpLoop          SUBQ.W  #1,D1                   ;decrement the index
                BEQ.S   gpCopy                  ;found the one we are looking for
                ADDQ    #8,A0                   ;skip over the pattern
                BRA.S   gpLoop                  ;and go on to next

gpCopy          MOVEQ   #8,D0                   ;a pattern is 8 bytes
                _BlockMove                      ;copy it into the string

gpret           UNLK    A6
                MOVE.L  (SP)+,A0                ;return addr
                ADDQ.L  #8,SP                   ;pop off parms
                JMP     (A0)                    ;return

                .END
