Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Z80 Register Question

Reply to topic
Author Message
Consolemu
  • Guest
Reply with quote
Z80 Register Question
Post Posted: Thu Apr 13, 2000 2:47 am
In my book, I saw a table that talked about a thing called "shadow registering" which involves bank switching...

BANK 0......BANK 1
[A][F]......[`A][`F]
[B][C]......[`B][`C]
[D][E]......[`D][`E]
[H][L]......[`H][`L]
[ IX ]
[ IY ]
[ SP ]
[ PC ]
[R][V]

It said something like the Z80 can switch between banking modes, enabling itself to have 8 extended or "shadow registers". Would someone mind colaborating on this for me? I'm curious as to how it works.

Chris :o)
 
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Post Posted: Thu Apr 13, 2000 7:32 am
Quote
> In my book, I saw a table that talked about a thing called "shadow registering" which involves bank switching...
>
> BANK 0......BANK 1
> [A][F]......[`A][`F]
> [B][C]......[`B][`C]
> [D][E]......[`D][`E]
> [H][L]......[`H][`L]
> [ IX ]
> [ IY ]
> [ SP ]
> [ PC ]
> [R][V]
>

> It said something like the Z80 can switch between banking modes, enabling itself to have 8 extended or "shadow registers". Would someone mind colaborating on this for me? I'm curious as to how it works.

They are just additionnal registers which are not directly usable.
EXchange functions allow you to exchange them with the standard ones, and that's it.
No "bank switching" involved.
Quote
> Chris :o)
  View user's profile Send private message Visit poster's website
Consolemu
  • Guest
Reply with quote
That's it?
Post Posted: Thu Apr 13, 2000 7:11 pm
That's all it is? Man, this book sucks in some areas and in others is like a message from God. Why did they talk about all this other "shadow registering" and stuff? Why couldn't they just tell me like you told me? I guess this guy probably works for Microsoft now...

Chris :o)
 
  • Site Admin
  • Joined: 25 Oct 1999
  • Posts: 2029
  • Location: Monterey, California
Reply with quote
Re: That's it?
Post Posted: Thu Apr 13, 2000 8:18 pm
Quote
> That's all it is? Man, this book sucks in some areas and in others is like a message from God. Why did they talk about all this other "shadow registering" and stuff? Why couldn't they just tell me like you told me? I guess this guy probably works for Microsoft now...

Well the shadow registers can be useful as time savers.

They can be used as an alternate registers that are only used during interrupt processing. Rather than pushing all registers to the stack, you can swifty exchange them with just a couple 4-cycle instructions, and restore them with the same instructions. Extra bonus: The values you keep in the shadow registers are still there for the next interrupt. This isn't particularly useful if your program only uses v-blanks, however, if you have a lot of complicated h-blank processing, the shadow registers are an excellent time saver. The h-blank period is very short, and the less time you spend pushing old registers and looking up variable values from memory, the quicker you can dump your data to ports and let the CPU get back to it's other tasks.
One trick I used ona previous never-released demo I was working on (I never got it working right, since I didn't quite understand how the sms implements line interrupts before) Is I made sure that the shadowed hl always pointed to the address of the next vertical or horizontal blank handler on the list that I needed. When the maskable (v/hblank) interrupt happened, I'd just exchange with the shadow regs immediately, and jump to the contents of hl ( jp (hl) is only 4 cycles, the z80's fastest branch instruction)). So it would go something like this

.org $0038 ;the interrupt vector for both vblanks and hblanks
exx ;exchanges bc,de, and hl for bc',de', and hl'
ex af,af' ;just what it looks like
;both the above instructions took only 8 cycles, compared with, I think, 40 or 44 cycles for four push instructions.
jp (hl) ;just 4 cycles, and I didn't have to look up any variables or do any costly comparisons to find out where to go


VBlankHandler:
[do vblank stuff]
[Set VDP to interrupt when we;'re 1/3 of the way down the screen]
ld hl,FirstHBlankHandler ;On the next interrupt, we'll jump straight there
exx
ex af,af' ;restores the regs, again in just 8 cycles
ei
ret ;anyone know precisely why sms carts never use reti?

FirstHBlankHandler:
[do raster effect #1]
[Set VDP to interrupt at 2/3s of the way down the screen]
ld hl,SecondHBlankHandler ;go straight there next
exx
ex af,af'
ei
ret

SecondHBlankHandler:
[do raster efect #2]
[set VDP not to interrupt until next vblank]
ld hl,VBlankHandler
exx
ex af,af'
ei
ret


Definately a time saver.
Of course, if you use the shadow registers in the interrupts like that, you can't use them in your main code, unless you disable interrupts.
  View user's profile Send private message Visit poster's website
  • Joined: 18 Sep 1999
  • Posts: 498
  • Location: Portland, Oregon USA
Reply with quote
Re: That's it?
Post Posted: Thu Apr 13, 2000 8:31 pm
Quote
> > That's all it is? Man, this book sucks in some areas and in others is like a message from God. Why did they talk about all this other "shadow registering" and stuff? Why couldn't they just tell me like you told me? I guess this guy probably works for Microsoft now...

> Well the shadow registers can be useful as time savers.

> They can be used as an alternate registers that are only used during interrupt processing.

In fact, according to what I've read, these registers were provided for exactly that reason (for use by interrupt handlers to quickly save processor state).

Eric Quinn
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!