Z80 interrupt sequence

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

Z80 interrupt sequence

Post 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. :)
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
User avatar
Joefish
Rick Dangerous
Posts: 2042
Joined: Tue Nov 14, 2017 10:26 am

Re: Z80 interrupt sequence

Post 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.
dfzx
Manic Miner
Posts: 673
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Z80 interrupt sequence

Post 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. :)
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Post Reply