Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Broseph Radson on January 18, 2011, 08:00:15 pm

Title: Another noob question. this time about interrupts
Post by: Broseph Radson on January 18, 2011, 08:00:15 pm
Im experimenting with interrupts since i just figured out how they could be used if i want to make a graphical shell (not that i can do any other part of making a shell BESIDES graphics and menus lol). I have this:
Code: [Select]
fnInt(S,0)
ClrHome
"A->A
Lbl 1
Disp A
Repeat getKey(15)
End

FnOff //to be safe
LnReg
Return

Lbl S //Interrupt subroutine
If getKey(54)
Goto 1
End
Return

It exits when i press Clear, but when i press 2nd, it doesnt jump to Lbl 1. Am i using the interrupt wrong or do i just have the wrong idea of how they work?
Title: Re: Another noob question. this time about interrupts
Post by: Deep Toaster on January 18, 2011, 08:02:58 pm
Try not to jump around when you're in an interrupt. An interrupt is kinda like a subroutine: it ends with a Return, and if you don't, it'll just keep calling it over and over until it crashes.
Title: Re: Another noob question. this time about interrupts
Post by: Broseph Radson on January 18, 2011, 08:07:15 pm
Oh so something like
Code: [Select]
fnInt(S,0)
ClrHome
"A->A
Lbl 1
Disp A
Repeat getKey(15)
If C
0->C
Goto 1
End
End

FnOff //to be safe
LnReg
Return

Lbl S //Interrupt subroutine
getKey(54)->C
Return

Also, can i call a regular subroutine from within an interrupt like
Code: [Select]
Lbl S //interrupt
If getKey(54)
sub(AB)
End
Return

?

EDIT:
Just tried both methods. Neither one worked.
Title: Re: Another noob question. this time about interrupts
Post by: Deep Toaster on January 18, 2011, 08:49:20 pm
Why do you need the getKey() in the interrupt though? It's a lot easier if it's just in the program loop.
Title: Re: Another noob question. this time about interrupts
Post by: Broseph Radson on January 18, 2011, 08:50:12 pm
Something like a teacher key where i can press it anywhere in the program and it works. Saves space in exchange for slightly less speed.
Title: Re: Another noob question. this time about interrupts
Post by: Deep Toaster on January 18, 2011, 08:54:52 pm
Well an interrupt is basically like a sub( that the calculator is forced to call every once in a while. So if you do something like

Code: (Axe) [Select]
:Lbl I
:Return
:...
:Lbl S . Interrupt
:If getKey(54)
:Goto I

all that the Return in Lbl I does is return from the subroutine, back to the program.

If you call I instead of using Goto , as in

Code: (Axe) [Select]
:Lbl I
:Return
:...
:Lbl S . Interrupt
:If getKey(54)
:sub(I)
:Return

the Return in Lbl I returns to the subroutine, which returns to the main program.
Title: Re: Another noob question. this time about interrupts
Post by: Broseph Radson on January 18, 2011, 09:05:32 pm
Code: [Select]
ClrHome
fnInt(S,0)
sub(A)

Repeat getKey(15)
End

FnOff
LnReg
Return

Lbl A
Disp 123>Dec
Disp i //imaginary i
Return

Lbl S
If getKey(54)
sub(A)
End
Return

It still doesnt register that im pressing 2nd
Title: Re: Another noob question. this time about interrupts
Post by: Broseph Radson on January 19, 2011, 01:16:11 pm
*bumpity*
Title: Re: Another noob question. this time about interrupts
Post by: Quigibo on January 19, 2011, 06:54:21 pm
It looks correct, I don't see any errors.  The only thing I can can think of is that maybe the Disp command cannot be used with custom interrupts because it uses an OS routine but I kind of doubt that.
Title: Re: Another noob question. this time about interrupts
Post by: Broseph Radson on January 19, 2011, 07:21:30 pm
It works with disp i believe. The same program using a timer instead of keypresses works fine, but when i make it wait for a keypress instead of just incrementing a number on each interrupt, it stops working. It reads the clear key fine and breaks the Repeat when i press it. Maybe a bug? EDIT: it appears that its not the keypress thats the problem, its that interrupts cant call subroutines. Man this is confusing
Title: Re: Another noob question. this time about interrupts
Post by: Binder News on January 19, 2011, 08:28:56 pm
How about:
Code: [Select]
//Main loop
ReturnIf A=-1
...
Lbl S
If getkey(54)
-1->A
End
Return
Title: Re: Another noob question. this time about interrupts
Post by: Broseph Radson on January 19, 2011, 08:49:55 pm
The only problem with that is that you still have to test for the keypress in every loop, just indirectly. Im trying to make it so you dont have to test for it in any loops, it just automatically tests for it.
Title: Re: Another noob question. this time about interrupts
Post by: Binder News on January 19, 2011, 11:28:14 pm
Here is the ASM to add in:
Code: [Select]
Asm(E1)
This will pop the last entry off the stack. This way, if it returns, it will return to the original address, I think.
Archive the source before trying. If Quigibo had Axe push something extra onto he stack, then it will be a problem.