Z80 interrupt sequence

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
dfzx
Dizzy
Posts: 81
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Z80 interrupt sequence

Post by dfzx » Wed Jun 13, 2018 9:36 am

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. :)
0 x

Joefish
Manic Miner
Posts: 223
Joined: Tue Nov 14, 2017 10:26 am

Re: Z80 interrupt sequence

Post by Joefish » Wed Jun 13, 2018 10:39 am

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.
0 x

dfzx
Dizzy
Posts: 81
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Z80 interrupt sequence

Post by dfzx » Wed Jun 13, 2018 11:58 am

Joefish wrote:
Wed Jun 13, 2018 10: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. :)
0 x

Post Reply