Page 1 of 1

Z80 interrupt sequence

Posted: Wed Jun 13, 2018 10:36 am
by dfzx
If I have code which logically looks like this:

Code: Select all

isr()
{
  stuff..
}

main()
{
...
 x=0
 halt
 x=1
...
}
am I guaranteed that 'stuff' will be called and execute to completion before x goes to 1?

My reading of the Z80 manual says that it will, but I'm not sure the halt and interrupt response parts are crystal clear in my head. :)

Re: Z80 interrupt sequence

Posted: Wed Jun 13, 2018 11:39 am
by Joefish
No.

But if you did:

EI
HALT

then 'Yes'. But that's being pedantic.
You can do the EI at the very end of your ISR to re-enable the next interrupt. Most people write like this.
(If you do HALT with interrupts disabled then you lock up the machine!)
So if your ISR always does EI then RET at the end, then the answer is 'Yes'. You can just use HALT whenever you like.

Some people though simply have the ISR do a RET and nothing else. It exists solely for timing. This is for people writing games where their whole code timing is super-critical. Therefore you have to do EI before HALT when you want it to happen.

Re: Z80 interrupt sequence

Posted: Wed Jun 13, 2018 12:58 pm
by dfzx
Joefish wrote: Wed Jun 13, 2018 11:39 am So if your ISR always does EI then RET at the end, then the answer is 'Yes'. You can just use HALT whenever you like.
Yes, the ISR re-enables the interrupt when it exits. So, all good, thanks. :)