2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 #include <aros/config.h>
9 #include <exec/execbase.h>
10 #include <exec/devices.h>
12 #include <exec/errors.h>
13 #include <aros/libcall.h>
14 #include <exec/libraries.h>
15 #include <proto/exec.h>
17 #ifndef DEBUG_SetFunction
18 # define DEBUG_SetFunction 0
24 #include <aros/debug.h>
27 char *const timername
= "timer.device";
28 char *const inputname
= "input.device";
30 /*****************************************************************************
34 AROS_LH4(BYTE
, OpenDevice
,
37 AROS_LHA(CONST_STRPTR
, devName
, A0
),
38 AROS_LHA(ULONG
, unitNumber
, D0
),
39 AROS_LHA(struct IORequest
*, iORequest
, A1
),
40 AROS_LHA(ULONG
, flags
, D1
),
43 struct ExecBase
*, SysBase
, 74, Exec
)
46 Tries to open a device and fill the iORequest structure. An error
47 is returned if this fails, 0 if all went well.
49 If the device doesn't exist in the current system device list, then
50 first the system ROMtag module list, then if the DOS is running,
51 then the DEVS: directory will be tried.
54 devName - Pointer to the devices's name.
55 unitNumber - The unit number. Most often 0.
56 iORequest - Pointer do device specific information.
57 Will be filled out by the device.
58 Must lie in public (or at least shared) memory.
59 flags - Some flags to give to the device.
62 Error code or 0 if all went well. The same value can be found
63 in the io_Error field.
76 *****************************************************************************/
80 AROS_LIBBASE_EXT_DECL(struct ExecBase
*,SysBase
)
81 struct Device
*device
;
82 BYTE ret
=IOERR_OPENFAIL
;
84 D(bug("OpenDevice $%lx $%lx $%lx %ld (\"%s\") by \"%s\"\n", devName
, unitNumber
, iORequest
,
85 flags
, (devName
> (STRPTR
)1) ? devName
: (UBYTE
*)"(null)", SysBase
->ThisTask
->tc_Node
.ln_Name
));
87 /* Arbitrate for the device list */
90 #if (AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
92 Kludge for compatibility with V40 kickstart. DO NOT depend on this!
93 See TaggedOpenLibrary() for more info.
95 if (devName
== (STRPTR
)0) devName
= timername
;
96 else if(devName
== (STRPTR
)1) devName
= inputname
;
99 /* Look for the device in our list */
100 device
=(struct Device
*)FindName(&SysBase
->DeviceList
,devName
);
102 /* Something found ? */
106 iORequest
->io_Error
=0;
107 iORequest
->io_Device
=device
;
108 iORequest
->io_Unit
= NULL
;
110 /* Call Open vector. */
112 AROS_LCA(struct IORequest
*,iORequest
,A1
),
113 AROS_LCA(ULONG
,unitNumber
,D0
),
114 AROS_LCA(ULONG
,flags
,D1
),
115 struct Device
*, device
, 1, dev
118 /* Check for error */
119 ret
=iORequest
->io_Error
;
121 /* Mark request as non-open */
122 iORequest
->io_Device
=NULL
;
126 * We cannot handle loading devices from disk. But thankfully this is
127 * taken care of by dos.library (well lddemon really). It replaces
128 * this function with one of its own via the SetFunction() call.