[comp.sys.mac.programmer] DrvrInstall and DrvrRemove

resnick@cogsci.uiuc.edu (Pete Resnick) (11/12/90)

I was reading a draft tech note written by Mark Bennett that talked
about installing drivers at INIT time. I have a couple of questions
concerning the procedure and my particular project:

1. The tech note says that I first get an open slot in the unit table
(I figured out that part) and then do a DrvrInstall with the *pointer*
to the driver. The declaration for the routine in TN 108 says to pass
it the handle. Is the pointer just for the trap itself and the handle
is for the C or Pascal call?

2. The tech note also says that after I call DrvrInstall I should move
the handle to the driver, the DrvrFlags, DrvrDelay, etc, to the appro-
priate fields in DCE. Do I need to do this if I immediately call
OpenDriver or PBOpen?

3. Can I do this at other than INIT time?

4. If I want to close the driver and get rid of it, I assume I call
CloseDriver and then DrvrRemove. Is that right or do I only need to
call CloseDriver (or PBClose)? If I need to call DrvrRemove, TN 108
says that it calls ReleaseResource. If I have done a DetachResource,
that won't work very well. Can this be right?

5. DrvrInstall and DrvrRemove are not in MacTraps in THINK C as far
as I can tell. What do I do with the MPW glue to make this work?

Thanks for any assistance in advance,
pr
--
Pete Resnick             (...so what is a mojo, and why would one be rising?)
Graduate assistant - Philosophy Department, Gregory Hall, UIUC
System manager - Cognitive Science Group, Beckman Institute, UIUC
Internet/ARPAnet/EDUnet  : resnick@cogsci.uiuc.edu
BITNET (if no other way) : FREE0285@UIUCVMD

urlichs@smurf.sub.org (Matthias Urlichs) (11/13/90)

In comp.sys.mac.programmer, article <1990Nov12.062133.29315@ux1.cso.uiuc.edu>,
  resnick@cogsci.uiuc.edu (Pete Resnick) writes:
< I was reading a draft tech note written by Mark Bennett that talked
< about installing drivers at INIT time. I have a couple of questions
< concerning the procedure and my particular project:
< 
< 3. Can I do this at other than INIT time?
< 
No problem. Just make sure that your driver and your DCE end up in the heap
you want them to be in.

< 4. If I want to close the driver and get rid of it, I assume I call
< CloseDriver and then DrvrRemove. Is that right or do I only need to
< call CloseDriver (or PBClose)? If I need to call DrvrRemove, TN 108
< says that it calls ReleaseResource. If I have done a DetachResource,
< that won't work very well. Can this be right?
< 
Yes -- there are flags in the DCE which tell DrvrRemove what to do.
"IL DrvrRemove+0E" (A2 contains the unit table entry; hand-disassembled):
	MOVE.L	(A2),A1
	BTST #5,5(A1)
	BNE.S	Error
	BTST #6,5(A1)
	BEQ.S	noRes
	MOVE.L	(A1),-(A7)
	_ReleaseResource
noRes	MOVE.L	A2,A0
	_DisposHandle
	...
Error	MOVEQ	#$E7,D0
	BRA Out

-- 
Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de     /(o\
Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(0700-2330)   \o)/

merlyn@digibd.com (Brian Westley (Merlyn LeRoy)) (11/17/90)

resnick@cogsci.uiuc.edu (Pete Resnick) writes:
...
>5. DrvrInstall and DrvrRemove are not in MacTraps in THINK C as far
>as I can tell. What do I do with the MPW glue to make this work?

Here's what I use (Think C)


/* "trap" is used in assembly thus:  trap _DrvrInstall */
#define	trap		dc.w

#define _DrvrInstall	0xA03D
#define _DrvrRemove	0xA03E

/*
 * Apple routine glue for DrvrInstall
 */
OSErr
DrvrInstall(drvrHandle, refNum)
Handle drvrHandle;
int refNum;
{
	OSErr result;

	asm {
	move.w	refNum, d0		; driver reference number
	move.l	drvrHandle, a0		; handle to driver 
	move.l	(a0), a0		; pointer to driver
	trap	_DrvrInstall
	move.w	d0, result		; get error
	}
	return (result);
}


/*
 * Apple routine glue for DrvrRemove
 */
OSErr
DrvrRemove(refNum)
int refNum;
{
	OSErr result;

	asm {
	move.w	refNum, d0		; driver reference number
	trap	_DrvrRemove
	move.w	d0, result		; get error
	}
	return (result);
}


HTH (hope this helps)
---
Merlyn LeRoy