Hello there everyone!

I had one quick question concerning this sprite routine that I found.


Code:
add   a,a
   add   a,a
   ld   (_JumpMASK),a

_LoopMASK:
   pop   de
   xor   a
   ld   c,d
   ld   d,a
   dec   a
   ex   de,hl
_JumpMASK   =$+1
   jr   $
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   ex   de,hl
   and   (hl)
   xor   d


Basically, I would like to do this part of the routine, but without the SMC. I have already tried using a djnz loop, but that included many pushes and pops, so I was wondering if any of you had any better ideas. Thanks!
Where's the rest of the routine? It's somewhat important to know what registers are what and available for use.
Runer112 wrote:
Where's the rest of the routine? It's somewhat important to know what registers are what and available for use.


Sorry, I probably should have cleared some stuff up first. I am not really concerned about the routine itself, I was wondering about the jump amount. Is there a faster way to do a jump without SMC rather than having to go through a loop? For instance, is it possible to construct something like this opcode in z80, even though it does not actually exist?


Code:
jr a    ; jumps the amount specified in register a


EDIT: I think that the opcode jp (hl) may be of some use, but this does not preserve register hl: Is there a better way?


Code:
ld hl,Jump
ld d,0
ld e,a
add hl,de
jp (hl)
Jump:
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl
   sll c \  rla \  add hl,hl


Thanks!
If the ix or iy regsiter is available, you can use jp (ix) or jp (iy). Besides jp (hl) and SMC, the only other way to perform a variable jump that comes to mind is to get the jump destination in any 16-bit register, push it onto the stack, and then return.
Runer112 wrote:
If the ix or iy regsiter is available, you can use jp (ix) or jp (iy). Besides jp (hl) and SMC, the only other way to perform a variable jump that comes to mind is to get the jump destination in any 16-bit register, push it onto the stack, and then return.


Okay, thanks! I do like paring both of those ideas, such as pushing ix and using ret. Thanks again!
Well if you have the destination in ix, it's better to just use jp (ix). The push/ret tactic is mainly useful for emulating jp (bc) and jp (de), or if you're really crazy, jp (af).

EDIT: And just a quick note to make sure the misnomer hasn't confused you or anyone else reading this, the jp (hl) instruction (and index register friends) jump to the destination held in the 16-bit register itself. The fact that the register name is in parentheses, which suggests indirection, is due to the instruction being misnamed by Zilog.
Pushing ix and ret'ing is going to be slower and larger than pushing a non-index register. Also, in your version you also need to multiply a by 4 Wink
Runner112 wrote:

Well if you have the destination in ix, it's better to just use jp (ix). The push/ret tactic is mainly useful for emulating jp (bc) and jp (de), or if you're really crazy, jp (af).

EDIT: And just a quick note to make sure the misnomer hasn't confused you or anyone else reading this, the jp (hl) instruction (and index register friends) jump to the destination held in the 16-bit register itself. The fact that the register name is in parentheses, which suggests indirection, is due to the instruction being misnamed by Zilog.


Ah, so I need parentheses... silly me. Thanks! As I recall, Kerm did post a topic about this about how jp hl could get mistranslated as a label. Fun with z80...

chickendude wrote:
Pushing ix and ret'ing is going to be slower and larger than pushing a non-index register. Also, in your version you also need to multiply a by 4 Wink


That is true; I will probably just end up doing a jp (ix) as I would like to perserve the hl register.
Another thing to keep in mind is the exx instruction. If interrupts are off, don't be afraid to use the shadow registers. The exx instruction swaps bc, de, and hl with their shadow counterparts, it takes one byte and only 4 t-states, more than twice as fast as a push/pop (plus it swaps all three, not just one). If you need to pass something through to the shadow registers you can use a or an index register. Another bonus is that you can jump out of it without messing up the stack. There's also ex af,af', which just swaps out af and its shadow register.
chickendude wrote:
Another thing to keep in mind is the exx instruction. If interrupts are off, don't be afraid to use the shadow registers. The exx instruction swaps bc, de, and hl with their shadow counterparts, it takes one byte and only 4 t-states, more than twice as fast as a push/pop (plus it swaps all three, not just one). If you need to pass something through to the shadow registers you can use a or an index register. Another bonus is that you can jump out of it without messing up the stack. There's also ex af,af', which just swaps out af and its shadow register.


Thanks! That sounds pretty handy... I'll try and see if I can work it in somehow. Very Happy
One point to highlight would be that you can overuse SMC. Whereas it can provide you with speed/size optimisations, sometimes it isnt the most appropriate solution.

That said, play with it and play plenty - it can lead to some serious (although not app-compatible) optimisations!
Though you can always load routines that need the speed into saferam when writing an app Wink
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement