Language…
6 users online: Alex No, Darolac, DixyNL, Rykon-V73, synthie_cat,  Tahixham - Guests: 236 - Bots: 383
Users: 64,795 (2,377 active)
Latest user: mathew

Custom Block Tutorial!

Alright, this is a Block Tutorial for ASM!

Let's get started!


1: OFFSETS!

Ok. The first thing you need for your custom block are the offsets. Offsets
are basically what tells the game to do in a certain case. Here's what I
mean:
Code
	JMP MarioBelow

That is an offset. It says to JuMP to a certain section of the code, or a
LABEL, and execute the Code. Pretty simple. They are seperated by a
Colon, : To keep things organized, you should set your labels to every action:
Code
JMP MarioBelow : JMP MarioAbove : JMP MarioSide : JMP SpriteV : JMP SpriteH : JMP MarioCape : JMP MarioFireBall


Now, offsets can be named ANYTHING as long as there is a corresponding LABEL. If you don't know what that means, it means that as long as the OFFSET is linked with a LABEL, you're fine =)
Offsets can also be combined. EX.

JMP Mario and JMP Return can be used if you want to have it work ONLY with specific things and don't want to write out the offsets, like so:
Code
JMP Mario : JMP Mario : JMP Return : JMP Return : JMP Return : JMP Return : JMP Return 


Honestly, I prefer writing them all out, but whichever works for you is better for you, obviously!

Also, there are 3 other offsets that can be used. They are JMP MarioCorner, JMP HeadInside, and JMP BodyInside. These require you to place a
Code
db $42

at the top.

So, what do all of these do???

Here:
MarioBelow = If mario hits the block from below.
MarioAbove = If mario touches the block from Above.
MarioSide = If mario hits the block from either sides.
SpriteV = If any sprite touches it vertically.
SpriteH = If any sprite touches it horizontally.
MarioCape = If mario hits it with his cape.
MarioFireball = If mario hits it with his fireball.
*MarioCorner = If mario hits any of the 4 corners.
*HeadInside = If mario's head is INSIDE the block.
*BodyInside = If mario's body is INSIDE the block.

*REQUIRES
Code
db $42


That's It for Offsets!

2: Labels!

This ones a quicky. Set up your labels like so:
Code
MarioAbove: 
MarioSide: 
MarioBelow:
SpriteV: 
SpriteH:
MarioCape: 
MarioFireBall:

That's all.

3: THE CODE!

Here's the fun part. Here is where you create your code. The possibilities are nearly endless! Let's start
with something simple:
Code
	LDA #$01 ;LoaD the value 01.
	STA $19 ;STore it into the Address $19, the power-up Address
	RTL ;This is important! It ends your code. DO NOT USE RTS!

Ok, if you don't know any ASM, you are going to look at this and say "What is he talking about!?"
It's actually quite simple. We LOAD a value using LDA, and STORE it with STA. When we load a value,
then store it into an address, we are telling the game to take our Value and make the address respond
to that value. Think of this:

You step on something sharp. Your Foot sends a signal to your brain and tells it "OUCH!"
like the game sends the Value we LDA'd to the Address and STA's it. Then your brain sends your foot
PAIN. Just like our Address says, "Yeah, uh, he touched the block, so, uh let's make him big." to the Game!

Let's get more complicated:
Code
	LDA $0DBF
	CMP #50
	BEQ HasCoins
	RTL
	HasCoins:
	LDA $0DBE
	CLC
	ADC #$05
	STA $0DBE
	RTL	

Ok. Let's break it down:
Code
	LDA $0DBF 

This loads mario's coins.
Code
	CMP #50

Now, this one is new, but is VERY useful! CMP means CoMPare. #50. A # means a Decimal value. So,
this:
Code
	LDA $0DBF
	CMP #50

Checks if mario has 50 coins!
Code
	BEQ HasCoins

Ok. BEQ means Branch if EQual. Branch means to go to a section of the code. BEQ will only branch if
the above is true. (In our case, if mario has 50 coins)
Code
	RTL

Otherwise, do nothing.
Code
	HasCoins:

This is a LABEL. When we branch, we need something for the branch to identify.
Code
	LDA $0DBE

Load mario's lives.
Code
	CLC
	ADC #$05

If you do not know ASM, then I might lose you here. Pay attention.

First, CLC. CLC pairs with ADC. What do they do? Well, ADC means to take an address that was loaded
with LDA and ADD a Value to it, in our case 5.

So, we are checking if mario has 50 coins. If he does, we Branch. If not, we do nothing. In the HasCoins
LABEL, we are taking mario's lives, and using CLC and ADC to add 5 to them.

If you want to make this a shop/trade block, just use STZ.

STZ will STore Zero to an Address. So it will look like this:
Code
	LDA $0DBF
	CMP #50
	BEQ HasCoins
	RTL
	HasCoins:
	LDA $0DBE
	CLC
	ADC #$05
	STA $0DBE
	ClearCoins:
	STZ $0DBF
	RTL

If you really want to make a shop block, you would use SDC to subtract 50 from your coins, but I won't
go into that.

