Sierra/Dynamix sound driver hacking

Getting old DOS games working. (DOSBox topics belong in DOSBox areas below, not here).

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby ripsaw8080 » 2012-6-16 @ 10:33

MT-32 music with SB sfx seems to be working in QFG2 version 1.102 with the attached patch. I'll let those more familiar with the game than myself decide if it's fully working or not. Extract the archive into the game directory and make sure soundDrv=MTBLAST.DRV is in the RESOURCE.CFG file. If you subsequently want to switch to the MT32.DRV or SNDBLAST.DRV drivers then delete the separate SOUND.* files. I've increased the SB initialization timeout in MTBLAST.DRV to where there should be no problem at 10000 cycles and even higher, so I hope that resolves the speed issue.
Attachments
qfg2_mtblast.zip
(128.24 KiB) Downloaded 456 times
User avatar
ripsaw8080
DOSBox Author
 
Posts: 4252
Joined: 2006-4-25 @ 23:24

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby rcblanke » 2012-6-16 @ 11:45

Nice, seems to work great with my 1.105 version on a real rev1.07 MT-32. Many thanks people!
User avatar
rcblanke
Oldbie
 
Posts: 1322
Joined: 2005-4-01 @ 09:44
Location: Round 42

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby tikalat » 2012-6-16 @ 12:33

(MUNT) Okay with 1.104 + 1.105 (Anthology). I don't know if the other digital samples are re-recordings of the MT-32 ones?


Decided to play around with the broken driver some more (if I can't fix this, I'm not good enough for Krondor).

So added in polyphonic + channel aftertouch. Raised polyphony to 255. All unused by game but like HunterZ + collector mention - maybe some hobbyist can take advantage of them (I finally get it now).


The init detection problem looks to be in the SB IRQ wait routine:

Code: Select all
(broken QFG2 merged driver)

      xor   cx, cx
      mov   dh, 49h   ; 'I'
      call   sub_2108
      mov   dx, cs:word_54
      add   dx, 0Ch
      mov   al, 40h   ; '@'
      call   sub_1FC0
      mov   al, 64h   ; 'd'
      call   sub_1FC0
      mov   al, 14h
      call   sub_1FC0
      xor   al, al
      call   sub_1FC0
      xor   al, al
      call   sub_1FC0
      xor   ax, ax
      mov   cx, 200h

loc_209F:            ; CODE XREF: sub_203E+69j
      ; sblaster fix!!
      hlt


      cmp   cs:byte_56, 0
      jnz   short loc_20AC
      loop   loc_209F
      mov   ax, 3


Note: SCI0 uses the hlt too. Wonder why they took it out later. :confused:

At 32000 cycles, I didn't have an init problem. Left the default code times alone. I should raise all the default loop times too though like ripsaw8080.


The GMBLAST.doc is really helpful. Read it over again and caught a missing IRQ handler address (remapping...).




edit:
Attached is a working QFG2-only merged driver. Plus ripsaw8080's sound files. With source and notes.


Note that there could be a problem with the current hacked resource files - the 1st track is always for Adlib. Replacing it with MT-32 device ID may accidentally use the Adlib MIDI channels + instrument programs.

I'm not sure though - don't know what happens when the interpreter sees two identical device tracks. :o

But the digital works like ripsaw8080 promises. ;)



edit2:
Re-added 255 polyphony again.


edit3:
It's not a problem - interpreter just uses the first $0c track info. But since each sound resource only holds music or sound effect, there's no conflict.
Attachments
QFG2 MTBLAST.7z
(276.04 KiB) Downloaded 465 times
tikalat
Member
 
Posts: 287
Joined: 2012-4-13 @ 16:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby collector » 2012-6-16 @ 17:50

Thanks, that works. Not to sound ungrateful, but is there no way to get it to work with the game's unaltered SOUND resources? I have been requested to add MT-32/Munt support into my installers, so I am looking at this from that viewpoint. While I could use the hacked SOUND resources with an installer, I prefer to include as little game data as possible for distribution. The Sierra MTBLAST.DRV was an after market driver file that did not require modification of the SOUND resources.

