Author Topic: Another noob question. this time about interrupts  (Read 5563 times)

0 Members and 1 Guest are viewing this topic.

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Another noob question. this time about interrupts
« 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?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Another noob question. this time about interrupts
« Reply #1 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.
« Last Edit: January 18, 2011, 08:51:24 pm by Deep Thought »




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #2 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.
« Last Edit: January 18, 2011, 08:17:59 pm by Broseph Radson »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Another noob question. this time about interrupts
« Reply #3 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.




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #4 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.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Another noob question. this time about interrupts
« Reply #5 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.




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #6 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
« Last Edit: January 18, 2011, 09:06:08 pm by Broseph Radson »

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #7 on: January 19, 2011, 01:16:11 pm »
*bumpity*

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: Another noob question. this time about interrupts
« Reply #8 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.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #9 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
« Last Edit: January 19, 2011, 07:32:13 pm by Broseph Radson »

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #10 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
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #11 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.

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: Another noob question. this time about interrupts
« Reply #12 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.
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results: