home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UMemory.a < prev    next >
Encoding:
Text File  |  1991-05-01  |  3.3 KB  |  101 lines  |  [TEXT/MPS ]

  1. ;=============================================================================
  2. ; UMemory assembly language routines
  3. ;
  4. ; Copyright © 1987-1990 Apple Computer, Inc.  All rights reserved.
  5. ;
  6.                 Blanks        On
  7.                 String        AsIs
  8.                 Case        On
  9.  
  10.                 Print        Off
  11.                 Include     'Macros.a'
  12.  
  13.                 LOAD            'ProgStrucMacs.d'
  14.                 LOAD            'FlowCtlMacs.d'
  15.                 Print        On
  16.  
  17.             
  18. ;---------------------------------------------------------------------------------------------------
  19. ;    PROCEDURE ALoadMacAppSeg;
  20. ;    This is the actual patch for LoadSeg.  It sets up the stack so that we
  21. ;    can call FUNCTION LoadMacAppSegment (segNum: INTEGER): LONGINT.
  22.  
  23.                 Seg         'MAMemoryRes'
  24. EXPORT PROCEDURE ALOADMACAPPSEG(theSegNum:W)
  25.  
  26.     BEGIN    Save=D0-D2/A0-A2
  27.     IMPORT    LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
  28.  
  29.                 CALL        LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
  30.  
  31.                 Move.W        theSegNum(FP),-(SP)            ; push the original parameter to loadseg
  32.                 PEA            ComeBack+6                    ; push a return address
  33.                                                         ; loadseg will knock 6 off the return address
  34.                 Jmp            (A0)                        ; Call the original loadseg
  35.  
  36. ComeBack
  37.                 CALL         POSTLOADMACAPPSEGMENT        ; call back to Pascal again
  38.  
  39.                 Sub.L            #6,4(FP)                ; jerk our return address just like loadseg does
  40. ;                Return                                     ; Return to the real world
  41. ; the Return macro doesn't preserve the A0 register because it generates the following code
  42.  
  43. ;00000026: 4CDF 0707      'L...'            MOVEM.L    (A7)+,D0-D2/A0-A2
  44. ;0000002A: 4E5E           'N^'              UNLK       A6
  45. ;0000002C: 205F           ' _'              MOVEA.L    (A7)+,A0
  46. ;0000002E: 544F           'TO'              ADDQ.W     #$2,A7
  47. ;00000030: 4ED0           'N.'              JMP        (A0)
  48.  
  49. ; So… we'll just have to take over from the computers and land this puppy by hand
  50.  
  51.                 MOVEM.L    (A7)+,D0-D2/A0-A2
  52.                 UNLK       A6
  53.                 MOVE.L    (A7),2(A7)        ; move the return address into the place of the
  54.                                             ; parameter because we will destroy the stack-frame
  55.                                             ; that includes the parameter and then just RTS
  56.                                             ; This assumes intimate knowledge (!) of the fact that
  57.                                             ; this function only has a single parameter that is
  58.                                             ; an integer (2 bytes)
  59.                 ADDQ.W     #$2,A7            ; Destroy the stack frame just like I told you
  60.                 RTS                            ; We're outta here with A0 preserved
  61.                 EndP
  62.  
  63. ;---------------------------------------------------------------------------------------------------
  64. ;    FUNCTION PreLoadSegment;
  65. ;    This function preloads a segment in both the resource manager sense and the
  66. ;    segment loader sense.
  67.  
  68.                 Seg         'MAMemoryRes'
  69. EXPORT FUNCTION PRELOADSEGMENT(theSegNum:W):B
  70.  
  71.     BEGIN    Save=D0-D2/A0-A2
  72.     IMPORT    PRELOADSEGMENTRESOURCE, LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
  73.     ; preload the resource so our call to the seg loader patch won't fail
  74.  
  75.                 CALL        PRELOADSEGMENTRESOURCE:B(theSegNum(FP):W),D0
  76.                 TST.B        D0
  77.                 BNZ.S        success
  78.     ;segment didn't load
  79.     
  80.                 Move.B        #0, PRELOADSEGMENT(FP)
  81.                 BRA.S        exit
  82.     
  83.  
  84. success
  85.                 CALL        LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
  86.  
  87.                 Move.W        theSegNum(FP),-(SP)            ; push the original parameter to loadseg
  88.                 PEA            ComeBack+6                    ; push a return address
  89.                                                         ; loadseg will knock 6 off the return address
  90.                 Jmp            (A0)                        ; Call the original loadseg
  91.  
  92. ComeBack
  93.                 CALL         POSTLOADMACAPPSEGMENT        ; call back to Pascal again
  94.  
  95.  
  96.                 Move.B        #1, PRELOADSEGMENT(FP)
  97. exit
  98.                 Return                                     ; Return to the real world
  99.  
  100.                 END
  101.