Index: apps/settings.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.c,v
retrieving revision 1.408
diff -u -u -r1.408 settings.c
--- apps/settings.c	22 Aug 2006 09:10:17 -0000	1.408
+++ apps/settings.c	22 Aug 2006 15:03:13 -0000
@@ -321,6 +321,13 @@
 #endif
 #endif /* CONFIG_BACKLIGHT */
 
+#ifdef HAVE_RECORDING
+#if defined(HAVE_LCD_BITMAP) && (LCD_WIDTH > 111)
+    {2, S_O(rec_histogram_mode), 1, "histogram mode", NULL},
+    {2, S_O(rec_histogram_interval), 0, "histogram interval", "0.5s,1s,2s,4s"},
+#endif
+#endif /* HAVE_RECORDING */
+
     /* new stuff to be added here */
     /* If values are just added to the end, no need to bump the version. */
 
Index: apps/settings.h
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.h,v
retrieving revision 1.233
diff -u -u -r1.233 settings.h
--- apps/settings.h	16 Aug 2006 23:26:54 -0000	1.233
+++ apps/settings.h	22 Aug 2006 15:03:13 -0000
@@ -200,6 +200,11 @@
     int rec_agc_cliptime;     /* 0.2, 0.4, 0.6, 0.8, 1s */
 #endif
 
+#if defined(HAVE_LCD_BITMAP) && (LCD_WIDTH > 111)
+    int rec_histogram_mode;     /* small lin/log /w balance, big lin/log */
+    int rec_histogram_interval; /* interval: 0.5s, 1s, 2s, 4s */
+#endif
+
     /* device settings */
 
 #ifdef HAVE_LCD_CONTRAST
Index: apps/sound_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/sound_menu.c,v
retrieving revision 1.108
diff -u -u -r1.108 sound_menu.c
--- apps/sound_menu.c	16 Aug 2006 23:26:54 -0000	1.108
+++ apps/sound_menu.c	22 Aug 2006 15:03:14 -0000
@@ -551,6 +551,22 @@
                       INT, names, 5, NULL );
 }
 #endif /* HAVE_AGC */
+
+#if LCD_HEIGHT > 111
+static bool history_interval(void)
+{
+    static const struct opt_items names[] = {
+        { "0.5s", TALK_ID(500, UNIT_MS) },
+        { "1s", TALK_ID(1, UNIT_SEC) },
+        { "2s", TALK_ID(2, UNIT_SEC) },
+        { "4s", TALK_ID(4, UNIT_SEC) }
+    };
+    return set_option(str(LANG_RECORDING_HISTOGRAM_INTERVAL),
+                      &global_settings.rec_histogram_interval,
+                      INT, names, 4, NULL );
+}
+#endif /* LCD_HEIGHT > 111 */
+
 #endif /* HAVE_RECORDING */
 
 static bool chanconf(void)
@@ -1050,6 +1066,10 @@
     items[i].desc = ID2P(LANG_RECORD_TRIGGER);
     items[i++].function = rectrigger;
 #endif
+#if LCD_HEIGHT > 111
+    items[i].desc = ID2P(LANG_RECORDING_HISTOGRAM_INTERVAL);
+    items[i++].function = history_interval;
+#endif
 #ifdef HAVE_AGC
     items[i].desc = ID2P(LANG_RECORD_AGC_PRESET);
     items[i++].function = agc_preset;
Index: apps/lang/deutsch.lang
===================================================================
RCS file: /cvsroot/rockbox/apps/lang/deutsch.lang,v
retrieving revision 1.103
diff -u -u -r1.103 deutsch.lang
--- apps/lang/deutsch.lang	18 Aug 2006 08:53:41 -0000	1.103
+++ apps/lang/deutsch.lang	22 Aug 2006 15:03:14 -0000
@@ -9045,3 +9045,73 @@
     *: ""
   </voice>
 </phrase>
