Friday, December 22, 2017

Parallel & Serial Sound Card Emulation Options for your Vintage PC

In the beginning the Intel 8088 and 8086 CPUs only implemented, Real Mode, where a program had total control over all aspects of a system.  Real Mode's main issue, other than it was limited to 1MB of RAM, was that multitasking was almost impossible to accomplish.  Then the 286 CPU implemented a Protected Mode and allowed the CPU to address 16MB in that Mode, but few applications used it because DOS required Real Mode. Finally, the 386 CPU implemented a far more usable Protected Mode and a Virtual 8086 Mode (V86).  V86 Mode allowed the CPU to run multiple instances of Real Mode where each program would be given access to up to 1MB of RAM for their own purposes without overwriting another program's data.  To each program running in V86 Mode, it would appear to it as though it had full control over the PC.

As a byproduct of V86 Mode, Expanded Memory, which had been implemented with expansion cards on 8088 & 286 machines, could be emulated with Expanded Memory Managers (EMS).  The most popular EMS was EMS386, which came with MS-DOS 5.0 and later.  There were other EMS softwares like QEMM and JEMM.  EMS also allowed a user to trap writes to memory locations and I/O ports.  Sound cards invariably wrote to I/O ports on a PC to make sound.  Eventually it was discovered that this port trapping capability could be used to emulate sound cards.  Software drivers of recent and ancient vintage have been being this feature, or implementing their own, to emulate sound cards and chips for systems that may not or cannot use them.  Let's take a look at some of these devices and methods.




SoftMPU + Serial MIDI Cable

SoftMPU has been around for a long time, comparatively speaking.  Originally it was intended to allow UART Mode MPU-401 hardware MIDI interfaces, like those found on a Sound Blaster 16, to run games that require Intelligent Mode MPU-401 support.  Given that 100% Roland MPU-401 compatible interfaces are rare and expensive these days, this software served a very important purpose given how cheap and common Sound Blaster 16s were.

SoftMPU did not stop there.  Then it supported the Sound Blaster MIDI interface, which is just incompatible enough not to work with UART Mode games.  It also allows the Roland RA-50 Realtime Arranger, which has a nearly 100% compatible MT-32 sound synthesis engine, to work fully with data intended for an MT-32.  Finally, it supported transmitting MIDI messages over a serial cable, something that was previously the domain of Windows applications.  A serial port typically communicates over 3F8-3FF (COM1) or 2F8-2FF (COM2).  An MPU-401 expects to communicate over 330-331 (default) or 300-301 (most common alternative).

SoftMPU has some advantages to using a real Roland MPU-401 interface or clone.  It can delay sysex messages so that you do not get the dreaded "Exec. Buffer Overflow" message when sysex data is sent to a rev.0 MT-32 too quickly.  You can also use the Serial MIDI to avoid the hanging notes issues of a Sound Blaster 16/AWE32/32.

Serial MIDI transfer is very similar to regular MIDI transfer, both are serial-based transfers.  RS-232 can use current loop signalling like MIDI, but is much more often used with TTL signalling.  Native MIDI runs at 31,250 baud while Serial MIDI runs at 38,400 baud.  Modules with a serial input will convert 38,400 baud rate MIDI data to 31,250 baud MIDI data for proper processing not only with the serial MIDI module but any DIN-only MIDI modules daisy-chained to the serial MIDI module.  That means you can hook up your MT-32 via daisy chain to an SC-55ST and hear proper music playback.

You need a MIDI Module like the Roland SC-55mkII and Yamaha MU10XG which have an input for a Serial MIDI cable.  Their Serial MIDI functionality is only intended to work with Windows 95 or better, not DOS.  Once you have the input, you can use a Roland module's MIDI Out connection to get the MIDI data to an MT-32 or SC-55, which do not have serial port connections.  Alternatively, you can use the MIDI Out of a module like the SC-55mkII to connect to a USB to MIDI interface and let the Serial MIDI drive MUNT or Virtual Sound Canvas on a modern PC.

Covox Speech Thing and the CVX4

The Covox Speech Thing was widely cloned back in the day and instructions to make a home-made Covox were common.  However, most of the clones and the homebrew just did not sound very good.  The sound usually ended up very quiet, noisy and muffled.  Then one day back in 2016, my friend Trixter demonstrated the audio output of a true Covox.  Unlike the clones and what we thought of as "Covox Sound", this output sounded good.  Really good, especially with the Crystal Dream demo.

Compare his demo video here :

https://www.youtube.com/watch?v=M0kxcc67l0w&t=413s

to Lazy Game Review's video of a clone here :

