Language…
7 users online: drkrdnk, Golden Yoshi,  MarioFanGamer, Oskise, pakkie, Papangu,  Telinc1 - Guests: 249 - Bots: 338
Users: 64,795 (2,377 active)
Latest user: mathew

Sprite/Block/HDMA/ASM Code Library

Link Thread Closed
There are 12 sprite tables, NOT 1. In a sprite, a byte is allocated to each sprite (00-0B), so you need to get rid of all 12 tables. That is done using a loop.

Quote
Doesn't spritexspeed and y need definitions

Yes, SPRITE_X_SPEED is supposed to be $00B6,y and SPRITE_Y_SPEED is supposed to be $00AA,y.
Ok I'll just assume he just didn't feel like searching the ram map.

edit: Ohhhhh so is that why you can only have 12 sprites at once? Isn't there a way to increase that or make a sprite use a freeram address as that table?
I own a community of TF2 servers!

ASMT - A new revolutionary ASM system, aka 65c816 ASseMbly Thing
SMWCP - SMW Central Presents a Product- tion long name

frog

http://esolangs.org/wiki/MarioLANG
Originally posted by edit1754
http://bin.smwcentral.net/5166/PseudoArcTangent_AimRoutine.txt
Here's the tracking/aiming used in my YI Blowhard sprite. It can be adapted for firing at Mario, staring at Mario, following Mario, and probably many other things. Unfortunately, I never bothered to comment it.

EDIT: keep in mind that this doesn't handle "gradual movement". That's a separate piece of code in the Blowhard.


Hm...well, I have to ask: What should I input before JSRing or JSLing to that routine, and what is the output? It seems to be made for 30 frames, but is that for a full circle (so the total number of frames would be 30) or just one quadrant (to the total number of frames would be 120)? And although he said that the routine didn't handle gradual movement, could I use the output of that routine to set a frame?


Edit(-1754): Okay, I tried out a different routine, tweaking it a little bit so that it would use 32 frames and a full 360 degrees. Unfortunately, it didn't quite work...the frames kind of went in the wrong order, which I haven't fixed yet. There really should be a routine that works like that for a full circle. (I also added an option to choose whether it should use 64 frames or 32 by loading different values into A before jumping to the subroutine.)

Oh, also: Maxx, wouldn't that routine halt the sprites' speed but not their animation, so they would be walking in place? Also, sprites that throw stuff might still throw stuff.

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

I'm working on a hack! Check it out here. Progress: 64/95 levels.
We need to get more HDMA routines submitted to this thread. This thread was the reason the old HDMA thread was trashed. Now let's get that going, guys.

