joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.81k stars 383 forks source link

NEC PC-98 Sound Blaster 16 emulation #1047

Open joncampbell123 opened 5 years ago

joncampbell123 commented 5 years ago

Not sure how similar the DSP or mixer interface is to the IBM PC Sound Blaster 16. Obviously it's not on the same I/O port range. According to some documentation, the card has a YM2203 instead of the usual OPL3. The YM2203 and Sound Blaster each have their own IRQ. So emulation of the full card would involve both enabling the FM card emulation and the adapted Sound Blaster emulation.

Not sure if easy or difficult.

Not sure if the I/O layout from 20D2h is simple and linear, considering that the I/O base is only 0002h apart.

Comments welcome.

I have a PC-9821 system and the C-bus version of the SB16 as reference hardware when development of this feature begins.

References:

http://radioc.web.fc2.com/column/pc98bas/ct2720.htm

joncampbell123 commented 5 years ago

I just pulled the card out of the box to examine it.

Apart from the C-Bus form, the chips on the board look just like any other Creative product.

From visual examination, despite different I/O port numbers, it provides a Creative DSP chip, mixer, and OPL3 FM.

The board ALSO provides a YM2203 for existing PC-98 games.

As another happy find, the second circuitboard attached to it on the top is the Wave Blaster card! Never seen one before. I wonder if I could disconnect it from the C-Bus version and attach it to the IBM PC versions I have that still have the Wave Blaster card pin header.

The card has a copyright date of 1993.

joncampbell123 commented 5 years ago

Just plugged it into a PC-9801FA. Using DEBUG.EXE I can confirm it responds to I/O port 20D2h.

Poking at it, it's fairly obvious the I/O port scheme used by Creative here is XXD2h.

20D2h-2FD2h appear to be the main Sound Blaster I/O port group. They function exactly the same as I/O ports 220h-22Fh do on the IBM PC versions of the Sound Blaster 16.

Not sure yet what 80D2h and C8D2h are.

joncampbell123 commented 5 years ago

vlcsnap-2019-04-07-13h18m18s306 overlay

joncampbell123 commented 5 years ago

80D2h, 81D2h appear to be the MPU-401 of the card.

On this particular card the Wave Blaster is attached, so according to documentation the Wave Blaster will receive MIDI output and render it.

joncampbell123 commented 5 years ago

C8D2h, C9D2h appears to be the OPL3 FM chip.

joncampbell123 commented 5 years ago

The card is also responding to 188h, which is the traditional I/O port base of the OPNA FM chip usually provided by the FM card. However it does NOT respond to port 88h, which means games written against the older FM card (the -26) will not work.

joncampbell123 commented 5 years ago

The similarity in function (despite the different I/O ports) means that DOSBox-X can easily adapt to emulate PC-98 Sound Blaster 16 by attaching to different I/O ports.

However SB16 emulation cannot emulate the fact that the card also has an OPNA, because that would conflict with the existing options for FM board emulation. It won't be 100% realistic that way.

I do not know of any PC-98 games that will talk to SB16, except (I think) the PC-98 ports of Doom and Wolfenstein 3D.

joncampbell123 commented 5 years ago

I doubt the card supports Plug & Play, since (as far as I know) C-bus didn't implement the Plug & Play protocol that the IBM PC platform did. The dip switches on the card are another clue that PnP is not supported. It also means that unlike the IBM PC version, the PC-98 version may not support reconfiguration of IRQ and DMA resources through mixer byte 80h-81h either. It may not exist, or may be read only (as it is on IBM PC versions of the PnP cards).

joncampbell123 commented 5 years ago

There is indeed something at mixer registers 80h-81h.

80h: 0xF8 81h: 0x14

DMA and IRQ values are probably completely different from the IBM PC versions.

joncampbell123 commented 5 years ago

When I pull the hardware out again for testing, I need to see if the SB16 card also responds to E0D0h, E0D2h as normal MPU-401 hardware does.

EDIT: Another test is to see if the mixer bytes 80h-81h are writeable. If so, what do the values mean? The PC-98 port of DOOM will write these bytes at startup.

joncampbell123 commented 5 years ago

Proposed changes:

joncampbell123 commented 5 years ago

Based on the "screenshot" provided by the website, the BLASTER variable is still there as well.

In the example shown:

SET BLASTER=AD2 I5 D3

joncampbell123 commented 5 years ago

Ah, while we're on the subject of giving MPU-401 emulation the option to choose I/O port base...

setup_000

joncampbell123 commented 5 years ago

I noticed that if DOOM cannot locate the MPU-401 as instructed, it will probe C0XXh to F8XXh in steps of 0800h, where XX is D0h then D2h. Interesting.

yksoft1 commented 5 years ago

In fact PC-9801-118 had an OPL3 and a FM chip YMF288 which is OPNA compatible. However, there is almost no DOS games that can make use of 118 sound generator's OPL3.

joncampbell123 commented 5 years ago

@yksoft1 At what I/O port did the -118 map the OPL3?

yksoft1 commented 5 years ago

PC-9801-118 is OPN3(OPNA compatible)+OPL3+CS4232+MIDI port I remember.

@yksoft1 At what I/O port did the -118 map the OPL3?

http://www.hi-ho.ne.jp/~y-exp/dustman/118b.htm

番外.YMF-297のOPL部は使えるか?

YMF-297はSOUND BLASTERで使われているOPL3部分を内蔵しています。 DOS上で実際に使えるかどうか。 I/O portは480hを使用しており、 またその部分はマスクされていないので環境変数で、
>SET BLASTER=A0480 I12 D3 T3
と指定すれば使えそうなのですが、 残念ながら私はSOUND BLASTERに対応したソフトを持ってません(^^; 

https://www.vector.co.jp/soft/dos/hardware/se069794.html

A tool to initialize PC-9801-118 (PnP mode) under DOS. Inside the archive there is a 118board.doc that had some useful info for 118 card.

in non-PNP mode:

 非PnPモードの場合   以下のリソースを消費する    本体1の場合     0480~0487 OPL     1480~148F MIDI     IRQ3,5,6,10 MIDI(割り込み使用時のみ)    本体3の場合     0480~0487 OPL     1480~148F MIDI     0188~018E OPN3     IRQ3,5,6,10 MIDI(割り込み使用時のみ)     IRQ3,10,12 OPN3    本体2,4,5の場合     0480~0487 OPL     1480~148F MIDI     0188~018E OPN3     A460~A461 WSS     0C24~0C25 WSS     0C2B~0C2C WSS     0C2D~0C2E WSS     0F40~0F4F WSS     IRQ3,5,6,10 MIDI(割り込み使用時のみ)     IRQ3,10,12 OPN3/WSS     DMA0,3 WSS

yksoft1 commented 5 years ago

@joncampbell123 Sound Blaster 16 (PC-98) diagnose program shows that both DMA channel 0 and 3 are "unavailable and might be occupied by other cards" on DOSBox-X PC-98 default settings.

image

The Sound Blaster 16 (PC-98) driver and utility can be downloaded from https://jp.creative.com/support/downloads/download.asp?MainCategory=1&nRegionFK=&nCountryFK=&nLanguageFK=&sOSName=Windows+3x&region=2&Product_Name=Sound+Blaster+16&Product_ID=1842&modelnumber=&driverlang=1041&OS=19&drivertype=0&x=47&y=11

yksoft1 commented 5 years ago

The SB16 Windows 3.1 driver complains that "MIDIPORT" value in system.ini [sndblst.drv] section was wrong and refuses to load.

joncampbell123 commented 5 years ago

DOSBox-X defaults to E0D0h for general MIDI emulation, not Sound Blaster specific MPU401 emulation.

Add to dosbox conf, the mpu401 section:

mpubase=80D2

And in the sblaster section

sbbase=D2

The low 8 bits of both must match.

joncampbell123 commented 5 years ago

General MPU-401 emulation on PC-98 has a base I/O of E0D0h, while the Sound Blaster MPU-401 has a base I/O port with the upper byte 80h and the lower byte matching the base I/O of the Sound Blaster.

In DOSBox-X the default base I/O is D2h, which puts the DSP and mixers at 20D2h to 2FD2h every 100h ports and the MPU-401 at 80D2h and another port.

joncampbell123 commented 5 years ago

PC-98 games from my testing are more likely to look for the MPU-401 at E0D0h than the Sound Blaster MPU-401 port.

yksoft1 commented 5 years ago

However the SB16 Windows 3.1 driver seems to require SB16's own MIDI port to work.

joncampbell123 commented 5 years ago

Understood. You can set the MPU base to match what it would be for a SB16 card on PC-98 as described.

joncampbell123 commented 5 years ago

Good news: The DOSLIB now has a working build of SNDSB and DOSAMP for PC-98, if you have a Sound Blaster 16 card installed.

Despite the different I/O port, IRQ and DMA mapping, it acts exactly like a Sound Blaster 16 would on an IBM PC compatible platform. Right down to that bug on DSP 4.5 boards where specific narrow ranges of sample rate are incorrectly set to the PLL.

pc98dosamp1

joncampbell123 commented 5 years ago

The "text GUI" program TEST.EXE in HW/SNDSB cannot be ported to PC-98 because the code there relies too heavily on IBM PC compatible CGA/EGA/VGA video memory layout and keyboard scan codes.

joncampbell123 commented 5 years ago

Another DOSLIB library given a PC-98 port is the Adlib OPL3 support library in HW/ADLIB, which now also works on the PC-98 Sound Blaster 16 board.

joncampbell123 commented 5 years ago

Again the "text GUI" in TEST.EXE for the Adlib library is heavily VGA dependent and cannot be ported to PC-98 yet.

joncampbell123 commented 5 years ago

IRQ and DMA mappings noted in DOSBox-X seem to match real hardware, though bits [7:2] of the DMA select register behave in a predictable but odd pattern (noted in DOSBox-X source code).

I cannot fully verify the IRQ settings because the particular PC-9821 I'm testing on is a newer unit with a PCI bus, and PCI-based Intel chipsets reserve certain IRQs for use with PCI devices and do not pass ISA (or in this case C-Bus) IRQ signals for those, so I was not able to verify anything other than the bit value for IRQ 10 is correct.