Jump to content
IGNORED

How to waste a single cycle?


Steril707

Recommended Posts

I am into heavy kernal tweaking at the moment, and i am in the situation now that i need to waste a single cycle for my asymmetric mirrored Kernal.

 

I want to insert typical 7 cycle load store combi like

 

lda blop,x ;4

sta COLUPF1 ;3

 

into a space that needs 8 cycle to get burnt, so my PF2 gets loadad at the correct cycle later on.

 

That means, I need kind of a 8 cycle lda/sta instead of the example typical 7 cycle one...

 

Is there any trick to do that? I encounter these kind of situations a lot while tweaking kernals, would be a big help for me to know a solution to this.

Link to comment
Share on other sites

I am into heavy kernal tweaking at the moment, and i am in the situation now that i need to waste a single cycle for my asymmetric mirrored Kernal.

 

I want to insert typical 7 cycle load store combi like

 

lda blop,x ;4

sta COLUPF1 ;3

 

into a space that needs 8 cycle to get burnt, so my PF2 gets loadad at the correct cycle later on.

 

That means, I need kind of a 8 cycle lda/sta instead of the example typical 7 cycle one...

 

Is there any trick to do that? I encounter these kind of situations a lot while tweaking kernals, would be a big help for me to know a solution to this.

sta.w COLUPF1 = 4 cycles (why the 1 at the end?)

Link to comment
Share on other sites

That means, I need kind of a 8 cycle lda/sta instead of the example typical 7 cycle one...

 

As noted, most 3-cycle instructions can be turned into 4-cycle instructions with the addition of a ".w" to the opcode. That will suffice for most of the places where it's necessary to add an extra cycle to your code. The one place where things really get tricky is when there's a need for a four-cycle jump or branch. Branches across page boundaries take four cycles, but it's seldom practical to place things deliberately to cause that.

 

In some cases, especially if your code requires use of both the stack pointer and a byte of RAM as two temporary variables, you may be able to swap your use of the stack pointer and the temp ram byte so as to move instruction times a little so you either won't need a cycle or else can insert two. In other cases, especially with JMP's (as opposed to branches) you can insert before the JMP a copy of the code at the destination, and stick an extra cycle somewhere within that code.

 

Of course, if 6502 programming were easy it wouldn't be so much fun.

Link to comment
Share on other sites

I am into heavy kernal tweaking at the moment, and i am in the situation now that i need to waste a single cycle for my asymmetric mirrored Kernal.

 

I want to insert typical 7 cycle load store combi like

 

lda blop,x ;4

sta COLUPF1 ;3

 

into a space that needs 8 cycle to get burnt, so my PF2 gets loadad at the correct cycle later on.

 

That means, I need kind of a 8 cycle lda/sta instead of the example typical 7 cycle one...

 

Is there any trick to do that? I encounter these kind of situations a lot while tweaking kernals, would be a big help for me to know a solution to this.

sta.w COLUPF1 = 4 cycles (why the 1 at the end?)

 

The 1 is just a typo...

 

Thanks guys...You rock!!!

Link to comment
Share on other sites

Another alternative (when you don't even have the spare byte to waste) is to shuffle the instructions a bit...swapping a 2-cycle instruction before the critical spot with a 3-cycle instruction that follows it. It's true that this is only possible some of the time (regarding on how dependant the critical spot is on preceding instructions), but it's something to look at if coding is getting really tight.

If a register at that point in the code is a known value, that would also work if it's value is greater than the address being stored to, without wasting a byte (e.g. STA COLUPF-X,X). Naturally, you'd need to work out COLUPF-X prior to assembly.

Link to comment
Share on other sites

  • 4 weeks later...
Just read the section on 'Wasting Cycles'. Beats the heck out of e.g. 17 NOP instructions just to burn 34 cycles.

 

But be sure to take some of the suggestions with necessary amounts of NaCl. A few have typos, and some have obvious side-effects which could easily be mitigated (e.g. LDA trashes the accumulator; CMP does not, but does trash flags) while others have side-effects that make them dangerous (e.g. if the value of X is unknown, CMP ($80,x) will waste six cycles but could potentially crash any bank-switching scheme (some with much greater probability than others).

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...