Author Topic: Timer?  (Read 2456 times)

0 Members and 1 Guest are viewing this topic.

Offline ClrDraw

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 627
  • Rating: +61/-2
    • View Profile
    • GitHub
Timer?
« on: March 14, 2014, 11:36:00 pm »
I'm making Don't Step The White Tile and need to time how long it takes the player to get to the end. How do I use a timer in axe? Do I need to use interrupts (And if so, how? My calc likes to freeze whenever I try using interrupts...)?


Please help; this is the last thing I need before my game is all finished  :)
Visit my GitHub for all my TI programs as well as other projects.
Also check out my website.

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Timer?
« Reply #1 on: March 15, 2014, 05:08:44 am »
Yeah, interrupts are the way to go when you need to measure a time. The slowest setting should be fine for a game, since you don't need it accurate. Inside the Interrupt Service Routine you increment a variable. Since interrupt speed "6" corresponds to 118 Hz on a 83+ or to 108 Hz on a 84+, you divide by 118 or 108 to get the amount of seconds elapsed (or by 12 / 11 for tenths of a second). It is important to put the calc back to normal interrupt mode before exiting, otherwise crashes occur.
Code: [Select]
... // initializing stuff
fnInt(TMR,6)   //turn on the interrupt
0->T   //say T is our timer variable, reset it when the game starts.
game loop {
...// Stuff
}
T->S  //save the time after the game finished
S/118->S //get the seconds elapsed
...// win display stuff
LnReg  // back to normal interrupt mode, this is important
LnRegr   //repair any damage done by the custom interrupt
Return //Exit


Lbl TMR //the actual interrupt service routine
T++  // increment the counter variable
Return  //it's a subroutine so we return as usual


We don't need to make sure it doesn't overflow if you reset it everytime a nee game starts. Since the counter is incremented 118 a second and can only hold values up to 65535, it can run 555 seconds before it resets, that's about 9 minutes. So if a game takes longer than that, you need to use multiple variables, but I guess that shouldn't be a problem right now ;)


Either way, good luck with your project - I'm looking forward to see it :)

Offline ClrDraw

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 627
  • Rating: +61/-2
    • View Profile
    • GitHub
Re: Timer?
« Reply #2 on: March 15, 2014, 11:28:00 am »
Thank you so much! That's just what I needed. It should be done really soon thanks to you  ;D
Visit my GitHub for all my TI programs as well as other projects.
Also check out my website.