summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/rockboy/menu.c57
1 files changed, 31 insertions, 26 deletions
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c
index 242518c01e..64d469f86d 100644
--- a/apps/plugins/rockboy/menu.c
+++ b/apps/plugins/rockboy/menu.c
@@ -11,6 +11,9 @@
11#include "rtc-gb.h" 11#include "rtc-gb.h"
12#include "pcm.h" 12#include "pcm.h"
13 13
14#define MAX_SLOTS 5
15#define DESC_SIZE 20
16
14/* load/save state function declarations */ 17/* load/save state function declarations */
15static void do_opt_menu(void); 18static void do_opt_menu(void);
16static void do_slot_menu(bool is_load); 19static void do_slot_menu(bool is_load);
@@ -22,6 +25,7 @@ static void munge_name(char *buf, size_t bufsiz);
22static int getbutton(char *text) 25static int getbutton(char *text)
23{ 26{
24 int fw, fh; 27 int fw, fh;
28 int button;
25 rb->lcd_clear_display(); 29 rb->lcd_clear_display();
26 rb->font_getstringsize(text, &fw, &fh,0); 30 rb->font_getstringsize(text, &fw, &fh,0);
27 rb->lcd_putsxy(LCD_WIDTH/2-fw/2, LCD_HEIGHT/2-fh/2, text); 31 rb->lcd_putsxy(LCD_WIDTH/2-fw/2, LCD_HEIGHT/2-fh/2, text);
@@ -31,11 +35,10 @@ static int getbutton(char *text)
31 while (rb->button_get(false) != BUTTON_NONE) 35 while (rb->button_get(false) != BUTTON_NONE)
32 rb->yield(); 36 rb->yield();
33 37
34 int button;
35 while(true) 38 while(true)
36 { 39 {
37 button = rb->button_get(true); 40 button = rb->button_get(true);
38 button=button&0x00000FFF; 41 button = button&(BUTTON_MAIN|BUTTON_REMOTE);
39 42
40 return button; 43 return button;
41 } 44 }
@@ -171,7 +174,7 @@ static void build_slot_path(char *buf, size_t bufsiz, int slot_id) {
171 * 174 *
172 */ 175 */
173static bool do_file(char *path, char *desc, bool is_load) { 176static bool do_file(char *path, char *desc, bool is_load) {
174 char desc_buf[20]; 177 char desc_buf[DESC_SIZE];
175 int fd, file_mode; 178 int fd, file_mode;
176 179
177 /* set file mode */ 180 /* set file mode */
@@ -185,7 +188,7 @@ static bool do_file(char *path, char *desc, bool is_load) {
185 if (is_load) 188 if (is_load)
186 { 189 {
187 /* load description */ 190 /* load description */
188 read(fd, desc_buf, 20); 191 read(fd, desc_buf, sizeof(desc_buf));
189 192
190 /* load state */ 193 /* load state */
191 loadstate(fd); 194 loadstate(fd);
@@ -196,12 +199,12 @@ static bool do_file(char *path, char *desc, bool is_load) {
196 else 199 else
197 { 200 {
198 /* build description buffer */ 201 /* build description buffer */
199 memset(desc_buf, 0, 20); 202 memset(desc_buf, 0, sizeof(desc_buf));
200 if (desc) 203 if (desc)
201 strlcpy(desc_buf, desc, 20); 204 strlcpy(desc_buf, desc, sizeof(desc_buf));
202 205
203 /* save state */ 206 /* save state */
204 write(fd, desc_buf, 20); 207 write(fd, desc_buf, sizeof(desc_buf));
205 savestate(fd); 208 savestate(fd);
206 } 209 }
207 210
@@ -218,18 +221,20 @@ static bool do_file(char *path, char *desc, bool is_load) {
218 * Returns true on success and false on failure. 221 * Returns true on success and false on failure.
219 */ 222 */
220static bool do_slot(int slot_id, bool is_load) { 223static bool do_slot(int slot_id, bool is_load) {
221 char path_buf[256], desc_buf[20]; 224 char path_buf[256], desc_buf[DESC_SIZE];
222 225
223 /* build slot filename, clear desc buf */ 226 /* build slot filename, clear desc buf */
224 build_slot_path(path_buf, 256, slot_id); 227 build_slot_path(path_buf, sizeof(path_buf), slot_id);
225 memset(desc_buf, 0, 20); 228 memset(desc_buf, 0, sizeof(desc_buf));
226 229
227 /* if we're saving to a slot, then get a brief description */ 230 /* if we're saving to a slot, then get a brief description */
228 if (!is_load) 231 if (!is_load)
229 if ( (rb->kbd_input(desc_buf, 20) < 0) || !strlen(desc_buf) ) 232 {
230 { 233 if ( rb->kbd_input(desc_buf, sizeof(desc_buf)) < 0 )
231 strlcpy(desc_buf, "Untitled", 20); 234 return false;
232 } 235 if ( !strlen(desc_buf) )
236 strlcpy(desc_buf, "Untitled", sizeof(desc_buf));
237 }
233 238
234 /* load/save file */ 239 /* load/save file */
235 return do_file(path_buf, desc_buf, is_load); 240 return do_file(path_buf, desc_buf, is_load);
@@ -243,26 +248,26 @@ static void slot_info(char *info_buf, size_t info_bufsiz, int slot_id) {
243 int fd; 248 int fd;
244 249
245 /* get slot file path */ 250 /* get slot file path */
246 build_slot_path(buf, 256, slot_id); 251 build_slot_path(buf, sizeof(buf), slot_id);
247 252
248 /* attempt to open slot */ 253 /* attempt to open slot */
249 if ((fd = open(buf, O_RDONLY)) >= 0) 254 if ((fd = open(buf, O_RDONLY)) >= 0)
250 { 255 {
251 /* this slot has a some data in it, read it */ 256 /* this slot has a some data in it, read it */
252 if (read(fd, buf, 20) > 0) 257 if (read(fd, buf, DESC_SIZE) == DESC_SIZE)
253 { 258 {
254 buf[20] = '\0'; 259 buf[DESC_SIZE] = '\0';
255 snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, buf); 260 strlcpy(info_buf, buf, info_bufsiz);
256 } 261 }
257 else 262 else
258 snprintf(info_buf, info_bufsiz, "%d. ERROR", slot_id + 1); 263 strlcpy(info_buf, "ERROR", info_bufsiz);
259 264
260 close(fd); 265 close(fd);
261 } 266 }
262 else 267 else
263 { 268 {
264 /* if we couldn't open the file, then the slot is empty */ 269 /* if we couldn't open the file, then the slot is empty */
265 snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, "<Empty>"); 270 strlcpy(info_buf, "<Empty>", info_bufsiz);
266 } 271 }
267} 272}
268 273
@@ -272,10 +277,10 @@ static void slot_info(char *info_buf, size_t info_bufsiz, int slot_id) {
272static const char* slot_get_name(int selected_item, void * data, 277static const char* slot_get_name(int selected_item, void * data,
273 char * buffer, size_t buffer_len) 278 char * buffer, size_t buffer_len)
274{ 279{
275 const char (*items)[20] = data; 280 const char (*items)[DESC_SIZE] = data;
276 (void) buffer; 281 snprintf(buffer, buffer_len, "%d. %s",
277 (void) buffer_len; 282 selected_item + 1, items[selected_item]);
278 return items[selected_item]; 283 return buffer;
279} 284}
280 285
281/* 286/*
@@ -294,7 +299,7 @@ static int list_action_callback(int action, struct gui_synclist *lists)
294 */ 299 */
295static void do_slot_menu(bool is_load) { 300static void do_slot_menu(bool is_load) {
296 bool done=false; 301 bool done=false;
297 char items[5][20]; 302 char items[MAX_SLOTS][DESC_SIZE];
298 int result; 303 int result;
299 int i; 304 int i;
300 int num_items = sizeof(items) / sizeof(*items); 305 int num_items = sizeof(items) / sizeof(*items);
@@ -302,7 +307,7 @@ static void do_slot_menu(bool is_load) {
302 307
303 /* create menu items */ 308 /* create menu items */
304 for (i = 0; i < num_items; i++) 309 for (i = 0; i < num_items; i++)
305 slot_info(items[i], 20, i); 310 slot_info(items[i], sizeof(*items), i);
306 311
307 rb->simplelist_info_init(&info, NULL, num_items, (void *)items); 312 rb->simplelist_info_init(&info, NULL, num_items, (void *)items);
308 info.get_name = slot_get_name; 313 info.get_name = slot_get_name;