viti95 / FastDoom

Doom port for DOS, optimized to be as fast as possible!
512 stars 33 forks source link

No music with the freeware IWAD release of Hacx : Twitch 'n Kill #15

Closed maximilien-noal closed 3 years ago

maximilien-noal commented 3 years ago

I got curious about running Hacx : Twitch 'n Kill inside Chrome/Firefox/Edge thanks to FastDoom + JS-DOS.

Right now I'm testing with regular DOSBox 0.74-3 on Windows 10 x64.

What I found is that while the vanilla DOOM2 IWAD has music & sound with FASTDOOM, and HACK.WAD has music and sound with GZDOOM, HACK.WAD with FASTDOOM has sounds, but no music.

The music is in MIDI format. I'm using the lastest FastDoom release (v7 RC1).

All is attached below:

HACK_IWAD + FastDoom + config file.zip

DOSBox config: default (sblaster = sb16, irq = 7 dma = 1, hdma = 5, SET BLASTER at A220 I7 D1 H5 T6

FastDoom config:

mouse_sensitivity       5
sfx_volume      8
music_volume        8
show_messages       1
key_right       77
key_left        75
key_up      72
key_down        80
key_strafeleft      51
key_straferight     52
key_fire        29
key_use     57
key_strafe      56
key_speed       54
use_mouse       1
mouseb_fire     1
mouseb_strafe       1
mouseb_forward      2
screenblocks        10
detaillevel     0
showfps     0
uncapped        0
flatsky     0
near        0
nomelt      0
flatShadows     0
saturnShadows       0
untexturedSurfaces      0
flatSurfaces        0
vsync       0
monosound       0
snd_channels        3
snd_musicdevice     3
snd_sfxdevice       3
snd_sbport      220
snd_sbirq       7
snd_sbdma       1
snd_mport       330
usegamma        0

Thank you very much for this very interesting project ! :)

viti95 commented 3 years ago

There is a bug somewhere in MUS2MID.C, it cannot convert the music to MIDI format and that causes the missing music. I'll try to fix it but i'm no expert in mus/midi formats 😅

maximilien-noal commented 3 years ago

Thanks for your answer. Now I know where to look. I'm not an expert either, but I'll try to see if this was introduced in a particular commit related to that file.

maximilien-noal commented 3 years ago

Same with v0.2. Seems that new code is indeed required.

maximilien-noal commented 3 years ago

It works with PrBoom-plus, and the mus2mid.C and mus2mid.H files there are very close.

maximilien-noal commented 3 years ago

OK, I have setup everything to compile FastDoom, well, fast (Windows ME VM + TASM + Open Watcom 1.9).

No debug however, which slows things a lot, I wonder how you do it ?

I don't have to debug the game, just the MUS parser part. I guess I could compile it as a library or command line program...

I'm debugging PrBoom-plus with VSCode under Linux with GDB, the sourcecode is very close, but no dice so far...

viti95 commented 3 years ago

What I do to debug is include the header "i_debug.h" and use the functions I_DebugWriteLineString, I_DebugWriteLineInteger and I_DebugWriteLineFixed to see the variables in realtime. Those functions write to the monochrome display (port 0xB0000), so it's possible to view the game in the VGA monitor and see the variables in the monochrome one. It's pretty primitive but works. There are DosBox builds that support that dual monitor configuration, and also you can debug this way with real hardware.

It's also possible to use the DosBox debugger, but I prefer the first method.

maximilien-noal commented 3 years ago

Thank you ! I have the DOSBox build in question. That should make things easier.

viti95 commented 3 years ago

I have updated the debugging functions in the last commits. They are now much easier to work with, as they behave as the original printf functions. I think these changes will help you debugging a lot 😄

maximilien-noal commented 3 years ago

Very nice ! I will try it ASAP. Right now it seems that mus2mid is not the culprit. Rather, the problem seems to be further up in the call stack.

maximilien-noal commented 3 years ago

PrBoom! Plus -> W_Init finds 6653 lumps. FastDoom -> W_AddFile finds 2784 lumps. Interesting. Edit: red herring. PrBoom Plus first loads FreeDoom, then prboom.wad, then HACKX.WAD ! The number of lumps found for HACKX.WAD itself is the same.

maximilien-noal commented 3 years ago

Ok, I found something.

from s_sound.c


void S_ChangeMusic(int musicnum,
                   int looping)
{
    musicinfo_t *music;
    char namebuf[9];

    I_Printf("%s", "S_ChangeMusic\n");
    if (snd_MusicDevice == snd_none)
        return;

    if (snd_MusicDevice == snd_Adlib && musicnum == mus_intro)
    {
        musicnum = mus_introa;
    }

    music = &S_music[musicnum];

    if (mus_playing == music)
    {
        return;
    }

    // shutdown old music
    S_StopMusic();

    // get lumpnum if neccessary
    if (!music->lumpnum)
    {
        I_Printf("D_%s\n", music->name);
        sprintf(namebuf, "D_%s", music->name);
        I_Printf("lumpnum: %d\n", music->lumpnum);
        I_Printf("namebuf: %s\n", namebuf);
        music->lumpnum = W_GetNumForName(namebuf);
        I_Printf("lumpnum updated: %d\n", music->lumpnum);
    }

    // load & register it
    music->data = (void *)W_CacheLumpNum(music->lumpnum, PU_MUSIC);
    music->handle = MUS_RegisterSong(music->data);

    // play it
    MUS_ChainSong(music->handle, looping ? music->handle : -1);
    MUS_PlaySong(music->handle, snd_MusicVolume);

    mus_playing = music;
}

The name is not correct. 'D_DM2_TTL' (hardcoded inside S_music) is not found (W_GetNumForName returns -1). If I replace it with 'd_haxttl', the menu music plays !

Now, I need to not hardcode it while still make FastDoom find it...

viti95 commented 3 years ago

You're right, the problem lies in the music lump names. FastDoom is only compatible with Vanilla Doom WADs, so the music lumps must have the same names as the original IWAD to work. This is a limitation from the original engine.