1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Gameboy emulator based on gnuboy
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "rockmacros.h"
35 #define optionname "options"
37 void die(char *message
, ...)
43 struct options options
;
45 void *audio_bufferbase
;
46 void *audio_bufferpointer
;
47 size_t audio_buffer_free
;
49 void *my_malloc(size_t size
)
53 if (size
+ 4 > audio_buffer_free
)
55 alloc
= audio_bufferpointer
;
56 audio_bufferpointer
+= size
+ 4;
57 audio_buffer_free
-= size
+ 4;
61 static void setoptions (void)
65 char optionsave
[sizeof(savedir
)+sizeof(optionname
)];
67 dir
=rb
->opendir(savedir
);
73 snprintf(optionsave
, sizeof(optionsave
), "%s/%s", savedir
, optionname
);
75 fd
= open(optionsave
, O_RDONLY
);
76 if(fd
< 0) /* no options to read, set defaults */
78 #ifdef HAVE_TOUCHSCREEN
79 options
.LEFT
=BUTTON_MIDLEFT
;
80 options
.RIGHT
=BUTTON_MIDRIGHT
;
82 options
.LEFT
=BUTTON_LEFT
;
83 options
.RIGHT
=BUTTON_RIGHT
;
86 #if CONFIG_KEYPAD == IRIVER_H100_PAD
88 options
.DOWN
=BUTTON_DOWN
;
92 options
.START
=BUTTON_REC
;
93 options
.SELECT
=BUTTON_SELECT
;
94 options
.MENU
=BUTTON_MODE
;
96 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
98 options
.DOWN
=BUTTON_DOWN
;
100 options
.A
=BUTTON_REC
;
101 options
.B
=BUTTON_MODE
;
102 options
.START
=BUTTON_ON
;
103 options
.SELECT
=BUTTON_SELECT
;
104 options
.MENU
=BUTTON_OFF
;
106 #elif CONFIG_KEYPAD == RECORDER_PAD
107 options
.UP
=BUTTON_UP
;
108 options
.DOWN
=BUTTON_DOWN
;
112 options
.START
=BUTTON_F3
;
113 options
.SELECT
=BUTTON_PLAY
;
114 options
.MENU
=BUTTON_OFF
;
116 #elif CONFIG_KEYPAD == IPOD_4G_PAD
117 options
.UP
=BUTTON_MENU
;
118 options
.DOWN
=BUTTON_PLAY
;
120 options
.A
=BUTTON_NONE
;
121 options
.B
=BUTTON_NONE
;
122 options
.START
=BUTTON_SELECT
;
123 options
.SELECT
=BUTTON_NONE
;
124 options
.MENU
=(BUTTON_SELECT
| BUTTON_REPEAT
);
126 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
127 options
.UP
=BUTTON_UP
;
128 options
.DOWN
=BUTTON_DOWN
;
130 options
.A
=BUTTON_PLAY
;
132 options
.START
=BUTTON_MODE
;
133 options
.SELECT
=(BUTTON_SELECT
| BUTTON_REL
);
134 options
.MENU
=(BUTTON_SELECT
| BUTTON_REPEAT
);
136 #elif CONFIG_KEYPAD == GIGABEAT_PAD
137 options
.UP
=BUTTON_UP
;
138 options
.DOWN
=BUTTON_DOWN
;
140 options
.A
=BUTTON_VOL_UP
;
141 options
.B
=BUTTON_VOL_DOWN
;
142 options
.START
=BUTTON_A
;
143 options
.SELECT
=BUTTON_SELECT
;
144 options
.MENU
=BUTTON_MENU
;
146 #elif CONFIG_KEYPAD == SANSA_E200_PAD
147 options
.UP
=BUTTON_UP
;
148 options
.DOWN
=BUTTON_DOWN
;
150 options
.A
=BUTTON_SELECT
;
151 options
.B
=BUTTON_REC
;
152 options
.START
=BUTTON_SCROLL_BACK
;
153 options
.SELECT
=BUTTON_SCROLL_FWD
;
154 options
.MENU
=BUTTON_POWER
;
156 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
157 options
.UP
=BUTTON_UP
;
158 options
.DOWN
=BUTTON_DOWN
;
160 options
.A
=BUTTON_SELECT
;
161 options
.B
=BUTTON_HOME
;
162 options
.START
=BUTTON_SCROLL_BACK
;
163 options
.SELECT
=BUTTON_SCROLL_FWD
;
164 options
.MENU
=BUTTON_POWER
;
166 #elif CONFIG_KEYPAD == SANSA_C200_PAD
167 options
.UP
=BUTTON_UP
;
168 options
.DOWN
=BUTTON_DOWN
;
170 options
.A
=BUTTON_SELECT
;
171 options
.B
=BUTTON_REC
;
172 options
.START
=BUTTON_VOL_DOWN
;
173 options
.SELECT
=BUTTON_VOL_UP
;
174 options
.MENU
=BUTTON_POWER
;
176 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
177 options
.UP
=BUTTON_UP
;
178 options
.DOWN
=BUTTON_DOWN
;
180 options
.A
=BUTTON_SELECT
;
181 options
.B
=BUTTON_HOME
;
182 options
.START
=BUTTON_VOL_DOWN
;
183 options
.SELECT
=BUTTON_VOL_UP
;
184 options
.MENU
=BUTTON_POWER
;
186 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
187 options
.UP
=BUTTON_UP
;
188 options
.DOWN
=BUTTON_DOWN
;
190 options
.A
=BUTTON_PLAY
;
191 options
.B
=BUTTON_REC
;
192 options
.START
=BUTTON_SELECT
;
193 options
.SELECT
=BUTTON_NONE
;
194 options
.MENU
=BUTTON_POWER
;
196 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
197 options
.UP
=BUTTON_SCROLL_UP
;
198 options
.DOWN
=BUTTON_SCROLL_DOWN
;
200 options
.A
=BUTTON_PLAY
;
202 options
.START
=BUTTON_REW
;
203 options
.SELECT
=BUTTON_NONE
;
204 options
.MENU
=BUTTON_POWER
;
206 #elif CONFIG_KEYPAD == MROBE500_PAD
207 options
.MENU
=BUTTON_POWER
;
209 #elif CONFIG_KEYPAD == COWON_D2_PAD
210 options
.A
=BUTTON_PLUS
;
211 options
.B
=BUTTON_MINUS
;
212 options
.MENU
=BUTTON_MENU
;
214 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
215 options
.UP
=BUTTON_UP
;
216 options
.DOWN
=BUTTON_DOWN
;
218 options
.A
=BUTTON_VOL_UP
;
219 options
.B
=BUTTON_VOL_DOWN
;
220 options
.START
=BUTTON_PLAY
;
221 options
.SELECT
=BUTTON_SELECT
;
222 options
.MENU
=BUTTON_MENU
;
223 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
224 options
.UP
=BUTTON_UP
;
225 options
.DOWN
=BUTTON_DOWN
;
227 options
.A
=BUTTON_CUSTOM
;
228 options
.B
=BUTTON_PLAY
;
229 options
.START
=BUTTON_BACK
;
230 options
.SELECT
=BUTTON_SELECT
;
231 options
.MENU
=BUTTON_MENU
;
233 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
234 options
.UP
=BUTTON_UP
;
235 options
.DOWN
=BUTTON_DOWN
;
237 options
.A
=BUTTON_VOL_UP
;
238 options
.B
=BUTTON_VOL_DOWN
;
239 options
.START
=BUTTON_VIEW
;
240 options
.SELECT
=BUTTON_SELECT
;
241 options
.MENU
=BUTTON_MENU
;
243 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
244 options
.UP
=BUTTON_UP
;
245 options
.DOWN
=BUTTON_DOWN
;
247 options
.A
=BUTTON_VOL_UP
;
248 options
.B
=BUTTON_VOL_DOWN
;
249 options
.START
=BUTTON_RIGHT
;
250 options
.SELECT
=BUTTON_LEFT
;
251 options
.MENU
=BUTTON_MENU
;
253 #elif CONFIG_KEYPAD == ONDAVX747_PAD
254 options
.A
=BUTTON_VOL_UP
;
255 options
.B
=BUTTON_VOL_DOWN
;
256 options
.MENU
=BUTTON_MENU
;
258 #elif CONFIG_KEYPAD == ONDAVX777_PAD
259 options
.MENU
=BUTTON_POWER
;
261 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
262 options
.UP
=BUTTON_UP
;
263 options
.DOWN
=BUTTON_DOWN
;
265 options
.A
=BUTTON_PLAY
;
266 options
.B
=BUTTON_FFWD
;
267 options
.START
=BUTTON_REW
;
268 options
.SELECT
=BUTTON_RIGHT
;
269 options
.MENU
=BUTTON_LEFT
;
271 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
272 options
.UP
=BUTTON_UP
;
273 options
.DOWN
=BUTTON_DOWN
;
275 options
.A
=BUTTON_PLAY
;
276 options
.B
=BUTTON_REW
;
277 options
.START
=BUTTON_REC
;
278 options
.SELECT
=BUTTON_FFWD
;
279 options
.MENU
=BUTTON_NONE
;
281 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
282 options
.UP
= BUTTON_OK
;
283 options
.DOWN
= BUTTON_CANCEL
;
284 options
.LEFT
= BUTTON_PREV
;
285 options
.RIGHT
= BUTTON_NEXT
;
287 options
.A
= BUTTON_POWER
;
288 options
.B
= BUTTON_REC
;
289 options
.START
= BUTTON_PLAY
;
290 options
.SELECT
= BUTTON_UP
;
291 options
.MENU
= BUTTON_MENU
;
294 #error No Keymap Defined!
297 #ifdef HAVE_TOUCHSCREEN
298 options
.UP
=BUTTON_TOPMIDDLE
;
299 options
.DOWN
=BUTTON_BOTTOMMIDDLE
;
300 options
.START
=BUTTON_TOPRIGHT
;
301 options
.SELECT
=BUTTON_CENTER
;
302 #if CONFIG_KEYPAD == MROBE500_PAD
303 options
.A
=BUTTON_BOTTOMLEFT
;
304 options
.B
=BUTTON_BOTTOMRIGHT
;
305 #elif CONFIG_KEYPAD != COWON_D2_PAD
306 options
.A
=BUTTON_BOTTOMLEFT
;
307 options
.B
=BUTTON_BOTTOMRIGHT
;
308 options
.MENU
=BUTTON_TOPLEFT
;
315 #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144)
324 read(fd
,&options
, sizeof(options
));
329 static void savesettings(void)
332 char optionsave
[sizeof(savedir
)+sizeof(optionname
)];
337 snprintf(optionsave
, sizeof(optionsave
), "%s/%s", savedir
, optionname
);
338 fd
= open(optionsave
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0666);
339 write(fd
,&options
, sizeof(options
));
350 while (ev_getevent(&ev
))
352 if (ev
.type
!= EV_PRESS
&& ev
.type
!= EV_RELEASE
)
354 st
= (ev
.type
!= EV_RELEASE
);
355 pad_set(ev
.code
, st
);
359 static int gnuboy_main(const char *rom
)
361 rb
->lcd_puts(0,0,"Init video");
363 rb
->lcd_puts(0,1,"Init sound");
365 rb
->lcd_puts(0,2,"Loading rom");
369 rb
->lcd_puts(0,3,"Emu reset");
371 rb
->lcd_puts(0,4,"Emu run");
372 rb
->lcd_clear_display();
380 /* this is the plugin entry point */
381 enum plugin_status
plugin_start(const void* parameter
)
387 rb
->lcd_clear_display();
391 rb
->splash(HZ
*3, "Play gameboy ROM file! (.gb/.gbc)");
394 if(rb
->audio_status())
396 audio_bufferbase
= audio_bufferpointer
397 = rb
->plugin_get_buffer(&audio_buffer_free
);
402 audio_bufferbase
= audio_bufferpointer
403 = rb
->plugin_get_audio_buffer(&audio_buffer_free
);
406 #if MEM <= 8 && !defined(SIMULATOR)
407 /* loaded as an overlay plugin, protect from overwriting ourselves */
408 if ((unsigned)(plugin_start_addr
- (unsigned char *)audio_bufferbase
)
410 audio_buffer_free
= plugin_start_addr
- (unsigned char *)audio_bufferbase
;
417 #ifdef HAVE_WHEEL_POSITION
418 rb
->wheel_send_events(false);
421 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
422 rb
->lcd_set_mode(LCD_MODE_PAL256
);
425 gnuboy_main(parameter
);
427 #ifdef HAVE_WHEEL_POSITION
428 rb
->wheel_send_events(true);
431 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
432 rb
->lcd_set_mode(LCD_MODE_RGB565
);
437 rb
->splash(HZ
/2, errormsg
);
440 if(!rb
->audio_status())
443 rb
->splash(HZ
/2, "Closing Rockboy");