I don't think I've seen anyone post a sprite-spawning routine here yet (there might have been one in Fakescaper's document...I can't remember), and a lot of people use them, so I thought I'd post a couple of them.
To spawn normal sprites:
LDA $15A0,x
ORA $186C,x
BNE EndSpawn
; This code prevents the sprite from spawning something if it is offscreen.
JSL $02A9DE
BMI EndSpawn
LDA #$01
STA $14C8,y
; The 01 is sometimes 08...depends on the sprite.
; 01 will make it run the init routine, and 08 will make it skip the init routine.
; If you want to spawn a shell, use 09 instead.
; If you want a kicked shell, use 0A.
; If you want the sprite to be carried (certain blocks, like the SMB2 Pow, do this), use 0B.
LDA #!SpriteNumber
STA $009E,y
LDA $E4,x
STA $00E4,y
LDA $14E0,x
STA $14E0,y
LDA $D8,x
STA $00D8,y
LDA $14D4,x
STA $14D4,y
; This sets the XY position of the spawned sprite.
; You can add offsets if you want.
; For example, if you want to move the spawned sprite right one tile,
; place "CLC ADC #$10" before the STA $00E4,y,
; and put "ADC #$00" before the STA $14E0,y.
PHX
TYX
JSL $07F7D2
PLX
; Here is where you can set certain things like the sprite's direction and speed.
; $00AA,y, $00B6,y, $157C,y, $151C,y, $00C2,y, $1540,y, $1570,y, $1510,y...
; Those are examples of sprite tables you can store to here.
EndSpawn:
RTS
To spawn custom sprites:
LDA $15A0,x
ORA $186C,x
BNE EndSpawn
; This code prevents the sprite from spawning something if it is offscreen.
JSL $02A9DE
BMI EndSpawn
LDA #$01
STA $14C8,y
; The 01 is sometimes 08...depends on the sprite.
; 01 will make it run the init routine, and 08 will make it skip the init routine.
; If you want to spawn a shell, use 09 instead.
; If you want a kicked shell, use 0A.
; If you want the sprite to be carried (certain blocks, like the SMB2 Pow, do this), use 0B.
PHX
TYX
LDA #!SpriteNumber
STA $7FAB9E,x
PLX
LDA $E4,x
STA $00E4,y
LDA $14E0,x
STA $14E0,y
LDA $D8,x
STA $00D8,y
LDA $14D4,x
STA $14D4,y
; This sets the XY position of the spawned sprite.
; You can add offsets if you want.
; For example, if you want to move the spawned sprite right one tile,
; place "CLC ADC #$10" before the STA $00E4,y,
; and put "ADC #$00" before the STA $14E0,y.
PHX
TYX
JSL $07F7D2
JSL $0187A7
LDA #$08
STA $7FAB10,x
; It's either 08 or 88, I can never figure out which.
; Use 0C/8C if you want the extra bit to be set.
PLX
; Here is where you can set certain things like the sprite's direction and speed.
; $00AA,y, $00B6,y, $157C,y, $151C,y, $00C2,y, $1540,y, $1570,y, $1510,y...
; Those are examples of sprite tables you can store to here.
EndSpawn:
RTS
To spawn extended sprites:
GenExtra:
LDY #$07
ExtraLoop:
LDA $170B,y
BEQ Extra1
DEY
BPL ExtraLoop
RTS
Extra1:
LDA #!ExSpriteNumber
STA $170B,y
LDA $E4,x
STA $171F,y ; X position low byte
LDA $14E0,x
STA $1733,y ; X position high byte
LDA $D8,x
STA $1715,y ; Y position low byte
LDA $14D4,x
STA $1729,y ; Y position high byte
LDA #!ExSpriteYSpeed
STA $173D,y
LDA #!ExSpriteXSpeed
STA $1747,y
LDA #$FF
STA $176F,y
; I'm not exactly sure what the function of $176F is.
; I think it's a misc. table, but I'm not positive...
; Storing to $176F,y may or may not be necessary.
; If you want to store to $1765,y, do it here as well.
; The same would no doubt hold true for $175B,y,
; but I know even less about that table.
RTS
Template for spawning multiple sprites:
SpawnedXSpeed:
db $10,$F0,$14,$EC
SpawnedYSpeed:
db $DA,$DA,$CE,$CE
XOffsetL:
db $0E,$F9,$12,$F6
XOffsetH:
db $00,$FF,$00,$FF ;
YOffset:
db $01,$01,$03,$03 ; this is negative
EndSpawn:
RTS
SpawnSprite:
LDA #$03 ; 4 sprites to spawn
STA $1594,x ;
JSL $02A9DE
BMI EndSpawn
LDA #$01
STA $14C8,y
PHX
LDA #!SpriteNumber
TYX
STA $7FAB9E,x
PLX
PHY
LDY $1594,x
LDA $E4,x ;
CLC ;
ADC XOffsetL,y ;
PLY
STA $00E4,y
PHY ;
LDY $1594,x ;
LDA $14E0,x ;
ADC XOffsetH,y ;
PLY ;
STA $14E0,y ;
PHY
LDY $1594,x
LDA $D8,x ;
SEC ;
SBC YOffset,y ;
PLY ;
STA $00D8,y ;
LDA $14D4,x ;
SBC #$00 ;
STA $14D4,y ;
JSL $07F7D2
JSL $0187A7
LDA #$08
STA $7FAB10,x
LDX $15E9
LDA $1594,x
TAX
LDA SpawnedXSpeed,x
STA $00B6,y
LDA SpawnedYSpeed,x
STA $00AA,y
PLX
DEC $1594,x
BPL SpawnLoop1
RTS
SpawnLoop1:
JMP SpawnLoop
Note that the multiple-sprite-spawning routine example is set to spawn
4 custom sprites with certain offsets and speeds. You can tweak it to suit your needs. I don't have a cluster-sprite-spawning routine, unfortunately, although I'd imagine it would look very similar to the extended sprite-spawning routine.
----------------
I'm working on a hack! Check it out
here. Progress: 64/95 levels.