[4.5.9] Move your Inputs out of the Static Bank

smilehero65

Active member
NES Maker puts all your button scripts into the static bank by default, which it really doesn't need to do 99% of the time. With a bit of messing around we can put them all into an empty bank and free up that precious space in 1F.

I'm going to use Bank 1A as that's blank from the start, but you can use any bank of course.

Part One - Moving the Input Read Script

First, in MainGameLoop.asm, we're going to find:

Code:
JSR doHandleInputReads

which is around line 42. Since we're moving our input reads to bank 1A, we just need to tell it to be in that bank first so we change it to:

Code:
        SwitchBank #$1A
            JSR doHandleInputReads
        ReturnBank

Next, in LoadAllSubroutines.asm, find these two lines:

Code:
.include ROOT\Game\Subroutines\doHandleInputReads.asm

;;;further down
.include "GameData\DataBank01_Includes.asm"

Cut and paste them straight in Bank1A.asm. In 1A by default there's some random leftover stuff you can just delete.

If you open up DataBank01_Includes.asm you'll see that it's all your input scripts. So now the code for reading inputs and the input scripts are in a new bank, we need to do few fiddly things so it doesn't keep

Now we load up Subroutines\doHandleInputReads.asm and remove a bunch of bank switches that we don't need any more (and didn't need in the first place). It looks like NES Maker was originally go to be set up to have input scripts in different banks but wasn't fully implemented.

At line 66 there's a bankswitch, we can just delete that:

Code:
    LDy tempBank
    JSR doBankswitchY

Next there are three instances of:

Code:
    LDA TargetScriptBank,y
    STA temp

 
    SwitchBank temp

Which have to be deleted.

And last there are several uses of ReturnBank through the file that need to be deleted.

Part Two - Fixing the Jump Script

