User Tools

Site Tools


base:decrease_x_register_by_more_than_1

Differences

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

Link to this comparison view

Next revision
Previous revision
base:decrease_x_register_by_more_than_1 [2015-04-17 04:31] – external edit 127.0.0.1base:decrease_x_register_by_more_than_1 [2017-03-30 12:44] (current) ftc
Line 12: Line 12:
 </code> </code>
  
-This procedure takes 8 cycles (and 5 bytes in mem). If the value of the carry flag is always known at this point in the code, it can be removed and the snippet would then take 6 cycles (and 4 bytes in mem). However, there is another way to do it. You can use the illegal opcode SBX (sometimes called AXS). It operates like this:+This procedure takes 8 cycles (and 5 bytes in mem). If the value of the carry flag is always known at this point in the code, the SEC instruction can be removed and the snippet would then take 6 cycles (and 4 bytes). However, there is another way to do it. You can use the illegal opcode SBX (sometimes called AXS). It operates like this:
  
   - AND X with A and put result in X   - AND X with A and put result in X
Line 40: Line 40:
  
 Another property of the SBX opcode is that it doesn't respeect the decimal mode, since it is derived from CPX rather than SBC. So if you need to perform table lookups and arithmetic in a tight interrupt routine there's no need to clear the decimal flag in case you've got some code running that operates in decimal mode. Another property of the SBX opcode is that it doesn't respeect the decimal mode, since it is derived from CPX rather than SBC. So if you need to perform table lookups and arithmetic in a tight interrupt routine there's no need to clear the decimal flag in case you've got some code running that operates in decimal mode.
 +
 +====== Examples ======
 +
 +===== Fill sprite with vertical pattern (containing $ff, $bf, $7f, $3f) =====
 +
 +<code>
 +ldx #60
 +fs
 +lda #xx
 +sta spr+o0,x
 +lda #yy
 +sta spr+o1,x
 +lda #$ff or $bf or $7f or $3f
 +sta spr+o2,x
 +axs#3
 +bpl fs
 +rts
 +</code>
 +
 +where o0,o1,o2 is an excluding choice of {0,1,2}.
 +On one column of the sprite a must contain $ff, $bf, $7f or $3f, because if it is anded with the value of the x reg, x must be preserved. As x runs from 60 to 0 (where 63 is $3f) this is only the case for these four values.
  
 ===== Info on SBX/AXS on external sites ===== ===== Info on SBX/AXS on external sites =====
   * [[http://unusedino.de/ec64/technical/aay/c64/bsbx.htm|Ninjas reference]]   * [[http://unusedino.de/ec64/technical/aay/c64/bsbx.htm|Ninjas reference]]
   * [[http://www.oxyron.de/html/opcodes02.html|Grahams reference]]   * [[http://www.oxyron.de/html/opcodes02.html|Grahams reference]]
base/decrease_x_register_by_more_than_1.1429237883.txt.gz · Last modified: 2015-04-17 04:31 by 127.0.0.1