Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
101b90_len_8f0.c File Reference

Go to the source code of this file.

Macros

#define ALIGN4(v)   (((u32)(v) >> 2) << 2)
 
#define SPR_SWIZZLE(base, offset)   ((void*)((s32)(offset) + (s32)(base)))
 

Functions

void spr_swizzle_anim_offsets (s32 arg0, s32 base, void *spriteData)
 
SpriteAnimDataspr_load_sprite (s32 idx, s32 isPlayerSprite, s32 useTailAlloc)
 
void spr_init_player_raster_cache (s32 cacheSize, s32 maxRasterSize)
 
IMG_PTR spr_get_player_raster (s32 rasterIndex, s32 playerSpriteID)
 
void spr_update_player_raster_cache (void)
 
void spr_load_npc_extra_anims (SpriteAnimData *header, u32 *extraAnimList)
 
SpriteComponent ** spr_allocate_components (s32 count)
 

Variables

s32 spr_allocateBtlComponentsOnWorldHeap
 
HeapNode heap_generalHead
 
HeapNode heap_spriteHead
 
BSS s32 spr_asset_entry [2]
 
BSS s32 PlayerRasterLoadDescBuffer [101]
 
BSS s32 PlayerRasterLoadDescNumLoaded
 
BSS s32 PlayerRasterLoadDescBeginSpriteIndex [SPR_Peach3]
 
BSS s32 PlayerRasterLoadDesc [0x2E0]
 
BSS PlayerRastersHeader PlayerRasterHeader
 
BSS s32 PlayerSpriteRasterSets [SPR_Peach3+1]
 
BSS s32 PlayerRasterCacheSize
 
BSS s32 PlayerRasterMaxSize
 
BSS s32 SpriteDataHeader [3]
 
BSS PlayerSpriteCacheEntry PlayerRasterCache [18]
 

Macro Definition Documentation

◆ ALIGN4

#define ALIGN4 ( v)    (((u32)(v) >> 2) << 2)

Definition at line 34 of file 101b90_len_8f0.c.

Referenced by spr_load_sprite(), and spr_swizzle_anim_offsets().

◆ SPR_SWIZZLE

#define SPR_SWIZZLE ( base,
offset )   ((void*)((s32)(offset) + (s32)(base)))

Definition at line 35 of file 101b90_len_8f0.c.

Referenced by spr_load_sprite(), and spr_swizzle_anim_offsets().

Function Documentation

◆ spr_swizzle_anim_offsets()

void spr_swizzle_anim_offsets ( s32 arg0,
s32 base,
void * spriteData )

Definition at line 37 of file 101b90_len_8f0.c.

37 {
38 u8* buffer;
39 SpriteAnimComponent*** animList;
40 SpriteAnimComponent** compList;
42 s32 animOffset;
43 s32 compOffset;
44 s32 temp;
45
46 // required to match, spriteData->animList would be nicer
47 animList = (SpriteAnimComponent***) spriteData;
48 animList += 4;
49
50 while (TRUE) {
51 if (*animList == PTR_LIST_END) {
52 break;
53 }
54 compList = (SpriteAnimComponent**) ((s32)*animList - ALIGN4(base));
55 compList = SPR_SWIZZLE(ALIGN4(spriteData), compList);
56 *animList = compList;
57 while (TRUE) {
58 if (*compList == PTR_LIST_END) {
59 break;
60 }
61 *compList = comp = SPR_SWIZZLE(ALIGN4(spriteData), (s32)*compList - ALIGN4(base));
62 comp->cmdList = SPR_SWIZZLE(ALIGN4(spriteData), (s32)comp->cmdList - ALIGN4(base));
63 compList++;
64 }
65 animList++;
66 }
67}
#define ALIGN4(v)
#define SPR_SWIZZLE(base, offset)
#define PTR_LIST_END
Definition macros.h:42

Referenced by spr_load_sprite().

◆ spr_load_sprite()

SpriteAnimData * spr_load_sprite ( s32 idx,
s32 isPlayerSprite,
s32 useTailAlloc )

