[Scummvm-git-logs] scummvm master -> a52072724702684d55126923c9bbc6b996781cad

dreammaster noreply at scummvm.org
Sat May 16 10:09:47 UTC 2026


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

Summary:
a1fe5a5535 MADS: PHANTOM: Implement timer_activate_low_priority, 60Hz timer
eac0f0c0eb MADS: PHANTOM: Properly loading sound driver for animview
a520727247 MADS: PHANTOM: Animview timer fixes, setting image_list flags


Commit: a1fe5a5535761be0015cf3df9025040d3934a21c
    https://github.com/scummvm/scummvm/commit/a1fe5a5535761be0015cf3df9025040d3934a21c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-05-16T20:08:09+10:00

Commit Message:
MADS: PHANTOM: Implement timer_activate_low_priority, 60Hz timer

Changed paths:
    engines/mads/madsv2/animview/anim_timer.cpp
    engines/mads/madsv2/core/timer.cpp
    engines/mads/madsv2/engine.cpp
    engines/mads/madsv2/engine.h


diff --git a/engines/mads/madsv2/animview/anim_timer.cpp b/engines/mads/madsv2/animview/anim_timer.cpp
index 6050e7db4fb..0a0f0b936e7 100644
--- a/engines/mads/madsv2/animview/anim_timer.cpp
+++ b/engines/mads/madsv2/animview/anim_timer.cpp
@@ -69,6 +69,8 @@ void anim_timer() {
 		goto done;
 	if (currentFrame < 0 || currentFrame >= maxFrame)
 		goto done;
+	// TODO: The min/max max values look like they're backwards. Plus, the code that sets
+	// up the values in animview.
 	if (foundSeries && currentFrame > seriesMaxFrame && currentFrame <= seriesMinFrame)
 		goto done;
 
diff --git a/engines/mads/madsv2/core/timer.cpp b/engines/mads/madsv2/core/timer.cpp
index 5b302af8fc9..37333715b93 100644
--- a/engines/mads/madsv2/core/timer.cpp
+++ b/engines/mads/madsv2/core/timer.cpp
@@ -48,11 +48,11 @@ void *timer_low_routine;
 
 
 void timer_install() {
-	// No implementation in ScummVM
+	timer_activate_low_priority(nullptr);
 }
 
 void timer_remove() {
-	// No implementation in ScummVM
+	timer_activate_low_priority(nullptr);
 }
 
 long timer_read() {
@@ -89,8 +89,8 @@ int timer_get_copy_protect() {
 	return timer_copy_protect_out;
 }
 
-void timer_activate_low_priority(void (*(routine))()) {
-	warning("TODO: timer_activate_low_priority");
+void timer_activate_low_priority(void (*routine)()) {
+	g_engine->setTimerFunction(routine);
 }
 
 byte *timer_get_interrupt_stack() {
diff --git a/engines/mads/madsv2/engine.cpp b/engines/mads/madsv2/engine.cpp
index 25c69ae5aa6..5bd2579ead0 100644
--- a/engines/mads/madsv2/engine.cpp
+++ b/engines/mads/madsv2/engine.cpp
@@ -237,6 +237,9 @@ void MADSV2Engine::pollEvents() {
 		_nextFrameTime = time + GAME_FRAME_TIME;
 	}
 
+	// Handle calling any set timer function
+	checkForTimerFunction();
+
 	// Poll for events
 	Common::Event e;
 	while (g_system->getEventManager()->pollEvent(e)) {
@@ -288,6 +291,18 @@ void MADSV2Engine::pollEvents() {
 	}
 }
 
+void MADSV2Engine::checkForTimerFunction() {
+	if (_timerFunction) {
+		uint32 time = g_system->getMillis();
+		if (time >= _nextTimerTime) {
+			_timerFunction();
+
+			// Determine the next time to call the function at 60Hz
+			_nextTimerTime = time + (1000 / 60);
+		}
+	}
+}
+
 bool MADSV2Engine::hasPendingKey() {
 	pollEvents();
 
diff --git a/engines/mads/madsv2/engine.h b/engines/mads/madsv2/engine.h
index 2f4ad4fa913..ccb55f8373d 100644
--- a/engines/mads/madsv2/engine.h
+++ b/engines/mads/madsv2/engine.h
@@ -35,6 +35,8 @@
 namespace MADS {
 namespace MADSV2 {
 
+typedef void (*TimerFunction)();
+
 class MADSV2Engine : public MADSEngine {
 private:
 	void initGlobals();
@@ -47,8 +49,11 @@ protected:
 	Common::Point _mousePos;
 	int _mouseButtons = 0;
 	Audio::SoundHandle _speechHandle;
+	TimerFunction _timerFunction = nullptr;
+	uint32 _nextTimerTime = 0;
 
 	void pollEvents();
+	void checkForTimerFunction();
 
 public:
 	MADS::SoundManager *_soundManager = nullptr;
@@ -110,6 +115,13 @@ public:
 	void playSpeech(Audio::AudioStream *stream);
 	void stopSpeech();
 	bool isSpeechPlaying() const;
+
+	/**
+	 * Sets the timer function to call at 60Hz
+	 */
+	void setTimerFunction(TimerFunction fn) {
+		_timerFunction = fn;
+	}
 };
 
 extern MADSV2Engine *g_engine;


Commit: eac0f0c0eb74792b96865504f4e28da8ede7f814
    https://github.com/scummvm/scummvm/commit/eac0f0c0eb74792b96865504f4e28da8ede7f814
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-05-16T20:08:09+10:00

Commit Message:
MADS: PHANTOM: Properly loading sound driver for animview

Changed paths:
    engines/mads/core/sound_manager.h
    engines/mads/madsv2/animview/anim_timer.cpp
    engines/mads/madsv2/animview/animview.cpp
    engines/mads/madsv2/core/anim.cpp
    engines/mads/madsv2/core/anim.h
    engines/mads/madsv2/engine.cpp


diff --git a/engines/mads/core/sound_manager.h b/engines/mads/core/sound_manager.h
index 9de6a45c456..377f15ae2d2 100644
--- a/engines/mads/core/sound_manager.h
+++ b/engines/mads/core/sound_manager.h
@@ -119,6 +119,13 @@ public:
 	 */
 	void init(int sectionNumber);
 
+	/**
+	 * Returns true if a driver is loaded
+	 */
+	bool isLoaded() const {
+		return _driver != nullptr;
+	}
+
 	/**
 	 * Stop any currently active sound and remove the driver
 	 */
diff --git a/engines/mads/madsv2/animview/anim_timer.cpp b/engines/mads/madsv2/animview/anim_timer.cpp
index 0a0f0b936e7..360e8f8d6f9 100644
--- a/engines/mads/madsv2/animview/anim_timer.cpp
+++ b/engines/mads/madsv2/animview/anim_timer.cpp
@@ -105,7 +105,7 @@ void anim_timer() {
 	}
 
 	sound = current_anim->frame[currentFrame].sound;
-	if (sound && runFx == 0)
+	if (sound && g_engine->_soundManager->isLoaded() && runFx == 0)
 		g_engine->_soundManager->command(sound);
 
 	if (speechIndex != -1)
@@ -208,6 +208,7 @@ block2:
 		}
 
 		if (!found) {
+			assert(image_marker < IMAGE_LIST_SIZE);
 			image_list[image_marker] = *img;
 			Series *series = series_list[img->series_id];
 			series->delta_series = (series->delta_series < 1) ? 1 : -4;
@@ -239,7 +240,7 @@ block3:
 		}
 
 		frame = &current_anim->frame[currentFrame];
-		if (frame->sound) {
+		if (frame->sound && g_engine->_soundManager->isLoaded()) {
 			g_engine->_soundManager->command(frame->sound);
 			timer1 = currTimer;
 		}
diff --git a/engines/mads/madsv2/animview/animview.cpp b/engines/mads/madsv2/animview/animview.cpp
index 7dda9a44256..e20330d24bc 100644
--- a/engines/mads/madsv2/animview/animview.cpp
+++ b/engines/mads/madsv2/animview/animview.cpp
@@ -401,22 +401,14 @@ static void animate() {
 			if (anim_get_sound_info(buf, sound_file_name, &soundLoadFlag))
 				goto done;
 
-			if (soundLoadFlag) {
-				oldMode = concat_mode;
-				*speech_name = '\0';
-				MADS_FORMAT(speech_name, sound_file_name);
-				env_get_path(sound_file_name, speech_name);
-				concat_mode = oldMode;
-
-				// Original did setup of sound card driver type here. Not needed for ScummVM
-
-				has_sound_file = Common::File::exists(sound_file_name);
-			}
+			has_sound_file = Common::isDigit(sound_file_name[strlen(sound_file_name) - 1]);
 		}
 
-		if (has_sound_file)
-			// TODO: Load proper driver number
-			g_engine->_soundManager->init(9);
+		if (has_sound_file) {
+			// Initialize the sound driver
+			int section = sound_file_name[strlen(sound_file_name) - 1] - '0';
+			g_engine->_soundManager->init(section);
+		}
 
 		if (anim_list[count].bg_load_status) {
 			buffer_free(&scr_depth);
@@ -521,6 +513,7 @@ static void animate() {
 
 		// Free the allocated sound driver
 		g_engine->_soundManager->closeDriver();
+		has_sound_file = false;
 
 		// Free surface
 		buffer_free(&scr_inter_orig);
diff --git a/engines/mads/madsv2/core/anim.cpp b/engines/mads/madsv2/core/anim.cpp
index 6731d480e41..dbf4268eeed 100644
--- a/engines/mads/madsv2/core/anim.cpp
+++ b/engines/mads/madsv2/core/anim.cpp
@@ -510,17 +510,26 @@ done:
 	return (anim);
 }
 
-int anim_get_sound_info(char *file_name, char *sound_file_buffer, int *sound_load_flag) {
+int anim_get_sound_info(const char *file_name, char *sound_file_buffer, int *sound_load_flag) {
 	int error_flag = true;
 	AnimFile anim_in;
 	Load load_handle;
 
 	load_handle.open = false;
 
+	// Open up the source animation file
 	if (loader_open(&load_handle, file_name, "rb", true)) goto done;
 
-	if (!loader_read(&anim_in, sizeof(AnimFile), 1, &load_handle)) goto done;
+	// Load the file header contents
+	byte buffer[AnimFile::SIZE];
+	if (!loader_read(buffer, AnimFile::SIZE, 1, &load_handle)) goto done;
 
+	{
+		Common::MemoryReadStream src(buffer, AnimFile::SIZE);
+		anim_in.load(&src);
+	}
+
+	// Copy out the sound filename
 	Common::strcpy_s(sound_file_buffer, 65536, anim_in.sound_file_name);
 	*sound_load_flag = (anim_in.load_flags & AA_LOAD_SOUND);
 
diff --git a/engines/mads/madsv2/core/anim.h b/engines/mads/madsv2/core/anim.h
index 6e31deb707a..2833bccf8e8 100644
--- a/engines/mads/madsv2/core/anim.h
+++ b/engines/mads/madsv2/core/anim.h
@@ -449,8 +449,7 @@ AnimPtr anim_load(const char *file_name,
 	RoomPtr *room, CycleListPtr cycle_list,
 	int load_flags);
 
-int anim_get_sound_info(char *file_name,
-	char *sound_file_buffer,
+int anim_get_sound_info(const char *file_name, char *sound_file_buffer,
 	int *sound_load_flag);
 
 int anim_get_header_info(char *file_name,
diff --git a/engines/mads/madsv2/engine.cpp b/engines/mads/madsv2/engine.cpp
index 5bd2579ead0..4b78734500d 100644
--- a/engines/mads/madsv2/engine.cpp
+++ b/engines/mads/madsv2/engine.cpp
@@ -295,10 +295,11 @@ void MADSV2Engine::checkForTimerFunction() {
 	if (_timerFunction) {
 		uint32 time = g_system->getMillis();
 		if (time >= _nextTimerTime) {
-			_timerFunction();
-
 			// Determine the next time to call the function at 60Hz
 			_nextTimerTime = time + (1000 / 60);
+
+			// Call the timer
+			_timerFunction();
 		}
 	}
 }


Commit: a52072724702684d55126923c9bbc6b996781cad
    https://github.com/scummvm/scummvm/commit/a52072724702684d55126923c9bbc6b996781cad
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-05-16T20:09:21+10:00

Commit Message:
MADS: PHANTOM: Animview timer fixes, setting image_list flags

Changed paths:
    engines/mads/madsv2/animview/anim_timer.cpp
    engines/mads/madsv2/animview/animview.cpp
    engines/mads/madsv2/animview/animview.h
    engines/mads/madsv2/engine.cpp


diff --git a/engines/mads/madsv2/animview/anim_timer.cpp b/engines/mads/madsv2/animview/anim_timer.cpp
index 360e8f8d6f9..1dc0d070bd6 100644
--- a/engines/mads/madsv2/animview/anim_timer.cpp
+++ b/engines/mads/madsv2/animview/anim_timer.cpp
@@ -26,6 +26,7 @@
 #include "mads/madsv2/core/matte.h"
 #include "mads/madsv2/core/mcga.h"
 #include "mads/madsv2/core/pal.h"
+#include "mads/madsv2/core/timer.h"
 #include "mads/madsv2/engine.h"
 
 namespace MADS {
@@ -46,7 +47,6 @@ static int matteId;
 static int normalTimer1, imageCount;
 static int messageCount;
 static int frameViewX, frameViewY;
-static int currentViewX, currentViewY;
 
 void anim_timer_init() {
 	paletteHandle = 0;
@@ -60,7 +60,7 @@ void anim_timer_init() {
 
 void anim_timer() {
 	bool flag = false;
-	uint32 currTimer = g_system->getMillis();
+	uint32 currTimer = timer_read();
 	Speech *speech;
 	Frame *frame;
 	int sound, count;
@@ -169,7 +169,6 @@ block2:
 		if (!picture_map.one_to_one) {
 			tile_pan(&picture_map, frameViewX, frameViewY);
 			tile_pan(&depth_map, frameViewX, frameViewY);
-
 		}
 
 		image_marker = 1;
@@ -204,14 +203,15 @@ block2:
 				img->depth == img2->depth &&
 				img->scale == img2->scale;
 			if (found)
-				img2->flags = 0;
+				img2->flags = IMAGE_STATIC;
 		}
 
 		if (!found) {
 			assert(image_marker < IMAGE_LIST_SIZE);
 			image_list[image_marker] = *img;
 			Series *series = series_list[img->series_id];
-			series->delta_series = (series->delta_series < 1) ? 1 : -4;
+			image_list[image_marker].flags = (series->delta_series >= 1) ?
+				IMAGE_DELTA : IMAGE_UPDATE;
 			++image_marker;
 		}
 	}
@@ -233,7 +233,7 @@ block2:
 
 block3:
 	if (runFx) {
-		currTimer = g_system->getMillis();
+		currTimer = timer_read();
 		if (currTimer < timer1) {
 			normalTimer1 = -1;
 			goto done;
diff --git a/engines/mads/madsv2/animview/animview.cpp b/engines/mads/madsv2/animview/animview.cpp
index e20330d24bc..cd72d568818 100644
--- a/engines/mads/madsv2/animview/animview.cpp
+++ b/engines/mads/madsv2/animview/animview.cpp
@@ -56,7 +56,7 @@ bool timerFlag1;
 bool peelFlag;
 int runCtr1;
 int runFx;
-uint32 timer1, timer2;
+long timer1, timer2;
 AnimPtr current_anim;
 AnimInterPtr current_anim_inter;
 int speechIndex;
@@ -66,6 +66,7 @@ int loadFontFlag;
 int imageFrame;
 CycleList anim_cycle_list;
 bool has_cycles;
+int currentViewX, currentViewY;
 
 static const byte FX_TIMES[16] = {
 	0, 110, 110, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, 0
@@ -187,6 +188,9 @@ static void run_animation(int animIndex) {
 
 	buffer_fill(scr_inter_orig, 0);
 
+	currentViewX = currentViewY = -1;
+	current_error_code = error_code;
+
 	if (minFrame == -1)
 		minFrame = 0;
 	if (maxFrame == -1)
@@ -195,7 +199,7 @@ static void run_animation(int animIndex) {
 	minFrame = CLIP<int>(minFrame, 0, current_anim->num_frames);
 	maxFrame = CLIP<int>(maxFrame, 0, maxFrame);
 	if (animIndex == 0)
-		timer1 = g_system->getMillis();
+		timer1 = timer_read();
 
 	speechIndex = -1;
 	loadFontFlag = current_anim->load_flags & AA_LOAD_FONT;
@@ -266,7 +270,7 @@ static void run_animation(int animIndex) {
 
 	if (!current_error_code && current_anim->misc_slow_fade) {
 		timer_activate_low_priority(nullptr);
-		timer2 = g_system->getMillis();
+		timer2 = timer_read();
 		bool fadeFlag = true;
 
 		while (fadeFlag && !current_error_code) {
@@ -280,7 +284,7 @@ static void run_animation(int animIndex) {
 				current_error_code = true;
 
 			g_system->delayMillis(10);
-			if (g_system->getMillis() < timer2)
+			if (timer_read() < timer2)
 				continue;
 
 			if (peelFlag) {
@@ -330,12 +334,11 @@ static void run_animation(int animIndex) {
  * in sequence
  */
 static void animate() {
-	char buf[80], speech_name[80];
+	char buf[80];
 	AnimFile anim_in;
 	int count, series_ctr, ctr;
 	int soundLoadFlag = 0;
 	bool foundSound;
-	int oldMode;
 	int imageIndex;
 	static int packIndex = 0;
 
diff --git a/engines/mads/madsv2/animview/animview.h b/engines/mads/madsv2/animview/animview.h
index 643609b6e2a..a7aeed408fd 100644
--- a/engines/mads/madsv2/animview/animview.h
+++ b/engines/mads/madsv2/animview/animview.h
@@ -41,7 +41,7 @@ extern bool timerFlag1;
 extern bool peelFlag;
 extern int runCtr1;
 extern int runFx;
-extern uint32 timer1, timer2;;
+extern long timer1, timer2;;
 extern AnimPtr current_anim;
 extern AnimInterPtr current_anim_inter;
 extern int speechIndex;
@@ -51,6 +51,7 @@ extern int loadFontFlag;
 extern int imageFrame;
 extern CycleList anim_cycle_list;
 extern bool has_cycles;
+extern int currentViewX, currentViewY;
 
 
 // Main animview function
diff --git a/engines/mads/madsv2/engine.cpp b/engines/mads/madsv2/engine.cpp
index 4b78734500d..090b70f017e 100644
--- a/engines/mads/madsv2/engine.cpp
+++ b/engines/mads/madsv2/engine.cpp
@@ -292,14 +292,17 @@ void MADSV2Engine::pollEvents() {
 }
 
 void MADSV2Engine::checkForTimerFunction() {
-	if (_timerFunction) {
+	if (_timerFunction && _nextTimerTime != (uint32)-1) {
 		uint32 time = g_system->getMillis();
 		if (time >= _nextTimerTime) {
-			// Determine the next time to call the function at 60Hz
-			_nextTimerTime = time + (1000 / 60);
+			// Flag the timer as disabled to prevent recursive calls
+			_nextTimerTime = (uint32)-1;
 
 			// Call the timer
 			_timerFunction();
+
+			// Determine the next time to call the function at 60Hz
+			_nextTimerTime = time + (1000 / 60);
 		}
 	}
 }




More information about the Scummvm-git-logs mailing list