home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / os20 / util / mfrhelp / mfrhelp.s < prev    next >
Text File  |  1993-12-21  |  6KB  |  230 lines

  1. ;-------------------------------------------------------------------------------
  2. *                                                                              *
  3. * MFRHelp                                                                      *
  4. *                                                                              *
  5. *                                                                              *
  6. *       Filename        mfrhelp.s                                              *
  7. *       Author          Daniel Weber                                           *
  8. *       Version         0.20                                                   *
  9. *       Start           18.10.93                                               *
  10. *                                                                              *
  11. *       Last Revision   18.10.93                                               *
  12. *                                                                              *
  13. *                                                                              *
  14. *       Written using the ProAsm assembler                                     *
  15. *                                                                              *
  16. ;-------------------------------------------------------------------------------
  17.  
  18.     output    'ram:mfrhelp'
  19.  
  20.     opt    o+,q+,ow-,qw-            ;optimize
  21.     verbose
  22.     super
  23.     MC68040
  24.  
  25. ;-------------------------------------------------------------------------------
  26.  
  27.     incdir    'include:'
  28.     incdir    'dh1:routines'
  29.  
  30.     include    'libraries/asl.i'
  31.     include    'exec/execbase.i'
  32.     include    'exec/memory.i'
  33.  
  34. ;-------------------------------------------------------------------------------
  35.  
  36. AbsExecBase            EQU    4
  37.  
  38. * exec library offsets
  39. _LVOSupervisor            EQU    -30
  40. _LVOForbid            EQU    -132
  41. _LVOPermit            EQU    -138
  42. _LVOAllocMem            EQU    -198
  43. _LVOCloseLibrary        EQU    -414
  44. _LVOSetFunction            EQU    -420
  45. _LVOOpenLibrary            EQU    -552
  46. _LVOCacheClearU            EQU    -636
  47.  
  48. * utility library offset
  49. _LVOFindTagItem            EQU    -30
  50.  
  51. * asl library offset
  52. _LVOAslRequest            EQU    -60
  53.  
  54.  
  55. ;-------------------------------------------------------------------------------
  56. progbase:
  57.     movem.l    d0-a6,-(a7)
  58.  
  59.     moveq    #36,d0                ;open asl.library
  60.     lea    AslName(pc),a1
  61.     move.l    (AbsExecBase).w,a6
  62.     jsr    _LVOOpenLibrary(a6)
  63.     move.l    d0,AslBase            ;no asl.library => exit
  64.     beq    .out
  65.  
  66.     move.l    #patchend-patch,d0        ;allocate memory for patch
  67.     move.l    #MEMF_PUBLIC,d1
  68.     jsr    _LVOAllocMem(a6)
  69.     move.l    d0,location            ;no memory for patch => exit
  70.     beq    .quit
  71.  
  72.     lea    patch(pc),a0            ;copy patch...
  73.     move.l    d0,a1
  74.     move.w    #patchend-patch-1,d7
  75. .copy:    move.b    (a0)+,(a1)+
  76.     dbra    d7,.copy
  77.  
  78. ;
  79. ; clear all caches if needed
  80. ;
  81. .clearcaches:
  82.     btst    #1,AttnFlags+1(a6)        ;68000/10 installed?
  83.     beq.s    .set
  84.     cmp.w    #36,LIB_VERSION(a6)        ;2.0 or higher?
  85.     bcc.s    .exec
  86.     lea    .clear(pc),a5
  87.     jsr    _LVOSupervisor(a6)
  88.     bra.s    .set
  89.  
  90. .clear:    movec    cacr,d1                ;save cache control register
  91.     move.w    #$8000,d2            ;small 68040 processor test
  92.     movec    d2,cacr
  93.     movec    cacr,d2
  94.     tst.w    d2                ;d2.w=$8xxx => 68040 installed
  95.     bmi.s    .68040
  96.     or.w    #$808,d1            ;data and instruction cache clear
  97.     bra.s    .cc
  98. .68040:    cpusha    bc                ;68040: clear both caches
  99. .cc:    movec    d1,cacr                ;restore cache control register
  100.     rte
  101.  
  102. .exec:    jsr    _LVOCacheClearU(a6)        ;exec used for 2.0 of higher
  103.  
  104.  
  105. ;
  106. ; install patch
  107. ;
  108. .set:    move.l    (AbsExecBase).w,a6
  109.     jsr    _LVOForbid(a6)
  110.  
  111.     move.l    AslBase(pc),a1            ;install patch
  112.     lea    _LVOAslRequest,a0
  113.     move.l    location(pc),a5
  114.     move.l    a5,d0
  115.     jsr    _LVOSetFunction(a6)
  116.     move.l    d0,oldFunction-patch(a5)
  117.  
  118.     jsr    _LVOPermit(a6)
  119.  
  120. ;
  121. ; done...
  122. ;
  123. .quit:    move.l    AslBase(pc),a1
  124.     jsr    _LVOCloseLibrary(a6)
  125.  
  126. .out:    movem.l    (a7)+,d0-a6
  127.     moveq    #0,d0
  128.     rts
  129.  
  130.  
  131.  
  132. ;-------------------------------------------------------------------------------
  133. *
  134. * the patch
  135. *
  136. ;-------------------------------------------------------------------------------
  137.  
  138. patch:    movem.l    a0/a1,-(a7)            ;save structure pointer & taglist
  139.     pea    patch2(pc)            ;return address for old function
  140.     move.l    oldFunction(pc),-(a7)    ;old Function (returned by SetFunction)
  141.     rts
  142.  
  143. ;
  144. ; correct result of MFR's ASLRequest patch
  145. ;
  146. patch2:    movem.l    (a7),a0/a1
  147.     tst.l    d0                ;no file selected
  148.     beq    .out
  149.  
  150.  
  151.     movem.l    d0-a6,-(a7)            ;check for DOMULTISELECT
  152.     moveq    #0,d5
  153.  
  154.     move.l    (AbsExecBase).w,a6        ;check for CygnusEd3.5
  155.     move.l    ThisTask(a6),a0
  156.     move.l    LN_NAME(a0),d0            ;pointer to name
  157.     beq.s    2$
  158.     move.l    d0,a0
  159.     lea    cedname(pc),a2
  160. .loop:    tst.b    (a2)                ;compare task name
  161.     beq.s    .ok
  162.     cmp.b    (a0)+,(a2)+
  163.     beq.s    .loop
  164.     bra.s    2$                ;not CygnusEd3.5
  165.  
  166. .ok:    moveq    #36,d0                ;open utility.library
  167.     lea    UtilityName(pc),a1
  168.     jsr    _LVOOpenLibrary(a6)
  169.     move.l    d0,a6
  170.     move.l    a6,d0
  171.     beq.s    2$
  172.  
  173.     move.l    #ASLFR_Flags1,d0        ;search for ASLFR_Flags1 tag
  174.     move.l    _movembytes+4(a7),a0        ;= 64(a7) (ced3.5's taglist)
  175.     jsr    _LVOFindTagItem(a6)
  176.     tst.l    d0
  177.     beq.s    1$                ;not found
  178.     move.l    d0,a0
  179.     move.l    ti_Data(a0),d0
  180.     btst    #FRB_DOMULTISELECT,d0        ;DOMULTISELECT bit set?
  181.     sne    d5
  182. 1$:    move.l    #ASLFR_DoMultiSelect,d0        ;search for ASLFR_DoMultiSelect
  183.     move.l    _movembytes+4(a7),a0        ;= 64(a7)
  184.     jsr    _LVOFindTagItem(a6)
  185.     tst.l    d0
  186.     beq.s    11$                ;not found
  187.     move.l    d0,a0
  188.     tst.l    ti_Data(a0)
  189.     sne    d5
  190.  
  191. 11$:    move.l    a6,a1                ;close utility.library
  192.     move.l    (AbsExecBase).w,a6
  193.     jsr    _LVOCloseLibrary(a6)
  194.  
  195. 2$:    tst.l    d5                ;d5: (0: no... -: DOMULTISELECT)
  196.     movem.l    (a7)+,d0-a6
  197.     beq.s    .out
  198.  
  199.     tst.l    fr_NumArgs(a0)            ;correct the ASL filerequester
  200.     bne.s    .out                ;structure...
  201.     addq.l    #1,fr_NumArgs(a0)        ;set fr_NumArgs to 1
  202.     tst.l    fr_ArgList(a0)
  203.     bne.s    .out
  204.     mea    (a0),fr_ArgList(a0)        ;HACK!!! (for CED) to simulate
  205. .out:    movem.l    (a7)+,a0/a1            ;a valid filelist with one entry
  206.     rts
  207.  
  208. oldFunction:    dc.l    0
  209.  
  210. cedname:    dc.b    "CygnusEd ver. 3.5",0
  211. UtilityName:    dc.b    "utility.library",0
  212.         even
  213. patchend:
  214.  
  215.  
  216. ;-------------------------------------------------------------------------------
  217. *
  218. * data
  219. *
  220. ;-------------------------------------------------------------------------------
  221.  
  222. AslName:    dc.b    "asl.library",0
  223.         even
  224.  
  225.  
  226. AslBase:    dc.l    0
  227. location:    dc.l    0
  228.  
  229.     END
  230.