Banner
Views: 854,281,001
Time:
15 users online: Ayami, Counterfeit, DoodleMyNoodle, ForthRightMC, Janno27, Jern,  KevinM, Lunartoad, MiracleWater, NerDose, orka-bln, PokerFace, TheNightmareKing, WhiteYoshiEgg, Zidan3 - Guests: 113 - Bots: 69 Users: 47,147 (2,481 active)
Latest: Jardeson
Tip: Doors and pipes act strange near screen boundaries. See this to avoid strange issues.Not logged in.
ASM for Beginners: Basic, Basic Codes in 20 minutes
Forum Index - SMW Hacking - SMW Hacking Help - Tutorials - Old Tutorials - ASM for Beginners: Basic, Basic Codes in 20 minutes
Pages: « 1 2 3 4 5 6 7 8 »
Welp, here you probably are, either embarking on your first ASM tutorial or have tried countless others and none have worked. In either case, I think this ASM tutorial is for you. It's designed to be simple, SMW-relative, easy, and most of all very explicit and plain. I'll teach you the easy stuff, and spell everything out. That way, you can do at least a LITTLE asm, right? Better than nothing. Then, if you're lucky, we'll do the harder stuff later. It's for the stuff you can use to make cool gimmicks in levels, but at the same time only being a few lines of code. Mostly, this is for cool stuff that you can add to levels for effects. Nothing complicated.

I'll start at the very beginning. This tutorial might have a lot of words, but it's made for skimming or heavy reading depending on how much you care.

What is ASM?
ASM, or Assembly, is the very basic code that the SNES runs to keep everything going. Sprites, blocks, LevelASM, EVERYTHING, uses this code. On one hand, you can get very very complicated, making 3Dish effects and fancy, gamechanging codes, but on the other, you can create simple things in quick, easy, steps. Note that this information will not try to be accurate, but simply easy to learn, as the accuracy doesn't matter yet in this stage. You can learn the hard stuff later, right? You learn single-digit subtraction first, and then your teacher teaches you all the exceptions and special rules.

