Simple ASM with mouse spirit - lesson one

mouse spirit

Well-known member
LESSON ONE ........


Intro
To start off, i am no expert. I actually got great with GameMaker and "lingo", i think they called it.
But, I have gotten alright at editing code in the NESmaker asm files and ofcourse, workarounds.
I have noticed people asking for some basic knowledge to do with coding with NESmaker.
Links to the other lessons are at the bottom of this post.
I wont cover anything crazy as i am fairly basic, so here we go.....



Common Sights
Here are some 3 letter abbreviations you may come across . I will simplify them.

BNE - Pay attention to NE, Not Equal To.
BEQ - And again here, Equal To.
LDA - This ones easy, Load. (side note,specifically loads A) LDA = Load Accumulator
CMP - Again , easy, Compare
STA - We'll call this Save ( STA = It stores whatever is currently IN the accumulator into RAM) "cuttercross edit"
RTS - Return ( more in depth than that, but lets just say return)
JMP - And finally, Jump. Only one letter off!


So , already you have the tools to code a bit if you can understand these 6 things.
Lets try a sample code example.This is for show, dont try to simply use this example verbatim
in your game, but it could work.This is for learning though.

A Few Tips
Good tip number one, back up your text asm files ,always, before editing,or
atleast use a program like notepad++ that has an undo function, and leave the
code open until you are finally done and it works as expected, or atleast how it started.
I would NOT advise editing within code the NESmaker program, As you cannot undo, as far as i know.

Oh, another thing.Im going to post code, in a code format. To do that here on the forum, as it is
absolutely appreciated all the time ever, you click the icon called "more options" on the far right
above the post you are posting.It brings up a few choices. One of those choices is "code".
To properly use,select all of you code text, then click that button.
cool example 1.png
Rich (BB code):
Like this!
if i remove a piece, heres truly what it looks like...
CODE=rich]Like this![/CODE]

Anyway, moving on.Lets make some codes n stuff.Aaaaafter i explain a variable.
A variable is just that, an amount that can change and certainly be called in code.
In NESmaker, we need to initialize a variable we want to use.
In project settings, you can achieve this by going to the variables tab and creating a new one.
I am choosing coinAmount.

;;;;;;Side note, this is how you comment in code. use a ; symbol before your code starts on that line.
Example
Rich (BB code):
;;;commented out code here
Actual code here

Code
Rich (BB code):
LDA coinAmount        ;(lets say, load up coinAmount, because i want to know if i have 5!)
CMP  #$05                                     ; (this is how we say 5, looks strange,it can be covered later though)
BEQ ++                                          ; (here after we compared coinAmount to 5, we are asking" was it equal to 5?")
                                                       ; (the ++ means, if equal to 5, travel to where the next  ++ is at in this asm.)
;;heres a comment for the next line because... if coinAmount was NOT equal to what we compared to (5), It passes up that last line and ends up here...
RTS                                                  ;( basically do nothing and return to the top and try again if the situation asks for it.
                                                       ;;Whether this code runs all the time or not, depending on where we use it)
++                                                  ;(so if it was 5 coins, we arrive here instead of RTS)(nothing happens here, this is just where we told it to go)

LDA #$00                           ;   ( so we are done asking how many coins, now we want to reset to 0 coins and add a life, because , duh)( so load 0)
STA coinAmount                   ;  (now here we are saving to that variable. We loaded 0, and so we save 0 to coinAmount.)
INC Lives                              ; (we did notcover INC, but im sure you can guess.It increases a value by 1,in this case Lives.)
                                            ;;;;thats it. this is a basic structure of an asm code snippit in a NESmaker text file.
                                           ;;;;;this will repeat itself as needed. But depending on where its located,it may not.so feel free to add an RTS here
RTS
Also note that we structured it in such a way that we will not be given
infinite lives. We orderd it logically, as to ask for 5 coins,remove the coins after the response says yes, then give us a life and
our coins are set to 0 and the loop goes on and on and on, but only "does anything"( gives me a life! ) if we are at 5 coins

Simplified:
Rich (BB code):
LDA coinAmount
CMP  #$05
BEQ ++
RTS
++

LDA #$00
STA coinAmount
INC Lives
RTS

The Wrap Up
Please ask questions.I will try to give good answers.
Maybe dont ask how to code something specific, as this is less of a "problem solving " space.
What i mean is, this is a basic "class". Meant to just teach some basics to help read and write code.
Heres a great link and reference to truly show what 3 letter words mean in code.
Next Time
The next lesson i will try to make it more convoluted but still use simple stuff.
That way when looking at code , no matter how many lines, you will know whats going on
even if not truly.



Links
lesson two
lesson three
 
Last edited:

CutterCross

Active member
Just a quick thing you might want to re-word. STA doesn't store anything into the accumulator. It stores whatever is currently IN the accumulator into RAM, specifically the variable or RAM address you specify. Same goes for its counterparts STX and STY.

STX = Store whatever's in the X register into RAM.
STY = Store whatever's in the Y register into RAM.

They also don't get rid of whatever's loaded into the registers, just copies them to RAM.

Otherwise what you've got is pretty good for beginner-level teaching.
 

PasseGaming

Active member
Thank you Mouse, I was asking for something like this a while back. I think it would be very useful to those who are new to coding. I sure as hell know it was useful to me.
 
Top Bottom