+<phrase>
+  id: LANG_RECORDING_HISTOGRAM_INTERVAL
+  desc: in record settings menu
+  user:
+  <source>
+    *: "Histogram interval"
+  </source>
+  <dest>
+    *: "Histogramm Abstand"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_DISKSPACE_LOW
+  desc: in recording screen
+  user:
+  <source>
+    *: "WARNING! Low Disk-Space!"
+  </source>
+  <dest>
+    *: "WARNUNG! Festplatte fast voll!"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_DISK_FULL
+  desc: in recording screen
+  user:
+  <source>
+    *: "Disk is full!"
+  </source>
+  <dest>
+    *: "Festplatte ist voll!"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_STOP_RECORDING
+  desc: in recording screen
+  user:
+  <source>
+    *: "Stopping Recording..."
+  </source>
+  <dest>
+    *: "Stoppe Aufnahme..."
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_BATTERY_LOW
+  desc: general warning
+  user:
+  <source>
+    *: "WARNING! Low Battery!"
+  </source>
+  <dest>
+    *: "WARNUNG! Batterie fast leer!"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
Index: apps/lang/english.lang
===================================================================
RCS file: /cvsroot/rockbox/apps/lang/english.lang,v
retrieving revision 1.271
diff -u -u -r1.271 english.lang
--- apps/lang/english.lang	18 Aug 2006 11:18:32 -0000	1.271
+++ apps/lang/english.lang	22 Aug 2006 15:03:15 -0000
@@ -9778,3 +9778,73 @@
     *: "pixels"
   </voice>
 </phrase>
+<phrase>
+  id: LANG_RECORDING_HISTOGRAM_INTERVAL
+  desc: in record settings menu
+  user:
+  <source>
+    *: "Histogram interval"
+  </source>
+  <dest>
+    *: "Histogram interval"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_DISKSPACE_LOW
+  desc: in recording screen
+  user:
+  <source>
+    *: "WARNING! Low Disk-Space!"
+  </source>
+  <dest>
+    *: "WARNING! Low Disk-Space!"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_DISK_FULL
+  desc: in recording screen
+  user:
+  <source>
+    *: "Disk is full!"
+  </source>
+  <dest>
+    *: "Disk is full!"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_STOP_RECORDING
+  desc: in recording screen
+  user:
+  <source>
+    *: "Stopping Recording..."
+  </source>
+  <dest>
+    *: "Stopping Recording..."
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WARNING_BATTERY_LOW
+  desc: general warning
+  user:
+  <source>
+    *: "WARNING! Low Battery!"
+  </source>
+  <dest>
+    *: "WARNING! Low Battery!"
+  </dest>
+  <voice>
+    *: ""
+  </voice>
+</phrase>
Index: apps/recorder/peakmeter.c
===================================================================
RCS file: /cvsroot/rockbox/apps/recorder/peakmeter.c,v
retrieving revision 1.41
diff -u -u -r1.41 peakmeter.c
--- apps/recorder/peakmeter.c	20 Aug 2006 21:33:40 -0000	1.41
+++ apps/recorder/peakmeter.c	22 Aug 2006 15:03:15 -0000
@@ -865,6 +865,9 @@
     int meterwidth = width - 3;
     int i;
 
+    /* store max peak value for peak_meter_get_peakhold_x readout */
+    pm_peakhold_left = MAX(pm_max_left, pm_peakhold_left);
+
 #ifdef PM_DEBUG
     static long pm_tick = 0;
     int tmp = peek_calls;
@@ -1036,6 +1039,9 @@
     }
 #endif /*HAVE_RECORDING*/
 
+    /* store max peak value for peak_meter_get_peakhold_x readout */
+    pm_peakhold_right = MAX(pm_max_right, pm_peakhold_right);
+
 #ifdef PM_DEBUG
     /* display a bar to show how many calls to peak_meter_peek 
        have ocurred since the last display */
Index: apps/recorder/recording.c
===================================================================
RCS file: /cvsroot/rockbox/apps/recorder/recording.c,v
retrieving revision 1.127
diff -u -u -r1.127 recording.c
--- apps/recorder/recording.c	20 Aug 2006 21:33:40 -0000	1.127
+++ apps/recorder/recording.c	22 Aug 2006 15:03:15 -0000
@@ -65,6 +65,10 @@
 #include "ata.h"
 #include "splash.h"
 #include "screen_access.h"
+#include "fat.h"
+#include "power.h"
+#include "powermgmt.h"
+#include "backlight.h"
 #include "action.h"
 #ifdef HAVE_RECORDING
 
@@ -88,7 +92,13 @@
 #define REC_FILE_ENDING ".mp3"
 #endif
 
