Index: settings.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.c,v
retrieving revision 1.37
diff -u -b -r1.37 settings.c
--- settings.c	26 Aug 2002 13:21:13 -0000	1.37
+++ settings.c	27 Aug 2002 06:30:31 -0000
@@ -69,6 +69,8 @@
 0x11    0x25    <AVC byte>
 0x12    0x26    <(int) Resume playlist index, or -1 if no playlist resume>
 0x16    0x2b    <(int) Byte offset into resume file>
+0x1a    0x2f    <disk spindown byte>
+0x1b    0x30    <(int) index of last song played in shuffle mode>
 
         <all unused space filled with 0xff>
 
@@ -274,6 +276,8 @@
     memcpy(&config_block[0x16], &global_settings.resume_offset, 4);
     memcpy(&config_block[0xF8], &global_settings.resume_seed, 4);
 
+    memcpy(&config_block[0x1b], &global_settings.last_shuffled_index, 4);
+
     memcpy(&config_block[0x24], &global_settings.total_uptime, 4);
     strncpy(&config_block[0xFC], global_settings.resume_file, MAX_PATH);
     
@@ -373,6 +377,9 @@
         if (config_block[0x1a] != 0xFF)
             global_settings.disk_spindown = config_block[0x1a];
 
+        if (config_block[0x1b] != 0xFF)
+            memcpy(&global_settings.last_shuffled_index, &config_block[0x1b], 4);
+
         memcpy(&global_settings.resume_seed, &config_block[0xF8], 4);
 
         if (config_block[0x24] != 0xFF)
@@ -422,6 +429,7 @@
     global_settings.resume_index = -1;
     global_settings.resume_offset = -1;
     global_settings.disk_spindown = 5;
+    global_settings.last_shuffled_index = 0;
 }
 
 
Index: settings.h
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.h,v
retrieving revision 1.28
diff -u -b -r1.28 settings.h
--- settings.h	26 Aug 2002 13:21:14 -0000	1.28
+++ settings.h	27 Aug 2002 06:30:31 -0000
@@ -52,6 +52,7 @@
 
     int resume;        /* resume option: 0=off, 1=ask, 2=on */
     int resume_index;  /* index in playlist (-1 for no active resume) */
+    int last_shuffled_index;  /* index of last song played in shuffle mode */
     int resume_offset; /* byte offset in mp3 file */
     int resume_seed;   /* random seed for playlist shuffle */
     unsigned char resume_file[MAX_PATH+1]; /* playlist name (or dir) */
Index: settings_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings_menu.c,v
retrieving revision 1.31
diff -u -b -r1.31 settings_menu.c
--- settings_menu.c	26 Aug 2002 13:21:14 -0000	1.31
+++ settings_menu.c	27 Aug 2002 06:30:31 -0000
@@ -213,7 +213,8 @@
     {
         if (global_settings.playlist_shuffle)
         {
-            randomise_playlist(current_tick);
+            randomise_playlist(global_settings.resume_seed);
+            playlist.index = global_settings.last_shuffled_index;
         }
         else
         {
Index: tree.c
===================================================================
RCS file: /cvsroot/rockbox/apps/tree.c,v
retrieving revision 1.102
diff -u -b -r1.102 tree.c
--- tree.c	26 Aug 2002 13:21:14 -0000	1.102
+++ tree.c	27 Aug 2002 06:30:32 -0000
@@ -517,7 +517,6 @@
                     lcd_stop_scroll();
                     if(dircache[dircursor+start].attr & TREE_ATTR_M3U )
                     {
-                        if ( global_settings.resume )
                             snprintf(global_settings.resume_file,
                                      MAX_PATH, "%s/%s",
                                      currdir,
@@ -530,7 +529,6 @@
                         start_index = 0;
                     }
                     else if (dircache[dircursor+start].attr & TREE_ATTR_MP3 ) {
-                        if ( global_settings.resume )
                             strncpy(global_settings.resume_file,
                                     currdir, MAX_PATH);
                         start_index = build_playlist(dircursor+start);
@@ -543,14 +541,14 @@
                     else
                         break;
 
-                    if ( global_settings.resume ) {
                         /* the resume_index must always be the index in the
                            shuffled list in case shuffle is enabled */
+                    global_settings.last_shuffled_index = start_index;
                         global_settings.resume_index = start_index;
                         global_settings.resume_offset = 0;
                         global_settings.resume_seed = seed;
+                    if ( global_settings.resume )
                         settings_save();
-                    }
 
                     status_set_playmode(STATUS_PLAY);
                     status_draw();
Index: wps.c
===================================================================
RCS file: /cvsroot/rockbox/apps/wps.c,v
retrieving revision 1.107
diff -u -b -r1.107 wps.c
--- wps.c	27 Aug 2002 01:05:16 -0000	1.107
+++ wps.c	27 Aug 2002 06:30:34 -0000
@@ -1219,6 +1219,11 @@
                 if (mpeg_is_playing() && id3)
                     display_file_time(id3->elapsed, id3->length);
                 
+                if ( id3 && 
+                     global_settings.playlist_shuffle &&
+                     global_settings.last_shuffled_index != id3->index )
+                    global_settings.last_shuffled_index = id3->index;
+                
                 /* save resume data */
                 if ( id3 && 
                      global_settings.resume &&

