[A83] Re: shadow registers


[Prev][Next][Index][Thread]

[A83] Re: shadow registers




Actually, that's not entirely correct.

The shadow registers are a second set of registers that "shadow" the regular
registers.  They are written as the normal register name followed by a
single quote.  The following is a list of the shadow registers:

AF', BC', DE', HL'

There is no shadow register for the stack pointer, or index registers (IX
and IY).  Shadow registers are useful for saving the state of the regular
registers during an interrupt, but they are very useful for other things,
and do not have to be used for this purpose.  You cannot access the shadow
registers directly.  You must first exchange them with the regular
registers.  Alternate registers is probably the more formal term for the
shadow registers.  There are two instructions to deal with the shadow
registers:

exx -- exchange BC <-> BC', DE <-> DE', and HL <-> HL'
ex af,af' -- exchange AF <-> AF'

The interrupt routine must exchange the registers at the start and end of
the routine if it wants to use them.  It can be useful to use a custom
interrupt routine that uses the stack to save the registers (push/pop), so
that you can use the shadow registers in your program.

The following example is the inner loop of a tile map routine.  You don't
need to understand it, but it demonstrates the use of the shadow registers
in non interrupt code.  The routine would be much slower if it were not for
the shadow registers:

; b   = msb of map sprites for row
; hl  = tile map start
; b'  = msb of left shift table for map
; de' = video buffer
; h'  = msb of right shift table for map

 ld c,(hl)  ; load map tile
 inc hl     ; next map tile
 ld a,(bc)  ; load map sprite
 exx
 ld l,a     ; point to right shifted byte
 ld a,(bc)  ; load left shifted byte from previous tile
 ld c,l     ; point to this byte in left shift table for next time
 or (hl)    ; combine with right shifted byte
 ld (de),a  ; write left byte to video buffer
 inc e      ; next video buffer position
 exx

> >Where are the shadow registers? Also on the Z80 itself??
> >And what is the use for them??
>
> They are a part of the z80 itself, and is used for interrupts.
> When an interrupt occours, the z80 switches place of the shadow regs and
> the regular regs so all their contents is saved until the interrupt
finishes.
> Therefore you have to disable interrupt if you want to use them in your
> program.






References: