(Solved) PC Out of Range [4.5]

So I've been working on my weapon selection in ChangeToAttack_AdventureBase, building off of what VOLTPT shared here: http://nesmakers.com/viewtopic.php?f=35&t=6002

I had it working so that I could select between sword and projectiles, lock or unlock each one individually, and fire arrows with the proper directional animations. I tried to add two more weapons to the table and set up weapon selection so that if the weapon you chose is locked or out of ammo, it automatically changes your weapon choice and checks the next one down the line. In the process I seem to have broken it, but seemingly not at the script I was working in. I'm new to assembly and have no idea what's happened.

Here's my code:
Code:
   ;; if you would like unlockable weapons, 
    ;; that will be created with the b button
    ;; use this code.
  
    LDA weaponsUnlocked
    BNE +canCreateWeapon
       LDY weaponChoice
       LDA weaponChoiceTable,y
       AND weaponsUnlocked
       BNE +canCreateWeapon
           RTS
    +canCreateWeapon
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ;END UNLOCKABLE WEAPONS
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    TXA
    STA temp ;; assumes the object that we want is in x.

    ChangeActionStep temp, #$02 ;; assumes that "attack" is in action 2
    ;arg0 = what object?
    ;arg1 = what behavior?
    StopMoving temp, #$FF, #$00
    
    ;;; some constants for where to create the sword.
    ;;; Constants do not take up any memory.
        WEAPON_POSITION_RIGHT_X = #$10
        WEAPON_POSITION_RIGHT_Y = #$00
        WEAPON_POSITION_UP_X = #$00
        WEAPON_POSITION_UP_Y = #$F0
        WEAPON_POSITION_DOWN_X = #$00
        WEAPON_POSITION_DOWN_Y = #$10
        WEAPON_POSITION_LEFT_X = #$F0
        WEAPON_POSITION_LEFT_Y = #$00
        WEAPON_OBJECT = #$03
        WEAPON_RIGHT_STATE = #$03
        WEAPON_LEFT_STATE = #$02
        WEAPON_UP_STATE = #$00
        WEAPON_DOWN_STATE = #$01
        
    ;;;;;; VOLTOPT - TO ASSIGN UNIQUE ATTRIBUTES TO SELECTED WEAPON ;;;;
        LDY weaponChoice
        LDA weaponObjectTable,y      	   ;;; load weapon choice
        STA tempC                      	 	   ;;; CHANGE TO CHECK WEAPON
        CMP #$0A                        		   ;;; CHECK WEAPON ONE *OBJECT 0A* (CHAKRA)
        BNE +notWeaponOne                     ;;; if not got check next weapon
            ;LDA myBoomerang                    ;;; this is a new variable set to 0
            ;BEQ +canUseWeaponTwo            ;;; if zero, means weapon has not been fired
                ;JMP +canNotUseWeapon  
                LDA weaponChoiceTable,y      ;;; Checking to see if chosen weapon is locked    
                AND weaponsUnlocked
                BNE +canUseWeaponOneBR    ;;; If not locked, go to weapon behavior(BranchOutOfRange soulution)
                    INC weaponChoice             ;;; Otherwise, change weapon choice and check to next option
                    LDY weaponChoice
                    LDA weaponObjectTable,y
                    STA tempC
                    JMP +notWeaponOne
                +canUseWeaponOneBR
                    JMP canUseWeaponOne
        ;+canShootWeaponOne                   ;;; there is ammo here.
        ;DEC myAmmo
        ;UpdateHudElement #$01                ;;; change this to which element shows myAmmo.
        ;JMP +canUseWeaponOne                ;;; jump to main for change to attack script
    
    +notWeaponOne                                 ;;; next weapon
        LDA tempC                                     ;;; reload weapon choice, not sure if this necessary
        CMP #$01                                       ;;; CHECK WEAPONTWO *OBJECT 01* (ARROWS)
        BNE +notWeaponTwo                       ;;; if not go to next weapon
            LDA myAmmo                             ;;; Checking for ammo
            BNE +canShootWeaponTwo
                JMP canNotShootWeaponTwo
            +canShootWeaponTwo    
                LDA weaponChoiceTable,y        ;;; Checking to see if chosen weapon is locked
                AND weaponsUnlocked
                BNE +canUseWeaponTwoBR       ;;; If not locked, go to weapon behavior(BranchOutOfRange solution)
            +canNotShootWeaponOne    
                    INC weaponChoice                ;;; Otherwise, change weapon choice and check the next option
                    LDY weaponChoice
                    LDA weaponObjectTable,y
                    STA tempC
                    JMP +notWeaponTwo
                +canUseWeaponTwoBR
                    JMP +canUseWeaponTwo
                
    ;+canUseWeaponTwo  
        ;LDA #$01
        ;STA myBoomerang
        ;JMP +canUseWeapon

    +notWeaponTwo                                   ;;; next weapon
        LDA tempC                                      ;;; reload weapon choice, not sure if this necessary
        CMP #$0B                                        ;;; CHECK WEAPONTWO *OBJECT 0B* (MACE)
        BNE +notWeaponThree                     ;;; if not go to next weapon
            LDA weaponChoiceTable,y            ;;; Checking to see if chosen weapon is locked
            AND weaponsUnlocked
            BNE +canUseWeaponThreeBR        ;;; If not locked, go to weapon behavior(BranchOutOfRange solution)
                INC weaponChoice                    ;;; Otherwise, change weapon choice and check the next option
                LDY weaponChoice
                LDA weaponObjectTable,y 
                STA tempC
                JMP +notWeaponThree
            +canUseWeaponThreeBR
                JMP +createWeapon
                
    +notWeaponThree                                ;;; next weapon
        LDA tempC                                      ;;; reload weapon choice, not sure if this necessary
        CMP #$03                                        ;;; CHECK WEAPONTWO *OBJECT 03* (SWORD)
        BNE +notWeaponFour                       ;;; if not go to next weapon
            LDA weaponChoiceTable,y            ;;; Checking to see if chosen weapon is locked
            AND weaponsUnlocked
            BNE +canUseWeaponFourBR          ;;; If not locked, go to weapon behavior(BranchOutOfRange solution)
                JMP canNotUseWeapon             ;;; No more wepon choices, All weapons locked
            +canUseWeaponFourBR
                JMP +createWeapon
        
    +notWeaponFour
        JMP canNotUseWeapon                     ;;; No WEAPONFIVE
    
    ;;;;WOULD ADD MORE WEAPONS HERE, SAME BASIC PREMISE


