Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 20th, 2011  |  syntax: None  |  size: 46.69 KB  |  views: 138  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
  2. index 3aeffa2..dc28eba 100644
  3. --- a/android/src/org/rockbox/RockboxService.java
  4. +++ b/android/src/org/rockbox/RockboxService.java
  5. @@ -45,6 +45,7 @@ import android.os.Bundle;
  6.  import android.os.Environment;
  7.  import android.os.IBinder;
  8.  import android.os.ResultReceiver;
  9. +import android.util.DisplayMetrics;
  10.  import android.util.Log;
  11.  import android.view.KeyEvent;
  12.  
  13. @@ -92,6 +93,12 @@ public class RockboxService extends Service
  14.          return instance;
  15.      }
  16.  
  17. +    public int[] getResolution()
  18. +    {
  19. +        DisplayMetrics metrics = getResources().getDisplayMetrics();
  20. +        return new int[] {metrics.widthPixels, metrics.heightPixels};
  21. +    }
  22. +
  23.      public boolean isRockboxRunning()
  24.      {
  25.          return rockbox_running;
  26. diff --git a/apps/bitmaps/native/SOURCES b/apps/bitmaps/native/SOURCES
  27. index 9ce7d89..ca3647b 100644
  28. --- a/apps/bitmaps/native/SOURCES
  29. +++ b/apps/bitmaps/native/SOURCES
  30. @@ -1,5 +1,13 @@
  31.  #ifdef HAVE_LCD_BITMAP
  32.  
  33. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  34. +/* This is a hack to prevent buildtime errors popping up */
  35. +#undef LCD_WIDTH
  36. +#undef LCD_HEIGHT
  37. +#define LCD_WIDTH 0
  38. +#define LCD_HEIGHT 0
  39. +#endif
  40. +
  41.  /* Rockbox logo */
  42.  #if (LCD_DEPTH == 1)
  43.  #if (LCD_WIDTH == 160)
  44. @@ -9,6 +17,12 @@ rockboxlogo.128x42x1.bmp
  45.  #else
  46.  rockboxlogo.112x30x1.bmp
  47.  #endif
  48. +#elif defined(HAVE_DYNAMIC_LCD_SIZE)
  49. +/* Currently only one screen size is supported.
  50. + * Ideally, we should compile in multiple logos and choose the correct one
  51. + * at runtime (and optionally discard the others using INIT_ATTR).
  52. + */
  53. +rockboxlogo.320x98x16.bmp
  54.  #elif (LCD_WIDTH == 128) && (LCD_DEPTH == 2)
  55.  rockboxlogo.128x42x2.bmp
  56.  #elif (LCD_WIDTH == 128) && (LCD_DEPTH == 16)
  57. @@ -41,7 +55,9 @@ rockboxlogo.640x198x16.bmp
  58.  
  59.  /* USB logo */
  60.  #ifdef HAVE_LCD_COLOR
  61. -#if LCD_WIDTH > 176
  62. +#if defined(HAVE_DYNAMIC_LCD_SIZE)
  63. +usblogo.176x48x16.bmp
  64. +#elif LCD_WIDTH > 176
  65.  usblogo.176x48x16.bmp
  66.  #elif LCD_WIDTH >= 128
  67.  usblogo.128x37x16.bmp
  68. diff --git a/apps/debug_menu.c b/apps/debug_menu.c
  69. index a43dd0a..7be071b 100644
  70. --- a/apps/debug_menu.c
  71. +++ b/apps/debug_menu.c
  72. @@ -345,8 +345,13 @@ static bool dbg_buffering_thread(void)
  73.              screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
  74.                              (long) filebuflen);
  75.  
  76. -#if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
  77. -            if (screens[i].lcdheight > 80)
  78. +            if ((LCD_HEIGHT > 80 ||
  79. +#ifdef HAVE_REMOTE_LCD
  80. +                LCD_REMOTE_HEIGHT > 80
  81. +#else
  82. +                0
  83. +#endif
  84. +                ) && screens[i].lcdheight > 80)
  85.              {
  86.                  gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
  87.                                     filebuflen, 0, audio_filebufused(), HORIZONTAL);
  88. @@ -359,19 +364,22 @@ static bool dbg_buffering_thread(void)
  89.                                     filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
  90.                  line++;
  91.              }
  92. -#endif
  93.  
  94.              screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
  95.                                                         (long)filebuflen);
  96.  
  97. -#if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
  98. -            if (screens[i].lcdheight > 80)
  99. +            if ((LCD_HEIGHT > 80 ||
  100. +#ifdef HAVE_REMOTE_LCD
  101. +                LCD_REMOTE_HEIGHT > 80
  102. +#else
  103. +                0
  104. +#endif
  105. +                ) && screens[i].lcdheight > 80)
  106.              {
  107.                  gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
  108.                                     filebuflen, 0, d.useful_data, HORIZONTAL);
  109.                  line++;
  110.              }
  111. -#endif
  112.  
  113.              screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
  114.  
  115. diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c
  116. index 12950a6..0cb9f22 100644
  117. --- a/apps/gui/skin_engine/skin_backdrops.c
  118. +++ b/apps/gui/skin_engine/skin_backdrops.c
  119. @@ -114,6 +114,21 @@ bool skin_backdrops_preload(void)
  120.                  global_settings.backdrop_file[0] != '-' && filename[0] == '-')
  121.              {
  122.                  filename = global_settings.backdrop_file;
  123. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  124. +                if (!file_exists(filename))
  125. +                {
  126. +                    char copy[MAX_PATH];
  127. +                    char* temp = backdrops[i].name+2; /* slightly hacky to get a buffer */
  128. +                    char *ext = strrchr(copy, '.');
  129. +                    size_t size = sizeof(backdrops[i].name) -2;
  130. +                    *ext = '\0'; ext++;
  131. +                    snprintf(temp, size, "%s.%dx%dx%d.%s", copy,
  132. +                            screens[screen].lcdwidth,
  133. +                            screens[screen].lcdheight,
  134. +                            screens[screen].depth, ext);
  135. +                    filename = temp;
  136. +                }
  137. +#endif
  138.              }
  139.              if (*filename && *filename != '-')
  140.              {
  141. diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c
  142. index fbedbb9..780c42d 100644
  143. --- a/apps/gui/skin_engine/skin_engine.c
  144. +++ b/apps/gui/skin_engine/skin_engine.c
  145. @@ -30,6 +30,7 @@
  146.  #include "settings.h"
  147.  #include "wps.h"
  148.  #include "file.h"
  149. +#include "filefuncs.h"
  150.  #include "buffer.h"
  151.  #if CONFIG_TUNER
  152.  #include "radio.h"
  153. @@ -227,6 +228,14 @@ struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type scre
  154.          if (strcmp(setting, "rockbox_failsafe"))
  155.          {
  156.              snprintf(buf, sizeof buf, WPS_DIR "/%s.%s", setting, ext);
  157. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  158. +            if (!file_exists(buf))
  159. +            {
  160. +                snprintf(buf, sizeof buf, WPS_DIR "/%s.%dx%dx%d.%s",
  161. +                     setting, screens[screen].lcdwidth,
  162. +                     screens[screen].lcdheight, screens[screen].depth, ext);
  163. +            }
  164. +#endif
  165.          }
  166.          cpu_boost(true);
  167.          skin_load(skin, screen, buf, true);
  168. diff --git a/apps/gui/skin_engine/skin_fonts.h b/apps/gui/skin_engine/skin_fonts.h
  169. index 698ed4f..48bef2c 100644
  170. --- a/apps/gui/skin_engine/skin_fonts.h
  171. +++ b/apps/gui/skin_engine/skin_fonts.h
  172. @@ -31,11 +31,7 @@
  173.  #ifndef _SKINFONTS_H_
  174.  #define _SKINFONTS_H_
  175.  
  176. -#if LCD_HEIGHT > 160
  177. -#define SKIN_FONT_SIZE (1024*10)
  178. -#else
  179. -#define SKIN_FONT_SIZE (1024*3)
  180. -#endif
  181. +#define SKIN_FONT_SIZE  (LCD_HEIGHT > 160 ? 1024*10 : 1024*3)
  182.  #define GLYPHS_TO_CACHE 256
  183.  
  184.  void skin_font_init(void);
  185. diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
  186. index 2370a38..757f980 100644
  187. --- a/apps/gui/skin_engine/skin_parser.c
  188. +++ b/apps/gui/skin_engine/skin_parser.c
  189. @@ -1892,7 +1892,8 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
  190.      if (isfile)
  191.      {
  192.          /* get the bitmap dir */
  193. -        char *dot = strrchr(buf, '.');
  194. +        char *slash = strrchr(buf, '/');
  195. +        char *dot = strchr(slash, '.');
  196.          strlcpy(bmpdir, buf, dot - buf + 1);
  197.      }
  198.      else
  199. diff --git a/apps/main.c b/apps/main.c
  200. index 0b566b5..ab75e95 100644
  201. --- a/apps/main.c
  202. +++ b/apps/main.c
  203. @@ -348,6 +348,7 @@ static void init(void)
  204.      lcd_remote_init();
  205.  #endif
  206.      font_init();
  207. +    screen_init();
  208.      show_logo();
  209.      button_init();
  210.      powermgmt_init();
  211. diff --git a/apps/plugin.c b/apps/plugin.c
  212. index ea290c8..c76eb08 100644
  213. --- a/apps/plugin.c
  214. +++ b/apps/plugin.c
  215. @@ -145,7 +145,7 @@ static int close_wrapper(int fd);
  216.  static int creat_wrapper(const char *pathname, mode_t mode);
  217.  #endif
  218.  
  219. -static const struct plugin_api rockbox_api = {
  220. +static struct plugin_api rockbox_api = {
  221.  
  222.      /* lcd */
  223.  #ifdef HAVE_LCD_CONTRAST
  224. @@ -170,7 +170,7 @@ static const struct plugin_api rockbox_api = {
  225.      lcd_icon,
  226.      lcd_double_height,
  227.  #else
  228. -    &lcd_framebuffer[0][0],
  229. +    NULL, /* will get filled in later */
  230.      lcd_update_rect,
  231.      lcd_set_drawmode,
  232.      lcd_get_drawmode,
  233. @@ -841,7 +841,8 @@ int plugin_load(const char* plugin, const void* parameter)
  234.  #else
  235.      plugin_size = 0;
  236.  #endif
  237. -
  238. +    rockbox_api.lcd_framebuffer = lcd_framebuffer;
  239. +    
  240.      *(p_hdr->api) = &rockbox_api;
  241.  
  242.  #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
  243. diff --git a/apps/plugins/SOURCES.app_build b/apps/plugins/SOURCES.app_build
  244. index ddac2b9..93231ba 100644
  245. --- a/apps/plugins/SOURCES.app_build
  246. +++ b/apps/plugins/SOURCES.app_build
  247. @@ -1,5 +1,7 @@
  248.  /* plugins common to all models */
  249. +#ifndef HAVE_DYNAMIC_LCD_SIZE
  250.  credits.c
  251. +#endif
  252.  properties.c
  253.  random_folder_advance_config.c
  254.  search.c
  255. diff --git a/apps/plugins/SUBDIRS.app_build b/apps/plugins/SUBDIRS.app_build
  256. index dbf4382..8fc61be 100644
  257. --- a/apps/plugins/SUBDIRS.app_build
  258. +++ b/apps/plugins/SUBDIRS.app_build
  259. @@ -1,7 +1,7 @@
  260.  /* For all targets with a bitmap display */
  261.  #ifdef HAVE_LCD_BITMAP
  262.  
  263. -#ifdef HAVE_TAGCACHE
  264. +#if defined(HAVE_TAGCACHE) && !defined(HAVE_DYNAMIC_LCD_SIZE)
  265.  pictureflow
  266.  #endif
  267.  
  268. @@ -11,7 +11,9 @@ pictureflow
  269.  #if CONFIG_CODEC == SWCODEC
  270.  
  271.  #if MEMORYSIZE > 2 /* we need a lot of RAM for instruments */
  272. +#ifndef HAVE_DYNAMIC_LCD_SIZE
  273.  mikmod
  274.  #endif
  275. +#endif
  276.  
  277.  #endif /* CONFIG_CODEC == SWCODEC */
  278. diff --git a/apps/plugins/bitmaps/mono/SOURCES b/apps/plugins/bitmaps/mono/SOURCES
  279. index c12c7c7..3c53515 100644
  280. --- a/apps/plugins/bitmaps/mono/SOURCES
  281. +++ b/apps/plugins/bitmaps/mono/SOURCES
  282. @@ -1,5 +1,13 @@
  283.  #ifdef HAVE_LCD_BITMAP
  284.  
  285. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  286. +/* This is a hack to prevent buildtime errors popping up */
  287. +#undef LCD_WIDTH
  288. +#undef LCD_HEIGHT
  289. +#define LCD_WIDTH 0
  290. +#define LCD_HEIGHT 0
  291. +#endif
  292. +
  293.  /* Bubbles */
  294.  #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
  295.  bubbles_bubble.112x64x1.bmp
  296. diff --git a/apps/plugins/bitmaps/native/SOURCES b/apps/plugins/bitmaps/native/SOURCES
  297. index 65b1a38..9f7bee6 100644
  298. --- a/apps/plugins/bitmaps/native/SOURCES
  299. +++ b/apps/plugins/bitmaps/native/SOURCES
  300. @@ -1,5 +1,13 @@
  301.  #ifdef HAVE_LCD_BITMAP
  302.  
  303. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  304. +/* This is a hack to prevent buildtime errors popping up */
  305. +#undef LCD_WIDTH
  306. +#undef LCD_HEIGHT
  307. +#define LCD_WIDTH 0
  308. +#define LCD_HEIGHT 0
  309. +#endif
  310. +
  311.  /* Brickmania */
  312.  #ifdef HAVE_LCD_COLOR
  313.  brickmania_gameover.112x54x16.bmp
  314. diff --git a/apps/plugins/lib/simple_viewer.c b/apps/plugins/lib/simple_viewer.c
  315. index 16cbcb3..5d633fd 100644
  316. --- a/apps/plugins/lib/simple_viewer.c
  317. +++ b/apps/plugins/lib/simple_viewer.c
  318. @@ -182,7 +182,11 @@ static int init_view(struct view_info *info,
  319.  static void draw_text(struct view_info *info)
  320.  {
  321.  #ifdef HAVE_LCD_BITMAP
  322. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  323. +#define OUTPUT_SIZE MAX_LCD_WIDTH+1
  324. +#else
  325.  #define OUTPUT_SIZE LCD_WIDTH+1
  326. +#endif
  327.  #else
  328.  #define OUTPUT_SIZE LCD_WIDTH*3+1
  329.  #endif
  330. diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.h
  331. index 31bd073..88a6297 100644
  332. --- a/apps/recorder/bmp.h
  333. +++ b/apps/recorder/bmp.h
  334. @@ -33,7 +33,7 @@
  335.  
  336.  #define IMG_NORESIZE           0
  337.  #define IMG_RESIZE             1
  338. -#define BM_MAX_WIDTH (((LCD_WIDTH) + 7) & ~7)
  339. +#define BM_MAX_WIDTH (((MAX_LCD_WIDTH) + 7) & ~7)
  340.  
  341.  struct uint8_rgb {
  342.      uint8_t blue;
  343. diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
  344. index 1b2d76e..c748add 100644
  345. --- a/apps/recorder/keyboard.c
  346. +++ b/apps/recorder/keyboard.c
  347. @@ -371,10 +371,8 @@ int kbd_input(char* text, int buflen)
  348.              const unsigned char *p;
  349.              int len = 0;
  350.  
  351. -#if LCD_WIDTH >= 160 && LCD_HEIGHT >= 96
  352. -            struct screen *sc = &screens[l];
  353. -
  354. -            if (sc->getwidth() >= 160 && sc->getheight() >= 96)
  355. +            if (LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 &&
  356. +                screens[l].getwidth() >= 160 && screens[l].getheight() >= 96)
  357.              {
  358.                  p = "ABCDEFG abcdefg !?\" @#$%+'\n"
  359.                      "HIJKLMN hijklmn 789 &_()-`\n"
  360. @@ -389,7 +387,6 @@ int kbd_input(char* text, int buflen)
  361.                  pm->max_line_len = 26;
  362.              }
  363.              else
  364. -#endif /* LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 */
  365.              {
  366.                  p = "ABCDEFG !?\" @#$%+'\n"
  367.                      "HIJKLMN 789 &_()-`\n"
  368. diff --git a/apps/screen_access.c b/apps/screen_access.c
  369. index b83e842..00794d1 100644
  370. --- a/apps/screen_access.c
  371. +++ b/apps/screen_access.c
  372. @@ -105,8 +105,6 @@ struct screen screens[NB_SCREENS] =
  373.  {
  374.      {
  375.          .screen_type=SCREEN_MAIN,
  376. -        .lcdwidth=LCD_WIDTH,
  377. -        .lcdheight=LCD_HEIGHT,
  378.          .depth=LCD_DEPTH,
  379.          .getnblines=&screen_helper_getnblines,
  380.  #if defined(HAVE_LCD_COLOR)
  381. @@ -316,3 +314,9 @@ void screen_clear_area(struct screen * display, int xstart, int ystart,
  382.      display->set_drawmode(DRMODE_SOLID);
  383.  }
  384.  #endif
  385. +
  386. +void screen_init(void)
  387. +{
  388. +    screens[SCREEN_MAIN].lcdwidth = LCD_WIDTH;
  389. +    screens[SCREEN_MAIN].lcdheight = LCD_HEIGHT;
  390. +}
  391. diff --git a/apps/screen_access.h b/apps/screen_access.h
  392. index efe232b..599ca76 100644
  393. --- a/apps/screen_access.h
  394. +++ b/apps/screen_access.h
  395. @@ -177,4 +177,6 @@ void screen_clear_area(struct screen * display, int xstart, int ystart,
  396.   */
  397.  extern struct screen screens[NB_SCREENS];
  398.  
  399. +void screen_init(void) INIT_ATTR;
  400. +
  401.  #endif /*_SCREEN_ACCESS_H_*/
  402. diff --git a/apps/settings_list.c b/apps/settings_list.c
  403. index 5b9a840..b72d8ea 100644
  404. --- a/apps/settings_list.c
  405. +++ b/apps/settings_list.c
  406. @@ -205,7 +205,7 @@ static const char graphic_numeric[] = "graphic,numeric";
  407.  #define DEFAULT_SBSNAME  "-"
  408.  #define DEFAULT_FMS_NAME DEFAULT_WPSNAME
  409.  
  410. -#ifdef HAVE_LCD_BITMAP
  411. +#if defined(HAVE_LCD_BITMAP) && !defined(HAVE_DYNAMIC_LCD_SIZE)
  412.  
  413.  #if LCD_HEIGHT <= 64
  414.    #define DEFAULT_FONTNAME "08-Rockfont"
  415. @@ -224,7 +224,7 @@ static const char graphic_numeric[] = "graphic,numeric";
  416.  #endif
  417.  
  418.  #else
  419. -  #define DEFAULT_FONTNAME ""
  420. +  #define DEFAULT_FONTNAME "27-Adobe-Helvetica"
  421.  #endif
  422.  
  423.  #ifdef HAVE_REMOTE_LCD
  424. @@ -732,7 +732,7 @@ const struct settings_list settings[] = {
  425.                    LANG_SCROLL_BAR, SCROLLBAR_LEFT, "scrollbar","off,left,right",
  426.                    NULL, 3, ID2P(LANG_OFF), ID2P(LANG_LEFT), ID2P(LANG_RIGHT)),
  427.      INT_SETTING(F_THEMESETTING, scrollbar_width, LANG_SCROLLBAR_WIDTH, 6,
  428. -                "scrollbar width",UNIT_INT, 3, MAX(LCD_WIDTH/10,25), 1,
  429. +                "scrollbar width",UNIT_INT, 3, 25, 1,
  430.                  NULL, NULL, NULL),
  431.  #if CONFIG_KEYPAD == RECORDER_PAD
  432.      OFFON_SETTING(F_THEMESETTING,buttonbar, LANG_BUTTON_BAR ,true,"buttonbar", NULL),
  433. @@ -919,9 +919,9 @@ const struct settings_list settings[] = {
  434.                    false, "Screen Scrolls Out Of View",
  435.                    gui_list_screen_scroll_out_of_view),
  436.      INT_SETTING(F_PADTITLE, scroll_step, LANG_SCROLL_STEP, 6, "scroll step",
  437. -                UNIT_PIXEL, 1, LCD_WIDTH, 1, NULL, NULL, lcd_scroll_step),
  438. +                UNIT_PIXEL, 1, 400/*LCD_WIDTH*/, 1, NULL, NULL, lcd_scroll_step),
  439.      INT_SETTING(F_PADTITLE, screen_scroll_step, LANG_SCREEN_SCROLL_STEP, 16,
  440. -                "screen scroll step", UNIT_PIXEL, 1, LCD_WIDTH, 1, NULL, NULL,
  441. +                "screen scroll step", UNIT_PIXEL, 1, 400/*LCD_WIDTH*/, 1, NULL, NULL,
  442.                  gui_list_screen_scroll_step),
  443.  #endif /* HAVE_LCD_BITMAP */
  444.      OFFON_SETTING(0,scroll_paginated,LANG_SCROLL_PAGINATED,
  445. diff --git a/firmware/bidi.c b/firmware/bidi.c
  446. index 2f4e137..a20334b 100644
  447. --- a/firmware/bidi.c
  448. +++ b/firmware/bidi.c
  449. @@ -137,14 +137,32 @@ static void arabjoin(unsigned short * stringprt, int length)
  450.  
  451.  unsigned short *bidi_l2v(const unsigned char *str, int orientation)
  452.  {
  453. -    static unsigned short  utf16_buf[SCROLL_LINE_SIZE];
  454. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  455. +    static unsigned short *utf16_buf = NULL;
  456. +#else
  457. +    static unsigned short utf16_buf[SCROLL_LINE_SIZE];
  458. +#endif
  459.      unsigned short *target, *tmp;
  460.  #ifndef BOOTLOADER
  461. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  462. +    static unsigned short *bidi_buf = NULL;
  463. +#else
  464.      static unsigned short  bidi_buf[SCROLL_LINE_SIZE];
  465. +#endif
  466.      unsigned short *heb_str; /* *broken_str */
  467.      int block_start, block_end, block_type, block_length, i;
  468.      int length = utf8length(str);
  469.  #endif
  470. +
  471. +
  472. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  473. +    /* FIXME: find somewhere better for this. */
  474. +    if (utf16_buf == NULL)
  475. +        utf16_buf = malloc(SCROLL_LINE_SIZE);
  476. +    if (bidi_buf == NULL)
  477. +        bidi_buf = malloc(SCROLL_LINE_SIZE);
  478. +#endif
  479. +
  480.      /*
  481.      long max_chars=0;
  482.      int begin, end, char_count, orig_begin;
  483. diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c
  484. index 28c3285..19fc20a 100644
  485. --- a/firmware/drivers/lcd-16bit.c
  486. +++ b/firmware/drivers/lcd-16bit.c
  487. @@ -46,9 +46,12 @@ enum fill_opt {
  488.  };
  489.  
  490.  /*** globals ***/
  491. -fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH]
  492. +fb_data *lcd_framebuffer;
  493. +#if !defined(HAVE_DYNAMIC_LCD_SIZE) && \
  494. +    (CONFIG_PLATFORM != (PLATFORM_HOSTED|PLATFORM_ANDROID))
  495. +fb_data _lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH]
  496.      IRAM_LCDFRAMEBUFFER CACHEALIGN_AT_LEAST_ATTR(16);
  497. -
  498. +#endif
  499.  
  500.  static fb_data* lcd_backdrop = NULL;
  501.  static long lcd_backdrop_offset IDATA_ATTR = 0;
  502. @@ -57,8 +60,6 @@ static struct viewport default_vp =
  503.  {
  504.      .x        = 0,
  505.      .y        = 0,
  506. -    .width    = LCD_WIDTH,
  507. -    .height   = LCD_HEIGHT,
  508.      .font     = FONT_SYSFIXED,
  509.      .drawmode = DRMODE_SOLID,
  510.      .fg_pattern = LCD_DEFAULT_FG,
  511. @@ -78,6 +79,13 @@ void lcd_init(void)
  512.      /* Call device specific init */
  513.      lcd_init_device();
  514.      scroll_init();
  515. +
  516. +    default_vp.width = LCD_WIDTH;
  517. +    default_vp.height = LCD_HEIGHT;
  518. +#if !defined(HAVE_DYNAMIC_LCD_SIZE) && \
  519. +    (CONFIG_PLATFORM != (PLATFORM_HOSTED|PLATFORM_ANDROID))
  520. +    lcd_framebuffer = &_lcd_framebuffer[0][0];
  521. +#endif
  522.  }
  523.  /*** Viewports ***/
  524.  
  525. @@ -203,7 +211,7 @@ int lcd_getstringsize(const unsigned char *str, int *w, int *h)
  526.  
  527.  /*** low-level drawing functions ***/
  528.  
  529. -#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
  530. +#define LCDADDR(x, y) (lcd_framebuffer + y * LCD_WIDTH + x)
  531.  
  532.  static void ICODE_ATTR setpixel(fb_data *address)
  533.  {
  534. @@ -247,7 +255,7 @@ void lcd_set_backdrop(fb_data* backdrop)
  535.      lcd_backdrop = backdrop;
  536.      if (backdrop)
  537.      {
  538. -        lcd_backdrop_offset = (long)backdrop - (long)&lcd_framebuffer[0][0];
  539. +        lcd_backdrop_offset = (long)backdrop - (long)lcd_framebuffer;
  540.          lcd_fastpixelfuncs = lcd_fastpixelfuncs_backdrop;
  541.      }
  542.      else
  543. diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c
  544. index fc84fdd..9c77c8c 100644
  545. --- a/firmware/drivers/lcd-bitmap-common.c
  546. +++ b/firmware/drivers/lcd-bitmap-common.c
  547. @@ -383,7 +383,7 @@ void LCDFN(puts_scroll_style_xyoffset)(int x, int y, const unsigned char *string
  548.      s->start_tick = current_tick + LCDFN(scroll_info).delay;
  549.      s->style = style;
  550.  
  551. -    strlcpy(s->line, string, sizeof s->line);
  552. +    strlcpy(s->line, string, LCDFN(scroll_info).max_line);
  553.  
  554.      /* get width */
  555.      s->width = LCDFN(getstringsize)(s->line, &w, &h);
  556. diff --git a/firmware/export/config.h b/firmware/export/config.h
  557. index c8531b8..bffe30a 100644
  558. --- a/firmware/export/config.h
  559. +++ b/firmware/export/config.h
  560. @@ -592,6 +592,24 @@ Lyre prototype 1 */
  561.  #define LCD_SPLIT_LINES 0
  562.  #endif
  563.  
  564. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  565. +#define LCD_WIDTH ({extern int lcd_width; lcd_width;})
  566. +#define LCD_HEIGHT ({extern int lcd_height; lcd_height;})
  567. +#ifdef HAVE_REMOTE_LCD
  568. +#error unsupported config (HAVE_REMOTE_LCD && HAVE_DYNAMIC_LCD_SIZE)
  569. +#endif
  570. +#else
  571. +#ifdef DEFAULT_LCD_HEIGHT
  572. +#define LCD_HEIGHT DEFAULT_LCD_HEIGHT
  573. +#endif
  574. +#ifdef DEFAULT_LCD_WIDTH
  575. +#define LCD_WIDTH DEFAULT_LCD_WIDTH
  576. +#endif
  577. +#ifndef MAX_LCD_WIDTH
  578. +#define MAX_LCD_WIDTH LCD_WIDTH
  579. +#endif
  580. +#endif /* HAVE_DYNAMIC_LCD_SIZE */
  581. +
  582.  /* Simulator LCD dimensions. Set to standard dimensions if undefined */
  583.  #ifndef SIM_LCD_WIDTH
  584.  #define SIM_LCD_WIDTH LCD_WIDTH
  585. diff --git a/firmware/export/config/android.h b/firmware/export/config/android.h
  586. index 69a758d..eb1623a 100644
  587. --- a/firmware/export/config/android.h
  588. +++ b/firmware/export/config/android.h
  589. @@ -36,22 +36,14 @@
  590.  /* define this if you would like tagcache to build on this target */
  591.  #define HAVE_TAGCACHE
  592.  
  593. -/* LCD dimensions
  594. - *
  595. - * overriden by configure for application builds */
  596. -#ifndef LCD_WIDTH
  597. -#define LCD_WIDTH  320
  598. -#endif
  599. -
  600. -#ifndef LCD_HEIGHT
  601. -#define LCD_HEIGHT 480
  602. -#endif
  603. -
  604.  #define LCD_DEPTH  16
  605.  #define LCD_PIXELFORMAT 565
  606.  
  607.  #define HAVE_LCD_ENABLE
  608.  
  609. +//#define HAVE_DYNAMIC_LCD_SIZE
  610. +#define MAX_LCD_WIDTH 1024
  611. +
  612.  /* define this to indicate your device's keypad */
  613.  #define HAVE_TOUCHSCREEN
  614.  #define HAVE_BUTTON_DATA
  615. diff --git a/firmware/export/config/sdlapp.h b/firmware/export/config/sdlapp.h
  616. index a55b7e3..43f4c6e 100644
  617. --- a/firmware/export/config/sdlapp.h
  618. +++ b/firmware/export/config/sdlapp.h
  619. @@ -39,13 +39,9 @@
  620.  /* LCD dimensions
  621.   *
  622.   * overriden by configure for application builds */
  623. -#ifndef LCD_WIDTH
  624. -#define LCD_WIDTH  320
  625. -#endif
  626.  
  627. -#ifndef LCD_HEIGHT
  628. -#define LCD_HEIGHT 480
  629. -#endif
  630. +#define HAVE_DYNAMIC_LCD_SIZE
  631. +#define MAX_LCD_WIDTH 1024
  632.  
  633.  #define LCD_DEPTH  16
  634.  #define LCD_PIXELFORMAT 565
  635. diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
  636. index e6e19b1..ea66358 100644
  637. --- a/firmware/export/lcd.h
  638. +++ b/firmware/export/lcd.h
  639. @@ -407,7 +407,7 @@ static inline unsigned lcd_color_to_native(unsigned color)
  640.  #define LCD_FBHEIGHT LCD_HEIGHT
  641.  #endif
  642.  /* The actual framebuffer */
  643. -extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
  644. +extern fb_data *lcd_framebuffer;
  645.  
  646.  /** Port-specific functions. Enable in port config file. **/
  647.  #ifdef HAVE_REMOTE_LCD_AS_MAIN
  648. diff --git a/firmware/export/scroll_engine.h b/firmware/export/scroll_engine.h
  649. index 0fe6fe4..e731e70 100644
  650. --- a/firmware/export/scroll_engine.h
  651. +++ b/firmware/export/scroll_engine.h
  652. @@ -49,7 +49,7 @@ void lcd_remote_scroll_stop_line(const struct viewport* vp, int y);
  653.  struct scrollinfo
  654.  {
  655.      struct viewport* vp;
  656. -    char line[SCROLL_LINE_SIZE];
  657. +    char *line;
  658.  #ifdef HAVE_LCD_CHARCELLS
  659.      int len;    /* length of line in chars */
  660.  #endif
  661. @@ -68,9 +68,10 @@ struct scrollinfo
  662.  
  663.  struct scroll_screen_info
  664.  {
  665. -    struct scrollinfo * const scroll;
  666. +    struct scrollinfo * scroll;
  667.      const int num_scroll; /* number of scrollable lines (also number of scroll structs) */
  668.      int lines;  /* Number of currently scrolling lines */
  669. +    int max_line; /* max chars storable on each scroll line */
  670.      long ticks; /* # of ticks between updates*/
  671.      long delay; /* ticks delay before start */
  672.      int bidir_limit;  /* percent */
  673. diff --git a/firmware/font.c b/firmware/font.c
  674. index 0f9f453..a3e4253 100644
  675. --- a/firmware/font.c
  676. +++ b/firmware/font.c
  677. @@ -31,6 +31,7 @@
  678.  #include <stdlib.h>
  679.  #include "inttypes.h"
  680.  #include "lcd.h"
  681. +#include "buffer.h"
  682.  #include "system.h"
  683.  #include "font.h"
  684.  #include "file.h"
  685. @@ -44,15 +45,7 @@
  686.  
  687.  /* max static loadable font buffer size */
  688.  #ifndef MAX_FONT_SIZE
  689. -#if LCD_HEIGHT > 64
  690. -#if MEMORYSIZE > 2
  691. -#define MAX_FONT_SIZE   60000
  692. -#else
  693. -#define MAX_FONT_SIZE   10000
  694. -#endif
  695. -#else
  696. -#define MAX_FONT_SIZE   4000
  697. -#endif
  698. +#define MAX_FONT_SIZE (LCD_HEIGHT > 64 ? (MEMORYSIZE > 2 ? 60000 : 10000) : 4000)
  699.  #endif
  700.  
  701.  #ifndef FONT_HEADER_SIZE
  702. @@ -77,11 +70,12 @@ extern struct font sysfont;
  703.  /* structure filled in by font_load */
  704.  static struct font font_ui;
  705.  /* static buffer allocation structures */
  706. -static unsigned char main_buf[MAX_FONT_SIZE] CACHEALIGN_ATTR;
  707. +static unsigned char *main_buf CACHEALIGN_ATTR;
  708. +static size_t main_buf_size;
  709.  #ifdef HAVE_REMOTE_LCD
  710.  #define REMOTE_FONT_SIZE 10000
  711.  static struct font remote_font_ui;
  712. -static unsigned char remote_buf[REMOTE_FONT_SIZE] CACHEALIGN_ATTR;
  713. +static unsigned char *remote_buf CACHEALIGN_ATTR;
  714.  #endif
  715.  
  716.  /* system font table, in order of FONT_xxx definition */
  717. @@ -98,8 +92,11 @@ void font_init(void)
  718.      int i = SYSTEMFONTCOUNT;
  719.      while (i<MAXFONTS)
  720.          sysfonts[i++] = NULL;
  721. +    main_buf_size = MAX_FONT_SIZE;
  722. +    main_buf = buffer_alloc(main_buf_size);
  723.      font_reset(NULL);
  724.  #ifdef HAVE_REMOTE_LCD
  725. +    remote_buf = buffer_alloc(REMOTE_FONT_SIZE);
  726.      font_reset(&remote_font_ui);
  727.  #endif
  728.  }
  729. @@ -444,7 +441,7 @@ int font_load(struct font* pf, const char *path)
  730.          /* currently, font loading replaces earlier font allocation*/
  731.          buffer = (unsigned char *)(((intptr_t)main_buf + 3) & ~3);
  732.          /* make sure above doesn't exceed */
  733. -        buffer_size = MAX_FONT_SIZE-3;
  734. +        buffer_size = main_buf_size-3;
  735.      }
  736.      else
  737.      {
  738. diff --git a/firmware/screendump.c b/firmware/screendump.c
  739. index 30b9539..b0a3c19 100644
  740. --- a/firmware/screendump.c
  741. +++ b/firmware/screendump.c
  742. @@ -53,25 +53,44 @@
  743.  #define BMP_DATASIZE   (DUMP_BMP_LINESIZE * (LCD_HEIGHT+LCD_SPLIT_LINES))
  744.  #define BMP_TOTALSIZE  (BMP_HEADERSIZE + BMP_DATASIZE)
  745.  
  746. -static const unsigned char bmpheader[] =
  747. -{
  748. -    0x42, 0x4d,                 /* 'BM' */
  749. -    LE32_CONST(BMP_TOTALSIZE),  /* Total file size */
  750. -    0x00, 0x00, 0x00, 0x00,     /* Reserved */
  751. -    LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
  752. -
  753. -    0x28, 0x00, 0x00, 0x00,     /* Size of (2nd) header */
  754. -    LE32_CONST(LCD_WIDTH),      /* Width in pixels */
  755. -    LE32_CONST(LCD_HEIGHT+LCD_SPLIT_LINES),  /* Height in pixels */
  756. -    0x01, 0x00,                 /* Number of planes (always 1) */
  757. -    LE16_CONST(DUMP_BMP_BPP),   /* Bits per pixel 1/4/8/16/24 */
  758. -    LE32_CONST(BMP_COMPRESSION),/* Compression mode */
  759. -    LE32_CONST(BMP_DATASIZE),   /* Size of bitmap data */
  760. -    0xc4, 0x0e, 0x00, 0x00,     /* Horizontal resolution (pixels/meter) */
  761. -    0xc4, 0x0e, 0x00, 0x00,     /* Vertical resolution (pixels/meter) */
  762. -    LE32_CONST(BMP_NUMCOLORS),  /* Number of used colours */
  763. -    LE32_CONST(BMP_NUMCOLORS),  /* Number of important colours */
  764. -
  765. +#define ASSIGN_LE32(dst, x) memcpy((dst), (unsigned char[4]){LE32_CONST(x)}, 4);
  766. +
  767. +static struct {
  768. +    const unsigned char header[2];
  769. +    unsigned char       file_size[4];
  770. +    const unsigned char reserved[4];
  771. +    unsigned char       header_size[4];
  772. +    const unsigned char second_header_size[4];
  773. +    unsigned char       lcd_width[4];
  774. +    unsigned char       lcd_height[4];
  775. +    const unsigned char nr_planes[2];
  776. +    const unsigned char bpp[2];
  777. +    const unsigned char compression[4];
  778. +    unsigned char       data_size[4];
  779. +    const unsigned char horizontal_resolution[4];
  780. +    const unsigned char vertical_resolution[4];
  781. +    const unsigned char nr_used_colors[4];
  782. +    const unsigned char nr_important_colors[4];
  783. +    const unsigned char colors[BMP_NUMCOLORS*4];
  784. +} __attribute__((__packed__)) bmpheader = {
  785. +    {0x42, 0x4d},                 /* 'BM' */
  786. +    {},                           /* Total file size */
  787. +    {0x00, 0x00, 0x00, 0x00},     /* Reserved */
  788. +    {},                           /* Offset to start of pixel data */
  789. +
  790. +    {0x28, 0x00, 0x00, 0x00},     /* Size of (2nd) header */
  791. +    {},                           /* Width in pixels */
  792. +    {},                           /* Height in pixels */
  793. +    {0x01, 0x00},                 /* Number of planes (always 1) */
  794. +    {LE16_CONST(DUMP_BMP_BPP)},   /* Bits per pixel 1/4/8/16/24 */
  795. +    {LE32_CONST(BMP_COMPRESSION)},/* Compression mode */
  796. +    {},                           /* Size of bitmap data */
  797. +    {0xc4, 0x0e, 0x00, 0x00},     /* Horizontal resolution (pixels/meter) */
  798. +    {0xc4, 0x0e, 0x00, 0x00},     /* Vertical resolution (pixels/meter) */
  799. +    {LE32_CONST(BMP_NUMCOLORS)},  /* Number of used colours */
  800. +    {LE32_CONST(BMP_NUMCOLORS)},  /* Number of important colours */
  801. +
  802. +    {
  803.  #if LCD_DEPTH == 1
  804.  #ifdef HAVE_NEGATIVE_LCD
  805.      BMP_COLOR(LCD_BL_DARKCOLOR),
  806. @@ -94,6 +113,7 @@ static const unsigned char bmpheader[] =
  807.      0xe0, 0x07, 0x00, 0x00,     /* green bitfield mask */
  808.      0x1f, 0x00, 0x00, 0x00,     /* blue bitfield mask */
  809.  #endif
  810. +    }
  811.  };
  812.  
  813.  static void (*screen_dump_hook)(int fh) = NULL;
  814. @@ -136,7 +156,12 @@ void screen_dump(void)
  815.      }
  816.      else
  817.      {
  818. -        write(fd, bmpheader, sizeof(bmpheader));
  819. +        ASSIGN_LE32(bmpheader.file_size, BMP_TOTALSIZE);
  820. +        ASSIGN_LE32(bmpheader.header_size, BMP_HEADERSIZE);
  821. +        ASSIGN_LE32(bmpheader.lcd_width, LCD_WIDTH);
  822. +        ASSIGN_LE32(bmpheader.lcd_height, LCD_HEIGHT+LCD_SPLIT_LINES);
  823. +        ASSIGN_LE32(bmpheader.data_size, BMP_DATASIZE);
  824. +        write(fd, &bmpheader, sizeof(bmpheader));
  825.  
  826.          /* BMP image goes bottom up */
  827.          for (y = LCD_HEIGHT - 1; y >= 0; y--)
  828. @@ -214,7 +239,7 @@ void screen_dump(void)
  829.  #endif
  830.  #elif LCD_DEPTH == 16
  831.              dst_end = dst + LCD_WIDTH;
  832. -            src = lcd_framebuffer[y];
  833. +            src = &lcd_framebuffer[y];
  834.              
  835.              do
  836.              {
  837. diff --git a/firmware/scroll_engine.c b/firmware/scroll_engine.c
  838. index 5dd80f1..5bc71e6 100644
  839. --- a/firmware/scroll_engine.c
  840. +++ b/firmware/scroll_engine.c
  841. @@ -33,6 +33,7 @@
  842.  #ifdef HAVE_REMOTE_LCD
  843.  #include "lcd-remote.h"
  844.  #endif
  845. +#include "buffer.h"
  846.  #include "scroll_engine.h"
  847.  
  848.  static const char scroll_tick_table[16] = {
  849. @@ -45,16 +46,13 @@ static void scroll_thread(void);
  850.  static char scroll_stack[DEFAULT_STACK_SIZE*3];
  851.  static const char scroll_name[] = "scroll";
  852.  
  853. -static struct scrollinfo lcd_scroll[LCD_SCROLLABLE_LINES];
  854.  
  855.  #ifdef HAVE_REMOTE_LCD
  856. -static struct scrollinfo lcd_remote_scroll[LCD_REMOTE_SCROLLABLE_LINES];
  857.  static struct event_queue scroll_queue SHAREDBSS_ATTR;
  858.  #endif
  859.  
  860.  struct scroll_screen_info lcd_scroll_info =
  861.  {
  862. -    .scroll       = lcd_scroll,
  863.      .lines        = 0,
  864.      .ticks        = 12,
  865.      .delay        = HZ/2,
  866. @@ -71,7 +69,6 @@ struct scroll_screen_info lcd_scroll_info =
  867.  #ifdef HAVE_REMOTE_LCD
  868.  struct scroll_screen_info lcd_remote_scroll_info =
  869.  {
  870. -    .scroll       = lcd_remote_scroll,
  871.      .lines        = 0,
  872.      .ticks        = 12,
  873.      .delay        = HZ/2,
  874. @@ -341,6 +338,8 @@ static void scroll_thread(void)
  875.  
  876.  void scroll_init(void)
  877.  {
  878. +    int i;
  879. +    const int max_line = SCROLL_LINE_SIZE;
  880.  #ifdef HAVE_REMOTE_LCD
  881.      queue_init(&scroll_queue, true);
  882.  #endif
  883. @@ -348,5 +347,23 @@ void scroll_init(void)
  884.                    sizeof(scroll_stack), 0, scroll_name
  885.                    IF_PRIO(, PRIORITY_USER_INTERFACE)
  886.                    IF_COP(, CPU));
  887. +
  888. +    struct scrollinfo *lcd_scroll = buffer_alloc(sizeof(struct scrollinfo) *
  889. +                                                 LCD_SCROLLABLE_LINES);
  890. +    lcd_scroll_info.scroll = lcd_scroll;
  891. +    lcd_scroll_info.max_line = max_line;
  892. +
  893. +    for (i = 0; i < LCD_SCROLLABLE_LINES; i++)
  894. +        lcd_scroll[i].line = buffer_alloc(max_line);
  895. +#ifdef HAVE_REMOTE_LCD
  896. +    struct scrollinfo *lcd_remote_scroll;
  897. +    lcd_remote_scroll = buffer_alloc(sizeof(struct scrollinfo) *
  898. +                                     LCD_REMOTE_SCROLLABLE_LINES);
  899. +    lcd_remote_scroll_info.scroll = lcd_remote_scroll;
  900. +    lcd_remote_scroll_info.max_line = max_line;
  901. +
  902. +    for (int i = 0; i < LCD_REMOTE_SCROLLABLE_LINES; i++)
  903. +        lcd_remote_scroll[i].line = buffer_alloc(max_line);
  904. +#endif
  905.  }
  906.  
  907. diff --git a/firmware/target/arm/ipod/video/lcd-video.c b/firmware/target/arm/ipod/video/lcd-video.c
  908. index c499e9f..db7f35e 100644
  909. --- a/firmware/target/arm/ipod/video/lcd-video.c
  910. +++ b/firmware/target/arm/ipod/video/lcd-video.c
  911. @@ -410,7 +410,7 @@ void lcd_update_rect(int x, int y, int width, int height)
  912.      /* Prevent the tick from triggering BCM updates while we're writing. */
  913.      lcd_block_tick();
  914.  
  915. -    addr = &lcd_framebuffer[y][x];
  916. +    addr = (lcd_framebuffer + y * LCD_WIDTH + x);
  917.      bcmaddr = BCMA_CMDPARAM + (LCD_WIDTH*2) * y + (x << 1);
  918.  
  919.      if (width == LCD_WIDTH)
  920. diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
  921. index abde721..757879d 100644
  922. --- a/firmware/target/hosted/android/lcd-android.c
  923. +++ b/firmware/target/hosted/android/lcd-android.c
  924. @@ -30,6 +30,7 @@
  925.  
  926.  extern JNIEnv *env_ptr;
  927.  extern jobject RockboxService_instance;
  928. +extern jclass  RockboxService_class;
  929.  
  930.  static jobject RockboxFramebuffer_instance;
  931.  static jmethodID java_lcd_update;
  932. @@ -40,6 +41,8 @@ static int dpi;
  933.  static int scroll_threshold;
  934.  static bool display_on;
  935.  
  936. +int lcd_width, lcd_height;
  937. +
  938.  /* this might actually be called before lcd_init_device() or even main(), so
  939.   * be sure to only access static storage initalized at library loading,
  940.   * and not more */
  941. @@ -75,11 +78,10 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
  942.  
  943.      /* Create native_buffer */
  944.      jobject buffer = (*env)->NewDirectByteBuffer(env, lcd_framebuffer,
  945. -                                               (jlong) sizeof(lcd_framebuffer));
  946. -
  947. +                            (jlong) (lcd_width * lcd_height * sizeof(fb_data)));
  948.      /* we need to setup parts for the java object every time */
  949. -    (*env)->CallVoidMethod(env, fb_instance, java_lcd_init,
  950. -                          (jint)LCD_WIDTH, (jint)LCD_HEIGHT, buffer);
  951. +    (*env)->CallVoidMethod(env, fb_instance, java_lcd_init, lcd_width,
  952. +                           lcd_height, buffer);
  953.  }
  954.  
  955.  /*
  956. @@ -87,6 +89,19 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
  957.   */
  958.  void lcd_init_device(void)
  959.  {
  960. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  961. +    jmethodID getResolution = (*env_ptr)->GetMethodID(env_ptr, RockboxService_class, "getResolution", "()[I");
  962. +    jintArray resolution = (jintArray) (*env_ptr)->CallObjectMethod(env_ptr, RockboxService_instance, getResolution);
  963. +    jint *resolutionElements = (*env_ptr)->GetIntArrayElements(env_ptr, resolution, NULL);
  964. +
  965. +    lcd_width = resolutionElements[0];
  966. +    lcd_height = resolutionElements[1];
  967. +    (*env_ptr)->ReleaseIntArrayElements(env_ptr, resolution, resolutionElements, 0);
  968. +#else
  969. +    lcd_height = LCD_HEIGHT;
  970. +    lcd_width = LCD_WIDTH;
  971. +#endif
  972. +    lcd_framebuffer = malloc(sizeof(fb_data) * lcd_width * lcd_height);
  973.  }
  974.  
  975.  void lcd_update(void)
  976. @@ -190,6 +205,8 @@ void lcd_yuv_set_options(unsigned options)
  977.      (void)options;
  978.  }
  979.  
  980. +#define LCDADDR(x, y) (lcd_framebuffer + y * LCD_WIDTH + x)
  981. +
  982.  /* Draw a partial YUV colour bitmap - similiar behavior to lcd_blit_yuv
  983.     in the core */
  984.  void lcd_blit_yuv(unsigned char * const src[3],
  985. @@ -205,13 +222,13 @@ void lcd_blit_yuv(unsigned char * const src[3],
  986.      width &= ~1;
  987.      linecounter = height >> 1;
  988.  
  989. -#if LCD_WIDTH >= LCD_HEIGHT
  990. -    dst     = &lcd_framebuffer[y][x];
  991. -    row_end = dst + width;
  992. -#else
  993. -    dst     = &lcd_framebuffer[x][LCD_WIDTH - y - 1];
  994. +    if (LCD_WIDTH >= LCD_HEIGHT) {
  995. +        dst     = LCDADDR(y, x);
  996. +        row_end = dst + width;
  997. +    } else {
  998. +    dst     = LCDADDR(x, LCD_WIDTH - y - 1);
  999.      row_end = dst + LCD_WIDTH * width;
  1000. -#endif
  1001. +    }
  1002.  
  1003.      z    = stride * src_y;
  1004.      ysrc = src[0] + z + src_x;
  1005. @@ -250,11 +267,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1006.  
  1007.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1008.  
  1009. -#if LCD_WIDTH >= LCD_HEIGHT
  1010. -            dst++;
  1011. -#else
  1012. -            dst += LCD_WIDTH;
  1013. -#endif
  1014. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1015. +                dst++;
  1016. +            else
  1017. +                dst += LCD_WIDTH;
  1018.  
  1019.              y = YFAC*(*ysrc++ - 16);
  1020.              r = y + rv;
  1021. @@ -270,11 +286,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1022.  
  1023.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1024.  
  1025. -#if LCD_WIDTH >= LCD_HEIGHT
  1026. -            dst++;
  1027. -#else
  1028. -            dst += LCD_WIDTH;
  1029. -#endif
  1030. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1031. +                dst++;
  1032. +            else
  1033. +                dst += LCD_WIDTH;
  1034.          }
  1035.          while (dst < row_end);
  1036.  
  1037. @@ -282,13 +297,13 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1038.          usrc    -= width >> 1;
  1039.          vsrc    -= width >> 1;
  1040.  
  1041. -#if LCD_WIDTH >= LCD_HEIGHT
  1042. -        row_end += LCD_WIDTH;
  1043. -        dst     += LCD_WIDTH - width;
  1044. -#else
  1045. -        row_end -= 1;
  1046. -        dst     -= LCD_WIDTH*width + 1;
  1047. -#endif
  1048. +        if (LCD_WIDTH >= LCD_HEIGHT) {
  1049. +            row_end += LCD_WIDTH;
  1050. +            dst     += LCD_WIDTH - width;
  1051. +        } else {
  1052. +            row_end -= 1;
  1053. +            dst     -= LCD_WIDTH*width + 1;
  1054. +        }
  1055.  
  1056.          do
  1057.          {
  1058. @@ -315,11 +330,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1059.  
  1060.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1061.  
  1062. -#if LCD_WIDTH >= LCD_HEIGHT
  1063. -            dst++;
  1064. -#else
  1065. -            dst += LCD_WIDTH;
  1066. -#endif
  1067. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1068. +                dst++;
  1069. +            else
  1070. +                dst += LCD_WIDTH;
  1071.  
  1072.              y = YFAC*(*ysrc++ - 16);
  1073.              r = y + rv;
  1074. @@ -335,11 +349,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1075.  
  1076.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1077.  
  1078. -#if LCD_WIDTH >= LCD_HEIGHT
  1079. -            dst++;
  1080. -#else
  1081. -            dst += LCD_WIDTH;
  1082. -#endif
  1083. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1084. +                dst++;
  1085. +            else
  1086. +                dst += LCD_WIDTH;
  1087.          }
  1088.          while (dst < row_end);
  1089.  
  1090. @@ -347,19 +360,18 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1091.          usrc    += stride >> 1;
  1092.          vsrc    += stride >> 1;
  1093.  
  1094. -#if LCD_WIDTH >= LCD_HEIGHT
  1095. -        row_end += LCD_WIDTH;
  1096. -        dst     += LCD_WIDTH - width;
  1097. -#else
  1098. -        row_end -= 1;
  1099. -        dst     -= LCD_WIDTH*width + 1;
  1100. -#endif
  1101. +        if (LCD_WIDTH >= LCD_HEIGHT) {
  1102. +            row_end += LCD_WIDTH;
  1103. +            dst     += LCD_WIDTH - width;
  1104. +        } else {
  1105. +            row_end -= 1;
  1106. +            dst     -= LCD_WIDTH*width + 1;
  1107. +        }
  1108.      }
  1109.      while (--linecounter > 0);
  1110.  
  1111. -#if LCD_WIDTH >= LCD_HEIGHT
  1112. -    lcd_update_rect(x, y, width, height);
  1113. -#else
  1114. -    lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
  1115. -#endif
  1116. +    if (LCD_WIDTH >= LCD_HEIGHT)
  1117. +        lcd_update_rect(x, y, width, height);
  1118. +    else
  1119. +        lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
  1120.  }
  1121. diff --git a/firmware/target/hosted/sdl/lcd-bitmap.c b/firmware/target/hosted/sdl/lcd-bitmap.c
  1122. index 4c29692..239d5a0 100644
  1123. --- a/firmware/target/hosted/sdl/lcd-bitmap.c
  1124. +++ b/firmware/target/hosted/sdl/lcd-bitmap.c
  1125. @@ -30,6 +30,9 @@
  1126.  #endif
  1127.  
  1128.  SDL_Surface* lcd_surface;
  1129. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  1130. +extern int lcd_width, lcd_height;
  1131. +#endif
  1132.  
  1133.  #if LCD_DEPTH <= 8
  1134.  #ifdef HAVE_BACKLIGHT
  1135. @@ -88,6 +91,8 @@ unsigned long (*lcd_ex_getpixel)(int, int) = NULL;
  1136.  static const unsigned char colorindex[4] = {128, 85, 43, 0};
  1137.  #endif
  1138.  
  1139. +#define LCD_PIXEL(x, y) (lcd_framebuffer + y * LCD_WIDTH + x)
  1140. +
  1141.  static unsigned long get_lcd_pixel(int x, int y)
  1142.  {
  1143.  #if LCD_DEPTH == 1
  1144. @@ -113,7 +118,7 @@ static unsigned long get_lcd_pixel(int x, int y)
  1145.  #if   defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
  1146.      return *(&lcd_framebuffer[0][0]+LCD_HEIGHT*x+y);
  1147.  #else
  1148. -    return lcd_framebuffer[y][x];
  1149. +    return *LCD_PIXEL(x, y);
  1150.  #endif
  1151.  #endif
  1152.  #endif
  1153. @@ -140,7 +145,7 @@ void lcd_update_rect(int x_start, int y_start, int width, int height)
  1154.      sdl_update_rect(lcd_surface, x_start, y_start, width, height,
  1155.                      LCD_WIDTH, LCD_HEIGHT, get_lcd_pixel);
  1156.      sdl_gui_update(lcd_surface, x_start, y_start, width,
  1157. -                   height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
  1158. +                   height + LCD_SPLIT_LINES, LCD_WIDTH, LCD_HEIGHT,
  1159.                     background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
  1160.  }
  1161.  
  1162. @@ -168,7 +173,7 @@ void sim_backlight(int value)
  1163.  #endif /* LCD_DEPTH */
  1164.  
  1165.      sdl_gui_update(lcd_surface, 0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
  1166. -                   SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
  1167. +                   LCD_WIDTH, LCD_HEIGHT,
  1168.                     background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
  1169.  }
  1170.  #endif /* HAVE_BACKLIGHT */
  1171. @@ -176,10 +181,14 @@ void sim_backlight(int value)
  1172.  /* initialise simulator lcd driver */
  1173.  void lcd_init_device(void)
  1174.  {
  1175. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  1176. +    lcd_framebuffer = malloc(lcd_width * lcd_height * sizeof(fb_data));
  1177. +#endif
  1178. +
  1179.  #if LCD_DEPTH == 16
  1180.      lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
  1181. -                                       SIM_LCD_WIDTH * display_zoom,
  1182. -                                       SIM_LCD_HEIGHT * display_zoom,
  1183. +                                       LCD_WIDTH * display_zoom,
  1184. +                                       LCD_HEIGHT * display_zoom,
  1185.                                         LCD_DEPTH, 0, 0, 0, 0);
  1186.  #elif LCD_DEPTH <= 8
  1187.      lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
  1188. @@ -217,7 +226,7 @@ void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
  1189.          sdl_update_rect(lcd_surface, x_start, y_start, width, height,
  1190.                          LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
  1191.          sdl_gui_update(lcd_surface, x_start, y_start, width,
  1192. -                       height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
  1193. +                       height + LCD_SPLIT_LINES, LCD_WIDTH, LCD_HEIGHT,
  1194.                         background ? UI_LCD_POSX : 0,
  1195.                         background ? UI_LCD_POSY : 0);
  1196.      }
  1197. @@ -269,13 +278,16 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1198.      width &= ~1;
  1199.      linecounter = height >> 1;
  1200.  
  1201. -#if LCD_WIDTH >= LCD_HEIGHT
  1202. -    dst     = &lcd_framebuffer[y][x];
  1203. -    row_end = dst + width;
  1204. -#else
  1205. -    dst     = &lcd_framebuffer[x][LCD_WIDTH - y - 1];
  1206. -    row_end = dst + LCD_WIDTH * width;
  1207. -#endif
  1208. +    if (LCD_WIDTH >= LCD_HEIGHT)
  1209. +    {
  1210. +        dst     = LCD_PIXEL(x, y);
  1211. +        row_end = dst + width;
  1212. +    }
  1213. +    else
  1214. +    {
  1215. +        dst     = LCD_PIXEL(x, LCD_WIDTH - y - 1);
  1216. +        row_end = dst + LCD_WIDTH * width;
  1217. +    }
  1218.  
  1219.      z    = stride * src_y;
  1220.      ysrc = src[0] + z + src_x;
  1221. @@ -314,11 +326,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1222.  
  1223.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1224.  
  1225. -#if LCD_WIDTH >= LCD_HEIGHT
  1226. -            dst++;
  1227. -#else
  1228. -            dst += LCD_WIDTH;
  1229. -#endif
  1230. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1231. +                dst++;
  1232. +            else
  1233. +                dst += LCD_WIDTH;
  1234.  
  1235.              y = YFAC*(*ysrc++ - 16);
  1236.              r = y + rv;
  1237. @@ -334,11 +345,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1238.  
  1239.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1240.  
  1241. -#if LCD_WIDTH >= LCD_HEIGHT
  1242. -            dst++;
  1243. -#else
  1244. -            dst += LCD_WIDTH;
  1245. -#endif
  1246. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1247. +                dst++;
  1248. +            else
  1249. +                dst += LCD_WIDTH;
  1250.          }
  1251.          while (dst < row_end);
  1252.  
  1253. @@ -346,13 +356,16 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1254.          usrc    -= width >> 1;
  1255.          vsrc    -= width >> 1;
  1256.  
  1257. -#if LCD_WIDTH >= LCD_HEIGHT
  1258. -        row_end += LCD_WIDTH;
  1259. -        dst     += LCD_WIDTH - width;
  1260. -#else
  1261. -        row_end -= 1;
  1262. -        dst     -= LCD_WIDTH*width + 1;
  1263. -#endif
  1264. +        if (LCD_WIDTH >= LCD_HEIGHT)
  1265. +        {
  1266. +            row_end += LCD_WIDTH;
  1267. +            dst     += LCD_WIDTH - width;
  1268. +        }
  1269. +        else
  1270. +        {
  1271. +            row_end -= 1;
  1272. +            dst     -= LCD_WIDTH*width + 1;
  1273. +        }
  1274.  
  1275.          do
  1276.          {
  1277. @@ -379,11 +392,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1278.  
  1279.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1280.  
  1281. -#if LCD_WIDTH >= LCD_HEIGHT
  1282. -            dst++;
  1283. -#else
  1284. -            dst += LCD_WIDTH;
  1285. -#endif
  1286. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1287. +                dst++;
  1288. +            else
  1289. +                dst += LCD_WIDTH;
  1290.  
  1291.              y = YFAC*(*ysrc++ - 16);
  1292.              r = y + rv;
  1293. @@ -399,11 +411,10 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1294.  
  1295.              *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
  1296.  
  1297. -#if LCD_WIDTH >= LCD_HEIGHT
  1298. -            dst++;
  1299. -#else
  1300. -            dst += LCD_WIDTH;
  1301. -#endif
  1302. +            if (LCD_WIDTH >= LCD_HEIGHT)
  1303. +                dst++;
  1304. +            else
  1305. +                dst += LCD_WIDTH;
  1306.          }
  1307.          while (dst < row_end);
  1308.  
  1309. @@ -411,20 +422,22 @@ void lcd_blit_yuv(unsigned char * const src[3],
  1310.          usrc    += stride >> 1;
  1311.          vsrc    += stride >> 1;
  1312.  
  1313. -#if LCD_WIDTH >= LCD_HEIGHT
  1314. -        row_end += LCD_WIDTH;
  1315. -        dst     += LCD_WIDTH - width;
  1316. -#else
  1317. -        row_end -= 1;
  1318. -        dst     -= LCD_WIDTH*width + 1;
  1319. -#endif
  1320. +        if (LCD_WIDTH >= LCD_HEIGHT)
  1321. +        {
  1322. +            row_end += LCD_WIDTH;
  1323. +            dst     += LCD_WIDTH - width;
  1324. +        }
  1325. +        else
  1326. +        {
  1327. +            row_end -= 1;
  1328. +            dst     -= LCD_WIDTH*width + 1;
  1329. +        }
  1330.      }
  1331.      while (--linecounter > 0);
  1332.  
  1333. -#if LCD_WIDTH >= LCD_HEIGHT
  1334. -    lcd_update_rect(x, y, width, height);
  1335. -#else
  1336. -    lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
  1337. -#endif
  1338. +    if (LCD_WIDTH >= LCD_HEIGHT)
  1339. +        lcd_update_rect(x, y, width, height);
  1340. +    else
  1341. +        lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
  1342.  }
  1343.  #endif /* HAVE_LCD_COLOR */
  1344. diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
  1345. index 750a014..bae1e45 100644
  1346. --- a/firmware/target/hosted/sdl/system-sdl.c
  1347. +++ b/firmware/target/hosted/sdl/system-sdl.c
  1348. @@ -61,6 +61,10 @@ char            having_new_lcd = true;      /* Used for player simulator */
  1349.  bool            sim_alarm_wakeup = false;
  1350.  const char     *sim_root_dir = NULL;
  1351.  extern int      display_zoom;
  1352. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  1353. +int             lcd_width = DEFAULT_LCD_WIDTH;
  1354. +int             lcd_height = DEFAULT_LCD_HEIGHT;
  1355. +#endif
  1356.  
  1357.  static SDL_Thread *evt_thread = NULL;
  1358.  
  1359. @@ -287,6 +291,19 @@ void sys_handle_argv(int argc, char *argv[])
  1360.                  background = false;
  1361.                  printf("Disabling background image.\n");
  1362.              }
  1363. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  1364. +            else if (!strcmp("--display", argv[x]))
  1365. +            {
  1366. +                x++;
  1367. +                if(x < argc)
  1368. +                {
  1369. +                    /* <width>x<height> */
  1370. +                    char *xchar = strchr(argv[x], 'x');
  1371. +                    lcd_width = atoi(argv[x]);
  1372. +                    lcd_height = atoi(xchar+1);
  1373. +                }
  1374. +            }
  1375. +#endif
  1376.  #ifdef HAVE_REMOTE_LCD
  1377.              else if (!strcmp("--noremote", argv[x]))
  1378.              {
  1379. @@ -342,6 +359,9 @@ void sys_handle_argv(int argc, char *argv[])
  1380.  #endif
  1381.                  printf("  --debugwps \t Print advanced WPS debug info\n");
  1382.                  printf("  --nobackground \t Disable the background image\n");
  1383. +#ifdef HAVE_DYNAMIC_LCD_SIZE
  1384. +                printf("  --display WIDTHxHEIGHT\t Set the window size\n");
  1385. +#endif
  1386.  #ifdef HAVE_REMOTE_LCD
  1387.                  printf("  --noremote \t Disable the remote image (will disable backgrounds)\n");
  1388.  #endif
  1389. diff --git a/tools/configure b/tools/configure
  1390. index 9f95fec..90ee0f0 100755
  1391. --- a/tools/configure
  1392. +++ b/tools/configure
  1393. @@ -104,8 +104,8 @@ app_set_lcd_size () {
  1394.      ARG_LCDWIDTH=$app_lcd_width
  1395.      ARG_LCDHEIGHT=$app_lcd_height
  1396.  
  1397. -    app_lcd_width="#define LCD_WIDTH $app_lcd_width"
  1398. -    app_lcd_height="#define LCD_HEIGHT $app_lcd_height"
  1399. +    app_lcd_width="#define DEFAULT_LCD_WIDTH $app_lcd_width"
  1400. +    app_lcd_height="#define DEFAULT_LCD_HEIGHT $app_lcd_height"
  1401.  }
  1402.  
  1403.  findarmgcc() {