home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / System / Swatch / Development / swatch 1.2 / swatch INIT / drvr.patches.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-17  |  3.9 KB  |  179 lines  |  [TEXT/KAHL]

  1. /**
  2.  
  3.     drvr.patches.c
  4.     Copyright (c) 1990, Adobe Systems, Inc.
  5.  
  6.  **/
  7.  
  8.  
  9. /**-----------------------------------------------------------------------------
  10.  **
  11.  **    Headers
  12.  **
  13.  **/
  14.  
  15. #include "drvr.globals.h"
  16. #include "drvr.patches.h"
  17.  
  18.  
  19. /**-----------------------------------------------------------------------------
  20.  **
  21.  ** Private Constants
  22.  **
  23.  **/
  24.  
  25. #define TRAP_OpenResFile    0xA997
  26. #define TRAP_CloseResFile    0xA99A
  27.  
  28.  
  29. /**-----------------------------------------------------------------------------
  30.  **
  31.  ** Private Variables
  32.  **
  33.  **/
  34.  
  35. void *OpenResFile_orig_addr;
  36. void *CloseResFile_orig_addr;
  37.  
  38.  
  39. /**-----------------------------------------------------------------------------
  40.  **
  41.  ** Private Variables
  42.  **
  43.  **/
  44.  
  45. void OpenResFile_patch( void );
  46. void CloseResFile_patch( void );
  47.  
  48.  
  49. /*******************************************************************************
  50.  **
  51.  **    Public Functions
  52.  **
  53.  **/
  54.  
  55. /*******************************************************************************
  56.  ***
  57.  *** OSErr Install_patches( void );
  58.  ***
  59.  *** summary
  60.  ***
  61.  *** History:
  62.  ***
  63.  ***/
  64.  
  65. OSErr Install_patches( void )
  66. {
  67.     register App_stat_t *a;
  68.     register int16 i;
  69.  
  70.     asm {
  71.                 lea        @swatch_A4, A0
  72.                 move.l    A4, (A0)
  73.     }
  74.     Globals.version = VERSION;
  75.     Globals.max_apps = MAX_APPS;
  76.     Globals.zero = 0;
  77.     Globals.num_apps = 0;
  78.     Globals.apps_need_updating = FALSE;
  79.     if ( !( a = (App_stat_t *) NewPtr( (int32) sizeof( App_stat_t ) * MAX_APPS ) ) )
  80.         return MemError();
  81.     Globals.apps = a;
  82.     for ( i = MAX_APPS; i; ++a, --i )
  83.         a->free = TRUE;
  84.  
  85.     OpenResFile_orig_addr = (void *) NGetTrapAddress( TRAP_OpenResFile, ToolTrap );
  86.     NSetTrapAddress( OpenResFile_patch, TRAP_OpenResFile, ToolTrap );
  87.  
  88.     CloseResFile_orig_addr = (void *) NGetTrapAddress( TRAP_CloseResFile, ToolTrap );
  89.     NSetTrapAddress( CloseResFile_patch, TRAP_CloseResFile, ToolTrap );
  90.  
  91.     return noErr;
  92.  
  93.     asm {
  94. swatch_A4:        dc.l    0
  95.  
  96. extern OpenResFile_patch:
  97.                 movem.l    A0/A1/A4, -(A7)
  98.                 lea        @swatch_A4, A4            ; get our app's globals
  99.                 movea.l    (A4), A4
  100.  
  101.                 movea.l    0x10(A7), A0            ; get name of res file
  102.                 lea        CurApName, A1            ; are we opening the current app?
  103.                 moveq    #0, D0
  104.                 move.b    (A0), D0
  105. @open2:            cmpm.b    (A0)+, (A1)+
  106.                 dbne    D0, @open2
  107.  
  108.                 bne.s    @open9
  109.  
  110.                 move.w    #MAX_APPS, D0            ; yes, find avail slot and fill it in
  111.                 cmp.w    Globals.num_apps, D0
  112.                 beq.s    @open9                    ; app table full
  113.  
  114.                 subq.w    #1, D0
  115.                 movea.l    Globals.apps, A1
  116. @open4:            tst.b    OFFSET( App_stat_t, free )(A1)
  117.                 bne.s    @open5                    ; found a free slot
  118.  
  119.                 adda.w    #sizeof( App_stat_t ), A1
  120.                 dbra    D0, @open4
  121.  
  122.                 bra.s    @open9                    ; should never happen...
  123.  
  124. @open5:            clr.b    OFFSET( App_stat_t, free )(A1)        ; set up stats
  125.                 move.l    ApplZone, OFFSET( App_stat_t, zone )(A1)
  126.                 lea        CurApName, A0
  127.                 lea        OFFSET( App_stat_t, appname )(A1), A1
  128.                 moveq    #0, D0
  129.                 move.b    (A0), D0
  130. @open6:            move.b    (A0)+, (A1)+
  131.                 dbra    D0, @open6
  132.  
  133.                 addq.w    #1, Globals.num_apps
  134.                 move.b    #TRUE, Globals.apps_need_updating
  135.  
  136. @open9:            move.l    OpenResFile_orig_addr, D0    ; do the _OpenResFile
  137.                 movem.l    (A7)+, A0/A1/A4
  138.                 move.l    D0, -(A7)
  139.                 rts
  140.  
  141.  
  142. extern CloseResFile_patch:
  143.                 movem.l    D1/A0-A2/A4, -(A7)
  144.                 lea        @swatch_A4, A4            ; get our app's globals
  145.                 movea.l    (A4), A4
  146.  
  147.                 move.w    CurApRefNum, D0
  148.                 cmp.w    0x18(A7), D0            ; are we closing the current app?
  149.                 bne.s    @close9
  150.  
  151.                 move.w    #MAX_APPS-1, D0            ; yes, find slot and free it
  152.                 movea.l    Globals.apps, A1
  153. @close1:        tst.b    OFFSET( App_stat_t, free )(A1)
  154.                 bne.s    @close3
  155.  
  156.                 lea        CurApName, A0            ; is this the app?
  157.                 lea        OFFSET( App_stat_t, appname )(A1), A2
  158.                 moveq    #0, D1
  159.                 move.b    (A0), D1
  160. @close2            cmpm.b    (A0)+, (A2)+
  161.                 dbne    D1, @close2
  162.  
  163.                 bne.s    @close3                    ; no, keep looking
  164.  
  165.                 move.b    #TRUE, OFFSET( App_stat_t, free )(A1)    ; yes, make free
  166.                 subq.w    #1, Globals.num_apps
  167.                 move.b    #TRUE, Globals.apps_need_updating
  168.                 bra.s    @close9
  169.  
  170. @close3:        adda.w    #sizeof( App_stat_t ), A1
  171.                 dbra    D0, @close1
  172.                 
  173. @close9:        move.l    CloseResFile_orig_addr, D0    ; do the _CloseResFile
  174.                 movem.l    (A7)+, D1/A0-A2/A4
  175.                 move.l    D0, -(A7)
  176.                 rts
  177.     }
  178. }
  179.