home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / Split_GUI.lha / Split_v1.0 / Sources.lha / Sources / handler.s < prev    next >
Encoding:
Text File  |  1995-03-06  |  2.3 KB  |  127 lines

  1. ;    INCDIR    "INCLUDE:"
  2.     INCLUDE    "exec/types.i"
  3.     INCLUDE    "exec/io.i"
  4.     INCLUDE    "devices/inputevent.i"
  5.     INCLUDE "LVO3.0/exec_lib.i"
  6.     INCLUDE "LVO3.0/dos_lib.i"
  7.  
  8.     section text,code
  9.  
  10. ;    This file contains source for the handler signalling a disk has been
  11. ;    inserted or removed, plus the code to patch Delete and Close.
  12.  
  13.     xref    _diskSig
  14.     xref    _thisTask
  15.     xref    _DOSBase
  16.     xref    _IntuitionBase
  17.  
  18.     xdef    _checkDisk
  19.     xdef    _patchDOSlibrary
  20.     xdef    _resetDOSlibrary
  21.  
  22.  
  23. _checkDisk:
  24.     move.l    a0,-(sp)
  25.     moveq    #0,d0
  26. .checkloop
  27.     cmp.b    #IECLASS_DISKREMOVED,ie_Class(a0)
  28.     bne.s    .try_inserted
  29.     moveq    #1,d0
  30.     bra    .end
  31. .try_inserted
  32.     cmp.b    #IECLASS_DISKINSERTED,ie_Class(a0)
  33.     bne.s    .try_nextevent
  34.     moveq    #1,d0
  35.     bra .end
  36. .try_nextevent
  37.     move.l    (a0),d0
  38.     move.l    d0,a0
  39.     bne.s    .checkloop
  40. .end
  41.     tst    d0
  42.     beq    .nosig
  43.     move.l    $4,a6
  44.     move.l    _thisTask,a1
  45.     move.l    _diskSig,d0
  46.     jsr    _LVOSignal(a6)
  47. .nosig
  48.     move.l    (sp)+,d0
  49.     rts
  50.  
  51. ;    calling this function from here will patch Delete and Close
  52. ;    with the new values; while "startpatch" label is a jump from
  53. ;    _resetDOSlibrary in case the patches were re-patched - so they're
  54. ;    set again with the re-patched value.
  55.  
  56. _patchDOSlibrary:
  57.     move.l    $4,a6
  58.     move.l    #_patchDelete,oldDelete
  59.     move.l    #_patchClose,oldClose
  60.     jsr    _LVOForbid(a6)
  61. startpatch
  62.     move.l    _DOSBase,a1
  63.     move.l    oldDelete,d0
  64.     move.w    #_LVODeleteFile,a0
  65.     jsr    _LVOSetFunction(a6)
  66.     move.l    d0,oldDelete
  67.     move.l    _DOSBase,a1
  68.     move.l    oldClose,d0
  69.     move.w    #_LVOClose,a0
  70.     jsr    _LVOSetFunction(a6)
  71.     move.l    d0,oldClose
  72.     jsr    _LVOPermit(a6)
  73.     move.w    #0,d0            ; this *IS* important (return FALSE
  74.     rts                ;    from resetDOSlibrary)
  75.  
  76. _resetDOSlibrary:
  77.     move.l    $4,a6
  78.     jsr    _LVOForbid(a6)
  79.     move.l    _DOSBase,a1
  80.     move.l    oldDelete,d0
  81.     move.w    #_LVODeleteFile,a0
  82.     jsr    _LVOSetFunction(a6)
  83.     move.l    d0,patchReturn1        ; a temporary value
  84.     move.l    _DOSBase,a1
  85.     move.l    oldClose,d0
  86.     move.w    #_LVOClose,a0
  87.     jsr    _LVOSetFunction(a6)
  88.     cmp.l    #_patchClose,d0
  89.     bne    .resetError
  90.     move.l    patchReturn1,d0
  91.     cmp.l    #_patchDelete,d0
  92.     bne    .resetError
  93.     move.w    #1,d0
  94.     jsr    _LVOPermit(a6)
  95.     rts
  96. .resetError:
  97.     move.l    d0,oldClose
  98.     move.l    patchReturn1,oldDelete
  99.     bra    startpatch
  100.  
  101. _patchClose:
  102.     move.l    a2,-(sp)
  103.     move.l    oldClose,a2
  104.     bra.s    cont
  105.  
  106. _patchDelete:
  107.     move.l    a2,-(sp)
  108.     move.l    oldDelete,a2
  109. cont:
  110.     jsr    (a2)
  111.     movem.l    d0/a6,-(sp)
  112.     move.l    $4,a6
  113.     move.l    _thisTask,a1
  114.     move.l    _diskSig,d0
  115.     jsr    _LVOSignal(a6)
  116.     movem.l    (sp)+,d0/a6
  117.     move.l    (sp)+,a2
  118.     rts
  119.  
  120. oldClose:
  121.     dc.l    0
  122. oldDelete:
  123.     dc.l    0
  124. patchReturn1
  125.     dc.l    0
  126.     end
  127.