I am trying to convert demo7_4 from tricks of the windows game programming gurus to HLA but I am having a problem. The program terminates from a loop in the Game_Main procedure but if I include a message somewhere like in game_init it runs without a problem.


// erase double buffer
MemSet(double_buffer,0, SCREEN_WIDTH*SCREEN_HEIGHT);
stdout.put( "after erasing double buffer", nl );
mov( double_buffer, ebx );

for( mov( 0, ecx ); ecx < 5000; add( 1, ecx )) do
stdout.put ( ecx, nl );
rand.urange( 0, SCREEN_WIDTH );
mov( eax, esi );
rand.urange( 0, SCREEN_HEIGHT );
mov( eax, edi );

mov( SCREEN_WIDTH, eax );
mul( edi );

add( eax, esi );

rand.urange( 0, 256 );
mov( al, [ebx + esi] );


The program terminates after a number of iterations of the loop above.

w.MessageBox( main_window_handle, "leaving game_init", 0, 0 );
mov( true, eax );

pop( ebx );
end Game_Init;

If I comment out the message box the program doesn't work but if I leave it as it is it does. Anyway idea what's the problem?
Posted on 2004-10-08 17:06:23 by Odyssey
I don't know enough HLA but a guess would be that if you're having problems with the for loop it may be because ecx is being modified somewhere inside it. Pushing and popping it may solve you're problem.

The Messagebox bit makes no real sense but it could be something wierd such as the certain registers or the stack is being set to some value(s) which just happen to cause things to work :? .
Posted on 2004-10-08 17:37:38 by Eóin
Thanks for the help anyway Eoin. Now that I've found the problem I think this post belongs in the HLA section. :-D The problem is that the HLA rand.urange doesn't work the same as rand()%SCREEN_HEIGHT. The c code produces values ranging from 0 to 479 while the HLA function produces values from 0 to 480 and sometimes all the numbers add up to an index that is outside the double_buffer array. I haven't had any problems with the rand function before with examples that wrote directly to vram. Why is this?
Posted on 2004-10-08 18:29:49 by Odyssey
Nrmally when a numeric ranged value is zerobased, we subtract one from the high-end value (0-479). C does this for us, for example if we rand(50), we will get 0 to 49... never 50.

What you are witnessing is called inclusive ranging - apparently HLA numeric ranges are ALL-INCLUSIVE, so you will have to manually edit the high-end values (subtract one).

Not a big job, and yes this post belongs under HLA.
Posted on 2004-10-15 01:29:31 by Homer