flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > Sound Blaster/AdLib in NTVDM doesn’t work?

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 362
Location: Belarus
Hello, everyone!

I’ve been trying to add a bit of sound to my small MS-DOS game. I’ve chosen Sound Blaster-way.

But it seems Windows XP’s NTVDM does a very bad job emulating the sound card. My autoexec.nt file contains the following line:

Code:
SET BLASTER=A220 I5 D1 P330 T3    


I wrote a piece of code that parses MS-DOS environment variables, finds the BLASTER one and gets the settings out of it. Then the program tries to play some sound and… fails no matter which way I try to.

Consider the following piece of code (proc16.inc is used).

Code:
proc Sound._FMWrite\
     bRegister, bData
     mov        dx, $0388
     mov        ax, [bRegister]
     out        dx, al

     mov        cx, 6
@@:
     in         al, dx
     loop       @B

     mov        dx, $0389
     mov        ax, [bData]
     out        dx, al

     mov        dx, $0388
     mov        cx, 35
@@:
     in         al, dx
     loop       @B
     ret
endp

...

     stdcall    Sound._FMWrite, $20, $01
     stdcall    Sound._FMWrite, $40, $10
     stdcall    Sound._FMWrite, $60, $F0
     stdcall    Sound._FMWrite, $80, $77
     stdcall    Sound._FMWrite, $A0, $98
     stdcall    Sound._FMWrite, $23, $01
     stdcall    Sound._FMWrite, $43, $00
     stdcall    Sound._FMWrite, $63, $F0
     stdcall    Sound._FMWrite, $83, $77
     stdcall    Sound._FMWrite, $B0, $31
    


This code makes the program produce an infinite sound when run from DOSBox, but it keeps silent when run under WinXP NTVDM.

Does anyone have a working sample piece of code or any useful information to solve the problem?

P.S. I also couldn’t make the program sound when writing to DSP using direct mode (command 10h), but I guess it would work in DOSBox if I wouldn’t be too lazy to generate a piece of code for a valid sine wave of stuff like that.
Post 19 Apr 2016, 17:33
View user's profile Send private message Visit poster's website Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 113
Location: i@grompe.org.ru
NTVDM's emulation is subpar at best, even worse when you think of its sound emulation.

VDMSound project was aimed to fill this gap, so you may have some results if you retry with it installed.
Post 24 Apr 2016, 07:30
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 362
Location: Belarus
VDMSound didn’t really help. DOSBox made it work, but I once had similar problems with NTVDM (related to speaker control) and it turned out NTVDM is just more strict to the order of the program requests.

Since the question was asked I’ve done quite a lot of experiments. Consider the following piece of code…

Code:
include 'macro\proc16.inc'

MIDIPORT_DATA           = $0330
MIDIPORT_COMMAND        = $0331

        org 100h

Start:
        stdcall MIDI.Initialize

        stdcall MIDI._WriteData, $90
        stdcall MIDI._WriteData, $05
        stdcall MIDI._WriteData, $7F

;        stdcall MIDI._WriteData, $90
;        stdcall MIDI._WriteData, $60
;        stdcall MIDI._WriteData, $7F

        xor     ax, ax
        int     16h
        ret

proc MIDI._WriteCommand\
     bValue

     mov        dx, MIDIPORT_COMMAND
@@:
     in         al, dx
     test       al, $40
     jnz        @B

     mov        ax, [bValue]
     out        dx, al
     ret
endp

proc MIDI._WriteData\
     bValue

     mov        dx, MIDIPORT_COMMAND
@@:
     in         al, dx
     test       al, $40
     jnz        @B

     mov        dx, MIDIPORT_DATA
     mov        ax, [bValue]
     out        dx, al
     ret
endp

proc DSP.Reset
     mov        dx, $226
     mov        al, 1
     out        dx, al
     xor        al, al
@@:
     dec        al
     jnz        @B
     out        dx, al

     mov        dx, $22E
@@:
     in         al, dx
     test       al, al
     jns        @B
     mov        dx, $22A
     in         al, dx
     cmp        al, $AA
     jne        @B
     ret
endp

proc DSP.Write\
     bData

     mov        dx, $22C
@@:
     in         al, dx
     test       al, al
     js         @B

     mov        ax, [bData]
     out        dx, al
     ret
endp

proc DSP.Read
     mov        dx, $22E
@@:
     in         al, dx
     test       al, al
     jns        @B

     mov        dx, $22A
     in         al, dx
     ret
endp

proc MIDI.Initialize
     stdcall    MIDI._WriteCommand, $FF
.WaitAck:
     mov        dx, MIDIPORT_COMMAND
@@:
     in         al, dx
     test       al, $80
     jnz        @B

     mov        dx, MIDIPORT_DATA
     in         al, dx
     cmp        al, $FE
     jne        .WaitAck

     stdcall    MIDI._WriteCommand, $3F
     ret
endp    


It uses another group of ports but with the same intention. It works as expected in DOSBox but keeps silent in NTVDM. But!.. If you add another MIDI message (say, uncomment those three lines), you’ll see (or hear?) that NTVDM actually starts “executing” a message only when the next one arrives, i.e. in this case NTVDM plays 1 note while DOSBox plays 2 of them.

In fact, adding any well-formed MIDI message makes the previous one work (I tried with one-byte $F4 message).

Besides, when run from Turbo Debugger (in NTVDM as well) the program doesn’t work as expected for the first time but if you restart it with Ctrl + F2, the 2nd, 3rd, etc. runs work perfect!..

So, I guess it’s a matter of internal state of the emulated MPU-401 which is slightly different for NTVDM and DOSBox. But I couldn’t find any information about that.
Post 25 Apr 2016, 11:37
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.