[Scummvm-git-logs] scummvm master -> 15ea8b571e252f6f2bff288fcd7be24354ee5fa1

dreammaster noreply at scummvm.org
Tue Jun 16 08:31:14 UTC 2026


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

Summary:
a6fca5ba75 MADS: FOREST: In progress room 503
7e8bd38783 MADS: FOREST: Finished room 503
0e6b2d62ec MADS: FOREST: Implemented rooms 509 and 510
15ea8b571e MADS: FOREST: Implemented room 520


Commit: a6fca5ba756392fcbd39a375addc4598142cc3d6
    https://github.com/scummvm/scummvm/commit/a6fca5ba756392fcbd39a375addc4598142cc3d6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-06-16T16:03:03+10:00

Commit Message:
MADS: FOREST: In progress room 503

Changed paths:
    engines/mads/madsv2/forest/rooms/room503.cpp


diff --git a/engines/mads/madsv2/forest/rooms/room503.cpp b/engines/mads/madsv2/forest/rooms/room503.cpp
index 89187a9c0cf..7961800ade9 100644
--- a/engines/mads/madsv2/forest/rooms/room503.cpp
+++ b/engines/mads/madsv2/forest/rooms/room503.cpp
@@ -1,4 +1,4 @@
-/* ScummVM - Graphic Adventure Engine
+/* 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
@@ -20,17 +20,23 @@
  */
 
 #include "mads/madsv2/core/conv.h"
+#include "mads/madsv2/core/digi.h"
 #include "mads/madsv2/core/game.h"
 #include "mads/madsv2/core/imath.h"
 #include "mads/madsv2/core/inter.h"
 #include "mads/madsv2/core/kernel.h"
+#include "mads/madsv2/core/matte.h"
+#include "mads/madsv2/core/midi.h"
+#include "mads/madsv2/core/mouse.h"
+#include "mads/madsv2/core/player.h"
 #include "mads/madsv2/core/sound.h"
 #include "mads/madsv2/core/text.h"
+#include "mads/madsv2/forest/journal.h"
 #include "mads/madsv2/forest/mads/inventory.h"
 #include "mads/madsv2/forest/mads/sounds.h"
 #include "mads/madsv2/forest/mads/words.h"
 #include "mads/madsv2/forest/global.h"
