Author Topic: How to use interrupts  (Read 10358 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
How to use interrupts
« on: September 01, 2010, 11:50:27 pm »
Hi, can somebody provide a short example on how to use interrupts?
Just a few snippets of code to provide an example for me to work with?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: How to use interrupts
« Reply #1 on: September 02, 2010, 12:10:53 am »
Do you mean axe or pure asm?

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: How to use interrupts
« Reply #2 on: September 02, 2010, 12:12:17 am »
I'm fairly sure in Axe since this is in the Axe sub-forum. Plus I think he is planning on trying to use them in his Minesweeper game.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: How to use interrupts
« Reply #3 on: September 02, 2010, 01:30:25 am »
So interrupts are not that bad, here is some simple code:

FnInt(INT,6) Run this to turn on inbterupts.  This code turns on interupts with the label INT.  So that every couple of milliseconds, it will Sub(INT).  The second number 6, represents the time it takes between each Sub().  0 is the fastest, and 6 is the slowest.  The only possible values are 0,2,4 and 6.

Do you want some example code?  Interups are surprisingly simple to set up, why dont you give it a try! :D

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: How to use interrupts
« Reply #4 on: September 02, 2010, 01:36:51 am »
What are interrupts exactly?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: How to use interrupts
« Reply #5 on: September 02, 2010, 01:44:33 am »
What are interrupts exactly?

Well, suppose you have a routine that you want to run every certain amount of time, no matter where you are in the program.  After the certain amount of time has passed, the program will be "interrupted" and run the routine.  When the routine is finished, the program will continue running normally.

That's why many people use interrupts for things requiring a timer.  For example, in S.A.D., I need a building to construct no matter what the user is doing in a program.  Whether the player is moving a ship, buying buildings, or collecting resources, that building has to keep on constructing.  So I have an interrupt routine to construct the building.  Whenever a certain amount of time has passed, the building's HP will increase by 1 HP.
« Last Edit: September 02, 2010, 01:45:17 am by Hot_Dog »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: How to use interrupts
« Reply #6 on: September 02, 2010, 01:46:07 am »
Axe makes interrupts very simple, there really isn't much to them.  You just give it the name of the routine that you want to use for the interrupt and the frequency (how often the interrupt is executed every second).  The fnInt() command also enables the interrupts for you so they start working right away.  Generally though, interrupt code makes the program much larger and slightly slower so I would only use them for applications where you're actually using it for it's timing feature.  For example; a stopwatch or music player.

Once its set up, it will execute the interrupt code at a regular frequency "in the background" except that it has to halt normal code execution while the interrupt code is used which might make your game appear to pause if the interrupt code is too long.  Interrupt code should normally be short like increasing a timer variable.  There are several commands that go with interrupts explained in the commands list.  fnOff will temporarily turn off the interrupts.  fnOn will turn them back on.  Stop will wait until the next interrupt before continuing.  And lastly but most importantly is LnReg which kills the custom interrupt completely and returns back to the normal OS interrupt.  You NEED this before you exit the program or else the calculator will freeze.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: How to use interrupts
« Reply #7 on: September 02, 2010, 02:07:27 am »
Oh, ok. That makes sense, I think. So just a quick situation for this. Say your game character has lost health and you want to increase his health by six every few seconds until it is full again. Would you then set the interrupt but then turn it off right away and then when your characters health is lower than full you use FnOn to turn the interrupt on and the when it gets full again run FnOff to stop the interrupts?

Code: ( Pseudo Code) [Select]
FnInt(HLT,6
FnOff
Some type of loop
If CurrentHealth<MaxHealth
FnOn
End
If CurrentHealth=MaxHealth
FnOff
End
Other code
End
sub(HLT
CurrentHealth+6
Return

Obviously that's not a good example, but ya. Just curious if that's kinda what ya mean.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: How to use interrupts
« Reply #8 on: September 02, 2010, 02:10:29 am »
There are only 2 things wrong with that code.  1, its a Label, so you do Label HLT, not Sub(.  The second is to note that interrupts trigger many many times per second, even at the slowest rate, so the health would regenerate very quickly indeed :P

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: How to use interrupts
« Reply #9 on: September 02, 2010, 02:17:42 am »
Oh ok. I thought it was a sub-routine, misread that :P And for the sake of this we'll pretend the characters health is OVER 9000! :P
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: How to use interrupts
« Reply #10 on: September 02, 2010, 02:19:31 am »
Well it is a subroutine, which are defined with labels :) Sub() is the command to call a subroutine, not define it

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: How to use interrupts
« Reply #11 on: September 02, 2010, 02:23:01 am »
OH! That's right. My bad. Show's how much I use Axe :P
« Last Edit: September 02, 2010, 02:23:17 am by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: How to use interrupts
« Reply #12 on: September 02, 2010, 10:44:50 am »
By the way, you should take into account that at least in normal speed (6Mhz), the Ti-83+ has more interrupts per second than a Ti-83+ silver edition does.  It's roughly 110 interrupts per second for the Ti-83+ SE, and 120 interrupts per second for the Ti-83+. 

This was only tested on Wabbitemu, so please feel free to correct me.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: How to use interrupts
« Reply #13 on: September 02, 2010, 10:48:40 am »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: How to use interrupts
« Reply #14 on: September 02, 2010, 11:49:31 am »
Also, you are increasing health by 6 each time but checking that it's equal to the max health.  If the current health is 999 and you add 6, that's 1005 which is not equal to 1000 and the health would continue to increase.
___Axe_Parser___
Today the calculator, tomorrow the world!