VOGONS


First post, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

I'm making decent progress converting my RPG engine to Allegro from it's current SDL implementation and am at the point of replacing the input handlers with those of Allegro. These make use of various system timers that Allegro initialises after a "install_timer()" function. Things like mouse tracking don't work until that is done.

Allegro is the last available release that natively supported DOS: 4.2.3.1, from here, since it's now a bit of a chore to compile with anything recent (I'm using Open Watcom 2, a late November 2022 release, cross-compiling from Linux).

The issue is that as soon as I issue the install_timer() function, my application blows up. I comment the line out again and everything is fine (although I don't have timers to enable input, audio playback etc).

Code looks like this:

int input_Init(void){
int has_timer = 0;
int has_mouse = 0;
int has_joystick = 0;

draw_LoadText("System timer...");

// Crashes here!!!
if (install_timer() == 0){
has_timer = 1;
draw_LoadBar(-1);
} else {
screen_Exit();
printf("Error, Unable to setup Allegro system timers for input devices!\n");
return -1;
}

draw_LoadText("Mouse...");
if (install_mouse() >= 0){
has_mouse = 1;
}
draw_LoadBar(-1);

draw_LoadText("Joystick...");
if (install_joystick(JOY_TYPE_AUTODETECT) == 0){
has_joystick = 1;
}
draw_LoadBar(-1);

draw_LoadText("Inputs configured");
draw_ProgressIcon(TILE_CONTROLS);
return OK;
}

Obviously none of the draw_* functions have anything to do with the timers; they're all on-screen indicators for the loading screen. Depending on whether the install_timer() line is commented out or not, I get the following behaviour:

Working: https://www.youtube.com/watch?v=nw-UY8WWjHU

Crashing: https://www.youtube.com/watch?v=INYKW50ZS40

The same behaviour is exhibited both within Dosbox and real hardware (the videos are of one of my real systems). Dosbox throws the following at the point of crashing:

DOSBox version 0.74-3
Copyright 2002-2019 DOSBox Team, published under GNU GPL.
---
CONFIG:Loading primary settings from config file ../etc/dosbox-386-4mb-sb16.conf
MIXER:Got different values from SDL: freq 44100, blocksize 512
ALSA:Client initialised [128:0]
MIDI:Opened device:alsa
terminate called after throwing an instance of 'char*'
Aborted

The Allegro forums are pretty inactive these days, so I though my Vogons pals here may have some experience with Allegro?

My collection database and technical wiki:
https://www.target-earth.net

Reply 1 of 9, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

More madness.

This works:

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <allegro.h>

int errno;

int main(){
int i;

printf("Starting allegro\n");
i = install_allegro(SYSTEM_AUTODETECT, &errno, NULL);
if (i != 0){
printf("Error: Allegro library did not install!\n");
return(-1);
} else {
printf("Ok!\n");
}

printf("Installing timer\n");
if (install_timer() == 0){
printf("Ok!\n");
} else {
printf("Error, Unable to setup Allegro system timers for input devices!\n");
return -1;
}
allegro_exit();
return 0;
}

... but adding the install_timer() call after install_allegro() in my main() (rather than the very basic test main above) still results in the exe terminating abnormally.

It's literally the second thing I'm doing in my own main() section, the only things before it are the call to install_allegro, and a few logging statements.

There must be something else, some symbol, some global variable, or some other startup code that is present in some other part of my application which is causing install_timer to behave this way. I'm at a loss though - I'm not doing anything with timers or interrupts myself, and the only third party bits of code is Allegro itself, and the Judas audio library (which I temporary commented out and excluded from the linker).

My collection database and technical wiki:
https://www.target-earth.net

Reply 3 of 9, by gerwin

User metadata
Rank l33t
Rank
l33t

Can you build the whole Allegro package with tools and examples? Surely there is one example in there using the timers.

OpenWatcom + Linux Cross-compile is not really a common platform for Allegro, I suppose... I use DJGPP on Windows XP x86, two separate setups. But neither of them are semi-modern DJGPP together with Allegro v4.
I do use Allegro 4, but only in its Windows version.

--> ISA Soundcard Overview // Doom MBF 2.04 // SetMul

Reply 4 of 9, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

Yeah, I am coming round to the conclusion that I am going to have to start this from scratch with a complete source install of djgpp, Allegro and the rest, so that I know if anything is broken, it's down to me.

It's a shame having to install yet another cross compile toolchain for dos, as the Watcom stuff is brilliant for 16bit work.

I'll get djgpp installed and bodge the makefile around to get it to play nice with GCC/LD instead of WCC/wcl.

My collection database and technical wiki:
https://www.target-earth.net

Reply 5 of 9, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

Ok, confirmed. Swapping out OpenWatcom with a GCC 12.x version of djgpp, and rebuilding the Allegro 4.2.3.1 library to use it (bear in mind anyone wanting to compile Allegro 4.x from source with a modern compiler - you need to add the -fgnu89-inline argument to the CFLAGS options in makefile.dj to support some of the inline code in the various Allegro header files [deprecated in C99 and later], and add two missing integer symbols in vbeaf.c for it to work - it has clearly bitrotted somewhat when it comes to compatability with modern toolchains).

No more abnormal termination when install_timer() is encountered in my code!

Sadly, it does mean moving to the use of cwsdpmi rather than the much neater (and seemingly leaner) dos32a.exe as the runtime support.

Moral of the story - don't use OpenWatcom for Allegro on DOS. You *can* use a later version of djgpp, but also be prepared to patch a few bugs when building it.

My collection database and technical wiki:
https://www.target-earth.net

Reply 6 of 9, by gerwin

User metadata
Rank l33t
Rank
l33t
megatron-uk wrote on 2022-12-22, 22:26:
Ok, confirmed. Swapping out OpenWatcom with a GCC 12.x version of djgpp, and rebuilding the Allegro 4.2.3.1 library to use it (b […]
Show full quote

Ok, confirmed. Swapping out OpenWatcom with a GCC 12.x version of djgpp, and rebuilding the Allegro 4.2.3.1 library to use it (bear in mind anyone wanting to compile Allegro 4.x from source with a modern compiler - you need to add the -fgnu89-inline argument to the CFLAGS options in makefile.dj to support some of the inline code in the various Allegro header files [deprecated in C99 and later], and add two missing integer symbols in vbeaf.c for it to work - it has clearly bitrotted somewhat when it comes to compatability with modern toolchains).

No more abnormal termination when install_timer() is encountered in my code!

Sadly, it does mean moving to the use of cwsdpmi rather than the much neater (and seemingly leaner) dos32a.exe as the runtime support.

Moral of the story - don't use OpenWatcom for Allegro on DOS. You *can* use a later version of djgpp, but also be prepared to patch a few bugs when building it.

Good to hear that. And thanks for the tips there.

--> ISA Soundcard Overview // Doom MBF 2.04 // SetMul

Reply 7 of 9, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie

Be aware DJGPP might have timer issues with DOSBox.. it does some funky things to workaround DPMI interrupt handling limitations which aren't emulated correctly by DOSBox (segment limit checking).

Reply 8 of 9, by hail-to-the-ryzen

User metadata
Rank Member
Rank
Member

One test is to run dosbox-x configured with normal core and segment limits active. It should log the segment limit events. If the segment limit checking is on cs/ds, then another option is to link against hdpmi, if possible, or test with djgpp_nearptr_enable.

Reply 9 of 9, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

Allegro and DJGPP are working nicely with each other, including interrupt timer based playback of the native Allegro midi support as well as my custom tracker music backend based on the Judas Audio library. Digital effect playback is next.

All working really well. Game isn't complete, but should have a video up shortly showing at least the loading/configuration and main story/navigation interface. Combat isn't quite done yet.

My collection database and technical wiki:
https://www.target-earth.net