I was dicking about with an IM2 interrupt in C using z88dk. I wanted to return to BASIC leaving my interrupt routine running, but z88dk doesn't support that. (It restores IM1 when returning to BASIC from C.) It's a simple-ish change to add support to the framework, but I discovered I really didn't understand the relationship between the Spectrum BASIC interrupt handler at 0x0038 and the IY register. The fix Alcoholics Anonymous gave me on the z88dk forum was, at the end of my ISR, to load IY with 0x5c38, then call 0x0038, then return. I have no doubt he'll be right, but... why?
I was looking at the Spectrum ROM disassembly book, and I see in there:
Code: Select all
LD IY,+5C3A IY holds +ERR-NR always.
but searching for "IY" in the rest of the book yields nothing. Um, eh? IY is set but never read or referenced? That can't be right. I must be missing something.
So I sort of understand. The BASIC ISR (and possibly the entire BASIC system?) expects IY to always hold the value 0x5c3a, so restoring it to that value before calling the BASIC ISR would clearly be the right thing to do. But why is IY needed to point to the ERR NR system variable and why doesn't it appear to be dereferenced in the Spectrum ROM?