Lost in Time
17 Nov 2023 02:00 / last edited 21 Nov 2023 15:25
Hi there,

A long time ago, about 20 years ago to be more precise - when my nephew wasn't even born - I messed a lot with the Beats of Rage source code for DOS.

Now that my referred nephew is learning C Programming Language AT THE UNIVERSITY    (we're getting old, aren't we) I'd like him to mess with the BoR code too, but I can't link the source code.

I can compile using Watcom:
wcc386 -fp3 -3r -bt=pmodew BOR.C

The problem is I can't link it.
All the attempts end in failure "E2028" "undefined symbol" throwing a function_name_with_an_extra_underscore.
I've been searching for days for a way to prevent wcc386 from adding that extra underscore to the function names, but I'm lost.

Could you guys please tell us how to compile and link the original BoR source code properly?
I have no clue how I used to compile and link properly back in 2003. I simply can't remember.

Thank you in advance for your time and congratulations for your great work.

PS: I'm using DOSBox 0.74-3 and tried on a Windows machine under VirtualBox too.

Roel
Senile Team Big Cheese
Avatar
17 Nov 2023 10:15 / last edited 17 Nov 2023 10:19
Well that's a difficult question, because it was 20 years ago for me too! 

I tried to find the commands I used back in those days. I didn't find the exact ones, but here are some lines I found in a batch file from around the same time:

Code:
for %%i in (*.c) do wcc386 -i=%WATCOM%\h -fp5 -5r -bt=dos32a -wx -we -ox -dDOS -dDEVBUILD %%i
:: move all except main.obj into the object/ directory
for %%i in (*.OBJ) do if not %%i==MAIN.OBJ move /Y %%i object
wlink system dos32a file main,object\*.obj
SS main.exe d32cfg.d32


I forgot the exact mechanism, but I vaguely remember that compilers add underscores and other tokens to distinguish functions with the same names but different argument lists. This is a C++ feature, so it should not affect C code. Perhaps the compiler is interpreting the code as C++ for some reason.

You can check if you're dealing with a C++ compiler by putting this somewhere in the code:
Code:
#ifdef __cplusplus
#error "You are compiling in C++ mode"
#endif

To force C++ compilers to use the C naming standard, you can put these lines in your header files around the exported function prototypes.
Code:
#ifdef __cplusplus
extern "C" {
#endif

// Function prototypes...

#ifdef __cplusplus
}
#endif
It should then be possible to link the files into an executable.


I haven't tested the things I wrote here, so apologies if I made any mistakes. 20 years is a long time.

Lost in Time
17 Nov 2023 23:24
Hey Roel! Nice talking to you!

I tried your suggestions but still couldn't compile and link.

As you suggested, I added the code you provided between the function prototypes to some of the header files inside GAMELIB3, but the compiler still adds that extra underscore after the names of those very functions.

I also tried the code:
Code:
#ifdef __cplusplus
#error "You are compiling in C++ mode"
#endif
Although the compiler did not give any error messages, it still added those extra underscore characters.

Same happens even trying the lines from your old batch file.
I found this batch on some of my backup disks:
Code:
wcl386 -i=%WATCOM%\h @%WATCOM%\pmodew\pmodew.lnk -bt=pmodew %1 GAMELIB3\*.OBJ
pmwlite /C4 %1.exe
pmwsetup /B0 %1.exe

Does it "click" about the linking procedure? I really can't remember.
I tried that batch too, but still, no success.

Do you think we could be missing some environment setup or something like that?
Maybe Watcom does not work properly on virtual machines... I really have no idea.


Thank you for your time.

Lost in Time
18 Nov 2023 02:26 / last edited 18 Nov 2023 04:13
I Got it!!!

The "secret" was to use wlink instead of wcl386. I created a batch script so anyone who wants to try the original Beats of Rage should be able to compile and link it easily. All they have to do is install Watcom or Open Watcom at C:\ and make sure PMODEW is there. Also make sure the batch script is named "COMPILE.BAT"

It is here for the record. Not that beautiful but it works. 

Code:
@ECHO OFF
CLS
ECHO ----------------------------------------------
ECHO - Beats of Rage                              -
ECHO - Compilation Script by Lost in Time 2023    -
ECHO ----------------------------------------------
ECHO -  1) Set Watcom environment variables       -
ECHO -  2) Clean Compilation Directory            -
ECHO -  3) Full Project Compilation               -
ECHO ----------------------------------------------
ECHO -  4) Exit                                   -
ECHO ----------------------------------------------

