home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / lynxlib / mediach.s < prev    next >
Text File  |  1993-10-23  |  7KB  |  161 lines

  1. *--------------------------------------------------------------------------*
  2. *                                                                          *
  3. *   Following code is Copyright 1989 by Atari Corporation                  *
  4. *                                                                          *
  5. *   Taken from Rainbow TOS Release Notes - August 7, 1989,                 *
  6. *   pp. 52-55.                                                             *
  7. *                                                                          *
  8. *--------------------------------------------------------------------------*
  9. *                                                                          *
  10. *   mediach: cause media-change on a logical device.                       *
  11. *                                                                          *
  12. *   USAGE:                                                                 *
  13. *       errcode = mediach(devno);   /* returns 1 for error */              *
  14. *                                                                          *
  15. *                                                                          *
  16. *   This procedure causes a media change by installing a new               *
  17. *   handler for the mediach, rwabs, and getbpb vectors; for device         *
  18. *   devno, the mediach handler returns "definitely changed." and           *
  19. *   the rwabs handler returns E_CHNG, until the new getbpb handler         *
  20. *   is called.  The new getbpb handler un-installs the new                 *
  21. *   handlers.                                                              *
  22. *                                                                          *
  23. *   After installing the new handlers, this procedure performs a           *
  24. *   disk operation (e.g. open a file) which makes GEMDOS check             *
  25. *   the media-change status of the drive: this will trigger the            *
  26. *   new rwabs, mediach and getbpb handlers to do their things.             *
  27. *                                                                          *
  28. *   RETURNS:  0 for no error, 1 for error (GEMDOS never did a              *
  29. *           getbpb call; should never happen.)                             *
  30. *                                                                          *
  31. *--------------------------------------------------------------------------*
  32.  
  33.             .globl      _mediach
  34.             
  35. _mediach:
  36.             move.l      d7,saved7       ; be good and save register for C
  37.             move.w      4(sp),d0
  38.             move.w      d0,mydev
  39.             add.b       #'A',d0
  40.             move.b      d0,fspec        ; set drive spec for search first
  41.             
  42. loop:
  43.             clr.l       -(sp)           ; get super mode, leave old ssp
  44.             move.w      #$20,-(sp)      ; and "super" function code on stack
  45.             trap        #1
  46.             addq        #6,sp
  47.             move.l      d0,-(sp)
  48.             move.w      #$20,-(sp)
  49.             
  50.             move.l      $472,oldgetbpb
  51.             move.l      $47e,oldmediach
  52.             move.l      $476,oldrwabs
  53.             
  54.             move.l      #newgetbpb,$472
  55.             move.l      #newmediach,$47e
  56.             move.l      #newrwabs,$476
  57.             
  58.             ; Fopen a file on that drive
  59.             
  60.             move.w      #0,-(sp)
  61.             move.l      #fspec,-(sp)
  62.             move.w      #$3d,-(sp)
  63.             trap        #1
  64.             addq        #8,sp
  65.             
  66.             ; Fclose the handle we just got
  67.             
  68.             tst.l       d0
  69.             bmi.s       noclose    
  70.  
  71.             move.w      d0,-(sp)
  72.             move.w      #$3e,-(sp)
  73.             trap        #1
  74.             addq        #4,sp
  75.             
  76. noclose:
  77.             moveq       #0,d7
  78.             cmp.l       #newgetbpb,$472 ; still installed
  79.             bne.s       done            ; nope
  80.             
  81.             moveq       #1,d7           ; yup! remove & return TRUE
  82.             move.l      oldgetbpb,$472
  83.             move.l      oldmediach,$47e
  84.             move.l      oldrwabs,$476
  85.             
  86. done:       trap        #1              ; go back to user mode (use stuff
  87.             addq        #$6,sp          ; left on stack above)
  88.             
  89.             move.l      d7,d0
  90.             move.l      saved7,d7       ; restore d7
  91.             rts
  92.  
  93.  
  94. *--------------------------------------------------------------------------*
  95. *                                                                          *
  96. * new getbpb: if it's our device, uninstall vectors;                       *
  97. *           in any case, call the old getbpb vector (to really             *
  98. *           get it)                                                        *
  99. *                                                                          *
  100. *--------------------------------------------------------------------------*
  101.  
  102. newgetbpb:
  103.             move.w      mydev,d0
  104.             cmp.w       4(sp),d0
  105.             bne.s       dooldg
  106.             move.l      oldgetbpb,$472  ; it's mine: un-install new vectors
  107.             move.l      oldmediach,$47e
  108.             move.l      oldrwabs,$476
  109. dooldg:     move.l      oldgetbpb,a0    ; continue here whether mine or not:
  110.                                         ; call old
  111.             jmp         (a0)
  112.   
  113. *--------------------------------------------------------------------------*
  114. *                                                                          *
  115. * new mediach:  if it's our device, return 2; else call old.               *
  116. *                                                                          *
  117. *--------------------------------------------------------------------------*
  118.                       
  119. newmediach:
  120.             move.w      mydev,d0
  121.             cmp.w       4(sp),d0
  122.             bne.s       dooldm
  123.             moveq.l     #2,d0   ; it's mine: return 2 (definitely changed)
  124.             rts
  125. dooldm:
  126.             move.l      oldmediach,a0   ; not mine: call old vector.
  127.             jmp         (a0)
  128.             
  129. *--------------------------------------------------------------------------*
  130. *                                                                          *
  131. * new rwabs:  return E_CHG (-14) if it's my device                         *
  132. *                                                                          *
  133. *--------------------------------------------------------------------------*
  134.              
  135. newrwabs:
  136.             move.w      mydev,d0
  137.             cmp.w       $e(sp),d0
  138.             bne.s       dooldr
  139.             moveq.l     #-14,d0
  140.             rts
  141.             
  142. dooldr:     move.l      oldmediach,a0
  143.             jmp         (a0)
  144.             
  145. .data
  146. fspec:      dc.b        "X:\\X",0   ; file to look for (doesn't matter)
  147.  
  148. .bss
  149. saved7:     ds.l        1
  150. mydev:      ds.w        1
  151. oldgetbpb:  ds.l        1
  152. oldmediach: ds.l        1
  153. oldrwabs:   ds.l        1
  154.  
  155. *--------------------------------------------------------------------------*
  156. *                                                                          *
  157. *           end of mediach                                                 *
  158. *                                                                          *
  159. *--------------------------------------------------------------------------*
  160.  
  161.