Author Topic: How to stop interrupts being disabled after exiting app?  (Read 3555 times)

0 Members and 1 Guest are viewing this topic.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
How to stop interrupts being disabled after exiting app?
« on: January 08, 2014, 10:14:43 pm »
I was trying to figure out why the calculator kept on freezing after Bad Apple finished, and it turns out iff1 and iff2 were disabled. I enable interrupts and set the interrupt mode to 1 immediately before doing bjump(_JForceCmdNoChar). iff1 and iff2 are enabled when that happens, but sometime after the bjump, the interrupts get disabled. What is going on here?

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: How to stop interrupts being disabled after exiting app?
« Reply #1 on: January 08, 2014, 10:17:06 pm »
You probably need to set interrupt mode to 1, THEN enable interrupts again, not the other way around.

You also need to disable the crystal timers. The OS interrupts requires one of them, I think. Also, did you reset the normal interrupts?

NOTE: This post was edited too many times shortly after the initial post. I really need to collect my thoughts better.
« Last Edit: January 08, 2014, 10:19:02 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: How to stop interrupts being disabled after exiting app?
« Reply #2 on: January 08, 2014, 10:22:13 pm »
I am already doing im 1 first and then ei. The crystal timers are disabled by writing 0 to ports $30-$38, and the regular interrupts are restored by writing $0B to port $03.

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: How to stop interrupts being disabled after exiting app?
« Reply #3 on: January 08, 2014, 10:24:27 pm »
Posting the relevant parts of the code may help. Also, posting how you set up the interrupt may also be helpful.
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: How to stop interrupts being disabled after exiting app?
« Reply #4 on: January 08, 2014, 10:25:27 pm »
This code will fix the interrupts. If it crashes after this, interrupts are not the issue. Also, you don't need to enable interrupts when you quit, the OS takes care of that for you.

Code: [Select]
di
im 1
ld a, $0B
out (03), a
xor a
out ($31), a
out ($34), a
out ($37), a
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: How to stop interrupts being disabled after exiting app?
« Reply #5 on: January 08, 2014, 10:31:21 pm »
Setting up the interrupts:
Code: [Select]
;set up interrupt vector table from $9900 to $9A00 to always go to $9A9A
ld hl, $9900
ld b, 0
ld d, $9A
IvtLoop:
  ld (hl), d
  inc hl
  djnz IvtLoop
  ld (hl), d
Code: [Select]
;disable all other interrupts
  ld a, %01000
  out ($03), a

Code: [Select]
ld a, $99
  ld i, a
  im 2
  ei
Cleanup:
Code: [Select]
di
  ;turn off timers
  ld a, 0
  out ($30), a
  out ($31), a
  out ($32), a
  out ($33), a
  out ($34), a
  out ($35), a
  out ($36), a
  out ($37), a
  out ($38), a
  ;restore regular interrupts
  ld a, 0
  out ($03), a
  ld a, $0B
  out ($03), a
  ;set LCD to row auto increment
  ld a, $05
  call LCD_BUSY_QUICK
  out ($10), a
  ;set CPU to 6MHz
  ld a, 0
  out ($20), a
  ;statVars was used to store code, so it needs to be invalidated
b_call _DelRes
  ;enable auto power down
set apdAble,(IY+apdFlags)
im 1
ei
bjump(_JForceCmdNoChar)

EDIT: Tried thepenguin77's code, and it looks like interrupts are not the problem.
« Last Edit: January 08, 2014, 10:37:18 pm by fb39ca4 »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: How to stop interrupts being disabled after exiting app?
« Reply #6 on: January 10, 2014, 09:46:42 am »
Are you doing any RAM page swapping or stack pointer manipulation?