1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Dave Chapman
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 ****************************************************************************/
29 #include "wps_internals.h"
32 bool debug_wps
= true;
33 int wps_verbose_level
= 0;
37 const struct settings_list
*settings
;
38 const int nb_settings
= 0;
40 /* static endianness conversion */
41 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
42 ((unsigned short)(x) << 8)))
44 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
45 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
46 (((unsigned long)(x) & 0xff00ul) << 8) | \
47 ((unsigned long)(x) << 24)))
50 unsigned short letoh16(unsigned short x
)
52 unsigned short n
= 0x1234;
53 unsigned char* ch
= (unsigned char*)&n
;
66 unsigned short letoh32(unsigned short x
)
68 unsigned short n
= 0x1234;
69 unsigned char* ch
= (unsigned char*)&n
;
82 unsigned int htole32(unsigned int x
)
84 unsigned short n
= 0x1234;
85 unsigned char* ch
= (unsigned char*)&n
;
97 int read_line(int fd
, char* buffer
, int buffer_size
)
104 while (count
< buffer_size
)
108 if (1 != read(fd
, &c
, 1))
122 buffer
[MIN(count
, buffer_size
- 1)] = 0;
124 return errno
? -1 : num_read
;
127 bool load_wps_backdrop(const char* filename
)
132 bool load_remote_wps_backdrop(const char* filename
)
137 int recalc_dimension(struct dim
*dst
, struct dim
*src
)
142 int resize_on_load(struct bitmap
*bm
, bool dither
,
143 struct dim
*src
, struct rowset
*tmp_row
,
144 unsigned char *buf
, unsigned int len
,
145 const struct custom_format
*cformat
,
146 IF_PIX_FMT(int format_index
,)
147 struct img_part
* (*store_part
)(void *args
),
153 int audio_status(void)
158 struct mp3entry
* audio_current_track(void)
163 void audio_stop(void)
167 void audio_play(long offset
)
171 static char pluginbuf
[PLUGIN_BUFFER_SIZE
];
173 static unsigned dummy_func2(void)
178 void* plugin_get_buffer(size_t *buffer_size
)
180 *buffer_size
= PLUGIN_BUFFER_SIZE
;
184 struct user_settings global_settings
= {
186 #ifdef HAVE_LCD_COLOR
187 .bg_color
= LCD_DEFAULT_BG
,
188 .fg_color
= LCD_DEFAULT_FG
,
192 int getwidth(void) { return LCD_WIDTH
; }
193 int getheight(void) { return LCD_HEIGHT
; }
194 #ifdef HAVE_REMOTE_LCD
195 int remote_getwidth(void) { return LCD_REMOTE_WIDTH
; }
196 int remote_getheight(void) { return LCD_REMOTE_HEIGHT
; }
199 struct screen screens
[NB_SCREENS
] =
202 .screen_type
=SCREEN_MAIN
,
204 .lcdheight
=LCD_HEIGHT
,
206 #ifdef HAVE_LCD_COLOR
211 .getwidth
= getwidth
,
212 .getheight
= getheight
,
214 .get_foreground
=dummy_func2
,
215 .get_background
=dummy_func2
,
217 .backdrop_load
=backdrop_load
,
219 #ifdef HAVE_REMOTE_LCD
221 .screen_type
=SCREEN_REMOTE
,
222 .lcdwidth
=LCD_REMOTE_WIDTH
,
223 .lcdheight
=LCD_REMOTE_HEIGHT
,
224 .depth
=LCD_REMOTE_DEPTH
,
225 .is_color
=false,/* No color remotes yet */
226 .getwidth
=remote_getwidth
,
227 .getheight
=remote_getheight
,
228 #if LCD_REMOTE_DEPTH > 1
229 .get_foreground
=dummy_func2
,
230 .get_background
=dummy_func2
,
232 .backdrop_load
=backdrop_load
,
237 #ifdef HAVE_LCD_BITMAP
238 void screen_clear_area(struct screen
* display
, int xstart
, int ystart
,
239 int width
, int height
)
241 display
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
242 display
->fillrect(xstart
, ystart
, width
, height
);
243 display
->set_drawmode(DRMODE_SOLID
);
247 /* From skin_display.c */
248 void skin_data_init(struct wps_data
*wps_data
)
250 #ifdef HAVE_LCD_BITMAP
251 wps_data
->wps_sb_tag
= false;
252 wps_data
->show_sb_on_wps
= false;
253 wps_data
->peak_meter_enabled
= false;
254 wps_data
->images
= NULL
;
255 wps_data
->progressbars
= NULL
;
257 #else /* HAVE_LCD_CHARCELLS */
259 for (i
= 0; i
< 8; i
++)
261 wps_data
->wps_progress_pat
[i
] = 0;
263 wps_data
->full_line_progressbar
= false;
265 wps_data
->button_time_volume
= 0;
266 wps_data
->wps_loaded
= false;
269 #ifdef HAVE_LCD_BITMAP
270 struct gui_img
* find_image(char label
, struct wps_data
*data
)
272 struct skin_token_list
*list
= data
->images
;
275 struct gui_img
*img
= (struct gui_img
*)list
->token
->value
.data
;
276 if (img
->label
== label
)
284 struct skin_viewport
* find_viewport(char label
, struct wps_data
*data
)
286 struct skin_token_list
*list
= data
->viewports
;
289 struct skin_viewport
*vp
= (struct skin_viewport
*)list
->token
->value
.data
;
290 if (vp
->label
== label
)
297 int skin_last_token_index(struct wps_data
*data
, int line
, int subline
)
299 int first_subline_idx
= data
->lines
[line
].first_subline_idx
;
300 int idx
= first_subline_idx
+ subline
;
301 if (idx
< data
->num_sublines
- 1)
303 /* This subline ends where the next begins */
304 return data
->sublines
[idx
+1].first_token_idx
- 1;
308 /* The last subline goes to the end */
309 return data
->num_tokens
- 1;
313 /* From viewport.c & misc.h */
314 #define LIST_VALUE_PARSED(setvals, position) ((setvals) & BIT_N(position))
316 /*some short cuts for fg/bg/line selector handling */
317 #ifdef HAVE_LCD_COLOR
318 #define LINE_SEL_FROM_SETTINGS(vp) \
320 vp->lss_pattern = global_settings.lss_color; \
321 vp->lse_pattern = global_settings.lse_color; \
322 vp->lst_pattern = global_settings.lst_color; \
324 #define FG_FALLBACK global_settings.fg_color
325 #define BG_FALLBACK global_settings.bg_color
327 /* mono/greyscale doesn't have most of the above */
328 #define LINE_SEL_FROM_SETTINGS(vp)
329 #define FG_FALLBACK LCD_DEFAULT_FG
330 #define BG_FALLBACK LCD_DEFAULT_BG
333 #ifdef HAVE_LCD_COLOR
334 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
336 #define ARG_STRING(_depth) "dddddgg"
339 extern const char* parse_list(const char *fmt
, uint32_t *set_vals
,
340 const char sep
, const char* str
, ...);
342 const char* viewport_parse_viewport(struct viewport
*vp
,
343 enum screen_type screen
,
345 const char separator
)
347 /* parse the list to the viewport struct */
348 const char *ptr
= bufptr
;
362 /* Work out the depth of this display */
363 depth
= screens
[screen
].depth
;
364 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
367 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
368 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
373 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
376 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
377 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
378 &vp
->fg_pattern
,&vp
->bg_pattern
)))
386 /* X and Y *must* be set */
387 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
391 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
392 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
393 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
394 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
396 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
397 if (!LIST_VALUE_PARSED(set
, PL_FG
))
398 vp
->fg_pattern
= FG_FALLBACK
;
399 if (!LIST_VALUE_PARSED(set
, PL_BG
))
400 vp
->bg_pattern
= BG_FALLBACK
;
401 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
403 LINE_SEL_FROM_SETTINGS(vp
);
405 /* Validate the viewport dimensions - we know that the numbers are
406 non-negative integers, ignore bars and assume the viewport takes them
408 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
409 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
410 (vp
->y
>= screens
[screen
].lcdheight
) ||
411 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
416 /* Default to using the user font if the font was an invalid number or '-'*/
417 if (((vp
->font
!= FONT_SYSFIXED
) && (vp
->font
!= FONT_UI
))
418 || !LIST_VALUE_PARSED(set
, PL_FONT
)
422 /* Set the defaults for fields not user-specified */
423 vp
->drawmode
= DRMODE_SOLID
;
428 int main(int argc
, char **argv
)
434 struct screen
* wps_screen
= &screens
[SCREEN_MAIN
];
436 /* No arguments -> print the help text
437 * Also print the help text upon -h or --help */
439 strcmp(argv
[1],"-h") == 0 ||
440 strcmp(argv
[1],"--help") == 0 )
442 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
443 printf("\nOPTIONS:\n");
444 printf("\t-v\t\tverbose\n");
445 printf("\t-vv\t\tmore verbose\n");
446 printf("\t-vvv\t\tvery verbose\n");
447 printf("\t-h,\t--help\tshow this message\n");
451 if (argv
[1][0] == '-') {
454 while (argv
[1][i
] && argv
[1][i
] == 'v') {
462 /* Go through every wps that was thrown at us, error out at the first
464 while (argv
[filearg
]) {
465 printf("Checking %s...\n", argv
[filearg
]);
466 #ifdef HAVE_REMOTE_LCD
467 if(strcmp(&argv
[filearg
][strlen(argv
[filearg
])-4], "rwps") == 0)
469 wps_screen
= &screens
[SCREEN_REMOTE
];
470 wps
.remote_wps
= true;
474 wps_screen
= &screens
[SCREEN_MAIN
];
475 wps
.remote_wps
= false;
479 res
= skin_data_load(&wps
, wps_screen
, argv
[filearg
], true);
482 printf("WPS parsing failure\n");
486 printf("WPS parsed OK\n\n");