Definition at line 69 of file 101b90_len_8f0.c.

69 {
70 SpriteAnimData* animData;
71 s32 base;
72 s32 i;
73 s32 compressedSize;
74 s32* ptr1;
75 IMG_PTR image;
76 s32 count;
77 s32** data;
78 s32** palettes;
79
80 if (isPlayerSprite) {
81 base = SpriteDataHeader[1];
82 } else {
83 base = SpriteDataHeader[2];
84 }
85
86 // read current and next sprite offsets, so we can find the difference
87 nuPiReadRom(base + idx * 4, &spr_asset_entry, sizeof(spr_asset_entry));
88
89 compressedSize = ALIGN8(spr_asset_entry[1] - spr_asset_entry[0]);
90 data = general_heap_malloc(compressedSize);
91 nuPiReadRom(base + spr_asset_entry[0], data, compressedSize);
92
93 ptr1 = (s32*)data;
94 // skip 4 bytes: 'YAY0' signature
95 ptr1++;
96
97 if (useTailAlloc) {
98 animData = _heap_malloc_tail(&heap_spriteHead, *ptr1);
99 } else {
100 animData = _heap_malloc(&heap_spriteHead, *ptr1);
101 }
102 ASSERT_MSG(animData, "out of sprite memory");
103 decode_yay0(data, animData);
104 general_heap_free(data);
105
106 // swizzle raster array
107 data = (s32**)animData->rastersOffset;
108 data = SPR_SWIZZLE(ALIGN4(animData), data);
109 animData->rastersOffset = (SpriteRasterCacheEntry**)data;
110
111 while (TRUE) {
112 ptr1 = *data;
113 if (ptr1 == PTR_LIST_END) {
114 break;
115 }
116 // swizzle each raster cache entry
117 ptr1 = SPR_SWIZZLE(ALIGN4(animData), ptr1);
118 *data++ = ptr1;
119 image = ((SpriteRasterCacheEntry*)ptr1)->image;
120
121 if (!isPlayerSprite) {
122 // swizzle image pointer in the cache entry
123 image = SPR_SWIZZLE(ALIGN4(animData), image);
124 *ptr1 = (s32)image;
125 }
126 }
127
128 if (isPlayerSprite) {
130 count = PlayerSpriteRasterSets[idx + 1] - PlayerSpriteRasterSets[idx];
131 // load a range of raster loading desciptors to a buffer and copy contents into PlayerRasterLoadDesc
134 for (i = 0; i < count; i++) {
136 }
137 }
138
139 // swizzle palettes array
140 palettes = SPR_SWIZZLE(ALIGN4(animData), animData->palettesOffset);
141 animData->palettesOffset = (PAL_PTR*)palettes;
142 while (TRUE) {
143 ptr1 = *palettes;
144 if (ptr1 == PTR_LIST_END) {
145 break;
146 }
147 // swizzle each palette pointer
148 ptr1 = SPR_SWIZZLE(ALIGN4(animData), ptr1);
149 *palettes++ = ptr1;
150 }
151
152 spr_swizzle_anim_offsets(0, 0, animData);
153 return animData;
154}
BSS PlayerRastersHeader PlayerRasterHeader
BSS s32 spr_asset_entry[2]
BSS s32 SpriteDataHeader[3]
BSS s32 PlayerRasterLoadDescBuffer[101]
HeapNode heap_spriteHead
Definition heaps3.c:4
BSS s32 PlayerRasterLoadDesc[0x2E0]
BSS s32 PlayerSpriteRasterSets[SPR_Peach3+1]
BSS s32 PlayerRasterLoadDescNumLoaded
BSS s32 PlayerRasterLoadDescBeginSpriteIndex[SPR_Peach3]
void spr_swizzle_anim_offsets(s32 arg0, s32 base, void *spriteData)
#define PAL_PTR
#define IMG_PTR
#define general_heap_malloc
void * _heap_malloc(HeapNode *head, u32 size)
Definition 43F0.c:78
void * _heap_malloc_tail(HeapNode *head, u32 size)
Definition 43F0.c:153
s32 general_heap_free(void *data)
Definition heap.c:18
void decode_yay0(void *src, void *dst)
#define ASSERT_MSG(condition, msg, args...)
Definition macros.h:66
#define ALIGN8(val)
Definition macros.h:21
SpriteRasterCacheEntry ** rastersOffset
Definition sprite.h:75
PAL_PTR * palettesOffset
Definition sprite.h:76
Sprite data header.
Definition sprite.h:74

