Mercurial > repos > ghero
comparison sprites.s68 @ 14:166d58b234c3
Added my old sprite library I forgot to add earlier
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 08 Sep 2013 12:17:02 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:30f1d4c90900 | 14:166d58b234c3 |
---|---|
1 ;Sprite Management Library | |
2 ;Copyright 2003 by Mike Pavone a.k.a. Mask of Destiny | |
3 ; | |
4 ;This library manages the allocation and deallocation of sprites for use with the Genesis VDP | |
5 ;Keep in mind that you shouldn't play with the link field of your sprites when using this library | |
6 ; | |
7 | |
8 SpriteTable equ $FFFFF000 | |
9 SpriteTable4 equ SpriteTable+4 | |
10 SpriteLink equ SpriteTable+3 | |
11 | |
12 | |
13 ;InitSprites - This initializes the library, call it once before using the any of the other functions | |
14 ;Doesn't effect any registers | |
15 | |
16 InitSprites: | |
17 move.l #0,(SpriteTable).w | |
18 move.l #0,(SpriteTable4).w | |
19 rts | |
20 | |
21 ;AddSprites - Adds a sprite to the sprite list and initializes it's entry. Returns pointer to sprite list | |
22 ;entry in A0, destroys data in a0, d2, d1 and d0 | |
23 | |
24 AddSprite: | |
25 lea (SpriteLink).w,a0 | |
26 moveq #0,d2 | |
27 moveq #0,d0 | |
28 | |
29 tst.b (FirstSprite) | |
30 beq FoundFirst | |
31 | |
32 | |
33 moveq #78,d1 | |
34 FindEmpty: | |
35 move.b (a0),d0 | |
36 tst.b d0 | |
37 beq FoundEmpty | |
38 | |
39 sub.b d2,d0 | |
40 cmp.b #1,d0 | |
41 bne FoundEmpty | |
42 add.b #1,d2 | |
43 add.l #8,a0 | |
44 dbra d1,FindEmpty | |
45 | |
46 move.l #0,a0 | |
47 rts | |
48 | |
49 FoundFirst: | |
50 sub.l #3,a0 | |
51 move.b #1,(FirstSprite) | |
52 bra CopyDefaultSprite | |
53 | |
54 FoundEmpty: | |
55 move.b (a0),d0 | |
56 add.b #1,d2 | |
57 move.b d2,(a0) | |
58 add.l #5,a0 | |
59 | |
60 CopyDefaultSprite: | |
61 move.w #144,(a0)+ | |
62 move.b $0,(a0)+ | |
63 move.b d0,(a0)+ | |
64 move.l #144,(a0) | |
65 sub.l #4,a0 | |
66 | |
67 rts | |
68 | |
69 | |
70 DefaultSprite: ;not actually used, just there for reference | |
71 dc.b $0, $20, $0, $0, $0, $0, $0, $20 | |
72 FirstSprite | |
73 dc.w $0 | |
74 | |
75 | |
76 ;FreeSprite - Deletes a sprite from the sprite table. Takes a pointer to the sprite table entry to be removed in a0 | |
77 | |
78 FreeSprite: | |
79 move.l a0,d0 | |
80 move.b 3(a0),d2 | |
81 sub.w #SpriteTable,d0 | |
82 lsr.w #3,d0 | |
83 | |
84 | |
85 | |
86 | |
87 lea (SpriteLink).w,a0 | |
88 FindPrecedingSprite: | |
89 move.b (a0),d1 | |
90 beq PrecedingSpriteNotFound | |
91 | |
92 cmp.b d1,d0 | |
93 beq FoundPrecedingSprite | |
94 | |
95 add.l #8,a0 | |
96 | |
97 bra FindPrecedingSprite | |
98 | |
99 FoundPrecedingSprite: | |
100 move.b d2,(a0) | |
101 | |
102 PrecedingSpriteNotFound: | |
103 rts | |
104 | |
105 | |
106 | |
107 ;SpriteCopyVRAM - Copies the sprite table from RAM to VRAM. Should be called once every frame during VBLANK. Expects addresses for VDP to | |
108 ;be in A4 and A5 and that auto-increment is set appropriately | |
109 | |
110 SpriteCopyVRAM: | |
111 move.l #$95009678,(a5) ;setup DMA source | |
112 move.w #$977F,(a5) | |
113 move.l #$93409401,(a5) ;set DMA length | |
114 move.l #$78000083,(a5) ;Do DMA to sprite table | |
115 | |
116 rts | |
117 | |
118 lea (SpriteTable).w,a0 | |
119 move.l #$78000003,(a5) ;VDP command word for sprite table | |
120 | |
121 moveq #39,d0 | |
122 SpriteCopyLoop: | |
123 move.l (a0)+,(a4) | |
124 move.l (a0)+,(a4) | |
125 move.l (a0)+,(a4) | |
126 move.l (a0)+,(a4) | |
127 dbra d0,SpriteCopyLoop | |
128 | |
129 rts | |
130 Stuff: | |
131 dc.b 0 | |
132 Stuffb: | |
133 dc.b 0 | |
134 dc.w 0 | |
135 | |
136 AddBigSprite: | |
137 move.w (a1)+,d3 | |
138 lea BigSpritePointerTable(pc),a2 | |
139 subq #1,d3 ;change back to a sub 1 | |
140 | |
141 BigSpriteMapLoop: | |
142 bsr AddSprite | |
143 move.w #$265D,d1 | |
144 move.b (a1)+,2(a0) | |
145 add.b (a1)+,d1 | |
146 move.w d1,4(a0) | |
147 move.b (a1)+,d1 | |
148 add.b d1,7(a0) | |
149 move.b (a1)+,d1 | |
150 add.b d1,1(a0) | |
151 move.l a0,(a2)+ | |
152 dbra d3,BigSpriteMapLoop | |
153 | |
154 move.l #0,(a2) | |
155 | |
156 move.w (a1)+,d0 | |
157 move.w #$9360,(a5) | |
158 move.w #$9404,(a5) | |
159 | |
160 move.l a1,d7 | |
161 move.w #$9500,d6 | |
162 ror.l #1,d7 | |
163 move.b d7,d6 | |
164 move.w d6,(a5) | |
165 ror.l #8,d7 | |
166 move.b d7,d6 | |
167 add.w #$100,d6 | |
168 move.w d6,(a5) | |
169 ror.l #8,d7 | |
170 move.b d7,d6 | |
171 add.w #$100,d6 | |
172 and.b #$7F,d6 | |
173 move.w d6,(a5) | |
174 | |
175 move.l #$4BA00083,(a5) | |
176 | |
177 ;SpriteLoop: | |
178 ; move.w (a1)+,(a4) | |
179 ; dbra d0,SpriteLoop | |
180 | |
181 ; move.l (BigSpriteXPos),(BigSpriteXPosOld) | |
182 | |
183 ; move.l #$00900090,(BigSpriteXPos) | |
184 rts | |
185 | |
186 FreeBigSprite: | |
187 lea BigSpritePointerTable(pc),a1 | |
188 BigSpriteFreeLoop: | |
189 move.l (a1)+,d0 | |
190 beq BigspriteFreeDone | |
191 move.l d0,a0 | |
192 bsr FreeSprite | |
193 bra BigSpriteFreeLoop | |
194 | |
195 | |
196 BigspriteFreeDone: | |
197 rts | |
198 | |
199 ChangeFrameBigSprite: | |
200 lea BigSpriteFrameTable(pc),a2 | |
201 ; move.l (a2),d0 | |
202 ; beq OldFreeBigSprite | |
203 | |
204 bsr FreeBigSprite | |
205 | |
206 OldFreeBigSprite: | |
207 add.l d3,d3 | |
208 add.l d3,d3 | |
209 add.l d3,a2 | |
210 | |
211 move.l (a2),a1 | |
212 | |
213 bsr AddBigSprite | |
214 | |
215 move.w (BigSpriteXPos),d0 | |
216 move.w (BigSpriteYPos),d1 | |
217 bsr MoveBigSprite | |
218 move.w d0,(BigSpriteXPos) | |
219 move.w d1,(BigSpriteYPos) | |
220 | |
221 rts | |
222 | |
223 InitFrameBigSprite: | |
224 lea BigSpriteFrameTable(pc),a1 | |
225 InitFrameBigSpriteLoop: | |
226 move.l (a0)+,d0 | |
227 beq DoneInitBigSprite | |
228 move.l a0,(a1)+ | |
229 add.l d0,a0 | |
230 bra InitFrameBigSpriteLoop | |
231 | |
232 DoneInitBigSprite: | |
233 move.l a0,(a1)+ | |
234 move.l #0,(a1) | |
235 move.l a0,a1 | |
236 bsr AddBigSprite | |
237 rts | |
238 | |
239 | |
240 MoveBigSprite: | |
241 lea BigSpritePointerTable(pc),a0 | |
242 BigSpriteMoveLoop: | |
243 move.l (a0)+,a1 | |
244 move.l a1,d2 | |
245 beq BigSpriteMoveDone | |
246 add.w d1,(a1) | |
247 | |
248 add.w d0,6(a1) | |
249 bra BigSpriteMoveLoop | |
250 BigSpriteMoveDone: | |
251 add.w d1,(BigSpriteYPos) | |
252 add.w d0,(BigSpriteXPos) | |
253 rts | |
254 | |
255 | |
256 ; include sendrecv.asm | |
257 | |
258 BigSpritePointerTable: | |
259 dc.l 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
260 BigSpriteFrameTable: | |
261 dc.l 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
262 BigSpriteXPos: | |
263 dc.w 0 | |
264 BigSpriteYPos: | |
265 dc.w 0 | |
266 BigSpriteXPosOld: | |
267 dc.w 0 | |
268 BigSpriteYPosOld: | |
269 dc.w $0 |