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_LEFT
;
162 options
.START
=BUTTON_SCROLL_BACK
;
163 options
.SELECT
=BUTTON_SCROLL_FWD
;
164 options
.MENU
=BUTTON_HOME
;
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 == IAUDIO_X5M5_PAD
177 options
.UP
=BUTTON_UP
;
178 options
.DOWN
=BUTTON_DOWN
;
180 options
.A
=BUTTON_PLAY
;
181 options
.B
=BUTTON_REC
;
182 options
.START
=BUTTON_SELECT
;
183 options
.SELECT
=BUTTON_NONE
;
184 options
.MENU
=BUTTON_POWER
;
186 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
187 options
.UP
=BUTTON_SCROLL_UP
;
188 options
.DOWN
=BUTTON_SCROLL_DOWN
;
190 options
.A
=BUTTON_PLAY
;
192 options
.START
=BUTTON_REW
;
193 options
.SELECT
=BUTTON_NONE
;
194 options
.MENU
=BUTTON_POWER
;
196 #elif CONFIG_KEYPAD == MROBE500_PAD
197 options
.UP
=BUTTON_RC_PLAY
;
198 options
.DOWN
=BUTTON_RC_DOWN
;
199 options
.LEFT
=BUTTON_RC_REW
;
200 options
.RIGHT
=BUTTON_RC_FF
;
202 options
.A
=BUTTON_RC_VOL_DOWN
;
203 options
.B
=BUTTON_RC_VOL_UP
;
204 options
.START
=BUTTON_RC_HEART
;
205 options
.SELECT
=BUTTON_RC_MODE
;
206 options
.MENU
=BUTTON_POWER
;
208 #elif CONFIG_KEYPAD == COWOND2_PAD
209 options
.A
=BUTTON_PLUS
;
210 options
.B
=BUTTON_MINUS
;
211 options
.MENU
=BUTTON_MENU
;
213 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
214 options
.UP
=BUTTON_UP
;
215 options
.DOWN
=BUTTON_DOWN
;
217 options
.A
=BUTTON_VOL_UP
;
218 options
.B
=BUTTON_VOL_DOWN
;
219 options
.START
=BUTTON_PLAY
;
220 options
.SELECT
=BUTTON_SELECT
;
221 options
.MENU
=BUTTON_MENU
;
222 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
223 options
.UP
=BUTTON_UP
;
224 options
.DOWN
=BUTTON_DOWN
;
226 options
.A
=BUTTON_CUSTOM
;
227 options
.B
=BUTTON_PLAY
;
228 options
.START
=BUTTON_BACK
;
229 options
.SELECT
=BUTTON_SELECT
;
230 options
.MENU
=BUTTON_MENU
;
232 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
233 options
.UP
=BUTTON_UP
;
234 options
.DOWN
=BUTTON_DOWN
;
236 options
.A
=BUTTON_VOL_UP
;
237 options
.B
=BUTTON_VOL_DOWN
;
238 options
.START
=BUTTON_VIEW
;
239 options
.SELECT
=BUTTON_SELECT
;
240 options
.MENU
=BUTTON_MENU
;
242 #elif CONFIG_KEYPAD == ONDAVX747_PAD
243 options
.A
=BUTTON_VOL_UP
;
244 options
.B
=BUTTON_VOL_DOWN
;
245 options
.MENU
=BUTTON_MENU
;
247 #error No Keymap Defined!
250 #ifdef HAVE_TOUCHSCREEN
251 options
.UP
=BUTTON_TOPMIDDLE
;
252 options
.DOWN
=BUTTON_BOTTOMMIDDLE
;
253 options
.START
=BUTTON_TOPRIGHT
;
254 options
.SELECT
=BUTTON_CENTER
;
255 #if CONFIG_KEYPAD != COWOND2_PAD
256 options
.A
=BUTTON_BOTTOMLEFT
;
257 options
.B
=BUTTON_BOTTOMRIGHT
;
258 options
.MENU
=BUTTON_TOPLEFT
;
265 #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144)
274 read(fd
,&options
, sizeof(options
));
279 static void savesettings(void)
282 char optionsave
[sizeof(savedir
)+sizeof(optionname
)];
287 snprintf(optionsave
, sizeof(optionsave
), "%s/%s", savedir
, optionname
);
288 fd
= open(optionsave
, O_WRONLY
|O_CREAT
|O_TRUNC
);
289 write(fd
,&options
, sizeof(options
));
300 while (ev_getevent(&ev
))
302 if (ev
.type
!= EV_PRESS
&& ev
.type
!= EV_RELEASE
)
304 st
= (ev
.type
!= EV_RELEASE
);
305 pad_set(ev
.code
, st
);
309 static int gnuboy_main(const char *rom
)
311 rb
->lcd_puts(0,0,"Init video");
313 rb
->lcd_puts(0,1,"Init sound");
315 rb
->lcd_puts(0,2,"Loading rom");
319 rb
->lcd_puts(0,3,"Emu reset");
321 rb
->lcd_puts(0,4,"Emu run");
322 rb
->lcd_clear_display();
330 /* this is the plugin entry point */
331 enum plugin_status
plugin_start(const void* parameter
)
337 rb
->lcd_clear_display();
341 rb
->splash(HZ
*3, "Play gameboy ROM file! (.gb/.gbc)");
344 if(rb
->audio_status())
346 audio_bufferbase
= audio_bufferpointer
347 = rb
->plugin_get_buffer(&audio_buffer_free
);
352 audio_bufferbase
= audio_bufferpointer
353 = rb
->plugin_get_audio_buffer(&audio_buffer_free
);
356 #if MEM <= 8 && !defined(SIMULATOR)
357 /* loaded as an overlay plugin, protect from overwriting ourselves */
358 if ((unsigned)(plugin_start_addr
- (unsigned char *)audio_bufferbase
)
360 audio_buffer_free
= plugin_start_addr
- (unsigned char *)audio_bufferbase
;
367 #ifdef HAVE_WHEEL_POSITION
368 rb
->wheel_send_events(false);
371 gnuboy_main(parameter
);
373 #ifdef HAVE_WHEEL_POSITION
374 rb
->wheel_send_events(true);
379 rb
->splash(HZ
/2, errormsg
);
382 if(!rb
->audio_status())
384 rb
->splash(HZ
/2, "Closing Rockboy");