-#include "mads/madsv2/forest/rooms/section1.h"
+#include "mads/madsv2/forest/rooms/section5.h"
 #include "mads/madsv2/forest/rooms/room503.h"
 
 namespace MADS {
@@ -39,10 +45,24 @@ namespace Forest {
 namespace Rooms {
 
 struct Scratch {
-	int16 sprite[10];       /* Sprite series handles */
-	int16 sequence[10];     /* Sequence handles      */
-	int16 animation[10];     /* Animation handles     */
-	AnimationInfo animation_info[10];
+	int16 sprite[10];                  /* Sprite series handles */
+	int16 sequence[10];                /* Sequence handles      */
+	int16 animation[10];               /* Animation handles     */
+	AnimationInfo animation_info[13];  /* 13 entries: _val3/_val4 initialised for [0..11],
+	                                      _active/_frame for [1..12]; [10]._val3 = _90 flag,
+	                                      [11]._val3 = _98 flag */
+	int16 _pad_a4;                     /* 0xA4 unused */
+	int16 _a6;                         /* visit-count / playback-stage select */
+	int16 _pad_a8;                     /* 0xA8 unused */
+	int16 _pad_aa;                     /* 0xAA unused */
+	int16 _pad_ac;                     /* 0xAC unused */
+	int16 _ae;                         /* converse-anim handle (kernel_reset_animation / kernel_synch) */
+	int16 _pad_b0;                     /* 0xB0 unused */
+	int16 _b2;                         /* converse-anim handle (kernel_abort_animation / global_anim3) */
+	int16 _b4;                         /* ambient audio num arg / uninitialised flag */
+	int16 _b6;                         /* ambient audio playing flag */
+	int16 _b8;                         /* ambient loop active flag */
+	int16 _ba;                         /* playback variant (1 / 2 / -1) */
 };
 
 static Scratch scratch;
@@ -53,11 +73,865 @@ static Scratch scratch;
 #define aa    local->animation
 #define aainfo scratch.animation_info
 
+static void room_503_init1();
+static void room_503_init2();
+static void room_503_init3();
+
+static void room_503_anim1();
+static void room_503_anim2();
+static void room_503_anim3();
+static void room_503_anim12();
+static void room_503_anim4();
+static void room_503_anim5();
+static void room_503_anim6();
+static void room_503_anim7();
+static void room_503_anim8();
+static void room_503_anim9();
+static void room_503_anim10();
+static void room_503_anim11();
 
 static void room_503_init() {
+	scratch._b8 = -1;
+	scratch._b4 = -1;
+	scratch._ba = 1;
+	global[g009] = -1;
+
+	if (previous_room != KERNEL_RESTORING_GAME) {
+		player.walker_visible = 0;
+		player.commands_allowed = 0;
+
+		for (int count = 0; count < 12; count++) {
+			aainfo[count]._val3 = 0;
+			aainfo[count]._val4 = -1;
+			aainfo[count + 1]._active = 0;
+			aainfo[count + 1]._frame = 0;
+		}
+
+		if (previous_room != 199) {
+			if (flags[33] != 3)
+				flags[33]++;
+		}
+	}
+
+	switch (flags[33]) {
+	case -3:
+		flags[33] = 1;
+		room_503_init1();
+		break;
+	case 1:
+		room_503_init1();
+		break;
+	case 2:
+		flags[33] = 3;
+		room_503_init3();
+		break;
+	case 5:
+		room_503_init2();
+		break;
+	case 6:
+	case 7:
+		room_503_init3();
+		break;
+	default:
+		room_503_init3();
+		break;
+	}
+}
+
+static void room_503_init1() {
+	global[player_score] = 0;
+	player.walker_visible = 0;
+	player.commands_allowed = 0;
+
+	if (previous_room == 199) {
+		if (global[g100] != 0) {
+			global_digi_play(14);
+			viewing_at_y = 22;
+			scratch._ba = 2;
+			aainfo[0]._active = kernel_run_animation(kernel_name('N', 2), 106);
+			aainfo[10]._val3 = -1;
+			aa[8] = kernel_run_animation(kernel_name('F', 1), 0);
+			aainfo[8]._val3 = -1;
+			scratch._a6 = 104;
+			flags[33] = 4;
+		} else {
+			aa[9] = kernel_run_animation(kernel_name('N', 1), 106);
+			aainfo[9]._val3 = -1;
+			aainfo[0]._active = kernel_run_animation(kernel_name('N', 2), 106);
+			aainfo[10]._val3 = -1;
+
+			if (aainfo[9]._val3 == -1) {
+				kernel.trigger_setup_mode = 1;
+				digi_initial_volume(30);
+				digi_play_build(503, '_', 1, 2);
+				scratch._b8 = 1;
+			}
+
+			aainfo[0]._frame = kernel_run_animation(kernel_name('Z', 1), 0);
+			aainfo[11]._val3 = -1;
+		}
+	} else {
+		aa[9] = kernel_run_animation(kernel_name('N', 1), 106);
+		aainfo[9]._val3 = -1;
+		aainfo[0]._active = kernel_run_animation(kernel_name('N', 2), 106);
+		aainfo[10]._val3 = -1;
+
+		if (aainfo[9]._val3 == -1) {
+			kernel.trigger_setup_mode = 1;
+			digi_initial_volume(30);
+			digi_play_build(503, '_', 1, 2);
+			scratch._b8 = 1;
+		}
+
+		global_digi_play(6);
+		aa[0] = kernel_run_animation(kernel_name('y', 2), 100);
+		aainfo[0]._val3 = -1;
+		scratch._a6 = 52;
+	}
+}
+
+static void room_503_init2() {
+	viewing_at_y = 22;
+	global[player_score] = 0;
+	player.walker_visible = 0;
+	player.commands_allowed = 0;
+	mouse_hide();
+	scratch._ba = -1;
+	aa[6] = kernel_run_animation(kernel_name('F', 2), 0);
+	aainfo[6]._val3 = -1;
+}
+
+static void room_503_init3() {
+	global[player_score] = 0;
+	player.walker_visible = 0;
+	player.commands_allowed = 0;
+
+	if (previous_room == 199) {
+		if (global[g100] != 0) {
+			global_digi_play(14);
+			viewing_at_y = 22;
+			scratch._ba = 2;
+			aainfo[0]._active = kernel_run_animation(kernel_name('N', 2), 106);
+			aainfo[10]._val3 = -1;
+			aa[8] = kernel_run_animation(kernel_name('F', 1), 0);
+			aainfo[8]._val3 = -1;
+			scratch._a6 = 104;
+			flags[33] = 4;
+		} else {
+			aa[9] = kernel_run_animation(kernel_name('N', 1), 106);
+			aainfo[9]._val3 = -1;
+			aainfo[0]._active = kernel_run_animation(kernel_name('N', 2), 106);
+			aainfo[10]._val3 = -1;
+
+			if (aainfo[9]._val3 == -1) {
+				kernel.trigger_setup_mode = 1;
+				digi_initial_volume(30);
+				digi_play_build(503, '_', 1, 2);
+				scratch._b8 = 1;
+			}
+
+			aainfo[0]._frame = kernel_run_animation(kernel_name('Z', 1), 0);
+			aainfo[11]._val3 = -1;
+		}
+	} else {
+		aa[9] = kernel_run_animation(kernel_name('N', 1), 106);
+		aainfo[9]._val3 = -1;
+		aainfo[0]._active = kernel_run_animation(kernel_name('N', 2), 106);
+		aainfo[10]._val3 = -1;
+
+		if (aainfo[9]._val3 == -1) {
+			kernel.trigger_setup_mode = 1;
+			digi_initial_volume(30);
+			digi_play_build(503, '_', 1, 2);
+			scratch._b8 = 1;
+		}
+
+		aa[0] = kernel_run_animation(kernel_name('y', 1), 107);
+		aainfo[0]._val3 = -1;
+		scratch._a6 = 50;
+	}
+}
+
+static void room_503_anim1() {
+	if (kernel_anim[aa[0]].frame != aainfo[0]._val4)
+		aainfo[0]._val4 = kernel_anim[aa[0]].frame;
+
+	if (global[player_hyperwalked] == -1) {
+		aainfo[0]._val4 = scratch._a6 - 1;
+		kernel_reset_animation(aa[0], aainfo[0]._val4);
+	}
+}
+
+static void room_503_anim2() {
+	if (kernel_anim[aainfo[0]._frame].frame == aainfo[11]._val4)
+		return;
+	aainfo[11]._val4 = kernel_anim[aainfo[0]._frame].frame;
+	if (aainfo[11]._val4 == 69)
+		new_room = 501;
+}
+
+static void room_503_anim3() {
+	if (kernel_anim[aa[6]].frame != aainfo[6]._val4) {
+		aainfo[6]._val4 = kernel_anim[aa[6]].frame;
+		int frame = aainfo[6]._val4;
+		if (frame == 50) {
+			kernel_abort_animation(aa[6]);
+			aainfo[6]._val3 = 0;
+			aa[7] = kernel_run_animation(kernel_name('F', 3), 0);
+			aainfo[7]._val3 = -1;
+			kernel_synch(KERNEL_ANIM, aa[7], KERNEL_ANIM, aa[6]);
+			digi_initial_volume(50);
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+			scratch._b6 = 1;
+		} else if (frame < 50) {
+			if (frame == 1) {
+				kernel_seq_delete(seq[0]);
+				kernel_seq_delete(seq[1]);
+				kernel_seq_delete(seq[2]);
+				kernel_seq_delete(seq[3]);
+			} else if (frame == 2) {
+				digi_initial_volume(50);
+				digi_play_build(503, '_', 2, 3);
+				digi_val2 = -1;
+				scratch._b6 = 1;
+			} else if (frame == 10) {
+				digi_play_build(503, 'r', 7, 1);
+				scratch._b4 = 10;
+			}
+		}
+	}
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._b4 == 10)
+			scratch._b4 = -1;
+	}
+	if (kernel.trigger == 8) {
+		if (scratch._b6 == 1) {
+			digi_initial_volume(80);
+			scratch._b6++;
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+		} else if (scratch._b6 == 2) {
+			digi_initial_volume(100);
+			scratch._b6 = 2;
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+		}
+	}
+}
+
+static void room_503_anim4() {
+	if (kernel_anim[aa[7]].frame != aainfo[7]._val4) {
+		aainfo[7]._val4 = kernel_anim[aa[7]].frame;
+		int frame = aainfo[7]._val4;
+		if (frame == 59) {
+			new_room = 510;
+		} else if (frame < 59) {
+			if (frame == 1) {
+				digi_initial_volume(30);
+				digi_play_build(503, '_', 3, 3);
+				scratch._b6 = 1;
+				digi_val2 = -1;
+			} else if (frame == 30) {
+				digi_play_build(503, 'e', 5, 1);
+				scratch._b4 = 30;
+			}
+		}
+	}
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._b4 == 30)
+			scratch._b4 = -1;
+	}
+	if (kernel.trigger == 8) {
+		if (scratch._b6 == 1) {
+			digi_initial_volume(30);
+			scratch._b6 = 1;
+			digi_play_build(503, '_', 3, 3);
+			digi_val2 = -1;
+		}
+	}
+}
+
+static void room_503_anim5() {
+	if (kernel_anim[aa[8]].frame != aainfo[8]._val4) {
+		aainfo[8]._val4 = kernel_anim[aa[8]].frame;
+		int frame = aainfo[8]._val4;
+		if (frame == 104) {
+			new_room = 509;
+		} else if (frame < 104) {
+			if (frame == 2) {
+				digi_initial_volume(50);
+				digi_play_build(503, '_', 2, 3);
+				digi_val2 = -1;
+				scratch._b6 = 1;
+			} else if (frame == 3) {
+				digi_play_build(503, 'r', 6, 1);
+				scratch._b4 = 3;
+			}
+		}
+	}
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._b4 == 3)
+			scratch._b4 = -1;
+	}
+	if (kernel.trigger == 8) {
+		if (scratch._b6 == 1) {
+			digi_initial_volume(30);
+			scratch._b6 = 1;
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+		}
+	}
+}
+static void room_503_anim6() {
+	if (kernel_anim[aa[1]].frame != aainfo[1]._val4) {
+		aainfo[1]._val4 = kernel_anim[aa[1]].frame;
+		switch (aainfo[1]._val4) {
+		case 5:
+			aainfo[2]._active = 11;
+			digi_play_build(503, 'e', 1, 1);
+			scratch._b4 = 5;
+			break;
+		case 10:
+			if (aainfo[2]._active == 11) {
+				aainfo[1]._val4 = 5;
+				kernel_reset_animation(aa[1], 5);
+			}
+			break;
+		case 14:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 13;
+				kernel_reset_animation(aa[1], 13);
+			}
+			break;
+		case 15:
+			aainfo[2]._active = 15;
+			digi_play_build(503, 'g', 1, 1);
+			scratch._b4 = 15;
+			break;
+		case 20:
+			if (aainfo[2]._active == 15) {
+				aainfo[1]._val4 = 15;
+				kernel_reset_animation(aa[1], 15);
+			}
+			break;
+		case 24:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 23;
+				kernel_reset_animation(aa[1], 23);
+			}
+			break;
+		case 25:
+			aainfo[2]._active = 12;
+			digi_play_build(503, 'r', 1, 1);
+			scratch._b4 = 25;
+			break;
+		case 30:
+			if (aainfo[2]._active == 12) {
+				aainfo[1]._val4 = 25;
+				kernel_reset_animation(aa[1], 25);
+			}
+			break;
+		case 34:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 33;
+				kernel_reset_animation(aa[1], 33);
+			}
+			break;
+		case 35:
+			aainfo[2]._active = 15;
+			digi_play_build(503, 'g', 2, 1);
+			scratch._b4 = 35;
+			break;
+		case 40:
+			if (aainfo[2]._active == 15) {
+				aainfo[1]._val4 = 35;
+				kernel_reset_animation(aa[1], 35);
+			}
+			break;
+		case 44:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 43;
+				kernel_reset_animation(aa[1], 43);
+			}
+			break;
+		case 45:
+			aainfo[2]._active = 12;
+			digi_play_build(503, 'r', 2, 1);
+			scratch._b4 = 45;
+			break;
+		case 50:
+			if (aainfo[2]._active == 12) {
+				aainfo[1]._val4 = 45;
+				kernel_reset_animation(aa[1], 45);
+			}
+			break;
+		case 54:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 53;
+				kernel_reset_animation(aa[1], 53);
+			}
+			break;
+		case 55:
+			aainfo[2]._active = 15;
+			digi_play_build(503, 'g', 3, 1);
+			scratch._b4 = 55;
+			break;
+		case 60:
+			if (aainfo[2]._active == 15) {
+				aainfo[1]._val4 = 55;
+				kernel_reset_animation(aa[1], 55);
+			}
+			break;
+		case 64:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 63;
+				kernel_reset_animation(aa[1], 63);
+			}
+			break;
+		case 65:
+			aainfo[2]._active = 12;
+			digi_play_build(503, 'r', 3, 1);
+			scratch._b4 = 65;
+			break;
+		case 70:
+			if (aainfo[2]._active == 12) {
+				aainfo[1]._val4 = 65;
+				kernel_reset_animation(aa[1], 65);
+			}
+			break;
+		case 74:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 73;
+				kernel_reset_animation(aa[1], 73);
+			}
+			break;
+		case 75:
+			aainfo[2]._active = 11;
+			digi_play_build(503, 'e', 2, 1);
+			scratch._b4 = 75;
+			break;
+		case 80:
+			if (aainfo[2]._active == 11) {
+				aainfo[1]._val4 = 75;
+				kernel_reset_animation(aa[1], 75);
+			}
+			break;
+		case 84:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 83;
+				kernel_reset_animation(aa[1], 83);
+			}
+			break;
+		case 85:
+			aainfo[2]._active = 12;
+			digi_play_build(503, 'r', 4, 1);
+			scratch._b4 = 85;
+			break;
+		case 90:
+			if (aainfo[2]._active == 12) {
+				aainfo[1]._val4 = 85;
+				kernel_reset_animation(aa[1], 85);
+			}
+			break;
+		case 94:
+			if (aainfo[2]._active == 13) {
+				aainfo[1]._val4 = 93;
+				kernel_reset_animation(aa[1], 93);
+			}
+			break;
+		case 95:
+			dont_frag_the_palette();
+			kernel_abort_animation(aa[1]);
+			aainfo[1]._val3 = 0;
+			aa[2] = kernel_run_animation("*RM503T21", 0);
+			aainfo[2]._val3 = -1;
+			kernel_synch(KERNEL_ANIM, aa[2], KERNEL_ANIM, aa[1]);
+			digi_initial_volume(20);
+			scratch._b4 = 1;
+			digi_play_build(503, '_', 1, 3);
+			digi_val2 = -1;
+			break;
+		}
+	}
+
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		switch (scratch._b4) {
+		case 5:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 6;
+			break;
+		case 6:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 10;
+			kernel_reset_animation(aa[1], 10);
+			scratch._b4 = -1;
+			break;
+		case 15:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 16;
+			break;
+		case 16:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 20;
+			kernel_reset_animation(aa[1], 20);
+			scratch._b4 = -1;
+			break;
+		case 25:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 26;
+			break;
+		case 26:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 30;
+			kernel_reset_animation(aa[1], 30);
+			scratch._b4 = -1;
+			break;
+		case 35:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 36;
+			break;
+		case 36:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 41;
+			kernel_reset_animation(aa[1], 41);
+			scratch._b4 = -1;
+			break;
+		case 45:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 46;
+			break;
+		case 46:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 50;
+			kernel_reset_animation(aa[1], 50);
+			scratch._b4 = -1;
+			break;
+		case 55:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 56;
+			break;
+		case 56:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 60;
+			kernel_reset_animation(aa[1], 60);
+			scratch._b4 = -1;
+			break;
+		case 65:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 66;
+			break;
+		case 66:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 70;
+			kernel_reset_animation(aa[1], 70);
+			scratch._b4 = -1;
+			break;
+		case 75:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 76;
+			break;
+		case 76:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 80;
+			kernel_reset_animation(aa[1], 80);
+			scratch._b4 = -1;
+			break;
+		case 85:
+			kernel_timing_trigger(30, 28);
+			aainfo[2]._active = 13;
+			scratch._b4 = 86;
+			break;
+		case 86:
+			aainfo[2]._active = 14;
+			aainfo[1]._val4 = 91;
+			kernel_reset_animation(aa[1], 91);
+			scratch._b4 = -1;
+			break;
+		}
+	}
+	if (kernel.trigger == 8) {
+		if (scratch._b4 == 1) {
+			digi_initial_volume(20);
+			scratch._b4 = 1;
+			digi_play_build(503, '_', 1, 3);
+			digi_val2 = -1;
+		}
+	}
+}
+static void room_503_anim7() {
+	if (kernel_anim[aa[2]].frame == aainfo[2]._val4)
+		return;
+	aainfo[2]._val4 = kernel_anim[aa[2]].frame;
+	if (aainfo[2]._val4 == 31) {
+		dont_frag_the_palette();
+		kernel_abort_animation(aa[2]);
+		aainfo[2]._val3 = 0;
+		aa[3] = kernel_run_animation("*RM503T22", 0);
+		aainfo[3]._val3 = -1;
+		kernel_synch(KERNEL_ANIM, aa[3], KERNEL_ANIM, aa[2]);
+		digi_initial_volume(20);
+		scratch._b4 = 1;
+		digi_play_build(503, '_', 1, 3);
+		digi_val2 = -1;
+	}
+}
+
+static void room_503_anim8() {
+	if (kernel_anim[aa[3]].frame == aainfo[3]._val4)
+		goto check_trigger;
+	aainfo[3]._val4 = kernel_anim[aa[3]].frame;
+
+	if (aainfo[3]._val4 == 5) {
+		aainfo[4]._active = 15;
+		digi_play_build(503, 'g', 4, 1);
+		scratch._b4 = 5;
+	} else if (aainfo[3]._val4 == 10) {
+		if (aainfo[4]._active == 15) {
+			aainfo[3]._val4 = 5;
+			kernel_reset_animation(aa[3], 5);
+		}
+	} else if (aainfo[3]._val4 == 14) {
+		if (aainfo[4]._active == 13) {
+			aainfo[3]._val4 = 13;
+			kernel_reset_animation(aa[3], 13);
+		}
+	} else if (aainfo[3]._val4 == 42) {
+		dont_frag_the_palette();
+		kernel_abort_animation(aa[3]);
+		aainfo[3]._val3 = 0;
+		aa[4] = kernel_run_animation(kernel_name('T', 3), 0);
+		aainfo[4]._val3 = -1;
+		kernel_synch(KERNEL_ANIM, aa[3], KERNEL_ANIM, aa[4]);
+		digi_initial_volume(20);
+		scratch._b4 = 1;
+		digi_play_build(503, '_', 1, 3);
+		digi_val2 = -1;
+	}
+
+check_trigger:
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._b4 == 5) {
+			kernel_timing_trigger(30, 28);
+			aainfo[4]._active = 13;
+			scratch._b4 = 6;
+		} else if (scratch._b4 == 6) {
+			aainfo[4]._active = 14;
+			aainfo[3]._val4 = 10;
+			kernel_reset_animation(aa[3], 10);
+			scratch._b4 = -1;
+		}
+	}
+}
+static void room_503_anim9()  { }
+
+static void room_503_anim10() {
+	if (kernel_anim[aa[5]].frame != aainfo[5]._val4) {
+		aainfo[5]._val4 = kernel_anim[aa[5]].frame;
+		int frame = aainfo[5]._val4;
+		if (frame == 40) {
+			midi_stop();
+			global[g100] = -1;
+			display_journal();
+		} else if (frame < 40) {
+			if (frame == 5) {
+				aainfo[6]._active = 16;
+				digi_play_build(503, 'i', 1, 1);
+				scratch._b4 = 5;
+			} else if (frame == 10) {
+				if (aainfo[6]._active == 16) {
+					aainfo[5]._val4 = 5;
+					kernel_reset_animation(aa[5], 5);
+				}
+			} else if (frame == 14) {
+				if (aainfo[6]._active == 13) {
+					aainfo[5]._val4 = 13;
+					kernel_reset_animation(aa[5], 13);
+				}
+			} else if (frame == 31) {
+				aainfo[6]._active = 16;
+				digi_play_build(503, 'b', 3, 1);
+				scratch._b4 = 31;
+			} else if (frame == 36) {
+				if (aainfo[6]._active == 16) {
+					aainfo[5]._val4 = 31;
+					kernel_reset_animation(aa[5], 31);
+				}
+			} else if (frame == 39) {
+				if (aainfo[6]._active == 13) {
+					aainfo[5]._val4 = 38;
+					kernel_reset_animation(aa[5], 38);
+				}
+			}
+		}
+	}
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._b4 == 5) {
+			kernel_timing_trigger(30, 28);
+			aainfo[6]._active = 13;
+			scratch._b4 = 6;
+		} else if (scratch._b4 == 6) {
+			aainfo[6]._active = 14;
+			aainfo[5]._val4 = 9;
+			kernel_reset_animation(aa[5], 9);
+			scratch._b4 = -1;
+		} else if (scratch._b4 == 31) {
+			kernel_timing_trigger(30, 28);
+			aainfo[6]._active = 13;
+			scratch._b4 = 32;
+		} else if (scratch._b4 == 32) {
+			aainfo[6]._active = 14;
+			aainfo[5]._val4 = 36;
+			kernel_reset_animation(aa[5], 36);
+			scratch._b4 = -1;
+		}
+	}
+}
+
+static void room_503_anim11() {
+	if (kernel_anim[aainfo[0]._active].frame == aainfo[10]._val4)
+		return;
+	aainfo[10]._val4 = kernel_anim[aainfo[0]._active].frame;
+
+	int frame = aainfo[10]._val4;
+	if (frame == 49) {
+		aainfo[10]._val4 = 1;
+		kernel_reset_animation(aainfo[0]._active, 1);
+		return;
+	}
+	if (frame > 49)
+		return;
+
+	if (frame == 19 || frame == 30 || frame == 40) {
+		if (imath_random(0, 100) > 20) {
+			aainfo[10]._val4--;
+			kernel_reset_animation(aainfo[0]._active, aainfo[10]._val4);
+		}
+	} else if (frame == 34 || frame == 46) {
+		if (imath_random(0, 100) > 40) {
+			aainfo[10]._val4--;
+			kernel_reset_animation(aainfo[0]._active, aainfo[10]._val4);
+		}
+	} else if (frame == 20) {
+		if (imath_random(0, 100) > 60) {
+			aainfo[10]._val4 -= 2;
+			kernel_reset_animation(aainfo[0]._active, aainfo[10]._val4);
+		}
+	}
+}
+
+static void room_503_anim12() {
+	if (kernel_anim[aa[9]].frame == aainfo[9]._val4)
+		return;
+	aainfo[9]._val4 = kernel_anim[aa[9]].frame;
+	if (aainfo[9]._val4 == 49) {
+		aainfo[9]._val4 = 1;
+		kernel_reset_animation(aa[9], 1);
+	}
 }
 
 static void room_503_daemon() {
+	if (global[g101] != 0 && global[player_hyperwalked] == -1) {
+		game_save_name(0);
+		kernel_save_game(save_game_buf);
+		new_room = 904;
+	}
+
+	switch (kernel.trigger) {
+	case 8:
+		if (scratch._b8 == 1) {
+			digi_initial_volume(30);
+			digi_play_build(503, '_', 1, 3);
+			digi_val2 = -1;
+			scratch._b8 = 1;
+		}
+		break;
+
+	case 27:
+		global[walker_converse_now] = 0;
+		kernel_abort_animation(scratch._b2);
+		kernel_reset_animation(scratch._ae, 1);
+		kernel_synch(KERNEL_ANIM, scratch._ae, KERNEL_NOW, 0);
+		global[g133] = 0;
+		player.commands_allowed = -1;
+		break;
+
+	case 100:
+		kernel_abort_animation(aa[0]);
+		aainfo[0]._val3 = 0;
+		aa[1] = kernel_run_animation(kernel_name('t', 1), 1);
+		kernel_synch(KERNEL_ANIM, aa[1], KERNEL_NOW, 0);
+		aainfo[1]._val3 = -1;
+		player.commands_allowed = 0;
+		digi_initial_volume(20);
+		scratch._b4 = 1;
+		digi_play_build(503, '_', 1, 3);
+		digi_val2 = -1;
+		break;
+
+	case 104:
+		if (flags[33] == 6) {
+			aa[8] = kernel_run_animation(kernel_name('F', 1), 0);
+			aainfo[8]._val3 = -1;
+			scratch._a6 = 104;
+			digi_initial_volume(50);
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+			scratch._b6 = 1;
+		}
+		break;
+
+	case 105:
+		if (flags[33] == 7) {
+			aa[6] = kernel_run_animation(kernel_name('F', 2), 0);
+			aainfo[6]._val3 = -1;
+			digi_initial_volume(50);
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+			scratch._b6 = 1;
+		}
+		break;
+
+	case 107:
+		kernel_abort_animation(aa[0]);
+		aainfo[0]._val3 = 0;
+		midi_stop();
+		global[g100] = -1;
+		display_journal();
+		break;
+
+	default:
+		break;
+	}
+
+	if (aainfo[0]._val3 != 0)  room_503_anim1();
+	if (aainfo[11]._val3 != 0) room_503_anim2();
+	if (aainfo[6]._val3 != 0)  room_503_anim3();
+	if (aainfo[7]._val3 != 0)  room_503_anim4();
+	if (aainfo[8]._val3 != 0)  room_503_anim5();
+	if (aainfo[1]._val3 != 0)  room_503_anim6();
+	if (aainfo[2]._val3 != 0)  room_503_anim7();
+	if (aainfo[3]._val3 != 0)  room_503_anim8();
+	if (aainfo[4]._val3 != 0)  room_503_anim9();
+	if (aainfo[5]._val3 != 0)  room_503_anim10();
+
+	if (scratch._ba == 1) {
+		room_503_anim12();
+		room_503_anim11();
+	} else if (scratch._ba == 2) {
+		room_503_anim11();
+	}
+
+	if (global[walker_converse_now] != 0)
+		global_anim3(scratch._b2, &global[g008]);
 }
 
 static void room_503_pre_parser() {
@@ -70,13 +944,26 @@ void room_503_synchronize(Common::Serializer &s) {
 	for (int16 &v : scratch.sprite)    s.syncAsSint16LE(v);
 	for (int16 &v : scratch.sequence)  s.syncAsSint16LE(v);
 	for (int16 &v : scratch.animation) s.syncAsSint16LE(v);
+	for (AnimationInfo &ai : scratch.animation_info) ai.synchronize(s);
+	s.syncAsSint16LE(scratch._pad_a4);
+	s.syncAsSint16LE(scratch._a6);
+	s.syncAsSint16LE(scratch._pad_a8);
+	s.syncAsSint16LE(scratch._pad_aa);
+	s.syncAsSint16LE(scratch._pad_ac);
+	s.syncAsSint16LE(scratch._ae);
+	s.syncAsSint16LE(scratch._pad_b0);
+	s.syncAsSint16LE(scratch._b2);
+	s.syncAsSint16LE(scratch._b4);
+	s.syncAsSint16LE(scratch._b6);
+	s.syncAsSint16LE(scratch._b8);
+	s.syncAsSint16LE(scratch._ba);
 }
 
 void room_503_preload() {
-	room_init_code_pointer = room_503_init;
+	room_init_code_pointer       = room_503_init;
 	room_pre_parser_code_pointer = room_503_pre_parser;
-	room_parser_code_pointer = room_503_parser;
-	room_daemon_code_pointer = room_503_daemon;
+	room_parser_code_pointer     = room_503_parser;
+	room_daemon_code_pointer     = room_503_daemon;
 
 	global_section_walker();
 	global_section_interface();


Commit: 7e8bd38783978e8d9ac1ffb5ff52566ebb4de2d7
    https://github.com/scummvm/scummvm/commit/7e8bd38783978e8d9ac1ffb5ff52566ebb4de2d7
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-06-16T16:55:36+10:00

Commit Message:
MADS: FOREST: Finished room 503

Changed paths:
    engines/mads/madsv2/forest/rooms/room503.cpp


diff --git a/engines/mads/madsv2/forest/rooms/room503.cpp b/engines/mads/madsv2/forest/rooms/room503.cpp
index 7961800ade9..e13cf1f3c89 100644
--- a/engines/mads/madsv2/forest/rooms/room503.cpp
+++ b/engines/mads/madsv2/forest/rooms/room503.cpp
@@ -731,7 +731,225 @@ check_trigger:
 		}
 	}
 }