https://www.youtube.com/watch?v=spOenlrSSOE

As you can hear, there is no comparison between the clone Covox and the genuine Covox.  What was the secret sauce that Covox used to make their dongle sound so good?  Actually, the real Covox is simpler that anyone expected.  All that inside the parallel port dongle enclosure appears to be an R2R resistor network pack (100/200ohms).  The implementation is more simple than the Covox' patents or the silkscreening on some of the Covox PCBs would suggest.  Any filtering beyond what the resistor pack may accomplish was done in the accompanying powered speaker.  The resistor pack made the tolerances of each resistor much closer together than your typical discrete resistor clones.  Resistors used in Covox clones tend to have tolerances in the 1-5% range, but the best sound requires resistors as precisely matched as possible.

The CVX4 is a device which comes as close to recreating the original operating characteristics of the Covox as possible.  It uses 0.1% tolerance resistors and includes several filtering options.  The CVX1-3 were never put into production (except for the CVX2, which had a limited release) and designated as such for testing purposes to refine the board to its present state.  I own a Sound Jr. clone, which is more filtered than the CVX4 Covox clone, but still a good solution.

The Covox device was an inexpensive way to add some sound capability greater than the PC speaker to laptops and systems like the IBM PS/2 microchannel line which lacked ISA expansion slots.  But the number of games that support the device is around 60, so support was limited.  Given that it takes the CPU a lot of time to output samples through the parallel port, few of those games are likely to run well on less than a 386.

There was a competing device called the Disney Sound Source which had greater support in games (about 130) than the Covox because it took less CPU overhead due to its 16-byte FIFO buffer.  However, it ran on a fixed timer, only allowed for 8-bit output at 7KHz.  The Covox could output up to 44KHz and beyond depending on how much CPU time was allocated to the task.  Games and programs supporting the Covox usually do not work on the Disney and vice versa unless they support both kinds of parallel port DACs.  There is work ongoing to make a Disney adapter for the CVX4. 

The theme of this blog entry is emulation on vintage hardware, and there are programs which use a Covox to emulate other devices.  One such program is TEMU (v3.03) by Friends Software (1993), which emulates the Tandy sound chip found in Tandy 1000s.  It handles the three square wave channels and the noise channel.  It will implement the Tandy sound chip at I/O Ports 60, 60, 1E0, 1E1, 201 and 205.  This allows it to work with games and drivers supporting the Tandy 1000 and the IBM PS/1 Audio/Game card (although the sound chip has no function at 201 on a PS/1, this may not work well with a joystick)  The driver does not try to fool a program into thinking it is running on a Tandy 1000 or IBM PS/1, so you are mostly limited to games that allow you to manually select Tandy sound or have been hacked to bypass the system check.  TEMU also emulates a Disney Sound Source and works with Wolfenstein 3D at least.  It will not work with an Expanded Memory Manager like EMM386, it does its own V86 thing.  It will support a Disney on either 378-37F (LPT1) or 278-27F (LPT2), but will have trouble if the Disney parallel port is designated as 3BC-3BF (MDA LPT1).

Friends Software also released Virtual Sound Blaster (v2.02) (1995).  This emulates a Sound Blaster and returns a DSP of v1.10 (which never existed in reality).  It will make a Sound Blaster appear at I/O 220-22F, IRQ 5 or 7 and DMA 1.  It will also work alongside a real Adlib.  It will work with games supporting an Extended Memory Manager but games requiring EMS will work with this emulator only through QEMM 7.0 or better.  It only supports certain v1.xx DSP commands.  It does not support the ADPCM (8bit to 4bit, 3bit or 2bit) modes or the auto-init DSP modes of the v2.00 DSP.  Essentially it supports direct DSP output writes and single-cycle DMA.  A lot of games used the single-cycle DMA mode to ensure compatibility with all Sound Blasters and most clones.

Here is a sample of KQ1's Greensleeves playing via TEMU and the CVX4 board :



compare to the real Tandy 1000 :



Now here is a recording of some of Wolfenstein 3D's sound effects using VSB (emulating a Sound Blaster) and TEMU (emulating a Disney Sound Source).  The recordings switch over at the 1:10 mark :



As you can hear, the Sound Blaster emulation is not only louder than the Disney emulation, but the playback speed is correct.  The Disney emulation results in samples being played back about 40% faster than they should.  I would avoid using the Disney emulation if at all possible, virtually all Disney games support the Sound Blaster anyway.

You can buy the board here http://www.serdashop.com/CVX4 or here  http://www.the8bitguy.com/product/cvx4-parallel-sound-card-covox-compatible/

OPL2LPT

