Jump to content
Sign in to follow this  
vdub_bobby

Loops with two counters

Recommended Posts

Here's my situation:

 

I am writing a (2600) kernel that uses Y to count scanlines but also uses X to count down as well.

 

So, the looping code looks something like this:

   dey                 ;+2   50

  tya                 ;+2   52
  cmp BlockChange,X   ;+4   56
  bne Kernel1Loopa    ;+2   58
  dex                 ;+2   60
  bpl Kernel1Loopb    ;+3   63

That takes 15 cycles. Is there a faster way?

Share this post


Link to post
Share on other sites
Here's my situation:

 

I am writing a (2600) kernel that uses Y to count scanlines but also uses X to count down as well.

 

So, the looping code looks something like this:

   dey                ;+2   50

  tya                ;+2   52
  cmp BlockChange,X  ;+4   56
  bne Kernel1Loopa   ;+2   58
  dex                ;+2   60
  bpl Kernel1Loopb   ;+3   63

That takes 15 cycles.  Is there a faster way?

887790[/snapback]

 

I'm not sure exactly how BlockChange works, but if you could extend it to have a separate entry for every scanline then you could combine X & Y as follows to save 3 cycles:

 

dey  	+2
bmi EndKernel  +2
lda BlockChange,Y	+4
bne KernelLoopa  +2
beq KernelLoopb  +2
EndKernel

 

Chris

Share this post


Link to post
Share on other sites

Hello,

 

Without understanding the relationship of the loopa and loopb labels to the flow of the kernel code its hard to recommend an optimization. Can you post the complete loop? Also is the BlockChange table stored in RAM or ROM?

 

Cheers!

Share this post


Link to post
Share on other sites
Hello,

 

Without understanding the relationship of the loopa and loopb labels to the flow of the kernel code its hard to recommend an optimization.  Can you post the complete loop?  Also is the BlockChange table stored in RAM or ROM?

 

Cheers!

888337[/snapback]

I don't really want to post the complete loop at this time, but the BlockChange table is stored in ROM.

 

I have come to a solution, though; thanks to everyone here (and on [stella] who helped).

 

Sorry, though - it isn't for a 2600 Prince of Persia. It is for something else...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...