Qbasicnews.com
Help with porting allegro timer - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Help with porting allegro timer (/thread-6296.html)

Pages: 1 2


Help with porting allegro timer - Jotz - 03-02-2005

I'm trying to copy the method of using a timer for Allegro that is in C++. The problem is I don't know how to convert some things from C++ to FB:
Code:
volatile long speed_counter = 0; //what would I use for volatiles?

void increment_speed_counter() //a function
{
  speed_counter++;  //easy: speed_counter = speed_counter + 1
}
END_OF_FUNCTION(increment_speed_counter);  //that is a macro,
                                                                         //how would I use?

//more macros...

LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);

I don't know how to do the volatile variables and the macros. How would I make those?


Help with porting allegro timer - DrV - 03-03-2005

IIRC (don't quote me on this!) on Windows, the LOCK_VARIABLE and LOCK_FUNCTION don't do anything, nor does END_OF_FUNCTION - but I could be wrong!!!! I'll read the headers in a minute, but I think it should work without the macros.

Regarding volatile variables: FreeBASIC doesn't do any optimizations (yet) that would require a 'volatile' keyword, so you shouldn't need it.


EDIT: Yup, LOCK_FUNCTION etc. don't do anything on Windows. I'll add them sometime soon for DOS, though - DOS and Mac need them.


Help with porting allegro timer - Jotz - 03-03-2005

Ok thanks, but I'm still having some trouble making the timer in allegro. Here is the basic parts of my timer:

Code:
allegro_init
install_timer

thetimer = 0                                      'the timer variable

declare function increment_timer()   'creates the timer incrementer

function increment_timer()                'function to increment timer
   thetimer = thetimer + 1
end function

install_int_ex(increment_timer, BPS_TO_TIMER(60))  'sets the BPS

while thetimer > 0
   ... (logical operations)
   thetimer = thetimer - 1
wend

The while loop seems to only run once. I know that it doesn't set thetimer back to 60, but it's supposed to already do it. Help would be appreciated.


Help with porting allegro timer - shiftLynx - 03-04-2005

Quote:
Code:
allegro_init
install_timer

thetimer = 0                                      'the timer variable
...

while thetimer > 0
   ... (logical operations)
wend


thetimer is 0 when it reaches the loop containing the condition thetimer > 0.

By the way, after one call to your timer function, that while loop will become an infinite loop... thetimer is always increased, which means it will always be >0.

-shiftLynx


Help with porting allegro timer - Jotz - 03-04-2005

Oops, sorry I forgot to add:

Code:
while thetimer > 0
   ... (logical operations)
   thetimer = thetimer - 1
wend



Help with porting allegro timer - Jotz - 03-08-2005

Well, I've tried to set the timer back to 60 every time after the while loop, but it either crashes or doesn't work. Also, one of the C++ examples of it said that the volatile keyword is needed or else it would not work. I'm worried because I already did a lot of my game in Allegro and I don't want to have to convert all of it into FBGFX or SDL. Does anyone know how to create the timer?


Help with porting allegro timer - v3cz0r - 03-08-2005

If i remember, the Allegro callbacks use the C calling convention, try redeclaring them as function mycallback cdecl ... (...) ... .


Help with porting allegro timer - Jotz - 03-08-2005

Ok, I tried changing it:

Code:
declare function increment_timer cdecl()

function increment_timer cdecl()
   thetimer = thetimer + 1
end function

But it still produced similar results. The tutorials and forum posts I read said that the volatile keyword and END_OF_FUNCTION(), LOCK_FUNCTION(), etc. macros are necessary for the timer. I still don't know, how would I make it without the them? If it may help, here is a link to one of the tutorials: http://www.glost.eclipse.co.uk/gfoot/vivace/vivace.html#Timers


Help with porting allegro timer - DrV - 03-08-2005

this line:
install_int_ex(increment_timer, BPS_TO_TIMER(60)) 'sets the BPS
should be:
install_int_ex(@increment_timer, BPS_TO_TIMER(60)) 'sets the BPS
or:
install_int_ex(procptr(increment_timer), BPS_TO_TIMER(60)) 'sets the BPS


Help with porting allegro timer - Jotz - 03-08-2005

I tried that, but it still didn't affect it. Argh I can't get it to work without the macros + volatile. Could it have something to do with the fact that the Allegro header is incomplete?