-static void room_503_anim9()  { }
+static void room_503_anim9() {
+	if (kernel_anim[aa[4]].frame != aainfo[4]._val4) {
+		aainfo[4]._val4 = kernel_anim[aa[4]].frame;
+		switch (aainfo[4]._val4) {
+		case 5:
+			aainfo[5]._active = 11;
+			digi_play_build(503, 'e', 3, 1);
+			scratch._b4 = 5;
+			break;
+		case 9:
+			if (aainfo[5]._active == 11) {
+				aainfo[4]._val4 = 5;
+				kernel_reset_animation(aa[4], 5);
+			}
+			break;
+		case 18:
+			if (aainfo[5]._active == 13) {
+				aainfo[4]._val4 = 17;
+				kernel_reset_animation(aa[4], 17);
+			}
+			break;
+		case 19:
+			aainfo[5]._active = 15;
+			digi_play_build(503, 'g', 5, 1);
+			scratch._b4 = 19;
+			break;
+		case 22:
+			if (aainfo[5]._active == 15) {
+				aainfo[4]._val4 = 19;
+				kernel_reset_animation(aa[4], 19);
+			}
+			break;
+		case 25:
+			if (aainfo[5]._active == 13) {
+				aainfo[4]._val4 = 24;
+				kernel_reset_animation(aa[4], 24);
+			}
+			break;
+		case 26:
+			aainfo[5]._active = 11;
+			digi_play_build(503, 'e', 4, 1);
+			scratch._b4 = 26;
+			break;
+		case 30:
+			if (aainfo[5]._active == 11) {
+				aainfo[4]._val4 = 26;
+				kernel_reset_animation(aa[4], 26);
+			}
+			break;
+		case 36:
+			if (aainfo[5]._active == 13) {
+				aainfo[4]._val4 = 35;
+				kernel_reset_animation(aa[4], 35);
+			}
+			break;
+		case 37:
+			aainfo[5]._active = 16;
+			digi_play_build(503, 'b', 1, 1);
+			scratch._b4 = 37;
+			break;
+		case 45:
+			if (aainfo[5]._active == 16) {
+				aainfo[4]._val4 = 37;
+				kernel_reset_animation(aa[4], 37);
+			}
+			break;
+		case 50:
+			if (aainfo[5]._active == 13) {
+				aainfo[4]._val4 = 49;
+				kernel_reset_animation(aa[4], 49);
+			}
+			break;
+		case 51:
+			aainfo[5]._active = 12;
+			digi_play_build(503, 'r', 5, 1);
+			scratch._b4 = 51;
+			break;
+		case 55:
+			if (aainfo[5]._active == 12) {
+				aainfo[4]._val4 = 51;
+				kernel_reset_animation(aa[4], 51);
+			}
+			break;
+		case 60:
+			if (aainfo[5]._active == 13) {
+				aainfo[4]._val4 = 59;
+				kernel_reset_animation(aa[4], 59);
+			}
+			break;
+		case 61:
+			aainfo[5]._active = 15;
+			digi_play_build(503, 'g', 6, 1);
+			scratch._b4 = 61;
+			break;
+		case 66:
+			if (aainfo[5]._active == 15) {
+				aainfo[4]._val4 = 61;
+				kernel_reset_animation(aa[4], 61);
+			}
+			break;
+		case 69:
+			if (aainfo[5]._active == 13) {
+				aainfo[4]._val4 = 68;
+				kernel_reset_animation(aa[4], 68);
+			}
+			break;
+		case 70:
+			aainfo[5]._active = 10;
+			digi_play_build(503, 'b', 2, 1);
+			scratch._b4 = 70;
+			break;
+		case 73:
+			if (aainfo[5]._active == 10) {
+				aainfo[4]._val4 = 70;
+				kernel_reset_animation(aa[4], 70);
+			}
+			break;
+		case 74:
+			if (aainfo[5]._active == 13) {
+				aainfo[4]._val4 = 73;
+				kernel_reset_animation(aa[4], 73);
+			} else {
+				dont_frag_the_palette();
+				kernel_abort_animation(aa[4]);
+				aainfo[4]._val3 = 0;
+				aa[5] = kernel_run_animation(kernel_name('T', 4), 0);
+				aainfo[5]._val3 = -1;
+				kernel_synch(KERNEL_ANIM, aa[5], KERNEL_ANIM, aa[4]);
+				digi_initial_volume(20);
+				scratch._b4 = 1;
+				digi_play_build(503, '_', 1, 3);
+				digi_val2 = -1;
+			}
+			break;
+		}
+	}
+
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		switch (scratch._b4) {
+		case 5:
+			kernel_timing_trigger(30, 28);
+			aainfo[5]._active = 13;
+			scratch._b4 = 6;
+			break;
+		case 6:
+			aainfo[5]._active = 14;
+			aainfo[4]._val4 = 9;
+			kernel_reset_animation(aa[4], 9);
+			scratch._b4 = -1;
+			break;
+		case 19:
+			kernel_timing_trigger(30, 28);
+			aainfo[5]._active = 13;
+			scratch._b4 = 20;
+			break;
+		case 20:
+			aainfo[5]._active = 14;
+			aainfo[4]._val4 = 22;
+			kernel_reset_animation(aa[4], 22);
+			scratch._b4 = -1;
+			break;
+		case 26:
+			kernel_timing_trigger(30, 28);
+			aainfo[5]._active = 13;
+			scratch._b4 = 27;
+			break;
+		case 27:
+			aainfo[5]._active = 14;
+			aainfo[4]._val4 = 30;
+			kernel_reset_animation(aa[4], 30);
+			scratch._b4 = -1;
+			break;
+		case 37:
+			kernel_timing_trigger(30, 28);
+			aainfo[5]._active = 13;
+			scratch._b4 = 38;
+			break;
+		case 38:
+			aainfo[5]._active = 14;
+			aainfo[4]._val4 = 45;
+			kernel_reset_animation(aa[4], 45);
+			scratch._b4 = -1;
+			break;
+		case 51:
+			kernel_timing_trigger(30, 28);
+			aainfo[5]._active = 13;
+			scratch._b4 = 52;
+			break;
+		case 52:
+			aainfo[5]._active = 14;
+			aainfo[4]._val4 = 55;
+			kernel_reset_animation(aa[4], 55);
+			scratch._b4 = -1;
+			break;
+		case 61:
+			kernel_timing_trigger(30, 28);
+			aainfo[5]._active = 13;
+			scratch._b4 = 62;
+			break;
+		case 62:
+			aainfo[5]._active = 14;
+			aainfo[4]._val4 = 65;
+			kernel_reset_animation(aa[4], 65);
+			scratch._b4 = -1;
+			break;
+		case 70:
+			kernel_timing_trigger(30, 28);
+			aainfo[5]._active = 13;
+			scratch._b4 = 71;
+			break;
+		case 71:
+			aainfo[5]._active = 14;
+			aainfo[4]._val4 = 70;
+			kernel_reset_animation(aa[4], 70);
+			scratch._b4 = -1;
+			break;
+		}
+	}
+}
 
 static void room_503_anim10() {
 	if (kernel_anim[aa[5]].frame != aainfo[5]._val4) {
@@ -934,12 +1152,6 @@ static void room_503_daemon() {
 		global_anim3(scratch._b2, &global[g008]);
 }
 
-static void room_503_pre_parser() {
-}
-
-static void room_503_parser() {
-}
-
 void room_503_synchronize(Common::Serializer &s) {
 	for (int16 &v : scratch.sprite)    s.syncAsSint16LE(v);
 	for (int16 &v : scratch.sequence)  s.syncAsSint16LE(v);
@@ -961,8 +1173,6 @@ void room_503_synchronize(Common::Serializer &s) {
 
 void room_503_preload() {
 	room_init_code_pointer       = room_503_init;
-	room_pre_parser_code_pointer = room_503_pre_parser;
-	room_parser_code_pointer     = room_503_parser;
 	room_daemon_code_pointer     = room_503_daemon;
 
 	global_section_walker();


Commit: 0e6b2d62ecbab3449972166b3c81677d559e0d19
    https://github.com/scummvm/scummvm/commit/0e6b2d62ecbab3449972166b3c81677d559e0d19
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-06-16T18:23:46+10:00

Commit Message:
MADS: FOREST: Implemented rooms 509 and 510

Changed paths:
    engines/mads/madsv2/core/game.h
    engines/mads/madsv2/forest/rooms/room509.cpp
    engines/mads/madsv2/forest/rooms/room510.cpp


diff --git a/engines/mads/madsv2/core/game.h b/engines/mads/madsv2/core/game.h
index c98531586d9..eaf730a697f 100644
--- a/engines/mads/madsv2/core/game.h
+++ b/engines/mads/madsv2/core/game.h
@@ -190,6 +190,7 @@ extern char config_file_name[20];
 extern char save_game_key[8];
 extern char restart_game_key[40];
 extern char save_game_buf[20];
+extern int last_keypressed;
 
 extern void (*game_menu_routine)();   /* Game Menu routines      */
 extern void (*game_menu_init)();
diff --git a/engines/mads/madsv2/forest/rooms/room509.cpp b/engines/mads/madsv2/forest/rooms/room509.cpp
index 4bef95018d3..480dbdc7665 100644
--- a/engines/mads/madsv2/forest/rooms/room509.cpp
+++ b/engines/mads/madsv2/forest/rooms/room509.cpp
@@ -1,4 +1,4 @@
-/* ScummVM - Graphic Adventure Engine
+/* 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
@@ -19,18 +19,14 @@
  *
  */
 
-#include "mads/madsv2/core/conv.h"
+#include "mads/madsv2/core/digi.h"
 #include "mads/madsv2/core/game.h"
-#include "mads/madsv2/core/imath.h"
-#include "mads/madsv2/core/inter.h"
 #include "mads/madsv2/core/kernel.h"
-#include "mads/madsv2/core/sound.h"
-#include "mads/madsv2/core/text.h"
-#include "mads/madsv2/forest/mads/inventory.h"
-#include "mads/madsv2/forest/mads/sounds.h"
-#include "mads/madsv2/forest/mads/words.h"
+#include "mads/madsv2/core/matte.h"
+#include "mads/madsv2/core/mouse.h"
+#include "mads/madsv2/core/player.h"
+#include "mads/madsv2/core/sprite.h"
 #include "mads/madsv2/forest/global.h"
-#include "mads/madsv2/forest/rooms/section1.h"
 #include "mads/madsv2/forest/rooms/room509.h"
 
 namespace MADS {
@@ -39,10 +35,13 @@ namespace Forest {
 namespace Rooms {
 
 struct Scratch {
-	int16 sprite[10];       /* Sprite series handles */
-	int16 sequence[10];     /* Sequence handles      */
-	int16 animation[10];     /* Animation handles     */
-	AnimationInfo animation_info[10];
+	int16 sprite[10];           /* 0x00 — sprite series handles */
+	int16 sequence[10];         /* 0x14 — sequence handles      */
+	int16 animation[10];        /* 0x28 — animation handles     */
+	AnimationInfo animation_info[10]; /* 0x3C                   */
+	int16 _8c;                  /* 0x8C — unused                */
+	int16 _8e;                  /* 0x8E — phase/step counter    */
+	int16 _90;                  /* 0x90 — volume-tier flag      */
 };
 
 static Scratch scratch;
@@ -53,29 +52,247 @@ static Scratch scratch;
 #define aa    local->animation
 #define aainfo scratch.animation_info
 
+static void room_509_anim1();
+static void room_509_anim2();
+static void room_509_anim3();
+static void room_509_anim4();
+static void room_509_anim5();
 
 static void room_509_init() {
+	global[g101] = -1;
+	mouse_hide();
+	global[player_score] = 0;
+	global[g009] = -1;
+	global_digi_play(15);
+	global[g009] = -1;
+	viewing_at_y = 22;
+	global[player_score] = 0;
+	player.walker_visible = 0;
+	player.commands_allowed = 0;
+
+	for (int count = 0; count < 10; count++) {
+		aainfo[count]._active = 0;
+		aainfo[count]._frame = -1;
+	}
+
+	aa[0] = kernel_run_animation(kernel_name('F', 1), 0);
+	aainfo[0]._active = -1;
 }
 
 static void room_509_daemon() {
+	if (global[player_hyperwalked] == -1) {
+		game_save_name(0);
+		kernel_save_game(save_game_buf);
+		new_room = 904;
+	}
+
+	if (kernel.trigger == 102)
+		new_room = 520;
+
+	if (aainfo[0]._active) room_509_anim1();
+	if (aainfo[1]._active) room_509_anim2();
+	if (aainfo[2]._active) room_509_anim3();
+	if (aainfo[3]._active) room_509_anim4();
+	if (aainfo[4]._active) room_509_anim5();
+}
+
+static void room_509_anim1() {
+	int16 aa_frame = kernel_anim[aa[0]].frame;
+	if (aa_frame != aainfo[0]._frame) {
+		aainfo[0]._frame = aa_frame;
+		if (aa_frame == 65) {
+			dont_frag_the_palette();
+			kernel_abort_animation(aa[0]);
+			aainfo[0]._active = 0;
+			aa[1] = kernel_run_animation(kernel_name('F', 2), 0);
+			aainfo[1]._active = -1;
+			kernel_synch(KERNEL_ANIM, aa[1], KERNEL_ANIM, aa[0]);
+		} else if (aa_frame < 65) {
+			if (aa_frame == 2) {
+				digi_initial_volume(30);
+				scratch._90 = 2;
+				digi_play_build(503, '_', 2, 3);
+				digi_val2 = -1;
+			} else if (aa_frame == 15) {
+				digi_play_build(509, 'b', 1, 1);
+				scratch._8e = 15;
+			}
+		}
+	}
+
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._8e == 15) {
+			kernel_timing_trigger(30, 28);
+			scratch._8e = 16;
+		} else if (scratch._8e == 16) {
+			scratch._8e = 17;
+			digi_play_build(509, 'r', 1, 1);
+		} else if (scratch._8e == 17) {
+			scratch._8e = -1;
+		}
+	}
+
+	if (kernel.trigger == 8 && scratch._90 == 2) {
+		digi_initial_volume(60);
+		scratch._90 = 2;
+		digi_play_build(503, '_', 2, 3);
+		digi_val2 = -1;
+	}
+}
+
+static void room_509_anim2() {
+	int16 aa_frame = kernel_anim[aa[1]].frame;
+	if (aa_frame != aainfo[1]._frame) {
+		aainfo[1]._frame = aa_frame;
+		if (aa_frame == 2) {
+			digi_initial_volume(30);
+			scratch._90 = 2;
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+		} else if (aa_frame == 42) {
+			dont_frag_the_palette();
+			kernel_abort_animation(aa[1]);
+			aainfo[1]._active = 0;
+			aa[2] = kernel_run_animation(kernel_name('F', 3), 0);
+			aainfo[2]._active = -1;
+			kernel_synch(KERNEL_ANIM, aa[2], KERNEL_ANIM, aa[1]);
+		}
+	}
+
+	if (kernel.trigger == 8 && scratch._90 == 2) {
+		digi_initial_volume(60);
+		scratch._90 = 2;
+		digi_play_build(503, '_', 2, 3);
+		digi_val2 = -1;
+	}
 }
 
-static void room_509_pre_parser() {
+static void room_509_anim3() {
+	int16 aa_frame = kernel_anim[aa[2]].frame;
+	if (aa_frame != aainfo[2]._frame) {
+		aainfo[2]._frame = aa_frame;
+		if (aa_frame == 2) {
+			digi_initial_volume(30);
+			scratch._90 = 2;
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+		} else if (aa_frame == 20) {
+			dont_frag_the_palette();
+			kernel_abort_animation(aa[2]);
+			aainfo[2]._active = 0;
+			aa[3] = kernel_run_animation(kernel_name('F', 4), 0);
+			aainfo[3]._active = -1;
+			kernel_synch(KERNEL_ANIM, aa[3], KERNEL_ANIM, aa[2]);
+		}
+	}
+
+	if (kernel.trigger == 8 && scratch._90 == 2) {
+		digi_initial_volume(60);
+		scratch._90 = 2;
+		digi_play_build(503, '_', 2, 3);
+		digi_val2 = -1;
+	}
 }
 
-static void room_509_parser() {
+static void room_509_anim4() {
+	int16 aa_frame = kernel_anim[aa[3]].frame;
+	if (aa_frame != aainfo[3]._frame) {
+		aainfo[3]._frame = aa_frame;
+		if (aa_frame == 53) {
+			dont_frag_the_palette();
+			kernel_abort_animation(aa[3]);
+			aainfo[3]._active = 0;
+			aa[4] = kernel_run_animation(kernel_name('F', 5), 0);
+			aainfo[4]._active = -1;
+			kernel_synch(KERNEL_ANIM, aa[4], KERNEL_ANIM, aa[3]);
+		} else if (aa_frame < 53) {
+			if (aa_frame == 2) {
+				digi_initial_volume(30);
+				scratch._90 = 2;
+				digi_play_build(503, '_', 2, 3);
+				digi_val2 = -1;
+			} else if (aa_frame == 27) {
+				digi_play_build(509, 'r', 2, 1);
+				scratch._8e = 27;
+			}
+		}
+	}
+
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._8e == 27)
+			scratch._8e = -1;
+	}
+
+	if (kernel.trigger == 8 && scratch._90 == 2) {
+		digi_initial_volume(60);
+		scratch._90 = 2;
+		digi_play_build(503, '_', 2, 3);
+		digi_val2 = -1;
+	}
+}
+
+static void room_509_anim5() {
+	int16 aa_frame = kernel_anim[aa[4]].frame;
+	if (aa_frame != aainfo[4]._frame) {
+		aainfo[4]._frame = aa_frame;
+		if (aa_frame == 80) {
+			kernel_reset_animation(aa[4], 79);
+			aainfo[4]._frame = 79;
+		} else if (aa_frame < 80) {
+			if (aa_frame == 2) {
+				digi_initial_volume(30);
+				scratch._90 = 2;
+				digi_play_build(503, '_', 2, 3);
+				digi_val2 = -1;
+			} else if (aa_frame == 27) {
+				digi_play_build(509, 'e', 1, 1);
+				scratch._8e = 27;
+			} else if (aa_frame == 79) {
+				kernel_timing_trigger(40, 102);
+			}
+		}
+	}
+
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._8e == 27) {
+			kernel_timing_trigger(2, 28);
+			scratch._8e = 16;
+		} else if ((uint16)scratch._8e <= 27) {
+			if (scratch._8e == 16) {
+				scratch._8e = 17;
+				digi_play_build(509, 'b', 2, 1);
+			} else if (scratch._8e == 17) {
+				kernel_timing_trigger(2, 28);
+				scratch._8e = 18;
+			} else if (scratch._8e == 18) {
+				digi_play_build(509, 'r', 3, 1);
+				scratch._8e = 19;
+			} else if (scratch._8e == 19) {
+				scratch._8e = -1;
+			}
+		}
+	}
+
+	if (kernel.trigger == 8 && scratch._90 == 2) {
+		digi_initial_volume(60);
+		scratch._90 = 2;
+		digi_play_build(503, '_', 2, 3);
+		digi_val2 = -1;
+	}
 }
 
 void room_509_synchronize(Common::Serializer &s) {
 	for (int16 &v : scratch.sprite)    s.syncAsSint16LE(v);
 	for (int16 &v : scratch.sequence)  s.syncAsSint16LE(v);
 	for (int16 &v : scratch.animation) s.syncAsSint16LE(v);
+	for (AnimationInfo &ai : scratch.animation_info) ai.synchronize(s);
+	s.syncAsSint16LE(scratch._8c);
+	s.syncAsSint16LE(scratch._8e);
+	s.syncAsSint16LE(scratch._90);
 }
 
 void room_509_preload() {
 	room_init_code_pointer = room_509_init;
-	room_pre_parser_code_pointer = room_509_pre_parser;
-	room_parser_code_pointer = room_509_parser;
 	room_daemon_code_pointer = room_509_daemon;
 
 	global[g016] = -1;
diff --git a/engines/mads/madsv2/forest/rooms/room510.cpp b/engines/mads/madsv2/forest/rooms/room510.cpp
index 546e036c21f..2fcaf671ffa 100644
--- a/engines/mads/madsv2/forest/rooms/room510.cpp
+++ b/engines/mads/madsv2/forest/rooms/room510.cpp
@@ -1,4 +1,4 @@
-/* ScummVM - Graphic Adventure Engine
+/* 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
@@ -19,18 +19,17 @@
  *
  */
 
-#include "mads/madsv2/core/conv.h"
+#include "mads/madsv2/core/digi.h"
+#include "mads/madsv2/core/font.h"
 #include "mads/madsv2/core/game.h"
-#include "mads/madsv2/core/imath.h"
-#include "mads/madsv2/core/inter.h"
 #include "mads/madsv2/core/kernel.h"
-#include "mads/madsv2/core/sound.h"
-#include "mads/madsv2/core/text.h"
-#include "mads/madsv2/forest/mads/inventory.h"
-#include "mads/madsv2/forest/mads/sounds.h"
-#include "mads/madsv2/forest/mads/words.h"
+#include "mads/madsv2/core/matte.h"
+#include "mads/madsv2/core/midi.h"
+#include "mads/madsv2/core/mouse.h"
+#include "mads/madsv2/core/player.h"
+#include "mads/madsv2/core/quote.h"
+#include "mads/madsv2/core/sprite.h"
 #include "mads/madsv2/forest/global.h"
-#include "mads/madsv2/forest/rooms/section1.h"
 #include "mads/madsv2/forest/rooms/room510.h"
 
 namespace MADS {
@@ -39,10 +38,17 @@ namespace Forest {
 namespace Rooms {
 
 struct Scratch {
-	int16 sprite[10];       /* Sprite series handles */
-	int16 sequence[10];     /* Sequence handles      */
-	int16 animation[10];     /* Animation handles     */
-	AnimationInfo animation_info[10];
+	int16 sprite[10];           /* 0x00 — sprite series handles */
+	int16 sequence[10];         /* 0x14 — sequence handles      */
+	int16 animation[10];        /* 0x28 — animation handles     */
+	AnimationInfo animation_info[10]; /* 0x3C                   */
+	int16 _8c;                  /* 0x8C                         */
+	int16 _8e;                  /* 0x8E — digi-play phase check */
+	int16 _90;                  /* 0x90 — volume/replay flag    */
+	int16 _92;                  /* 0x92 — timing accumulator    */
+	int16 _94;                  /* 0x94 — sequence table index  */
+	int16 _96;                  /* 0x96 — active flag           */
+	int16 _98;                  /* 0x98 — room mode (669/670)   */
 };
 
 static Scratch scratch;
@@ -53,28 +59,307 @@ static Scratch scratch;
 #define aa    local->animation
 #define aainfo scratch.animation_info
 
+// Credits-line table
+struct Room510Entry {
+	int16 quote_id;	// quote ID to display, or -1 (schedule anim4), or -2 (end).
+	int16 x;		// x position override (0 = auto-centre on 320-wide screen).
+	int16 y;		// y position override (0 = use 70).
+};
+
+static const Room510Entry room_510_array1[112] = {
+	/* [0] unused */ {  0,  0,   0 },
+	/* [1]  */ {  74,  0,  40 }, /* [2]  */ {  75,  0,  60 },
+	/* [3]  */ {  76,  0,  80 }, /* [4]  */ {  77,  0, 100 },
+	/* [5]  */ {  -1,  0,   0 }, /* [6]  */ {  78,  0,   0 },
+	/* [7]  */ {  -1,  0,   0 }, /* [8]  */ {  79,  0,   0 },
+	/* [9]  */ {  -1,  0,   0 }, /* [10] */ {  80,  0,   0 },
+	/* [11] */ {  -1,  0,   0 }, /* [12] */ {  81,  0,   0 },
+	/* [13] */ {  -1,  0,   0 }, /* [14] */ {  82,  0,  50 },
+	/* [15] */ {  83,  0,  80 }, /* [16] */ {  -1,  0,   0 },
+	/* [17] */ {  84,  0,  50 }, /* [18] */ {  85,  0,  80 },
+	/* [19] */ {  -1,  0,   0 }, /* [20] */ {  86,  0,  50 },
+	/* [21] */ {  87,  0,  80 }, /* [22] */ {  -1,  0,   0 },
+	/* [23] */ {  88,  0,  50 }, /* [24] */ {  89,  0,  80 },
+	/* [25] */ {  -1,  0,   0 }, /* [26] */ {  90,  0,  40 },
+	/* [27] */ {  91,  0,  60 }, /* [28] */ {  92,  0,  80 },
+	/* [29] */ {  93,  0, 100 }, /* [30] */ {  -1,  0,   0 },
+	/* [31] */ {  94,  0,  50 }, /* [32] */ {  95,  0,  80 },
+	/* [33] */ {  -1,  0,   0 }, /* [34] */ {  96,  0,  50 },
+	/* [35] */ {  97,  0,  80 }, /* [36] */ {  -1,  0,   0 },
+	/* [37] */ {  98,  0,  50 }, /* [38] */ {  99,  0,  80 },
+	/* [39] */ { 100,  0, 100 }, /* [40] */ {  -1,  0,   0 },
+	/* [41] */ { 101,  0,  50 }, /* [42] */ { 102,  0,  80 },
+	/* [43] */ {  -1,  0,   0 }, /* [44] */ { 103,  0,  50 },
+	/* [45] */ { 104,  0,  80 }, /* [46] */ {  -1,  0,   0 },
+	/* [47] */ { 105,  0,  50 }, /* [48] */ { 106,  0,  80 },
+	/* [49] */ { 107,  0, 100 }, /* [50] */ {  -1,  0,   0 },
+	/* [51] */ { 108,  0,  50 }, /* [52] */ { 109,  0,  80 },
+	/* [53] */ {  -1,  0,   0 }, /* [54] */ { 110,  0,  50 },
+	/* [55] */ { 111,  0,  80 }, /* [56] */ { 112,  0, 100 },
+	/* [57] */ {  -1,  0,   0 }, /* [58] */ { 113,  0,  50 },
+	/* [59] */ { 114,  0,  80 }, /* [60] */ { 115,  0, 100 },
+	/* [61] */ {  -1,  0,   0 }, /* [62] */ { 116,  0,  50 },
+	/* [63] */ { 117,  0,  80 }, /* [64] */ {  -1,  0,   0 },
+	/* [65] */ { 118,  0,  20 }, /* [66] */ { 119,  0,  40 },
+	/* [67] */ { 120,  0,  60 }, /* [68] */ { 121,  0,  80 },
+	/* [69] */ { 122,  0, 100 }, /* [70] */ { 123,  0, 120 },
+	/* [71] */ {  -1,  0,   0 }, /* [72] */ { 124,  0,  20 },
+	/* [73] */ { 125,  0,  40 }, /* [74] */ { 126,  0,  60 },
+	/* [75] */ { 127,  0,  80 }, /* [76] */ { 128,  0, 100 },
+	/* [77] */ {  -1,  0,   0 }, /* [78] */ { 129,  0,  40 },
+	/* [79] */ { 130,  0,  80 }, /* [80] */ { 131,  0, 120 },
+	/* [81] */ {  -1,  0,   0 }, /* [82] */ { 132,  0,  40 },
+	/* [83] */ { 133,  0,  60 }, /* [84] */ { 134,  0,  80 },
+	/* [85] */ {  -1,  0,   0 }, /* [86] */ { 135,  0,  40 },
+	/* [87] */ { 136,  0,  80 }, /* [88] */ {  -1,  0,   0 },
+	/* [89] */ { 137,  0,  40 }, /* [90] */ { 138,  0,  60 },
+	/* [91] */ { 139,  0,  80 }, /* [92] */ {  -1,  0,   0 },
+	/* [93] */ { 140,  0,  40 }, /* [94] */ { 141,  0,  80 },
+	/* [95] */ {  -1,  0,   0 }, /* [96] */ { 142,  0,  20 },
+	/* [97] */ { 143,  0,  40 }, /* [98] */ { 144,  0,  60 },
+	/* [99] */ { 145,  0,  80 }, /* [100]*/ { 146,  0, 100 },
+	/* [101]*/ { 147,  0, 120 }, /* [102]*/ {  -1,  0,   0 },
+	/* [103]*/ { 148,  0,  40 }, /* [104]*/ { 149,  0,  60 },
+	/* [105]*/ { 150,  0,  80 }, /* [106]*/ { 151,  0, 100 },
+	/* [107]*/ {  -1,  0,   0 }, /* [108]*/ { 152,  0,  50 },
+	/* [109]*/ { 153,  0,  80 }, /* [110]*/ {  -1,  0,   0 },
+	/* [111]*/ {  -2,  0,   0 },
+};
+
+static void room_510_anim4() {
+	for (int i = 0; i < 10; i++)
+		kernel_message_delete(i);
+
+	// The original called an anim5 function here, which did a shift within an unused array.
+}
+
+static void room_510_load_quotes() {
+	scratch._94 = 1;
+	kernel.quotes = quote_load(
+		74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
+		93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
+		110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
+		125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
+		140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 0);
+	scratch._92 = 100;
+}
+
+static void room_510_anim1() {
+	const Room510Entry &entry = room_510_array1[scratch._94];
+	char *text = quote_string(kernel.quotes, entry.quote_id);
+	int x;
+	if (entry.x) {
+		x = entry.x;
+	} else {
+		x = 160 - font_string_width(font_conv, text, -1) / 2;
+	}
+	int y = entry.y ? entry.y : 70;
+	kernel_message_add(text, x, y, 92, 999, 0, 0);
+}
+
+static void room_510_anim2() {
+	int16 aa_frame = kernel_anim[aa[0]].frame;
+	if (aa_frame != aainfo[0]._frame) {
+		aainfo[0]._frame = aa_frame;
+		if (aa_frame == 1) {
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+			scratch._90 = 1;
+			kernel_seq_delete(seq[0]);
+			kernel_seq_delete(seq[1]);
+			kernel_seq_delete(seq[2]);
+			kernel_seq_delete(seq[3]);
+			kernel_seq_delete(seq[4]);
+		} else if (aa_frame == 57) {
+			digi_play_build(510, 'e', 1, 1);
+			scratch._8e = 63;
+		} else if (aa_frame == 131) {
+			if (digi_val1)
+				digi_stop(1);
+			scratch._90 = 133;
+			digi_play_build(510, '_', 3, 2);
+		} else if (aa_frame == 140) {
+			kernel_abort_animation(aa[0]);
+			aainfo[0]._active = 0;
+			aa[1] = kernel_run_animation(kernel_name('F', 2), 0);
+			aainfo[1]._active = -1;
+			scratch._8c = 40;
+			kernel_synch(KERNEL_ANIM, aa[1], KERNEL_ANIM, aa[0]);
+		}
+	}
+
+	if (kernel.trigger == 7 || kernel.trigger == 28) {
+		if (scratch._8e == 63) {
+			scratch._8e = 66;
+			kernel_timing_trigger(2, 28);
+		} else if (scratch._8e == 66) {
+			scratch._8e = 90;
+			digi_play_build(510, 'b', 1, 1);
+		} else if (scratch._8e == 90) {
+			scratch._8e = 91;
+			kernel_timing_trigger(2, 28);
+		} else if (scratch._8e == 91) {
+			scratch._8e = 132;
+			digi_play_build(510, 'r', 1, 1);
+		} else if (scratch._8e == 133) {
+			scratch._8e = -1;
+		}
+	}
+
+	if (kernel.trigger == 8) {
+		if (scratch._90 == 1) {
+			scratch._90 = 1;
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+		} else if (scratch._90 == 133) {
+			scratch._90 = -1;
+		}
+	}
+}
+
+static void room_510_anim3() {
+	int16 aa_frame = kernel_anim[aa[1]].frame;
+	if (aa_frame != aainfo[1]._frame) {
+		aainfo[1]._frame = aa_frame;
+		if (aa_frame == 1) {
+			digi_play_build(510, '_', 1, 2);
+			scratch._90 = 1;
+			midi_stop();
+			global_digi_play(4);
+		} else if (aa_frame == 40) {
+			midi_stop();
+			new_room = 107;
+		}
+	}
+
+	if (kernel.trigger == 8 && scratch._90 == 1)
+		scratch._90 = -1;
+}
 
 static void room_510_init() {
+	global[player_score] = 0;
+	global[g009] = 0;
+	scratch._96 = 0;
+	scratch._98 = 670;
+	viewing_at_y = 22;
+	player.walker_visible = 0;
+	player.commands_allowed = 0;
+	mouse_hide();
+
+	for (int count = 0; count < 10; count++) {
+		aainfo[count]._active = 0;
+		aainfo[count]._frame = -1;
+	}
+
+	if (previous_room == 104) {
+		room_510_load_quotes();
+		scratch._98 = 669;
+		aa[2] = kernel_run_animation(kernel_name('c', 1), 106);
+		aainfo[2]._active = -1;
+		aainfo[2]._frame = 0;
+		return;
+	}
+
+	if (global[g102] != 0 || flags[4] == 5) {
+		room_510_load_quotes();
+		kernel_timing_trigger(50, 106);
+		kernel_timing_trigger(51, 108);
+		return;
+	}
+
+	aa[0] = kernel_run_animation(kernel_name('F', 1), 0);
+	aainfo[0]._active = -1;
+	scratch._8c = 140;
 }
 
 static void room_510_daemon() {
-}
+	if (global[player_hyperwalked] == -1) {
+		if (global[g102] == 0) {
+			game_save_name(0);
+			kernel_save_game(save_game_buf);
+		}
+		global[g102] = 0;
+		new_room = 904;
+	}
+
+	switch (kernel.trigger) {
+	case 8:
+		if (scratch._8e == 668) {
+			scratch._8e = -1;
+			global[g009] = 0;
+			global_digi_play(14);
+			kernel_timing_trigger(2100, 104);
+		}
+		break;
+	case 102: {
+		int16 action = room_510_array1[scratch._94].quote_id;
+		if (action == -2) {
+			global[g102] = 0;
+			new_room = 904;
+		} else if (action == -1) {
+			kernel_timing_trigger(scratch._92, 103);
+			scratch._92 = 100;
+		} else {
+			room_510_anim1();
+			kernel_timing_trigger(1, 102);
+			scratch._92 += 20;
+		}
+		scratch._94++;
+		break;
+	}
+	case 103:
+		room_510_anim4();
+		kernel_timing_trigger(20, 102);
+		break;
+	case 104:
+		global[g009] = -1;
+		global_digi_play(11);
+		break;
+	case 106:
+		scratch._96 = -1;
+		last_keypressed = -1;
+		aainfo[2]._active = 0;
+		kernel_timing_trigger(40, 107);
+		kernel_timing_trigger(30, 102);
+		if (scratch._98 == 669)
+			kernel_timing_trigger(1400, 108);
+		break;
+	case 107:
+		mouse_cursor_sprite(cursor, 1);
+		break;
+	case 108:
+		midi_stop();
+		digi_play_build(306, '_', 999, 2);
+		scratch._8e = 668;
+		break;
+	default:
+		break;
+	}
 
-static void room_510_pre_parser() {
+	if (aainfo[0]._active) room_510_anim2();
+	if (aainfo[1]._active) room_510_anim3();
 }
 
 static void room_510_parser() {
+	player.command_ready = 0;
 }
 
 void room_510_synchronize(Common::Serializer &s) {
 	for (int16 &v : scratch.sprite)    s.syncAsSint16LE(v);
 	for (int16 &v : scratch.sequence)  s.syncAsSint16LE(v);
 	for (int16 &v : scratch.animation) s.syncAsSint16LE(v);
+	for (AnimationInfo &ai : scratch.animation_info) ai.synchronize(s);
+	s.syncAsSint16LE(scratch._8c);
+	s.syncAsSint16LE(scratch._8e);
+	s.syncAsSint16LE(scratch._90);
+	s.syncAsSint16LE(scratch._92);
+	s.syncAsSint16LE(scratch._94);
+	s.syncAsSint16LE(scratch._96);
+	s.syncAsSint16LE(scratch._98);
 }
 
 void room_510_preload() {
-	room_init_code_pointer = room_510_init;
-	room_pre_parser_code_pointer = room_510_pre_parser;
+	room_init_code_pointer   = room_510_init;
 	room_parser_code_pointer = room_510_parser;
 	room_daemon_code_pointer = room_510_daemon;
 


Commit: 15ea8b571e252f6f2bff288fcd7be24354ee5fa1
    https://github.com/scummvm/scummvm/commit/15ea8b571e252f6f2bff288fcd7be24354ee5fa1
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-06-16T18:31:02+10:00

Commit Message:
MADS: FOREST: Implemented room 520

Changed paths:
    engines/mads/madsv2/forest/rooms/room520.cpp


diff --git a/engines/mads/madsv2/forest/rooms/room520.cpp b/engines/mads/madsv2/forest/rooms/room520.cpp
index dd529a92c73..4c44a7458df 100644
--- a/engines/mads/madsv2/forest/rooms/room520.cpp
+++ b/engines/mads/madsv2/forest/rooms/room520.cpp
@@ -1,4 +1,4 @@
-/* ScummVM - Graphic Adventure Engine
+/* 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
@@ -19,18 +19,14 @@
  *
  */
 
-#include "mads/madsv2/core/conv.h"
+#include "mads/madsv2/core/digi.h"
 #include "mads/madsv2/core/game.h"
-#include "mads/madsv2/core/imath.h"
-#include "mads/madsv2/core/inter.h"
 #include "mads/madsv2/core/kernel.h"
-#include "mads/madsv2/core/sound.h"
-#include "mads/madsv2/core/text.h"
-#include "mads/madsv2/forest/mads/inventory.h"
-#include "mads/madsv2/forest/mads/sounds.h"
-#include "mads/madsv2/forest/mads/words.h"
+#include "mads/madsv2/core/matte.h"
+#include "mads/madsv2/core/mouse.h"
+#include "mads/madsv2/core/player.h"
+#include "mads/madsv2/core/sprite.h"
 #include "mads/madsv2/forest/global.h"
-#include "mads/madsv2/forest/rooms/section1.h"
 #include "mads/madsv2/forest/rooms/room520.h"
 
 namespace MADS {
@@ -39,10 +35,12 @@ namespace Forest {
 namespace Rooms {
 
 struct Scratch {
-	int16 sprite[10];       /* Sprite series handles */
-	int16 sequence[10];     /* Sequence handles      */
-	int16 animation[10];     /* Animation handles     */
+	int16 sprite[10];
+	int16 sequence[10];
+	int16 animation[10];
 	AnimationInfo animation_info[10];
+	int16 _8c;
+	int16 _8e;
 };
 
 static Scratch scratch;
@@ -53,30 +51,105 @@ static Scratch scratch;
 #define aa    local->animation
 #define aainfo scratch.animation_info
 
-
 static void room_520_init() {
-}
+	ss[0] = kernel_load_series(kernel_name('n', 1), 0);
+	seq[0] = kernel_seq_stamp(ss[0], false, -1);
+	kernel_seq_depth(seq[0], 7);
+	kernel_seq_loc(seq[0], 252, 75);
+	kernel_seq_scale(seq[0], 100);
 
-static void room_520_daemon() {
+	ss[1] = kernel_load_series(kernel_name('n', 1), 0);
+	seq[1] = kernel_seq_stamp(ss[1], false, -1);
+	kernel_seq_depth(seq[1], 7);
+	kernel_seq_loc(seq[1], 272, 80);
+	kernel_seq_scale(seq[1], 100);
+
+	ss[2] = kernel_load_series(kernel_name('p', 3), 0);
+	seq[2] = kernel_seq_stamp(ss[2], false, -1);
+	kernel_seq_depth(seq[2], 1);
+	kernel_seq_loc(seq[2], 175, 90);
+	kernel_seq_scale(seq[2], 50);
+
+	viewing_at_y = 22;
+	global[player_score] = 0;
+	global[g009] = 0;
+	player.walker_visible = 0;
+	player.commands_allowed = 0;
+	mouse_hide();
+
+	for (int i = 0; i < 10; i++) {
+		aainfo[i]._active = 0;
+		aainfo[i]._frame = -1;
+	}
+
+	kernel_timing_trigger(100, 101);
+	kernel_timing_trigger(5, 100);
 }
 
-static void room_520_pre_parser() {
+static void room_520_anim1() {
+	int16 aa_frame = kernel_anim[aa[0]].frame;
+	if (aa_frame != aainfo[0]._frame) {
+		aainfo[0]._frame = aa_frame;
+		if (aa_frame == 66) {
+			new_room = 503;
+		} else if (aa_frame < 66) {
+			if (aa_frame == 1) {
+				digi_initial_volume(90);
+				digi_play_build(503, '_', 2, 3);
+				digi_val2 = -1;
+				scratch._8e = 1;
+			} else if (aa_frame == 3) {
+				kernel_seq_delete(seq[0]);
+				kernel_seq_delete(seq[1]);
+				kernel_seq_delete(seq[2]);
+			}
+		}
+	}
+
+	if (kernel.trigger == 8 || kernel.trigger == 28) {
+		if (scratch._8e - 1 == 0) {
+			digi_initial_volume(60);
+			scratch._8e = 1;
+			digi_play_build(503, '_', 2, 3);
+			digi_val2 = -1;
+		}
+	}
 }
 
-static void room_520_parser() {
+static void room_520_daemon() {
+	if (global[player_hyperwalked] == -1) {
+		game_save_name(0);
+		kernel_save_game(save_game_buf);
+		new_room = 904;
+	}
+
+	switch (kernel.trigger) {
+	case 100:
+		aa[0] = kernel_run_animation(kernel_name('F', 1), 0);
+		aainfo[0]._active = -1;
+		scratch._8c = 66;
+		break;
+	case 101:
+		global_digi_play(14);
+		break;
+	}
+
+	if (aainfo[0]._active)
+		room_520_anim1();
 }
 
 void room_520_synchronize(Common::Serializer &s) {
 	for (int16 &v : scratch.sprite)    s.syncAsSint16LE(v);
 	for (int16 &v : scratch.sequence)  s.syncAsSint16LE(v);
 	for (int16 &v : scratch.animation) s.syncAsSint16LE(v);
+	for (AnimationInfo &ai : scratch.animation_info) ai.synchronize(s);
+	s.syncAsSint16LE(scratch._8c);
+	s.syncAsSint16LE(scratch._8e);
 }
 
 void room_520_preload() {
-	room_init_code_pointer = room_520_init;
-	room_pre_parser_code_pointer = room_520_pre_parser;
-	room_parser_code_pointer = room_520_parser;
-	room_daemon_code_pointer = room_520_daemon;
+	room_init_code_pointer       = room_520_init;
+	room_daemon_code_pointer     = room_520_daemon;
 
 	global_section_walker();
 	global_section_interface();




More information about the Scummvm-git-logs mailing list