Referenced by spr_load_npc_sprite(), and spr_load_player_sprite().

◆ spr_init_player_raster_cache()

void spr_init_player_raster_cache ( s32 cacheSize,
s32 maxRasterSize )

Definition at line 156 of file 101b90_len_8f0.c.

156 {
157 void* raster;
158 s32 i;
159
160 nuPiReadRom(SPRITE_ROM_START, &SpriteDataHeader, sizeof(SpriteDataHeader));
161 PlayerRasterCacheSize = cacheSize;
162 PlayerRasterMaxSize = maxRasterSize;
163 SpriteDataHeader[0] += SPRITE_ROM_START;
164 SpriteDataHeader[1] += SPRITE_ROM_START;
165 SpriteDataHeader[2] += SPRITE_ROM_START;
166 raster = _heap_malloc(&heap_spriteHead, maxRasterSize * cacheSize);
167
168 for (i = 0; i < ARRAY_COUNT(PlayerRasterCache); i++) {
169 PlayerRasterCache[i].raster = raster;
170 raster += PlayerRasterMaxSize;
174 }
175
178 }
180 nuPiReadRom(SpriteDataHeader[0], &PlayerRasterHeader, sizeof(PlayerRasterHeader));
182}
BSS s32 PlayerRasterCacheSize
BSS s32 PlayerRasterMaxSize
BSS PlayerSpriteCacheEntry PlayerRasterCache[18]
#define ARRAY_COUNT(arr)
Definition macros.h:40

Referenced by spr_init_sprites().

◆ spr_get_player_raster()

IMG_PTR spr_get_player_raster ( s32 rasterIndex,
s32 playerSpriteID )

Definition at line 184 of file 101b90_len_8f0.c.

184 {
185 PlayerSpriteCacheEntry* cacheEntry;
186 u32 playerRasterInfo;
187 s32 idx = -1;
188 s32 i;
189
190 for (i = 0; i < PlayerRasterCacheSize; i++) {
191 if (PlayerRasterCache[i].lazyDeleteTime != 0) {
192 if (PlayerRasterCache[i].rasterIndex == rasterIndex && PlayerRasterCache[i].spriteIndex == playerSpriteID) {
194 return PlayerRasterCache[i].raster;
195 }
196 } else if (idx == -1) {
197 idx = i;
198 }
199 }
200
201 if (idx == -1) {
202 return NULL;
203 }
204
205 cacheEntry = &PlayerRasterCache[idx];
206 cacheEntry->rasterIndex = rasterIndex;
207 cacheEntry->spriteIndex = playerSpriteID;
208 cacheEntry->lazyDeleteTime = 2;
209
210 // each player raster load descriptor has image size (in bytes) and relative offset packed into one word
211 // upper three nibbles give size / 16, lower 5 give offset
212 playerRasterInfo = PlayerRasterLoadDesc[PlayerRasterLoadDescBeginSpriteIndex[playerSpriteID] + rasterIndex];
213 nuPiReadRom(SpriteDataHeader[0] + (playerRasterInfo & 0xFFFFF), cacheEntry->raster, (playerRasterInfo >> 0x10) & 0xFFF0);
214 return cacheEntry->raster;
215}

Referenced by spr_draw_component(), and spr_get_player_raster_info().

◆ spr_update_player_raster_cache()

void spr_update_player_raster_cache ( void )

Definition at line 217 of file 101b90_len_8f0.c.

217 {
218 s32 i;
219
221
222 for (i = 0; i < PlayerRasterCacheSize; i++) {
223 if (PlayerRasterCache[i].lazyDeleteTime != 0) {
225 }
226 }
227}
void func_8013A4D0(void)
Definition imgfx.c:267

