2006-01-09 11:22:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-02-03 15:19:58 +00:00
|
|
|
* Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
|
2006-01-09 11:22:36 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-01-09 11:22:36 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
#include <stdlib.h>
|
2006-02-09 11:17:52 +00:00
|
|
|
#include <string.h>
|
2007-09-10 03:49:12 +00:00
|
|
|
#include <setjmp.h>
|
2006-02-03 15:19:58 +00:00
|
|
|
#include "autoconf.h"
|
|
|
|
#include "button.h"
|
2007-10-26 23:11:18 +00:00
|
|
|
#include "system-sdl.h"
|
2006-02-03 15:19:58 +00:00
|
|
|
#include "thread.h"
|
|
|
|
#include "kernel.h"
|
2006-02-09 21:49:28 +00:00
|
|
|
#include "uisdl.h"
|
|
|
|
#include "lcd-sdl.h"
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "lcd-bitmap.h"
|
2007-02-20 15:12:56 +00:00
|
|
|
#elif defined(HAVE_LCD_CHARCELLS)
|
2007-03-31 09:58:49 +00:00
|
|
|
#include "lcd-charcells.h"
|
2006-02-09 21:49:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2006-07-28 07:35:45 +00:00
|
|
|
#include "lcd-remote-bitmap.h"
|
2006-02-09 21:49:28 +00:00
|
|
|
#endif
|
|
|
|
#include "thread-sdl.h"
|
|
|
|
#include "SDL_mutex.h"
|
|
|
|
#include "SDL_thread.h"
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
/* extern functions */
|
2008-03-25 02:34:12 +00:00
|
|
|
extern void new_key(int key);
|
2006-02-03 15:19:58 +00:00
|
|
|
|
|
|
|
void button_event(int key, bool pressed);
|
|
|
|
|
|
|
|
SDL_Surface *gui_surface;
|
2006-02-09 11:17:52 +00:00
|
|
|
bool background = false; /* Don't use backgrounds by default */
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
bool lcd_display_redraw = true; /* Used for player simulator */
|
2006-02-21 21:48:06 +00:00
|
|
|
char having_new_lcd = true; /* Used for player simulator */
|
2007-10-13 12:07:59 +00:00
|
|
|
bool sim_alarm_wakeup = false;
|
2007-11-08 10:15:44 +00:00
|
|
|
const char *sim_root_dir = NULL;
|
2006-02-21 21:48:06 +00:00
|
|
|
|
|
|
|
bool debug_audio = false;
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2007-04-24 23:58:57 +00:00
|
|
|
bool debug_wps = false;
|
2007-07-22 17:17:53 +00:00
|
|
|
int wps_verbose_level = 3;
|
2007-04-24 23:58:57 +00:00
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
void gui_message_loop(void)
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
2006-02-03 15:19:58 +00:00
|
|
|
SDL_Event event;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
while(!done && SDL_WaitEvent(&event))
|
|
|
|
{
|
|
|
|
switch(event.type)
|
|
|
|
{
|
|
|
|
case SDL_KEYDOWN:
|
2007-10-26 23:11:18 +00:00
|
|
|
sim_enter_irq_handler();
|
2006-02-03 15:19:58 +00:00
|
|
|
button_event(event.key.keysym.sym, true);
|
2007-10-26 23:11:18 +00:00
|
|
|
sim_exit_irq_handler();
|
2006-02-03 15:19:58 +00:00
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
2007-10-26 23:11:18 +00:00
|
|
|
sim_enter_irq_handler();
|
2006-02-03 15:19:58 +00:00
|
|
|
button_event(event.key.keysym.sym, false);
|
2007-10-26 23:11:18 +00:00
|
|
|
sim_exit_irq_handler();
|
2006-02-03 15:19:58 +00:00
|
|
|
break;
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifndef HAVE_TOUCHSCREEN
|
2007-11-11 01:50:18 +00:00
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
if (debug_wps && event.button.button == 1)
|
|
|
|
{
|
|
|
|
printf("Mouse at: (%d, %d)\n", event.button.x, event.button.y);
|
|
|
|
}
|
|
|
|
break;
|
2008-04-15 10:35:11 +00:00
|
|
|
#else
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
sim_enter_irq_handler();
|
2008-08-23 09:46:38 +00:00
|
|
|
button_event(BUTTON_TOUCHSCREEN, false);
|
2008-04-15 10:35:11 +00:00
|
|
|
sim_exit_irq_handler();
|
|
|
|
break;
|
2007-11-11 01:50:18 +00:00
|
|
|
#endif
|
2006-02-03 15:19:58 +00:00
|
|
|
case SDL_QUIT:
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
default:
|
2006-03-19 06:59:36 +00:00
|
|
|
/*printf("Unhandled event\n"); */
|
2006-02-03 15:19:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-17 22:09:34 +00:00
|
|
|
bool gui_startup(void)
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
2006-02-03 15:19:58 +00:00
|
|
|
SDL_Surface *picture_surface;
|
2006-02-09 11:17:52 +00:00
|
|
|
int width, height;
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) {
|
2007-09-10 21:18:19 +00:00
|
|
|
fprintf(stderr, "fatal: %s\n", SDL_GetError());
|
2006-02-03 15:19:58 +00:00
|
|
|
return false;
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
atexit(SDL_Quit);
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2006-02-09 11:17:52 +00:00
|
|
|
/* Try and load the background image. If it fails go without */
|
|
|
|
if (background) {
|
|
|
|
picture_surface = SDL_LoadBMP("UI256.bmp");
|
|
|
|
if (picture_surface == NULL) {
|
|
|
|
background = false;
|
2007-09-10 21:18:19 +00:00
|
|
|
fprintf(stderr, "warn: %s\n", SDL_GetError());
|
2006-02-09 11:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set things up */
|
|
|
|
|
|
|
|
if (background) {
|
|
|
|
width = UI_WIDTH;
|
|
|
|
height = UI_HEIGHT;
|
|
|
|
} else {
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
width = UI_LCD_WIDTH > UI_REMOTE_WIDTH ? UI_LCD_WIDTH : UI_REMOTE_WIDTH;
|
|
|
|
height = UI_LCD_HEIGHT + UI_REMOTE_HEIGHT;
|
|
|
|
#else
|
|
|
|
width = UI_LCD_WIDTH;
|
|
|
|
height = UI_LCD_HEIGHT;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
|
2006-02-09 11:17:52 +00:00
|
|
|
fprintf(stderr, "fatal: %s\n", SDL_GetError());
|
2006-02-03 15:19:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
SDL_WM_SetCaption(UI_TITLE, NULL);
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
sim_lcd_init();
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
sim_lcd_remote_init();
|
|
|
|
#endif
|
2006-02-09 11:17:52 +00:00
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
2006-02-09 11:17:52 +00:00
|
|
|
|
|
|
|
if (background && picture_surface != NULL) {
|
2006-02-03 15:19:58 +00:00
|
|
|
SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
|
|
|
|
SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
|
2006-02-09 11:17:52 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
return true;
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-17 22:09:34 +00:00
|
|
|
bool gui_shutdown(void)
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
2007-09-10 03:49:12 +00:00
|
|
|
/* Order here is relevent to prevent deadlocks and use of destroyed
|
|
|
|
sync primitives by kernel threads */
|
|
|
|
thread_sdl_shutdown();
|
2007-10-26 23:11:18 +00:00
|
|
|
sim_kernel_shutdown();
|
2006-02-03 15:19:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2006-10-22 12:41:13 +00:00
|
|
|
#if defined(WIN32) && defined(main)
|
|
|
|
/* Don't use SDL_main on windows -> no more stdio redirection */
|
|
|
|
#undef main
|
|
|
|
#endif
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
int main(int argc, char *argv[])
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
2007-11-08 10:15:44 +00:00
|
|
|
if (argc >= 1)
|
|
|
|
{
|
2006-02-09 11:17:52 +00:00
|
|
|
int x;
|
2007-11-08 10:15:44 +00:00
|
|
|
for (x = 1; x < argc; x++)
|
|
|
|
{
|
|
|
|
if (!strcmp("--debugaudio", argv[x]))
|
|
|
|
{
|
2006-02-21 21:48:06 +00:00
|
|
|
debug_audio = true;
|
|
|
|
printf("Writing debug audio file.\n");
|
2007-11-08 10:15:44 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp("--debugwps", argv[x]))
|
|
|
|
{
|
2007-04-24 23:58:57 +00:00
|
|
|
debug_wps = true;
|
|
|
|
printf("WPS debug mode enabled.\n");
|
2007-11-08 10:15:44 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp("--background", argv[x]))
|
|
|
|
{
|
2006-02-09 11:17:52 +00:00
|
|
|
background = true;
|
|
|
|
printf("Using background image.\n");
|
2007-11-08 10:15:44 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp("--old_lcd", argv[x]))
|
|
|
|
{
|
2006-02-09 11:17:52 +00:00
|
|
|
having_new_lcd = false;
|
|
|
|
printf("Using old LCD layout.\n");
|
2007-11-08 10:15:44 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp("--zoom", argv[x]))
|
|
|
|
{
|
2006-02-09 21:49:28 +00:00
|
|
|
x++;
|
2006-02-21 21:56:38 +00:00
|
|
|
if(x < argc)
|
|
|
|
display_zoom=atoi(argv[x]);
|
|
|
|
else
|
|
|
|
display_zoom = 2;
|
2006-02-09 21:49:28 +00:00
|
|
|
printf("Window zoom is %d\n", display_zoom);
|
2007-11-08 10:15:44 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp("--alarm", argv[x]))
|
|
|
|
{
|
2007-10-13 12:07:59 +00:00
|
|
|
sim_alarm_wakeup = true;
|
|
|
|
printf("Simulating alarm wakeup.\n");
|
2007-11-08 10:15:44 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp("--root", argv[x]))
|
|
|
|
{
|
|
|
|
x++;
|
|
|
|
if (x < argc)
|
|
|
|
{
|
|
|
|
sim_root_dir = argv[x];
|
|
|
|
printf("Root directory: %s\n", sim_root_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-09 11:17:52 +00:00
|
|
|
printf("rockboxui\n");
|
|
|
|
printf("Arguments:\n");
|
2006-02-21 21:48:06 +00:00
|
|
|
printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
|
2007-04-24 23:58:57 +00:00
|
|
|
printf(" --debugwps \t Print advanced WPS debug info\n");
|
2006-02-09 11:17:52 +00:00
|
|
|
printf(" --background \t Use background image of hardware\n");
|
|
|
|
printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
|
2007-11-08 10:15:44 +00:00
|
|
|
printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
|
|
|
|
printf(" --alarm \t Simulate a wake-up on alarm\n");
|
|
|
|
printf(" --root [DIR]\t Set root directory\n");
|
2006-02-09 11:17:52 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
if (display_zoom > 1) {
|
|
|
|
background = false;
|
|
|
|
}
|
|
|
|
|
2007-10-26 23:11:18 +00:00
|
|
|
if (!sim_kernel_init()) {
|
|
|
|
fprintf(stderr, "sim_kernel_init failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-09-10 03:49:12 +00:00
|
|
|
if (!gui_startup()) {
|
|
|
|
fprintf(stderr, "gui_startup failed\n");
|
2006-02-03 15:19:58 +00:00
|
|
|
return -1;
|
2007-09-10 03:49:12 +00:00
|
|
|
}
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2007-09-10 03:49:12 +00:00
|
|
|
/* app_main will be called by the new main thread */
|
|
|
|
if (!thread_sdl_init(NULL)) {
|
|
|
|
fprintf(stderr, "thread_sdl_init failed\n");
|
2006-02-03 15:19:58 +00:00
|
|
|
return -1;
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
gui_message_loop();
|
|
|
|
|
|
|
|
return gui_shutdown();
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
2006-02-03 15:19:58 +00:00
|
|
|
|