Banner
Views: 290,816,554
Time: 2014-04-23 09:36:10 AM
22 users online: Arctic Avenger, Catobat, o Chikane, Daniel 115, o Everest, Face, GloriousWater, GreenHammerBro, Infrared, KochiyaStar, Lui37, o Lynnes, Medic, MichMasteR, RaccoonStar24, Rockythetigre, o sleepy, Sokobansolver, Stephen, tcdw, TheDarkOnyx, Wuthering - Guests: 25 - Bots: 65Users: 24,814 (1,122 active)
Latest: Kamia Elpida
Tip: If you're using the wall-running purple triangles in your hack, remember to add tile 1EB (or a tile that acts like tile 1EB) underneath it. Extended object 44/45 will include this tile for you.
Extended Sprite Coding
Forum Index - SMW Hacking - General SMW Hacking Help - Tutorials - Extended Sprite Coding
Pages: « 1 »
A semi-advanced knowledge of ASM things such as:

- Basic ASM (LDA, STA, LDX, STX, LDY, STY, etc)
- Stacking (PHA, PHY, PHX, PLA, PLX, PLY, etc)
- Jumping (JSR, JML, JSL, etc)
- Branching (BEQ, BNE, BCC, etc)
- Math (LSR, etc)

is mostly required for the understanding of the tutorial. Having custom sprite coding knowledge is also a plus.

So what exactly are extended sprites?


Extended sprites are those sprites which are used for general aesthetics and projectiles. Such examples are any kind are fireballs that are projected by sprites. Another example would be the little lava splash that appears when a Blarg goes into the lava. In this tutorial I'm going to show you how to create one, and how to code the generating sprite as well. You must note that, just like cluster sprites, extended sprites are NOT regular sprites. You can't insert them via Lunar Magic, you have spawn them through ASM routines. You can have up to 8 extended sprites on the screen at once.

First of all, you need a patch to allow you to insert your custom extended sprites, seeing as the original SMW only allows 12. I have made one, I think Jagfillit has made one as well. In this tutorial I'm using examples to which can be applied to my patch, I haven't released it yet, you can find it here. Let's learn how to code them.

How do I code them?


First of all, find the sprite number that you want to use, since SMW uses 12 extended sprites, I'm going to use extended sprite 13. In my patch, I find the label "CusExSprite13" and I put my code under it. The first thing I'm going to do is restore every register that got messed up in the craziness of the jumping to different routines in different banks. Here is the code I use to do that:
Originally posted by
LDA !freeRAM
LDX !freeRAM+1
LDY !freeRAM+2
PHA
PHX
PHY
PHB
PHK
PLB

Basically, all you need to know about that is that it restores A,X, and Y then pushes registers to keep them save and pushes the bank number. Now what I'm going to do is make sure sprites aren't locked. I do that with:
Originally posted by
LDA $9D
BNE Locked

Now, when sprites are locked, the extended sprite will NOT run.

Now that's taken care of I want to JSR to the two routines that handle the sprites X/Y speed. In my patch these routines are just a simple JSR to SHARED00 and SHARED01, but if you're using Jagfillit's the addresses are $02B554 and $02B560. Now, I want to give the sprite some Y speed. Here is the code I use for that:
Originally posted by
LDA $173D,x
CLC
ADC #$01
STA $173D,x

All that is doing is adding #$01 to the extended sprites Y speed every frame. Now, I'm going to set the sprites X position:
Originally posted by
LDY.w XLOW,x
LDA $171F,x
SEC
SBC $1A
STA $00

What this does is sets some scratch RAM for the sprites X low byte from a table relative to the screen boundary, to be used later when doing the graphics routine. We'll look at the "XLOW" table later. Now I'm going to check the extended sprites X high byte and if it exceeds the screen boundary I want the sprite to die. Since there's no use having the sprite still running when you can't see it.
Originally posted by
LDA $1733,x
SEC
SBC $1B
BNE Die

Okay, now it's finally time to do the sprites graphics routine. I'm going to break it up into a few pieces and comment for you all to understand what's going on:
Originally posted by
LDA $00
STA $0200,y
LDA $1715,x
SEC
SBC $1C
CMP #$F0
BCS Die
STA $0201,y

The first part just gets the scratch RAM we wrote to earlier and puts it in the OAM for the sprites X position. The next bit loads the sprites Y low byte and compares it to the Y screen boundary low and dies if it's greater than or equal to #$F0. Basically, it destroys the sprite if it exceeds screen boundary. Lastly it stores the Y low byte to the OAM of the sprites Y position.
Originally posted by
LDA #$A8
STA $0202,y

This means that I'm using tile #$A8 for my graphics.

Originally posted by
LDA #$44
ORA $64
STA $0203,y

If you noticed, this part is exactly the same as a regular sprite. It's the YXPPCCCT.
Originally posted by
TYA
LSR
LSR
TAY

We wrote 4 OAM bytes, so increment the OAM count accordingly.
Originally posted by
LDA #$02
STA $0420,y
LDX $15E9

We store the tile size to $0420,y. #$00 is 8x8 and #$02 would be 16x16. And lastly, we load X with the currently processing sprite. ($15E9)

That's it. Our graphics routine is done. You may be wondering about some labels/tables.
Originally posted by
Die:
STZ $170B,x

This kills the extended sprite.
Originally posted by
XLOW:
db $90,$94,$98,$9C,$A0,$A4,$A8,$AC

The X position tables..

Now, everything is done, take a look at the complete sprite:
Originally posted by
CusExSprite13:
LDA !freeRAM
LDX !freeRAM+1
LDY !freeRAM+2
PHA
PHX
PHY
PHB
PHK
PLB
LDA $9D
BNE locked
JSR SHARED00
JSR SHARED01

