Language…
17 users online:  Ahrion, Anas, anonimzwx, autisticsceptile1993, Batata Douce, codfish1002, Foxy_9000_, Hammerer, Housemeister, LuigiTron, magianegra21, Mario's GameBase, Maw, NewPointless, playagmes169, ppp9q, sinseiga - Guests: 261 - Bots: 357
Users: 64,795 (2,376 active)
Latest user: mathew

Sprite/Block/HDMA/ASM Code Library

Link Thread Closed
Here is a code I wrote yesterday to check how many specified map16 tiles are in a level (not counting sublevels too). To be used with "LevelASM + INIT"'s INIT routine. The code is somewhat sloppy (I think) and increases the level fade-in time a bit. But I couldn't really find a way to improve this.

I/O:
In: $7E0000: 24-bit pointer to a table with specified map16 tiles.
In: $7E000E: 16-bit size of the table with specified map16 tiles, minus 2.
Out: $7E0006: 16-bit result of how many specified map16 tiles there are within the level. $06 = Low byte, $07 = high byte.

Here is an example usage, which counts the amount of map16 tiles $0000, $002B, $0130, $0132 and $0200 present in the level:

Code
CompareTable:	dw $0000,$002B,$0130,$0132,$0200
.end
levelinit105:

Main:	REP #$10
	LDA.b #CompareTable
	STA $00
	LDA.b #CompareTable>>8
	STA $01
	LDA.b #CompareTable>>16
	STA $02
	LDY.w #CompareTable_end-CompareTable-$02
	STY $0E

	JSL Count
	LDY $06
	STY $0EF9
	SEP #$10
	RTS

Count:	PHP
	SEP #$30
	PHA
	PHY
	PHX
	STZ $06
	STZ $07
	REP #$10
	LDX #$37FF
Loop:	SEP #$20
	LDA $7FC800,x
	XBA
	LDA $7EC800,x
	REP #$20
	LDY $0E
InLoop:	CMP [$00],y
	BNE SkipIn
	INC $06
SkipIn:	DEY
	DEY
	BPL InLoop
	DEX
	BPL Loop
	SEP #$30
	PLX
	PLY
	PLA
	PLP
	RTL


You could make a level where you have to collect every single coin without counting them yourself for example. No hardcoded blocks etc.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lose Yoshi Routine ;;
;; This routine will cause Mario to lose Yoshi as if hit by an enemy ;;
;; By SMWEdit/Edit1754 ;;
;; Based off code starting at $02:A469 SNES ($01:2669 PC) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LOSEYOSHI


wouldn't it be
LOSEYOSHI:
??

Also if I where to insert that as a patch somehow, would I be able to make some kind of custom block that does this...

[JMPS here]
JSL LOSEYOSHI
RTL
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 Fakescaper
Also if I where to insert that as a patch somehow, would I be able to make some kind of custom block that does this...

[JMPS here]
JSL LOSEYOSHI
RTL


No, if your freespace for the patch was $13B6E8, for example, you would do:

[JMPS here]
JSL $13B6E8
RTL

JLS LOSEYOSHI, would go to the label called LOSEYOSHI, not the address.
Background image by Tzadkiel & Anomalin
It would actually be a few bytes higher if you have a RATS tag.
So if I were to make it a patch (which I don't know how to do yet, I'm only doing things like editing levelASM right now)

Wouldn't it just cause you to lose yoshi as soon as you touch him though? Or would it be ok?
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
depends on where you hook it too. Hooks are the part of the code SMW runs, but you hijack to run your code. If you hooked it to a piece of code that always runs, you would lose yoshi as soon as you touch hi (with some side effects of course).
hook example:

Code
Code_123456:
LDA #$01
STA $19
[...]


which in hex would be:
Code
 A9 01
85 19

4 bytes, the same as a JSL $XXXXXX. So then
Code
org $123456 ;originate your code at the start of the LDA #$01...
JSL Main
org !FREESPACE ;originate at freespace designated by a definition
Main: 
;loseyoshicode
LDA #$01
STA $19
RTL

you would lose yoshi everytime the code at $123456 is executed. Hope that helps.
Wait I just realized... is that code supposed to be used as a custom block how it is?
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
Does anybody have the 'Reset the Game' code?
Background image by Tzadkiel & Anomalin
Not sure but you could try STZ $0100.
Originally posted by Iceguy
Not sure but you could try STZ $0100.