The Adlib Sound Card's core was its YM3812 chip.  Yamaha implemented it directly onto the ISA bus at ports 388 and 389.  Port 388 is the index register when written and the status register when read.  Port 389 is for the data registers and is write only.  You send a byte directly to the registers that produce the sound.  The Adlib is programmed 8-bits at a time and has 240 registers.

The parallel port can handle a steady stream of 8-bit writes through the data output port at 378 and a control port bit at 37A can tell the YM3812 whether the byte is intended for the index register or data registers.  While reading the YM3812's status register could have been implemented using the parallel port's status input register, that was not done.  Games can detect a YM3812 by writing to the chip to set one or both of the timers and then read the status register to see if the time had elapsed as expected.

What we have in the OPL2LPT is excellent for a hobbyist friendly project.  All the parts are through-hole parts or have wide surface mount pads, which makes it easier for beginners to solder.  The USB port only provides power, it cannot communicate with the YM3812.  In order to use this device with a modern PC, you need a parallel port.  Most modern motherboards have long ditched the parallel port header, but USB parallel port adapters do exist and communication with the YM3812 is so simple that you can get the OPL2LPT working in a modern Windows system running DOSBox.

The OPL2LPT supports headphone amplification with a volume adjustable knob.  It has a reset button to silence the YM3812 if a game quits without doing that via register writes or you get noise when the system boots.  You should never insert or remove this device when the computer is on, neither it nor most parallel ports have ESD protection.  This is not an issue with the CVX4, which is just a bunch of passive resistors and capacitors.

No DOS software will work with this device without either the driver or patching the game manually to redirect port writes from where the Adlib should be to the parallel port.  In the utilities there is a program called adpatch that will patch certain games for you to redirect their writes.  This allows you to use those games on a 286 or older CPU (assuming the game does not require a 386 to run) and will bypass the performance penalty of running the redirection driver.  The games currently supported is limited to the following as of the current version of the utilities v0.6.0 :

- Sierra
  - Games using the "SCI" engine. Patch `ADL.DRV`.
- id Software
  - The Commander Keen series (4,5,6)
  - Wolfenstein 3D
  - DOOM (v1.9 tested)
  - DOOM II
- Softdisk
  - Keen Dreams
  - Dangerous Dave's Risky Rescue
  - Dave Does Nutz
- Apogee
  - Bio Menace

You obtain the driver from here : https://github.com/pdewacht/adlipt/releases and the board and parts from here http://www.serdashop.com/OPL2LPT or here http://www.the8bitguy.com/product/opl2lpt-ad-lib-compatible-parallel-sound-card/

I really like the idea of this board, but I would hope that the project could be pushed further to implement an OPL3 chip, USB communication to/from the chip and pure digital audio output.  I believe the redirection driver may support the OPL2LPT at LPT2, but I doubt the patching program does.

Limitations of the Expansion-less Sound Devices

The software drivers for these devices were made by different programmers at different times, so they may not play well or at all with each other.

The software drivers will not work with games that refuse to run in V86 Mode, namely Ultima VII, Serpent Isle and Comanche.   Later games often used a DOS Protected Mode Interface (DPMI) extender like DOS4GW or CWSDPMI.  This includes DOOM, Duke Nukem 3D, Descent and most games released after 1994.  There are a few games that support the similar VCPI like Wing Commander Privateer and Strike Commander, don't expect those to work either.  Just to reiterate, they will not work with a 286 or earlier CPU.

Performance on a 386 CPU may be less than ideal.  These drivers need to vet lots of port writes to determine which to allow through and which to redirect.  They also often do more than port redirection such as emulating Intelligent MPU-401 or a basic Sound Blaster DSP.  Pentium laptops tended to have real sound cards built into them and could manage much of the functionality provided by these programs.  So the laptop sweet-spot is the 486 machines.

Another use for these products are for systems that are beyond ISA slots and decent PCI sound card Sound Blaster emulation.  PCI cards, with the exceptions of the Yamaha YMF-7x4 series and the CMI8738 chip, generally have terrible Adlib emulation.  Eventually, sound cards and integrated audio devices lost all support for the Sound Blaster and Windows XP's emulation of the Sound Blaster leaves much to be desired, so the Covox may ironically be the only way to obtain digital audio by playing DOS games natively on hardware running an Intel Core 2 Duo for example.

Remarked YM3812 Pulls

Before we end, I must make a Public Service Announcement.  Someone remarked that they were surprised that Yamaha still made YM3812s chips in the 21st Century.  Well, it is extremely likely that Yamaha does not make those chips anymore and the chips that are being shipped with this kit may have 21st century dates but are really remarked chips.

