R Register Update

Página 1/2
| 2

Por realpeterjack

Champion (417)

Imagen del realpeterjack

27-09-2005, 22:48

Hello! This is my first post to the forum, an I have a question about the Z80 refresh register update: is it updated at the execution of each instruction or at each "memory fetch" (this means that the R register would be increased by 2 for 2 byte instructions, 3 for three byte instructions, and so on). The documentation I have is not very clear about this, and for different Z80 emulators I tested, the behaviour varies.

Thanks in advance.

Login sesión o register para postear comentarios

Por anonymous

incognito ergo sum (116)

Imagen del anonymous

09-05-2012, 23:18

IIRC it's increased after each instruction. You could download the z80 manual from www.zilog.com and also lot's of info can be found on www.z80.info

Por realpeterjack

Champion (417)

Imagen del realpeterjack

27-09-2005, 22:59

Thanks, msd (that was fast!).

Por norakomi

Paragon (1125)

Imagen del norakomi

28-09-2005, 08:04

That gives me the next question.

I've never directly used R or I in my programming.....
Could someone give me an example of when to use them??
And the same for SP (when do you use the SP, next to the push and pop instructions) ???

Por Tanni

Hero (556)

Imagen del Tanni

28-09-2005, 11:01

You can use the refresh register to get a new seed value for random number generation. I don't know about I register. The Stack Pointer (SP) is automatically updated by push and pop instructions. You can locate the stack on another memory location by reloading the SP.

Por ro

Scribe (4714)

Imagen del ro

28-09-2005, 11:11

SP is also a great help on debugging. Just start your asm by SAVING SP and exiting with LOADING SP again, that way you'll be sure to return to your programming environment.

e.g.

run: ld (spsave),sp
call routine
call routine
blabla
.
.
ld sp,(spsave)
ret

If you got any STACK fuckups during your program you will hardly notice.

Also, moving the STACK (by assigning a new value to SP) can do some wonders. Why? dunno. figure it out Smile

Por norakomi

Paragon (1125)

Imagen del norakomi

28-09-2005, 12:15

You can use the refresh register to get a new seed value for random number generation.
could you give an example??
do you load R into A or something??
or can R be used as an extra storage??

Por marison

Expert (104)

Imagen del marison

28-09-2005, 12:17

@Tanni

In this topic http://www.msx.org/forumtopic4941.html you could see a good example of random number generator.

Por ro

Scribe (4714)

Imagen del ro

28-09-2005, 14:58

LD A, R will give ya a "random" number. it's that simple

Por norakomi

Paragon (1125)

Imagen del norakomi

28-09-2005, 15:24

haha, thats cool....

a random number from 0 to 255 i suppose !!!

cool
thanx

Por marison

Expert (104)

Imagen del marison

28-09-2005, 16:00

@ro

R register usage as a random number is a poor solution. If used in sequence you get numbers in sequence too (with few jumps).

If you use the R register to determine a angle of some enemies movement, each successive enemy will have angles in sequence, always bigger than the last.

Página 1/2
| 2