[4.5.9] Move your Inputs out of the Static Bank

JamesNES

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.

1656807553697.png

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:

1656807603743.png

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.
 

Attachments

  • doHandleInputReads.zip
    3.7 KB · Views: 11
Last edited:
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.
This "might" help me free up space man! Thanks!
 

Jonny

Well-known member
I'm glad I read this as there WAS indeedy something I did wrong. For doHandleInputReads.asm I thought I needed to change TargetScriptBank,y to the new bank not just remove it alltogether so will go ahead and comment that out.

So much space for activities in 1F now :)
 

drexegar

Member
Does moving the inputs have a significant slow down with bankswitching on every press? Or its pretty small?
 

JamesNES

Active member
Does moving the inputs have a significant slow down with bankswitching on every press? Or its pretty small?
Bankswitching has virtually no effect on speed! So you can go nuts with it. Just look at the macro, takes almost nothing
 
okay so long story short JameNES I followed your tutorial and it WORKS! but with one issue...
despite it saving loads of space I need in the main bank... sometimes the game will run the input scripts regardless of player input
here's a video describing what I mean:
View: https://youtu.be/3f1P0uFP-Yc


Help?
(also I know this isn't my game dev channel but it's there for the newer private videos I make)
 

TakuikaNinja

Active member
Does the music use DPCM by any chance? It can corrupt inputs (yes, really - this hardware fault was fixed on PAL systems). If this is the case, you should replace the controller polling script with a double read version instead: 2-player double read routine
 
Does the music use DPCM by any chance? It can corrupt inputs (yes, really - this hardware fault was fixed on PAL systems). If this is the case, you should replace the controller polling script with a double read version instead: 2-player double read routine
It uses DPCM yeah but I wanna move my inputs outta the static bank
EDIT: I TRIED IT AND IT FIXED IT... THANK YOU!
 
Last edited:
Top Bottom