summaryrefslogtreecommitdiff
path: root/apps/plugins/xrick/system/sysevt_rockbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/xrick/system/sysevt_rockbox.c')
-rw-r--r--apps/plugins/xrick/system/sysevt_rockbox.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/apps/plugins/xrick/system/sysevt_rockbox.c b/apps/plugins/xrick/system/sysevt_rockbox.c
new file mode 100644
index 0000000000..f5314712e8
--- /dev/null
+++ b/apps/plugins/xrick/system/sysevt_rockbox.c
@@ -0,0 +1,156 @@
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Port of xrick, a Rick Dangerous clone, to Rockbox.
11 * See http://www.bigorno.net/xrick/
12 *
13 * Copyright (C) 2008-2014 Pierluigi Vicinanza
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#include "xrick/system/system.h"
26
27#include "xrick/config.h"
28#include "xrick/control.h"
29#include "xrick/game.h"
30#include "xrick/system/sysmenu_rockbox.h"
31#include "xrick/system/rockboxcodes.h"
32
33/*
34 * Helper function to set/clear controls according to key press
35 */
36static inline void checkKey(int key, unsigned button, control_t control)
37{
38 if (key & button)
39 {
40 control_set(control);
41 }
42 else
43 {
44 control_clear(control);
45 }
46}
47
48/*
49 * Process events, if any, then return
50 */
51void sysevt_poll(void)
52{
53 static int previousKey, currentKey;
54
55 /* this is because "Restart Game" is handled via menu */
56 if (control_test(Control_END))
57 {
58 control_clear(Control_END);
59 }
60
61 for (;;)
62 {
63 /* check for USB connection */
64 if ((rb->default_event_handler(rb->button_get(false)) == SYS_USB_CONNECTED)
65#if defined(HAS_BUTTON_HOLD)
66 || rb->button_hold()
67#endif
68 )
69 {
70 sysmenu_exec();
71 }
72
73 currentKey = rb->button_status();
74 if (currentKey != previousKey)
75 {
76 break;
77 }
78 else if (game_waitevt)
79 {
80 rb->yield();
81 }
82 else /* (currentKey == previousKey) && !game_waitevt */
83 {
84 return;
85 }
86 }
87
88#ifdef XRICK_BTN_MENU
89 if (currentKey & XRICK_BTN_MENU)
90 {
91 sysmenu_exec();
92 }
93#endif
94
95#ifdef XRICK_BTN_PAUSE
96 checkKey(currentKey, XRICK_BTN_PAUSE, Control_PAUSE);
97#endif
98
99 checkKey(currentKey, XRICK_BTN_UP, Control_UP);
100
101 checkKey(currentKey, XRICK_BTN_DOWN, Control_DOWN);
102
103 checkKey(currentKey, XRICK_BTN_LEFT, Control_LEFT);
104
105 checkKey(currentKey, XRICK_BTN_RIGHT, Control_RIGHT);
106
107 checkKey(currentKey, XRICK_BTN_FIRE, Control_FIRE);
108
109#ifdef XRICK_BTN_UPLEFT
110 if (!control_test(Control_UP | Control_LEFT))
111 {
112 checkKey(currentKey, XRICK_BTN_UPLEFT, Control_UP | Control_LEFT);
113 }
114#endif /* XRICK_BTN_UPLEFT */
115
116#ifdef XRICK_BTN_UPRIGHT
117 if (!control_test(Control_UP | Control_RIGHT))
118 {
119 checkKey(currentKey, XRICK_BTN_UPRIGHT, Control_UP | Control_RIGHT);
120 }
121#endif /* XRICK_BTN_UPRIGHT */
122
123#ifdef XRICK_BTN_DOWNLEFT
124 if (!control_test(Control_DOWN | Control_LEFT))
125 {
126 checkKey(currentKey, XRICK_BTN_DOWNLEFT, Control_DOWN | Control_LEFT);
127 }
128#endif /* XRICK_BTN_DOWNLEFT */
129
130#ifdef XRICK_BTN_DOWNRIGHT
131 if (!control_test(Control_DOWN | Control_RIGHT))
132 {
133 checkKey(currentKey, XRICK_BTN_DOWNRIGHT, Control_DOWN | Control_RIGHT);
134 }
135#endif /* XRICK_BTN_DOWNRIGHT */
136
137 previousKey = currentKey;
138}
139
140/*
141 * Wait for an event, then process it and return
142 */
143void sysevt_wait(void)
144{
145#ifdef HAVE_ADJUSTABLE_CPU_FREQ
146 rb->cpu_boost(false);
147#endif
148
149 sysevt_poll(); /* sysevt_poll deals with blocking case as well */
150
151#ifdef HAVE_ADJUSTABLE_CPU_FREQ
152 rb->cpu_boost(true);
153#endif
154}
155
156/* eof */