So, all together it should look like this:
Code
JMP MarioBelow : JMP MarioAbove : JMP MarioSide : JMP SpriteV : JMP SpriteH : JMP MarioCape : JMP MarioFireBall	

MarioAbove: 
MarioSide: 
RTL
MarioBelow:
	LDA $0DBF ;Load coins
	CMP #50 ; Check if we have 50
	BEQ HasCoins ; If so, branch
	RTL ; Otherwise, do nothing
	HasCoins:
	LDA $0DBE ;Load lives
	CLC ; Add 5 to lives
	ADC #$05 ;|
	STA $0DBE ;Store it to our lives
	ClearCoins:
	STZ $0DBF ;Set coins to 0
	RTL ; End code
SpriteV: 
SpriteH:
MarioCape: 
MarioFireBall:
RTL


4: MORE TO DO!!!

There is A LOT more you can do than explained here. To learn more ASM use either Schwa's or Maxx' Tutorials. They are very good, detailed tutorials.

One more thing I will show you is what I call a Dictionary. What it is is defining something(Address, Value, or whatever) using something like a Variable.

This can be very useful if you are making a large coded block or a customizable block.

So, the way it is used is like this:

Code
!VAR=VALUE


Now, the VAR would be whatever, whether it be !Coins, !Powerup, !KillPlayer, as long as it has the ! in front.

The VALUE is where your address or value goes.

Ex.
Code
!Powerup=$19


So, whenever you want to change a value or address, it is always waiting at the top!

Think of this:

The Dictionary is all of your ! codes are. You need a word, or VAR, and you need a definition, VALUE! It's really easy once you get used to it.

So, to use it you do this:
Code
LDA #$03
STA !Powerup

See, it's as simple as that!

Thanks for reading my tutorial. I have seen A LOT of people requesting CUSTOM BLOCK TUTORIALS specifically.


I will almost ALWAYS be adding on to this. PM me or post if you have a question!
Your layout has been removed.
Erm... I'd say that since this is a 'Block' tutorial and not an 'ASM' tutorial, you really ought to focus more on how to organize the offsets instead of the example code, such as how the offsets can be renamed (and combined into, say, simply 'Mario', 'Return', and 'X' like some people do for neatness), what each offset means, and go over the newer offsets introduced with Lunar Magic 1.64/1.65:

db $42 ; enable corner and inside offsets
JMP MarioBelow : JMP MarioAbove : JMP MarioSide : JMP SpriteV : JMP SpriteH : JMP MarioCape : JMP MarioFireBall : JMP MarioCorner : JMP HeadInside : JMP BodyInside

World Community Grid: Thread | Team
 
@Ultimaximus:

Ok. I have updated the Tutorial.
Your layout has been removed.
Although i already know ASM, you should talk about the other Branch Commands.
Originally posted by My ASM Library
BEQ - Branch only if mario/luigi has the compared amount

BCC - Branch only if mario/luigi has less than the compared amount

BCS - Branch only if mario/luigi has more than the compared amount

BNE - Branch only if mario/luigi don't meet the compared amount. (Basically works the same as BEQ but it's a little different when you use AND)

BPL - Branch only if the amount is in the range of 00-7F in hex (00-127 in decimal)

BMI - Branch only if the amount is in the range of 80-FF in hex (128-255 in decimal)

BRA - Branch always. It's basically useless when you compare something using this seeing as it will always branch


Example of BCC:
LDA $19
CMP #$01 ; If Small/Super. Return
BCC Return
ASL $0DBF ; Else multiply the amount of coins the player has by 2

Return:
RTL



Example of BCS:
LDA $0DBF
CMP #20 ; If mario has 20 coins or more, branch
BCS Fire
RTL

Fire:
LDA $0DBF ;\
SEC ;| Subtract
SBC #20 ;| 20 coins
STA $0DBF ;/
LDA #$02 ;\ Add a Fire Flower to
STA $0DC2 ;/ the Status bar
RTL



Example of BNE:
LDA $13D4
CMP #$01 ; If game is not paused, branch (Note: Compares if the game is paused right now)
BNE Return
LDA #$01 ;\ Make the On/Off
STA $14AF ;/ Flag Off.

Return:
RTL



Example if BPL:
LDA $7B
BPL Water ; If mario is going right, branch
RTL

Water:
LDA #$01 ;\ Make the level a
STA $85 ;/ water level.
RTL



Example if BMI:
LDA $7D
BMI Cape ; If mario is going up, branch
RTL

Cape:
LDA #$02 ;\ Make mario
STA $19 ;/ have a cape
RTL



Example if BRA:
LDA $19
CMP #$01
BEQ Mush
CMP #$02
BEQ Cape
CMP #$03
BEQ Fire
RTL

Mush:
LDA #$03
BRA Storeto19 ; Branch to Store it into $19

Cape:
LDA #$01
BRA Storeto19 ; Branch to Store it into $19

Fire:
LDA #$02

Storeto19:
STA $19
RTL


Hacks I Support:


Not terrible, but not for GPS. Might rewrite later.
Your layout has been removed.