choice /c1234 /s Wassup? [1-4]: /n 
if errorlevel 4 goto exit
if errorlevel 3 goto compile
if errorlevel 2 goto clean
if errorlevel 1 goto setenv

:setenv
PATH=C:\WATCOM\BINW;C:\WATCOM\PMODEW;%PATH%
SET WATCOM=C:\WATCOM
SET INCLUDE=C:\WATCOM\H
SET EDPATH=C:\WATCOM\EDDAT
SET WIPFC=C:\WIPFC
echo .
echo DONE!
PAUSE
COMPILE.BAT

:clean
:: CLEAN THE PROJECT
@echo off
echo.
echo Removing OBJ, ERR and EXE files
echo.
del *.obj
del *.err
del BOR.EXE
cd GAMELIB3
del *.obj
del *.err
cd ..
echo .
echo DONE!
PAUSE
COMPILE.BAT

:compile
@echo off
:: DEFINE COMPILATION COMMAND
SET COMPASM=wasm -5pr -fp5 -mf -bt=pmodew
SET COMPC=wcc386 -5r -fp5 -mf -i=C:\WATCOM\H -bt=pmodew
:: COMPILE GAMELIB FILES
CD GAMELIB3
:: ASM Files
%COMPASM% ASMCOPY.ASM
%COMPASM% KEYBOARD.ASM
%COMPASM% RAND32.ASM
%COMPASM% TIMER.ASM
%COMPASM% VGA.ASM
:: C FILES
%COMPC% ANIGIF.C
%COMPC% SPRITE.C
%COMPC% SOUNDMIX.C
%COMPC% VESA.C
%COMPC% CONTROL.C
%COMPC% VIDEO.C
%COMPC% PALETTE.C
%COMPC% SYSTEM.C
%COMPC% LOADIMG.C
%COMPC% BITMAP.C
%COMPC% PACKFILE.C
%COMPC% DRAW.C
%COMPC% SAVEPCX.C
%COMPC% FONT.C
%COMPC% SCREEN.C
%COMPC% JOY.C
%COMPC% SBLASTER.C
%COMPC% SPRITEQ.C
%COMPC% ADPCM.C
%COMPC% TEXTURE.C
%COMPC% SSPRITE.C
:: COMPILE MAIN SOURCE CODE
CD ..
%COMPC% BOR.C
:: LINK THE PROJECT
wlink system pmodew file BOR.OBJ,gamelib3\*.obj
echo.
PAUSE
COMPILE.BAT

:exit
echo .<-
echo -------
echo - Ok. -
echo -------


Thank you very much, Roel, for your time and your amazing work! Although I played many mods at the time, not much from the OpenBoR era, but the original ones, the original BoR still has me. It's very neat and well crafted. I still play it to this day, but mostly the console ports.

Again, thank you Roel, Jeroen, Ian Micheal, Kirby2K, Shaun Nichols, Mr. Q (Mauricio), Master Drico, bWWd, Rameen, L@Cible, DemonCaskey, KungFuCoder, KungPow and of course Neil Corlett for porting this amazing game to PS2, Dreamcast and og XboX (or was the original XboX port made by a600? Can't remember).

Well, just in case I forgot to mention someone, thanks to all the BoR community, from all over the world, who always brings me sweet memories from 20 years ago. 
That was a really, really nice time.

That's why it's important to me my nephew could play with the original BoR source code.


All the best!

bor_compilation_success.png

EDIT: I just forgot to mention:
Make sure you have PMODEW directives in your WLINK.LNK:
File: C:\WATCOM\BINW\WLINK.LNK
Code:
# example linker initialization file.
# remember, don't put carets (^) in these!
system begin 286
    libpath %WATCOM%\lib286
    libpath %WATCOM%\lib286\dos
    format dos
end
system begin 386
    option osname='DOS/4G'
    libpath %WATCOM%\lib386
    libpath %WATCOM%\lib386\dos
    op stub=wstub.exe
    format os2 le
end
system begin pmodew
    option osname='PMODE/W'
    libpath %WATCOM%\pmodew
    libpath %WATCOM%\lib386
    libpath %WATCOM%\lib386\dos
    option stub=pmodew.exe
    format os2 le
end
@%watcom%\binw\wlsystem.lnk

This should avoid the annoyance of calling DOS4GW.EXE before BOR.EXE.
I think this is it.


Roel
Senile Team Big Cheese
Avatar
18 Nov 2023 11:53
Well done! I'm glad you found the solution. I hope you and your nephew will have as much fun with BOR as you did back in the day!