Changes

Programming:Fast Sprites

67 bytes removed, 23:26, 6 May 2007
/* Fast Sprites */ - Removed DB #DD and DB #FD to use HX,LX etc
AND (HL):INC H:OR (HL):DEC H
LD (DE),A:INC E
DB #DD:DEC HHX
JR NZ,dobyte</pre>
<pre>LD A,E
DB #DD:SUB LLX
LD E,A</pre>
The only thing left to do now is continue the loop for each row, depending on where you stored your loop counter(s), this could be as simple as:
<pre>DB #FD:DEC HHY
JR NZ,dobyte</pre>
<pre>;Entry: BC = Sprite address, D = width, E = height, HL = screen address
DB #DD:LD LLX,D ;LX = widthDB #FD:LD HHY,E ;HY = height
EX DE,HL
LD H,andmasks / 256
.rowloop
DB #DD: LD HHX,L LX ;HX <= width
.dobyte
LD A,(BC):INC C
AND (HL):INC H:OR (HL):DEC H
LD (DE),A:INC E
DB #DD:DEC HHX
JR NZ,dobyte
DB #FD:DEC HHY
RET Z
LD A,E
DB #DD:SUB LLX
LD E,A
LD A,D
At the start of the code, pass in the clipped width in E, and the sprite width in A for example:
<pre>SUB E:DB #FD:LD LLY,A ;LY = sprite width - displayed width</pre>
Then at the end of the loop (just after <code>RET Z</code>):
<pre>LD A,C:DB #FD:ADD LLY:LD C,A</pre>
'''One last thought'''
151
edits