+#if defined(HAVE_LCD_BITMAP) && (LCD_HEIGHT > 111)
+#define HAVE_HISTOGRAM /* only for bigger screens */
+#endif
+
 #define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
+#define MIN_DISK_SPACE 48        /* minimum remaining disk space */
+unsigned long disk_space = 0;
 
 int screen_update = NB_SCREENS;
 bool remote_display_on = true;
@@ -159,6 +169,44 @@
 static short agc_maxgain;
 #endif /* HAVE_AGC */
 
+/* Histogram data, only for bigger screens */
+#ifdef HAVE_HISTOGRAM
+#define HIST_Y (LCD_HEIGHT - 1)
+#define HIST_W (LCD_WIDTH / 2 - 4)
+static short history_mode;
+static short hist_time_interval = 1; /* 1, 2, 4, 8 */
+static int hist_l = 0;
+static int hist_r = 0;
+static unsigned char history_l[HIST_W];
+static unsigned char history_r[HIST_W];
+#if LCD_DEPTH > 1
+#ifdef HAVE_LCD_COLOR
+#define LCD_BATT_OK LCD_RGBPACK(63, 63, 63)
+#define LCD_BATT_LO LCD_RGBPACK(159, 0, 0)
+#define LCD_DISK_OK LCD_RGBPACK(0, 0, 143)
+#define LCD_DISK_LO LCD_RGBPACK(127, 0, 0)
+#define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
+#define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
+#define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
+#define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
+#define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
+#else
+#define LCD_BATT_OK LCD_BLACK
+#define LCD_BATT_LO LCD_DARKGRAY
+#define LCD_DISK_OK LCD_BLACK
+#define LCD_DISK_LO LCD_DARKGRAY
+#define LCD_HIST_OVER LCD_BLACK
+#define LCD_HIST_OK LCD_DARKGRAY
+#define LCD_BAL LCD_DARKGRAY
+#endif
+#else
+#define LCD_HIST_OVER LCD_DEFAULT_FG
+#define LCD_HIST_OK LCD_DEFAULT_FG
+#define LCD_BAL LCD_DEFAULT_FG
+#endif
+#endif /* HAVE_HISTOGRAM */
+
+
 static void set_gain(void)
 {
     if(global_settings.rec_source == SOURCE_MIC)
@@ -204,6 +252,13 @@
         *balance += balance_mem[i];
     *balance = *balance / BAL_MEM_SIZE;
 
+    #ifdef HAVE_HISTOGRAM
+    if (*peak_l > hist_l)
+        hist_l = *peak_l;
+    if (*peak_r > hist_r)
+        hist_r = *peak_r;
+    #endif
+
     return true;
 }
 
@@ -437,8 +492,25 @@
 {
     int max_cursor;
     
-    if(cursor < 0)
+    if(cursor < 0) {
         cursor = 0;
+#ifdef HAVE_HISTOGRAM
+        int i;
+        history_mode++;
+        if (history_mode == 2) {
+            for (i=0; i < HIST_W; i++) {
+                history_l[i] = history_l[i] * 2;
+                history_r[i] = history_r[i] * 2;
+            }
+        } else if (history_mode == 4) {
+            for (i=0; i < HIST_W; i++) {
+                history_l[i] = history_l[i] / 2;
+                history_r[i] = history_r[i] / 2;
+            }
+            history_mode = 0;
+        }
+#endif
+    }
 
 #ifdef HAVE_AGC
     switch(global_settings.rec_source)
@@ -573,6 +645,11 @@
     int w, h;
     int update_countdown = 1;
     bool have_recorded = false;
+    bool disk_was_active = false;
+    bool warn_message = true;
+    unsigned long disk_free;
+    int bitrate;
+    int disk_time;
     unsigned int seconds;
     int hours, minutes;
     char path_buffer[MAX_PATH];
@@ -603,6 +680,60 @@
         ID2P(LANG_GIGABYTE)
     };
 
