R Register Update

페이지 1/2
| 2

By realpeterjack

Champion (417)

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 or 등록 to post comments

By anonymous

incognito ergo sum (116)

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

By realpeterjack

Champion (417)

realpeterjack의 아바타

27-09-2005, 22:59

Thanks, msd (that was fast!).

By norakomi

Paragon (1133)

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) ???

By Tanni

Hero (556)

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.

By ro

Scribe (4817)

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

By norakomi

Paragon (1133)

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??

By marison

Expert (104)

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.

By ro

Scribe (4817)

ro의 아바타

28-09-2005, 14:58

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

By norakomi

Paragon (1133)

norakomi의 아바타

28-09-2005, 15:24

haha, thats cool....

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

cool
thanx

By marison

Expert (104)

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.

페이지 1/2
| 2