+canUseWeaponOne
    ;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.
;;; Assumes variable called myAmmo exists.
;;; assumes myAmmo is in hud element 8.
    ;LDA myAmmo
    ;BNE canShoot
    ;JMP canNotShoot
    ;canShoot:
    ;; there is ammo here.
    DEC myAmmo
    UpdateHudElement #$03 ;; change this to which element shows myAmmo.
    TXA
    PHA
    TYA
    PHA
        LDX player1_object
        LDA Object_x_hi,x
            CLC
        ADC #$04
        STA tempA
        LDA Object_y_hi,x
            CLC
        ADC #$04
        STA tempB
        LDA Object_direction,x
        AND #%00000111
        STA tempC
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; Now, we have to create the object.
        ;; We will need to determine the direction
        ;; of the player.
        LDX player1_object
        TXA
        STA temp
        GetObjectDirection temp ;; temp still observed from above.
            ;;; this object's direction is now loaded into the 
            ;;; accumulator for comparison after the macro.
            ;; 0 = down
            ;; 1 = downright
            ;; 2 = right
            ;; 3 = upright
            ;; 4 = up
            ;; 5 = upleft
            ;; 6 = left
            ;; 7 = downleft
            BNE +notDown ;; jump if not equal to zero.
               ;;; CREATE DOWN WEAPON
               ;;; create an object for the weapon.
               ;;; create it at the down positions.
               ;;; create it with the down state
        
        
               CreateObject tempA, tempB, #$01, #$01
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
               JMP +doneWithCreatingWeapon
               
            +notDown
            CMP #$02
            BNE +notRight
            ;;; CREATE RIGHT WEAPON
            CreateObject tempA, tempB, #$01, #$03
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
            JMP +doneWithCreatingWeapon  
                
            +notRight
            CMP #$04
            BNE +notUp
            CreateObject tempA, tempB, #$01, #$00
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
            JMP +doneWithCreatingWeapon
            
            +notUp
            CMP #$06
            BNE +notLeft
            CreateObject tempA, tempB, #$01, #$02
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
            
    +doneWithCreatingWeapon        
    +notLeft        
    PLA
    TAY
    PLA
    TAX
    ;canNotShoot:
    RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    

+canUseWeaponTwo
    ;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.
;;; Assumes variable called myAmmo exists.
;;; assumes myAmmo is in hud element 8.
    ;LDA myAmmo
    ;BNE canShoot
    ;JMP canNotShoot
    ;canShoot:
    ;; there is ammo here.
    DEC myAmmo
    UpdateHudElement #$03 ;; change this to which element shows myAmmo.
    TXA
    PHA
    TYA
    PHA
        LDX player1_object
        LDA Object_x_hi,x
            CLC
        ADC #$04
        STA tempA
        LDA Object_y_hi,x
            CLC
        ADC #$04
        STA tempB
        LDA Object_direction,x
        AND #%00000111
        STA tempC
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; Now, we have to create the object.
        ;; We will need to determine the direction
        ;; of the player.
        LDX player1_object
        TXA
        STA temp
        GetObjectDirection temp ;; temp still observed from above.
            ;;; this object's direction is now loaded into the 
            ;;; accumulator for comparison after the macro.
            ;; 0 = down
            ;; 1 = downright
            ;; 2 = right
            ;; 3 = upright
            ;; 4 = up
            ;; 5 = upleft
            ;; 6 = left
            ;; 7 = downleft
            BNE +notDown ;; jump if not equal to zero.
               ;;; CREATE DOWN WEAPON
               ;;; create an object for the weapon.
               ;;; create it at the down positions.
               ;;; create it with the down state
        
        
               CreateObject tempA, tempB, #$01, #$01
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
               JMP +doneWithCreatingWeapon
               
            +notDown
            CMP #$02
            BNE +notRight
            ;;; CREATE RIGHT WEAPON
            CreateObject tempA, tempB, #$01, #$03
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
            JMP +doneWithCreatingWeapon  
                
            +notRight
            CMP #$04
            BNE +notUp
            CreateObject tempA, tempB, #$01, #$00
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
            JMP +doneWithCreatingWeapon
            
            +notUp
            CMP #$06
            BNE +notLeft
            CreateObject tempA, tempB, #$01, #$02
               ;;; x, y, object, starting action.
               ;;; and now with that object, copy the player's
               ;;; direction and start it moving that way.
               LDA tempC
               STA Object_direction,x
               TAY
               LDA DirectionTableOrdered,y
               STA temp1
               TXA
               STA temp
               StartMoving temp, temp1
            
    +doneWithCreatingWeapon        
    +notLeft        
    PLA
    TAY
    PLA
    TAX
canNotShoot:
    RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
        

+createWeapon
    
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; Now, we have to create the object.
        ;; We will need to determine the direction
        ;; of the player.
        LDX player1_object
        TXA
        STA temp
        GetObjectDirection temp ;; temp still observed from above.
            ;;; this object's direction is now loaded into the 
            ;;; accumulator for comparison after the macro.
            ;; 0 = down
            ;; 1 = downright
            ;; 2 = right
            ;; 3 = upright
            ;; 4 = up
            ;; 5 = upleft
            ;; 6 = left
            ;; 7 = downleft
             BNE +notDown ;; jump if not equal to zero.
                ;;; CREATE DOWN WEAPON
                ;;; create an object for the weapon.
                ;;; create it at the down positions.
                ;;; create it with the down state
            
                LDX player1_object
                LDA Object_x_hi,x
                CLC
                ADC #WEAPON_POSITION_DOWN_X
                STA tempA
                LDA Object_y_hi,x
                CLC
                ADC #WEAPON_POSITION_DOWN_Y
                STA tempB
                    LDY weaponChoice                
                LDA weaponObjectTable,y
                STA tempC
               ;; use this is you want to always create a single object, based on
                   ;; the constant above.
                   ; CreateObject tempA, tempB, #WEAPON_OBJECT, #WEAPON_DOWN_STATE, currentNametable
                 
                   ;;; use this if you want to create a variable object based on 
                   ;;; the weaponChoice varaible.
                   CreateObject tempA, tempB, tempC, #WEAPON_DOWN_STATE, currentNametable
                   
                   LDA #%00110000
                 STA Object_direction,x
                 JMP +doneWithCreatingWeapon
            +notDown
                CMP #$02
                BNE +notRight
                ;;; CREATE RIGHT WEAPON
                LDX player1_object
                LDA Object_x_hi,x
                CLC
                ADC #WEAPON_POSITION_RIGHT_X
                STA tempA
                LDA Object_y_hi,x
                CLC
                ADC #WEAPON_POSITION_RIGHT_Y
                STA tempB
                    LDY weaponChoice
                LDA weaponObjectTable,y
                STA tempC
               ;; use this is you want to always create a single object, based on
                   ;; the constant above.
                   ; CreateObject tempA, tempB, #WEAPON_OBJECT, #WEAPON_RIGHT_STATE, currentNametable
                 
                   ;;; use this if you want to create a variable object based on 
                   ;;; the weaponChoice varaible.
                   CreateObject tempA, tempB, tempC, #WEAPON_RIGHT_STATE, currentNametable
                   LDA #%11000000
                   STA Object_direction,x
                   JMP +doneWithCreatingWeapon
            +notRight
            CMP #$04
            BNE +notUp
                ;;; CREATE UP WEAPON
                LDX player1_object
                LDA Object_x_hi,x
                CLC
                ADC #WEAPON_POSITION_UP_X
                STA tempA
                LDA Object_y_hi,x
                CLC
                ADC #WEAPON_POSITION_UP_Y
                STA tempB
                    LDY weaponChoice
                LDA weaponObjectTable,y
                STA tempC
               ;; use this is you want to always create a single object, based on
                   ;; the constant above.
                   ; CreateObject tempA, tempB, #WEAPON_OBJECT, #WEAPON_DOWN_STATE, currentNametable
                 
                   ;;; use this if you want to create a variable object based on 
                   ;;; the weaponChoice varaible.
                   CreateObject tempA, tempB, tempC, #WEAPON_UP_STATE, currentNametable
                 LDA #%00100000
                 STA Object_direction,x
                 JMP +doneWithCreatingWeapon
            +notUp
            CMP #$06
            BNE +notLeft
                ;;; CREATE LEFT WEAPON
                LDX player1_object
                LDA Object_x_hi,x
                CLC
                ADC #WEAPON_POSITION_LEFT_X
                STA tempA
                LDA Object_y_hi,x
                CLC
                ADC #WEAPON_POSITION_LEFT_Y
                STA tempB
                
                    LDY weaponChoice
                LDA weaponObjectTable,y
                STA tempC
                ;; use this if you want to always create a single object, based on
                ;; the constant above.
                 ;CreateObject tempA, tempB, #WEAPON_OBJECT, #WEAPON_DOWN_STATE, currentNametable
                 
                ;;; use this if you want to create a variable object based on 
                ;;; the weaponChoice varaible.
                 CreateObject tempA, tempB, tempC, #WEAPON_LEFT_STATE, currentNametable
                 LDA #%10000000
                 STA Object_direction,x
                 JMP +doneWithCreatingWeapon
            +notLeft
            
        +doneWithCreatingWeapon
        
:canNotUseWeapon;;;;;;;;;;;;;
    RTS
    
weaponChoiceTable:
    .db #%00000001, #%00000010, #%00000100, #%00001000
    .db #%00010000, #%00100000, #%01000000, #%10000000
    
    
weaponObjectTable:
    .db #$0A, #$01, #$0B, #$03, #$08, #$08, #$08, #$08

and here's what happens when I try to compile:
Code:
C:\Creativity\NESmaker_4_5_6\GameEngineData>asm6 MainASM.nes game.nes demo.txt
pass 1..
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(20):MoveTowardsPoint(30): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(20):MoveTowardsPoint(31): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(20):MoveTowardsPoint(32): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(20):MoveTowardsPoint(50): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(20):MoveTowardsPoint(51): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(20):MoveTowardsPoint(52): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(20):MoveTowardsPoint(53): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(21): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(22): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(23): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(24): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(26): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(27): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(28): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\MoveTowardsPlayer_AdventureBase.asm(29): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(80): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\StopMoving_AdventureBase.asm(2): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\StopMoving_AdventureBase.asm(3): PC out of range.
Routines\BASE_4_5\Game\MOD_AdventureBase\AI_Scripts\StopMoving_AdventureBase.asm(4): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(83): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(86): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(89): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(92): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(95): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(98): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(101): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(104): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(107): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(110): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(113): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(116): PC out of range.
Routines\BASE_4_5\Game\LoadAllSubroutines.asm(119): PC out of range.
demo.txt written.

C:\Creativity\NESmaker_4_5_6\GameEngineData>pause
Press any key to continue . . .

I know I'm close to having this working but these errors aren't pointing to the issue in a way I can understand.
Any thoughts?
 
TakuikaNinja said:
PC out of range means the code is trying to jump too far. Check your JMP instructions.

I condensed my script and that fixed it! Thanks! Once I have it fully working I'll share it over on VOLTPT's thread.
 
Top Bottom