Z80 Interrupts, I and R register

The R register

The R register is used for memory refresh. It is increased after each instruction, whereby the CB, DD, ED, FD, DDCB and FDCB prefixes are viewed as separate instructions. Bit 7 is never changed by this increasing but it can be changed with LD R,A.

The LDIR, LDDR increase the R register by two times BC, etc. In LD A,R and LD R,A the R register is first increased before being read or written too.

Generating a maskable interrupt increases the R register by 1.

DAA

Okay, this is my theory so far:

if (F AND 2) ; sub

 if (A >= 09ah) or carry(set) then A=A-60h

 if ( (A AND 15) >= 9) or halfcarry(set) then A=A-6

else ; add

 if (A >= 09ah) or carry(set) then A=A+60h

 if ( (A AND 15) >= 9) or halfcarry(set) then A=A+6

endif

Interrupts

There are two flags used for interrupts: IFF1 and IFF2. The state of these two flags is:

		IFF1	IFF2

/reset		0	0

EI		1	1

DI		0	0

/INT		0	0

/NMI		0	IFF2

RETN		IFF2	IFF2

IFF1 determines whether or not maskable interrupts are excepted. IFF1 can't be read, but IFF2 can be with LD A,R and LD A,I.

Interrupt Modes

IM 0

The device that generates the interrupt also provides an one byte opcode, which is executed. RST instructions are used.

IM 1

A call is made to 38h.

IM 2

A call is made to an address read from register I x 256 + byte from device.

MSX Specific

On a MSX, NMI are not supported; they never occur. Because of this, the two interrupt flip-flops always have the same state.

The only device that generates an interrupt on a MSX is the VDP. It always provides value FFh (=RST 38h) so the MSX effectively operates the same in IM 0 as in IM 1. In IM 2, a call is made to an address read from register I x 256 + FFh.


This page is maintained by Sean Young.