Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / rom / hidds / serialmouse / mouseclass.c
blobe8c8ac0413364a3a1b3d010d7877f40d43da2329
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: The main mouse class.
6 Lang: English.
7 */
9 /*
10 This is the universal serial mouse driver.
11 The code is very old, and is actually one big TODO. Here is a short list
12 of things to change:
13 1. Drop serial HIDDs and use device API instead. This will allow to do
14 interesting things, like handling serial mice on USB-Serial adapters.
15 Useful at least for testing.
16 2. Rewrite detection routine. Device detection should be done in startup.c,
17 and one instance should be created for every mouse detected. Yes, we can
18 handle several mice at once. Additionally it will provide correct
19 hardware name.
20 3. Replace busyloop PIT-based mouse_usleep() with timer.device-based delay.
21 Will make the driver working on any arch.
23 Please keep code clean from all .bss and .data sections. .rodata may exist
24 as it will be connected together with .text section during linking.
27 #include <proto/exec.h>
28 #include <proto/utility.h>
29 #include <proto/oop.h>
30 #include <oop/oop.h>
31 #include <exec/alerts.h>
32 #include <exec/memory.h>
33 #include <hidd/hidd.h>
34 #include <hidd/mouse.h>
35 #include <devices/inputevent.h>
36 #include <string.h>
37 #include <aros/symbolsets.h>
39 #include "mouse.h"
41 #define DEBUG 0
42 #include <aros/debug.h>
44 /* Prototypes */
46 int test_mouse_serial(OOP_Class *, OOP_Object *);
47 void dispose_mouse_serial(OOP_Class *, OOP_Object *);
49 /* defines for buttonstate */
51 #define LEFT_BUTTON 1
52 #define RIGHT_BUTTON 2
53 #define MIDDLE_BUTTON 4
55 /***** Mouse::New() ***************************************/
56 OOP_Object * PCMouse__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
58 EnterFunc(bug("_Mouse::New()\n"));
60 if (MSD(cl)->mousehidd) /* Cannot open twice */
61 ReturnPtr("_Mouse::New", OOP_Object *, NULL); /* Should have some error code here */
63 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
64 if (o)
66 struct mouse_data *data = OOP_INST_DATA(cl, o);
67 struct TagItem *tag, *tstate;
69 tstate = msg->attrList;
71 /* Search for all mouse attrs */
73 while ((tag = NextTagItem(&tstate)))
75 ULONG idx;
77 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
79 switch (idx)
81 case aoHidd_Mouse_IrqHandler:
82 data->mouse_callback = (APTR)tag->ti_Data;
83 break;
85 case aoHidd_Mouse_IrqHandlerData:
86 data->callbackdata = (APTR)tag->ti_Data;
87 break;
91 } /* while (tags to process) */
93 /* Search for mouse installed. Check every COM port in the system */
94 if (!test_mouse_serial(cl, o))
96 /* No mouse found. What we can do now is just Dispose() :( */
97 OOP_MethodID disp_mid = msg->mID - moRoot_New + moRoot_Dispose;
99 /* Do not call own Dispose */
100 OOP_DoSuperMethod(cl, o, &disp_mid);
101 o = NULL;
104 MSD(cl)->mousehidd = o;
107 return o;
110 VOID PCMouse__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
112 MSD(cl)->mousehidd = NULL;
114 dispose_mouse_serial(cl, o);
116 OOP_DoSuperMethod(cl, o, msg);
119 /***** Mouse::Get() ***************************************/
120 VOID PCMouse__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
122 struct mouse_data *data = OOP_INST_DATA(cl, o);
123 ULONG idx;
125 if (IS_HIDDMOUSE_ATTR(msg->attrID, idx))
127 switch (idx)
129 case aoHidd_Mouse_IrqHandler:
130 *msg->storage = (IPTR)data->mouse_callback;
131 return;
133 case aoHidd_Mouse_IrqHandlerData:
134 *msg->storage = (IPTR)data->callbackdata;
135 return;
137 case aoHidd_Mouse_State:
138 *msg->storage = 0; /* FIXME: Implement this */
139 return;
141 case aoHidd_Mouse_RelativeCoords:
142 *msg->storage = TRUE;
143 return;
148 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
151 /******************** init and expunge *********************************/
153 #undef OOPBase
154 #define OOPBase (LIBBASE->msd.oopBase)
156 static int PCMouse_InitAttrs(struct mousebase *LIBBASE)
158 struct OOP_ABDescr attrbases[] =
160 { IID_Hidd , &LIBBASE->msd.hiddAttrBase },
161 { IID_Hidd_Mouse, &LIBBASE->msd.hiddMouseAB },
162 { NULL , NULL }
165 EnterFunc(bug("PCMouse_InitAttrs\n"));
167 LIBBASE->msd.utilityBase = OpenLibrary("utility.library", 36);
168 if (!LIBBASE->msd.utilityBase)
169 return FALSE;
171 if (!OOP_ObtainAttrBases(attrbases))
172 return FALSE;
174 LIBBASE->msd.hwMethodBase = OOP_GetMethodID(IID_HW, 0);
175 return TRUE;
178 /*************** free_kbdclass() **********************************/
179 static int PCMouse_ExpungeAttrs(struct mousebase *LIBBASE)
181 struct OOP_ABDescr attrbases[] =
183 { IID_Hidd , &LIBBASE->msd.hiddAttrBase },
184 { IID_Hidd_Mouse, &LIBBASE->msd.hiddMouseAB },
185 { NULL , NULL }
188 EnterFunc(bug("PCMouse_InitClass\n"));
190 OOP_ReleaseAttrBases(attrbases);
192 if (LIBBASE->msd.utilityBase)
193 CloseLibrary(LIBBASE->msd.utilityBase);
195 return TRUE;
198 ADD2INITLIB(PCMouse_InitAttrs, 0)
199 ADD2EXPUNGELIB(PCMouse_ExpungeAttrs, 0)