tikalat wrote:Note that there could be a problem with the current hacked resource files - the 1st track is always for Adlib. Replacing it with MT-32 device ID may accidentally use the Adlib MIDI channels + instrument programs.

I'm not sure though - don't know what happens when the interpreter sees two identical device tracks. :o

edit3:
It's not a problem - interpreter just uses the first $0c track info. But since each sound resource only holds music or sound effect, there's no conflict.

The way that the SCI interpreter uses resources is to look in its own folder to see if the resource it needs exists there, first. If it does not find it, it will check the MAP file to see where to find it in the RESOURCE.0** archives. The reason for this is so that Sierra could distribute patches that could be simply dropped in the game's folder to override the original. If you notice, many of QfG's resources have multiple copies of its resources as the early SCI games were designed to be able to be played without a hard drive. The resources were spanned over several disks, so some resources were packed in more than one RESOURCE.00* file to minimize disk swapping.

A limitation with SCI0 games is that it can only play one sound resource at a time. This does not seem to be the case with QfG2, but it is an SCI0.1 game. However, a single SOUND file can and often does include MT-32/AdLib variants of the sound effect over the digital sample. The genii laugh in the intro of QfG also includes an MT-32 version of the laugh and empty ones for AdLib and Tandy.
User avatar
collector
l33t
 
Posts: 4245
Joined: 2003-1-15 @ 10:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby tikalat » 2012-6-16 @ 18:39

Okay. I can follow that SCI file lookup logic.

A limitation with SCI0 games is that it can only play one sound resource at a time. This does not seem to be the case with QfG2, but it is an SCI0.1 game. However, a single SOUND file can and often does include MT-32/AdLib variants of the sound effect over the digital sample. The genii laugh in the intro of QfG also includes an MT-32 version of the laugh and empty ones for AdLib and Tandy.


So if the driver can't find the digital track flag, it plays the MIDI synth version. Alright I see where you're going with this.


Thanks, that works. Not to sound ungrateful, but is there no way to get it to work with the game's unaltered SOUND resources? While I could use the hacked SOUND resources with an installer, I prefer to include as little game data as possible for distribution.


You could run an external tool that unpacks. Run another tool that applies the patches. Then move the files to game dir.

The actual patches won't need game data (in this case).



I don't think there's a practical way to trick the game into playing the digital and MT-32 music, given the way all the track ID tags are structured. Hacking / distributing the exe would be worse.

I'll give it some more thought first. I'm looking at the Krondor bit-unpacking algorithm and for me it's a ballbuster.
tikalat
Member
 
Posts: 287
Joined: 2012-4-13 @ 16:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby ripsaw8080 » 2012-6-16 @ 18:50

collector wrote:The Sierra MTBLAST.DRV was an after market driver file that did not require modification of the SOUND resources.

In which games was only the driver added later? It may be instructive to learn if something different is happening in the case of those particular games. Perhaps the interpreter already had latent ability to internally translate ID 0x06 into music=0x0c sfx=0x00, which seems feasible.
User avatar
ripsaw8080
DOSBox Author
 
Posts: 4252
Joined: 2006-4-25 @ 23:24

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby tikalat » 2012-6-16 @ 19:25

Note:
Using QFG2 Anthology 1.105, tried both device ID 0c + 06 with untouched sound resources. Game does not call LoadSample, PlaySample, StopSample driver routines. There's no way to force them from the driver side.


Don't see anything else to try other than hacking the exe. 1.102 = 1.105 sciv.exe (and they're both LZ91 compressed requiring a tool for that one).
tikalat
Member
 
Posts: 287
Joined: 2012-4-13 @ 16:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby collector » 2012-6-17 @ 10:12

I'll have go through my games to come up with a list. Off hand, KQ1SCI and I believe SQ3 come to mind.
User avatar
collector
l33t
 
