Language…
6 users online: abhinavkrishna123, CONLUSH666, Cristian Cardoso, dreamycarnival, MegaSonic1999,  Telinc1 - Guests: 147 - Bots: 263
Users: 64,667 (2,406 active)
Latest user: DarthHylian

Sprite/Block/HDMA/ASM Code Library

Link Thread Closed
Since Bio's original post was quite messy and the code snippets were unorganized, I've rewritten the first post. In this thread you will find commonly used code snippets and routines which you can use in your blocks, sprites and patches.

Blocks:
Change Map16 Number (load the Map16 tile in X, it can be 8-bit or 16-bit)
Causes a block to disappear
Causes a block to shatter
Causes a block to shatter on sprite contact
Check which side of a block Mario touched

Sprites:
Causes the sprite to explode like a Bob-omb
Draw smoke at sprite's position
Stores Mario to the sprite position
Stores sprite to Mario's position
Horizontal proximity check
Vertical proximity check
Spawn a normal sprite
Spawn a custom sprite
Spawn an extended sprite
Set sprite (extended, regular or minor extended) speed based on Mario's speed
Cape collision detection
Fireball Contact Routine
Sprite Interacts With Map16 Tile xxx.

HDMA:
Bright blue to darker blue, background colour gradient. ($2132)
Blue sky gradient
Green sky gradient (Image)
Pink sky gradient (Image)
Night sky gradient (Image)
Sunset gradient (Image)
Window effect (Image)
Wavy HDMA effect
HDMA Brightness gradient

Misc:
Yoshi's Earthquake
Pointer Subroutine
Random Number Generation (Ersanio)
Random Number Generation (1024)
Reset the game
The for() loop in ASM
Lose Yoshi
Convert time to binary
Use JSL with RTS
Hex -> Dec (short)
Hex -> Dec (long)
Layer 3 scroll (left and right codes included)
Stop level at a certain screen (assuming level moves from bottom to top)
Stop level at a certain screen (assuming level moves from top to bottom)
Stop level at a certain screen (assuming level moves from left to right)
Stop level at a certain screen (assuming level moves from right to left)
Find the number ($13BF format) of the level the current player is on.
Wouldn't the Wiki be the perfect place for things like this?
I'm not sure if the custom sprites section is the right place to submit this, that's why I didn't approve that submission (but someone else did).

... but I don't see anywhere else to submit it to (besides making a wiki article), so I guess it's ok.

I could make a subroutine section, but I didn't get the coder position (nobody did). A subroutine section would be nice, though. I have many things to submit to it.

EDIT: nevermind, that wouldn't be a good idea at all

Originally posted by smwedit
I could make a subroutine section, but I didn't get the coder position (nobody did)


That wouldn't be a good idea, even if you were a coder. When newbies see all those sections, they probably think "Oh, I want to add subroutines in my hack, they'd look cool!" and stuff.
Also, I don't see why it has to be a downloadable .zip when it's just a text file. You could make an article in the wiki or upload a text file to someone's webspace, and write all the codes in it.

Anyway, this is great for ASM beginners like me. Thanks!



 
Originally posted by Smallhacker
Wouldn't the Wiki be the perfect place for things like this?

I kinda forgot the wiki existed while making this... It do seem like a much better idea than filling the custom sprite and block section. a subroutine section would probably the best but the wiki is fine enough:P

