[Scummvm-git-logs] scummvm master -> 4d5699a8e7cf66cac06a12aaeccc3462fa518ab6

sluicebox 22204938+sluicebox at users.noreply.github.com
Fri Oct 11 23:39:56 CEST 2019


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ea01e42918 SCI: Fix more kFileIO return values
511e5441e3 SCI32: Enable Mac code (remove ENABLE_SCI32_MAC)
4d5699a8e7 SCI32: Add support for Mac SND resource playback


Commit: ea01e42918b1582f774727fd0fceb0672762af45
    https://github.com/scummvm/scummvm/commit/ea01e42918b1582f774727fd0fceb0672762af45
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2019-10-11T14:14:15-07:00

Commit Message:
SCI: Fix more kFileIO return values

Fix a number of incorrect return values from file IO functions, continuing
the kFileIOWriteString fix from 7c1fb8bee1890f831adde61a98d94a563f9d14fa

One of the misconceptions was that these functions return DOS error
error codes on failure. Instead, SCI16 immediately zeros those out.

Changed paths:
    engines/sci/engine/kfile.cpp


diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index 156d294..f364e9d 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -566,7 +566,7 @@ reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
 
 	if (handle >= kVirtualFileHandleStart) {
 		// it's a virtual handle? ignore it
-		return getSciVersion() >= SCI_VERSION_2 ? TRUE_REG : SIGNAL_REG;
+		return TRUE_REG;
 	}
 
 	FileHandle *f = getFileFromHandle(s, handle);
@@ -574,7 +574,7 @@ reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
 		f->close();
 		if (getSciVersion() <= SCI_VERSION_0_LATE)
 			return s->r_acc;	// SCI0 semantics: no value returned
-		return getSciVersion() >= SCI_VERSION_2 ? TRUE_REG : SIGNAL_REG;
+		return TRUE_REG;
 	}
 
 	if (getSciVersion() <= SCI_VERSION_0_LATE)
