.SetBank DEC runningSetBank ; Decrement runningSetBank from 0 to $FF to denote that ; we are in the process of switching ROM banks ; ; This will disable the call to MakeSounds in the NMI ; handler, which instead will increment runningSetBank ; each time it is called STA currentBank ; Store the number of the new ROM bank in currentBank STA $FFFF ; Set the MMC1 PRG bank register (which is mapped to LSR A ; $C000-$DFFF) to the ROM bank number in A, to map the STA $FFFF ; specified ROM bank into memory at $8000 LSR A ; STA $FFFF ; Bit 4 of the ROM bank number will be zero, as A is in LSR A ; the range 0 to 7, which also ensures that PRG-RAM is STA $FFFF ; enabled and mapped to $6000-$7FFF LSR A STA $FFFF INC runningSetBank ; Increment runningSetBank again BNE sban1 ; If runningSetBank is non-zero, then this means the NMI ; handler was called while we were switching the ROM ; bank, in which case MakeSounds won't have been called ; in the NMI handler, so jump to sban1 to call the ; MakeSounds routine now instead RTS ; Return from the subroutine .sban1 LDA #0 ; Set runningSetBank = 0 so the NMI handler knows we are STA runningSetBank ; no longer switching ROM banks LDA currentBank ; Fetch the number of the ROM bank that is currently PHA ; paged into memory at $8000 and store it on the stack TXA ; Store X and Y on the stack PHA TYA PHA JSR MakeSounds_b6 ; Call the MakeSounds routine to make the current sounds ; (music and sound effects) PLA ; Retrieve X and Y from the stack TAY PLA TAX JMP ResetBank ; Fetch the previous ROM bank number from the stack and ; page that bank back into memory at $8000, returning ; from the subroutine using a tail callName: SetBank [Show more] Type: Subroutine Category: Utility routines Summary: Page a specified ROM bank into memory at $8000 Deep dive: Splitting NES Elite across multiple ROM banksContext: See this subroutine in context in the source code References: This subroutine is called as follows: * BEEP_b7 calls SetBank * ChangeCmdrName_b6 calls SetBank * ChangeToView_b0 calls SetBank * CheckForPause_b0 calls SetBank * CheckSaveSlots_b6 calls SetBank * ChooseLanguage_b6 calls SetBank * ChooseMusic_b6 calls SetBank * CHPR_b2 calls SetBank * CIRCLE2_b1 calls SetBank * ClearDashEdge_b6 calls SetBank * ClearScreen_b3 calls SetBank * CLIP_b1 calls SetBank * DASC_b2 calls SetBank * DEATH2_b0 calls SetBank * DETOK_b2 calls SetBank * DIALS_b6 calls SetBank * DrawBackground_b3 calls SetBank * DrawBigLogo_b4 calls SetBank * DrawCmdrImage_b6 calls SetBank * DrawDashNames_b3 calls SetBank * DrawEquipment_b6 calls SetBank * DrawImageFrame_b3 calls SetBank * DrawImageNames_b4 calls SetBank * DrawLaunchBox_b6 calls SetBank * DrawLightning_b6 calls SetBank * DrawScreenInNMI_b0 calls SetBank * DrawSmallBox_b3 calls SetBank * DrawSmallLogo_b4 calls SetBank * DrawSpriteImage_b6 calls SetBank * DrawSystemImage_b3 calls SetBank * DTS_b2 calls SetBank * ex_b2 calls SetBank * FadeToBlack_b3 calls SetBank * FadeToColour_b3 calls SetBank * GetCmdrImage_b4 calls SetBank * GetDefaultNEWB calls SetBank * GetHeadshot_b4 calls SetBank * GetHeadshotType_b4 calls SetBank * GetShipBlueprint calls SetBank * GetSystemBack_b5 calls SetBank * GetSystemImage_b5 calls SetBank * HALL_b1 calls SetBank * HideFromScanner_b1 calls SetBank * IncreaseTally calls SetBank * InputName_b6 calls SetBank * JAMESON_b6 calls SetBank * LL164_b6 calls SetBank * LL9_b1 calls SetBank * LoadHighFont_b3 calls SetBank * LoadNormalFont_b3 calls SetBank * MakeSounds_b6 calls SetBank * MVS5_b0 calls SetBank * PAS1_b0 calls SetBank * PauseGame_b6 calls SetBank * PDESC_b2 calls SetBank * PlayDemo_b0 calls SetBank * PrintCtrlCode_b0 calls SetBank * ResetBankA calls SetBank * ResetBankP calls SetBank * ResetCommander_b6 calls SetBank * ResetScanner_b3 calls SetBank * ResetScreen_b3 calls SetBank * SCAN_b1 calls SetBank * SendBitplaneToPPU_b3 calls SetBank * SendViewToPPU_b3 calls SetBank * SetBank0 calls SetBank * SetDemoAutoPlay_b5 calls SetBank * SetKeyLogger_b6 calls SetBank * SetLinePatterns_b3 calls SetBank * SetNonZeroBank calls SetBank * SetupAfterLoad_b0 calls SetBank * SetupIconBar_b3 calls SetBank * SetupViewInNMI_b3 calls SetBank * SetViewAttrs_b3 calls SetBank * ShowIconBar_b3 calls SetBank * ShowScrollText_b6 calls SetBank * SIGHT_b3 calls SetBank * STARS_b1 calls SetBank * StartEffect_b6 calls SetBank * StartGame_b0 calls SetBank * StopSounds_b6 calls SetBank * SUN_b1 calls SetBank * SVE_b6 calls SetBank * TIDY_b1 calls SetBank * TT24_b6 calls SetBank * TT27_b2 calls SetBank * TT66_b0 calls SetBank * UpdateHangarView calls SetBank * UpdateIconBar_b3 calls SetBank * UpdateView_b0 calls SetBank
Arguments: A The number of the ROM bank to page into memory at $8000
[X]
Subroutine MakeSounds_b6 (category: Sound)
Call the MakeSounds routine in ROM bank 6
[X]
Subroutine ResetBank (category: Utility routines)
Retrieve a ROM bank number from the stack and page that bank into memory at $8000
[X]
Variable currentBank in workspace ZP
Contains the number of the ROM bank (0 to 6) that is currently paged into memory at $8000
[X]
Variable runningSetBank in workspace ZP
A flag that records whether we are in the process of switching ROM banks in the SetBank routine when the NMI handler is called
[X]
Label sban1 is local to this routine