I tried this, the game gets :( when you do. I doubt there is any sort of prep code you can do that will let it run properly.
JSL $008000 wouldn't work either, I suppose?

Also, I don't know if this is the best place to ask, but...remember when Iceguy showed off a video of his and Bio's pause menu? Remember the "save game" option? I'd be curious to know what routine that is, what should be called if one wants to save the game at any given moment, such as in the middle of a level. I think somebody else was also asking about that.

I guess I might as well ask another thing, too...what exactly does that routine 1024 posted do? Does it...well, if I wanted to check the Map16 tile number at, say, X-position 36 and Y-position 0A, would that enable me to do so? Or if I wanted to check the Map16 tile number exactly 4 tiles to the right of the current block being processed, could I do that as well? How exactly would I use it? (And I don't suppose anyone has a version of it without all that disassembler junk after the semicolons, do they?)

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

I'm working on a hack! Check it out here. Progress: 64/95 levels.
There's nothing stopping you from doing resets at runtime except the SPC which is impossible to reset without some manual work (or just pushing that button on your snes).

I tested this block together a bunch of times and it seemed to work:

Code
JMP Mario : JMP Mario : JMP Mario : JMP Return : JMP Return : JMP Return : JMP Return

Mario:
	STZ $4200	;no interrupts from here on out
	SEI
	SEP #$30	;request upload
	LDA #$FF
	STA $2141
	LDA #$00	;DB must be zero, this is done by the h/w normally
	PHA
	PLB

	STZ $420C	;disable any HDMA, this is done by the h/w normally
	JML $008016

Return:
	RTL


The code should work anywhere actually. Just don't forget the 2141, DB switch and $008016 jump instead of $008000. STZ $2141 trashes the FF I wrote here to make it upload stuff. I took some SPC code notes while I'm at it but I'm not posting walls of code since SPC hackers are almost non-existant here.

;----

1024's code is mostly disassembled SMW code that puts a map16 # at a given location (by 16bit $98 and 16bit $9A) into CHKTILE and CHKTILEB.
Fireball Contact
Shatter Block
The fireball contact routine was posted earlier in this thread, I uploaded it to the file bin. The shatter block routine was in one of my first blocks. Feel free to put the links in the first post again.
Here's another version of my pointer subroutine. This one should be JSL-able.

ExecutePointer16BitOutside:

; this subroutine can be JSL'd to, unlike my other version,
; which had to remain within the current bank
; Note: The code assumes that $05-$06 already contained the starting address of the pointer table.
; (For example, you can LDA PtrsStart STA $05 INC STA $06 in 8-bit mode.)

PHA ; preserve our index
PHB ;
PLA ;
STA $09 ; get the data bank from before into the bank byte of the pointer
PLA ; pull our index back
REP #$30 ; 16-bit AXY
AND.w #$00FF ; clear the high 8 bits just in case
ASL A ; multiply the base value by 2 since the pointers are 16-bit
PHX ; preserve X
TAX ; transfer to X, our index
LDA ($05,x) ; load an address from the address in $05-$06, plus whatever our index is
STA $07 ; that depends on the index
SEP #$30 ; go back to 8-bit AXY
PLX ; pull back X
PHK ; push a 24-bit return address:
PER Return-$01 ; bank byte first, then the two lower bytes
JML [$0007] ; jump to the set pointer
Return: ;
RTL ;

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

I'm working on a hack! Check it out here. Progress: 64/95 levels.
And how about a code to make a sprite to get hitpoints?
Fierce Deity is cool.
Workin' in OW request...
Currently attendind Scape Santa, but I don't know what to do...
Ok so I have successfully made an xkas patch that puts in the loseyoshi routine, and a custom block that makes you lose yoshi.

But I don't understand how to make yoshi run away faster???

LDY $157B,x ; \
PHX ; | set Yoshi's
TYX ; | running-away
LDA $02A4B3,x ; | X speed
PLX ; |
STA $B5,x ; /

I don't understand this. What to do change? Or preferably, with the custom block can I set yoshi's speed to make him run very fast?

Also on another note, I've tried to replicate the Brutal Mario levelASM that causes sprites to freeze in place when you hit a blue POW, but STZ'ing the ram addresses for the sprite x and y speed tables didn't work. Same with the x or y positions. I even tried putting a ,x thing after it but it didn't work. Any idea on how to freeze sprites that way without making it a custom sprite?

I figured out what to do with
LDA $02A4B3,x ; | X speed
I basically made the patch hex edit the table there to $50,$50 since that was pretty fast, which was perfect. Although I think I shouldn't overwrite that because I dunno what it's used for. In other words I'll set it with the freespace or something.
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 projectile Xspeed routine I ripped straight from SMB3's hammer powerup throwing routine, tweaked so that it can be used in SMW.

If you played SMB3, then you know that hammers go at different Xspeeds depending on Mario's speed. This routine does that too.

I/O
In: nothing
Out: nothing

Indices
X: Index to sprite getting spawned
Y: Unused

Run how many times
1 frame.

When to run the code
At a sprite creation routine. This routine sets the initial x-speed of the spawned sprite.

You can see a demonstration of this code here.

Code
;AXY = 8-bit.
!Type = $1747			;$1747 = Extended sprites,
				;$B6 = Regular sprites.
				;$182C = Minor extended sprites.

		STZ $00		;initialize scratch RAM
		LDA $76
		CLC
		ROR A
		ROR A
		EOR $7B
		BPL +
		LDA $7B
		STA $00
+		LDA #$10
		LDY $76
		BNE +
		EOR #$FF
		INC A
+		CLC
		ADC $00
		STA !Type,x	;Store into somespritetype's X speed


My blog. I could post stuff now and then

My Assembly for the SNES tutorial (it's actually finished now!)
Originally posted by Fakescaper
Also on another note, I've tried to replicate the Brutal Mario levelASM that causes sprites to freeze in place when you hit a blue POW, but STZ'ing the ram addresses for the sprite x and y speed tables didn't work. Same with the x or y positions. I even tried putting a ,x thing after it but it didn't work. Any idea on how to freeze sprites that way without making it a custom sprite?


I'm not sure this is the way, but try setting the Sprites Locked timer to the P-switch length when a p-switch is hit:


Code
$7E:009D	1 byte	Sprites	Lock sprites timer
Not quite lolcats. That causes Mario to mess up his frames and there is no sprite interaction possible.

Actually, try this:


LDY #$0B
Loop:
LDA #$00
STA $SPRITE_X_SPEED,y
STA $SPRITE Y_SPEED,y
DEY
BEQ done
BRA loop
done:


There you go. That runs a loop so it affects every sprite. This is because that RAM address is actually a series of 12, one for each sprite, so you have to get rid of every single one.
Huh? How exactly does that work. I mean, how does it effect ram addresses at all. Doesn't spritexspeed and y need definitions, and that would just be the ram addresses for that anyways?


Also yeah I've already tried sprites locked and got some crazy weird stuff. But mainly it disables clipping.
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