3 // ©1996-2002 Henrik Isaksson
16 struct InputEvent
* __saveds ASM
myhandler(register __a0
struct InputEvent
*ev
GNUCREG(a0
),
17 register __a1
struct MsgPort
*port
GNUCREG(a1
))
19 struct InputEvent
*evnt
=ev
;
22 if(evnt
->ie_Class
== IECLASS_RAWKEY
) {
25 m
=PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
27 m
->msg
.mn_Length
=sizeof(struct PM_InpMsg
);
28 m
->msg
.mn_ReplyPort
=NULL
;
30 switch(evnt
->ie_Code
) {
33 m
->Kind
=PM_MSG_TERMINATE
;
42 m
->Kind
=PM_MSG_OPENSUB
;
45 m
->Kind
=PM_MSG_CLOSESUB
;
49 m
->Kind
=PM_MSG_SELECT
;
52 m
->Kind
=PM_MSG_MULTISELECT
;
55 m
->Kind
=PM_MSG_DEBUGINFO
;
58 if(m
->Kind
) PutMsg(port
, (struct Message
*)m
);
63 if(evnt
->ie_Class
== IECLASS_TIMER
) {
66 m
=PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
68 m
->msg
.mn_Length
=sizeof(struct PM_InpMsg
);
69 m
->msg
.mn_ReplyPort
=NULL
;
71 PutMsg(port
, (struct Message
*)m
);
74 if(evnt
->ie_Class
== IECLASS_RAWMOUSE
) {
77 m
=PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
79 m
->msg
.mn_Length
=sizeof(struct PM_InpMsg
);
80 m
->msg
.mn_ReplyPort
=NULL
;
81 m
->Kind
=PM_MSG_RAWMOUSE
;
82 m
->Code
=evnt
->ie_Code
;
83 m
->Qual
=evnt
->ie_Qualifier
;
84 PutMsg(port
, (struct Message
*)m
);
87 evnt
->ie_Code
=IECODE_NOBUTTON
;
89 evnt
=evnt
->ie_NextEvent
;
97 static char handlername
[] = "PM Input Handler";
101 AROS_UFH2(struct InputEvent
*, myhandler_aros
,
102 AROS_UFHA(struct InputEvent
*, ev
, A0
),
103 AROS_UFHA(struct MsgPort
*, port
, A1
))
107 return myhandler(ev
, port
);
111 #define HANDLER_CODE (APTR)AROS_ASMSYMNAME(myhandler_aros)
113 #define HANDLER_CODE (void *)myhandler
118 struct PM_InputHandler
*PM_InstallHandler(int pri
)
120 struct PM_InputHandler
*pmh
;
122 pmh
=PM_Mem_Alloc(sizeof(struct PM_InputHandler
));
124 pmh
->mp
=CreatePort(0,0);
126 pmh
->port
=CreatePort(0,0);
128 pmh
->ior
=CreateStdIO(pmh
->mp
);
130 pmh
->error
=OpenDevice("input.device",0,(struct IORequest
*)pmh
->ior
,0);
132 pmh
->intr
.is_Data
=(APTR
)pmh
->port
;
133 pmh
->intr
.is_Code
=HANDLER_CODE
;
134 pmh
->intr
.is_Node
.ln_Pri
=pri
;
135 pmh
->intr
.is_Node
.ln_Name
=handlername
;
136 pmh
->ior
->io_Command
=IND_ADDHANDLER
;
137 pmh
->ior
->io_Data
=(APTR
)&pmh
->intr
;
138 pmh
->ior
->io_Message
.mn_ReplyPort
=pmh
->mp
;
140 DoIO((struct IORequest
*)pmh
->ior
);
154 void PM_RemoveHandler(struct PM_InputHandler
*pmh
)
156 struct PM_InpMsg
*msg
;
162 pmh
->ior
->io_Command
=IND_REMHANDLER
;
163 pmh
->ior
->io_Data
=(APTR
)&pmh
->intr
;
164 DoIO((struct IORequest
*)pmh
->ior
);
166 CloseDevice((struct IORequest
*)pmh
->ior
);
168 DeleteStdIO(pmh
->ior
);
170 while((msg
=(struct PM_InpMsg
*)GetMsg(pmh
->port
))) {
173 DeletePort(pmh
->port
);
190 void EZDeleteTimer(struct timerequest
*TimeRequest
)
192 struct MsgPort
*TimePort
;
196 if(TimeRequest
->tr_node
.io_Device
)
197 CloseDevice((struct IORequest
*)TimeRequest
);
199 if((TimePort
=TimeRequest
->tr_node
.io_Message
.mn_ReplyPort
))
200 DeletePort(TimePort
);
202 DeleteExtIO((struct IORequest
*)TimeRequest
);
206 struct timerequest
*EZCreateTimer(LONG Unit
)
208 struct MsgPort
*TimePort
;
209 struct timerequest
*TimeRequest
;
211 if(!(TimePort
= (struct MsgPort
*)CreatePort(NULL
,0)))
214 if(!(TimeRequest
= (struct timerequest
*)CreateExtIO(TimePort
,sizeof(struct timerequest
))))
216 DeletePort(TimePort
);
221 if(OpenDevice(TIMERNAME
, Unit
, (struct IORequest
*)TimeRequest
, 0))
223 DeleteExtIO((struct IORequest
*)TimeRequest
);
224 DeletePort(TimePort
);