+    memset(balance_mem, 0x00, BAL_MEM_SIZE);
+
+#ifdef HAVE_HISTOGRAM
+    int history_pos = 0;
+    int hist_height;
+    const short hist_size_h[2] = {17, 31};
+    /* 
+     * Peak histogram linear to logarithmic [dB] table.
+     * The thresholds are scaled between the corresponding
+     * dispayed values, e.g. -6dB is -5.5dB < level <= 6.5dB
+     */
+    const short hist_peak_lin2dB[2][31] =
+    {
+        /* Clip,  0,    -2,    -4,    -6,    -8,    -10 */
+        { 32767, 28539, 23197, 18427, 14637, 11627, 9236,
+        /* -12, -14,  -16,  -18,  -20,  -24,  -30, -36, -48, -inf */
+          7336, 5828, 4629, 3677, 2602, 1642, 734, 328, 104, 0 },
+        /* Clip,  0,    -1,    -2,    -3,    -4,    -5,    -6,    -7,    -8 */
+        { 32767, 30579, 27569, 24573, 21901, 19519, 17397, 15505, 13819, 12316,
+        /* -9,   -10,  -11,  -12,  -13,  -14,  -15,  -16,  -18,  -20,  -22 */
+          10977, 9783, 8719, 7771, 6926, 6173, 5502, 4629, 3677, 2921, 2320,
+        /* -24, -27,  -30, -33, -36, -39, -42, -48, -60, -inf */
+          1842, 1232, 872, 618, 437, 310, 207, 124, 33, 0 }
+    };
+    const char hist_level_marks[4][6] =
+    {
+        /* linear: 0, -6, -12, -24, -inf [dB] */
+        { 15,  8, 4, 1, 0, 0},
+        /* logarithmic: 0, -6, -12, -24, -48 [dB] */
+        { 15, 12, 9, 4, 1, 1},
+        /* linear: 0, -3, -6, -12, -24, -inf [dB] */
+        { 29, 21, 15,  7, 2, 0},
+        /* logarithmic: 0, -3, -6, -12, -24, -48 [dB] */
+        { 29, 26, 23, 17, 9, 2}
+    };
+    const short hist_balance_marks[12] =
+    /* -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6 */
+    {-4988, -4377, -3690, -2920, -2057, -1087,
+      1087,  2057,  2920,  3690,  4377,  4988};
+
+    const unsigned char rec_icons_6x8[][6] =
+    {
+        {0x00,0x1c,0x3e,0x36,0x3e,0x1c}
+    };
+    enum icons_6x8
+    {
+        Icon_Disk,
+        Icon_6x8end
+    };
+
+    memset(history_l, 0x00, sizeof(history_l));
+    memset(history_r, 0x00, sizeof(history_r));
+#endif /* HAVE_HISTOGRAM */
+
     cursor = 0;
 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
     ata_set_led_enabled(false);
@@ -614,6 +745,8 @@
     audio_init_recording(0);
 #endif
 
+    gui_syncsplash(1, true, "%s...", str(LANG_RECORDING));
+
     sound_set_volume(global_settings.volume);
 
 #if CONFIG_CODEC == SWCODEC
@@ -695,6 +828,19 @@
         gui_syncsplash(0, true, str(LANG_REMOTE_LCD_OFF));
     }
 
+    /* store the free disk space for this session [MBytes] */
+    fat_size(IF_MV2(0,) NULL, &disk_free); /* free KBytes */
+    disk_free = disk_free / 1024;
+    if (disk_free > disk_space)
+        disk_space = disk_free;
+    bitrate = 1411; /* [kbps] default for 44kHz stereo 16bit WAV */
+
+#ifdef HAVE_HISTOGRAM
+    history_mode = global_settings.rec_histogram_mode;
+    hist_time_interval = 1 << global_settings.rec_histogram_interval;
+#endif
+
+
     while(!done)
     {
 #if CONFIG_CODEC == SWCODEC        
@@ -1047,6 +1193,9 @@
                     adjust_cursor();
                     set_gain();
                     update_countdown = 1; /* Update immediately */
+#ifdef HAVE_HISTOGRAM
+                    hist_time_interval = 1 << global_settings.rec_histogram_interval;
+#endif
 
                     FOR_NB_SCREENS(i)
                     {
@@ -1128,8 +1277,11 @@
             auto_gain_control(&peak_l, &peak_r, &balance);
 #endif
 
-            FOR_NB_SCREENS(i)       
-                screens[i].setfont(FONT_SYSFIXED);
+        peak_read = !peak_read;
+        if (peak_read) {
+            peak_time++;
+            peak_valid = read_peak_levels(&peak_l, &peak_r, &balance);
+        }
 
         seconds = audio_recorded_time() / HZ;
         
@@ -1143,7 +1295,15 @@
 
             update_countdown = 5;
             last_seconds = seconds;
-
+            
+            /* Get free disk space and calculate remain time */
+            fat_size( IF_MV2(0,) NULL, &disk_free ); /* [KBytes] */
+            disk_free  = disk_free / 1024;
+            if (disk_free < MIN_DISK_SPACE)
+                disk_free = MIN_DISK_SPACE;
+            disk_free -= MIN_DISK_SPACE;
+            disk_time = 140 * (int)disk_free / bitrate; /* rough estimation */
+            
             dseconds = rec_timesplit_seconds();
             dsize = rec_sizesplit_bytes();
             num_recorded_bytes = audio_num_recorded_bytes();
@@ -1317,6 +1477,202 @@
                 }                
             }
 