I'll kick off with my ancient HDMA gradient example (see first post). Feel free to submit your own, as long as they're significantly different (and don't make it only colour gradients. Parallax scrolling, brightness, etc. would also be nice to see.)
--------> Don't follow "Find Roy's Dignity", my hack. Because it's pretty outdated. <--------
Oh, cool. I've never thought of uploading my HDMA here, so here is one I
whipped up in a few minutes, it's a nighttime-ish gradient.
That reminds me...since background gradients are so common, and since they all have the same format, mightn't it be a good idea to modify the routine so that it has to be used only once? Something like this is what I'm thinking:

LDA #GradientNumber
JSL ActivateHDMABG

...

ActivateHDMABG:

PHB
PHK
PLB
JSR BackgroundGradientMain
PLB
RTL

...

BackgroundGradientMain:

ASL
PHX
TAX
REP #$20
LDA #$3200
STA $4330
LDA GradientPointersRed,x
STA $4332
PHK
PLY
STY $4334
LDA #$3200
STA $4340
LDA GradientPointersGreen,x
STA $4342
PHK
PLY
STY $4344
LDA #$3200
STA $4350
LDA GradientPointersBlue,x
STA $4352
PHK
PLY
STY $4354
SEP #$20
LDA #$38
TSB $0D9F
PLX
RTS

GradientPointersRed:

dw Gradient0Red
dw Gradient1Red
dw Gradient2Red

GradientPointersGreen:

dw Gradient0Green
dw Gradient1Green
dw Gradient2Green

GradientPointersBlue:

dw Gradient0Blue
dw Gradient1Blue
dw Gradient2Blue

Would that be viable? That's pretty much what I'm doing with my HDMA.


Oh, yeah, I do have an HDMA code to post. Yes, it is another background gradient. It's a tan gradient of sorts, designed for a desert.

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

I'm working on a hack! Check it out here. Progress: 64/95 levels.
Originally posted by edit1754
http://bin.smwcentral.net/5166/PseudoArcTangent_AimRoutine.txt
Here's the tracking/aiming used in my YI Blowhard sprite. It can be adapted for firing at Mario, staring at Mario, following Mario, and probably many other things. Unfortunately, I never bothered to comment it.

EDIT: keep in mind that this doesn't handle "gradual movement". That's a separate piece of code in the Blowhard.


Out of curiosity does this require the dynamic sprites patch? I guess I could download it if I have to.

Thanks for this, this should come in handy...
No, it doesn't require the dynamic sprite patch, but that reminds me...I need to bug edit1754 some more to make a more customizable version of that routine. I have a sprite in mind that uses 16 frames for each quadrant (an even number, so there are both horizontal and vertical frames, but no 45-degree one) and requires a routine like that, but I don't know how to make my own. The ideal thing to do would be for the routine to return a value from 00-0F depending on the frame, and 00-03 depending on the quadrant. The latter part would be easy with SubHorzPos and SubVertPos (I think), but the more important part...ugh.


Edit: By the way, I have another subroutine to add. This is a 16-bit version of the hexadecimal-to-decimal conversion subroutines.

Input:
-A = 16-bit value to convert
-8-bit XY (m = 0, x = 1)

Output:
-A = 1s digit of the original number
-Y = 10s digit of the original number
-X = 100s digit of the original number
-$0A = 1000s digit of the original number
-$0B = 10000s digit of the original number
-8-bit AXY (m = 1, x = 1)

HexToDecSuper:

STZ $0A
LDY #$00
LDX #$00

StartCompare4:
CMP #$2710
BCC StartCompare5
SBC #$2710
INC $0B
BRA StartCompare4

StartCompare5:
CMP #$03E8
BCC StartCompare6
SBC #$03E8
INC $0A
BRA StartCompare5

StartCompare6:
CMP.w #$0064
BCC StartCompare7
SBC.w #$0064
INX
BRA StartCompare6

StartCompare7:
CMP.w #$000A
BCC FinishHTD3
SBC.w #$000A
INY
BRA StartCompare7

FinishHTD3:

SEP #$20

RTL

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

I'm working on a hack! Check it out here. Progress: 64/95 levels.
I have a question. You know how some of the automatic marios have those blocks that make mario jump or run right or left fast if he touches them? I can't find them. Can someone tell me the name of them and maybe give me a link? THANKS!!!:)
If i recall correctly, they're called "Boost Blocks" and can be found in the original Blcoktool.

However, this isn't really the right place to ask... This thread is for collecting ASM code, not for asking for certain blocks. Just make sure to look for an appropriate section next time, and don't be afraid to make a new thread (or ask in the "Ask Anything" thread in Basic SMW Hacking) for your questions. :)


 
I'm not quite sure this is the correct place to put this, but I don't know where else it would go. This is a sound-test code I made. Just put this in LevelASM, and you can test out what every sound effect and music value in $1DF9, $1DFA, $1DFB, and $1DFC sound like. (It uses $06F2 and $06F3 as free RAM; you might want to clear the former at level load, although it is not strictly necessary.) The way this code works is, you use L and R to switch between sound banks, and you use Up and Down to switch between sound numbers. Pressing X will play the sound effect or music. Careful, though...if you press X while the sound effect/music value is not a valid number (for example, a value over 61 in $1DFC), it will disable all sound for the rest of the level. And I've tested it only on ZSNES; it might have more severe consequences on other emulators. The sound bank and sound effect number also show up on the status bar.

Here is the code. It isn't the most optimized thing out there, but it works.

Banks:
db $09,$0A,$0B,$0C

PHB
PHK
PLB

JSR ChangeIndex
JSR ChangeSound
JSR ShowBank
JSR ShowSound

LDA $18
AND #$40
BEQ NoSound

LDY $06F2
LDA $06F3
STA $1DF9,y

NoSound:

PLB

RTS

ShowSound:
LDA $06F3
PHA
AND #$0F
STA $0F1A
PLA
LSR #4
STA $0F19
RTS

ChangeSound:

LDA $16
PHA
AND #$F3
STA $16
PLA
AND #$0C
CMP #$04
BEQ DecSound
CMP #$08
BEQ IncSound
RTS

DecSound:
DEC $06F3
RTS

IncSound:
INC $06F3
RTS

ShowBank:

LDY $06F2
LDA #$01
STA $0EF9
LDA #$0D
STA $0EFA
LDA #$0F
STA $0EFB
LDA Banks,y
STA $0EFC

RTS

ChangeIndex:

LDA $18
AND #$30
BEQ NoChangeIndex
CMP #$10
BEQ IncIndex
CMP #$20
BEQ DecIndex
NoChangeIndex:
RTS

IncIndex:
LDA $06F2
INC
AND #$03
STA $06F2
RTS

DecIndex:
LDA $06F2
DEC
AND #$03
STA $06F2
RTS


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

I'm working on a hack! Check it out here. Progress: 64/95 levels.
Does someone have the Mushroom creation code (when it's created from a ?-block)?
This file is something I'm compiling for myself which I update to my file bin once in a while. It contains alot of useful ASM information and credit to who I learned it from, along with some codes I or others made.

(If you put it in the OP call it "Chdata's Library")

It includes not just cool levelASM effects and such but also useful minidiagrams such as...

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;RATS tag - makes the code really start at !FREESPACE + 8 (hex) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!FREESPACE = $168000
org !FREESPACE
db "STAR"
dw Endcode-Startcode
dw Endcode-Startcode^#$FFFF
Startcode:
;[code here]
RTS
Endcode:


I do add alot of stuff from this thread too.

Now if I can't understand why it's useful (or can't understand / even recognize it for anything) I don't include it. Like that decimal to hexidecimal code or whatever it was.
I own a community of TF2 servers!

ASMT - A new revolutionary ASM system, aka 65c816 ASseMbly Thing
SMWCP - SMW Central Presents a Product- tion long name

frog

http://esolangs.org/wiki/MarioLANG
Thanks to you, very much!
edit:

Actually I need 16bit Hex into Decimal represented in 16bit.
I own a community of TF2 servers!

ASMT - A new revolutionary ASM system, aka 65c816 ASseMbly Thing
SMWCP - SMW Central Presents a Product- tion long name

frog

http://esolangs.org/wiki/MarioLANG
I made a code that displays 8-bit ram addresses over Mario's name, mostly for testing out how a RAM address works.

All you do is change the define to what you want to see the values of.

!RAM = $15

LDA !RAM
AND #$0F
STA $0EFA
LDA !RAM
REP 4 : LSR
AND #$0F
STA $0EF9
RTS

This works in levelASM, it should display whatever your $15 button presses are in hex.

You can use any ram address you want as long as it isn't 16-bit. For 16-bit you can just use the code in my LVL num show patch.
I own a community of TF2 servers!

ASMT - A new revolutionary ASM system, aka 65c816 ASseMbly Thing
SMWCP - SMW Central Presents a Product- tion long name

frog

http://esolangs.org/wiki/MarioLANG
Here's a parallax scrolling code, made by me with lotsa help from kaijyuu, for use in LevelASM + Init:

This goes in the init:

LDX #$06 ;the amount of bytes in the scroll table. Should be a multiple of 3
LOOP:
LDA ScrollTable,x
STA $7FA000,x
DEX
BPL LOOP
RTS

ScrollTable:
db $7F,$01,$01
db $10,$01,$01
db $00 ;end byte, don't remove it

For the table:

First byte = Scanline count
Second byte = Low byte of scroll value
Third byte = High byte of scroll value

You don't really need to worry about the low and high scroll values, they will be dynamically changed in this next part.



This goes in the normal level routine:

REP #$20
LDA #$0F02
STA $4330
SEP #$20
LDA #$00 ;last byte of free RAM address
STA $4332
LDA #$A0 ;middle byte of RAM address
STA $4333
LDA #$7F ;first byte of RAM address
STA $4334

;The below code is what you mess around with to get coolsauce effects.
REP #$20
LDA $1E ;Layer 2 X-position
STA $7FA000+$4
LSR
STA $7FA000+$1
SEP #$20

LDA #$08
TSB $0D9F
RTS


The code should make the top half of the background scroll slower than the bottom half. I used $7FA000 as free RAM, though you may choose any, I think.

Haven't tested it either, I really just copypasta'd it from my hack. :P

Note that background vertical scroll should be set to none, or else it will kinda mess up when you scroll the screen up.
Thanks a lot!!!
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.
I add pretty much everything here to my document, but it does need an update lol.
I own a community of TF2 servers!

ASMT - A new revolutionary ASM system, aka 65c816 ASseMbly Thing
SMWCP - SMW Central Presents a Product- tion long name

frog

http://esolangs.org/wiki/MarioLANG
Link Thread Closed