I will leave this thread open for a while to allow others to voice their opinion
My opinion is that it may be good to leave this thread here as a locked sticky and have a link to the wiki page. That way more people will know it exists when they come looking for information (I mean, after all, Bio said it all when he stated "I forgot the wiki even existed".

One thing I would suggest with things like this:
This is pretty detailed stuff for a beginner. I can make blocks, but I am new to sprite ASM. I just started learning it a few days ago, and most of it is well documented in the information that came with Sprite Tool, so it is easy to pick up since I know some basic ASM. With more advanced codes like this cape thing, there needs to be documentation and comments in the code so we know what to do with it, and how it works. Maybe include some basic examples of how the code would look in a real situation for those of us who are visual learners.

[?]
I've removed my NoFades patch until I can find the brightness code for Star Road warps.
As you can see here, my attempt to add it to the wiki got a lot of weird problem(if anyone can delete it, do it), so I decided I would just host them on my noob freeweb site
*puts in <nowiki> tags*
ok, I fixed the wiki, but I don't know why it wouldn't work without the tags o_O
It didn't work properly due to some rows beginning with a tab instead of a space.
LOLBUMP
*shot*
I felt like adding some code to this thread. So here is a simple brightness gradient code, for use with sprite tool, insert as custom sprite:

http://ersan00b.googlepages.com/HDMABRIGHTNESSGRADIENT.asm

shazam

And don't forget to check the first post in this thread!

Another routine: Yoshi's Earthquake routine (When you have a yellow shell in your mouth and stuff)

http://ersan00b.googlepages.com/YoshiEarthQuake.asm

yay, this thread is up and running... Let me find some code templates and what not.
  
  
 



Breaking/shatter code for blocks

LDA #$02 ; Replace block with blank tile
STA $9C
JSL $00BEB0

PHB
LDA #$02
PHA
PLB
LDA #$00 ;set to 0 for normal explosion, 1 for rainbow (throw blocks)
JSR $028663 ;breaking effect
PLB

It messes up with certain 'acts like' settings, though. If it's set to 25 and is glitching, try setting it to 1E6.
(This is already in a page that Bio linked, but there's some info he missed.)


 
 
       

Fluffy video games by me and Raibys!
 
 
   
 
 
Finally finished disassembling the change in the next map16 routine used in many blktool block, wich for some strange reason, nobody bothered to disassemble yet

here

the routine is very large and not fully documented, but it should be easy enough to do variation wich affect nearby block and change to any map16

this also mean the map16++ patch is now mostly useless.
next is using the stripe image table in custom sprite...
Originally posted by Bio
Finally finished disassembling the change in the next map16 routine used in many blktool block, wich for some strange reason, nobody bothered to disassemble yet

here

the routine is very large and not fully documented, but it should be easy enough to do variation wich affect nearby block and change to any map16

this also mean the map16++ patch is now mostly useless.
next is using the stripe image table in custom sprite...

that is going to be very useful. thanks bio
I ripped the contact routine for contact with fireballs. It should be useful for custom boss HP.

Fireball Contact Routine
I have a question to the random number generator: Where can I adjust what's the max number? I want either 0, 1, 2 or 3.

1024: THAT'S WHAT I'VE SEARCHED!! Thank you!
Your layout has been removed.
This is extremely useful. I wish there were a bit more routines, but hey, this is already great.
Your layout has been removed.
VERY useful. Thank you, Bio, Smallhacker, edit1754, et al. I have two things to ask, though:

1) If I want a block to change to the PREVIOUS Map16 block instead of the next one...

clc ; |Set map16 number to change to current's +1
adc #$0001 ;/

...should I just replace CLC and ADC with SEC and SBC in this part of the code? (And, now that I think of it...does this routine only change the block's graphics, or does it change its properties to those of the next Map16 tile as well?)

2) What are all the block numbers for the Map16 tile-generating routine at $00BEB0? It appears that #$02 is a blank block (tile 25) and #$0D is a brown used block, but I don't see any pattern there. What about all the other possible values? Is there a list of these anywhere?

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

I'm working on a hack! Check it out here. Progress: 64/95 levels.
I can't acess SMWWiki, and in the backup I didn't find it so... Does someone have the Fireball Contact Routine?
I need a copy of the fireball contact routine if anyone has it. It's not in the SMWiki backup.
I've removed my NoFades patch until I can find the brightness code for Star Road warps.
Link Thread Closed