Referenced by spr_render_init().

◆ spr_load_npc_extra_anims()

void spr_load_npc_extra_anims ( SpriteAnimData * header,
u32 * extraAnimList )

Definition at line 229 of file 101b90_len_8f0.c.

229 {
230 u8* src;
231 s32 imgID;
232 s32 rasterSize;
233 s32 remaining;
234 u16 animCmd;
235 u16* cmdList;
236 u32 extraAnimID;
237 u8* dataPos;
238 void* copyEnd;
240 SpriteAnimComponent** compList;
241 void* writePos;
242 SpriteRasterCacheEntry** rasterList;
244 u16** oldPalList;
245 u16* palette;
246 // one extra required for 'done' sentinel
247 s32 sawRaster[100 + 1];
248 s32 i;
249
250 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
251 sawRaster[i] = FALSE;
252 }
253
254 while ((extraAnimID = *extraAnimList++) != -1) {
255 compList = header->animListStart[extraAnimID & 0xFF];
256 while ((comp = *compList++) != PTR_LIST_END) {
257 cmdList = comp->cmdList;
258 remaining = (s16) comp->cmdListSize / 2;
259 while (remaining > 0) {
260 animCmd = *cmdList++;
261 remaining--;
262 switch (animCmd & 0xF000) {
263 case 0x1000:
264 i = animCmd; // required to match
265 imgID = i & 0xFF;
266 if (imgID < ARRAY_COUNT(sawRaster) - 1) {
267 sawRaster[imgID] = TRUE;
268 }
269 break;
270 case 0x3000:
271 cmdList++;
272 remaining--;
273 // fallthrough
274 case 0x4000:
275 cmdList++;
276 remaining--;
277 // fallthrough
278 case 0x7000:
279 case 0x5000:
280 cmdList++;
281 remaining--;
282 // fallthrough
283 case 0x0000:
284 case 0x2000:
285 case 0x6000:
286 case 0x8000:
287 break;
288 }
289 }
290 }
291 }
292
293 rasterList = header->rastersOffset;
294 raster = *rasterList;
295 dataPos = raster->image;
296
297 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
298 if ((raster = *rasterList) == PTR_LIST_END) {
299 break;
300 }
301 if (sawRaster[i]) {
302 src = raster->image;
303 rasterSize = (raster->width * raster->height) / 2;
304 copyEnd = &dataPos[rasterSize];
305 rasterSize += 8;
306 if (dataPos != src) {
307 raster->image = dataPos;
308 bcopy(src, dataPos, rasterSize);
309 }
310 *rasterList = copyEnd;
311 dataPos += rasterSize;
312 }
313 rasterList++;
314 }
315 // sentinel value to mark end of valid data
316 sawRaster[i] = TRUE;
317
318 writePos = dataPos;
319
320 // copy raster list
321 rasterList = header->rastersOffset;
322 header->rastersOffset = writePos;
323
324 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
325 raster = *rasterList++;
326 if (sawRaster[i]) {
327 *(SpriteRasterCacheEntry**) writePos = raster;
328 } else {
329 *(SpriteRasterCacheEntry**) writePos = (SpriteRasterCacheEntry*) copyEnd;
330 }
331 writePos += 4;
332 if (raster == PTR_LIST_END) {
333 break;
334 }
335 }
336
337 // copy palette list
338 oldPalList = header->palettesOffset;
339 header->palettesOffset = writePos;
340
341 for (i = 0; i < ARRAY_COUNT(sawRaster) - 1; i++) {
342 raster = (SpriteRasterCacheEntry*)*oldPalList++; // required to match
343 *(u16**)writePos = (u16*)raster;
344 writePos += 4;
345 if (raster == PTR_LIST_END) {
346 break;
347 }
348 }
349
350 _heap_realloc(&heap_spriteHead, header, (s32)writePos - (s32)header);
351}
void * _heap_realloc(HeapNode *heapNodeList, void *addr, u32 newSize)
Definition 43F0.c:286
SpriteAnimComponent ** animListStart[VLA]
Definition sprite.h:79