Posts: 4245
Joined: 2003-1-15 @ 10:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby ripsaw8080 » 2012-6-17 @ 11:31

The SNDBLAST.DRV and MTBLAST.DRV included with your installers for SQ3 are interesting. It seems unlikely that Sierra would offer drivers using an extra segment register only available on 386 and later, so maybe a fan-made creation? The drivers work in KQ1 SCI, but crash in QFG2 because of incompatible driver function numbering. Perhaps MusicallyInspired will recall the origin of these other drivers, and if source code for them is available. In any case, the MTBLAST.DRV may be doing a runtime hack in the interpreter or some other trick that could be made to work for QFG2.
User avatar
ripsaw8080
DOSBox Author
 
Posts: 4252
Joined: 2006-4-25 @ 23:24

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby tikalat » 2012-6-17 @ 12:37

In any case, the MTBLAST.DRV may be doing a runtime hack in the interpreter or some other trick that could be made to work for QFG2.


Could be doable. Driver entry - check retf address. Then insert miracle code. Neat idea ripsaw8080. Must check installer driver



Would be useful for Krondor. Uses variant of SCI LZW (not solved). Had to grab run-time driver binaries. Then rebuild sx.ovl after fixing sndblast to work on fast cpus (ex. 60000+ cycles).

Game loads sndblast.drv (audblast) only when sb is picked. Then forces auto-loading of adlib driver.

Replacing adlib with gmidi gives _nothing_. Changing gmidi device to adlib (00) gives sb dma + adlib soundtrack. No extra gmidi polyphony.

Incredible. :|
tikalat
Member
 
Posts: 287
Joined: 2012-4-13 @ 16:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby Qbix » 2012-6-17 @ 12:42

I should have somewhere a lzw decoder that decompresses sci resources, but you can look at the one of scummvm as well of course.
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10676
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby HunterZ » 2012-6-17 @ 14:50

I'm going to split this thread in a bit, since we took it way off-topic to something more interesting :)
User avatar
HunterZ
l33t++
 
Posts: 6075
Joined: 2003-1-31 @ 19:04
Location: Seattle

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby tikalat » 2012-6-17 @ 16:05

Forgot about scummvm. They have a Dynamix version with LZW + RLE compression:
http://wiki.scummvm.org/index.php/DGDS

That looks closer to what I'm seeing. Have to compare them more later. May also hack GoSierra to see what that does too. :)



Checked out SQ3 driver - it's old SCI0. The same sound resource is passed to each driver. And that resource has digital track flags.
(see func_557 - jumps to 5AB = digital)

So each driver is allowed to process / ignore the PCM stuff. No special SCI1 MIDI track stuff we're seeing in QFG2. Don't see any interpreter hacking.

Note that the driver GetDeviceInfo = patch # + poly #. No device ID. Whoever wrote it though... doesn't look like Sierra stuff I'm used to. ^^



Something else I notice now:
http://sourceforge.net/tracker/?func=de ... tid=418823

SQ3 driver is made to play all digital tracks. Including the low-res ones. Would need to hack this driver to only play for the speech sample for best experience.
tikalat
Member
 
Posts: 287
Joined: 2012-4-13 @ 16:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby collector » 2012-6-17 @ 18:24

The MTBLAST.DRV that is included with my installers came from Sierra's FTP. They had a number of aftermarket audio drivers. The GMBLAST.DRV is a fan made driver modeled after the Sierra MTBLAST.DRV. Maggio took the SB part of the driver and appended it onto the Sierra GENMIDI.DRV. There have been a few other fan made audio drivers, mostly by Ravi Iyengar, though most of his were intended for fan made SCI0 games.

I have a number of the aftermarket drivers here. Most of the official ones were just updated SB drivers to address the SB initialization bug.
User avatar
collector
l33t
 
Posts: 4245
Joined: 2003-1-15 @ 10:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby Cloudschatze » 2012-6-17 @ 21:40

