Update vdp_spr.c
Fixed VDP_updateSprites() with DMA queue operation to prevent modify before DMA occurs.
// important to have a global structure here (consumes 640 bytes of memory)
VDPSprite vdpSpriteCache[MAX_VDP_SPRITE];
+// copy of the global structure needed for DMA queue as we can modify
+// global structure before DMA actually occurs (consumes 640 bytes of memory)
+VDPSprite vdpSpriteCacheQueue[MAX_VDP_SPRITE];
// keep trace of last allocated sprite (for special operation as link)
VDPSprite *lastAllocatedVDPSprite;
// keep trace of highest index allocated since the last VDP_resetSprites() or VDP_releaseAllSprites.
@@ -223,8 +226,14 @@ void VDP_updateSprites(u16 num, u16 queue)
// send the sprite cache to VRAM sprite table using DMA queue
if (queue)
- DMA_queueDma(DMA_VRAM, (u32) vdpSpriteCache, VDP_SPRITE_TABLE, (sizeof(VDPSprite) / 2) * num, 2);
+ {
+ // copy global structure to queue copy
+ memcpy(vdpSpriteCacheQueue, vdpSpriteCache, sizeof(VDPSprite) * num);
+ // then queue the DMA operation
+ DMA_queueDma(DMA_VRAM, (u32) vdpSpriteCacheQueue, VDP_SPRITE_TABLE, (sizeof(VDPSprite) / 2) * num, 2);
+ }
else
+ // send the sprite cache to the VRAM with DMA now
DMA_doDma(DMA_VRAM, (u32) vdpSpriteCache, VDP_SPRITE_TABLE, (sizeof(VDPSprite) / 2) * num, 2);
}