+#ifdef HAVE_HISTOGRAM
+            /* Draw histogram graphs (on main unit only).
+             * 4 modes: low size linear or logarithmic histogram with
+             * disk space usage, battery level and balance meter or
+             * high size linear or logarithmic peak histogram.
+             */
+#define HIST_BAL_X (LCD_WIDTH/2 + 4)
+#define HIST_BAL_W (LCD_WIDTH/2 - 5)
+#define BAL_MAX_R 4988
+#define BAL_MAX_L (-BAL_MAX_R * (HIST_BAL_W/2 + 1) / (HIST_BAL_W/2))
+            int hist_bal_y = HIST_Y - hist_size_h[history_mode/2] - 11;
+
+            if (hist_bal_y > (8 + 8 * h))
+            {
+                lcd_setfont(FONT_SYSFIXED);
+                lcd_set_drawmode(DRMODE_FG);
+#if LCD_DEPTH > 1
+                if (battery_level() > 10)
+                    lcd_set_foreground(LCD_BATT_OK);
+                else
+                    lcd_set_foreground(LCD_BATT_LO);
+#else
+                lcd_set_foreground(LCD_DEFAULT_FG);
+#endif /* LCD_DEPTH > 1 */
+                lcd_fillrect(0, hist_bal_y,
+                             (30 * battery_level() + 60) / 100, 9);
+#if LCD_DEPTH > 1
+                if (disk_time > 59)
+                    lcd_set_foreground(LCD_DISK_OK);
+                else
+                    lcd_set_foreground(LCD_DISK_LO);
+#endif /* LCD_DEPTH > 1 */
+                if ((LCD_WIDTH/2 - 36)*(disk_space-disk_free-3) / disk_space)
+                    lcd_fillrect(35, hist_bal_y, (LCD_WIDTH/2 - 37) *
+                             (disk_space - disk_free - 1) / disk_space, 9);
+                lcd_set_drawmode(DRMODE_COMPLEMENT);
+                lcd_set_foreground(LCD_DEFAULT_FG);
+                if (charger_inserted())
+                    lcd_mono_bitmap(bitmap_icons_7x8[Icon_Plug],
+                                    2 + 19*(battery_level() > 48),
+                                    hist_bal_y + 1, 7, 8);
+                if (battery_time() > 90)
+                    snprintf(buf, 32, "%dh", (battery_time() + 10) / 60);
+                else
+                    snprintf(buf,32, "%dm", battery_time());
+                if (battery_level() > 48)
+                    i = 1;
+                else if ((battery_time() < 590) && (battery_time() > 90))
+                    i = 15;
+                else
+                    i = 10;
+                lcd_putsxy(i, hist_bal_y + 1, buf);
+                if (disk_time > 90)
+                    snprintf(buf, 32, "%dh", (disk_time + 10) / 60);
+                else
+                    snprintf(buf, 32, "%dm", disk_time);
+                i = ((disk_time < 91) || (disk_time > 589))? 30:26;
+                if ((hist_time % 2) || !ata_disk_is_active())
+                    lcd_mono_bitmap(rec_icons_6x8[Icon_Disk],
+                                    LCD_WIDTH/2 - 11,
+                                    hist_bal_y + 1, 6, 8);
+                lcd_putsxy((5*disk_free > 3*disk_space) ?
+                           (LCD_WIDTH/2 - i) : 37,
+                           hist_bal_y + 1, buf);
+                lcd_drawrect(34, hist_bal_y - 1, LCD_WIDTH/2 - 36, 11);
+                lcd_set_drawmode(DRMODE_SOLID);
+                lcd_drawrect(0, hist_bal_y - 1, 30, 11);
+                lcd_vline(30, hist_bal_y + 2, hist_bal_y + 6);
+                lcd_vline(31, hist_bal_y + 2, hist_bal_y + 6);
+
+                int bal;
+                lcd_drawrect(HIST_BAL_X-2, hist_bal_y-1, HIST_BAL_W+3, 11);
+                lcd_hline(HIST_BAL_X + HIST_BAL_W/2 - 1,
+                          HIST_BAL_X + HIST_BAL_W/2 + 1,
+                          hist_bal_y - 2);
+                lcd_hline(HIST_BAL_X + HIST_BAL_W/2 - 1,
+                          HIST_BAL_X + HIST_BAL_W/2 + 1,
+                          hist_bal_y + 10);
+                lcd_set_drawmode(DRMODE_FG);
+#ifndef HAVE_LCD_COLOR
+                lcd_set_foreground(LCD_BAL);
+#endif
+                for (i = 0; i < BAL_MEM_SIZE; i++) {
+                    bal = MIN(balance_mem[i], BAL_MAX_R);
+                    bal = MAX(bal, BAL_MAX_L);
+#ifdef HAVE_LCD_COLOR
+                    if (bal > 142)
+                        lcd_set_foreground(LCD_BAL_L);
+                    else if (bal < 142)
+                        lcd_set_foreground(LCD_BAL_R);
+                    else
+                        lcd_set_foreground(LCD_DARKGRAY);
+#endif
+                    lcd_vline(HIST_BAL_X + HIST_BAL_W/2 +
+                              HIST_BAL_W * bal / 9976,
+                              hist_bal_y + 1, hist_bal_y + 7);
+                }
+                lcd_set_foreground(LCD_BLACK);
+                bal = MAX(balance, BAL_MAX_L);
+                bal = MIN(bal, BAL_MAX_R);
+                lcd_fillrect(HIST_BAL_X-1 + HIST_BAL_W/2 +
+                             HIST_BAL_W * bal / 9976,
+                             hist_bal_y, 3, 9);
+                lcd_drawpixel(HIST_BAL_X + HIST_BAL_W/2, hist_bal_y + 4);
+                lcd_set_drawmode(DRMODE_COMPLEMENT);
+                lcd_drawpixel(HIST_BAL_X + HIST_BAL_W/2, hist_bal_y - 1);
+                lcd_drawpixel(HIST_BAL_X + HIST_BAL_W/2, hist_bal_y + 9);
+                for (i = 0; i < 12; i++)
+                    lcd_drawpixel(HIST_BAL_X + HIST_BAL_W/2 +
+                                  HIST_BAL_W * hist_balance_marks[i] / 9976,
+                                  hist_bal_y + 4);
+            }
+
+            hist_height = hist_size_h[history_mode/2] - 1;
+            if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
+            {
+                if (history_mode % 2) {
+                    i = 0;
+                    while (hist_l < hist_peak_lin2dB[history_mode / 2][i])
+                        i++;
+                    history_l[history_pos] = hist_height - i;
+                    i = 0;
+                    while (hist_r < hist_peak_lin2dB[history_mode / 2][i])
+                        i++;
+                    history_r[history_pos] = hist_height - i;
+                } else {
+                    history_l[history_pos] = hist_l * hist_height / 32767;
+                    history_r[history_pos] = hist_r * hist_height / 32767;
+                }
+                history_pos = (history_pos + 1) % HIST_W;
+                history_l[history_pos] = history_r[history_pos] = 0;
+                history_l[(history_pos + 1) % HIST_W] = 0;
+                history_r[(history_pos + 1) % HIST_W] = 0;
+                hist_l = 0;
+                hist_r = 0;
+            }
+            lcd_set_drawmode(DRMODE_SOLID);
+            lcd_drawrect(0, HIST_Y - hist_height,
+                         HIST_W + 2, hist_height + 1);
+            lcd_drawrect(HIST_W + 6, HIST_Y - hist_height,
+                         HIST_W + 2, hist_height + 1);
+            lcd_set_drawmode(DRMODE_FG);
+#ifdef HAVE_LCD_COLOR
+            for (i = 0; i < HIST_W; i++) {
+                if (history_l[i]) {
+                    if (history_l[i] == hist_height)
+                        lcd_set_foreground(LCD_HIST_OVER);
+                    else if (history_l[i] > hist_level_marks[history_mode][1])
+                        lcd_set_foreground(LCD_HIST_HI);
+                    else
+                        lcd_set_foreground(LCD_HIST_OK);
+                    lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[i]);
+                }
+                if (history_r[i]) {
+                    if (history_r[i] == hist_height)
+                        lcd_set_foreground(LCD_HIST_OVER);
+                    else if (history_r[i] > hist_level_marks[history_mode][1])
+                        lcd_set_foreground(LCD_HIST_HI);
+                    else
+                        lcd_set_foreground(LCD_HIST_OK);
+                    lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[i]);
+                }
+            }
+#else
+            for (i = 0; i < HIST_W; i++) {
+                if (history_l[i]) {
+                    if (history_l[i] == hist_height)
+                        lcd_set_foreground(LCD_HIST_OVER);
+                    else
+                        lcd_set_foreground(LCD_HIST_OK);
+                    lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[i]);
+                }
+                if (history_r[i]) {
+                    if (history_r[i] == hist_height)
+                        lcd_set_foreground(LCD_HIST_OVER);
+                    else
+                        lcd_set_foreground(LCD_HIST_OK);
+                    lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[i]);
+                }
+            }
+            lcd_set_foreground(LCD_WHITE);
+            for (i = 0; i < HIST_W; i++) {
+                if (history_l[i] == hist_height)
+                    lcd_drawpixel(1 + i, HIST_Y - 1);
+                if (history_r[i] == hist_height)
+                    lcd_drawpixel(HIST_W + 7 + i, HIST_Y - 1);
+            }
+#endif /* HAVE_LCD_COLOR */
+            lcd_set_foreground(LCD_DEFAULT_FG);
+            for (i = 0; i < 6; i++)
+                lcd_hline(HIST_W + 3, HIST_W + 4,
+                          HIST_Y - hist_level_marks[history_mode][i]);
+#endif /* HAVE_HISTOGRAM */
+
+            hist_time++;
+
             FOR_NB_SCREENS(i)
             {
                 if (global_settings.rec_source == SOURCE_LINE)
@@ -1500,6 +1856,49 @@
                                     TRIG_WIDTH + 2, TRIG_HEIGHT);
                 }
             }