Referenced by spr_load_npc_sprite().

◆ spr_allocate_components()

SpriteComponent ** spr_allocate_components ( s32 count)

Definition at line 353 of file 101b90_len_8f0.c.

353 {
354 s32 listSize;
355 SpriteComponent** listStart;
356 SpriteComponent* component;
357 SpriteComponent** listPos;
358 u32 totalSize;
359 s32 i;
360
361 // data will contain a -1 terminated list, followed by the SpriteComponents
362 // corresponding to that list
363 listSize = (count + 1) * 4;
364 totalSize = (count * sizeof(SpriteComponent)) + listSize;
365
367 listStart = _heap_malloc(&heap_generalHead, totalSize);
368 listPos = listStart;
369 component = (SpriteComponent*) listPos;
370 } else {
371 listStart = _heap_malloc(&heap_spriteHead, totalSize);
372 listPos = listStart;
373 component = (SpriteComponent*) listPos;
374 }
375
376 component = (SpriteComponent*)((s32)(component) + (listSize / 4) * 4);
377
378 // fill list values
379 for (i = 0; i < count; i++) {
380 *listPos++ = component;
381 component++;
382 }
383 *listPos = PTR_LIST_END;
384
385 return listStart;
386}
s32 spr_allocateBtlComponentsOnWorldHeap
Definition sprite.c:9
HeapNode heap_generalHead
Definition heaps3.c:3

Referenced by spr_load_npc_sprite(), and spr_update_player_sprite().

Variable Documentation

◆ spr_allocateBtlComponentsOnWorldHeap

s32 spr_allocateBtlComponentsOnWorldHeap
extern

Definition at line 9 of file sprite.c.

Referenced by spr_allocate_components(), spr_free_sprite(), and spr_init_sprites().

◆ heap_generalHead

HeapNode heap_generalHead
extern

Definition at line 3 of file heaps3.c.

Referenced by spr_allocate_components().

◆ heap_spriteHead

HeapNode heap_spriteHead
extern

◆ spr_asset_entry

BSS s32 spr_asset_entry[2]

Definition at line 21 of file 101b90_len_8f0.c.

Referenced by spr_load_sprite().

◆ PlayerRasterLoadDescBuffer

BSS s32 PlayerRasterLoadDescBuffer[101]

Definition at line 22 of file 101b90_len_8f0.c.

Referenced by spr_load_sprite().

◆ PlayerRasterLoadDescNumLoaded

BSS s32 PlayerRasterLoadDescNumLoaded

Definition at line 23 of file 101b90_len_8f0.c.

Referenced by spr_init_player_raster_cache(), and spr_load_sprite().

◆ PlayerRasterLoadDescBeginSpriteIndex

BSS s32 PlayerRasterLoadDescBeginSpriteIndex[SPR_Peach3]

◆ PlayerRasterLoadDesc

BSS s32 PlayerRasterLoadDesc[0x2E0]

Definition at line 25 of file 101b90_len_8f0.c.

Referenced by spr_get_player_raster(), and spr_load_sprite().

◆ PlayerRasterHeader

BSS PlayerRastersHeader PlayerRasterHeader

Definition at line 27 of file 101b90_len_8f0.c.

Referenced by spr_init_player_raster_cache(), and spr_load_sprite().

◆ PlayerSpriteRasterSets

BSS s32 PlayerSpriteRasterSets[SPR_Peach3+1]

Definition at line 28 of file 101b90_len_8f0.c.

Referenced by spr_init_player_raster_cache(), and spr_load_sprite().

◆ PlayerRasterCacheSize

BSS s32 PlayerRasterCacheSize

◆ PlayerRasterMaxSize

BSS s32 PlayerRasterMaxSize

Definition at line 30 of file 101b90_len_8f0.c.

Referenced by spr_init_player_raster_cache().

◆ SpriteDataHeader

BSS s32 SpriteDataHeader[3]

◆ PlayerRasterCache