User Tools

Site Tools


base:advanced_optimizing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
base:advanced_optimizing [2022-12-09 14:34] – [Executable parameters] bitbreakerbase:advanced_optimizing [2022-12-09 14:47] – [Shifting] bitbreaker
Line 752: Line 752:
  
 This way bit 7 is copied to carry first and then shifted in on the right end again. This way bit 7 is copied to carry first and then shifted in on the right end again.
 +
 +If you deal with chars, you often need numbers divided by 8, this also includes numbers bigger than 8 bits, as the screen is 320 pixels wide. If you include clipping you might even span over a bigger range.
 +An easy way to shift 11 bits to a final 8 bit results without having to deal with two different bytes being shifted independently, is the following:
 +
 +<code>
 +        lda xhi        ;00000hhh
 +        asr #$0f       ;000000hh h - might also be a lsr in case if no upper bits need to be clamped
 +        ora xlo        ;lllll0hh h
 +        ror            ;hlllll0h h
 +        ror            ;hhlllll0 h
 +        ror            ;hhhlllll 0
 +</code>
 +
 +As the least significant 3 bits are lost during the shift anyway, we place the bits for the highbyte there and rotate them back in on the left side, so all we need to shift then is a single byte. To make the rotation work, the highbyte needs to be preshiftet by one before the lowbyte is merged in. The only prerequisite of this method is, that the lowbyte must have least significant three bits cleared. 
 ====== Jumpcode ====== ====== Jumpcode ======
  
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker