Simple ASM with mouse spirit - lesson three

mouse spirit

Well-known member
LESSON THREE ........
For anyone wondering, i am using 4.1.5. These rules should still apply,but you will
see some commands or code that wont work in 4.5, such as GetCurrentActionType player1_object.
That may be in 4.5, i have no clue. Just guessing.

Intro
Be sure to check out lesson one and two before this one.
Here we are going to learn how to move around a script with code.
Using stuff like + , ++ , here: , thisPlaceNow: , canShoot: , and JMP.

More Common Sights
Here are some 3 letter abbreviations you may come across . I will simplify them.
But it can seem more complex than last lesson.

SEC - Set- (But truly, Set Carry)
SBC - Subtract - (But truly, Subtract Carry) (There is no way to subtract without the carry which works as an inverse borrow.)
"i.e, to subtract you set the carry before the operation. If the carry is cleared by the operation, it indicates a borrow occurred."
But lets stick with just Subtract for simplicitie's sake.
CLC - Clear....... Carry
ADC - Add (But truly, Add Carry. There is no way to add without carry)

Note that these all have to do with Carry. INC and DEC do not.
They are quite literally increments(and decrements),meaning by 1, or small bits.
They only do 1 at a time, whereas with ADC and SBC ,we can save ouselves alot of
lines by not going only 1 at a time. Imagine that Carry is our value we are messing with.
To make it simpler, most likely you usually want to...

LDA Something,like a variable that equals... 0, or just a value like #$00. (doesnt need to be 0, just an example)
SEC Set the Carry here. It sets to whats currently Loaded, we loaded 0.
SBC Now we could subtract #$08 from the Carry which is #$00.(A nice way to "go below 0")
STA temp1 Lets save it as temp1
And so when adding.....

LDA temp1 ( which we currently are at "-8".Not technically, i dont think there are negative numbers.
But imagine we are at -8. Don't worry about all that really, its ok because.....
CLC ...we are Clearing the Carry here. (We dont have to clear,it depends on the situation truly.
Buuuut if we didnt clear it, we would be at -3 when we add this next 5 !)
ADC #$05 Then we add to carry here. lets say 5 (#$05)

What did we do? 0-8= -8 then -8=0 then 0+5=5. Why you ask?
Just to show that you should/can CLC and SEC at certain times, but basically
its just adding and subtracting. Or you can simply say "222=0" by CLCing.
Cool stuff.Feel free to correct me on anything here.


Some Tips
Now flip on some House of Pain, we's 'bout ta jump around....
Or some Kriss Kross...

When we JMP , our limit on amount of lines we can jump is 76 (i actually cant remember).
When we just BNE , or BEQ , we are more limited.We will say 38 lines.(also cant remember)(i will look these up)
Yeah so remember or think of BNE and BEQ as small jumps, and JMP's as bigger jumps.
That will come into play, and obviously JMP doesnt ask Equal To or Not Equal To, it just jumps.

So here is my madeUpThis.asm
Code 1

Rich (BB code):
LDA isPaused
BEQ +
RTS      ;;(so lets put some garbage in between to make some lines)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(ect.....)
((french accent)"30... lines.... later")
+
(sometimes NESmaker will give you an Out Of Range Error. Many times it is because
you juuuust went over the line limit for skipping lines.But what can you do.......?)


    RTS
Daddy Mac'll Make ya... JMP! JMP!
Lets JMP instead. But in order to do that ,we have to rethink our question....

Rich (BB code):
LDA isPaused
BNE ++  (in order to put a JMP in after our answer,we have to kinda reverse our thinking)
JMP +    (the reason we BNE'd instead of BEQ, is because we have to skip this JMP if Not Equal To.)
++           (So the same thing happens,we just had to ask the other question.This is easy to do,
unless we have many questions.More on that later.)
RTS    ;;(so lets put some garbage in between to make some lines, again)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(Imagine code here)
(ect.....)
((french accent)"30... lines.... later")
+
(now depending on what the error was truly talking about,but lets assume it was this asm,
it should be fixed!This was an example of how to use JMP to aid skipping lines, but it can be
used whenever you want, within reason.)


    RTS

Now what if i dont ask a question?
Code 2

Rich (BB code):
LDA isPaused
JMP ++  (Our code here would never do anything else)
JMP +
++         (it would only end up here every time.)
RTS

Why Use JMP, if not to go far?
I'd say, if youdont wanna ask a question and/or you want to skip some code.
Code 3

Rich (BB code):
LDA currentHealth        ;(check my health against 0)
CMP #$00
BNE amAlive                 ;(if anything but 0, i live!)
JMP amDead               ; ( if 0, im dead. this way we skip all that code below untill amDead: )
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
amAlive:                      ; ( if im alive, check if i just leveled up!please!)
LDA currentXP
CMP maxXP
BNE ++         ;( if i did not)
(imagine code here)  (if i did)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
RTS
++
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
JMP ++            ;(to skip creating the "you are dead" message directly below here)
amDead:                ;( so notice, this line can only be reached by jumping to it,its blocked off from above)
(imagine code here)
("play text that says "you are dead"" code here)
++
RTS

What about if i have several questions or compares in a row?
What are some good ways to ask them?Well....
If you wanna know whether or not you have 7 coins,
theres no need to ask if we have 0,1,2,3,ect...
We just need to say BEQ to #$07.
But what happens when i need to BEQ And can only BNE because i wanna JMP too?!
Sometimes you just gotta get in there and try different things.
So in short, try not to ask a billion questions, boil it down to just one when you can.
Code 4

Rich (BB code):
LDA currentHealth
CMP #$08
BEQ amAlive    
CMP #$07
BEQ amAlive
CMP #$06
BEQ amAlive
CMP #$05
BEQ amAlive
CMP #$04
BEQ amAlive
ect......
;(or it can end up looking like this.Try to think logically and keep it simple and short
whenever possible.)
What if you need to jump further?!
What about the legendary double jump?!

Code 5

Rich (BB code):
BEQ ++                            ;(If Equal To, do all this code down here)
JMP toHere                      ;(If  NotEqual To, double jump/skip all this code down here)
++
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine 40 more line of code here)
JMP skipDoubleJump    (here we need to "skip"(jump) the 2nd jump because we arent "double jumping".)

toHere:
JMP nowHere    (here we are... a JMP to a JMP. Properly skipped when not "double jumping".)

skipDoubleJump:
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine code here)
(imagine 40 more line of code here)
nowHere:                 (whether we jumped or not, we end up here.)
RTS
The Wrap Up
I hope i'm doing an alright job of simply explaining things.Let me know, and
ask questions if you wanna.

Next Time

I'll think of something.


Links
lesson one
lesson two
 
Last edited:
Top Bottom