home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / alloc_misc.a < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.9 KB  |  85 lines

  1. * Alloc_Misc.a
  2. *
  3. * Assembly language fragment that grabs the two parts of the serial
  4. * resource (using misc.resource).  If it gets the resource, it will
  5. * wait for CTRL-C to be pressed before releasing.
  6. *
  7. * While we are waiting, the query_serial program should be run.  It will try
  8. * to open the serial device and if unsuccessful, will return the name of the
  9. * owner.  It will be us, Serial Port Hog!
  10. *
  11. * When a task has successfully obtained the serial resource, it "owns"
  12. * the hardware registers that control the serial port.  No other tasks
  13. * are allowed to interfere.
  14. *
  15. * Assemble with Adapt
  16. *     HX68 Allocate_Misc.a to Allocate_Misc.o
  17. *
  18. * Link
  19. *     Blink FROM Allocate_Misc.o TO Allocate_Misc LIB LIB:amiga.lib
  20. *
  21.  
  22.                 INCDIR  "include:"
  23.                 INCLUDE "exec/types.i"
  24.                 INCLUDE "resources/misc.i"
  25.                 INCLUDE "dos/dos.i"
  26.  
  27.         xref    _AbsExecBase     ; We get this from outside...
  28.         xref    _LVOOpenResource ; We get this from outside...
  29.         xref    _LVOWait         ; We get this from outside...
  30.  
  31. ;
  32. ; Open Exec and the misc.resource, check for success
  33. ;
  34.                 move.l  _AbsExecBase,a6         ;Prepare to use exec
  35.                 lea.l   MiscName(pc),a1
  36.                 jsr     _LVOOpenResource(a6)    ;Open "misc.resource"
  37.                 move.l  d0,d7                   ;Stash resource base
  38.                 bne.s   resource_ok
  39.                 moveq   #RETURN_FAIL,d0
  40.                 rts
  41.  
  42. resource_ok     exg.l   d7,a6                   ;Put resource base in A6
  43.  
  44. ;
  45. ; We now have a pointer to a resource.
  46. ; Call one of the resource's library-like vectors.
  47. ;
  48.                 move.l  #MR_SERIALBITS,d0       ;We want these bits
  49.                 lea.l   MyName(pc),a1           ;This is our name
  50.                 jsr     MR_ALLOCMISCRESOURCE(a6)
  51.                 tst.l   d0
  52.                 bne.s   no_bits                 ;Someone else has it...
  53.                 move.l  #MR_SERIALPORT,d0
  54.                 lea.l   MyName(pc),a1
  55.                 jsr     MR_ALLOCMISCRESOURCE(a6)
  56.                 tst.l   d0
  57.                 bne.s   no_port                 ;Someone else has it...
  58. ;
  59. ; We just stole the serial port registers; wait.
  60. ; Nobody else can use the serial port, including the serial.device!
  61. ;
  62.                 exg.l   d7,a6                   ;use exec again
  63.                 move.l  #SIGBREAKF_CTRL_C,d0
  64.                 jsr     _LVOWait(a6)            ;Wait for CTRL-C
  65.                 exg.l   d7,a6                   ;Get resource base back
  66. ;
  67. ; Free 'em up
  68. ;
  69.                 move.l  #MR_SERIALPORT,d0
  70.                 jsr     MR_FREEMISCRESOURCE(a6)
  71. no_port
  72.                 move.l  #MR_SERIALBITS,d0
  73.                 jsr     MR_FREEMISCRESOURCE(a6)
  74. no_bits
  75.                 moveq   #RETURN_FAIL,d0
  76.                 rts
  77. ;
  78. ; Text area
  79. ;
  80. MiscName        dc.b    'misc.resource',0
  81. MyName          dc.b    'Serial Port Hog',0
  82.                 dc.w    0
  83.                 END
  84.  
  85.