ripsaw8080 wrote:The SNDBLAST.DRV and MTBLAST.DRV included with your installers for SQ3 are interesting. It seems unlikely that Sierra would offer drivers using an extra segment register only available on 386 and later, so maybe a fan-made creation?


Neither of these drivers came from Sierra's FTP - both were created by NewRisingSun. I take it no-one noticed that the FM output is in stereo (on supported cards)?
User avatar
Cloudschatze
Oldbie
 
Posts: 1007
Joined: 2005-6-16 @ 14:32

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby ripsaw8080 » 2012-6-17 @ 22:05

Sierra targeted 8088/8086 for SCI0 games, so you wouldn't see a driver they made using the FS register. The NRS drivers seem to work well enough on SQ3, but have glitches on KQ1 SCI, such as the first time you open the door of the witch's house there is a couple of seconds of ear-grinding noise at the end of the sample, but every time after the first seems fine.

From what I understand, some of the PCM sfx are low-quality samples of MT-32 sounds, so using them with MTBLAST.DRV is not an improvement over a real MT-32 or MUNT. The QFG2 patch as it is now should probably cherry-pick the "desirable" SOUND.XXX replacement sounds, such as the genie laugh. Would have to go through and listen to all of the samples, but could be a somewhat subjective process of selection...
User avatar
ripsaw8080
DOSBox Author
 
Posts: 4252
Joined: 2006-4-25 @ 23:24

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby tikalat » 2012-6-17 @ 22:34

Neither of these drivers came from Sierra's FTP - both were created by NewRisingSun. I take it no-one noticed that the FM output is in stereo (on supported cards)?


That would explain why they're so small and optimized. And pristine and clean. With some hard stuff to follow. :lol:
(the techniques do resemble that of his SQ5 drivers) :approving:

Improvement stuff that's out-of-my-league.


Not so sure I'm going to touch his SQ3 work now though - he is around at VOGONS. The driver does use the 'low-res' replacements (debugger confirms SB DMA) but I think it should be his call what he wants to do with his work.

The QFG2 patch as it is now should probably cherry-pick the "desirable" SOUND.XXX replacement sounds, such as the genie laugh. Would have to go through and listen to all of the samples, but could be a somewhat subjective process of selection...


I found the interpreter code that runs through the device ID tracks. Should be able to insert some injection code that lets the driver do all the dirty hacky stuff. Use your idea of patching the Adlib ID for digital-tracks only.

I don't have the QA ears to pick-and-choose though.


Unless of course, NewRisingSun wants to take over or surprise us with some of his coding magic.
tikalat
Member
 
Posts: 287
Joined: 2012-4-13 @ 16:39

Re: Betrayal at Krondor - This program requires microsoft windows?

Postby tikalat » 2012-6-18 @ 00:50

Here's a new version:
1- Generic SCI01 MTBLAST driver
2- QFG2 special driver (plays all digital sounds)


#2 hacks the interpreter to play the SB PCM
#1 no longer includes external sound files. Provided for reference only.

Both have 255 poly, control codes $A0 + $D0 added


We're getting there. ;)


edit:
I'm assuming they didn't change the code much between 1.000 and 1.102? (don't have that version to check sciv.exe)



edit2:
The prescence of any unique MT-32 sounds could give more insight to what's synth vs digital. SQ3 has a good chunk of them - have to use SCI viewer to see how they map up
Attachments
QFG2_MTBLAST.7z
(159.97 KiB) Downloaded 416 times
Last edited by tikalat on 2013-7-14 @ 01:27, edited 1 time in total.
tikalat
Member
 
Posts: 287
Joined: 2012-4-13 @ 16:39


Re: Sierra/Dynamix sound driver hacking

Postby HunterZ » 2012-6-18 @ 16:03

Split discussion from viewtopic.php?t=32552
User avatar
HunterZ
l33t++
 
Posts: 6075
Joined: 2003-1-31 @ 19:04
Location: Seattle

PreviousNext

Return to DOS

Who is online

Users browsing this forum: No registered users and 2 guests