Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / exec / opendevice.c
blob7bc399b9e99f9b3550d9da5484fa49583c77f5ca
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Open a device.
6 Lang: english
7 */
8 #include <aros/config.h>
9 #include <exec/execbase.h>
10 #include <exec/devices.h>
11 #include <exec/io.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
19 #endif
20 #undef DEBUG
21 #if DEBUG_SetFunction
22 # define DEBUG 1
23 #endif
24 #include <aros/debug.h>
25 #undef kprintf
27 char *const timername = "timer.device";
28 char *const inputname = "input.device";
30 /*****************************************************************************
32 NAME */
34 AROS_LH4(BYTE, OpenDevice,
36 /* SYNOPSIS */
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),
42 /* LOCATION */
43 struct ExecBase *, SysBase, 74, Exec)
45 /* FUNCTION
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.
53 INPUTS
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.
61 RESULT
62 Error code or 0 if all went well. The same value can be found
63 in the io_Error field.
65 NOTES
67 EXAMPLE
69 BUGS
71 SEE ALSO
72 OpenDevice()
74 INTERNALS
76 *****************************************************************************/
78 AROS_LIBFUNC_INIT
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 */
88 Forbid();
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;
97 #endif
99 /* Look for the device in our list */
100 device=(struct Device *)FindName(&SysBase->DeviceList,devName);
102 /* Something found ? */
103 if(device!=NULL)
105 /* Init iorequest */
106 iORequest->io_Error=0;
107 iORequest->io_Device=device;
108 iORequest->io_Unit = NULL;
110 /* Call Open vector. */
111 AROS_LVO_CALL3NR(
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;
120 if(ret)
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.
131 /* All done. */
132 Permit();
133 return ret;
134 AROS_LIBFUNC_EXIT
135 } /* OpenDevice */