SNES metasprite demo

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
lex
Posts: 13
Joined: Sat Dec 31, 2022 9:31 pm

SNES metasprite demo

Post by lex »

These are demos I made a while back but never released to the public. This demo
showcases a metasprite engine that I made.

The main advantage of this metasprite engine is that it allows you to have a lot of sprite
frames without using a lot of rom.

So how it works is I wrote a program that chops a sprite into the ideal number
of 8x8 and 16x16 tiles. So in a 32kb bank, there is some space for 8x8 sprites,
16x16 sprites, as well as an area that contains tilemap data and metasprite
data. Also, when chopping up sprites the program ignores blank tiles with no
data.

The tilemap data basically tells you how to rebuild each metasprite. Essentially,
each 8x8 and 16x16 tile is given its own ID. So the tilemap data for a metasprite
is a collection of tile IDs.

So on the SNES side; I wrote some code to read the tilemap data and upload the necessary sprite
tiles to VRAM. The code also updates sprite positions. 16x16 tiles are DMA'd straight from rom.
Basically, there is a DMA list that tells the SNES each 16x16 tile to DMA and where to send it in VRAM.

For 8x8 tiles, the data for each 8x8 tile is uploaded to a buffer in work ram. 8x8 tiles take more CPU
since you have to upload them byte by byte instead of just DMAing them from ROM.

In VRAM, there is a space allocated for 8x8 tiles and a space allocated for 16x16 tiles.

However, doing the math for this metasprite engine can be a little intensive for the SNES.
It requires a lot of updating of sprite positions using OAM. In one frame the code can handle
around 3 32x64 sprites.

Overall, this metasprite engine allows you to have large sprites with a lot of animations
using less rom.
Attachments
metasprite_demo2.smc
(256 KiB) Downloaded 58 times
metasprite_demo1.smc
(256 KiB) Downloaded 49 times
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: SNES metasprite demo

Post by psycopathicteen »

I used a debugger to trace the CPU, and it looks like you're using a delay loop instead of a NMI interrupt. You just have to write #$81 to $4200 at the end of the reset routine, and read $4210 at the beginning of every frame. I believe doing that would allow more sprites onscreen.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: SNES metasprite demo

Post by psycopathicteen »

When you say it can only handle 3 32x64 sprites do you mean DMA bandwidth, or do you mean CPU speed?
lex
Posts: 13
Joined: Sat Dec 31, 2022 9:31 pm

Re: SNES metasprite demo

Post by lex »

psycopathicteen wrote: Thu Mar 23, 2023 7:54 am When you say it can only handle 3 32x64 sprites do you mean DMA bandwidth, or do you mean CPU speed?
When I say it can handle around 3 32x64 sprites I mean that's pretty much the limit of what the code can handle in a single frame.

Any more than that and the code will not be able to finish before Vblank.

The code probably could be optimized to allow more metasprites per frame though.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES metasprite demo

Post by Oziphantom »

lots of room for optimization.

don't clear the VRAM buffer at 7e000-7e220 with a loop, DMA clear it.

Don't DMA each sprite bit, just do a single block DMA of the 8 and 16 size sprites all at once, it will be faster than all the set up and stores and checks. It looks like you prebuild the buffer into 7F bank, is that correct. you can also optimise your base sprite storage in ROM to but as much as each frame continuous for a faster setup time.

for sprite allocation in OAM see the Reverse Stack Sprite Allocator from my 5th video https://www.youtube.com/watch?v=8YowrDT9cB8&t=535s
Post Reply