use strict;
for my $f (<DATA>) {
	chomp $f;
	if (open F, "../$f" and binmode F) {
		local $/;
		$_ = <F>;
		if (/^TYPE C\r\nMUSIC (\w{4})\r\n/m) {
			my $music = hex($1);
			my $i = 2 + index $_, "\xff\xff";
			while ($i < length) {
				my ($start, $end) = unpack("x${i}vv", $_);
				# printf "MUSIC %04X START %04X END %04X %s\n", $music, $start, $end, $f;
				if ($start == $music) {
					my $o = $_;
					for my $p (0 .. 63) {
						my ($l, $h) = unpack("x${i}x24x${p}Cx63C", $_);
						if ($h == 0xff && $l != 0xff) {
							printf "pattern %02x at %02x%02x %s\n", $p, $h, $l, $f;
							die if substr($_, $i + 24 + $p, 1) ne chr($l);
							substr($_, $i + 24 + $p, 1, "\xff");
						}
					}
					if ($_ ne $o) {
						open F, ">../$f" and binmode F and print F $_ or die;
					}
					last;
				}
				printf "MUSIC %04X START %04X END %04X %s\n", $music, $start, $end, $f;
				$i += 5 + $end - $start;
				print "MUSIC block not found in $f\n" if $i >= length;
			}
		}
		else {
			print "Not TYPE C: $f\n";
		}
	}
	else {
		print "$f: cannot open\n";
	}
}
__DATA__
asma/Composers/Badkowski_Marek/Nemesis.sap
asma/Composers/Badkowski_Marek/Vacares.sap
asma/Composers/Banas_Pawel/Allesgut.sap
asma/Composers/Banaszkiewicz_Marcin/Jean_Michel_Jarre.sap
asma/Composers/Banaszkiewicz_Marcin/Terror2000_Odlot.sap
asma/Composers/Banaszkiewicz_Michal/Hugo_2.sap
asma/Composers/Bendyk_Piotr/Prozac_Dream_second_part.sap
asma/Composers/Bendyk_Piotr/Silly_Venture_2k18_Invitat.sap
asma/Composers/Bernasek_Jiri/Multi_Dash.sap
asma/Composers/Bernasek_Jiri/Strange_Mountains_II.sap
asma/Composers/Bienias_Adam/Digital_Trash.sap
asma/Composers/Bienias_Adam/Rzog_Joins_XE_Team_1.sap
asma/Composers/Bienias_Adam/Rzog_Joins_XE_Team_2.sap
asma/Composers/Bryla_Krzysztof/Demo_Music_2.sap
asma/Composers/Bryla_Krzysztof/Endless_Dream_2.sap
asma/Composers/Bryla_Krzysztof/Odyseja.sap
asma/Composers/Bryla_Krzysztof/Persil.sap
asma/Composers/Bryla_Krzysztof/Ray_of_Hope_End.sap
asma/Composers/Bryla_Krzysztof/Techno_Test.sap
asma/Composers/Bryla_Krzysztof/Techwop.sap
asma/Composers/Bryla_Krzysztof/Woppie_V2.sap
asma/Composers/Ce_Pumpkin/Life_to_Back.sap
asma/Composers/Ce_Pumpkin/Too_Hard_4_1.sap
asma/Composers/Cierkonski_Michal/Atari_Makes_Me_Sick_1.sap
asma/Composers/Cierkonski_Michal/Coitus_Interruptus.sap
asma/Composers/Cierkonski_Michal/The_Car_SA.sap
asma/Composers/Cierkonski_Michal/Yo.sap
asma/Composers/Claas_Clever/Speed_Matter.sap
asma/Composers/Cybruch_Ryszard/Endless_Dream_4.sap
asma/Composers/Czartynski_Marcin/Asskicker_Main_Part.sap
asma/Composers/Czartynski_Marcin/Cedyn1.sap
asma/Composers/Czartynski_Marcin/Exodus.sap
asma/Composers/Czartynski_Marcin/Paczka_Tynku_2.sap
asma/Composers/Czartynski_Marcin/Top_Secret.sap
asma/Composers/Derkach_Andrey/Zybex.sap
asma/Composers/Drozdowski_Marek/Dual_Yellow_Energy.sap
asma/Composers/Drozdowski_Marek/Land.sap
asma/Composers/Drozdowski_Marek/Lemmings_Prevision_Intro.sap
asma/Composers/Drozdowski_Marek/Shake.sap
asma/Composers/Drozdowski_Marek/Shakemix.sap
asma/Composers/Drozdowski_Marek/Sweet_Illusions_APC_Part.sap
asma/Composers/Eisenhammer_Zdenek/Deus_Ex_Machina.sap
asma/Composers/Ezcan_Kemal/Chromatics.sap
asma/Composers/Ezcan_Kemal/Fred_vom_Jupiter.sap
asma/Composers/Ezcan_Kemal/Tinory_Quest_Invention_13.sap
asma/Composers/Ezcan_Kemal/Tinory_Quest_Morning.sap
asma/Composers/Ezcan_Kemal/Tinory_Quest_Praeludium_15.sap
asma/Composers/Ezcan_Kemal/Tinory_Quest_Praeludium_5.sap
asma/Composers/Ezcan_Kemal/Tinory_Quest_Praeludium_6.sap
asma/Composers/Farkas_Felker/Cool_Emotion_Intro.sap
asma/Composers/Farkas_Felker/Joyride_Intro.sap
asma/Composers/Farkas_Felker/Joyride_Landscape.sap
asma/Composers/Farkas_Felker/Joyride_Scrolls.sap
asma/Composers/Feske_Nils/Short.sap
asma/Composers/Galinski_Adrian/Demologicus_1.sap
asma/Composers/Galinski_Adrian/Demologicus_6.sap
asma/Composers/Galinski_Adrian/Intel_Outside_Fractal_Part.sap
asma/Composers/Galinski_Adrian/Intel_Outside_Intro.sap
asma/Composers/Galinski_Adrian/Rockman.sap
asma/Composers/Gilbertson_Gary/Face_of_the_Galaxy.sap
asma/Composers/Gmurek_Konrad/Test_Drive.sap
asma/Composers/Godlewski_Artur/Space.sap
asma/Composers/Golewski_Filip/Big_Zine_1_Greetings.sap
asma/Composers/Golewski_Filip/Sweet.sap
asma/Composers/Golewski_Filip/Tekkno.sap
asma/Composers/Golewski_Filip/Unknown_1.sap
asma/Composers/Golewski_Filip/Unknown_2.sap
asma/Composers/Gorecki_Marek/Microdemo_5.sap
asma/Composers/Gorecki_Marek/Nexuss.sap
asma/Composers/Grad_Jacek/Dwie_Wieze.sap
asma/Composers/Grad_Jacek/Extra.sap
asma/Composers/Grad_Jacek/Fatum_Intro.sap
asma/Composers/Kwiatek_Grzegorz/Energy_1_Loader.sap
asma/Composers/Kwiatek_Grzegorz/Sadness.sap
asma/Composers/Sychowicz_Lukasz/Wariacje_na_drutach.sap
asma/Composers/Sychowicz_Lukasz/X_Ray_2.sap
asma/Composers/Wasiel_Bartek/Triple_Threat.sap
asma/Composers/Holda_Leszek/Klatwa.sap
asma/Composers/Hryn_Piotr/Demos_End.sap
asma/Composers/Hryn_Piotr/Demos_End_II.sap
asma/Composers/Hryn_Piotr/Endless_Dream_1.sap
asma/Composers/Hryn_Piotr/Endless_Dream_3.sap
asma/Composers/Hryn_Piotr/Endless_Dream_5.sap
asma/Composers/Hryn_Piotr/Music_Compo_93.sap
asma/Composers/Hryn_Piotr/Party_5.sap
asma/Composers/Hughes_Trevin/1bit_Body_Puncher.sap
asma/Composers/Hughes_Trevin/1bit_Boss.sap
asma/Composers/Hughes_Trevin/1bit_Phazer_Phunk.sap
asma/Composers/Hughes_Trevin/1bit_Pirate.sap
asma/Composers/Hughes_Trevin/1bit_Rock.sap
asma/Composers/Hughes_Trevin/1bit_Smile.sap
asma/Composers/Hughes_Trevin/1bit_of_Advice.sap
asma/Composers/Hughes_Trevin/1bit_of_Training_Before_Yo.sap
asma/Composers/Husak_Jakub/Bank_Bang.sap
asma/Composers/Husak_Jakub/Bank_Bang_Ingame.sap
asma/Composers/Husak_Jakub/Flying_Microbits.sap
asma/Composers/Husak_Jakub/Garfield_Part_2.sap
asma/Composers/Kalinowski_Bartosz/Fanatic.sap
asma/Composers/Kalinowski_Bartosz/Infinity.sap
asma/Composers/Kalinowski_Bartosz/Kapitan_Planeta.sap
asma/Composers/Kalinowski_Bartosz/Robin_Wojownik_Czasu_Ingam.sap
asma/Composers/Kalinowski_Bartosz/Self_Test_2.sap
asma/Composers/Kalinowski_Bartosz/Spectrum.sap
asma/Composers/Kalinowski_Bartosz/Sweet_Illusions_Credits.sap
asma/Composers/Kalinowski_Bartosz/Sweet_Illusions_Infos.sap
asma/Composers/Kalinowski_Bartosz/Sweet_Illusions_Techno.sap
asma/Composers/Karwoth_Torsten/Megablast.sap
asma/Composers/Krawczyk_Adam/Magic_Dimension_2.sap
asma/Composers/Kucisz_Tomasz/Disk_Copy.sap
asma/Composers/Kucisz_Tomasz/Graphics_Projector.sap
asma/Composers/Kucisz_Tomasz/Second_Life_Syndrome.sap
asma/Composers/Libic_Ladislav/Lac_Intro_II_part_4.sap
asma/Composers/Liebich_Tomasz/Bilinski.sap
asma/Composers/Liebich_Tomasz/Dark_Abyss.sap
asma/Composers/Liebich_Tomasz/Fluid_Kha_Title.sap
asma/Composers/Liebich_Tomasz/Ship.sap
asma/Composers/Liebich_Tomasz/Technus_Intro.sap
asma/Composers/Lis_Marcin/Perly_Orckyego.sap
asma/Composers/Loos_Uwe/ABBUC_28.sap
asma/Composers/Loos_Uwe/Das_Omen.sap
asma/Composers/Loos_Uwe/Das_Omen_Intro.sap
asma/Composers/Loos_Uwe/Studio_Dream.sap
asma/Composers/Luszcz_Tomasz/Wladca.sap
asma/Composers/Machnio_Jakub/No_Sacrifices_No_Heroics.sap
asma/Composers/Maderanek_Peter/Avex_1.sap
asma/Composers/Majchrzak_Marcin/D_City.sap
asma/Composers/Majewski_Tomasz/Stellar_Ingame.sap
asma/Composers/Makary_Brauner/Podkarpacka_Nuta.sap
asma/Composers/Makowski_Robert/Alfaboot_1.sap
asma/Composers/Makowski_Robert/Alfaboot_2.sap
asma/Composers/Makowski_Robert/Ilussion.sap
asma/Composers/Makowski_Robert/Lady_Pank.sap
asma/Composers/Makowski_Robert/Phone.sap
asma/Composers/Makowski_Robert/Techno.sap
asma/Composers/Martin_Aleksander/Troubles.sap
asma/Composers/Matoga_Adrian/Sleep.sap
asma/Composers/Mauchly_Bill/Aerobics_1_2.sap
asma/Composers/Mikolajczak_Pawel/Jaffar.sap
asma/Composers/Mikolajczak_Pawel/Magia.sap
asma/Composers/Mister_Beep/Unbearable_Bee.sap
asma/Composers/Nabialek_Dawid/Benny_Hill_Show_Theme.sap
asma/Composers/Numan_Daniel/Pentagram_3_Music_3.sap
asma/Composers/Oscadal_Filip/Brutal_Recall_Demo_Bonus.sap
asma/Composers/Oscadal_Filip/Digi_Synth.sap
asma/Composers/Oscadal_Filip/Rabbacan_The_Finale.sap
asma/Composers/Oscadal_Filip/Rabbacan_Waterlands.sap
asma/Composers/Oscadal_Filip/Rabbacan_Woodystone.sap
asma/Composers/Oscadal_Filip/Vaxeen_Cygnus_Lyrae.sap
asma/Composers/Oscadal_Filip/Vaxeen_Vaxeen_4U.sap
asma/Composers/Padula_Jaroslaw/Fuckcore.sap
asma/Composers/Padula_Jaroslaw/Hardcore.sap
asma/Composers/Padula_Jaroslaw/Keczapek.sap
asma/Composers/Padula_Jaroslaw/Kwas.sap
asma/Composers/Padula_Jaroslaw/Martwa_Cisha.sap
asma/Composers/Padula_Jaroslaw/No.sap
asma/Composers/Padula_Jaroslaw/PSH4_2.sap
asma/Composers/Padula_Jaroslaw/Prodigy.sap
asma/Composers/Padula_Jaroslaw/Pszykowitz.sap
asma/Composers/Padula_Jaroslaw/Strefa_Smierci.sap
asma/Composers/Padula_Jaroslaw/Techno_Collection_3.sap
asma/Composers/Padula_Jaroslaw/Wave_X.sap
asma/Composers/Pasek_Marek/90_60_90.sap
asma/Composers/Pelc_Janusz/Captain_Gather.sap
asma/Composers/Pelc_Janusz/Captain_Gather_Ingame.sap
asma/Composers/Pelc_Janusz/Fred.sap
asma/Composers/Pelc_Janusz/Lasermania.sap
asma/Composers/Pelc_Janusz/Misja.sap
asma/Composers/Pelc_Janusz/Trix.sap
asma/Composers/Pelc_Janusz/Try.sap
asma/Composers/Pesout_Marek/Bad_Drome.sap
asma/Composers/Pesout_Marek/Cannon.sap
asma/Composers/Pesout_Marek/Minos.sap
asma/Composers/Pesout_Marek/SOS_Solaris.sap
asma/Composers/Pesout_Marek/Trident.sap
asma/Composers/Podedworny_Wojtek/Psycho.sap
asma/Composers/Podedworny_Wojtek/Tech.sap
asma/Composers/Podedworny_Wojtek/Tech_Ingame.sap
asma/Composers/Pucinski_Rafal/Big_Zine_1_Invitro.sap
asma/Composers/Radecki_Michal/High_Voltage_Intro.sap
asma/Composers/Radecki_Michal/Neuroid.sap
asma/Composers/Radzikowski_Ireneusz/Cyper_Space.sap
asma/Composers/Radzikowski_Ireneusz/Puzintro_Part_2.sap
asma/Composers/Radzikowski_Ireneusz/Savage.sap
asma/Composers/Roemer_Markus/Biene_Maja.sap
asma/Composers/Roemer_Markus/Das_Grauen.sap
asma/Composers/Roemer_Markus/Way_You_Are.sap
asma/Composers/Rosolek_Maciej/Magia_Fortuny_Intro.sap
asma/Composers/Sabath_Peter/Graphic_Demo_8.sap
asma/Composers/Sikorski_Pawel/Warkot.sap
asma/Composers/Skrzypek_Tomasz/Spirit_Vision_1.sap
asma/Composers/Skwiot_Stanislaw/Big_in_Japan.sap
asma/Composers/Skwiot_Stanislaw/Music_from_Poland_II_p_3_4.sap
asma/Composers/Skwiot_Stanislaw/Roxette.sap
asma/Composers/Skwiot_Stanislaw/Stanley_2.sap
asma/Composers/Sniegon_Daniel/Zumbaja_Game_Over.sap
asma/Composers/Spilka_David/SCMC_Demo.sap
asma/Composers/Sterba_Radek/Sniper.sap
asma/Composers/Strzelec_Pawel/Miny.sap
asma/Composers/Strzelec_Pawel/Osadnicy.sap
asma/Composers/Stuermer_Armin/Herbert.sap
asma/Composers/Swierszcz_Piotr/Rebellion_Rise.sap
asma/Composers/Swierszcz_Piotr/Resal.sap
asma/Composers/Szczesniak_Konrad/Electra.sap
asma/Composers/Szczesniak_Konrad/Electra_Ingame.sap
asma/Composers/Szerniewicz_Robert/Bijatyka_na_Straganie.sap
asma/Composers/Szerniewicz_Robert/Siekiery.sap
asma/Composers/Szmatola_Krzysztof/Change_2.sap
asma/Composers/Szmatola_Krzysztof/Change_3.sap
asma/Composers/Szpilowski_Michal/Das_Boot_X.sap
asma/Composers/Szpilowski_Michal/Miker_4.sap
asma/Composers/Szpilowski_Michal/Overmind_2.sap
asma/Composers/Takacs_Gabriel/Survive.sap
asma/Composers/Trokowicz_Bartlomiej/Miecze_Valdgira_II.sap
asma/Composers/Vogt_Dariusz/Music_1.sap
asma/Composers/Vogt_Dariusz/Music_2.sap
asma/Composers/Voss_Roland/Ride_the_Fractals.sap
asma/Composers/Vybostok_Marian/Allstars.sap
asma/Composers/Wasilewski_Dariusz/Buu_Sampled.sap
asma/Composers/Wasilewski_Dariusz/Daras_2.sap
asma/Composers/Wasilewski_Dariusz/Guitar_Solo.sap
asma/Composers/Wasilewski_Dariusz/Koto.sap
asma/Composers/Wasilewski_Dariusz/Laguna.sap
asma/Composers/Wasilewski_Dariusz/Morph.sap
asma/Composers/Wasilewski_Dariusz/No_Limits.sap
asma/Composers/Wasilewski_Dariusz/Technoid.sap
asma/Composers/Witkiewicz_Dariusz/Annael.sap
asma/Composers/Wyszynski_Jaroslaw/Bonanza.sap
asma/Composers/Zaborowski_Robert/Bombay.sap
asma/Composers/Zuegner_Alfred/For_Emily_Whenever_I_May_F.sap
asma/Games/Adebar.sap
asma/Games/Axilox.sap
asma/Games/Biathlon.sap
asma/Games/Deflektor.sap
asma/Games/Deneb.sap
asma/Games/Ghostbusters.sap
asma/Games/Jet_Action.sap
asma/Games/King_of_Killers.sap
asma/Games/Mad_Stone.sap
asma/Games/Mental_Age_Demo.sap
asma/Games/Muminki.sap
asma/Games/Pooyan.sap
asma/Games/Saper.sap
asma/Games/Simple_Minds.sap
asma/Games/Spy_Games_Ingame.sap
asma/Games/Starbowl_Football.sap
asma/Games/Taxicab_Hill.sap
asma/Games/Technoid.sap
asma/Games/Wyspa.sap
asma/Games/X_8.sap
asma/Misc/Arena_Bzdur_Orneta95.sap
asma/Misc/Banklan_1.sap
asma/Misc/Banklan_2.sap
asma/Misc/Delicate.sap
asma/Misc/Do_You_See_the_Light.sap
asma/Misc/Electronic.sap
asma/Misc/Gazetka_1.sap
asma/Misc/Guns_n_Roses.sap
asma/Misc/Gunship.sap
asma/Misc/Halle_Project_XCIV_Top_Mag.sap
asma/Misc/Impossible_But_Real_End.sap
asma/Misc/KevSoft.sap
asma/Misc/Luzik.sap
asma/Misc/Miksik.sap
asma/Misc/Reharden.sap
asma/Misc/Sound_in_Stereo.sap
asma/Misc/Too_Hard_2_3.sap
asma/Unknown/Autum.sap
asma/Unknown/Bach.sap
asma/Unknown/Bonanza_Digi.sap
asma/Unknown/Cielito.sap
asma/Unknown/Condor.sap
asma/Unknown/Cool.sap
asma/Unknown/Demo1.sap
asma/Unknown/Demo2.sap
asma/Unknown/Dream.sap
asma/Unknown/For_Lobo_2.sap
asma/Unknown/Funicula.sap
asma/Unknown/Galliard.sap
asma/Unknown/Music1.sap
asma/Unknown/Music2.sap
asma/Unknown/Range.sap
asma/Unknown/Ranger1.sap
asma/Unknown/Ranger2.sap
asma/Unknown/Ranger3.sap
asma/Unknown/Ranger4.sap
asma/Unknown/Ranger5.sap
asma/Unknown/Ranger6.sap
asma/Unknown/Ranger7.sap
asma/Unknown/Ranger8.sap
asma/Unknown/Ranger9.sap
asma/Unknown/Sorella.sap
asma/Unknown/Telemann.sap
asma/Unknown/Think.sap
