User Tools

Site Tools


base:use_shy_as_sty_abs_x

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
base:use_shy_as_sty_abs_x [2017-11-16 01:26] cruzerbase:use_shy_as_sty_abs_x [2017-11-16 01:38] (current) cruzer
Line 1: Line 1:
-====== Using SHY as sta abs,y ======+====== Using shx/shy as stx,y/sty,======
  
-The 6510 doesn't have a sty abs,x. So instead you would normally do something like this:+The 6510 doesn't have a stx abs,y or sty abs,x. So instead you would normally do something like this:
  
 <code> <code>
-tay+//store X indexed by Y: 
 +txa 
 +sta address,y 
 + 
 +//store Y indexed by X: 
 +tya
 sta address,x sta address,x
 </code> </code>
  
-Which takes 7 cycles. But instead you can do this, which only takes 5:+Which each take 7 cycles. But instead you can do this, which only takes 5:
  
 <code> <code>
 +//store X indexed by Y:
 +shx address,y
 +
 +//store Y indexed by X:
 shy address,x shy address,x
 </code> </code>
  
-However, there's a little catch. The value is and'ed with the high byte of the address. And to make it even more confusing, it's actually the high byte + 1. So if you store it in $fe00, the value is and'ed with $ff, and therefore unaffected. But since you don't always use all the 8 bits, other addresses might work as well. E.g. if your values are C64 colors, which are between $00 and $0f, the upper 4 bits don't matter. So in that case all pages ending in $e will work, i.e. $0e00, $1e00, etc.+However, there's a little catch. The value is and'ed with the high byte of the address before it's stored. And to make it even more confusing, it's actually the high byte + 1. So if you store it in $fe00, the value is and'ed with $ff, and therefore unaffected. But since you don't always use all the 8 bits, other addresses might work as well. E.g. if your values are C64 colors, which are between $00 and $0f, the upper 4 bits don't matter. So in that case all pages ending in $e will work, i.e. $0e00, $1e00, etc
 + 
 +The opcodes are classified as unstable, but this only affects the and'ing. So sometimes the original X/Y value is stored, and sometimes it's and'ed first. But if you use value/address combinations where the and'ing doesn't matter, the result is always the same.
  
base/use_shy_as_sty_abs_x.txt · Last modified: 2017-11-16 01:38 by cruzer