Simple ASM with mouse spirit - lesson two

mouse spirit

Well-known member
LESSON TWO ........

This time we will actually look at one of my overly rediculous codes.
It works, but it aint pretty. I will help you understand my absurd input code.
Please view lesson one to help further understand lesson two as i will try not to repeat too much.
Intro
That was basically the intro, but i guess to go on, this script is long, and its for a
projectile input. i will try to seperate it and show how you can see whats going on.
You may notice alot of commented out code in my script. It doesnt hurt to have comments,
they dont take up lines when the game is created. They can help immensely, especially
when coming back to an old script after a while.

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

INC - Increases a variable value.
DEC - Decreases a variable value.
AND - The way i think of it is, ignore everything except this.

Example: AND #%10101010 (if 10000000 or 00100000 or 00001000 or 00000010 are flagged, then thats what is accepted,
but if any of these spots "01010101" spots are flagged with 1s, they get ignored.Meaning...
spots marked with x's here "0x0x0x0x" are ignored when using AND #%10101010. That way it only pays attention to certain
criteria... i think, basically. Lets go with that for now.

Just One Tip
Put your boots on.
First i will show the whole code, then explain things.



Code
Rich (BB code):
LDA isPaused
BEQ +
RTS
+
LDA canIShoit
CMP #$00
BNE +
JMP doneShooting
+
;LDA gameHandler
LDA weaponsUnlocked
     AND #%00000010
     BNE canAttacker
     JMP doneShooting
     canAttacker:
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;new code for jump attack
LDA Object_physics_byte,x
    AND #%00000001 ;; is it on the ground?
    BNE try1
LDA  leftOrRight
CMP #$01 ;; facing left?
BNE ++
FaceDirection player1_object, FACE_UP_LEFT
JMP+
++
LDA  leftOrRight
CMP #$02;;facing right?
BNE +
FaceDirection player1_object, FACE_UP_RIGHT
+
try1:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;new code for jump attack/button combos allowed
LDA gamepad
CMP #%00010011
BEQ canShoot
CMP #%10010011
BEQ canShoot
CMP #%01010011
BEQ canShoot




LDA gamepad
CMP #%00010010
BEQ canShoot
CMP #%10010010
BEQ canShoot
CMP #%01010010
BEQ canShoot
JMP doneShooting
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
canShoot:


   ;; We count the projectile already on screen to see if can Shoot another one :
   CountObjects #%00000100, #$00   ;; count player weapon on screen
   LDA monsterCounter              ;; the variable used to count is monsterCounter
   CLC
   CMP #PROJECTILE_MAX             ;; compare to 2
   BCC +                    ;; if less than 2 on screen we can create a projectile
   RTS                             ;; else we quit
+
LDX player1_object
;;; check if already shooting
CMP #$06
BNE notAlreadyShooting
JMP wasAlreadyShooting
notAlreadyShooting
+
++
  ChangeObjectState #$03 , #$02
;;;if you wanna stop player comment out next eight lines




LDY player1_object
CPY #$FF;;;;;
BNE playerCanCreateProjectile
RTS
playerCanCreateProjectile:
LDA limitProjectile
BNE continueCreateProjectile
RTS
continueCreateProjectile:


DEC limitProjectile


LDA Object_physics_byte,x
    AND #%00000001 ;; is it on the ground?
    BEQ wasAlreadyShooting


    LDA Object_movement,x
AND #%00001111
STA Object_movement,x
LDA #$00
STA Object_h_speed_hi,x
STA Object_h_speed_lo,x
STA Object_v_speed_hi,x
STA Object_v_speed_lo,x
; if was already shooting
wasAlreadyShooting:


LDA Object_movement,x
AND #%00000111
STA temp2


CMP #%00000100
BCS +
LDA #FACE_RIGHT
STA temp2
JMP++
+
LDA #FACE_LEFT
STA temp2
++






TAY


LDA Object_x_hi,x
SEC
SBC #$08 ;; width
STA temp
LDA Object_scroll,x
SBC #$00
STA temp3


LDA temp;;; offset x for creation
CLC
ADC projOffsetTableX,y
STA temp
LDA temp3
ADC #$00
STA temp3






LDA Object_y_hi,x
CLC
ADC projOffsetTableY,y
sec
sbc #$08 ;; height
STA temp1




         ;;test if player has weaponm 1
       ;LDA weaponsUnlocked
       ;AND #%00000001
       ;BEQ playerDoesNotHaveWeapon1
       ;else weapon 1 is now unlocked

       ;;test if player has weaponm 2
        ;LDA weaponsUnlocked
       ; AND #%00000010
       ;BEQ playerDoesNotHaveWeapon2
       ;else weapon 2is now unlocked


       ; continueCreatingTheProjectileObject:




          CreateObject temp , temp1, #OBJECT_PLAYER_PROJECTILE, #$00, temp3
;;;;x is now the newly created objects x
LDA Object_movement,x
ORA temp2
STA Object_movement,x
LDY temp2
LDA directionTable,y
ORA Object_movement,x
STA Object_movement,x
;PlaySound #SND_SHOOT

++
doneShooting:
;DEC limitProjectile


  RTS

Simplified Seperated Blocks And Examples:

1.


Rich (BB code):
LDA isPaused  ;(the first thing i ask in my input script is, is the game paused?, by loading a variable first...)
BEQ +                                 ;(you may be saying, wheres the compare? well, if we only want to compare to #$00,
                                           ;we actually dont even have to say it, as it is implied by default.Saves a line of code too)
RTS                                      ;( if isPaused equalled "NOT 0", it is paused.Do nothing on input,return to top of script)
+                                        ;;(so if isPaused was 0,meaning not paused at all, lets move on
LDA canIShoit                    ;;;(Now im asking canIShoit {can i shoot} by loading this variable then...)
CMP #$00                          ; (comparing to 0,i do this because i wanted to look at all my lines,but as i said, this is redundant )
BNE +                                  ;(if NOT Equal to 0, go to +)
JMP doneShooting            ; (Jump to doneShooting, which is further down in the code)(This command doesnt ask if
                                            ;equal or not, i am just saying, jump to here no matter what if this line is "active".
+                                         ; (We end up here if NOT Equal to 0)

So in the end, this part asks and answers" is the game paused? Am i able to shoot a projectile?
Also note, if i say" JMP ++" It goes to the next ++ in line (atleast when i code).
Thats why we can have multiple + or ++ in a single script,if arranged properly.
So if not paused and i can shoit......

2.
Rich (BB code):
LDA weaponsUnlocked   ;(Next i asked, is my projectile weapon unlocked?specifically weapon 2?
     AND #%00000010                           ;( explained above. But here we are only comparing the bit for the weapon im asking about in the unlockedWeapons bits/flags )
;;;;;;;;;(So we could put CMP #$00 here, but we dont need to)
     BNE canAttacker                              ;(if not equal to 0,"i know, its not there, its implied again" go down to canAttacker)
     JMP doneShooting                          ;(instead, if this line is active, jump down in the code to doneShooting,which means no go, no shooting)
     canAttacker:                                    ;(we end up here if the projectile weapon is known to be unlocked, game is unpaused, andwe are  in a "canshoot" readiness.

I had all of these checks to make sure i would only fire a projectile when i wanted it to happen in the game during gameplay
in a few different situations.This way i would never fire in the situations that im not supposed to.

3.

Rich (BB code):
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;new code for jump attack
LDA Object_physics_byte,x         (this is loading the physics bytes so i can ask about if we are on the ground or not.)
    AND #%00000001                   ;; is it on the ground?(here we ask that it only pays attention to the ongroundflag)
    BNE try1                                  (if not equal to 0, go down to try1)
LDA  leftOrRight                           (if equal to 0, now i wanna ask am i facing left or right, loading a variable i made)
CMP #$01                                    ;; facing left?
BNE ++
FaceDirection player1_object, FACE_UP_LEFT (this command faces me in a certain direction as long as i set up animations coreectly)
JMP+
++
LDA  leftOrRight
CMP #$02;;facing right?
BNE +
FaceDirection player1_object, FACE_UP_RIGHT
+
try1:

I stopped commenting because it get redundant looking.I bet you are starting to grasp it
and could even understand the last part without the comments.
The Wrap Up
Im not gonna run through that whole script because i think this was good enough for now.
Im not here to show off my "skills" for make a looooong input script.....
And this is just for a projectile! Alot of my games code was input oriented.

Next Time
I think jumping around a script will be next. JMP's can be very usefull and bypass what
would otherwise create errors because of the rules of code here.I'll explain simply
next time.


Links
lesson one
lesson three
 
Last edited:
Top Bottom