Language…
4 users online: Anas, CONLUSH666, Firstnamebutt, Zavok - Guests: 186 - Bots: 404
Users: 64,795 (2,380 active)
Latest user: mathew

ASM code for expanding circle effect used in SNES games

As I play more and more SNES games I keep on seeing this certain expanding explosion like effect being used. Since its across multiple games I'm guessing that this was some kind of resource that Nintendo gave its developers or something.



I know that there is the expanding circle intro in SMW, but I don't know if it's the same code as in the other games.

Anyway I was wondering if anyone here has tried to create this same effect in SMW. Since it was pretty commonly used, I'm sure somebody knows something about it.
It is the same kind of effect as the keyhole and the outro circle.
It's windowing HDMA, a lot of RPGs liked to use this effect for fancy spell casting effects. They just make it yellow instead of black and enable color math on it so it appears transparent.
You can even make it so that a certain layer shines through it instead of just a solid color, which a lot of games used to make fire effects or have stars appear inside that bubble.


I don't have the code for it, but people have done this before. Most prominent example I can think of would be Brutal Mario, which loves to use this effect.
Your layout has been removed.
Maybe it's yellow for light...?
My Mode 0 guide.

My Discord server. It has a lot of archived ASM stuff, so check that out!

Yes. I have a levelasm library with a bunch of those effects, but they're all coded for SA-1.

Here it is if you want to give it a try

It's not the simplest thing to use though.
It's not some big secret; it's just making a circle, for which many mathematical methods exist.

SMW uses trigonometry to find the sides of the circle for HDMA. To speed things up, it uses tables rather than actually calculating them too (only 256 integers to ever calculate sin/cos/tan for anyway).


As for "why yellow" well like skodwarde said, yellow is often used to depict light, and it especially stands out for low saturation environments like the ones in your screenies.
Originally posted by undefinied3
Yes. I have a levelasm library with a bunch of those effects, but they're all coded for SA-1.

Here it is if you want to give it a try

It's not the simplest thing to use though.

Oh, neat. Would you mind if I tried these out (and made them work without needing SA-1 if possible)? What's the "Windowing X/Y Scaling" routine for? (And shouldn't the "sen" be "sin"?)

----------------

I'm working on a hack! Check it out here. Progress: 64/95 levels.
Yep, that's totally free to use/tweak. I coded it to use with an RPG battle system I was creating but I don't have enough time to continue that.
It would be really nice if you can convert them to non-SA-1. It shouldn't be too hard I think, the only issue is the signed/unsigned division of SNES, there are some effects which I had to code in a specific way to use the signed SA-1 maths, so you might get confused while trying to understand what each piece of code does. I might be able to help you if you have any questions during the conversion.
Oh and yes haha, sen would be sin. It's written "sen" because in my language sine is "seno", so we abbreviate as sen.
The windowing X/Y scaling is to scale any window by a specific factor in X and Y axis. If you have a.. idk, any shape that you have the static windowing table for it, a star shape figure for example (although you would need both windows for that, but you can still use the code with some RAM tweaks), and you want to make it bigger/smaller, or just stretch in some direction, you can use that code.

You can check all the effects on my channel, except the cylinder:
https://www.youtube.com/user/undefinied3/videos

There're 2 ultima-effect videos, the most recent one uses the specific ultima code you can see in the ASM file, and the later uses the Windowing X/Y, because I hadn't figured the ellipse algorithm that time. Also, the ellipse video is outdated. The lag you'll see doesn't exist anymore because I found a way to use only 16-bit division; the video is an old code which used 32-bit division.

One last thing I forgot to mention, I don't know how just snes would be able to handle without major lag some of those effects, since let's say I'm not the best person when it comes to efficient coding, let alone finding better algorithms to fit ASM's limitations, so some of them I just recreated exactly what computers would use to rasterize some stuff since SA-1 can handle that stuff pretty ok.
Originally posted by undefinied3
Oh and yes haha, sen would be sin. It's written "sen" because in my language sine is "seno", so we abbreviate as sen.

Ah. That makes sense.

Originally posted by undefinied3
The windowing X/Y scaling is to scale any window by a specific factor in X and Y axis. If you have a.. idk, any shape that you have the static windowing table for it, a star shape figure for example (although you would need both windows for that, but you can still use the code with some RAM tweaks), and you want to make it bigger/smaller, or just stretch in some direction, you can use that code.

Oh, so it's supposed to be used in conjunction with the other routines. I see.

Originally posted by undefinied3
You can check all the effects on my channel, except the cylinder:
https://www.youtube.com/user/undefinied3/videos

Now that you mention it, I remember some of those. Cool stuff.

Originally posted by undefinied3
One last thing I forgot to mention, I don't know how just snes would be able to handle without major lag some of those effects, since let's say I'm not the best person when it comes to efficient coding, let alone finding better algorithms to fit ASM's limitations, so some of them I just recreated exactly what computers would use to rasterize some stuff since SA-1 can handle that stuff pretty ok.

Yeah, that would be a lot to process for sure. It would be best for things like one-off effects in boss battles, cutscenes, or other places where there wouldn't be much else going on.

----------------

I'm working on a hack! Check it out here. Progress: 64/95 levels.
I just watched the youtube videos on this and this is amazing. I'll have to try this out.
It will take me a while to figure out how the ASM code posted works, but I've been thinking about this lately.

I know you only need to calculate the first 45 degrees of the circle (which is only 14.6% of the circle's height) and every other side of is just mirroring.
I thought of another optimization. Doing x scroll calculation and clipping can be done like this:


//using 16-bit A
lda {x_center}
clc
adc #clipping_table
sta {clipping_table_address}

Then for each line, you do this for left boundaries:

//using 8-bit A, and 16-bit Y
ldy {left_boundary}
lda ({clipping_table_address}),y

and the same for right boundaries

ldy {right_boundary}
lda ({clipping_table_address})

Left and right boundary values would have to be centered around 256, as opposed to 0.