@@ -628,19 +628,10 @@ reg_t kFileIOWriteRaw(EngineState *s, int argc, reg_t *argv) {
 
 	delete[] buf;
 
-#ifdef ENABLE_SCI32
-	if (getSciVersion() >= SCI_VERSION_2) {
-		if (!success) {
-			return SIGNAL_REG;
-		}
-
+	if (success) {
 		return make_reg(0, bytesWritten);
 	}
-#endif
-
-	if (success)
-		return NULL_REG;
-	return make_reg(0, 6); // DOS - invalid handle
+	return getSciVersion() >= SCI_VERSION_2 ? SIGNAL_REG : NULL_REG;
 }
 
 reg_t kFileIOUnlink(EngineState *s, int argc, reg_t *argv) {
@@ -694,15 +685,7 @@ reg_t kFileIOUnlink(EngineState *s, int argc, reg_t *argv) {
 
 	debugC(kDebugLevelFile, "kFileIO(unlink): %s", name.c_str());
 
-#ifdef ENABLE_SCI32
-	if (getSciVersion() >= SCI_VERSION_2) {
-		return make_reg(0, result);
-	}
-#endif
-
-	if (result)
-		return NULL_REG;
-	return make_reg(0, 2); // DOS - file not found error code
+	return make_reg(0, result);
 }
 
 reg_t kFileIOReadString(EngineState *s, int argc, reg_t *argv) {
@@ -758,14 +741,10 @@ reg_t kFileIOWriteString(EngineState *s, int argc, reg_t *argv) {
 
 	if (f && f->_out) {
 		uint32 bytesWritten = f->_out->write(str.c_str(), str.size());
-		if (getSciVersion() <= SCI_VERSION_0_LATE)
-			return s->r_acc;	// SCI0 semantics: no value returned
 		return make_reg(0, bytesWritten);
 	}
 
-	if (getSciVersion() <= SCI_VERSION_0_LATE)
-		return s->r_acc;	// SCI0 semantics: no value returned
-	return make_reg(0, 6); // DOS - invalid handle
+	return getSciVersion() >= SCI_VERSION_2 ? SIGNAL_REG : NULL_REG;
 }
 
 reg_t kFileIOSeek(EngineState *s, int argc, reg_t *argv) {
@@ -943,9 +922,11 @@ reg_t kFileIOReadByte(EngineState *s, int argc, reg_t *argv) {
 
 reg_t kFileIOWriteByte(EngineState *s, int argc, reg_t *argv) {
 	FileHandle *f = getFileFromHandle(s, argv[0].toUint16());
-	if (f)
+	if (f) {
 		f->_out->writeByte(argv[1].toUint16() & 0xff);
-	return s->r_acc;
+		return make_reg(0, 1); // bytesWritten
+	}
+	return SIGNAL_REG;
 }
 
 reg_t kFileIOReadWord(EngineState *s, int argc, reg_t *argv) {
@@ -972,12 +953,12 @@ reg_t kFileIOWriteWord(EngineState *s, int argc, reg_t *argv) {
 	const uint16 handle = argv[0].toUint16();
 
 	if (handle == kVirtualFileHandleSci32Save) {
-		return s->r_acc;
+		return make_reg(0, 2); // bytesWritten
 	}
 
 	FileHandle *f = getFileFromHandle(s, handle);
 	if (!f) {
-		return s->r_acc;
+		return SIGNAL_REG;
 	}
 
 	if (f->_name == "-scummvm-save-") {
@@ -990,7 +971,7 @@ reg_t kFileIOWriteWord(EngineState *s, int argc, reg_t *argv) {
 		f->_out->writeUint16LE(argv[1].toUint16());
 	}
 
-	return s->r_acc;
+	return make_reg(0, 2); // bytesWritten
 }
 
 reg_t kFileIOGetCWD(EngineState *s, int argc, reg_t *argv) {


Commit: 511e5441e360bf283cafc48981580bea2e07a44b
    https://github.com/scummvm/scummvm/commit/511e5441e360bf283cafc48981580bea2e07a44b
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2019-10-11T14:18:26-07:00

Commit Message:
SCI32: Enable Mac code (remove ENABLE_SCI32_MAC)

Changed paths:
    engines/sci/engine/kernel.cpp
    engines/sci/engine/kernel.h
    engines/sci/engine/kmisc.cpp
    engines/sci/engine/ksound.cpp
    engines/sci/engine/message.cpp
    engines/sci/graphics/cursor32.cpp
    engines/sci/graphics/cursor32.h
    engines/sci/graphics/palette32.cpp
    engines/sci/resource.cpp


diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp
index ab33251..3cf5fd5 100644
--- a/engines/sci/engine/kernel.cpp
+++ b/engines/sci/engine/kernel.cpp
@@ -116,7 +116,7 @@ void Kernel::loadSelectorNames() {
 	Resource *r = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SELECTORS), 0);
 	bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
 
-#ifdef ENABLE_SCI32_MAC
+#ifdef ENABLE_SCI32
 	// Starting with KQ7, Mac versions have a BE name table. GK1 Mac and earlier (and all
 	// other platforms) always use LE.
 	const bool isBE = (g_sci->getPlatform() == Common::kPlatformMacintosh && getSciVersion() >= SCI_VERSION_2_1_EARLY
@@ -608,7 +608,7 @@ void Kernel::mapFunctions() {
 			continue;
 		}
 
-#ifdef ENABLE_SCI32_MAC
+#ifdef ENABLE_SCI32
 		// HACK: Phantasmagoria Mac uses a modified kDoSound (which *nothing*
 		// else seems to use)!
 		if (g_sci->getPlatform() == Common::kPlatformMacintosh && g_sci->getGameId() == GID_PHANTASMAGORIA && kernelName == "DoSound") {
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index c1cce33..f88afcc 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -644,10 +644,8 @@ reg_t kDeleteLine(EngineState *s, int argc, reg_t *argv);
 
 reg_t kWinDLL(EngineState *s, int argc, reg_t *argv);
 
-#ifdef ENABLE_SCI32_MAC
 // Phantasmagoria Mac Special Kernel Function
 reg_t kDoSoundPhantasmagoriaMac(EngineState *s, int argc, reg_t *argv);
-#endif
 
 // SCI3 Kernel functions
 reg_t kPlayDuck(EngineState *s, int argc, reg_t *argv);
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 2112460..4c2bb2f 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -546,7 +546,7 @@ reg_t kMacPlatform(EngineState *s, int argc, reg_t *argv) {
 		// In SCI1, its usage is still unknown
 		// In SCI1.1, it's NOP
 		// In SCI32, it's used for remapping cursor ID's
-#ifdef ENABLE_SCI32_MAC
+#ifdef ENABLE_SCI32
 		if (getSciVersion() >= SCI_VERSION_2_1_EARLY) // Set Mac cursor remap
 			g_sci->_gfxCursor32->setMacCursorRemapList(argc - 1, argv + 1);
 		else
@@ -662,12 +662,10 @@ reg_t kPlatform32(EngineState *s, int argc, reg_t *argv) {
 		case Common::kPlatformWindows:
 			return make_reg(0, kSciPlatformWindows);
 		case Common::kPlatformMacintosh:
-#ifdef ENABLE_SCI32_MAC
 			// For Mac versions, kPlatform(0) with other args has more functionality
 			if (argc > 1)
 				return kMacPlatform(s, argc - 1, argv + 1);
 			else
-#endif
 				return make_reg(0, kSciPlatformMacintosh);
 		default:
 			error("Unknown platform %d", g_sci->getPlatform());
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index e6cd4ff..1a34e82 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -70,7 +70,7 @@ CREATE_DOSOUND_FORWARD(DoSoundSetVolume)
 CREATE_DOSOUND_FORWARD(DoSoundSetPriority)
 CREATE_DOSOUND_FORWARD(DoSoundSetLoop)
 
-#ifdef ENABLE_SCI32_MAC
+#ifdef ENABLE_SCI32
 reg_t kDoSoundPhantasmagoriaMac(EngineState *s, int argc, reg_t *argv) {
 	// Phantasmagoria Mac (and seemingly no other game (!)) uses this
 	// cutdown version of kDoSound.
diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp
index 0d7f03c..2d195b1 100644
--- a/engines/sci/engine/message.cpp
+++ b/engines/sci/engine/message.cpp
@@ -151,7 +151,7 @@ public:
 	}
 };
 
-#ifdef ENABLE_SCI32_MAC
+#ifdef ENABLE_SCI32
 // SCI32 Mac decided to add an extra byte (currently unknown in meaning) between
 // the talker and the string...
 class MessageReaderV4_MacSCI32 : public MessageReader {
@@ -211,8 +211,6 @@ bool MessageState::getRecord(CursorStack &stack, bool recurse, MessageRecord &re
 	case 4:
 #ifdef ENABLE_SCI32
 	case 5: // v5 seems to be compatible with v4
-#endif
-#ifdef ENABLE_SCI32_MAC
 		// SCI32 Mac is different than SCI32 DOS/Win here
 		if (g_sci->getPlatform() == Common::kPlatformMacintosh && getSciVersion() >= SCI_VERSION_2_1_EARLY)
 			reader = new MessageReaderV4_MacSCI32(*res);
diff --git a/engines/sci/graphics/cursor32.cpp b/engines/sci/graphics/cursor32.cpp
index a189f74..46fce8e 100644
--- a/engines/sci/graphics/cursor32.cpp
+++ b/engines/sci/graphics/cursor32.cpp
@@ -196,7 +196,6 @@ void GfxCursor32::setView(const GuiResourceId viewId, const int16 loopNo, const
 	_cursorInfo.loopNo = loopNo;
 	_cursorInfo.celNo = celNo;
 
-#ifdef ENABLE_SCI32_MAC
 	if (!_macCursorRemap.empty() && viewId != -1) {
 		// Mac cursor handling
 		GuiResourceId viewNum = viewId;
@@ -241,9 +240,7 @@ void GfxCursor32::setView(const GuiResourceId viewId, const int16 loopNo, const
 
 		// The cursor will be drawn on next refresh
 		delete macCursor;
-	} else
-#endif
-	if (viewId != -1) {
+	} else if (viewId != -1) {
 		CelObjView view(viewId, loopNo, celNo);
 
 		_hotSpot = view._origin;
@@ -449,11 +446,9 @@ void GfxCursor32::move() {
 	}
 }
 
-#ifdef ENABLE_SCI32_MAC
 void GfxCursor32::setMacCursorRemapList(int cursorCount, reg_t *cursors) {
 	for (int i = 0; i < cursorCount; i++)
 		_macCursorRemap.push_back(cursors[i].toUint16());
 }
-#endif
 
 } // End of namespace Sci
diff --git a/engines/sci/graphics/cursor32.h b/engines/sci/graphics/cursor32.h
index fb07c49..1dcd679 100644
--- a/engines/sci/graphics/cursor32.h
+++ b/engines/sci/graphics/cursor32.h
@@ -219,14 +219,12 @@ private:
 	 */
 	void move();
 
-#ifdef ENABLE_SCI32_MAC
 public:
 	void setMacCursorRemapList(int cursorCount, reg_t *cursors);
 
 private:
 	// Mac versions of games use a remap list to remap their cursors
 	Common::Array<uint16> _macCursorRemap;
-#endif
 };
 
 } // End of namespace Sci
diff --git a/engines/sci/graphics/palette32.cpp b/engines/sci/graphics/palette32.cpp
index 803dc74..e139a05 100644
--- a/engines/sci/graphics/palette32.cpp
+++ b/engines/sci/graphics/palette32.cpp
@@ -531,15 +531,11 @@ void GfxPalette32::updateHardware() {
 	memset(bpal + (maxIndex + 1) * 3, 0, (255 - maxIndex - 1) * 3);
 #endif
 
-#ifdef ENABLE_SCI32_MAC
 	if (g_sci->getPlatform() == Common::kPlatformMacintosh) {
 		bpal[255 * 3    ] = 0;
 		bpal[255 * 3 + 1] = 0;
 		bpal[255 * 3 + 2] = 0;
 	} else {
-#else
-	{
-#endif
 		// The last color must always be white
 		bpal[255 * 3    ] = 255;
 		bpal[255 * 3 + 1] = 255;
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 8e48d0a..89ab6e0 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -481,7 +481,7 @@ void MacResourceForkResourceSource::decompressResource(Common::SeekableReadStrea
 	bool canBeCompressed = !(g_sci && g_sci->getGameId() == GID_KQ6) && isCompressableResource(resource->_id.getType());
 	uint32 uncompressedSize = 0;
 
-#ifdef ENABLE_SCI32_MAC
+#ifdef ENABLE_SCI32
 	// GK2 Mac is crazy. In its Patches resource fork, picture 2315 is not
 	// compressed and it is hardcoded in the executable to say that it's
 	// not compressed. Why didn't they just add four zeroes to the end of


Commit: 4d5699a8e7cf66cac06a12aaeccc3462fa518ab6
    https://github.com/scummvm/scummvm/commit/4d5699a8e7cf66cac06a12aaeccc3462fa518ab6
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2019-10-11T14:19:43-07:00

Commit Message:
SCI32: Add support for Mac SND resource playback

Used by at least GK1 Mac, which can now be started without erroring

Changed paths:
    engines/sci/sound/audio32.cpp


diff --git a/engines/sci/sound/audio32.cpp b/engines/sci/sound/audio32.cpp
index f9a0140..9bf08c5 100644
--- a/engines/sci/sound/audio32.cpp
+++ b/engines/sci/sound/audio32.cpp
@@ -22,6 +22,7 @@
 
 #include "sci/sound/audio32.h"
 #include "audio/audiostream.h"      // for SeekableAudioStream
+#include "audio/decoders/mac_snd.h" // for makeMacSndStream
 #include "audio/decoders/raw.h"     // for makeRawStream, RawFlags::FLAG_16BITS
 #include "audio/decoders/wave.h"    // for makeWAVStream
 #include "audio/rate.h"             // for RateConverter, makeRateConverter
@@ -83,6 +84,23 @@ bool detectWaveAudio(Common::SeekableReadStream &stream) {
 	return true;
 }
 
+bool detectMacSndAudio(Common::SeekableReadStream &stream) {
+	const size_t initialPosition = stream.pos();
+
+	byte header[14];
+	if (stream.read(header, sizeof(header)) != sizeof(header)) {
+		stream.seek(initialPosition);
+		return false;
+	}
+
+	stream.seek(initialPosition);
+
+	return (READ_BE_UINT16(header) == 1 &&
+		READ_BE_UINT16(header + 2) == 1 &&
+		READ_BE_UINT16(header + 4) == 5 &&
+		READ_BE_UINT32(header + 10) == 0x00018051);
+}
+
 #pragma mark -
 #pragma mark MutableLoopAudioStream
 
@@ -793,6 +811,8 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool
 		audioStream = makeSOLStream(dataStream, DisposeAfterUse::YES);
 	} else if (detectWaveAudio(*dataStream)) {
 		audioStream = Audio::makeWAVStream(dataStream, DisposeAfterUse::YES);
+	} else if (detectMacSndAudio(*dataStream)) {
+		audioStream = Audio::makeMacSndStream(dataStream, DisposeAfterUse::YES);
 	} else {
 		byte flags = Audio::FLAG_LITTLE_ENDIAN;
 		if (_globalBitDepth == 16) {





More information about the Scummvm-git-logs mailing list