LDA $173D,x
CLC
ADC #$01
STA $173D,x
locked:
LDY.w XLOW,x
LDA $171F,x
SEC
SBC $1A
STA $00

LDA $1733,x
SEC
SBC $1B
BNE Die

LDA $00
STA $0200,y

LDA $1715,x
SEC
SBC $1C
CMP #$F0
BCS Die
STA $0201,y

LDA #$A8 ;tile # A8
STA $0202,y

LDA #$44 ;YXPPCCCT
ORA $64
STA $0203,y

TYA
LSR
LSR
TAY
LDA #$02
STA $0420,y
LDX $15E9
BRA Return
Die:
STZ $170B,x
Return:
PLB
PLY
PLX
PLA
RTS

XLOW:
db $90,$94,$98,$9C,$A0,$A4,$A8,$AC


Patch the patch now, and copy your ROM into spritetool's folder, now we will be coding the generating sprite.

The generating sprite


The generating sprite is the custom sprite that will spawn our custom extended sprite. I'll just let it explain itself:
Originally posted by
;-----------------------------------;
; Random Extended sprite shooter ;
;------ by zkip --------;
; This IS NOT a shooter, though it ;
; does generate a custom extended ;
; sprite. ;
;-----------------------------------;

dcb "INIT"
RTL

dcb "MAIN"
LDY #$07 ; \ Find a free extended sprite slot
Loop: ; |
LDA $170B,Y ; |
BEQ ThisMain ; |
DEY ; |
BPL Loop ; |
RTL ; / Return if no free slots

ThisMain:
LDA #$13 ; \ Extended sprite = Custom #13
STA $170B,y ; /

LDA $D8,x ; \ sprite Y low to exsprite Y low
STA $1715,y ; /

LDA $14D4,x ; \ sprite Y high to exsprite Y high
STA $1729,y ; /

LDA $E4,x ; \ sprite X low to exsprite X low
CLC ; |
ADC #$04 ; |
STA $171F,y ; /

LDA $14E0,x ; \ sprite X high to exsprite X high
STA $1733,y ; /

LDA #$05 ; \ Set the extended sprites X speed
STA $1747,y ; /

LDA #$E0 ; \ Set the extended sprites Y speed
STA $173D,y ; /

DEC $00 ; \ This keeps the loop going, but makes sure
BPL Loop ; | there aren't too many sprites on screen.
RTL ; /

This is just an example, extended sprites are sometimes used as projectiles, thus the generation routine is inside a working sprite. This is just a simple no-graphic sprite that generates the custom extended sprite. Insert that via spritetool AS A REGULAR SPRITE and you've got yourself a generator for a working extended sprite. You could just as well put the code in the init routine and make it appear once. Also, as I said before, one of the good ways to use extended sprites is using them as projectiles. Slap that generation routine in a working functional sprite and you've got a sprite that shoots.

Library


Here I've included a few things:
Here is a few screen shots of whats possible with extended sprites.






Interaction:
Originally posted by
LDA $94
SEC
SBC $171F,y ; xlow
CLC
ADC #$0C
CMP #$18
BCS NoTouch
LDA #$20
LDX $73
BNE StoreTemp
LDX $19
BEQ StoreTemp
LDA #$30
StoreTemp:
STA $03
LDA $96
SEC
SBC $1715,y ;ylow
CLC
ADC #$20
CMP $03
BCS NoTouch
JSL $00F5B7 ;Hurt Mario

Thats the basic custom interaction code for a extended sprite that is 16x16. Not much to say.

RAM addresses:
Originally posted by
$176F - The RAM map says "Fireball Hit Frame Counter Table", but trust me, this is used in a lot of extended sprites as misc tables.

$171F - Extended sprite X position low

$1733 - Extended sprite X position high

$1747 - Extended sprite X speed

$1715 - Extended sprite Y position low

$1729 - Extended sprite Y position high

$173D - Extended sprite Y speed


Also, I want to talk about something else for a minute. If you check the RAM map here, it says that $176F is fireball specific, but actually in my research of these sprites, most of them seem to use it as a misc. table. You can use it as a frame timer for animation. Like so:
Originally posted by
LDA $176F,x
LSR
LSR
AND #$03
TAX
LDA Tilemap,x
STA $0202,y


tl;dr:


I've worked on this tutorial for a little, having coded several custom extended sprites, they are really fun to work with. I know that this tutorial isn't the best, and it's most certainly still WIP.

Oh, also, for the record, extended sprites could be used to create snow, rain, etc. but the limitation there is that only 8 extended sprites can be on the screen at once, though a water splash or something always adds that extra bit of c00lness to your hack.
Last edited on 2011-01-10 08:39:39 PM by zkip.
Well, looks "Good". A little confusing, though.
gj making a tutorial and everything, but I don't really get the point. There's only 8 exspr slots and they get used by fireballs, lava lotus balls, splashes and I think smoke. Well actually, the best use for them would be new projectiles and powerups. Kipernal (I think) had a great idea when he made that danmakufu sprite that did all the interaction and graphics within the main sprite, and personally if I wanted to do something like a 'splash', I'd just do that within the sprite too.

finish the tut though. I still wanna see what you do for the gfx. IT has 2 routines for that, no?
Pages: « 1 »
Forum Index - SMW Hacking - General SMW Hacking Help - Tutorials - Extended Sprite Coding

The purpose of this site is not to distribute copyrighted material, but to honor one of our favourite games.

Copyright © 2005 - 2014 - SMW Central
Legal Information - Link To Us


Total queries: 27

Menu

Affiliates

  • Talkhaus
  • SMBX Community