+
+            /* check battery level & free disk space */
+            if (ata_disk_is_active())
+                disk_was_active = true;
+            else if (disk_was_active)
+            {
+                lcd_setfont(FONT_UI);
+                if (disk_time == 0) {
+                    backlight_on();
+#ifdef HAVE_REMOTE_LCD
+                    remote_backlight_on();
+#endif
+                    if (audio_stat & AUDIO_STATUS_RECORD) {
+                        gui_syncsplash(HZ, true, "%s %s",
+                            str(LANG_WARNING_DISK_FULL),
+                            str(LANG_WARNING_STOP_RECORDING));
+                        audio_stop_recording();
+                    }
+                    else {
+                        gui_syncsplash(2*HZ, true,
+                            str(LANG_WARNING_DISK_FULL));
+                    }
+                }
+                else if (warn_message && (battery_level() < 10)) {
+                    backlight_on();
+#ifdef HAVE_REMOTE_LCD
+                    remote_backlight_on();
+#endif
+                    gui_syncsplash(3*HZ, true,
+                        str(LANG_WARNING_BATTERY_LOW));
+                }
+                else if (!warn_message && (disk_free < 512)) {
+                    backlight_on();
+#ifdef HAVE_REMOTE_LCD
+                    remote_backlight_on();
+#endif
+                    gui_syncsplash(3*HZ, true,
+                        str(LANG_WARNING_DISKSPACE_LOW));
+                }
+                lcd_setfont(FONT_SYSFIXED);
+                warn_message = !warn_message;
+                disk_was_active  = false;
+            }
         }
 
         if(audio_stat & AUDIO_STATUS_ERROR)
@@ -1556,6 +1955,10 @@
     if (have_recorded)
         reload_directory();
 
+#ifdef HAVE_HISTOGRAM
+    global_settings.rec_histogram_mode = history_mode;
+#endif
+
 #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
     ata_set_led_enabled(true);
 #endif
