diff options
Diffstat (limited to 'apps/plugins/xrick/system/system_rockbox.c')
-rw-r--r-- | apps/plugins/xrick/system/system_rockbox.c | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/apps/plugins/xrick/system/system_rockbox.c b/apps/plugins/xrick/system/system_rockbox.c new file mode 100644 index 0000000000..3b5f96a4ed --- /dev/null +++ b/apps/plugins/xrick/system/system_rockbox.c | |||
@@ -0,0 +1,262 @@ | |||
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 | #ifdef ENABLE_SOUND | ||
29 | #include "xrick/system/syssnd_rockbox.h" | ||
30 | #endif | ||
31 | |||
32 | #include "plugin.h" | ||
33 | |||
34 | enum { LINE_LENGTH = 80 }; | ||
35 | |||
36 | /* | ||
37 | * Error | ||
38 | */ | ||
39 | void sys_error(const char *err, ...) | ||
40 | { | ||
41 | va_list argptr; | ||
42 | char s[LINE_LENGTH]; | ||
43 | |||
44 | /* prepare message */ | ||
45 | va_start(argptr, err); | ||
46 | rb->vsnprintf(s, sizeof(s), err, argptr); | ||
47 | va_end(argptr); | ||
48 | |||
49 | /* print error message */ | ||
50 | rb->splashf(HZ*3, ID2P(LANG_ERROR_FORMATSTR), s); | ||
51 | DEBUGF("Error: %s\n", s); | ||
52 | } | ||
53 | |||
54 | /* | ||
55 | * Print a message to standard output | ||
56 | */ | ||
57 | void sys_printf(const char *msg, ...) | ||
58 | { | ||
59 | va_list argptr; | ||
60 | char s[LINE_LENGTH]; | ||
61 | |||
62 | /* prepare message */ | ||
63 | va_start(argptr, msg); | ||
64 | rb->vsnprintf(s, sizeof(s), msg, argptr); | ||
65 | va_end(argptr); | ||
66 | |||
67 | /* print message */ | ||
68 | DEBUGF("%s",s); | ||
69 | |||
70 | #ifdef ENABLE_SYSPRINTF_TO_SCREEN | ||
71 | { | ||
72 | static int currentYPos = 0; | ||
73 | size_t i; | ||
74 | |||
75 | /* Device LCDs display newlines funny. */ | ||
76 | for(i = 0; s[i] != '\0'; ++i) | ||
77 | { | ||
78 | if(s[i] == '\n') | ||
79 | { | ||
80 | s[i] = ' '; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | rb->lcd_putsxy(1, currentYPos, (unsigned char *)s); | ||
85 | rb->lcd_update(); | ||
86 | |||
87 | currentYPos += 12; | ||
88 | if(currentYPos > LCD_HEIGHT-12) | ||
89 | { | ||
90 | currentYPos = 0; | ||
91 | rb->lcd_clear_display(); | ||
92 | } | ||
93 | } | ||
94 | #endif /* ENABLE_SYSPRINTF_TO_SCREEN */ | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * Print a message to string buffer | ||
99 | */ | ||
100 | void sys_snprintf(char *buf, size_t size, const char *msg, ...) | ||
101 | { | ||
102 | va_list argptr; | ||
103 | |||
104 | va_start(argptr, msg); | ||
105 | rb->vsnprintf(buf, size, msg, argptr); | ||
106 | va_end(argptr); | ||
107 | } | ||
108 | |||
109 | /* | ||
110 | * Returns string length | ||
111 | */ | ||
112 | size_t sys_strlen(const char * str) | ||
113 | { | ||
114 | return rb->strlen(str); | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | * Return number of milliseconds elapsed since first call | ||
119 | */ | ||
120 | U32 sys_gettime(void) | ||
121 | { | ||
122 | long ticks = *(rb->current_tick); | ||
123 | return (U32)((ticks * 1000) / HZ); | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * Yield execution to another thread | ||
128 | */ | ||
129 | void sys_yield(void) | ||
130 | { | ||
131 | rb->yield(); | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * Initialize system | ||
136 | */ | ||
137 | bool sys_init(int argc, char **argv) | ||
138 | { | ||
139 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
140 | rb->cpu_boost(true); | ||
141 | #endif | ||
142 | |||
143 | if (!sysarg_init(argc, argv)) | ||
144 | { | ||
145 | return false; | ||
146 | } | ||
147 | if (!sysmem_init()) | ||
148 | { | ||
149 | return false; | ||
150 | } | ||
151 | if (!sysvid_init()) | ||
152 | { | ||
153 | return false; | ||
154 | } | ||
155 | #ifdef ENABLE_SOUND | ||
156 | if (!sysarg_args_nosound && !syssnd_init()) | ||
157 | { | ||
158 | return false; | ||
159 | } | ||
160 | #endif | ||
161 | if (!sysfile_setRootPath(sysarg_args_data? sysarg_args_data : sysfile_defaultPath)) | ||
162 | { | ||
163 | return false; | ||
164 | } | ||
165 | return true; | ||
166 | } | ||
167 | |||
168 | /* | ||
169 | * Shutdown system | ||
170 | */ | ||
171 | void sys_shutdown(void) | ||
172 | { | ||
173 | sysfile_clearRootPath(); | ||
174 | #ifdef ENABLE_SOUND | ||
175 | syssnd_shutdown(); | ||
176 | #endif | ||
177 | sysvid_shutdown(); | ||
178 | sysmem_shutdown(); | ||
179 | |||
180 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
181 | rb->cpu_boost(false); | ||
182 | #endif | ||
183 | } | ||
184 | |||
185 | /* | ||
186 | * Preload data before entering main loop | ||
187 | */ | ||
188 | bool sys_cacheData(void) | ||
189 | { | ||
190 | #ifdef ENABLE_SOUND | ||
191 | syssnd_load(soundGameover); | ||
192 | syssnd_load(soundSbonus2); | ||
193 | syssnd_load(soundBullet); | ||
194 | syssnd_load(soundBombshht); | ||
195 | syssnd_load(soundExplode); | ||
196 | syssnd_load(soundStick); | ||
197 | syssnd_load(soundWalk); | ||
198 | syssnd_load(soundCrawl); | ||
199 | syssnd_load(soundJump); | ||
200 | syssnd_load(soundPad); | ||
201 | syssnd_load(soundBox); | ||
202 | syssnd_load(soundBonus); | ||
203 | syssnd_load(soundSbonus1); | ||
204 | syssnd_load(soundDie); | ||
205 | syssnd_load(soundEntity[0]); | ||
206 | syssnd_load(soundEntity[1]); | ||
207 | syssnd_load(soundEntity[2]); | ||
208 | syssnd_load(soundEntity[3]); | ||
209 | syssnd_load(soundEntity[4]); | ||
210 | syssnd_load(soundEntity[5]); | ||
211 | syssnd_load(soundEntity[6]); | ||
212 | syssnd_load(soundEntity[7]); | ||
213 | syssnd_load(soundEntity[8]); | ||
214 | syssnd_load(soundTune0); | ||
215 | syssnd_load(soundTune1); | ||
216 | syssnd_load(soundTune2); | ||
217 | syssnd_load(soundTune3); | ||
218 | syssnd_load(soundTune4); | ||
219 | syssnd_load(soundTune5); | ||
220 | #endif /* ENABLE_SOUND */ | ||
221 | return true; | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * Clear preloaded data before shutdown | ||
226 | */ | ||
227 | void sys_uncacheData(void) | ||
228 | { | ||
229 | #ifdef ENABLE_SOUND | ||
230 | syssnd_unload(soundTune5); | ||
231 | syssnd_unload(soundTune4); | ||
232 | syssnd_unload(soundTune3); | ||
233 | syssnd_unload(soundTune2); | ||
234 | syssnd_unload(soundTune1); | ||
235 | syssnd_unload(soundTune0); | ||
236 | syssnd_unload(soundEntity[8]); | ||
237 | syssnd_unload(soundEntity[7]); | ||
238 | syssnd_unload(soundEntity[6]); | ||
239 | syssnd_unload(soundEntity[5]); | ||
240 | syssnd_unload(soundEntity[4]); | ||
241 | syssnd_unload(soundEntity[3]); | ||
242 | syssnd_unload(soundEntity[2]); | ||
243 | syssnd_unload(soundEntity[1]); | ||
244 | syssnd_unload(soundEntity[0]); | ||
245 | syssnd_unload(soundDie); | ||
246 | syssnd_unload(soundSbonus1); | ||
247 | syssnd_unload(soundBonus); | ||
248 | syssnd_unload(soundBox); | ||
249 | syssnd_unload(soundPad); | ||
250 | syssnd_unload(soundJump); | ||
251 | syssnd_unload(soundCrawl); | ||
252 | syssnd_unload(soundWalk); | ||
253 | syssnd_unload(soundStick); | ||
254 | syssnd_unload(soundExplode); | ||
255 | syssnd_unload(soundBombshht); | ||
256 | syssnd_unload(soundBullet); | ||
257 | syssnd_unload(soundSbonus2); | ||
258 | syssnd_unload(soundGameover); | ||
259 | #endif /* ENABLE_SOUND */ | ||
260 | } | ||
261 | |||
262 | /* eof */ | ||