[Scummvm-cvs-logs] SF.net SVN: scummvm:[50701] scummvm/trunk/backends

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Jul 5 21:10:22 CEST 2010


Revision: 50701
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50701&view=rev
Author:   fingolfin
Date:     2010-07-05 19:10:20 +0000 (Mon, 05 Jul 2010)

Log Message:
-----------
DS: Fix warnings, make some vars static, cleanup

Modified Paths:
--------------
    scummvm/trunk/backends/fs/ds/ds-fs.cpp
    scummvm/trunk/backends/fs/ds/ds-fs.h
    scummvm/trunk/backends/platform/ds/arm9/source/cdaudio.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp

Modified: scummvm/trunk/backends/fs/ds/ds-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ds/ds-fs.cpp	2010-07-05 18:48:58 UTC (rev 50700)
+++ scummvm/trunk/backends/fs/ds/ds-fs.cpp	2010-07-05 19:10:20 UTC (rev 50701)
@@ -416,18 +416,12 @@
 }
 
 int32 DSFileStream::pos() const {
-	if (_writeBufferPos > 0) {
-		// Discard constness.  Bad, but I can't see another way.
-		((DSFileStream *) (this))->flush();
-	}
+	assert(_writeBufferPos == 0);	// This method may only be called when reading!
 	return std_ftell((FILE *)_handle);
 }
 
 int32 DSFileStream::size() const {
-	if (_writeBufferPos > 0) {
-		// Discard constness.  Bad, but I can't see another way.
-		((DSFileStream *) (this))->flush();
-	}
+	assert(_writeBufferPos == 0);	// This method may only be called when reading!
 	int32 oldPos = std_ftell((FILE *)_handle);
 	std_fseek((FILE *)_handle, 0, SEEK_END);
 	int32 length = std_ftell((FILE *)_handle);
@@ -659,10 +653,10 @@
 		return bytes / size;
 	}
 
-	if ((int)(handle->pos + size * numItems) > handle->size) {
+	if (handle->pos > handle->size)
+		numItems = 0;
+	else if ((int)(handle->pos + size * numItems) > handle->size)
 		numItems = (handle->size - handle->pos) / size;
-		if (numItems < 0) numItems = 0;
-	}
 
 //	consolePrintf("read %d  ", size * numItems);
 

Modified: scummvm/trunk/backends/fs/ds/ds-fs.h
===================================================================
--- scummvm/trunk/backends/fs/ds/ds-fs.h	2010-07-05 18:48:58 UTC (rev 50700)
+++ scummvm/trunk/backends/fs/ds/ds-fs.h	2010-07-05 19:10:20 UTC (rev 50701)
@@ -173,7 +173,9 @@
 
 class DSFileStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
 protected:
-	static const int WRITE_BUFFER_SIZE = 512;
+	enum {
+		WRITE_BUFFER_SIZE = 512
+	};
 
 	/** File handle to the actual file. */
 	void 	*_handle;

Modified: scummvm/trunk/backends/platform/ds/arm9/source/cdaudio.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/cdaudio.cpp	2010-07-05 18:48:58 UTC (rev 50700)
+++ scummvm/trunk/backends/platform/ds/arm9/source/cdaudio.cpp	2010-07-05 19:10:20 UTC (rev 50701)
@@ -74,25 +74,25 @@
 	unsigned char	sample[1024];
 } __attribute__ ((packed));
 
-bool active = false;
-WaveHeader waveHeader;
-Header blockHeader;
-FILE *file;
-int fillPos;
-bool isPlayingFlag = false;
+static bool s_active = false;
+static WaveHeader waveHeader;
+static Header blockHeader;
+static FILE *s_file;
+static int fillPos;
+static bool isPlayingFlag = false;
 
-s16 *audioBuffer;
-u32 sampleNum;
-s16 *decompressionBuffer;
-int numLoops;
-int blockCount;
-int dataChunkStart;
-int blocksLeft;
-bool trackStartsAt2 = false;
+static s16 *audioBuffer;
+static u32 sampleNum;
+static s16 *decompressionBuffer;
+static int s_numLoops;
+static int blockCount;
+static int dataChunkStart;
+static int blocksLeft;
+static bool trackStartsAt2 = false;
 
 
 // These are from Microsoft's document on DVI ADPCM
