[Scummvm-cvs-logs] SF.net SVN: scummvm:[43524] scummvm/branches/gsoc2009-16bit

Kirben at users.sourceforge.net Kirben at users.sourceforge.net
Wed Aug 19 03:22:44 CEST 2009


Revision: 43524
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43524&view=rev
Author:   Kirben
Date:     2009-08-19 01:22:43 +0000 (Wed, 19 Aug 2009)

Log Message:
-----------
Merged revisions 43458-43468,43470-43471,43473-43475,43477,43479-43483,43485,43497-43498,43500,43503-43504,43507,43509-43510,43512-43515,43517,43519,43521,43523 via svnmerge from 
https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk

........
  r43458 | thebluegr | 2009-08-17 15:55:21 +1000 (Mon, 17 Aug 2009) | 8 lines
  
  - Simplified some functions to accept only the parts of the EngineState they need as parameters, instead of the whole EngineState
  - Moved the class table in the Segment manager - it's the only class using it directly
  - Removed the sci11 flag from save games (we already know this, we don't need to store it)
  - Moved script_get_segment() and get_class_address() inside the segment manager class
  - Removed the script_locate_by_segment wrapper
  - Simplified script_lookup_export() a lot by removing some paranoia checks
  - Added some WIP code for automatically determining the game id in the fallback detector (still not working)
  - General cleanup
........
  r43459 | lordhoto | 2009-08-17 17:36:08 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Fix compilation of the SCI engine. It seems that all of the SCI header files I touched (and probably others I luckily didn't touch) seem to assume that files including them will supply needed types. That looks like a major issue in SCI. Someone with knowledge of the SCI code should look into this and cleanup the includes of *all* SCI headers.
........
  r43460 | thebluegr | 2009-08-17 19:19:53 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Cleanup
........
  r43461 | strangerke | 2009-08-17 19:50:35 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Added OPCODEDRAW 0x85, with a specific workaround for Bambou hardcoded paths in scripts
........
  r43462 | strangerke | 2009-08-17 19:54:49 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Suppress useless parentheses
........
  r43463 | lordhoto | 2009-08-17 19:57:09 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Formatting.
........
  r43464 | strangerke | 2009-08-17 20:05:02 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Add back parenthesis (I wasn't aware of this convention, sorry) in saveload, and mimic this code in oPlaytoons_openItk
........
  r43465 | lordhoto | 2009-08-17 20:48:03 +1000 (Mon, 17 Aug 2009) | 2 lines
  
  - Add note about that modifing the parent stream will mess up SeekableSubReadStream and SeekableSubReadStreamEndian.
  - Link to SubReadStream documentation from SeekableSubReadStream and SeekableSubReadStreamEndian.
........
  r43466 | thebluegr | 2009-08-17 21:06:27 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Made sound effect playing code consistent for compressed and uncompressed sounds. MemoryReadStream is used again instead of SeekableSubReadStream, as there will be issues when multiple sound effects or voices are played simultaneously
........
  r43467 | thebluegr | 2009-08-17 21:11:38 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Ignore speech and sound effect samples with unknown compression, instead of trying to play them as raw sound. Some cleanup
........
  r43468 | dreammaster | 2009-08-17 21:36:09 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Fix for some more !!HIGH STRINGS!! when talking to the palace guards
........
  r43470 | thebluegr | 2009-08-17 21:49:07 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Simplified the sound playing code by removing the boolean variables for signed, stereo, endian and sample bit information - now sound flags are used instead. Some cleanup.
........
  r43471 | dreammaster | 2009-08-17 21:51:42 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Switched event loop while/do to do/while, to ensure event handling occurs even when the game is under heavy load
........
  r43473 | lordhoto | 2009-08-17 22:22:15 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Cleanup: don't copy the Kyrandia 1 Amiga credits data in a temporary buffer, and thus keeping it twice in memory.
........
  r43474 | lordhoto | 2009-08-17 22:22:30 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Clear input queue before displaying the credits in Kyrandia 1.
........
  r43475 | lordhoto | 2009-08-17 22:47:57 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Fix possible out of bounds access in Screen::drawShape.
........
  r43477 | joostp | 2009-08-17 22:57:37 +1000 (Mon, 17 Aug 2009) | 2 lines
  
  Commit (slightly) modified version of patch #2831248: Allow suspend/resume for PSP
........
  r43479 | thebluegr | 2009-08-17 23:16:40 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Added looping support to LinearDiskStream, needed by SAGA and perhaps other engines. Note that the loop end parameter is still not implemented
........
  r43480 | thebluegr | 2009-08-17 23:25:44 +1000 (Mon, 17 Aug 2009) | 2 lines
  
  - Removed the custom DigitalMusicInputStream used in SAGA for the digital music in ITE CD and replaced it with the common LinearDiskStream class
  - Removed leftover code which plays standalone tracks (it's not used anywhere)
........
  r43481 | lordhoto | 2009-08-17 23:49:56 +1000 (Mon, 17 Aug 2009) | 1 line
  
  Slight cleanup to makeLinearDiskStream interface.
........
  r43482 | waltervn | 2009-08-18 01:49:22 +1000 (Tue, 18 Aug 2009) | 1 line
  
  SCI: Add autodetection for DoSound. Cleanup.
........
  r43483 | waltervn | 2009-08-18 02:07:47 +1000 (Tue, 18 Aug 2009) | 1 line
  
  SCI: Build fix.
........
  r43485 | thebluegr | 2009-08-18 04:25:51 +1000 (Tue, 18 Aug 2009) | 1 line
  
  Put back the code for playing external digital music, used by the MIDI enhancement project, which was removed in rev. #43480
........
  r43497 | waltervn | 2009-08-18 09:11:25 +1000 (Tue, 18 Aug 2009) | 1 line
  
  SCI: Fix kernel table for multilingual SCI01 games. Cleanup.
........
  r43498 | joostp | 2009-08-18 09:54:40 +1000 (Tue, 18 Aug 2009) | 2 lines
  
  PSP: increase optimization level and change clock rate to 333mhz
........
  r43500 | thebluegr | 2009-08-18 16:43:06 +1000 (Tue, 18 Aug 2009) | 1 line
  
  Applied agent-q's patch to the SAGA pathfinding code for all platforms - x and y should not ever be greater than 640 and 480 respectively, so it looks safe enough to be applied
........
  r43503 | thebluegr | 2009-08-18 19:12:41 +1000 (Tue, 18 Aug 2009) | 1 line
  
  Removed the maxMemory parameter of the resource manager and replaced it with a define
........
  r43504 | thebluegr | 2009-08-18 20:01:18 +1000 (Tue, 18 Aug 2009) | 2 lines
  
  - Added game ID detection to the fallback detector. We still need to map some of Sierra's internal IDs to our own ones
  - The class table is now created in the segment manager constructor
........
  r43507 | dreammaster | 2009-08-18 22:25:04 +1000 (Tue, 18 Aug 2009) | 1 line
  
  Bugfix for Castle Skorl problem reported on the list
........
  r43509 | thebluegr | 2009-08-18 22:49:34 +1000 (Tue, 18 Aug 2009) | 1 line
  
  Mapped some Sierra internal IDs to our own ones, and added a note about a hack currently used in the fallback detector
........
  r43510 | thebluegr | 2009-08-19 00:10:31 +1000 (Wed, 19 Aug 2009) | 1 line
  
  Started rewriting the SCI engine to use FSNode instead of file names. This is the proper solution for removing the hack in the fallback detector, but it still needs work. Also, reduced the things needed to be initialized a bit, so that the detection is a bit faster
........
  r43512 | lordhoto | 2009-08-19 01:31:26 +1000 (Wed, 19 Aug 2009) | 1 line
  
  Made AGOS, DRASCULA, GOB, GROOVIE, MADE, SCUMM and TINSEL properly stop CD audio playback on engine quit. (This only problem affected playback from CD, not from ripped audio files)
........
  r43513 | lordhoto | 2009-08-19 01:32:26 +1000 (Wed, 19 Aug 2009) | 2 lines
  
  - Destory AudioCDManager singleton after user quits a game, this saves a few bytes memory
  - Added FIXME to audiocd.h, concering why destroying the AudioCDManager can not quit CD playback right now
........
  r43514 | joostp | 2009-08-19 01:39:47 +1000 (Wed, 19 Aug 2009) | 2 lines
  
  PSP: disable dosbox OPL
........
  r43515 | lordhoto | 2009-08-19 01:41:00 +1000 (Wed, 19 Aug 2009) | 1 line
  
  Typos.
........
  r43517 | joostp | 2009-08-19 03:12:01 +1000 (Wed, 19 Aug 2009) | 2 lines
  
  PSP: Make R-trigger act as a context sensitive modifier key, remap ENTER to triangle
........
  r43519 | joostp | 2009-08-19 04:06:50 +1000 (Wed, 19 Aug 2009) | 2 lines
  
  Implement setCursorPalette(), correct hasFeature() <-> getFeatureState() mixup.
........
  r43521 | john_doe | 2009-08-19 05:42:13 +1000 (Wed, 19 Aug 2009) | 2 lines
  
  - PMV player: Use frame count from PVM file and fix incorrect "invalid chunk type" warning
  - Fix sprite drawing glitch with vertically flipped sprites (bug #2825925)
........
  r43523 | buddha_ | 2009-08-19 07:37:31 +1000 (Wed, 19 Aug 2009) | 1 line
  
  Possible fix for #2828330 (AGI: KQ1: Fast text box). If doesn't break anything else then should go to the branch-1-0-0 too, but haven't had the time to do much testing yet - thus committing to the trunk first.
........

Modified Paths:
--------------
    scummvm/branches/gsoc2009-16bit/AUTHORS
    scummvm/branches/gsoc2009-16bit/COPYRIGHT
    scummvm/branches/gsoc2009-16bit/NEWS
    scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs-factory.cpp
    scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs.cpp
    scummvm/branches/gsoc2009-16bit/backends/module.mk
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/Makefile
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/README.PSP.in
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/module.mk
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.cpp
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.h
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.cpp
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.h
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp.spec
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp_main.cpp
    scummvm/branches/gsoc2009-16bit/base/main.cpp
    scummvm/branches/gsoc2009-16bit/common/stream.h
    scummvm/branches/gsoc2009-16bit/configure
    scummvm/branches/gsoc2009-16bit/engines/agi/cycle.cpp
    scummvm/branches/gsoc2009-16bit/engines/agi/menu.cpp
    scummvm/branches/gsoc2009-16bit/engines/agos/agos.cpp
    scummvm/branches/gsoc2009-16bit/engines/cruise/cruise_main.cpp
    scummvm/branches/gsoc2009-16bit/engines/drascula/drascula.cpp
    scummvm/branches/gsoc2009-16bit/engines/gob/inter.h
    scummvm/branches/gsoc2009-16bit/engines/gob/inter_playtoons.cpp
    scummvm/branches/gsoc2009-16bit/engines/gob/sound/cdrom.cpp
    scummvm/branches/gsoc2009-16bit/engines/groovie/music.cpp
    scummvm/branches/gsoc2009-16bit/engines/groovie/music.h
    scummvm/branches/gsoc2009-16bit/engines/kyra/screen.cpp
    scummvm/branches/gsoc2009-16bit/engines/kyra/sequences_lok.cpp
    scummvm/branches/gsoc2009-16bit/engines/lure/res.cpp
    scummvm/branches/gsoc2009-16bit/engines/made/made.cpp
    scummvm/branches/gsoc2009-16bit/engines/made/pmvplayer.cpp
    scummvm/branches/gsoc2009-16bit/engines/made/screen.cpp
    scummvm/branches/gsoc2009-16bit/engines/saga/actor.h
    scummvm/branches/gsoc2009-16bit/engines/saga/music.cpp
    scummvm/branches/gsoc2009-16bit/engines/saga/sndres.cpp
    scummvm/branches/gsoc2009-16bit/engines/saga/sound.cpp
    scummvm/branches/gsoc2009-16bit/engines/saga/sound.h
    scummvm/branches/gsoc2009-16bit/engines/sci/console.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/console.h
    scummvm/branches/gsoc2009-16bit/engines/sci/debug.h
    scummvm/branches/gsoc2009-16bit/engines/sci/detection.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/game.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/kernel.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/kernel.h
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/kmovement.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/kscripts.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/ksound.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/memobj.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/memobj.h
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/savegame.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/scriptdebug.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/seg_manager.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/seg_manager.h
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/state.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/state.h
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/vm.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/engine/vm.h
    scummvm/branches/gsoc2009-16bit/engines/sci/gfx/gfx_state_internal.h
    scummvm/branches/gsoc2009-16bit/engines/sci/gfx/gfx_widgets.h
    scummvm/branches/gsoc2009-16bit/engines/sci/resource.cpp
    scummvm/branches/gsoc2009-16bit/engines/sci/resource.h
    scummvm/branches/gsoc2009-16bit/engines/sci/sci.cpp
    scummvm/branches/gsoc2009-16bit/engines/scumm/sound.cpp
    scummvm/branches/gsoc2009-16bit/engines/tinsel/pcode.cpp
    scummvm/branches/gsoc2009-16bit/engines/tinsel/tinsel.cpp
    scummvm/branches/gsoc2009-16bit/gui/credits.h
    scummvm/branches/gsoc2009-16bit/sound/audiocd.h
    scummvm/branches/gsoc2009-16bit/sound/audiostream.cpp
    scummvm/branches/gsoc2009-16bit/sound/audiostream.h
    scummvm/branches/gsoc2009-16bit/sound/voc.cpp
    scummvm/branches/gsoc2009-16bit/tools/credits.pl

Added Paths:
-----------
    scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.cpp
    scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.h
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.cpp
    scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.h

Property Changed:
----------------
    scummvm/branches/gsoc2009-16bit/
    scummvm/branches/gsoc2009-16bit/backends/fs/ds/
    scummvm/branches/gsoc2009-16bit/backends/platform/ds/


Property changes on: scummvm/branches/gsoc2009-16bit
___________________________________________________________________
Modified: svnmerge-integrated
   - /scummvm/trunk:1-43455 /scummvm/branches/gsoc2008-tfmx:1-31765 /scummvm/branches/gsoc2008-gui:1-31703
   + /scummvm/trunk:1-43523 /scummvm/branches/gsoc2008-tfmx:1-31765 /scummvm/branches/gsoc2008-gui:1-31703
Modified: svn:mergeinfo
   - /scummvm/trunk:42578-43056,43066-43241,43245-43332,43338-43414,43417-43452
   + /scummvm/trunk:42578-43056,43066-43241,43245-43332,43338-43414,43417-43452,43458-43523

Modified: scummvm/branches/gsoc2009-16bit/AUTHORS
===================================================================
--- scummvm/branches/gsoc2009-16bit/AUTHORS	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/AUTHORS	2009-08-19 01:22:43 UTC (rev 43524)
@@ -314,6 +314,7 @@
      Andreas Karlsson      - Initial port for SymbianOS
      Claudio Matsuoka      - Daily Linux builds
      Thomas Mayer          - PSP port contributions
+     Yotam Barnoy          - PSP port suspend/resume support
      Sean Murray           - ScummVM tools GUI application (GSoC 2007 task)
      n0p                   - Windows CE port aspect ratio correction scaler
                              and right click input method

Modified: scummvm/branches/gsoc2009-16bit/COPYRIGHT
===================================================================
--- scummvm/branches/gsoc2009-16bit/COPYRIGHT	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/COPYRIGHT	2009-08-19 01:22:43 UTC (rev 43524)
@@ -205,3 +205,4 @@
 Xanathar "xanathar"
 Grant Yeager "glo_kidd"
 Benjamin W. Zale "junior_aepi"
+Yotam Barnoy "bluddy"

Modified: scummvm/branches/gsoc2009-16bit/NEWS
===================================================================
--- scummvm/branches/gsoc2009-16bit/NEWS	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/NEWS	2009-08-19 01:22:43 UTC (rev 43524)
@@ -59,6 +59,9 @@
    - Added support for PC Speaker based music and sound effects.
    - Added support for 16 color dithering in Kyrandia PC-9801.
 
+ PSP port:
+   - Added support for sleep mode (suspend/resume).
+
  WinCE port:
     - Speed optimized versions of low-res Smartphone and 2x scalers.
     - New aspect correction scaler for VGA (or higher) devices.


Property changes on: scummvm/branches/gsoc2009-16bit/backends/fs/ds
___________________________________________________________________
Modified: svn:mergeinfo
   - /scummvm/branches/branch-0-13-0/backends/fs/ds:35922-39517
/scummvm/trunk/backends/fs/ds:42578-43056,43066-43241,43245-43332,43338-43414,43417-43452
   + /scummvm/branches/branch-0-13-0/backends/fs/ds:35922-39517
/scummvm/trunk/backends/fs/ds:42578-43056,43066-43241,43245-43332,43338-43414,43417-43452,43458-43523

Modified: scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs-factory.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs-factory.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs-factory.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -34,7 +34,13 @@
 
 AbstractFSNode *PSPFilesystemFactory::makeCurrentDirectoryFileNode() const {
 	char buf[MAXPATHLEN];
-	return getcwd(buf, MAXPATHLEN) ? new PSPFilesystemNode(buf) : NULL;
+	char * ret = 0;
+
+	PowerMan.beginCriticalSection();
+	ret = getcwd(buf, MAXPATHLEN);
+	PowerMan.endCriticalSection();
+
+	return (ret ? new PSPFilesystemNode(buf) : NULL);
 }
 
 AbstractFSNode *PSPFilesystemFactory::makeFileNodePath(const Common::String &path) const {

Modified: scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-fs.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -26,7 +26,8 @@
 
 #include "engines/engine.h"
 #include "backends/fs/abstract-fs.h"
-#include "backends/fs/stdiostream.h"
+#include "backends/fs/psp/psp-stream.h"
+#include "backends/platform/psp/powerman.h"
 
 #include <sys/stat.h>
 #include <unistd.h>
@@ -35,6 +36,9 @@
 
 #define	ROOT_PATH	"ms0:/"
 
+#include "backends/platform/psp/trace.h"
+
+
 /**
  * Implementation of the ScummVM file system API based on PSPSDK API.
  *
@@ -61,13 +65,13 @@
 	 */
 	PSPFilesystemNode(const Common::String &p, bool verify = true);
 
-	virtual bool exists() const { return access(_path.c_str(), F_OK) == 0; }
+	virtual bool exists() const;
 	virtual Common::String getDisplayName() const { return _displayName; }
 	virtual Common::String getName() const { return _displayName; }
 	virtual Common::String getPath() const { return _path; }
 	virtual bool isDirectory() const { return _isDirectory; }
-	virtual bool isReadable() const { return access(_path.c_str(), R_OK) == 0; }
-	virtual bool isWritable() const { return access(_path.c_str(), W_OK) == 0; }
+	virtual bool isReadable() const;
+	virtual bool isWritable() const;
 
 	virtual AbstractFSNode *getChild(const Common::String &n) const;
 	virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
@@ -94,11 +98,44 @@
 
 	if (verify) {
 		struct stat st;
+		PowerMan.beginCriticalSection();
 		_isValid = (0 == stat(_path.c_str(), &st));
+		PowerMan.endCriticalSection();
 		_isDirectory = S_ISDIR(st.st_mode);
 	}
 }
 
+bool PSPFilesystemNode::exists() const {
+	int ret = 0;
+
+	PowerMan.beginCriticalSection();	// Make sure to block in case of suspend
+	ret = access(_path.c_str(), F_OK);
+	PowerMan.endCriticalSection();
+	
+	return ret == 0;
+}
+
+bool PSPFilesystemNode::isReadable() const {
+	int ret = 0;
+
+	PowerMan.beginCriticalSection();	// Make sure to block in case of suspend
+	ret = access(_path.c_str(), R_OK);
+	PowerMan.endCriticalSection();
+	
+	return ret == 0;
+}
+
+bool PSPFilesystemNode::isWritable() const {
+	int ret = 0;
+
+	PowerMan.beginCriticalSection();	// Make sure to block in case of suspend
+	ret = access(_path.c_str(), W_OK);
+	PowerMan.endCriticalSection();
+	
+	return ret == 0;
+}
+
+
 AbstractFSNode *PSPFilesystemNode::getChild(const Common::String &n) const {
 	// FIXME: Pretty lame implementation! We do no error checking to speak
 	// of, do not check if this is a special node, etc.
@@ -117,6 +154,10 @@
 
 	//TODO: honor the hidden flag
 
+	bool ret = true;
+
+	PowerMan.beginCriticalSection();	// Make sure to block in case of suspend
+	
 	int dfd  = sceIoDopen(_path.c_str());
 	if (dfd > 0) {
 		SceIoDirent dir;
@@ -149,10 +190,13 @@
 		}
 
 		sceIoDclose(dfd);
-		return true;
-	} else {
-		return false;
+		ret = true;
+	} else { // dfd <= 0
+		ret = false;
 	}
+
+	PowerMan.endCriticalSection();
+	return ret;
 }
 
 AbstractFSNode *PSPFilesystemNode::getParent() const {
@@ -166,11 +210,11 @@
 }
 
 Common::SeekableReadStream *PSPFilesystemNode::createReadStream() {
-	return StdioStream::makeFromPath(getPath().c_str(), false);
+	return PSPIoStream::makeFromPath(getPath(), false);
 }
 
 Common::WriteStream *PSPFilesystemNode::createWriteStream() {
-	return StdioStream::makeFromPath(getPath().c_str(), true);
+	return PSPIoStream::makeFromPath(getPath(), true);
 }
 
 #endif //#ifdef __PSP__

Copied: scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.cpp (from rev 43523, scummvm/trunk/backends/fs/psp/psp-stream.cpp)
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -0,0 +1,230 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+#ifdef __PSP__
+
+#include "backends/fs/psp/psp-stream.h"
+#include "backends/platform/psp/trace.h"
+#include <errno.h>
+
+PSPIoStream::PSPIoStream(const Common::String &path, bool writeMode)
+: StdioStream((void *)1), _path(path), _writeMode(writeMode) {
+
+	assert(!path.empty());
+
+	_handle = (void *)0;		// Need to do this since base class asserts not 0.
+
+	PowerMan.registerSuspend(this);	 // Register with the powermanager to be suspended
+
+}
+
+PSPIoStream::~PSPIoStream() {
+	PowerMan.unregisterSuspend(this); // Unregister with powermanager to be suspended
+								 // Must do this before fclose() or resume() will reopen.
+
+	fclose((FILE *)_handle);
+}
+
+// Function to open the file pointed to by the path.
+//
+//
+void * PSPIoStream::open() {
+	if (PowerMan.beginCriticalSection()==PowerManager::Blocked) {
+		// No need to open. Just return the _handle resume() already opened.
+		PSPDebugTrace("Suspended in PSPIoStream::open\n");
+	} else {
+		_handle = fopen(_path.c_str(), _writeMode ? "wb" : "rb"); 	// open
+	}
+	
+	PowerMan.endCriticalSection();
+
+	return _handle;
+}
+
+bool PSPIoStream::err() const {
+	bool ret;
+
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::err()\n");
+
+	ret = ferror((FILE *)_handle) != 0;
+
+	PowerMan.endCriticalSection();
+
+	return ret;
+}
+
+void PSPIoStream::clearErr() {
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::clearErr()\n");
+
+	clearerr((FILE *)_handle);
+
+	PowerMan.endCriticalSection();
+}
+
+bool PSPIoStream::eos() const {
+	bool ret;
+
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::eos()\n");
+
+	ret = feof((FILE *)_handle) != 0;
+
+	PowerMan.endCriticalSection();
+
+	return ret;
+}
+
+int32 PSPIoStream::pos() const {
+	int32 ret;
+
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::pos()\n");
+
+	ret = ftell((FILE *)_handle);
+
+	PowerMan.endCriticalSection();
+
+	return ret;
+}
+
+
+int32 PSPIoStream::size() const {
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::size()\n");
+
+	int32 oldPos = ftell((FILE *)_handle);
+	fseek((FILE *)_handle, 0, SEEK_END);
+	int32 length = ftell((FILE *)_handle);
+	fseek((FILE *)_handle, oldPos, SEEK_SET);
+
+	PowerMan.endCriticalSection();
+
+	return length;
+}
+
+bool PSPIoStream::seek(int32 offs, int whence) {
+	int ret = 0;
+
+	// Check if we can access the file
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::seek()\n");
+
+	ret = fseek((FILE *)_handle, offs, whence);
+
+	PowerMan.endCriticalSection();
+
+	return ret == 0;
+}
+
+uint32 PSPIoStream::read(void *ptr, uint32 len) {
+	int ret = 0;
+
+	// Check if we can access the file
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::read()\n");
+
+	ret = fread((byte *)ptr, 1, len, (FILE *)_handle);
+	
+	PowerMan.endCriticalSection();
+	
+	return ret;
+}
+
+uint32 PSPIoStream::write(const void *ptr, uint32 len) {
+	int ret = 0;
+
+	// Check if we can access the file
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::read()\n");
+
+	ret = fwrite(ptr, 1, len, (FILE *)_handle);
+
+	PowerMan.endCriticalSection();
+
+	return ret;
+}
+
+bool PSPIoStream::flush() {
+	int ret = 0;
+
+	// Check if we can access the file
+	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
+		PSPDebugTrace("Suspended in PSPIoStream::read()\n");
+
+	ret = fflush((FILE *)_handle);
+
+	PowerMan.endCriticalSection();
+
+	return ret == 0;
+}
+
+// For the PSP, since we're building in suspend support, we moved opening
+// the actual file to an open function since we need an actual PSPIoStream object to suspend.
+//
+PSPIoStream *PSPIoStream::makeFromPath(const Common::String &path, bool writeMode) {
+	PSPIoStream *stream = new PSPIoStream(path, writeMode);
+
+	if (stream->open() > 0) {
+		return stream;
+	} else {
+		delete stream;
+		return 0;
+	}
+}
+
+/*
+ *  Function to suspend the IO stream (called by PowerManager)
+ */
+int PSPIoStream::suspend() {
+	if (_handle > 0) {
+		_pos = ftell((FILE *)_handle);	// Save our position
+		fclose((FILE *)_handle);		// close our file descriptor
+		_handle = 0;					// Set handle to null
+	}
+
+	return 0;
+}
+
+/*
+ *  Function to resume the IO stream (called by Power Manager)
+ */
+int PSPIoStream::resume() {
+	int ret = 0;
+
+	// We reopen our file descriptor
+	_handle = fopen(_path.c_str(), _writeMode ? "wb" : "rb");
+	if (_handle <= 0) {
+		PSPDebugTrace("PSPIoStream::resume(): Couldn't reopen file %s\n", _path.c_str());
+		ret = -1;;
+	}
+
+	// Resume our previous position
+	if(_handle > 0) fseek((FILE *)_handle, _pos, SEEK_SET);
+
+	return ret;
+}
+
+#endif /* __PSP__ */

Copied: scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.h (from rev 43523, scummvm/trunk/backends/fs/psp/psp-stream.h)
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.h	                        (rev 0)
+++ scummvm/branches/gsoc2009-16bit/backends/fs/psp/psp-stream.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -0,0 +1,70 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef PSPSTREAM_H_
+#define PSPSTREAM_H_
+
+#include "backends/fs/stdiostream.h"
+#include "backends/platform/psp/powerman.h"
+#include "common/list.h"
+
+/*
+ *  Class to handle special suspend/resume needs of PSP IO Streams
+ */
+class PSPIoStream : public StdioStream, public Suspendable {
+protected:
+	Common::String _path;			/* Need to maintain for reopening after suspend */
+	bool _writeMode;				/* "" */
+	unsigned int _pos;				/* "" */
+
+public:
+	/**
+	 * Given a path, invoke fopen on that path and wrap the result in a
+	 * PSPIoStream instance.
+	 */
+	static PSPIoStream *makeFromPath(const Common::String &path, bool writeMode);
+
+	PSPIoStream(const Common::String &path, bool writeMode);
+	virtual ~PSPIoStream();
+
+	void * open();		// open the file pointed to by the file path
+
+	bool err() const;
+	void clearErr();
+	bool eos() const;
+
+	virtual uint32 write(const void *dataPtr, uint32 dataSize);
+	virtual bool flush();
+
+	virtual int32 pos() const;
+	virtual int32 size() const;
+	virtual bool seek(int32 offs, int whence = SEEK_SET);
+	virtual uint32 read(void *dataPtr, uint32 dataSize);
+
+	int suspend();		/* Suspendable interface (power manager) */
+	int resume();		/* " " */
+};
+
+#endif /* PSPSTREAM_H_ */

Modified: scummvm/branches/gsoc2009-16bit/backends/module.mk
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/module.mk	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/module.mk	2009-08-19 01:22:43 UTC (rev 43524)
@@ -11,6 +11,7 @@
 	fs/posix/posix-fs-factory.o \
 	fs/ps2/ps2-fs-factory.o \
 	fs/psp/psp-fs-factory.o \
+	fs/psp/psp-stream.o \
 	fs/symbian/symbian-fs-factory.o \
 	fs/windows/windows-fs-factory.o \
 	fs/wii/wii-fs-factory.o \


Property changes on: scummvm/branches/gsoc2009-16bit/backends/platform/ds
___________________________________________________________________
Modified: svn:mergeinfo
   - /scummvm/branches/branch-0-13-0/backends/platform/ds:35922-39516
/scummvm/trunk/backends/platform/ds:42578-43056,43066-43241,43245-43332,43338-43414,43417-43452
   + /scummvm/branches/branch-0-13-0/backends/platform/ds:35922-39516
/scummvm/trunk/backends/platform/ds:42578-43056,43066-43241,43245-43332,43338-43414,43417-43452,43458-43523

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/Makefile
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/Makefile	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/Makefile	2009-08-19 01:22:43 UTC (rev 43524)
@@ -62,7 +62,7 @@
 INCDIR   := $(srcdir) . $(srcdir)/engines/ . $(PSPSDK)/include
 LIBDIR   := $(LIBDIR) . $(PSPSDK)/lib
 
-CXXFLAGS = -O2 -Wall -D__PSP__ -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DUSE_ZLIB -Wno-multichar `$(PSPBIN)/sdl-config --cflags`
+CXXFLAGS = -O3 -Wall -D__PSP__ -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DUSE_ZLIB -DDISABLE_DOSBOX_OPL -Wno-multichar `$(PSPBIN)/sdl-config --cflags`
 CXXFLAGS:= $(addprefix -I,$(INCDIR)) $(CXXFLAGS)
 LDFLAGS := $(addprefix -L,$(LIBDIR)) $(LDFLAGS)
 LIBS     =
@@ -75,12 +75,13 @@
 CXXFLAGS+= -DUSE_VORBIS -DUSE_TREMOR
 LIBS	+= -lvorbisidec
 
-LIBS    += `$(PSPBIN)/sdl-config --libs` -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspsdk -lpspuser
+LIBS    += `$(PSPBIN)/sdl-config --libs` -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspuser -lpsppower
 
 CXXFLAGS := $(CXXFLAGS) -fno-exceptions -fno-rtti
 
 TARGET = scummvm-psp
-OBJS := psp_main.o \
+OBJS := powerman.o \
+	psp_main.o \
 	osys_psp.o \
 	osys_psp_gu.o \
 	kbd_ss_c.o \

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/README.PSP.in
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/README.PSP.in	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/README.PSP.in	2009-08-19 01:22:43 UTC (rev 43524)
@@ -13,15 +13,17 @@
 ========
 
 Left trigger		- ESC
-Right trigger		- Enter
+Right trigger		- Modifier key (see below for uses)
 Analog			- Mouse movement
+Right trigger + Analog	- Fine control mouse
 Directionals		- Mouse movement
-Analog + triangle	- Fine control mouse
+Triangle		- Enter
 Cross			- Mouse button 1
 Circle			- Mouse button 2
 Square			- '.' (skip dialogue in some games)
 Select			- Show/Hide Virtual Keyboard
 Start			- F5
+Right trigger + Start	- Return-To-Launcher menu
 
 Notes
 =====
@@ -32,9 +34,6 @@
   As such, it is recommended to play games in their original, uncompressed,
   form whenever possible.
 
-- Sleep/Suspend mode currently isn't supported, so don't use it when
-  running ScummVM.
-
 - This README may be outdated, for more up-to-date instructions and notes see
   the PSP Port Wiki: http://wiki.scummvm.org/index.php/PlayStation_Portable
 

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/module.mk
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/module.mk	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/module.mk	2009-08-19 01:22:43 UTC (rev 43524)
@@ -1,6 +1,7 @@
 MODULE := backends/platform/psp
 
 MODULE_OBJS := \
+	powerman.o \
 	psp_main.o \
 	osys_psp.o \
 	osys_psp_gu.o \

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -79,6 +79,8 @@
 
 	memset(_palette, 0, sizeof(_palette));
 
+	_cursorPaletteDisabled = true;
+
 	_samplesPerSec = 0;
 
 	//init SDL
@@ -110,14 +112,14 @@
 
 
 bool OSystem_PSP::hasFeature(Feature f) {
-	return false;
+	return (f == kFeatureOverlaySupportsAlpha || f == kFeatureCursorHasPalette);
 }
 
 void OSystem_PSP::setFeatureState(Feature f, bool enable) {
 }
 
 bool OSystem_PSP::getFeatureState(Feature f) {
-	return (f == kFeatureOverlaySupportsAlpha);
+	return false;
 }
 
 const OSystem::GraphicsMode* OSystem_PSP::getSupportedGraphicsModes() const {
@@ -411,7 +413,7 @@
 */
 	uint32 buttonsChanged = pad.Buttons ^ _prevButtons;
 
-	if (buttonsChanged & (PSP_CTRL_CROSS | PSP_CTRL_CIRCLE | PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER | PSP_CTRL_START | PSP_CTRL_SELECT | PSP_CTRL_SQUARE)) {
+	if (buttonsChanged & (PSP_CTRL_CROSS | PSP_CTRL_CIRCLE | PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER | PSP_CTRL_START | PSP_CTRL_SELECT | PSP_CTRL_SQUARE | PSP_CTRL_TRIANGLE)) {
 		if (buttonsChanged & PSP_CTRL_CROSS) {
 			event.type = (pad.Buttons & PSP_CTRL_CROSS) ? Common::EVENT_LBUTTONDOWN : Common::EVENT_LBUTTONUP;
 		} else if (buttonsChanged & PSP_CTRL_CIRCLE) {
@@ -419,23 +421,29 @@
 		} else {
 			//any of the other buttons.
 			event.type = buttonsChanged & pad.Buttons ? Common::EVENT_KEYDOWN : Common::EVENT_KEYUP;
+			event.kbd.ascii = 0;
 			event.kbd.flags = 0;
 
 			if (buttonsChanged & PSP_CTRL_LTRIGGER) {
 				event.kbd.keycode = Common::KEYCODE_ESCAPE;
 				event.kbd.ascii = 27;
-			} else if (buttonsChanged & PSP_CTRL_RTRIGGER) {
-				event.kbd.keycode = Common::KEYCODE_RETURN;
-				event.kbd.ascii = 13;
 			} else if (buttonsChanged & PSP_CTRL_START) {
 				event.kbd.keycode = Common::KEYCODE_F5;
 				event.kbd.ascii = Common::ASCII_F5;
+				if (pad.Buttons & PSP_CTRL_RTRIGGER) {
+					event.kbd.flags = Common::KBD_CTRL;	// Main menu to allow RTL
+				}
 /*			} else if (buttonsChanged & PSP_CTRL_SELECT) {
 				event.kbd.keycode = Common::KEYCODE_0;
 				event.kbd.ascii = '0';
 */			} else if (buttonsChanged & PSP_CTRL_SQUARE) {
 				event.kbd.keycode = Common::KEYCODE_PERIOD;
 				event.kbd.ascii = '.';
+			} else if (buttonsChanged & PSP_CTRL_TRIANGLE) {
+				event.kbd.keycode = Common::KEYCODE_RETURN;
+				event.kbd.ascii = 13;
+			} else if (pad.Buttons & PSP_CTRL_RTRIGGER) {
+				event.kbd.flags |= Common::KBD_SHIFT;
 			}
 
 		}
@@ -484,7 +492,7 @@
 				newY += _padAccel >> 2;
 
 			// If no movement then this has no effect
-			if (pad.Buttons & PSP_CTRL_TRIANGLE) {
+			if (pad.Buttons & PSP_CTRL_RTRIGGER) {
 				// Fine control mode for analog
 					if (analogStepAmountX != 0) {
 						if (analogStepAmountX > 0)

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -23,6 +23,9 @@
  *
  */
 
+#ifndef OSYS_PSP_H
+#define OSYS_PSP_H
+
 #include "common/scummsys.h"
 #include "graphics/surface.h"
 #include "graphics/colormasks.h"
@@ -65,6 +68,7 @@
 	int	_mouseHotspotX, _mouseHotspotY;
 	byte	_mouseKeyColour;
 	byte	*_mouseBuf;
+	bool	_cursorPaletteDisabled;
 
 	uint32	_prevButtons;
 	uint32	_lastPadCheck;
@@ -144,3 +148,5 @@
 	virtual Common::WriteStream *createConfigWriteStream();
 };
 
+
+#endif /* OSYS_PSP_H */

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -41,6 +41,7 @@
 unsigned int __attribute__((aligned(16))) list[262144];
 unsigned short __attribute__((aligned(16))) clut256[256];
 unsigned short __attribute__((aligned(16))) mouseClut[256];
+unsigned short __attribute__((aligned(16))) cursorPalette[256];
 unsigned short __attribute__((aligned(16))) kbClut[256];
 //unsigned int __attribute__((aligned(16))) offscreen256[640*480];
 //unsigned int __attribute__((aligned(16))) overlayBuffer256[640*480*2];
@@ -225,7 +226,25 @@
 	sceKernelDcacheWritebackAll();
 }
 
+void OSystem_PSP_GU::setCursorPalette(const byte *colors, uint start, uint num) {
+	const byte *b = colors;
 
+	for (uint i = 0; i < num; ++i) {
+		cursorPalette[start + i] = RGBToColour(b[0], b[1], b[2]);
+		b += 4;
+	}
+
+	cursorPalette[0] = 0;
+
+	_cursorPaletteDisabled = false;
+	
+	sceKernelDcacheWritebackAll();
+}
+
+void OSystem_PSP_GU::disableCursorPalette(bool disable) {
+	_cursorPaletteDisabled = disable;
+}
+
 void OSystem_PSP_GU::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
 	//Clip the coordinates
 	if (x < 0) {
@@ -364,7 +383,7 @@
 	if (_mouseVisible) {
 		sceGuTexMode(GU_PSM_T8, 0, 0, 0); // 8-bit image
 		sceGuClutMode(GU_PSM_5551, 0, 0xff, 0);
-		sceGuClutLoad(32, mouseClut); // upload 32*8 entries (256)
+		sceGuClutLoad(32, _cursorPaletteDisabled ? mouseClut : cursorPalette); // upload 32*8 entries (256)
 		sceGuAlphaFunc(GU_GREATER,0,0xff);
 		sceGuEnable(GU_ALPHA_TEST);
 		sceGuTexImage(0, MOUSE_SIZE, MOUSE_SIZE, MOUSE_SIZE, _mouseBuf);

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/osys_psp_gu.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -47,6 +47,8 @@
 	void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale);
 	void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) ;
 	void setPalette(const byte *colors, uint start, uint num);
+	void setCursorPalette(const byte *colors, uint start, uint num);
+	void disableCursorPalette(bool disable);
 	bool pollEvent(Common::Event &event);
 	int _graphicMode;
 	struct Vertex *_vertices;

Copied: scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.cpp (from rev 43523, scummvm/trunk/backends/platform/psp/powerman.cpp)
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -0,0 +1,297 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "./powerman.h"
+#include "./trace.h"
+
+DECLARE_SINGLETON(PowerManager);
+
+ /*******************************************
+*
+*	Constructor
+*
+********************************************/ 
+PowerManager::PowerManager() {
+	_flagMutex = NULL;					/* Init mutex handle */
+	_listMutex = NULL;					/* Init mutex handle */
+	_condSuspendable = NULL;			/* Init condition variable */
+	_condPM = NULL;
+	
+	_condSuspendable = SDL_CreateCond();
+	if (_condSuspendable <= 0) {
+		PSPDebugTrace("PowerManager::PowerManager(): Couldn't create condSuspendable\n");
+	}
+	
+	_condPM = SDL_CreateCond();
+	if (_condPM <= 0) {
+		PSPDebugTrace("PowerManager::PowerManager(): Couldn't create condPM\n");
+	}
+
+	_flagMutex = SDL_CreateMutex();
+	if (_flagMutex <= 0) {
+		PSPDebugTrace("PowerManager::PowerManager(): Couldn't create flagMutex\n");
+	}
+
+	_listMutex = SDL_CreateMutex();
+	if (_listMutex <= 0) {
+		PSPDebugTrace("PowerManager::PowerManager(): Couldn't create listMutex\n");
+	}
+
+	_suspendFlag = false;
+	_criticalCounter = 0;
+ }
+ 
+/*******************************************
+*
+*	Function to register to be notified when suspend/resume time comes
+*
+********************************************/ 
+int PowerManager::registerSuspend(Suspendable *item) {
+	// Register in list
+	PSPDebugTrace("In registerSuspend\n");
+
+	if (SDL_mutexP(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::registerSuspend(): Couldn't lock _listMutex %d\n", _listMutex);
+	}
+
+	_suspendList.push_front(item);
+
+	if (SDL_mutexV(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::registerSuspend(): Couldn't unlock _listMutex %d\n", _listMutex);
+	}
+
+	PSPDebugTrace("Out of registerSuspend\n");
+
+	return 0;
+}
+
+/*******************************************
+*
+*	Function to unregister to be notified when suspend/resume time comes
+*
+********************************************/  
+int PowerManager::unregisterSuspend(Suspendable *item) {
+
+	PSPDebugTrace("In unregisterSuspend\n");
+
+	 // Unregister from stream list
+	if (SDL_mutexP(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::unregisterSuspend(): Couldn't unlock _listMutex %d\n", _listMutex);
+	}
+
+	_suspendList.remove(item);
+
+	if (SDL_mutexV(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::unregisterSuspend(): Couldn't unlock _listMutex %d\n", _listMutex);
+	}
+
+	PSPDebugTrace("Out of unregisterSuspend\n");
+
+	return 0;
+ }
+ 
+ /*******************************************
+*
+*	Destructor
+*
+********************************************/ 
+ PowerManager::~PowerManager() {
+	SDL_DestroyCond(_condSuspendable);
+	_condSuspendable = 0;
+	
+	SDL_DestroyCond(_condPM);
+	_condPM = 0;
+
+	SDL_DestroyMutex(_flagMutex);
+	_flagMutex = 0;
+
+	SDL_DestroyMutex(_listMutex);
+	_listMutex = 0;
+ }
+ 
+ 
+ /*******************************************
+*
+*	Function to be called by threads wanting to block on the PSP entering suspend
+*
+********************************************/  
+ int PowerManager::blockOnSuspend()  {
+	return beginCriticalSection(true);
+}
+
+ /*
+  * Function to block on a suspend, then start a non-suspendable critical section
+  */
+int PowerManager::beginCriticalSection(bool justBlock) {
+	int ret = PowerManager::NotBlocked;
+
+	if (SDL_mutexP(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::blockOnSuspend(): Couldn't lock flagMutex %d\n", _flagMutex);
+		ret = PowerManager::Error;
+	}
+
+	// Check the access flag
+	if (_suspendFlag == true) {
+		PSPDebugTrace("Blocking!!\n");
+		ret = PowerManager::Blocked;
+
+		// If it's true, we wait for a signal to continue
+		if( SDL_CondWait(_condSuspendable, _flagMutex) != 0) {
+			PSPDebugTrace("PowerManager::blockOnSuspend(): Couldn't wait on cond %d\n", _condSuspendable);
+		}
+
+		PSPDebugTrace("We got blocked!!\n");
+	}
+	
+	// Now put the pm to sleep
+	if (justBlock == false)
+		_criticalCounter++;
+
+	if (SDL_mutexV(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::blockOnSuspend(): Couldn't unlock flagMutex %d\n", _flagMutex);
+		ret = PowerManager::Error;
+	}
+
+	return ret;
+}
+
+int PowerManager::endCriticalSection() {
+	int ret = 0;
+
+	if (SDL_mutexP(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::endCriticalSection(): Couldn't lock flagMutex %d\n", _flagMutex);
+		ret = PowerManager::Error;
+	}
+
+	// We're done with our critical section
+	_criticalCounter--;
+	
+	if (_criticalCounter <= 0) {
+		if(_suspendFlag == true) PSPDebugTrace("Waking up the PM and suspendFlag is true\n");
+
+		SDL_CondBroadcast(_condPM);
+
+		if (_criticalCounter < 0) {
+			PSPDebugTrace("PowerManager::endCriticalSection(): Error! Critical counter is %d\n", _criticalCounter);
+		}
+	}
+
+	if (SDL_mutexV(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::endCriticalSection(): Couldn't unlock flagMutex %d\n", _flagMutex);
+		ret = PowerManager::Error;
+	}
+
+	return ret;
+}
+
+ /*******************************************
+*
+*	Callback function to be called to put every Suspendable to suspend
+*
+********************************************/  
+int PowerManager::suspend() {
+	int ret = 0;
+
+	// First we set the suspend flag to true
+	if (SDL_mutexP(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::suspend(): Couldn't lock flagMutex %d\n", _flagMutex);
+		ret = -1;
+	}
+
+	_suspendFlag = true;
+	
+	if (_criticalCounter > 0)
+		SDL_CondWait(_condPM, _flagMutex);
+
+	if (SDL_mutexV(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::suspend(): Couldn't unlock flagMutex %d\n", _flagMutex);
+		ret = -1;
+	}
+
+	// Loop over list, calling suspend()
+	if (SDL_mutexP(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::suspend(): Couldn't lock listMutex %d\n", _listMutex);
+		ret = -1;
+	}
+
+	Common::List<Suspendable *>::iterator i = _suspendList.begin();
+
+	for (; i != _suspendList.end(); i++) {
+		(*i)->suspend();
+	}
+
+	if (SDL_mutexV(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::suspend(): Couldn't unlock listMutex %d\n", _listMutex);
+		ret = -1;
+	}
+
+	return ret;
+}
+
+/*******************************************
+*
+*	Callback function to resume every Suspendable
+*
+********************************************/  
+int PowerManager::resume() {
+	int ret = 0;
+
+	// First we notify our Suspendables. Loop over list, calling resume()
+	if (SDL_mutexP(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::resume(): Couldn't lock listMutex %d\n", _listMutex);
+		ret = -1;
+	}
+
+	Common::List<Suspendable *>::iterator i = _suspendList.begin();
+
+	for (; i != _suspendList.end(); i++) {
+		(*i)->resume();
+	}
+
+	if (SDL_mutexV(_listMutex) != 0) {
+		PSPDebugTrace("PowerManager::resume(): Couldn't unlock listMutex %d\n", _listMutex);
+		ret = -1;
+	}
+
+	// Now we set the suspend flag to false
+	if (SDL_mutexP(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::resume(): Couldn't lock flagMutex %d\n", _flagMutex);
+		ret = -1;
+	}
+	_suspendFlag = false;
+
+	// Signal the other threads to wake up
+	if (SDL_CondBroadcast(_condSuspendable) != 0) {
+		PSPDebugTrace("PowerManager::resume(): Couldn't broadcast condition %d\n", _condSuspendable);
+		ret = -1;
+	}
+
+	if (SDL_mutexV(_flagMutex) != 0) {
+		PSPDebugTrace("PowerManager::resume(): Couldn't unlock flagMutex %d\n", _flagMutex);
+		ret = -1;
+	}
+
+	return ret;
+}

Copied: scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.h (from rev 43523, scummvm/trunk/backends/platform/psp/powerman.h)
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.h	                        (rev 0)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/powerman.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -0,0 +1,87 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef POWERMAN_H
+#define POWERMAN_H
+ 
+#include <SDL/SDL_thread.h>
+#include <SDL/SDL_mutex.h>
+#include "common/singleton.h"
+#include "common/list.h"
+ 
+ /*
+  *  Implement this class (interface) if you want to use PowerManager's suspend callback functionality
+  *
+  */
+ class Suspendable {
+ public:
+	virtual ~Suspendable() {}
+	virtual int suspend() = 0;
+	virtual int resume() = 0;
+ };
+ 
+ /****************************************************************************************************** 
+ *
+ *  This class will call a Suspendable when the PSP goes to suspend/resumes. It also provides the ability to block
+ *  a thread when the PSP is going to suspend/suspending, and to wake it up when the PSP is resumed. 
+ *	This ability is very useful for managing the PSPIoStream class, but may be found useful by other classes as well.
+ *
+ *******************************************************************************************************/
+ class PowerManager: public Common::Singleton<PowerManager> {
+private:
+	friend class Common::Singleton<PowerManager>;
+	PowerManager();
+	~PowerManager();
+
+	Common::List<Suspendable *> _suspendList;		/* list to register in */
+
+	bool _suspendFlag;								/* protected variable */
+	SDL_mutex *_flagMutex;							/* mutex to access access flag */
+	SDL_mutex *_listMutex;							/* mutex to access Suspendable list */
+	SDL_cond *_condSuspendable;						/* signal to synchronize accessing threads */
+	SDL_cond *_condPM;								/* signal to wake up the PM from a critical section */
+	int _criticalCounter;							/* Counter of how many threads are in a critical section */
+
+public:
+	int blockOnSuspend();								/* block if suspending */
+	int beginCriticalSection(bool justBlock = false);	/* Use a critical section to block (if suspend was already pressed) */
+	int endCriticalSection();							/* and to prevent the PSP from suspending in a particular section */
+	int registerSuspend(Suspendable *item);			/* register to be called to suspend/resume */
+	int unregisterSuspend(Suspendable *item);		/* remove from suspend/resume list */
+	int suspend();									/* callback to have all items in list suspend */
+	int resume();									/* callback to have all items in list resume */
+	
+	enum {
+		Error = -1,
+		NotBlocked = 0,
+		Blocked = 1		
+	};
+		
+ };
+ 
+ // For easy access
+#define PowerMan	PowerManager::instance()
+
+ #endif /* POWERMAN_H */

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp.spec
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp.spec	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp.spec	2009-08-19 01:22:43 UTC (rev 43524)
@@ -1,3 +1,3 @@
 %rename lib	old_lib
 *lib:
-%(old_lib) -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspnet_inet -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspsdk -lpspuser 
+%(old_lib) -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspnet_inet -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspuser -lpsppower 

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp_main.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp_main.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/psp/psp_main.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -31,11 +31,15 @@
 #include <pspdebug.h>
 #endif
 
+#include <psppower.h>
+
 #include <common/system.h>
 #include <engines/engine.h>
 #include <base/main.h>
 #include <base/plugins.h>
+#include "backends/platform/psp/powerman.h"
 
+
 #include "osys_psp_gu.h"
 #include "./trace.h"
 
@@ -91,18 +95,37 @@
 #endif
 
 /* Exit callback */
-SceKernelCallbackFunction exit_callback(int /*arg1*/, int /*arg2*/, void * /*common*/) {
+int exit_callback(void) {
 	sceKernelExitGame();
 	return 0;
 }
 
+/* Function for handling suspend/resume */
+void power_callback(int , int powerinfo) {
+	if (powerinfo & PSP_POWER_CB_POWER_SWITCH || powerinfo & PSP_POWER_CB_SUSPENDING) {
+		PowerMan.suspend();
+	} else if (powerinfo & PSP_POWER_CB_RESUME_COMPLETE) {
+		PowerMan.resume();
+	}
+}
+
 /* Callback thread */
 int CallbackThread(SceSize /*size*/, void *arg) {
 	int cbid;
 
 	cbid = sceKernelCreateCallback("Exit Callback", (SceKernelCallbackFunction)exit_callback, NULL);
 	sceKernelRegisterExitCallback(cbid);
+	/* Set up callbacks for PSPIoStream */
 
+	cbid = sceKernelCreateCallback("Power Callback", (SceKernelCallbackFunction)power_callback, 0);
+	if (cbid >= 0) {
+		if(scePowerRegisterCallback(-1, cbid) < 0) {
+			PSPDebugTrace("SetupCallbacks(): Couldn't register callback for power_callback\n");
+		}
+	} else {
+		PSPDebugTrace("SetupCallbacks(): Couldn't create a callback for power_callback\n");
+	}
+
 	sceKernelSleepThreadCB();
 	return 0;
 }
@@ -119,8 +142,13 @@
 
 #undef main
 int main(void) {
+	PowerManager::instance();	// Setup power manager
+
 	SetupCallbacks();
 
+	//change clock rate to 333mhz
+	scePowerSetClockFrequency(333, 333, 166);
+
 	static const char *argv[] = { "scummvm", NULL };
 	static int argc = sizeof(argv)/sizeof(char *)-1;
 
@@ -131,6 +159,8 @@
 
 	g_system->quit();	// TODO: Consider removing / replacing this!
 
+	PowerManager::destroy();	// get rid of PowerManager
+
 	sceKernelSleepThread();
 
 	return res;

Modified: scummvm/branches/gsoc2009-16bit/base/main.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/base/main.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/base/main.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -45,9 +45,12 @@
 #include "common/file.h"
 #include "common/fs.h"
 #include "common/system.h"
+
 #include "gui/GuiManager.h"
 #include "gui/message.h"
 
+#include "sound/audiocd.h"
+
 #include "backends/keymapper/keymapper.h"
 
 #if defined(_WIN32_WCE)
@@ -416,6 +419,15 @@
 			warning("Could not find any engine capable of running the selected game");
 		}
 
+		// We will destroy the AudioCDManager singleton here to save some memory.
+		// This will not make the CD audio stop, one would have to enable this:
+		//AudioCD.stop();
+		// but the engine is responsible for stopping CD playback anyway and
+		// this way we catch engines not doing it properly. For some more
+		// information about why AudioCDManager::destroy does not stop the CD
+		// playback read the FIXME in sound/audiocd.h
+		Audio::AudioCDManager::destroy();
+
 		// reset the graphics to default
 		setupGraphics(system);
 		launcherDialog();

Modified: scummvm/branches/gsoc2009-16bit/common/stream.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/common/stream.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/common/stream.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -400,6 +400,7 @@
 /**
  * SubReadStream provides access to a ReadStream restricted to the range
  * [currentPosition, currentPosition+end).
+ *
  * Manipulating the parent stream directly /will/ mess up a substream.
  * Likewise, manipulating two substreams of a parent stream will cause them to
  * step on each others toes.
@@ -434,6 +435,9 @@
  * SeekableSubReadStream provides access to a SeekableReadStream restricted to
  * the range [begin, end).
  * The same caveats apply to SeekableSubReadStream as do to SeekableReadStream.
+ *
+ * Manipulating the parent stream directly /will/ mess up a substream.
+ * @see SubReadStream
  */
 class SeekableSubReadStream : public SubReadStream, public SeekableReadStream {
 protected:
@@ -451,6 +455,9 @@
 /**
  * This is a wrapper around SeekableSubReadStream, but it adds non-endian
  * read methods whose endianness is set on the stream creation.
+ *
+ * Manipulating the parent stream directly /will/ mess up a substream.
+ * @see SubReadStream
  */
 class SeekableSubReadStreamEndian : public SeekableSubReadStream {
 public:

Modified: scummvm/branches/gsoc2009-16bit/configure
===================================================================
--- scummvm/branches/gsoc2009-16bit/configure	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/configure	2009-08-19 01:22:43 UTC (rev 43524)
@@ -1181,7 +1181,7 @@
 		# TODO nds
 		;;
 	psp)
-		CXXFLAGS="$CXXFLAGS -O2 -G0 -I$PSPDEV/psp/sdk/include -D_PSP_FW_VERSION=150"
+		CXXFLAGS="$CXXFLAGS -O3 -G0 -I$PSPDEV/psp/sdk/include -D_PSP_FW_VERSION=150"
 		;;
 	wince)
 		CXXFLAGS="$CXXFLAGS -O3 -march=armv4 -mtune=xscale -D_WIN32_WCE=300 -D__ARM__ -D_ARM_ -DUNICODE -DFPM_DEFAULT -DNONSTANDARD_PORT"
@@ -2085,7 +2085,7 @@
 		# TODO nds
 		;;
 	psp)
-		DEFINES="$DEFINES -D__PSP__ -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE"
+		DEFINES="$DEFINES -D__PSP__ -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DDISABLE_DOSBOX_OPL"
 		INCLUDES="$INCLUDES -I$PSPDEV/psp/include/SDL"
 		LIBS="$LIBS -lSDL"
 		;;

Modified: scummvm/branches/gsoc2009-16bit/engines/agi/cycle.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/agi/cycle.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/agi/cycle.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -266,8 +266,8 @@
 			}
 
 			// commented out to close Sarien bug #438872
-			if (key)
-				_game.keypress = key;
+			//if (key)
+			//	_game.keypress = key;
 		}
 		break;
 	case INPUT_GETSTRING:

Modified: scummvm/branches/gsoc2009-16bit/engines/agi/menu.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/agi/menu.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/agi/menu.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -408,6 +408,7 @@
 		if (d->enabled) {
 			debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event);
 			_vm->_game.controllerOccured[d->event] = true;
+			_vm->_menuSelected = true;
 			goto exit_menu;
 		}
 		break;

Modified: scummvm/branches/gsoc2009-16bit/engines/agos/agos.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/agos/agos.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/agos/agos.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -899,7 +899,7 @@
 	if (_driver)
 		delete _driver;
 
-	AudioCD.destroy();
+	AudioCD.stop();
 
 	for (uint i = 0; i < _itemHeap.size(); i++) {
 		delete[] _itemHeap[i];

Modified: scummvm/branches/gsoc2009-16bit/engines/cruise/cruise_main.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/cruise/cruise_main.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/cruise/cruise_main.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -1738,7 +1738,7 @@
 			// Delay for the specified amount of time, but still respond to events
 			bool skipEvents = false;
 
-			while (currentTick < lastTick + _gameSpeed) {
+			do {
 				g_system->delayMillis(10);
 				currentTick = g_system->getMillis();
 
@@ -1749,7 +1749,7 @@
 
 				if (_vm->getDebugger()->isAttached())
 					_vm->getDebugger()->onFrame();
-			}
+			} while (currentTick < lastTick + _gameSpeed);
 		} else {
 			manageEvents();
 

Modified: scummvm/branches/gsoc2009-16bit/engines/drascula/drascula.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/drascula/drascula.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/drascula/drascula.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -106,6 +106,7 @@
 
 DrasculaEngine::~DrasculaEngine() {
 	delete _rnd;
+	stopSound();
 
 	free(_charMap);
 	free(_itemLocations);

Modified: scummvm/branches/gsoc2009-16bit/engines/gob/inter.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/gob/inter.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/gob/inter.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -560,6 +560,7 @@
 	bool oPlaytoons_checkData(OpFuncParams &params);
 	void oPlaytoons_CD_20_23();
 	void oPlaytoons_CD_25();
+	void oPlaytoons_openItk();
 };
 
 } // End of namespace Gob

Modified: scummvm/branches/gsoc2009-16bit/engines/gob/inter_playtoons.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/gob/inter_playtoons.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/gob/inter_playtoons.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -27,6 +27,7 @@
 
 #include "gob/gob.h"
 #include "gob/inter.h"
+#include "gob/helper.h"
 #include "gob/global.h"
 #include "gob/util.h"
 #include "gob/dataio.h"
@@ -70,6 +71,7 @@
 	OPCODEDRAW(0x20, oPlaytoons_CD_20_23);
 	OPCODEDRAW(0x23, oPlaytoons_CD_20_23);
 	OPCODEDRAW(0x25, oPlaytoons_CD_25);
+	OPCODEDRAW(0x85, oPlaytoons_openItk);
 }
 
 void Inter_Playtoons::setupOpcodesFunc() {
@@ -137,5 +139,25 @@
 	_vm->_game->_script->readVarIndex();
 }
 
+void Inter_Playtoons::oPlaytoons_openItk() {
+	char fileName[128];
+	char *backSlash;
 
+	_vm->_game->_script->evalExpr(0);
+	strncpy0(fileName, _vm->_game->_script->getResultStr(), 124);
+
+	if (!strchr(fileName, '.'))
+		strcat(fileName, ".ITK");
+
+	// Workaround for Bambou : In the script, the path is hardcoded (!!)
+	if ((backSlash = strrchr(fileName, '\\'))) {
+		debugC(2, kDebugFileIO, "Opening ITK file \"%s\" instead of \"%s\"", backSlash + 1, fileName);
+		_vm->_dataIO->openDataFile(backSlash + 1, true);
+	} else
+		_vm->_dataIO->openDataFile(fileName, true);
+	// All the other checks are meant to verify (if not found at the first try)
+	// if the file is present on the CD or not. As everything is supposed to 
+	// be copied, those checks are skipped
+}
+
 } // End of namespace Gob

Modified: scummvm/branches/gsoc2009-16bit/engines/gob/sound/cdrom.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/gob/sound/cdrom.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/gob/sound/cdrom.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -46,6 +46,7 @@
 }
 
 CDROM::~CDROM() {
+	stop();
 }
 
 void CDROM::readLIC(DataStream &stream) {

Modified: scummvm/branches/gsoc2009-16bit/engines/groovie/music.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/groovie/music.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/groovie/music.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -38,6 +38,10 @@
 	_prevCDtrack(0), _backgroundDelay(0) {
 }
 
+MusicPlayer::~MusicPlayer() {
+	AudioCD.stop();
+}
+
 void MusicPlayer::playSong(uint32 fileref) {
 	Common::StackLock lock(_mutex);
 

Modified: scummvm/branches/gsoc2009-16bit/engines/groovie/music.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/groovie/music.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/groovie/music.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -37,7 +37,7 @@
 class MusicPlayer {
 public:
 	MusicPlayer(GroovieEngine *vm);
-	virtual ~MusicPlayer() {}
+	virtual ~MusicPlayer();
 
 	void playSong(uint32 fileref);
 	void setBackgroundSong(uint32 fileref);

Modified: scummvm/branches/gsoc2009-16bit/engines/kyra/screen.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/kyra/screen.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/kyra/screen.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -1253,8 +1253,7 @@
 	}
 
 	if (flags & 0x200) {
-		++_drawShapeVar1;
-		_drawShapeVar1 &= (_vm->gameFlags().gameID == GI_KYRA1) ? 0x7 : 0xF;
+		_drawShapeVar1 = (_drawShapeVar1 + 1) & 0x7;
 		_drawShapeVar3 = drawShapeVar2[_drawShapeVar1];
 		_drawShapeVar4 = 0;
 		_drawShapeVar5 = 256;

Modified: scummvm/branches/gsoc2009-16bit/engines/kyra/sequences_lok.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/kyra/sequences_lok.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/kyra/sequences_lok.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -1134,6 +1134,11 @@
 	_seqPlayerFlag = false;
 
 	_screen->showMouse();
+
+	// To avoid any remaining input events, we remove the queue
+	// over here.
+	_eventList.clear();
+
 	if (_flags.platform == Common::kPlatformAmiga) {
 		_screen->_charWidth = -2;
 		_screen->setCurPage(2);
@@ -1354,15 +1359,12 @@
 	}
 
 	int size = 0;
-	const uint8 *bufferTmp = _staticres->loadRawData(k1CreditsStrings, size);
-	char *buffer = new char[size];
-	assert(buffer);
-	memcpy(buffer, bufferTmp, size);
+	const char *creditsData = (const char *)_staticres->loadRawData(k1CreditsStrings, size);
 
 	char stringBuffer[81];
 	memset(stringBuffer, 0, sizeof(stringBuffer));
 
-	char *cur = buffer;
+	const char *cur = creditsData;
 	char *specialString = stringBuffer;
 	bool fillRectFlag = false, subWidth = false, centerFlag = false;
 	x = 0;
@@ -1424,9 +1426,7 @@
 			removeInputTop();
 			break;
 		}
-	} while (++cur != buffer + size && !shouldQuit());
-
-	delete[] buffer;
+	} while (++cur != (creditsData + size) && !shouldQuit());
 }
 
 bool KyraEngine_LoK::seq_skipSequence() const {

Modified: scummvm/branches/gsoc2009-16bit/engines/lure/res.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/lure/res.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/lure/res.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -550,6 +550,7 @@
 uint16 englishLoadOffsets[] = {0x3afe, 0x41BD, 0x7167, 0x7172, 0x8617, 0x88ac, 0};
 
 Hotspot *Resources::activateHotspot(uint16 hotspotId) {
+	Resources &resources = Resources::getReference();
 	HotspotData *res = getHotspot(hotspotId);
 	if (!res) return NULL;
 	res->roomNumber &= 0x7fff; // clear any suppression bit in room #
@@ -561,7 +562,6 @@
 
 	// If it's NPC with a schedule, then activate the schedule
 	if ((res->npcScheduleId != 0) && (res->npcSchedule.isEmpty())) {
-		Resources &resources = Resources::getReference();
 		CharacterScheduleEntry *entry = resources.charSchedules().getEntry(res->npcScheduleId);
 		res->npcSchedule.addFront(DISPATCH_ACTION, entry, res->roomNumber);
 	}
@@ -621,9 +621,12 @@
 			// Special post-load handling
 			if (res->loadOffset == 3) hotspot->setPersistant(true);
 			if (res->loadOffset == 5) hotspot->handleTalkDialog();
-			if (hotspotId == CASTLE_SKORL_ID)
+			if (hotspotId == CASTLE_SKORL_ID) {
 				// The Castle skorl has a default room #99, so it needs to be adjusted dynamically
-				res->npcSchedule.top().setRoomNumber(res->roomNumber);
+				res->npcSchedule.clear();
+				CharacterScheduleEntry *entry = resources.charSchedules().getEntry(res->npcScheduleId);
+				res->npcSchedule.addFront(DISPATCH_ACTION, entry, res->roomNumber);
+			}
 
 			// TODO: Figure out why there's a room set in the animation decode for a range of characters,
 			// particularly since it doesn't seem to match what happens in-game

Modified: scummvm/branches/gsoc2009-16bit/engines/made/made.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/made/made.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/made/made.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -127,6 +127,8 @@
 }
 
 MadeEngine::~MadeEngine() {
+	AudioCD.stop();
+
 	delete _rnd;
 	delete _pmvPlayer;
 	delete _res;

Modified: scummvm/branches/gsoc2009-16bit/engines/made/pmvplayer.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/made/pmvplayer.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/made/pmvplayer.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -62,12 +62,8 @@
 	}
 
 	uint frameDelay = _fd->readUint16LE();
-	int unk;
 	_fd->skip(4);	// always 0?
-	unk = _fd->readByte();
-	debug(2, "%i", unk);
-	unk = _fd->readByte();
-	debug(2, "%i", unk);
+	uint frameCount = _fd->readUint16LE();
 	_fd->skip(4);	// always 0?
 
 	uint soundFreq = _fd->readUint16LE();
@@ -80,7 +76,7 @@
 	if (soundFreq == 22254) soundFreq = 22050;
 
 	for (int i = 0; i < 22; i++) {
-		unk = _fd->readUint16LE();
+		int unk = _fd->readUint16LE();
 		debug(2, "%i ", unk);
 	}
 
@@ -90,7 +86,7 @@
 	_fd->read(_paletteRGB, 768);
 	_vm->_screen->setRGBPalette(_paletteRGB);
 
-	uint32 frameCount = 0;
+	uint32 frameNumber = 0;
 	uint16 chunkCount = 0;
 	uint32 soundSize = 0;
 	uint32 soundChunkOfs = 0, palChunkOfs = 0;
@@ -108,7 +104,7 @@
 	// get it to work well?
 	_audioStream = Audio::makeAppendableAudioStream(soundFreq, Audio::Mixer::FLAG_UNSIGNED);
 
-	while (!_vm->shouldQuit() && !_aborted && !_fd->eos()) {
+	while (!_vm->shouldQuit() && !_aborted && !_fd->eos() && frameNumber < frameCount) {
 
 		int32 frameTime = _vm->_system->getMillis();
 
@@ -117,9 +113,6 @@
 			warning("Unknown chunk type");
 		}
 
-		if (_fd->eos())
-			break;
-
 		// Only reallocate the frame data buffer if its size has changed
 		if (prevChunkSize != chunkSize || !frameData) {
 			if (frameData)
@@ -192,7 +185,7 @@
 		updateScreen();
 
 		if (skipFrames == 0) {
-			int32 waitTime = (frameCount * frameDelay) -
+			int32 waitTime = (frameNumber * frameDelay) -
 				(g_system->getMillis() - soundStartTime) - (_vm->_system->getMillis() - frameTime);
 
 			if (waitTime < 0) {
@@ -204,7 +197,7 @@
 		} else
 			skipFrames--;
 
-		frameCount++;
+		frameNumber++;
 
 	}
 

Modified: scummvm/branches/gsoc2009-16bit/engines/made/screen.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/made/screen.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/made/screen.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -188,7 +188,7 @@
 
 	if (flipX) {
 		linePtrAdd = -1;
-		sourceAdd = sourceSurface->w;
+		sourceAdd = sourceSurface->w - 1;
 	} else {
 		linePtrAdd = 1;
 		sourceAdd = 0;
@@ -210,6 +210,7 @@
 			}
 			linePtr += linePtrAdd;
 		}
+
 		source += sourcePitch;
 		dest += clipInfo.destSurface->pitch;
 		if (_vm->getGameID() != GID_RTZ)

Modified: scummvm/branches/gsoc2009-16bit/engines/saga/actor.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/saga/actor.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/saga/actor.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -183,8 +183,8 @@
 
 struct PathDirectionData {
 	int8 direction;
-	int x;
-	int y;
+	int16 x;
+	int16 y;
 };
 
 struct ActorFrameRange {

Modified: scummvm/branches/gsoc2009-16bit/engines/saga/music.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/saga/music.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/saga/music.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -41,190 +41,6 @@
 #define BUFFER_SIZE 4096
 #define MUSIC_SUNSPOT 26
 
-class DigitalMusicInputStream : public Audio::AudioStream {
-private:
-	Audio::AudioStream *_compressedStream;
-	ResourceContext *_context;
-	ResourceData * resourceData;
-	GameSoundTypes soundType;
-	Common::File *_file;
-	uint32 _filePos;
-	uint32 _startPos;
-	uint32 _endPos;
-	bool _finished;
-	bool _looping;
-	int16 _buf[BUFFER_SIZE];
-	const int16 *_bufferEnd;
-	const int16 *_pos;
-	MemoryReadStream *_memoryStream;
-	SagaEngine *_vm;
-
-	void refill();
-	bool eosIntern() const {
-		return _pos >= _bufferEnd;
-	}
-
-public:
-	DigitalMusicInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping, uint32 loopStart);
-	~DigitalMusicInputStream();
-
-	void createCompressedStream();
-
-	int readBuffer(int16 *buffer, const int numSamples);
-
-	bool endOfData() const	{ return eosIntern(); }
-	bool isStereo() const	{
-		// The digital music in the ITE Mac demo version is not stereo
-		return _vm->getFeatures() & GF_MONO_MUSIC ? false : true;
-	}
-	int getRate() const	{ return 11025; }
-};
-
-DigitalMusicInputStream::DigitalMusicInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping, uint32 loopStart)
-	: _vm(vm), _context(context), _finished(false), _looping(looping), _bufferEnd(_buf + BUFFER_SIZE) {
-
-	byte compressedHeader[10];
-
-	resourceData = context->getResourceData(resourceId);
-	_file = context->getFile(resourceData);
-
-	_compressedStream = NULL;
-
-	if (context->isCompressed) {
-		// Read compressed header to determine compression type
-		_file->seek((long)resourceData->offset, SEEK_SET);
-		_file->read(compressedHeader, 9);
-
-		if (compressedHeader[0] == char(0)) {
-			soundType = kSoundMP3;
-		} else if (compressedHeader[0] == char(1)) {
-			soundType = kSoundOGG;
-		} else if (compressedHeader[0] == char(2)) {
-			soundType = kSoundFLAC;
-		}
-
-		createCompressedStream();
-	}
-
-	// Determine the end position
-	_filePos = resourceData->offset;
-	_endPos = _filePos + resourceData->size;
-
-	if (_compressedStream != NULL) {
-		_filePos += 9;	// skip compressed header
-		_endPos -= 9;	// decrease size by the size of the compressed header
-	}
-
-	_startPos = _filePos + loopStart;
-	if (_startPos >= _endPos)
-		_startPos = _filePos;
-
-	// Read in initial data
-	refill();
-}
-
-DigitalMusicInputStream::~DigitalMusicInputStream() {
-	delete _compressedStream;
-}
-
-void DigitalMusicInputStream::createCompressedStream() {
-#if defined(USE_MAD) || defined(USE_VORBIS) || defined(USE_FLAC)
-	uint numLoops = _looping ? 0 : 1;
-#endif
-	_memoryStream = _file->readStream(resourceData->size - 9);
-
-	switch (soundType) {
-#ifdef USE_MAD
-		case kSoundMP3:
-			debug(1, "Playing MP3 compressed digital music");
-			_compressedStream = Audio::makeMP3Stream(_memoryStream, true, 0, 0, numLoops);
-			break;
-#endif
-#ifdef USE_VORBIS
-		case kSoundOGG:
-			debug(1, "Playing OGG compressed digital music");
-			_compressedStream = Audio::makeVorbisStream(_memoryStream, true, 0, 0, numLoops);
-			break;
-#endif
-#ifdef USE_FLAC
-		case kSoundFLAC:
-			debug(1, "Playing FLAC compressed digital music");
-			_compressedStream = Audio::makeFlacStream(_memoryStream, true, 0, 0, numLoops);
-			break;
-#endif
-		default:
-			// Unknown compression
-			error("Trying to play compressed digital music, but the compression is not known");
-			break;
-	}
-}
-
-int DigitalMusicInputStream::readBuffer(int16 *buffer, const int numSamples) {
-	if (_compressedStream != NULL)
-		return _compressedStream->readBuffer(buffer, numSamples);
-
-	int samples = 0;
-	int len = 0;
-
-	while (samples < numSamples && !eosIntern()) {
-		len = MIN(numSamples - samples, (int) (_bufferEnd - _pos));
-		memcpy(buffer, _pos, len * 2);
-		buffer += len;
-		_pos += len;
-		samples += len;
-		if (_pos >= _bufferEnd)
-			refill();
-	}
-	return samples;
-}
-
-void DigitalMusicInputStream::refill() {
-	if (_finished)
-		return;
-
-	uint32 lengthLeft;
-	byte *ptr = (byte *) _buf;
-
-	_file->seek(_filePos, SEEK_SET);
-
-	if (_looping)
-		lengthLeft = 2 * BUFFER_SIZE;
-	else
-		lengthLeft = MIN((uint32) (2 * BUFFER_SIZE), _endPos - _filePos);
-
-	while (lengthLeft > 0) {
-		uint32 len = _file->read(ptr, MIN(lengthLeft, _endPos - _file->pos()));
-
-		if (len & 1)
-			len--;
-
-#ifdef SCUMM_BIG_ENDIAN
-		if (!_context->isBigEndian) {
-#else
-		if (_context->isBigEndian) {
-#endif
-			uint16 *ptr16 = (uint16 *)ptr;
-			for (uint32 i = 0; i < (len / 2); i++)
-				ptr16[i] = SWAP_BYTES_16(ptr16[i]);
-		}
-
-		lengthLeft -= len;
-		ptr += len;
-
-		if (lengthLeft > 0)
-			_file->seek(_startPos);
-	}
-
-	_filePos = _file->pos();
-	_pos = _buf;
-	_bufferEnd = (int16 *)ptr;
-
-	if (!_looping && _filePos >= _endPos) {
-		_finished = true;
-	}
-}
-
-
 MusicPlayer::MusicPlayer(MidiDriver *driver) : _parser(0), _driver(driver), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false) {
 	memset(_channel, 0, sizeof(_channel));
 	_masterVolume = 0;
@@ -461,9 +277,7 @@
 	sprintf(trackName[1], "track%02d", realTrackNumber);
 	Audio::AudioStream *stream = 0;
 	for (int i = 0; i < 2; ++i) {
-		// We multiply by 40 / 3 = 1000 / 75 to convert frames to milliseconds
-		// FIXME: Do we really want a duration of 10000 frames = 133 seconds, or is that just a random value?
-		stream = Audio::AudioStream::openStreamFile(trackName[i], 0, 10000 * 40 / 3, (flags == MUSIC_LOOP) ? 0 : 1);
+		stream = Audio::AudioStream::openStreamFile(trackName[i], 0, 0, (flags == MUSIC_LOOP) ? 0 : 1);
 		if (stream) {
 			_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, stream);
 			_digitalMusic = true;
@@ -474,15 +288,48 @@
 	if (_vm->getGameId() == GID_ITE) {
 		if (resourceId >= 9 && resourceId <= 34) {
 			if (_digitalMusicContext != NULL) {
-				//TODO: check resource size
 				loopStart = 0;
-				// fix ITE sunstatm/sunspot score
-				if ((_vm->getGameId() == GID_ITE) && (resourceId == MUSIC_SUNSPOT)) {
+				// Fix ITE sunstatm/sunspot score
+				if (resourceId == MUSIC_SUNSPOT)
 					loopStart = 4 * 18727;
-				}
 
-				// digital music
-				audioStream = new DigitalMusicInputStream(_vm, _digitalMusicContext, resourceId - 9, flags == MUSIC_LOOP, loopStart);
+				// Digital music
+				ResourceData *resData = _digitalMusicContext->getResourceData(resourceId - 9);
+				Common::File *musicFile = _digitalMusicContext->getFile(resData);
+				int offs = (_digitalMusicContext->isCompressed) ? 9 : 0;
+
+				Common::SeekableSubReadStream *musicStream = new Common::SeekableSubReadStream(musicFile, 
+							(uint32)resData->offset + offs, (uint32)resData->offset + resData->size - offs);
+
+				if (!_digitalMusicContext->isCompressed) {
+					byte musicFlags = Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_STEREO | 
+										Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN;
+					if (flags == MUSIC_LOOP)
+						musicFlags |= Audio::Mixer::FLAG_LOOP;
+
+					Audio::LinearDiskStreamAudioBlock audioBlocks[1];
+					audioBlocks[0].pos = 0;
+					audioBlocks[0].len = resData->size / 2;	// 16-bit sound
+					audioStream = Audio::makeLinearDiskStream(musicStream, audioBlocks, 1, 11025, musicFlags, false, loopStart, 0);
+				} else {
+					// Read compressed header to determine compression type
+					musicFile->seek((uint32)resData->offset, SEEK_SET);
+					byte identifier = musicFile->readByte();
+
+					if (identifier == 0) {		// MP3
+#ifdef USE_MAD
+						audioStream = Audio::makeMP3Stream(musicStream, false, 0, 0, (flags == MUSIC_LOOP ? 0 : 1));
+#endif
+					} else if (identifier == 1) {	// OGG
+#ifdef USE_VORBIS
+						audioStream = Audio::makeVorbisStream(musicStream, false, 0, 0, (flags == MUSIC_LOOP ? 0 : 1));
+#endif
+					} else if (identifier == 2) {	// FLAC
+#ifdef USE_FLAC
+						audioStream = Audio::makeFlacStream(musicStream, false, 0, 0, (flags == MUSIC_LOOP ? 0 : 1));
+#endif
+					}
+				}
 			}
 		}
 	}

Modified: scummvm/branches/gsoc2009-16bit/engines/saga/sndres.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/saga/sndres.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/saga/sndres.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -192,7 +192,6 @@
 	GameSoundTypes resourceType = kSoundPCM;
 	byte *data = 0;
 	int rate = 0, size = 0;
-	byte flags = 0;
 	Common::File* file;
 
 	if (resourceId == (uint32)-1) {
@@ -269,21 +268,17 @@
 
 	}
 
-	// Default sound type is 16-bit PCM (used in ITE)
-	buffer.isBigEndian = context->isBigEndian;
-	if ((context->fileType & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
-		buffer.isBigEndian = false;
+	// Default sound type is 16-bit signed PCM, used in ITE by PCM and VOX files
 	buffer.isCompressed = context->isCompressed;
 	buffer.soundType = resourceType;
 	buffer.originalSize = 0;
-	buffer.stereo = false;
-	buffer.isSigned = true;			// default for PCM and VOX
-	buffer.frequency = 22050;		// default for PCM and VOX
-	buffer.sampleBits = 16;			// default for PCM and VOX
+	// Set default flags and frequency for PCM, VOC and VOX files, which got no header
+	buffer.flags = Audio::Mixer::FLAG_16BITS;
+	buffer.frequency = 22050;
 	if (_vm->getGameId() == GID_ITE) {
 		if (_vm->getFeatures() & GF_8BIT_UNSIGNED_PCM) {	// older ITE demos
-			buffer.isSigned = false;
-			buffer.sampleBits = 8;
+			buffer.flags |= Audio::Mixer::FLAG_UNSIGNED;
+			buffer.flags &= ~Audio::Mixer::FLAG_16BITS;
 		} else {
 			// Voice files in newer ITE demo versions are OKI ADPCM (VOX) encoded
 			if (!scumm_stricmp(context->fileName, "voicesd.rsc"))
@@ -292,6 +287,12 @@
 	}
 	buffer.buffer = NULL;
 
+	// Check for LE sounds
+	if (!context->isBigEndian)
+		buffer.flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+	if ((context->fileType & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
+		buffer.flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+
 	// Older Mac versions of ITE were Macbinary packed
 	int soundOffset = (context->fileType & GAME_MACBINARY) ? 36 : 0;
 
@@ -321,25 +322,23 @@
 	case kSoundShorten:
 	case kSoundVOC:
 		if (resourceType == kSoundWAV) {
-			result = Audio::loadWAVFromStream(readS, size, rate, flags);
+			result = Audio::loadWAVFromStream(readS, size, rate, buffer.flags);
 		} else if (resourceType == kSoundAIFF) {
-			result = Audio::loadAIFFFromStream(readS, size, rate, flags);
+			result = Audio::loadAIFFFromStream(readS, size, rate, buffer.flags);
+#ifdef ENABLE_SAGA2
+		} else if (resourceType == kSoundShorten) {
+			result = Audio::loadShortenFromStream(readS, size, rate, buffer.flags);
+#endif
 		} else if (resourceType == kSoundVOC) {
 			data = Audio::loadVOCFromStream(readS, size, rate);
 			result = (data != 0);
 			if (onlyHeader)
 				free(data);
-#ifdef ENABLE_SAGA2
-		} else if (resourceType == kSoundShorten) {
-			result = Audio::loadShortenFromStream(readS, size, rate, flags);
-#endif
+			buffer.flags |= Audio::Mixer::FLAG_UNSIGNED;
 		}
 
 		if (result) {
 			buffer.frequency = rate;
-			buffer.sampleBits = (flags & Audio::Mixer::FLAG_16BITS) ? 16 : 8;
-			buffer.stereo = flags & Audio::Mixer::FLAG_STEREO;
-			buffer.isSigned = (resourceType == kSoundVOC) ? false : !(flags & Audio::Mixer::FLAG_UNSIGNED);
 			buffer.size = size;
 
 			if (!onlyHeader && resourceType != kSoundVOC) {
@@ -360,14 +359,20 @@
 		readS.readByte();	// Skip compression identifier byte
 		buffer.frequency = readS.readUint16LE();
 		buffer.originalSize = readS.readUint32LE();
-		buffer.sampleBits = readS.readByte();
-		buffer.stereo = (readS.readByte() == char(0)) ? false : true;
+		if (readS.readByte() == 8)	// read sample bits
+			buffer.flags &= ~Audio::Mixer::FLAG_16BITS;
+		if (readS.readByte() != 0)	// read stereo flag
+			buffer.flags |= Audio::Mixer::FLAG_STEREO;
 
 		buffer.size = soundResourceLength;
 		buffer.soundType = resourceType;
-		buffer.soundFile = context->getFile(resourceData);
 		buffer.fileOffset = resourceData->offset + 9; // skip compressed sfx header: byte + uint16 + uint32 + byte + byte
 
+		if (!onlyHeader) {
+			buffer.buffer = (byte *)malloc(buffer.size);
+			readS.read(buffer.buffer, buffer.size);
+		}
+
 		result = true;
 		break;
 	default:
@@ -403,12 +408,12 @@
 		msDouble = (double)buffer.size;
 	else
 		msDouble = (double)buffer.originalSize;
-	if (buffer.sampleBits == 16) {
+
+	if (buffer.flags & Audio::Mixer::FLAG_16BITS)
 		msDouble /= 2.0;
-	}
-	if (buffer.stereo) {
+
+	if (buffer.flags & Audio::Mixer::FLAG_STEREO)
 		msDouble /= 2.0;
-	}
 
 	msDouble = msDouble / buffer.frequency * 1000.0;
 	return (int)msDouble;

Modified: scummvm/branches/gsoc2009-16bit/engines/saga/sound.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/saga/sound.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/saga/sound.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -65,84 +65,45 @@
 
 void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume,
 				sndHandleType handleType, bool loop) {
-	byte flags;
 
-	flags = Audio::Mixer::FLAG_AUTOFREE;
+	buffer.flags |= Audio::Mixer::FLAG_AUTOFREE;
 
 	if (loop)
-		flags |= Audio::Mixer::FLAG_LOOP;
+		buffer.flags |= Audio::Mixer::FLAG_LOOP;
 
-	if (buffer.sampleBits == 16) {
-		flags |= Audio::Mixer::FLAG_16BITS;
+	Audio::Mixer::SoundType soundType = (handleType == kVoiceHandle) ? 
+				Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
 
-		if (!buffer.isBigEndian)
-			flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
-	}
-	if (buffer.stereo)
-		flags |= Audio::Mixer::FLAG_STEREO;
-	if (!buffer.isSigned)
-		flags |= Audio::Mixer::FLAG_UNSIGNED;
-
 	if (!buffer.isCompressed) {
-		if (handleType == kVoiceHandle)
-			_mixer->playRaw(Audio::Mixer::kSpeechSoundType, handle, buffer.buffer,
-					buffer.size, buffer.frequency, flags, -1, volume);
-		else
-			_mixer->playRaw(Audio::Mixer::kSFXSoundType, handle, buffer.buffer,
-					buffer.size, buffer.frequency, flags, -1, volume);
+		_mixer->playRaw(soundType, handle, buffer.buffer,
+				buffer.size, buffer.frequency, buffer.flags, -1, volume);
 	} else {
-		Audio::AudioStream *stream = NULL;
-#if defined(USE_MAD) || defined(USE_VORBIS) || defined(USE_FLAC)
-		MemoryReadStream *tmp = NULL;
-#endif
+		Audio::AudioStream *stream = 0;
 
 		switch (buffer.soundType) {
 #ifdef USE_MAD
 			case kSoundMP3:
-				debug(1, "Playing MP3 compressed sound");
-				buffer.soundFile->seek((long)buffer.fileOffset, SEEK_SET);
-				tmp = buffer.soundFile->readStream(buffer.size);
-				assert(tmp);
-				stream = Audio::makeMP3Stream(tmp, true);
+				stream = Audio::makeMP3Stream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
 				break;
 #endif
 #ifdef USE_VORBIS
 			case kSoundOGG:
-				debug(1, "Playing OGG compressed sound");
-				buffer.soundFile->seek((long)buffer.fileOffset, SEEK_SET);
-				tmp = buffer.soundFile->readStream(buffer.size);
-				assert(tmp);
-				stream = Audio::makeVorbisStream(tmp, true);
+				stream = Audio::makeVorbisStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
 				break;
 #endif
 #ifdef USE_FLAC
 			case kSoundFLAC:
-				debug(1, "Playing FLAC compressed sound");
-				buffer.soundFile->seek((long)buffer.fileOffset, SEEK_SET);
-				tmp = buffer.soundFile->readStream(buffer.size);
-				assert(tmp);
-				stream = Audio::makeFlacStream(tmp, true);
+				stream = Audio::makeFlacStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
 				break;
 #endif
 			default:
-				// No compression, play it as raw sound
-				if (handleType == kVoiceHandle)
-					_mixer->playRaw(Audio::Mixer::kSpeechSoundType, handle, buffer.buffer,
-							buffer.size, buffer.frequency, flags, -1, volume);
-				else
-					_mixer->playRaw(Audio::Mixer::kSFXSoundType, handle, buffer.buffer,
-							buffer.size, buffer.frequency, flags, -1, volume);
+				// Unknown compression, ignore sample
+				warning("Unknown compression, ignoring sound");
 				break;
 		}
 
-		if (stream != NULL) {
-			if (handleType == kVoiceHandle)
-				_mixer->playInputStream(Audio::Mixer::kSpeechSoundType, handle, stream, -1,
-							volume, 0, true, false);
-			else
-				_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, stream, -1,
-							volume, 0, true, false);
-		}
+		if (stream != NULL)
+			_mixer->playInputStream(soundType, handle, stream, -1, volume, 0, true, false);
 	}
 }
 

Modified: scummvm/branches/gsoc2009-16bit/engines/saga/sound.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/saga/sound.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/saga/sound.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -44,17 +44,13 @@
 
 struct SoundBuffer {
 	uint16 frequency;
-	int sampleBits;
-	bool stereo;
-	bool isSigned;
 	bool isCompressed;
+	byte flags;
 
 	byte *buffer;
 	size_t size;
 	size_t originalSize;
-	bool isBigEndian;
 	GameSoundTypes soundType;
-	Common::File *soundFile;
 	size_t fileOffset;
 };
 

Modified: scummvm/branches/gsoc2009-16bit/engines/sci/console.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/sci/console.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/sci/console.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -889,10 +889,11 @@
 
 bool Console::cmdClassTable(int argc, const char **argv) {
 	DebugPrintf("Available classes:\n");
-	for (uint i = 0; i < _vm->_gamestate->_classtable.size(); i++) {
-		if (_vm->_gamestate->_classtable[i].reg.segment) {
+	for (uint i = 0; i < _vm->_gamestate->seg_manager->_classtable.size(); i++) {
+		if (_vm->_gamestate->seg_manager->_classtable[i].reg.segment) {
 			DebugPrintf(" Class 0x%x at %04x:%04x (script 0x%x)\n", i, 
-					PRINT_REG(_vm->_gamestate->_classtable[i].reg), _vm->_gamestate->_classtable[i].script);
+					PRINT_REG(_vm->_gamestate->seg_manager->_classtable[i].reg), 
+					_vm->_gamestate->seg_manager->_classtable[i].script);
 		}
 	}
 
@@ -1394,10 +1395,11 @@
 		for (uint i = 0; i < scr->_objects.size(); i++) {
 			DebugPrintf("    ");
 			// Object header
-			Object *obj = obj_get(_vm->_gamestate, scr->_objects[i].pos);
+			Object *obj = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, scr->_objects[i].pos);
 			if (obj)
 				DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(scr->_objects[i].pos), 
-							obj_get_name(_vm->_gamestate, scr->_objects[i].pos), obj->_variables.size(), obj->methods_nr);
+							obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, 
+							scr->_objects[i].pos), obj->_variables.size(), obj->methods_nr);
 		}
 	}
 	break;
@@ -1438,12 +1440,13 @@
 				reg_t objpos;
 				objpos.offset = i;
 				objpos.segment = nr;
-				DebugPrintf("  [%04x] %s; copy of ", i, obj_get_name(_vm->_gamestate, objpos));
+				DebugPrintf("  [%04x] %s; copy of ", i, obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, objpos));
 				// Object header
-				Object *obj = obj_get(_vm->_gamestate, ct->_table[i].pos);
+				Object *obj = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, ct->_table[i].pos);
 				if (obj)
 					DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(ct->_table[i].pos), 
-								obj_get_name(_vm->_gamestate, ct->_table[i].pos), obj->_variables.size(), obj->methods_nr);
+								obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, ct->_table[i].pos), 
+								obj->_variables.size(), obj->methods_nr);
 			}
 	}
 	break;
@@ -2045,7 +2048,7 @@
 	for (iter = _vm->_gamestate->_executionStack.begin();
 	     iter != _vm->_gamestate->_executionStack.end(); ++iter, ++i) {
 		ExecStack &call = *iter;
-		const char *objname = obj_get_name(_vm->_gamestate, call.sendp);
+		const char *objname = obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, call.sendp);
 		int paramc, totalparamc;
 
 		switch (call.type) {
@@ -2187,7 +2190,7 @@
 		return true;
 	}
 
-	Object *obj = obj_get(_vm->_gamestate, objAddr);
+	Object *obj = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, objAddr);
 	int selector_id = _vm->getKernel()->findSelector(argv[2]);
 	reg_t addr;
 
@@ -2295,7 +2298,7 @@
 		return true;
 	}
 
-	o = obj_get(_vm->_gamestate, object);
+	o = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, object);
 	if (o == NULL) {
 		DebugPrintf("Address \"%04x:%04x\" is not an object\n", PRINT_REG(object));
 		return true;
@@ -2900,7 +2903,7 @@
 				}
 
 				if (valid) {
-					const char *objname = obj_get_name(s, objpos);
+					const char *objname = obj_get_name(s->seg_manager, s->_version, objpos);
 					if (!strcmp(objname, str_objname)) {
 						// Found a match!
 						if ((index < 0) && (times_found > 0)) {
@@ -3042,9 +3045,10 @@
 
 int Console::printObject(reg_t pos) {
 	EngineState *s = _vm->_gamestate;	// for the several defines in this function
-	Object *obj = obj_get(s, pos);
+	Object *obj = obj_get(s->seg_manager, s->_version, pos);
 	Object *var_container = obj;
 	int i;
+	SciVersion version = s->_version;	// for the selector defines
 
 	if (!obj) {
 		DebugPrintf("[%04x:%04x]: Not an object.", PRINT_REG(pos));
@@ -3052,11 +3056,11 @@
 	}
 
 	// Object header
-	DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(pos), obj_get_name(s, pos),
+	DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(pos), obj_get_name(s->seg_manager, s->_version, pos),
 				obj->_variables.size(), obj->methods_nr);
 
 	if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS))
-		var_container = obj_get(s, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]);
+		var_container = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]);
 	DebugPrintf("  -- member variables:\n");
 	for (i = 0; (uint)i < obj->_variables.size(); i++) {
 		printf("    ");
@@ -3068,9 +3072,9 @@
 		reg_t val = obj->_variables[i];
 		DebugPrintf("%04x:%04x", PRINT_REG(val));
 
-		Object *ref = obj_get(s, val);
+		Object *ref = obj_get(s->seg_manager, s->_version, val);
 		if (ref)
-			DebugPrintf(" (%s)", obj_get_name(s, val));
+			DebugPrintf(" (%s)", obj_get_name(s->seg_manager, s->_version, val));
 
 		DebugPrintf("\n");
 	}

Modified: scummvm/branches/gsoc2009-16bit/engines/sci/console.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/sci/console.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/sci/console.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -29,6 +29,7 @@
 #define SCI_CONSOLE_H
 
 #include "gui/debugger.h"
+#include "sci/engine/vm.h"
 
 namespace Sci {
 

Modified: scummvm/branches/gsoc2009-16bit/engines/sci/debug.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/sci/debug.h	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/sci/debug.h	2009-08-19 01:22:43 UTC (rev 43524)
@@ -26,6 +26,9 @@
 #ifndef SCI_DEBUG_H
 #define SCI_DEBUG_H
 
+#include "sci/engine/vm_types.h"	// for StackPtr
+#include "sci/engine/vm.h"			// for ExecStack
+
 namespace Sci {
 
 enum DebugSeeking {

Modified: scummvm/branches/gsoc2009-16bit/engines/sci/detection.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/sci/detection.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/sci/detection.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -27,7 +27,9 @@
 #include "base/plugins.h"
 
 #include "sci/sci.h"
+#include "sci/engine/kernel.h"
 #include "sci/exereader.h"
+#include "sci/engine/seg_manager.h"
 
 namespace Sci {
 
@@ -3031,7 +3033,77 @@
 	const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const;
 };
 
+Common::String convertSierraGameId(Common::String sierraId) {
+	// TODO: SCI32 IDs
 
+	// TODO: astrochicken
+	// TODO: The internal id of christmas1998 is "demo"
+	if (sierraId == "card")
+		return "christmas1990";
+	// TODO: christmas1992
+	if (sierraId == "arthur")
+		return "camelot";
+	if (sierraId == "brain")
+		return "castlebrain";
+	// iceman is the same
+	// longbow is the same
+	if (sierraId == "eco")
+		return "ecoquest";
+	if (sierraId == "rain")
+		return "ecoquest2";
+	if (sierraId == "fp")
+		return "freddypharkas";
+	if (sierraId == "emc")
+		return "funseeker";
+	if (sierraId == "cardgames")
+		return "hoyle1";
+	if (sierraId == "solitare")
+		return "hoyle2";
+	// TODO: hoyle3
+	// TODO: hoyle4
+	if (sierraId == "kq1")
+		return "kq1sci";
+	if (sierraId == "kq4")
+		return "kq4sci";
+	if (sierraId == "lsl1")
+		return "lsl1sci";
+	// lsl2 is the same
+	// lsl3 is the same
+	// lsl5 is the same
+	// lsl6 is the same
+	// TODO: lslcasino
+	// TODO: fairytales
+	// TODO: mothergoose
+	// TODO: msastrochicken
+	if (sierraId == "cb1")
+		return "laurabow";
+	if (sierraId == "lb2")
+		return "laurabow2";
+	// TODO: lb2 floppy (its resources can't be read)
+	if (sierraId == "twisty")
+		return "pepper";
+	// TODO: pq1sci (its resources can't be read)
+	if (sierraId == "pq")
+		return "pq2";
+	// pq3 is the same
+	if (sierraId == "glory")
+		return "qfg1";
+	// TODO: qfg1 VGA (its resources can't be read)
+	if (sierraId == "trial")
+		return "qfg2";
+	if (sierraId == "qfg1")
+		return "qfg3";
+	// TODO: slater
+	if (sierraId == "sq1")
+		return "sq1sci";
+	// sq3 is the same
+	// sq4 is the same
+	// sq5 is the same
+	// TODO: islandbrain
+
+	return sierraId;
+}
+
 const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fslist) const {
 	bool foundResMap = false;
 	bool foundRes000 = false;
@@ -3046,8 +3118,16 @@
 		Common::String filename = file->getName();
 		filename.toLowercase();
 
-		if (filename.contains("resource.map") || filename.contains("resmap.000"))
+		if (filename.contains("resource.map") || filename.contains("resmap.000")) {
+			// HACK: resource.map is located in the same directory as the other resource files,
+			// therefore add the directory here, so that the game files can be opened later on
+			// TODO/FIXME: This should be removed, as it will cause problems with game detection:
+			// if we got a game A, and then try to detect another game B, adding a default
+			// directory here means that game A's files will be opened first. We need to rewrite
+			// all the functions that access game files to use FSNodes instead
+			Common::File::addDefaultDirectory(file->getParent().getPath());
 			foundResMap = true;
+		}
 
 		if (filename.contains("resource.000") || filename.contains("resource.001")
 			|| filename.contains("ressci.000") || filename.contains("ressci.001"))
@@ -3080,12 +3160,31 @@
 		return 0;
 
 	// Set some defaults
-	s_fallbackDesc.desc.gameid = "sci";
 	s_fallbackDesc.desc.extra = "";
 	s_fallbackDesc.desc.language = Common::UNK_LANG;
 	s_fallbackDesc.desc.platform = exePlatform;
 	s_fallbackDesc.desc.flags = ADGF_NO_FLAGS;
 
+	// Determine the game id
+	ResourceManager *resMgr = new ResourceManager(fslist);
+	SciVersion version = resMgr->sciVersion();
+	Kernel *kernel = new Kernel(resMgr, true);
+	bool hasOldScriptHeader = kernel->hasOldScriptHeader();
+	delete kernel;
+
+	SegManager *segManager = new SegManager(resMgr, version, hasOldScriptHeader);
+	if (!script_instantiate(resMgr, segManager, version, hasOldScriptHeader, 0)) {
+		warning("fallbackDetect(): Could not instantiate script 0");
+		return 0;
+	}
+	reg_t game_obj = script_lookup_export(segManager, 0, 0);
+	Common::String gameName = obj_get_name(segManager, version, game_obj);
+	debug(2, "Detected ID: \"%s\" at %04x:%04x", gameName.c_str(), PRINT_REG(game_obj));
+	gameName.toLowercase();
+	s_fallbackDesc.desc.gameid = strdup(convertSierraGameId(gameName).c_str());
+	delete segManager;
+	delete resMgr;
+
 	printf("If this is *NOT* a fan-modified version (in particular, not a fan-made\n");
 	printf("translation), please, report the data above, including the following\n");
 	printf("version number, from the game's executable:\n");

Modified: scummvm/branches/gsoc2009-16bit/engines/sci/engine/game.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/sci/engine/game.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/sci/engine/game.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -188,159 +188,13 @@
 	return 0;
 }
 
-int create_class_table_sci11(EngineState *s) {
-	int scriptnr;
-	unsigned int seeker_offset;
-	char *seeker_ptr;
-	int classnr;
-
-	Resource *vocab996 = s->resmgr->findResource(ResourceId(kResourceTypeVocab, 996), 1);
-
-	if (!vocab996)
-		s->_classtable.resize(20);
-	else
-		s->_classtable.resize(vocab996->size >> 2);
-
-	for (scriptnr = 0; scriptnr < 1000; scriptnr++) {
-		Resource *heap = s->resmgr->findResource(ResourceId(kResourceTypeHeap, scriptnr), 0);
-
-		if (heap) {
-			int global_vars = READ_LE_UINT16(heap->data + 2);
-
-			seeker_ptr = (char*)heap->data + 4 + global_vars * 2;
-			seeker_offset = 4 + global_vars * 2;
-
-			while (READ_LE_UINT16((byte*)seeker_ptr) == SCRIPT_OBJECT_MAGIC_NUMBER) {
-				if (READ_LE_UINT16((byte*)seeker_ptr + 14) & SCRIPT_INFO_CLASS) {
-					classnr = READ_LE_UINT16((byte*)seeker_ptr + 10);
-					if (classnr >= (int)s->_classtable.size()) {
-						if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) {
-							warning("Invalid class number 0x%x in script.%d(0x%x), offset %04x",
-							        classnr, scriptnr, scriptnr, seeker_offset);
-							return 1;
-						}
-
-						s->_classtable.resize(classnr + 1); // Adjust maximum number of entries
-					}
-
-					s->_classtable[classnr].reg.offset = seeker_offset;
-					s->_classtable[classnr].reg.segment = 0;
-					s->_classtable[classnr].script = scriptnr;
-				}
-
-				seeker_ptr += READ_LE_UINT16((byte*)seeker_ptr + 2) * 2;
-				seeker_offset += READ_LE_UINT16((byte*)seeker_ptr + 2) * 2;
-			}
-		}
-	}
-
-	s->resmgr->unlockResource(vocab996);
-	vocab996 = NULL;
-	return 0;
-}
-
-static int create_class_table_sci0(EngineState *s) {
-	int scriptnr;
-	unsigned int seeker;
-	int classnr;
-	int magic_offset; // For strange scripts in older SCI versions
-
-	Resource *vocab996 = s->resmgr->findResource(ResourceId(kResourceTypeVocab, 996), 1);
-
-	if (!vocab996)
-		s->_classtable.resize(20);
-	else
-		s->_classtable.resize(vocab996->size >> 2);
-
-	for (scriptnr = 0; scriptnr < 1000; scriptnr++) {
-		int objtype = 0;
-		Resource *script = s->resmgr->findResource(ResourceId(kResourceTypeScript, scriptnr), 0);
-
-		if (script) {
-			if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader())
-				magic_offset = seeker = 2;
-			else
-				magic_offset = seeker = 0;
-
-			do {
-				while (seeker < script->size)	{
-					unsigned int lastseeker = seeker;
-					objtype = (int16)READ_LE_UINT16(script->data + seeker);
-					if (objtype == SCI_OBJ_CLASS || objtype == SCI_OBJ_TERMINATOR)
-						break;
-					seeker += (int16)READ_LE_UINT16(script->data + seeker + 2);
-					if (seeker <= lastseeker) {
-						s->_classtable.clear();
-						error("Script version is invalid");
-					}
-				}
-
-				if (objtype == SCI_OBJ_CLASS) {
-					int sugg_script;
-
-					seeker -= SCRIPT_OBJECT_MAGIC_OFFSET; // Adjust position; script home is base +8 bytes
-
-					classnr = (int16)READ_LE_UINT16(script->data + seeker + 4 + SCRIPT_SPECIES_OFFSET);
-					if (classnr >= (int)s->_classtable.size()) {
-
-						if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) {
-							warning("Invalid class number 0x%x in script.%d(0x%x), offset %04x",
-							        classnr, scriptnr, scriptnr, seeker);
-							return 1;
-						}
-
-						s->_classtable.resize(classnr + 1); // Adjust maximum number of entries
-					}
-
-					// Map the class ID to the script the corresponding class is contained in
-					// The script number is found in vocab.996, if it exists
-					if (!vocab996 || (uint32)classnr >= vocab996->size >> 2)
-						sugg_script = -1;
-					else
-						sugg_script = (int16)READ_LE_UINT16(vocab996->data + 2 + (classnr << 2));
-
-					// First, test whether the script hasn't been claimed, or if it's been claimed by the wrong script
-
-					if (sugg_script == -1 || scriptnr == sugg_script /*|| !s->_classtable[classnr].reg.segment*/)  {
-						// Now set the home script of the class
-						s->_classtable[classnr].reg.offset = seeker + 4 - magic_offset;
-						s->_classtable[classnr].reg.segment = 0;
-						s->_classtable[classnr].script = scriptnr;
-					}
-
-					seeker += SCRIPT_OBJECT_MAGIC_OFFSET; // Re-adjust position
-					seeker += (int16)READ_LE_UINT16(script->data + seeker + 2); // Move to next
-				}
-
-			} while (objtype != SCI_OBJ_TERMINATOR && seeker <= script->size);
-
-		}
-	}
-	s->resmgr->unlockResource(vocab996);
-	vocab996 = NULL;
-	return 0;
-}
-
 // Architectural stuff: Init/Unintialize engine
 int script_init_engine(EngineState *s) {
-	int result;
-
 	s->kernel_opt_flags = 0;
-
-	if (s->_version >= SCI_VERSION_1_1)
-		result = create_class_table_sci11(s);
-	else
-		result = create_class_table_sci0(s);
-
-	if (result) {
-		debug(2, "Failed to initialize class table");
-		return 1;
-	}
-
-	s->seg_manager = new SegManager(s->_version >= SCI_VERSION_1_1);
+	s->seg_manager = new SegManager(s->resmgr, s->_version, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader());
 	s->gc_countdown = GC_INTERVAL - 1;
 
-	SegmentId script_000_segment = script_get_segment(s, 0, SCRIPT_GET_LOCK);
+	SegmentId script_000_segment = s->seg_manager->getSegment(0, SCRIPT_GET_LOCK);
 
 	if (script_000_segment <= 0) {
 		debug(2, "Failed to instantiate script.000");
@@ -398,7 +252,8 @@
 void script_free_vm_memory(EngineState *s) {
 	debug(2, "Freeing VM memory");
 
-	s->_classtable.clear();
+	if (s->seg_manager)
+		s->seg_manager->_classtable.clear();
 
 	// Close all opened file handles
 	s->_fileHandles.clear();
@@ -433,14 +288,13 @@
 
 int game_init(EngineState *s) {
 	// FIXME Use new VM instantiation code all over the place"
-	reg_t game_obj; // Address of the game object
 	DataStack *stack;
 
 	stack = s->seg_manager->allocateStack(VM_STACK_SIZE, &s->stack_segment);
 	s->stack_base = stack->entries;
 	s->stack_top = s->stack_base + VM_STACK_SIZE;
 
-	if (!script_instantiate(s, 0)) {
+	if (!script_instantiate(s->resmgr, s->seg_manager, s->_version, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader(), 0)) {
 		warning("game_init(): Could not instantiate script 0");
 		return 1;
 	}
@@ -473,21 +327,12 @@
 	srand(g_system->getMillis()); // Initialize random number generator
 
 //	script_dissect(0, s->_selectorNames);
-	game_obj = script_lookup_export(s, 0, 0);
 	// The first entry in the export table of script 0 points to the game object
+	s->game_obj = script_lookup_export(s->seg_manager, 0, 0);
+	s->_gameName = obj_get_name(s->seg_manager, s->_version, s->game_obj);
 
-	const char *tmp = obj_get_name(s, game_obj);
+	debug(2, " \"%s\" at %04x:%04x", s->_gameName.c_str(), PRINT_REG(s->game_obj));
 
-	if (!tmp) {
-		warning("Error: script.000, export 0 (%04x:%04x) does not yield an object with a name -> sanity check failed", PRINT_REG(game_obj));
-		return 1;
-	}
-	s->_gameName = tmp;
-
-	debug(2, " \"%s\" at %04x:%04x", s->_gameName.c_str(), PRINT_REG(game_obj));
-
-	s->game_obj = game_obj;
-
 	// Mark parse tree as unused
 	s->parser_nodes[0].type = kParseTreeLeafNode;
 	s->parser_nodes[0].content.value = 0;
@@ -512,7 +357,9 @@
 		game_init_sound(s, SFX_STATE_FLAG_NOSOUND);
 	}
 
+	s->seg_manager->_classtable.clear();
 	delete s->seg_manager;
+	s->seg_manager = 0;
 
 	s->_synonyms.clear();
 

Modified: scummvm/branches/gsoc2009-16bit/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/sci/engine/kernel.cpp	2009-08-18 21:37:31 UTC (rev 43523)
+++ scummvm/branches/gsoc2009-16bit/engines/sci/engine/kernel.cpp	2009-08-19 01:22:43 UTC (rev 43524)
@@ -33,11 +33,7 @@
 
 namespace Sci {
 
-/** The string used to identify the "unknown" SCI0 function for each game */
-#define SCRIPT_UNKNOWN_FUNCTION_STRING "[Unknown]"
-
 // Default kernel name table
-#define SCI0_KNAMES_WELL_DEFINED 0x6e
 #define SCI_KNAMES_DEFAULT_ENTRIES_NR 0x89
 
 static const char *sci_default_knames[SCI_KNAMES_DEFAULT_ENTRIES_NR] = {
@@ -367,11 +363,15 @@
 	"Arithmetic"
 };
 
-Kernel::Kernel(ResourceManager *resmgr) : _resmgr(resmgr) {
+Kernel::Kernel(ResourceManager *resmgr, bool minimalLoad) : _resmgr(resmgr) {
 	memset(&_selectorMap, 0, sizeof(_selectorMap));	// FIXME: Remove this once/if we C++ify selector_map_t
 
-	detectSciFeatures(); // must be called before loadSelectorNames()
 	loadSelectorNames();
+	detectSciFeatures();
+
+	if (minimalLoad)	// If we're only asked to detect game features, stop here
+		return;
+
 	mapSelectors();      // Map a few special selectors for later use
 	loadOpcodes();
 	loadKernelNames();
@@ -382,61 +382,30 @@
 }
 
 void Kernel::detectSciFeatures() {
-	// FIXME Much of this is unreliable
+	SciVersion version = _resmgr->sciVersion();
 
-	Resource *r = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0);
-
-	Common::StringList staticSelectorTable;
-	
-	if (!r) { // No such resource?
-		staticSelectorTable = checkStaticSelectorNames();
-		if (staticSelectorTable.empty())
-			error("Kernel: Could not retrieve selector names");
-	}
-
-	int count = staticSelectorTable.empty() ? READ_LE_UINT16(r->data) + 1 : staticSelectorTable.size(); // Counter is slightly off
 	features = 0;
 
 	// Initialize features based on SCI version
-	switch (_resmgr->sciVersion()) {
-	case SCI_VERSION_0_EARLY:
-		features |= kFeatureOldScriptHeader;
-		/* Fallthrough */
-	case SCI_VERSION_0_LATE:
-		features |= kFeatureOldGfxFunctions;
-		break;
-	default:
-		break;
+
+	// Script header and graphics functions
+	if (version == SCI_VERSION_0_EARLY) {
+		features |= kFeatureOldScriptHeader | kFeatureOldGfxFunctions;
+	} else if (version == SCI_VERSION_0_LATE) {
+		if (findSelector("motionCue") == -1)
+			features |= kFeatureOldGfxFunctions;
 	}
 
-	for (int i = 0; i < count; i++) {
-		Common::String tmp;
-		
-		if (staticSelectorTable.empty()) {
-			int offset = READ_LE_UINT16(r->data + 2 + i * 2);
-			int len = READ_LE_UINT16(r->data + offset);
-			
-			tmp = Common::String((const char *)r->data + offset + 2, len);
-		} else {
-			tmp = staticSelectorTable[i];
-		}
-
-		if (tmp == "motionCue")
-			features &= ~kFeatureOldGfxFunctions;
-
-		if (tmp == "egoMoveSpeed" && _resmgr->sciVersion() < SCI_VERSION_1_1)
+	// Lofs absolute/relative
+	if (version >= SCI_VERSION_1_MIDDLE && version < SCI_VERSION_1_1) {
+		// Assume all games use absolute lofs
+		features |= kFeatureLofsAbsolute;
+	} else if (version == SCI_VERSION_1_EARLY) {
+		// Use heuristic
+		if (findSelector("egoMoveSpeed") != -1)
 			features |= kFeatureLofsAbsolute;
-
-		if (tmp == "setVol")
-			features |= kFeatureSci1Sound;
-
-		if (tmp == "nodePtr")
-			features |= kFeatureSci01Sound;
 	}
 
-	if (features & kFeatureSci1Sound)
-		features &= ~kFeatureSci01Sound;
-
 	printf("Kernel auto-detected features:\n");
 
 	printf("Graphics functions: ");
@@ -445,19 +414,13 @@
 	else
 		printf("new\n");
 
-	printf("lofs parameters: ");
-	if (features & kFeatureLofsAbsolute)
-		printf("absolute\n");
-	else
-		printf("relative\n");
-
-	printf("Sound functions: ");
-	if (features & kFeatureSci1Sound)
-		printf("SCI1\n");
-	else if (features & kFeatureSci01Sound)
-		printf("SCI01\n");
-	else
-		printf("SCI0\n");
+	if (version < SCI_VERSION_1_1) {
+		printf("lofs parameters: ");
+		if (features & kFeatureLofsAbsolute)
+			printf("absolute\n");
+		else
+			printf("relative\n");
+	}
 }
 
 void Kernel::loadSelectorNames() {
@@ -473,7 +436,7 @@
 		
 		for (uint32 i = 0; i < staticSelectorTable.size(); i++) {
 			_selectorNames.push_back(staticSelectorTable[i]);
-			if (features & kFeatureOldScriptHeader)
+			if (_resmgr->sciVersion() == SCI_VERSION_0_EARLY)
 				_selectorNames.push_back(staticSelectorTable[i]);
 		}
 			
@@ -492,7 +455,7 @@
 
 		// Early SCI versions used the LSB in the selector ID as a read/write
 		// toggle. To compensate for that, we add every selector name twice.
-		if (features & kFeatureOldScriptHeader)
+		if (_resmgr->sciVersion() == SCI_VERSION_0_EARLY)
 			_selectorNames.push_back(tmp);
 	}
 }
@@ -706,6 +669,8 @@
 
 	mobj = s->seg_manager->_heap[reg.segment];
 
+	SciVersion version = s->_version;	// for the offset defines
+
 	switch (mobj->getType()) {
 	case MEM_OBJ_SCRIPT:
 		if (reg.offset <= (*(Script *)mobj).buf_size && reg.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
@@ -817,32 +782,40 @@
 }
 
 void Kernel::setDefaultKernelNames() {
-	bool isSci0 = (_resmgr->sciVersion() <= SCI_VERSION_0_LATE);
-	int offset = 0;
+	_kernelNames = Common::StringList(sci_default_knames, SCI_KNAMES_DEFAULT_ENTRIES_NR);
 
-	_kernelNames.resize(SCI_KNAMES_DEFAULT_ENTRIES_NR + (isSci0 ? 4 : 0));
-	for (int i = 0; i < SCI_KNAMES_DEFAULT_ENTRIES_NR; i++) {
-		// In SCI0, Platform was DoAvoider
-		if (!strcmp(sci_default_knames[i], "Platform") && isSci0) {
-			_kernelNames[i + offset] = "DoAvoider";
-			continue;
-		}
+	switch (_resmgr->sciVersion()) {
+	case SCI_VERSION_0_EARLY:
+	case SCI_VERSION_0_LATE:
+		// Insert SCI0 file functions after SetCursor (0x28)
+		_kernelNames.insert_at(0x29, "FOpen");
+		_kernelNames.insert_at(0x2A, "FPuts");
+		_kernelNames.insert_at(0x2B, "FGets");
+		_kernelNames.insert_at(0x2C, "FClose");
 
-		_kernelNames[i + offset] = sci_default_knames[i];
+		// Function 0x55 is DoAvoider
+		_kernelNames[0x55] = "DoAvoider";
 
-		// SCI0 has 4 extra functions between SetCursor (0x28) and Savegame
-		if (!strcmp(sci_default_knames[i], "SetCursor") && isSci0) {
-			_kernelNames[i + 1] = "FOpen";
-			_kernelNames[i + 2] = "FPuts";
-			_kernelNames[i + 3] = "FGets";
-			_kernelNames[i + 4] = "FClose";
-			offset = 4;
-		}
-	}
+		// Cut off unused functions
+		_kernelNames.resize(0x72);
+		break;
 
-	if (_resmgr->sciVersion() == SCI_VERSION_1_1) {
-		// HACK: KQ6CD calls unimplemented function 0x26
+	case SCI_VERSION_01:

@@ Diff output truncated at 100000 characters. @@

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list