(You can skip this if your game doesn't have jumping)

Now, if you compile and load your game it should initially appear to be all done. Left and right will work, but if you try and jump, it'll crash. This is because in the default jump script, there's a switch to Bank 1C to get info like the player's height:

Code:
    SwitchBank #$1C
    LDY Object_type,x
    LDA ObjectBboxTop,y
    CLC
    ADC ObjectHeight,y
    sta temp2
 
    LDA Object_x_hi,x
    CLC
    ADC ObjectBboxLeft,y
    STA temp
    JSR getPointColTable

  ;;there are more further down the script too

These are all constant, they only change when you make changes in the character editor in NES Maker itself. So you can just replace them with numbers.

View attachment 6329

Using values from your character editor the code above becomes:

Code:
    LDA #$0F;; top + height
    sta temp2
 
    LDA Object_x_hi,x
    CLC
    ADC #$02
    STA temp
    JSR getPointColTable

At the bottom of the script is somewhere you need to use jump speed values, these are translated from the editor differently. To find out what values you're using for that, you can open up GameEngineData\ScreenData\ObjectData\monsterObjectStartJumpSpeedLo.dat and monsterObjectStartJumpSpeedHi.dat. If your player object is your first object, their value will be the first in the tables:

View attachment 6330

Also delete the ReturnBank at the end of the file. So with everything changed, my jump script now looks like this:

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
 

    LDA #$0F
    sta temp2
 
    LDA Object_x_hi,x
    CLC
    ADC #$02
    STA temp
    JSR getPointColTable
 
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1
 
    CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
       JMP +doJump
    +checkMore
 
    CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
     CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is prize block .
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
    CheckCollisionPoint temp, temp1, #$0A, tempA ;; check below feet to see if it is ladder.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
     BNE +dontDoJump
          JMP  +doJump
        +dontDoJump
            ;; check second point.
        LDA #$0C
        CLC
        ADC temp
        STA temp
        JSR getPointColTable
        CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                            ;;; if it is (equal), can jump.
                                            ;;; if not, skips jumping.       
        BEQ +doJump
     
        CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$0A, tempA ;; check below feet to see if it is ladder.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
            JMP +skipJumping
+doJump:
    TXA
    STA temp ;; assumes the object we want to move is in x.
    PlaySound #sfx_thump

    LDA #$E0
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA #$03
    EOR #$FF
    STA Object_v_speed_hi,x
     
    TXA
    STA temp ;; assumes the object we want to move is in x.
 ;  change the object's action so that he is in jump mode.

+skipJumping:
 
    RTS

And that does it. The jump script is the only I've seen getting data from other banks, but there might be something else out there. I did this a few months ago and haven't struck any issues yet, but your mileage may vary.

I've attached a zip with the changed asm files in it for reference. I did this on a new install of NES Maker so there shouldn't be anything else changed in there.

Extra Bit

Was messing around with some stuff today (I want more than eight states), and realised you can move
Code:
.include "GameData\ScriptTables.asm"

out of base.asm and put it into the same bank as where you moved your input scripts to. It saves a varying amount of space depending on how many scripts you have, but for me it was like 2% of the static bank. Nothing to sniff at.
Thanks JamesNES!
This really freed a lot of space.

However I have a little issue with Controller 2, and I think it might be related to this.
Controller 2 works just fine, until the player dies.
When that happens, the object assigned with Controller 2 doesn't move or do anything at all.
 

octopusman

Member
I'm on 4.5.9: My issue was that after migrating inputs, my character was not able to jump while near the edge of one side of a solid. This is due to only checking the bottom corner of one side of the player obj and not both (as done by the handle physics to determine if a player has landed on a solid or not). I replicated the logic from the physics script to get my player jumping near the edges of platforms again.
Adjust your player bounding box values and speeds as necessary:

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
    LDA #$0E;;  player bounding box top + player height
    sta temp2
   
    LDA Object_x_hi,x
    CLC
    ADC #$0C ; player bounding box left + player width
    STA temp
   
    LDA Object_x_hi,x
    CLC
    ADC #$04 ; player bounding box left + 1
    STA temp3
   
    JSR getPointColTable
   
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1

    GetCollisionPoint temp, temp1, tempA ;; is it a solid?

    CMP #$01
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
        CMP #$0E
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
    CMP #$07
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
   
    GetCollisionPoint temp3, temp1, tempA ;; is it a solid?

    CMP #$01
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
        CMP #$0E
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
    CMP #$07
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
JMP +skipJumping
+doJump:
    TXA
    STA temp ;; assumes the object we want to move is in x.
    GetActionStep temp
    CMP #$07 ;; Do not allow jump if hurt
    BNE +notHurt
        RTS
    +notHurt
   
     ;  change the object's action so that he is in jump mode.
    ChangeActionStep temp, #$02
   
    LDA #$E0
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA #$02
    EOR #$FF
    STA Object_v_speed_hi,x
       
+skipJumping:  
    RTS
 
Last edited:

octopusman

Member
1 more thing, sorry.
I found a bug where my player was able to jump while having a solid to the left. I changed the player bounding box left value to left +1 and it fixed. YMMV depending on your player bounding box. I updated my post.
 

vanderblade

Active member
For whatever reason, trying to move .include "GameData\ScriptTables.asm" from Base.asm to 1A (the bank I'm using for inputs), as you discuss at the end of your post, causes my player 1 object to freeze and the game to crash. I'd love even that extra 2% at this stage in my game. Any thoughts @JamesNES?
 

JamesNES

Well-known member
For whatever reason, trying to move .include "GameData\ScriptTables.asm" from Base.asm to 1A (the bank I'm using for inputs), as you discuss at the end of your post, causes my player 1 object to freeze and the game to crash. I'd love even that extra 2% at this stage in my game. Any thoughts @JamesNES?
I went and checked for you, the only references to the tables in ScriptTables.asm are in DoHandleInputReads, so if they're in the same bank there'd be no reason it'd be crashing. Maybe there's a bankswitch in one of your input routines?
 

vanderblade

Active member
I went and checked for you, the only references to the tables in ScriptTables.asm are in DoHandleInputReads, so if they're in the same bank there'd be no reason it'd be crashing. Maybe there's a bankswitch in one of your input routines?
Could be.

But now that I have your macro for bankswitching, I no longer need the space since I can store all my custom darw code in another bank. So either way, you helped me again.
 

TheRetroBro

Active member
before i go nuts with this. Im currently using a dash effect that effects players speed and jump distance when dashing....will this muck it up?
 

JamesNES

Well-known member
Only if those routines are using things that aren't in the static bank by default. Some things might include ObjectWidth/height etc that are in 1C.

If your routines just change RAM values then there won't be an issue.
 

TheRetroBro

Active member
Only if those routines are using things that aren't in the static bank by default. Some things might include ObjectWidth/height etc that are in 1C.

If your routines just change RAM values then there won't be an issue.
yeah it just changes the speed as far as im aware. Its Dale Coops hold b to run script
 

JamesNES

Well-known member
Just have a run through it looking for any bank switches, or loading any object stuff from ROM.
 

TheRetroBro

Active member
I'm on 4.5.9: My issue was that after migrating inputs, my character was not able to jump while near the edge of one side of a solid. This is due to only checking the bottom corner of one side of the player obj and not both (as done by the handle physics to determine if a player has landed on a solid or not). I replicated the logic from the physics script to get my player jumping near the edges of platforms again.
Adjust your player bounding box values and speeds as necessary:

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
    LDA #$0E;;  player bounding box top + player height
    sta temp2
  
    LDA Object_x_hi,x
    CLC
    ADC #$0C ; player bounding box left + player width
    STA temp
  
    LDA Object_x_hi,x
    CLC
    ADC #$04 ; player bounding box left + 1
    STA temp3
  
    JSR getPointColTable
  
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1

    GetCollisionPoint temp, temp1, tempA ;; is it a solid?

    CMP #$01
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
        CMP #$0E
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
    CMP #$07
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
  
    GetCollisionPoint temp3, temp1, tempA ;; is it a solid?

    CMP #$01
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
        CMP #$0E
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
    CMP #$07
    BNE +isNotSolid
        JMP +doJump
    +isNotSolid
JMP +skipJumping
+doJump:
    TXA
    STA temp ;; assumes the object we want to move is in x.
    GetActionStep temp
    CMP #$07 ;; Do not allow jump if hurt
    BNE +notHurt
        RTS
    +notHurt
  
     ;  change the object's action so that he is in jump mode.
    ChangeActionStep temp, #$02
  
    LDA #$E0
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA #$02
    EOR #$FF
    STA Object_v_speed_hi,x
      
+skipJumping: 
    RTS
Thanks for this! Absolute life saver!
 

TheRetroBro

Active member
So after implementing a few changes I realized that doing this my ability to jump off slopes was gone.

I don't know if it was by accident on my end but for anyone here in the future who may have some issues after this change, be sure to put in the tile collision check for the slopes in your jump script:

here is my fix to be able to add back in the ability to jump off slopes:

HTML clipboard
LDA #$1F;; top + height
sta temp2

LDA Object_x_hi,x
CLC
ADC #$F ; player bounding box left + player width
STA temp
JSR getPointColTable

LDA Object_y_hi,x
CLC
ADC #$02 ; player bounding box left + 1
CLC
ADC temp2
STA temp1
CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
;;; if it is (equal), can jump.
;;; if not, skips jumping.
BNE +noJumpYet
JMP +doJump
+noJumpYet

CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
;;; if it is (equal), can jump.
;;; if not, skips jumping.
BNE+
JMP +doJump
+
CheckCollisionPoint temp, temp1, #$B, tempA ;; check below feet to see if it is slope up right tile 11
BNE +
JMP +doJump
+
CheckCollisionPoint temp, temp1, #$C, tempA ;; check below feet to see if it is slope downtight tile 12
;;; if it is (equal), can jump.
BNE+
JMP +doJump
+


+noJumpYet

CheckCollisionPoint temp, temp1, #$0A, tempA ;; check below feet to see if it is ladder top platform.
;;; if it is (equal), can jump.
BNE +noJumpYet ;;; if not, skips jumping.
JMP +doJump ;; check second point.
+noJumpYet
LDA #$1F;; top + height
sta temp2

LDA Object_x_hi,x
CLC
ADC #$02
STA temp
JSR getPointColTable
CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
BNE+ ;;; if it is (equal), can jump.
JMP +doJump ;;; if not, skips jumping.
+

CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
BNE +
JMP +doJump ;;; if it is (equal), can jump.
+
CheckCollisionPoint temp, temp1, #$B, tempA ;; check below feet to see if it is slope up right tile 11
BNE +
JMP +doJump
+
CheckCollisionPoint temp, temp1, #$C, tempA ;; check below feet to see if it is slope downtight tile 12
;;; if it is (equal), can jump.
BNE+
JMP +doJump
+
;;; if not, skips jumping.
BNE +checkMore
JMP +doJump
 

smilehero65

Active member
So after implementing a few changes I realized that doing this my ability to jump off slopes was gone.

I don't know if it was by accident on my end but for anyone here in the future who may have some issues after this change, be sure to put in the tile collision check for the slopes in your jump script:

here is my fix to be able to add back in the ability to jump off slopes:
Weird...
When checking the slope collision, try to change #$B and #$C to #$0B and #$0C respectively
 
Top Bottom