-const int stepTab[ 89 ] = {
+static const int stepTab[ 89 ] = {
 7, 8, 9, 10, 11, 12, 13, 14,
 16, 17, 19, 21, 23, 25, 28, 31,
 34, 37, 41, 45, 50, 55, 60, 66,
@@ -106,7 +106,7 @@
 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
 32767 };
 
-const int indexTab[ 16 ] = { -1, -1, -1, -1, 2, 4, 6, 8,
+static const int indexTab[ 16 ] = { -1, -1, -1, -1, 2, 4, 6, 8,
 -1, -1, -1, -1, 2, 4, 6, 8 };
 
 void playNextBlock();
@@ -118,11 +118,11 @@
 }
 
 void setActive(bool active) {
-	DS::CD::active = active;
+	s_active = active;
 }
 
 bool getActive() {
-	return active;
+	return s_active;
 }
 
 void playTrack(int track, int numLoops, int startFrame, int duration) {
@@ -148,21 +148,21 @@
 
 	sprintf(str, "track%d.wav", track);
 	fname = path + str;
-	file = DS::std_fopen(fname.c_str(), "rb");
+	s_file = DS::std_fopen(fname.c_str(), "rb");
 
-	if (!file) {
+	if (!s_file) {
 		sprintf(str, "track%02d.wav", track);
 		fname = path + str;
-		file = DS::std_fopen(fname.c_str(), "rb");
+		s_file = DS::std_fopen(fname.c_str(), "rb");
 	}
 
-	if (!file) {
+	if (!s_file) {
 		consolePrintf("Failed to open %s!\n", path.c_str());
 		return;
 	}
 
 
-	DS::std_fread(&waveHeader, sizeof(waveHeader), 1, file);
+	DS::std_fread(&waveHeader, sizeof(waveHeader), 1, s_file);
 
 	consolePrintf("File: %s\n", fname.c_str());
 
@@ -174,7 +174,7 @@
 
 	if ((waveHeader.fmtFormatTag != 17) && (waveHeader.fmtFormatTag != 20)) {
 		consolePrintf("Wave file is in the wrong format!  You must use IMA-ADPCM 4-bit mono.\n");
-		DS::std_fclose(file);
+		DS::std_fclose(s_file);
 		return;
 	}
 
@@ -186,14 +186,14 @@
 
 	// Skip chunks until we reach the data chunk
 	chunkHeader chunk;
-	DS::std_fread(&chunk, sizeof(chunkHeader), 1, file);
+	DS::std_fread(&chunk, sizeof(chunkHeader), 1, s_file);
 
 	while (!((chunk.name[0] == 'd') && (chunk.name[1] == 'a') && (chunk.name[2] == 't') && (chunk.name[3] == 'a'))) {
-		DS::std_fseek(file, chunk.size, SEEK_CUR);
-		DS::std_fread(&chunk, sizeof(chunkHeader), 1, file);
+		DS::std_fseek(s_file, chunk.size, SEEK_CUR);
+		DS::std_fread(&chunk, sizeof(chunkHeader), 1, s_file);
 	}
 
-	dataChunkStart = DS::std_ftell(file);
+	dataChunkStart = DS::std_ftell(s_file);
 
 
 	static bool started = false;
@@ -237,14 +237,14 @@
 
 	// No need to seek if we're starting from the beginning
 	if (block != 0) {
-		DS::std_fseek(file, dataChunkStart + block * waveHeader.fmtBlockAlign, SEEK_SET);
+		DS::std_fseek(s_file, dataChunkStart + block * waveHeader.fmtBlockAlign, SEEK_SET);
 //		consolePrintf("Startframe: %d  msec: %d (%d,%d)\n", startFrame, tenthssec, samples, block);
 	}
 
 
 	//decompressBlock();
 	playNextBlock();
-	DS::CD::numLoops = numLoops;
+	s_numLoops = numLoops;
 }
 
 void update() {
@@ -266,20 +266,20 @@
 
 
 	do {
-		DS::std_fread(&blockHeader, sizeof(blockHeader), 1, file);
+		DS::std_fread(&blockHeader, sizeof(blockHeader), 1, s_file);
 
-		DS::std_fread(&block[0], waveHeader.fmtBlockAlign - sizeof(blockHeader), 1, file);
+		DS::std_fread(&block[0], waveHeader.fmtBlockAlign - sizeof(blockHeader), 1, s_file);
 
-		if (DS::std_feof(file) ) {
+		if (DS::std_feof(s_file)) {
 			// Reached end of file, so loop
 
 
-			if ((numLoops == -1) || (numLoops > 1)) {
+			if ((s_numLoops == -1) || (s_numLoops > 1)) {
 				// Seek file to first packet
-				if (numLoops != -1) {
-					numLoops--;
+				if (s_numLoops != -1) {
+					s_numLoops--;
 				}
-				DS::std_fseek(file, dataChunkStart, SEEK_SET);
+				DS::std_fseek(s_file, dataChunkStart, SEEK_SET);
 				loop = true;
 			} else {
 				// Fill decompression buffer with zeros to prevent glitching
@@ -465,7 +465,7 @@
 void stopTrack() {
 	if (!isPlayingFlag) return;
 
-	DS::std_fclose(file);
+	DS::std_fclose(s_file);
 
 	isPlayingFlag = false;
 
@@ -498,8 +498,8 @@
 	}
 	consolePrintf("Looking for %s...", path.c_str());
 
-	FILE *file;
-	if ((file = DS::std_fopen(path.c_str(), "r"))) {
+	FILE *file = DS::std_fopen(path.c_str(), "r");
+	if (file) {
 		consolePrintf("Success!\n");
 		setActive(true);
 		DS::std_fclose(file);

Modified: scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp	2010-07-05 18:48:58 UTC (rev 50700)
+++ scummvm/trunk/backends/platform/ds/arm9/source/dsmain.cpp	2010-07-05 19:10:20 UTC (rev 50701)
@@ -133,8 +133,7 @@
 	void *res = __real_malloc(size);
 	s_total_malloc += size;
 
-	if (!res)
-	{
+	if (!res) {
 //		*((u8 *) NULL) = 0;
 		consolePrintf("Failed alloc (new) %d (%d)\n", size, s_total_malloc);
 		return NULL;

Modified: scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp	2010-07-05 18:48:58 UTC (rev 50700)
+++ scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp	2010-07-05 19:10:20 UTC (rev 50701)
@@ -47,10 +47,10 @@
 //	consolePrintf("Closed file\n");
 }
 
-uint32 GBAMPSaveFile::read(void *buf, uint32 size) {
-	saveSize += size;
-//	consolePrintf("Read %d %d ", size, saveSize);
-	return DS::std_fread(buf, 1, size, handle);
+uint32 GBAMPSaveFile::read(void *buf, uint32 length) {
+	saveSize += length;
+//	consolePrintf("Read %d %d ", length, saveSize);
+	return DS::std_fread(buf, 1, length, handle);
 }
 
 bool GBAMPSaveFile::eos() const {
@@ -77,27 +77,27 @@
 int32 GBAMPSaveFile::size() const {
 	int position = pos();
 	DS::std_fseek(handle, 0, SEEK_END);
-	int size = DS::std_ftell(handle);
+	int length = DS::std_ftell(handle);
 	DS::std_fseek(handle, position, SEEK_SET);
-	return size;
+	return length;
 }
 
-bool GBAMPSaveFile::seek(int32 pos, int whence) {
-	return DS::std_fseek(handle, pos, whence) == 0;
+bool GBAMPSaveFile::seek(int32 newPos, int whence) {
+	return DS::std_fseek(handle, newPos, whence) == 0;
 }
 
 
-uint32 GBAMPSaveFile::write(const void *buf, uint32 size) {
-	if (bufferPos + size > SAVE_BUFFER_SIZE) {
+uint32 GBAMPSaveFile::write(const void *buf, uint32 length) {
+	if (bufferPos + length > SAVE_BUFFER_SIZE) {
 		flushSaveBuffer();
-		saveSize += size;
-//		consolePrintf("Writing %d bytes from %x", size, buf);
-//		DS::std_fwrite(buf, 1, size, handle);
+		saveSize += length;
+//		consolePrintf("Writing %d bytes from %x", length, buf);
+//		DS::std_fwrite(buf, 1, length, handle);
 
-		memcpy(buffer + bufferPos, buf, size);
-		bufferPos += size;
+		memcpy(buffer + bufferPos, buf, length);
+		bufferPos += length;
 
-		saveSize += size;
+		saveSize += length;
 
 
 /*		int pos = 0;
@@ -107,31 +107,31 @@
 		bufferPos = 512;
 		pos += rest;
 		flushSaveBuffer();
-		size -= rest;
+		length -= rest;
 //		consolePrintf("First section: %d\n", rest);
 
-		while (size >= 512) {
+		while (length >= 512) {
 			DS::std_fwrite(((char *) (buf)) + pos, 1, 512, handle);
-			size -= 512;
+			length -= 512;
 			pos += 512;
-//			consolePrintf("Full chunk, %d left ", size);
+//			consolePrintf("Full chunk, %d left ", length);
 		}
 
 		bufferPos = 0;
-		memcpy(buffer + bufferPos, ((char *) (buf)) + pos, size);
-		bufferPos += size;
+		memcpy(buffer + bufferPos, ((char *) (buf)) + pos, length);
+		bufferPos += length;
 //		consolePrintf("%d left in buffer ", bufferPos);*/
 
 	} else {
 
-		memcpy(buffer + bufferPos, buf, size);
-		bufferPos += size;
+		memcpy(buffer + bufferPos, buf, length);
+		bufferPos += length;
 
-		saveSize += size;
+		saveSize += length;
 	}
 
-//	if ((size > 100) || (size <= 0)) consolePrintf("Write %d bytes\n", size);
-	return size;
+//	if ((length > 100) || (length <= 0)) consolePrintf("Write %d bytes\n", length);
+	return length;
 }
 
 

Modified: scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp	2010-07-05 18:48:58 UTC (rev 50700)
+++ scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp	2010-07-05 19:10:20 UTC (rev 50701)
@@ -463,7 +463,7 @@
 }
 
 void OSystem_DS::updateScreen() {
-	static int cnt = 0;
+//	static int cnt = 0;
 //	consolePrintf("updatescr %d\n", cnt++);
 
 	if ((_frameBufferExists) && (DS::getIsDisplayMode8Bit())) {


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