Changes

Jump to: navigation, search

Programming:Fast Sprites

699 bytes added, 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'''
[[User:Executioner|Executioner]] 19:55, 12 July 2006 (CDT)
 
If you have enough memory, the fastest way to plot sprites is to use the "direct addressing" methode:
Here is a small example:
 
<pre>
LD HL,screen address
LD BC,#800+[most used byte]
LD DE,#C050
LD (HL),byte1:INC HL ;plot line 1
LD (HL),byte2:INC HL
LD (HL),C
LD A,H:ADD B:LD H,A
JR NC,line2
ADD HL,DE
.line2
LD (HL),byte6:DEC HL ;plot line 2
LD (HL),C :DEC HL
LD (HL),byte4
LD A,H:ADD B:LD H,A
JR NC,line3
ADD HL,DE
.line3
LD A,(HL):AND #55:OR byte7:LD (HL),A:INC HL ;plot line 3 (contains transparent areas)
LD (HL),byte8:INC HL
LD A,(HL):AND #AA:OR byte9:LD (HL),A
RET
</pre>
 
In mode 0 you will need two routines for every sprite, but I think there is no faster way to plot sprites on the CPC.
[[User:Prodatron|Prodatron]]
 
[[Category:Programming]]
151
edits