Some important terms:
ROM- This is that code that I talk about above! This is all the code for Super Mario World, made into numbers (that's not important; your assembler does that for you!) that the game reads. The sad part about this is that it can't be edited with other code. Sorry, but that's how it works!
RAM- This is a whole bunch of numbers, variables, that the game uses to determine everything. Think of it like a street, actually. Here you are at RAM Lane. The first house, with the address 1, has the number 4 in it. The second house, with the address 2, has the number 66 in it. Each address- we'll talk about this later- is just a "holding place" for a number, and you can access those numbers to find out what they are.
Hexidecimal- Sometimes refered to as hex, this is the proper number system for SNES programming. I know what you're thinking- what? I have to learn all-new numbers? Well, not quite. Hex simply works like this:
Decimal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Hexadecimal: (Hex)
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D
1E
1F
20
21
22
23
24
25

Notice how those "ABCDEF" got stuck in there! It adds (tens-place)A,B,C,D right after (tens-place)9. Lucky for you, this is all you have to learn for now. Use Windows Calculator to switch from decimal to hexidecimal whenever. (All Programs > Accessories > Calculator. Then, go to view > scientific. Type in your value, then press "hex." There you go!)

Accumulator-
This is like a RAM spot, but it can be changed using commands instead. It's the "holding place" for the number you are currently dealing with.

Now, let's finally just set up some actual code.
You need:
Lunar Magic
A ROM saved once with Lunar Magic, named smw.
LevelASM (go to patches section, make sure it's Ersanio's.)
Windows Calculator
Notepad
Xkas

Here's what I have:

Here

Alright. Put all of these things in a folder. Now, some of you are probably worried we are using xkas and LevelASM (complicated stuff, right?) But not to worry- I'll go through that step-by-step too.
Firstly, let's install LevelASM into your rom.
1. Open up the Start Menu. (You know, that little button at the bottom-right part of your screen.)
2. Near the bottom of the panel is "search..." type in "cmd" without the quotes.
3. Wait as it searches...
4. Aha!
5. Right-click on the top one.
6. Select "copy."
7. Now, go to your folder that has all that stuff listed above in it.
8. Right click on a empty space and press "paste."
7. Good, first part over.

Now, let's actually get it working.

1. Double-click that new "cmd" you just put in.
2. Now, this box pops up.
3. Type this, exactly:

xkas level.asm smw.smc

4. This should be the result. If it's not, and you get a error,
type "xkas smw.smc level.asm" instead (without quotes.)
5. Open your rom and start a level to make sure it still works.
6. Now, close your rom. Congrats, you have inserted levelasm. Now you just have to put in the code.

Putting in the code

First, I'm going to teach you two things: LDA and STA. These are codes, that tell the game what to do, the first you will learn. LDA will put a value in the accumulator (that variable that you put stuff in, remember?) and STA will take that value, and put it somewhere you want.

This all simply goes in a notepad document, but in this case do this:
1.Open up levelcode.asm.
2.Press "ctrl+f" at the same time.
3.In the box that comes up, type in "105" (no quotes.)
4. Press enter.
5. That area, right under the level105: and the RTS, is where you will put your code! Now, let's get started.

First, let's talk about what we will be doing. We are going to make some of the game's numbers, like lives, coins, and so on, stay at a value. We will do this by taking a number (LDA) and putting it in the address of the "house" that the game's other number, like lives, go in. So, you'd take a number like 5 and put it in the house for 19, which will make that house, 19, have the number 5. (STA)

Okay, now we get to run wild. Follow this format:

LDA #$__
STA $_____

The first blank is the number you want some number in the game to be. Let's say, 15. Well, just to be sure, you need to convert it to hex. So, get out the calculator, type in 15, and then put in the number you get into that blank. You can only use two-digit numbers. If you have a one digit number, like 3, you have to put a 0 in front, 03, 05, 08, 0B, and so on. More than two? Sorry, you're out of luck.

Now, let's go here! That wonderful little page has all the addresses for the "houses" that each number of SMW lives at. Almost all of them, anyway. So, let's find a entry that we like. How about this?

$7E:0019----1 byte-----Player-----Powerup. #$00 = Small, #$01 = Big, #$02 = Cape, #$03 = Fire.

Oho! The powerup the player has! That's right, it's just a number too.
Now, we can wreak havoc all over! The only thing you need to worry about is that first number, $7E:0019. Get rid of the colon, so it's $7E0019, and then that's it! That's the address to the house! So:
LDA #$02
STA $7E0019

That would make mario have a cape, all the time, in level 105. This is what it looks like to me. Save the file.
Now, go back to the command prompt (that black box) again.
Type in
xkas level.asm smw.smc

or

xkas smw.smc level.asm

depending on which worked last time.

Now, go to level 105 in your game.

Aha! Mario has a cape, awesome.

Now, I'll show a few more examples. Run wild!
Please note that not all addresses you choose will work. Some are bigger than what you can use right now, some have different ways of working, crazy stuff like that. But for now, just find a few and experement.

$7E:0073------1 byte----Flag---Mario is ducking flag.

Oh yeah, flags. Just a FYI, flags are easy. Value 01 is yes, value 00 is no. Okay, so

LDA #$01
STA $7E0073

Save the file, and then do that command prompt thing. Hahaha! Mario is aways ducking.

$7E:0DC2---1 byte----Player-----Reserved item aka Item Box. #$00=None; #$01=Mushroom; #$02=Fire Flower; #$03=Star; #$04=Cape

Oh, sweet. Mario can always have a star in the item box.

LDA #$03
STA $7E0DC2

Cool!

Now, let's do another template.

LDA $_______
CMP #$___
BEQ equal
RTS
equal:
LDA #$__
STA $_____

Now, this one is a little trickier. You can only have one copy of this code running in your entire file, so make sure that's the case.

This code checks to see if some number in SMW is equal to a number of your choosing, and then, if it is, you can load and store a number to it.

LDA $_______ ; Put a address to one of those values in SMW here.
CMP #$___ ; Put the number you want that address to be for it to do the store code here.
BEQ equal
RTS
equal:
LDA #$__ ; The value you want to load
STA $_____ ; the address you want to store it.

Now, how about this: If the powerup is a flower, (number 2,) then mario will have 10 coins. Okay.

LDA $7E0019
CMP #$02
BEQ equal
RTS
equal:
LDA #$0A
STA $7E0DBF

This is what it looks like for me. Save, and do the command prompt thing.

The CMP has the same rules as the LDA from the first code we did.

Okay, here is another. If you have 10 coins, then ,make mario have a cape.

LDA $7E0DBF
CMP #$0A
BEQ equal
RTS
equal:
LDA #$02
STA $7E0019

There you are. Not too hard at all.

If anything goes wrong, if you have any trouble, or questions, etc, just give a post here and I'll try to solve your problem. It makes the tutorial better, so it seems fair it goes here.

Wonderfull, Maxx, just wonderfull! If this had been here when I first started ASM with SMW I wouldn't have had such a struggle!

Give Mario some love?~
Wow thanks Maxx! Now I can learn ASM without videos!
Your layout has been renewed.
Thanks Maxx I finally understand basic asm.
Thanks maxx! Now I can be like carol! Never mind. I need VERY GOOD asm skillz to be like carol (I mean that the asm that carol has)But thanks! Great... Now how can I make Xkas patches...

--------------------
YOUR layout has been removed.

I do non-kaizo beta tests!
Check my profile for more details.

A Mario and Luigi Story: The Universe's Star Demo 2:
50%
Status: Dead until I regain interest. Link to hack thread.

I have a question. I'm using this code here:

LDA $7E0DBF
CMP #$32
BEQ fiftycoinsforflower
RTS
fiftycoinsforflower:
LDA #$03
STA $7E0019

It works, but it's lacking the code necessary for the animation to occur. Now, is this something I could just copy into the code, or do I have to code it myself?

Also, the coding from Levelinitcode.asm from the updated LevelASM patch will only take effect at the level start, am I correct? If so, if I were to set Mario's coins to zero in Levelinitcode.asm, they won't be permanently zero, right?
Maxx, you have explained asm the best. I already knew a bit more past this extent, but it's always helpful to get a good refresher course. great tutorial, I can already think of quite a few gimmicks for some levels! :)
Originally posted by GhastlyFox
I have a question. I'm using this code here:

LDA $7E0DBF
CMP #$32
BEQ fiftycoinsforflower
RTS
fiftycoinsforflower:
LDA #$03
STA $7E0019

It works, but it's lacking the code necessary for the animation to occur. Now, is this something I could just copy into the code, or do I have to code it myself?

Also, the coding from Levelinitcode.asm from the updated LevelASM patch will only take effect at the level start, am I correct? If so, if I were to set Mario's coins to zero in Levelinitcode.asm, they won't be permanently zero, right?

First, the animation can be helpfully done with this code:

LDA $7E0DBF
CMP #$32
BEQ fiftycoinsforflower
RTS
fiftycoinsforflower:
LDA #$03 ; These are comments, they won't mess with anything.
STA $7E0019 ; okay, make mario have a flower...
LDA #$20 ;\
STA $7E149B ;/ Put on the "flashing palettes" timer...
LDA #$04 ;\
STA $7E0071;/ Put on the "get flower" animation....
LDA #$00 ;\
STA $7E0DBF;/ reset coins (so that it doesn't do this code over and over.)


That should do it properly. And yes, about the init, that would work perfectly.

I'm glad you all enjoy it! Keep in mind that this teaches you the super-simple, however, so it works well to begin with but at one point you'll have to move up in tutorials.

Also, not a bad idea with the patches. However, that's fairly advanced. Maybe I'll make some more templates.
VERY well done, this was a simple and easy to understand ASM tutorial.
If only this had been around before i already learned this...

Also, you might consider including INC and DEC commands.

--------------------
aran - Graces of Heaven
Thanks Maxx! The tutorial is really good and easy to understand. I'll try learning ASM one day.
Thanks for the help, Maxx! Two more questions. I noticed that custom blocks used the same functions, but RAM addresses are put into STA differently. For Level ASM, you inserted the RAM address for Mario's powerup status as $7E0019. But for a custom block, it was shortened to $19. Why is this?

Also, can block functions such as STZ be used in other forms of ASM?
Originally posted by GhastlyFox
block functions

What's that? All opcodes works in all forms of ASM.

--------------------
<blm> zsnes users are the flatearthers of emulation
Originally posted by ghostlycool666
Thanks maxx! Now I can be like carol! Never mind. I need VERY GOOD asm skillz to be like carol (I mean that the asm that carol has)But thanks! Great... Now how can I make Xkas patches...

Also made by Maxx

Originally posted by GhastlyFox
Thanks for the help, Maxx! Two more questions. I noticed that custom blocks used the same functions, but RAM addresses are put into STA differently. For Level ASM, you inserted the RAM address for Mario's powerup status as $7E0019. But for a custom block, it was shortened to $19. Why is this?

Also, can block functions such as STZ be used in other forms of ASM?

Because the $7E00 is assumed. Thus, addressing such as $19 and $86 is fine. The $7E is assumed when using direct addressing ($xxxx), so $0DBF is valid. However, you must include the $7E for RAM addresses past $7E1FFF, which is explained by these tables.

World Community Grid: Thread | Team
 
You showed us how to make specific level asm,but what about asm that effects the whole game?Like mario can't ever reach top running speed, for example.

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


Then you would make an xkas patch to hijack a routine, which is explained in Maxx's other thread.

World Community Grid: Thread | Team
 
Yes. Universal hacks like that require a patch over levelASM. Besides, in most cases a simple LDA STA won't help you get any exciting features applicable to a whole game.
Really,then how would I go about doing that?I wanted to make it so mario can't reach top running speed(he changes to running frames)unless I press the spin jump button.

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


This, but it requires a understanding of ASM rather than a ability to fill out these templates.
A very neat tutorial. This is bound to help lots of people. Keep up the good work!

--------------------
Be a cool person and check out this thread and comment on it!
There's custom dimensions and really neat sorcery you can enjoy!
Scrydan does Datapack things to Minecraft - 1.16 Minecraft Java Datapack Requests

Minecraft Randomizer: Scrycrafter
You sir, are a life saver. Thanks a lot!

--------------------
Pages: « 1 2 3 4 5 6 7 8 »
Forum Index - SMW Hacking - SMW Hacking Help - Tutorials - Old Tutorials - ASM for Beginners: Basic, Basic Codes in 20 minutes

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

Copyright © 2005 - 2020 - SMW Central
Legal Information - Privacy Policy - Link To Us


Menu

Follow Us On

  • YouTube
  • Twitch
  • Twitter

Affiliates

  • Super Mario Bros. X Community
  • ROMhacking.net
  • Mario Fan Games Galaxy