[comp.sys.amiga.tech] Routines to allocate low level serial/parallel hardware via resources.

dillon@POSTGRES.BERKELEY.EDU (Matt Dillon) (11/16/88)

	These are excerps from my sup32.lib support library, recently
distributed to comp.sources/binaries.amiga:


rval  = AutoAllocMiscResource(resno, value)

	resno: MR_SERIALPORT, SERIALBITS, PARALLELPORT, or PARALLELBITS
	value:	-1 to allocate, 0 to check.

	This functions allocates or checks the specified resource.  0
	(ZERO) is returned on SUCCESS (allocated or could allocate),

	NON-ZERO is returned if the resource is already allocated by
	somebody else.

(void)= AutoFreeMiscResource(resno)

	Free's a resource you allocated.  YOU MUST OWN THE RESOURCE!

	Neither of these functions require you to open the misc.resource
	resource.


 ;
 ;  EXEC resource support
 ;			       4(sp)  8(sp)
 ;	AutoAllocMiscResource(resno, value)
 ;	    resno:  MR_SERIALPORT, SERIALBITS, PARALLELPORT, PARALLELBITS
 ;	    value:  -1 to allocate, 0 to check
 ;
 ;	    returns 0 on success
 ;
 ;	AutoFreeMiscResource(resno)
 ;			      4(sp)
 ;	    Free a misc resource you allocated
 ;
 ;	No need to open the misc.resource

	    public  _AutoAllocMiscResource
	    public  _AutoFreeMiscResource
	    public  _LVOOpenResource

	    FAR     DATA

_AutoAllocMiscResource:
	    move.l  A6,-(sp)
	    bsr     OpenMiscResource
	    beq     amfail
	    move.l  8(sp),D0
	    move.l  12(sp),A1
	    jsr     -6(A6)
	    bra     amret
amfail	    moveq.l #-1,D0
amret	    move.l  (sp)+,A6
	    rts

_AutoFreeMiscResource:
	    move.l  A6,-(sp)
	    bsr     OpenMiscResource
	    beq     fmret
	    move.l  8(sp),D0
	    jsr     -12(A6)
fmret	    move.l  (sp)+,A6
	    rts

OpenMiscResource:
	    move.l  4,A6
	    lea.l   MiscName,A1
	    jsr     _LVOOpenResource(A6)
	    move.l  D0,A6
	    tst.l   D0
	    rts

MiscName:   dc.b    "misc.resource",0