#266 BaK does not work on amd64

0.65
closed
graphics (66)
5
2012-09-07
2006-08-18
Guido de Jong
No

The game Betrayal at Krondor does not work properly on
amd64 architecture (64-bit mode). The game starts
correctly, shows the intro and the options screen. When
you start a new game, the chapter animation and story
is shown and sound is working too. After the map with
the chapter title in the lower left corner the screen
turns black and nothing happens. On x86 architecture
(32-bit mode) the game works just fine.

Discussion

  • Peter Veenstra
    Peter Veenstra
    2006-08-22

    Logged In: YES
    user_id=535630

    None of the developers has a amd64 machine.
    So it will be hard for us to track down the problem
    Are you capable of compiling DOSBox ? If so, I could provide
    you with a small patch that logs a lot of stuff that might
    not work under amd 64.

     
  • Guido de Jong
    Guido de Jong
    2006-08-28

    Logged In: YES
    user_id=2269

    Of course you can not be expected to have all possible
    configurations at you disposal. But sure I can build dosbox.
    As a matter of fact I already checked out the latest CVS
    version to make sure the problem was not fixed already. The
    bug still exists. So, please provide for the patch and I
    will provide you with the logs.

     
  • Guido de Jong
    Guido de Jong
    2006-08-28

    Logged In: YES
    user_id=2269

    According to AMD, many issues with porting from 32 to 64
    architecture can be prevented by making sure that your code
    compiles without warnings. I noticed that DOSbox generates
    an aweful lot of warnings. I added the following line to
    configure.in:

    CXXFLAGS="$CXXFLAGS -W -Wall -Wpointer-arith -Wcast-qual
    -Wwrite-strings -Wshadow -Wcast-align -Winline"

     
  • Guido de Jong
    Guido de Jong
    2006-08-30

    Logged In: YES
    user_id=2269

    Using the DOSbox debugger I noticed that BaK loops in the
    INT 0 handler (divide by 0) after executing a "div cx"
    instruction. Hope this helps ...

     
  • Peter Veenstra
    Peter Veenstra
    2006-09-01

    md5sum after the patch

     
    Attachments
  • Peter Veenstra
    Peter Veenstra
    2006-09-01

    Logged In: YES
    user_id=535630

    Hi,

    div cx looping: is cx =0 or not ?
    I added a log message for it.

    Let's start the session:
    www.alt-tab.net/games/betrayal-at-krondor/download/
    Using this archive (extracted in DOSBox)
    Installed the patch.
    Included the md5sums of all files in the file md5.txt
    configured the game. (although the soundblaster/adlib was
    allready selected)

    Applied the attached patch to dosbox.
    Run dosbox in debug mode (configure --enable-debug)
    create a new configfile
    look for the log= entry
    change that to log=/tmp/bak.txt
    start dosbox using that configfile
    run the game. I watched one full credits part. When that
    ended I continued to watch until the credits started the
    second time. Pressed escape.
    Pressed new game (with mouse) kept clicking to speed up the
    animation. Waited until I reached the ingame. exited dosbox
    with ctrl-f9 (this was after the map loading screen)

    Attach and/or compare the log with the one I attach here.

     
  • Peter Veenstra
    Peter Veenstra
    2006-09-01

    my log

     
    Attachments
  • Peter Veenstra
    Peter Veenstra
    2006-09-01

    Logged In: YES
    user_id=535630

    I used the original 0.65 source.

     
  • Peter Veenstra
    Peter Veenstra
    2006-09-01

    patch for dosbox to log dos calls and exception 0

     
    Attachments
  • Guido de Jong
    Guido de Jong
    2006-09-08

    Logged In: YES
    user_id=2269

    I patched the sources an ran BaK in DOSBox. The problem is
    the DIVW instruction:

    DIVW overflow B830 0 B8300000 D31C

    On AMD64 the numerator (num) is expanded to 64 bits. So
    internally num = FFFFFFFFB8300000, which eventually results
    in the overflow. The solution is simple: num should be
    limited to 32 bits (change to type bit32u).

    Note that IDIVW has a similar problem, but that is left as
    an exercise for the reader :-P

     
  • Guido de Jong
    Guido de Jong
    2006-09-09

    Patch to fix this bug

     
    Attachments
  • Peter Veenstra
    Peter Veenstra
    2006-09-09

    Logged In: YES
    user_id=535630

    would you suggest/try:

    Bitu num=(((Bit32u)reg_dx)<<16)|reg_ax

    or
    Bit32u num=(reg_dx<<16)|reg_ax

    I would prefer the first, as that makes it comparable
    to the DIVD variant, but I can't test if it works.

     
  • Guido de Jong
    Guido de Jong
    2006-09-10

    Logged In: YES
    user_id=2269

    I tried three different solutions:

    Bit32u num=(reg_dx<<16)|reg_ax;
    Bitu num=(((Bit32u)reg_dx)<<16)|reg_ax; // DIVD variant
    Bitu num=(Bit32u)((reg_dx<<16)|reg_ax); // IDIVW variant

    All of which work, so you can simply chose.

    Also note that checking for zer values is done in different
    ways:

    if (!val) EXCEPTION(0);
    if (val==0) EXCEPTION(0);

    Assuming that both compile to the same machine code, I'd
    suggest using the latter.

    One final note, in the AAD operation you can remove the line:

    Bit8u old_al = reg_al;

    Because the variable old_al is never used.

     
  • Peter Veenstra
    Peter Veenstra
    2006-09-14

    Logged In: YES
    user_id=535630

    Commited
    Bitu num=(((Bit32u)reg_dx)<<16)|reg_ax;
    changed the !val to val==0
    and removed the old_al in AAD