Consider the following videos :

https://youtu.be/iPVqAvgGbWo?t=197

https://youtu.be/z3DU2mNBa6M?t=487

https://www.youtube.com/watch?v=1yB-O4TFIz8&t=130s

At these points in the video, you can see the chip markings clearly.  Each chip has the exact same markings :

YAMAHA
YM3812
0824 EAYB

Now having chips from the same week (sometime in June of 2008) is not necessarily indicative of fake chips, my Sound Blaster Pro 1.0 has two chips in it with identical markings.  If the YM3812s came from one tube that would not be unusual.  Having laser marked vintage chips (brown lettering) is also unusual, but if the chip is still being manufactured, it is not necessary dispositive of whether the chips are real or fake.  Nintendo put epoxy-painted and laser marked 2A03H and 2C02H CPUs & PPUs in its AV Famicoms, a console that was produced from 1993 to 2003.

I asked an expert in chip remarking, kevtris, and he opined that these chips could be pulls.  Chinese factories will remove chips from spare cards, sand down the surface to remove the old part number and spray paint the surface of the chip.  Then they remark it with silver epoxy paint or laser printing.  They tin the IC's pins with solder to mask the residue from the desoldering removal process and straighten the pins to make them appear fresh off the factory fabrication line.  Sometimes you can see some silver epoxy paint on the eject holes, a chip that was only ever marked with a laser will not have that.  They produce these rebadged chips in batches, but each chip in the batch has the same datecode.  I guess it is easier to sell "new old stock" that way.  Kevtris' depressing adventure in remarked SID chips is documented here : http://kevtris.org/Projects/sid/remarked_sids.html

If you look around the 8 minute mark in 8-bit Guy's video you can see the light shine off the textured surface on the chip, and it has an uneven look.  A tell-tale sign of remarking is that when the factory spray paints the chip, it spray paints the whole chip, including the eject holes on the sides of the chip's surface.  Whether the chip was originally smooth or matted, the eject holes are always smooth on unremarked chips.  These videos show chips with fully matted eject holes.  In other words, they have been remarked.  Here are the chips from my Sound Blaster Pro 1.0, you can see the difference in the shiny surface of the eject holes and the matte surface elsewhere on the chip :


I own four Phillips SAA-1099 Game Blaster that exhibit these characteristics, so they have been remarked.  Fortunately, at least two of them work correctly.  If I had some acetone, I believe I could remove the paint and reveal the original epoxy paint markings underneath.



The above notwithstanding, the chips as displayed in these videos sound real.  You are unlikely to be getting fake chips, but these are not new old stock, these are used pulls, factory rejects or unlicensed clone chips.  Your lifespan may vary.

5 comments:

  1. Your real Tandy 1000 sample of Greensleeves sounds an awful lot like PC speaker, not Tandy 1000 3-voice. Maybe your variant of King's Quest didn't recognize the computer as a Tandy PC correctly?

    ReplyDelete
  2. Never attribute computer error when it can be attributed to user error! I linked to the wrong recording, but I fixed the link. You can now hear pure Tandy 1000 Greensleeves.

    ReplyDelete
  3. Being a software engineer myself, I should have assumed it was user error :)
    Much better now, thanks!

    ReplyDelete
  4. > Most modern motherboards have long ditched the parallel port header, but USB parallel port adapters do exist
    > {...} USB communication to/from the chip

    Note that OPL2LPT relies on "bit banging", precisely controling each line of the parallel port (among other, it uses some control line to simulate the ISA bus cycles to tell the OPL2 to read the input).

    Most ISA and PCI/PCIe (and various PC Card declination thereof) parallel ports can be controlled in this fashion.
    Most USB parallel port function at a higher level (application send data packets to be printed to printer, and the USB chip handles the actual low-level signal) and cannot be used for a low-level device like the OPL2LPT.

    If you want an USB connected device that can precisely control pins and thus drive an OPL2, your garden variety Arduino can fill the job.
    (There are some libraries on github, and there are people making OPL2LPT-like device that follow the arduino shield form factor for even simpler connection)

    > I would hope that the project could be pushed further to implement an OPL3 chip,

    The OPL2LPT author is now working on a OPL3LPT !
    (But surface mounted instead of through-holes)

    ReplyDelete
  5. > There is work ongoing to make a Disney adapter for the CVX4.
    Incorrect, that project has been finished since February 2015. See: https://www.vogons.org/viewtopic.php?f=62&t=42250&start=40#p405296
    Gotta have to love how projects stay under the radar if there's no "shut up and take my money"-style product.

    ReplyDelete