3 // ©1996-2002 Henrik Isaksson
19 M68KFUNC_P2(struct InputEvent
*, myhandler
,
20 A0
, struct InputEvent
*, ev
,
21 A1
, struct MsgPort
*, port
)
23 struct InputEvent
*evnt
= ev
;
26 if (evnt
->ie_Class
== IECLASS_RAWKEY
) {
29 m
= PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
31 m
->msg
.mn_Length
= sizeof(struct PM_InpMsg
);
32 m
->msg
.mn_ReplyPort
= NULL
;
34 switch(evnt
->ie_Code
) {
37 m
->Kind
= PM_MSG_TERMINATE
;
43 m
->Kind
= PM_MSG_DOWN
;
46 m
->Kind
= PM_MSG_OPENSUB
;
49 m
->Kind
= PM_MSG_CLOSESUB
;
53 m
->Kind
= PM_MSG_SELECT
;
56 m
->Kind
= PM_MSG_MULTISELECT
;
59 m
->Kind
= PM_MSG_DEBUGINFO
;
62 if (m
->Kind
) PutMsg(port
, (struct Message
*)m
);
67 if (evnt
->ie_Class
== IECLASS_TIMER
) {
70 m
= PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
72 m
->msg
.mn_Length
= sizeof(struct PM_InpMsg
);
73 m
->msg
.mn_ReplyPort
= NULL
;
74 m
->Kind
= PM_MSG_TIMER
;
75 PutMsg(port
, (struct Message
*)m
);
78 if (evnt
->ie_Class
== IECLASS_RAWMOUSE
) {
81 m
= PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
83 m
->msg
.mn_Length
= sizeof(struct PM_InpMsg
);
84 m
->msg
.mn_ReplyPort
= NULL
;
85 m
->Kind
= PM_MSG_RAWMOUSE
;
86 m
->Code
= evnt
->ie_Code
;
87 m
->Qual
= evnt
->ie_Qualifier
;
88 PutMsg(port
, (struct Message
*)m
);
91 evnt
->ie_Code
= IECODE_NOBUTTON
;
93 evnt
= evnt
->ie_NextEvent
;
102 static char handlername
[] = "PM Input Handler";
106 AROS_UFH2(struct InputEvent
*, myhandler_aros
,
107 AROS_UFHA(struct InputEvent
*, ev
, A0
),
108 AROS_UFHA(struct MsgPort
*, port
, A1
))
112 return myhandler(ev
, port
);
116 #define HANDLER_CODE (APTR)AROS_ASMSYMNAME(myhandler_aros)
118 #define HANDLER_CODE (void *)myhandler
123 struct PM_InputHandler
*PM_InstallHandler(int pri
)
125 struct PM_InputHandler
*pmh
;
126 STATIC_PATCHFUNC(myhandler
)
128 pmh
= PM_Mem_Alloc(sizeof(struct PM_InputHandler
));
130 pmh
->mp
= CreatePort(0,0);
132 pmh
->port
= CreatePort(0,0);
134 pmh
->ior
= CreateStdIO(pmh
->mp
);
136 pmh
->error
= OpenDevice("input.device",0,(struct IORequest
*)pmh
->ior
,0);
138 pmh
->intr
.is_Data
= (APTR
)pmh
->port
;
139 pmh
->intr
.is_Code
= (VOID (*)()) PATCH_NEWFUNC(myhandler
);
140 pmh
->intr
.is_Node
.ln_Pri
= pri
;
141 pmh
->intr
.is_Node
.ln_Name
= handlername
;
143 pmh
->ior
->io_Command
= IND_ADDHANDLER
;
144 pmh
->ior
->io_Data
= (APTR
)&pmh
->intr
;
145 pmh
->ior
->io_Message
.mn_ReplyPort
= pmh
->mp
;
147 DoIO((struct IORequest
*)pmh
->ior
);
161 void PM_RemoveHandler(struct PM_InputHandler
*pmh
)
163 struct PM_InpMsg
*msg
;
169 pmh
->ior
->io_Command
= IND_REMHANDLER
;
170 pmh
->ior
->io_Data
= (APTR
)&pmh
->intr
;
171 DoIO((struct IORequest
*)pmh
->ior
);
173 CloseDevice((struct IORequest
*)pmh
->ior
);
175 DeleteStdIO(pmh
->ior
);
177 while ((msg
= (struct PM_InpMsg
*)GetMsg(pmh
->port
))) {
180 DeletePort(pmh
->port
);
197 void EZDeleteTimer(T_TIMEREQUEST
*TimeRequest
)
199 struct MsgPort
*TimePort
;
203 if (TimeRequest
->tr_node
.io_Device
)
204 CloseDevice((struct IORequest
*)TimeRequest
);
206 if ((TimePort
= TimeRequest
->tr_node
.io_Message
.mn_ReplyPort
))
207 DeletePort(TimePort
);
209 DeleteExtIO((struct IORequest
*)TimeRequest
);
213 T_TIMEREQUEST
*EZCreateTimer(LONG Unit
)
215 struct MsgPort
*TimePort
;
216 T_TIMEREQUEST
*TimeRequest
;
218 if (!(TimePort
= (struct MsgPort
*)CreatePort(NULL
,0)))
221 if (!(TimeRequest
= (T_TIMEREQUEST
*)CreateExtIO(TimePort
,sizeof(T_TIMEREQUEST
))))
223 DeletePort(TimePort
);
228 if (OpenDevice(TIMERNAME
, Unit
, (struct IORequest
*)TimeRequest
, 0))
230 DeleteExtIO((struct IORequest
*)TimeRequest
);
231 DeletePort(TimePort
);