A85: Re: Re: Re: Programming help


[Prev][Next][Index][Thread]

A85: Re: Re: Re: Programming help




>>
>>What does the programmer do when the game loops so fast that the
>>character is uncontrollable?  Do you just insert a meaningless,
>>time-consuming loop at the beginning of the game loop (or the end, or
>>wherever)?
>
>
>Yes, though just a loop is not normally what is used.  A loop with HALTs in
>it usually works pretty well, or if only two or three are needed, you can
>save space by not looping at all.  The link routines should help the
timing,
>though.  Remember that interrupts are called approximately 200 times a
>second, though I have found (on the 86) that they are called closer to 175
>times a second (174 to be exact, but I think the battery level affects
>this).  So each halt will delay for up to (depends when the last interrupt
>occurred) 1/200th of a second.  So 20 halts would wait ~0.1 seconds...
>


i think it is best to install an interrupt.  if you use an interrupt, if
certain iterations of the loop take longer than others, the timing will
still be the same.  the interrupt routine needed is a simple counter.  here
would be the pseudo-code (though i posted actual code for this a couple of
weeks ago when someone asked about interrupt routines)

MainCode:

count = 0
install interrupt
begin game loop
  do some game stuff
  wait for count to be (greater than or) equal to say 200 (one second)
      once it is equal, you have waited one second
  count = 0
  jump to game loop?
end game loop
exit

InterruptRoutine:
  increment count
  return


remember that the interrupt routine gets called automatically every 1/200 of
a second once it has been installed.

-mike pearce