Hello,
I assume that your "spaghetti code" is actually written in assembly language. Is this correct? It is not entirely clear whether your problem is that interrupts become globally enabled when they should not, or whether interrupts are being globally disabled and not re-enabled. (Setting the I-bit disables interrupts.)
A common cause for interrupts to become enabled when they should not might be due to interrupts being disabled within a sub-routine. The software author then assumes that interrupts were previously enabled, so erroneously re-enables interrupts prior to exiting the sub-routine. Be wary of the use of any CLI instructions within the code. Apart from the enabling of interrupts during initialisation, I presume that there would be little need for use of the instruction.
If interupts need to be temporarily disabled within a sub-routine, the method I would normally use would be -
TPA
PSHA ; Status register value to stack
SEI ; Disable interrupts
; Critical code here
PULA
TAP ; Restore prior state
I guess that you will need to write the special test code for de-bugging as a macro, and then selectively incorporate the macro within each sub-routine, just prior to exiting.
Regards,
Mac