Optimize subroutine tail calls
parent
e2cf3e8ee0
commit
59f2a9b312
88
src/main.asm
88
src/main.asm
|
@ -1281,7 +1281,7 @@ ExitMsgs:
|
||||||
|
|
||||||
PlayerEndWorld:
|
PlayerEndWorld:
|
||||||
lda WorldEndTimer ; check to see if world end timer expired
|
lda WorldEndTimer ; check to see if world end timer expired
|
||||||
bne EndExitOne ; branch to leave if not
|
bne EndExit ; branch to leave if not
|
||||||
ldy WorldNumber ; check world number
|
ldy WorldNumber ; check world number
|
||||||
cpy #World8 ; if on world 8, player is done with game,
|
cpy #World8 ; if on world 8, player is done with game,
|
||||||
bcs EndChkBButton ; thus branch to read controller
|
bcs EndChkBButton ; thus branch to read controller
|
||||||
|
@ -1293,20 +1293,18 @@ PlayerEndWorld:
|
||||||
inc FetchNewGameTimerFlag ; set flag to load game timer from header
|
inc FetchNewGameTimerFlag ; set flag to load game timer from header
|
||||||
lda #GameModeValue
|
lda #GameModeValue
|
||||||
sta OperMode ; set mode of operation to game mode
|
sta OperMode ; set mode of operation to game mode
|
||||||
EndExitOne:
|
EndExit:
|
||||||
rts ; and leave
|
rts ; and leave
|
||||||
EndChkBButton:
|
EndChkBButton:
|
||||||
lda SavedJoypad1Bits
|
lda SavedJoypad1Bits
|
||||||
ora SavedJoypad2Bits ; check to see if B button was pressed on
|
ora SavedJoypad2Bits ; check to see if B button was pressed on
|
||||||
and #B_Button ; either controller
|
and #B_Button ; either controller
|
||||||
beq EndExitTwo ; branch to leave if not
|
beq EndExit ; branch to leave if not
|
||||||
lda #$01 ; otherwise set world selection flag
|
lda #$01 ; otherwise set world selection flag
|
||||||
sta WorldSelectEnableFlag
|
sta WorldSelectEnableFlag
|
||||||
lda #$ff ; remove onscreen player's lives
|
lda #$ff ; remove onscreen player's lives
|
||||||
sta NumberofLives
|
sta NumberofLives
|
||||||
jsr TerminateGame ; do sub to continue other player or end game
|
jmp TerminateGame ; continue other player or end game
|
||||||
EndExitTwo:
|
|
||||||
rts ; leave
|
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1335,7 +1333,7 @@ ScoreUpdateData:
|
||||||
|
|
||||||
FloateyNumbersRoutine:
|
FloateyNumbersRoutine:
|
||||||
lda FloateyNum_Control,x ; load control for floatey number
|
lda FloateyNum_Control,x ; load control for floatey number
|
||||||
beq EndExitOne ; if zero, branch to leave
|
beq EndExit ; if zero, branch to leave
|
||||||
cmp #$0b ; if less than $0b, branch
|
cmp #$0b ; if less than $0b, branch
|
||||||
bcc ChkNumTimer
|
bcc ChkNumTimer
|
||||||
lda #$0b ; otherwise set to $0b, thus keeping
|
lda #$0b ; otherwise set to $0b, thus keeping
|
||||||
|
@ -2126,8 +2124,7 @@ WriteBlankMT:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
ReplaceBlockMetatile:
|
ReplaceBlockMetatile:
|
||||||
jsr WriteBlockMetatile ; write metatile to vram buffer to replace block object
|
jmp WriteBlockMetatile ; write metatile to vram buffer to replace block object
|
||||||
rts ; leave
|
|
||||||
|
|
||||||
DestroyBlockMetatile:
|
DestroyBlockMetatile:
|
||||||
lda #$00 ; force blank metatile if branched/jumped to this point
|
lda #$00 ; force blank metatile if branched/jumped to this point
|
||||||
|
@ -3186,7 +3183,7 @@ DoAPTasks:
|
||||||
jsr AreaParserTasks
|
jsr AreaParserTasks
|
||||||
dec AreaParserTaskNum ; if all tasks not complete do not
|
dec AreaParserTaskNum ; if all tasks not complete do not
|
||||||
bne SkipATRender ; render attribute table yet
|
bne SkipATRender ; render attribute table yet
|
||||||
jsr RenderAttributeTables
|
jmp RenderAttributeTables
|
||||||
SkipATRender:
|
SkipATRender:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@ -5614,7 +5611,7 @@ UpdScrollVar:
|
||||||
lda #$00 ; reset vram buffer offset used in conjunction with
|
lda #$00 ; reset vram buffer offset used in conjunction with
|
||||||
sta VRAM_Buffer2_Offset ; level graphics buffer at $0341-$035f
|
sta VRAM_Buffer2_Offset ; level graphics buffer at $0341-$035f
|
||||||
RunParser:
|
RunParser:
|
||||||
jsr AreaParserTaskHandler ; update the name table with more level graphics
|
jmp AreaParserTaskHandler ; update the name table with more level graphics
|
||||||
ExitEng:
|
ExitEng:
|
||||||
rts ; and after all that, we're finally done!
|
rts ; and after all that, we're finally done!
|
||||||
|
|
||||||
|
@ -5996,8 +5993,7 @@ EnterSidePipe:
|
||||||
tay ; and nullify controller bit override here
|
tay ; and nullify controller bit override here
|
||||||
RightPipe:
|
RightPipe:
|
||||||
tya ; use contents of Y to
|
tya ; use contents of Y to
|
||||||
jsr AutoControlPlayer ; execute player control routine with ctrl bits nulled
|
jmp AutoControlPlayer ; execute player control routine with ctrl bits nulled
|
||||||
rts
|
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -6009,9 +6005,9 @@ PlayerChangeSize:
|
||||||
EndChgSize:
|
EndChgSize:
|
||||||
cmp #$c4 ; check again for another specific moment
|
cmp #$c4 ; check again for another specific moment
|
||||||
bne ExitChgSize ; and branch to leave if before or after that point
|
bne ExitChgSize ; and branch to leave if before or after that point
|
||||||
jsr DonePlayerTask ; otherwise do sub to init timer control and set routine
|
jmp DonePlayerTask ; otherwise do sub to init timer control and set routine
|
||||||
ExitChgSize:
|
ExitChgSize:
|
||||||
rts ; and then leave
|
rts ; leave
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -6961,7 +6957,7 @@ GiveFPScr:
|
||||||
FPGfx:
|
FPGfx:
|
||||||
jsr GetEnemyOffscreenBits ; get offscreen information
|
jsr GetEnemyOffscreenBits ; get offscreen information
|
||||||
jsr RelativeEnemyPosition ; get relative coordinates
|
jsr RelativeEnemyPosition ; get relative coordinates
|
||||||
jsr FlagpoleGfxHandler ; draw flagpole flag and floatey number
|
jmp FlagpoleGfxHandler ; draw flagpole flag and floatey number
|
||||||
ExitFlagP:
|
ExitFlagP:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@ -7223,8 +7219,7 @@ RunBBSubs:
|
||||||
jsr PlayerEnemyCollision ; handle player to enemy collisions
|
jsr PlayerEnemyCollision ; handle player to enemy collisions
|
||||||
jmp EnemyGfxHandler ; draw the bullet bill and leave
|
jmp EnemyGfxHandler ; draw the bullet bill and leave
|
||||||
KillBB:
|
KillBB:
|
||||||
jsr EraseEnemyObject ; kill bullet bill and leave
|
jmp EraseEnemyObject ; kill bullet bill
|
||||||
rts
|
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -7321,8 +7316,7 @@ RunHSubs:
|
||||||
jsr GetMiscOffscreenBits ; get offscreen information
|
jsr GetMiscOffscreenBits ; get offscreen information
|
||||||
jsr RelativeMiscPosition ; get relative coordinates
|
jsr RelativeMiscPosition ; get relative coordinates
|
||||||
jsr GetMiscBoundBox ; get bounding box coordinates
|
jsr GetMiscBoundBox ; get bounding box coordinates
|
||||||
jsr DrawHammer ; draw the hammer
|
jmp DrawHammer ; draw the hammer
|
||||||
rts ; and we are done here
|
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------------
|
||||||
; $02 - used to store vertical high nybble offset from block buffer routine
|
; $02 - used to store vertical high nybble offset from block buffer routine
|
||||||
|
@ -7578,9 +7572,9 @@ RunPUSubs:
|
||||||
jsr GetEnemyBoundBox ; get bounding box coordinates
|
jsr GetEnemyBoundBox ; get bounding box coordinates
|
||||||
jsr DrawPowerUp ; draw the power-up object
|
jsr DrawPowerUp ; draw the power-up object
|
||||||
jsr PlayerEnemyCollision ; check for collision with player
|
jsr PlayerEnemyCollision ; check for collision with player
|
||||||
jsr OffscreenBoundsCheck ; check to see if it went offscreen
|
jmp OffscreenBoundsCheck ; check to see if it went offscreen
|
||||||
ExitPUp:
|
ExitPUp:
|
||||||
rts ; and we're done
|
rts
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------------
|
||||||
; These apply to all routines in this section unless otherwise noted:
|
; These apply to all routines in this section unless otherwise noted:
|
||||||
|
@ -7738,7 +7732,7 @@ ExtraLifeMushBlock:
|
||||||
VineBlock:
|
VineBlock:
|
||||||
ldx #$05 ; load last slot for enemy object buffer
|
ldx #$05 ; load last slot for enemy object buffer
|
||||||
ldy SprDataOffset_Ctrl ; get control bit
|
ldy SprDataOffset_Ctrl ; get control bit
|
||||||
jsr Setup_Vine ; set up vine object
|
jmp Setup_Vine ; set up vine object
|
||||||
|
|
||||||
ExitBlockChk:
|
ExitBlockChk:
|
||||||
rts ; leave
|
rts ; leave
|
||||||
|
@ -7797,7 +7791,7 @@ CheckTopOfBlock:
|
||||||
sta ($06),y ; otherwise put blank metatile where coin was
|
sta ($06),y ; otherwise put blank metatile where coin was
|
||||||
jsr RemoveCoin_Axe ; write blank metatile to vram buffer
|
jsr RemoveCoin_Axe ; write blank metatile to vram buffer
|
||||||
ldx SprDataOffset_Ctrl ; get control bit
|
ldx SprDataOffset_Ctrl ; get control bit
|
||||||
jsr SetupJumpCoin ; create jumping coin object and update coin variables
|
jmp SetupJumpCoin ; create jumping coin object and update coin variables
|
||||||
TopEx:
|
TopEx:
|
||||||
rts ; leave!
|
rts ; leave!
|
||||||
|
|
||||||
|
@ -8414,9 +8408,9 @@ StrFre:
|
||||||
InitEnemyObject:
|
InitEnemyObject:
|
||||||
lda #$00 ; initialize enemy state
|
lda #$00 ; initialize enemy state
|
||||||
sta Enemy_State,x
|
sta Enemy_State,x
|
||||||
jsr CheckpointEnemyID ; jump ahead to run jump engine and subroutines
|
jmp CheckpointEnemyID ; jump ahead to run jump engine and subroutines
|
||||||
ExEPar:
|
ExEPar:
|
||||||
rts ; then leave
|
rts ; leave
|
||||||
|
|
||||||
DoGroup:
|
DoGroup:
|
||||||
jmp HandleGroupEnemies ; handle enemy group objects
|
jmp HandleGroupEnemies ; handle enemy group objects
|
||||||
|
@ -9838,7 +9832,7 @@ ChkKillGoomba:
|
||||||
lda Enemy_ID,x
|
lda Enemy_ID,x
|
||||||
cmp #Goomba ; check for goomba object
|
cmp #Goomba ; check for goomba object
|
||||||
bne NKGmba ; branch if not found
|
bne NKGmba ; branch if not found
|
||||||
jsr EraseEnemyObject ; otherwise, kill this goomba object
|
jmp EraseEnemyObject ; otherwise, kill this goomba object
|
||||||
NKGmba:
|
NKGmba:
|
||||||
rts ; leave!
|
rts ; leave!
|
||||||
|
|
||||||
|
@ -10975,8 +10969,7 @@ SetupExpl:
|
||||||
sta Fireball_Rel_XPos
|
sta Fireball_Rel_XPos
|
||||||
ldy Enemy_SprDataOffset,x ; get OAM data offset
|
ldy Enemy_SprDataOffset,x ; get OAM data offset
|
||||||
lda ExplosionGfxCounter,x ; get explosion graphics counter
|
lda ExplosionGfxCounter,x ; get explosion graphics counter
|
||||||
jsr DrawExplosion_Fireworks ; do a sub to draw the explosion then leave
|
jmp DrawExplosion_Fireworks ; do a sub to draw the explosion
|
||||||
rts
|
|
||||||
|
|
||||||
FireworksSoundScore:
|
FireworksSoundScore:
|
||||||
lda #$00 ; disable enemy buffer flag
|
lda #$00 ; disable enemy buffer flag
|
||||||
|
@ -11485,7 +11478,7 @@ YMDown:
|
||||||
ChkYPCollision:
|
ChkYPCollision:
|
||||||
lda PlatformCollisionFlag,x ; if collision flag not set here, branch
|
lda PlatformCollisionFlag,x ; if collision flag not set here, branch
|
||||||
bmi ExYPl ; to leave
|
bmi ExYPl ; to leave
|
||||||
jsr PositionPlayerOnVPlat ; otherwise position player appropriately
|
jmp PositionPlayerOnVPlat ; otherwise position player appropriately
|
||||||
ExYPl:
|
ExYPl:
|
||||||
rts ; leave
|
rts ; leave
|
||||||
|
|
||||||
|
@ -11514,9 +11507,9 @@ PPHSubt:
|
||||||
SetPVar:
|
SetPVar:
|
||||||
sta Player_PageLoc ; save result to player's page location
|
sta Player_PageLoc ; save result to player's page location
|
||||||
sty Platform_X_Scroll ; put saved value from second sub here to be used later
|
sty Platform_X_Scroll ; put saved value from second sub here to be used later
|
||||||
jsr PositionPlayerOnVPlat ; position player vertically and appropriately
|
jmp PositionPlayerOnVPlat ; position player vertically and appropriately
|
||||||
ExXMP:
|
ExXMP:
|
||||||
rts ; and we are done here
|
rts ; we are done here
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
|
|
||||||
|
@ -11524,7 +11517,7 @@ DropPlatform:
|
||||||
lda PlatformCollisionFlag,x ; if no collision between platform and player
|
lda PlatformCollisionFlag,x ; if no collision between platform and player
|
||||||
bmi ExDPl ; occurred, just leave without moving anything
|
bmi ExDPl ; occurred, just leave without moving anything
|
||||||
jsr MoveDropPlatform ; otherwise do a sub to move platform down very quickly
|
jsr MoveDropPlatform ; otherwise do a sub to move platform down very quickly
|
||||||
jsr PositionPlayerOnVPlat ; do a sub to position player appropriately
|
jmp PositionPlayerOnVPlat ; do a sub to position player appropriately
|
||||||
ExDPl:
|
ExDPl:
|
||||||
rts ; leave
|
rts ; leave
|
||||||
|
|
||||||
|
@ -11536,9 +11529,9 @@ RightPlatform:
|
||||||
bmi ExRPl ; and platform, branch ahead, leave speed unaltered
|
bmi ExRPl ; and platform, branch ahead, leave speed unaltered
|
||||||
lda #$10
|
lda #$10
|
||||||
sta Enemy_X_Speed,x ; otherwise set new speed (gets moving if motionless)
|
sta Enemy_X_Speed,x ; otherwise set new speed (gets moving if motionless)
|
||||||
jsr PositionPlayerOnHPlat ; use saved value from earlier sub to position player
|
jmp PositionPlayerOnHPlat ; use saved value from earlier sub to position player
|
||||||
ExRPl:
|
ExRPl:
|
||||||
rts ; then leave
|
rts ; leave
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
|
|
||||||
|
@ -11565,9 +11558,9 @@ MoveLiftPlatforms:
|
||||||
ChkSmallPlatCollision:
|
ChkSmallPlatCollision:
|
||||||
lda PlatformCollisionFlag,x ; get bounding box counter saved in collision flag
|
lda PlatformCollisionFlag,x ; get bounding box counter saved in collision flag
|
||||||
beq ExLiftP ; if none found, leave player position alone
|
beq ExLiftP ; if none found, leave player position alone
|
||||||
jsr PositionPlayerOnS_Plat ; use to position player correctly
|
jmp PositionPlayerOnS_Plat ; use to position player correctly
|
||||||
ExLiftP:
|
ExLiftP:
|
||||||
rts ; then leave
|
rts ; leave
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------------
|
||||||
; $00 - page location of extended left boundary
|
; $00 - page location of extended left boundary
|
||||||
|
@ -11621,7 +11614,7 @@ ExtendLB:
|
||||||
cpy #JumpspringObject ; if jumpspring, do not erase
|
cpy #JumpspringObject ; if jumpspring, do not erase
|
||||||
beq ExScrnBd ; erase all others too far to the right
|
beq ExScrnBd ; erase all others too far to the right
|
||||||
TooFar:
|
TooFar:
|
||||||
jsr EraseEnemyObject ; erase object if necessary
|
jmp EraseEnemyObject ; erase object if necessary
|
||||||
ExScrnBd:
|
ExScrnBd:
|
||||||
rts ; leave
|
rts ; leave
|
||||||
|
|
||||||
|
@ -11855,7 +11848,7 @@ UpToSuper:
|
||||||
|
|
||||||
UpToFiery:
|
UpToFiery:
|
||||||
ldy #$00 ; set value to be used as new player state
|
ldy #$00 ; set value to be used as new player state
|
||||||
jsr SetPRout ; set values to stop certain things in motion
|
jmp SetPRout ; set values to stop certain things in motion
|
||||||
NoPUp:
|
NoPUp:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@ -11950,7 +11943,7 @@ HandlePECollisions:
|
||||||
bcs KSPts ; data obtained from the stomp counter + 3
|
bcs KSPts ; data obtained from the stomp counter + 3
|
||||||
lda KickedShellPtsData,y ; otherwise, set points based on proximity to timer expiration
|
lda KickedShellPtsData,y ; otherwise, set points based on proximity to timer expiration
|
||||||
KSPts:
|
KSPts:
|
||||||
jsr SetupFloateyNumber ; set values for floatey number now
|
jmp SetupFloateyNumber ; set values for floatey number now
|
||||||
ExPEC:
|
ExPEC:
|
||||||
rts ; leave!!!
|
rts ; leave!!!
|
||||||
|
|
||||||
|
@ -12730,7 +12723,7 @@ ChkGERtn:
|
||||||
; $06-$07 - block buffer address
|
; $06-$07 - block buffer address
|
||||||
|
|
||||||
StopPlayerMove:
|
StopPlayerMove:
|
||||||
jsr ImpedePlayerMove ; stop player's movement
|
jmp ImpedePlayerMove ; stop player's movement
|
||||||
ExCSM:
|
ExCSM:
|
||||||
rts ; leave
|
rts ; leave
|
||||||
|
|
||||||
|
@ -13174,9 +13167,9 @@ SetForStn:
|
||||||
sta EnemyIntervalTimer,x ; set timer here
|
sta EnemyIntervalTimer,x ; set timer here
|
||||||
lda #$03 ; set state here, apparently used to render
|
lda #$03 ; set state here, apparently used to render
|
||||||
sta Enemy_State,x ; upside-down koopas and buzzy beetles
|
sta Enemy_State,x ; upside-down koopas and buzzy beetles
|
||||||
jsr EnemyLanding ; then land it properly
|
jmp EnemyLanding ; then land it properly
|
||||||
ExSteChk:
|
ExSteChk:
|
||||||
rts ; then leave
|
rts ; leave
|
||||||
|
|
||||||
ProcEnemyDirection:
|
ProcEnemyDirection:
|
||||||
lda Enemy_ID,x ; check enemy identifier for goomba
|
lda Enemy_ID,x ; check enemy identifier for goomba
|
||||||
|
@ -13902,7 +13895,7 @@ RenderH:
|
||||||
lda #$00
|
lda #$00
|
||||||
sta Misc_State,x ; otherwise nullify misc object state
|
sta Misc_State,x ; otherwise nullify misc object state
|
||||||
lda #$f8
|
lda #$f8
|
||||||
jsr DumpTwoSpr ; do sub to move hammer sprites offscreen
|
jmp DumpTwoSpr ; do sub to move hammer sprites offscreen
|
||||||
NoHOffscr:
|
NoHOffscr:
|
||||||
rts ; leave
|
rts ; leave
|
||||||
|
|
||||||
|
@ -14076,7 +14069,7 @@ SLChk:
|
||||||
lda Enemy_OffscreenBits ; check d7 of offscreen bits
|
lda Enemy_OffscreenBits ; check d7 of offscreen bits
|
||||||
asl ; and if d7 is not set, skip sub
|
asl ; and if d7 is not set, skip sub
|
||||||
bcc ExDLPl
|
bcc ExDLPl
|
||||||
jsr MoveSixSpritesOffscreen ; otherwise branch to move all sprites offscreen
|
jmp MoveSixSpritesOffscreen ; otherwise branch to move all sprites offscreen
|
||||||
ExDLPl:
|
ExDLPl:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@ -14744,7 +14737,7 @@ AllRowC:
|
||||||
lda Enemy_Y_HighPos,x ; check high byte of vertical position
|
lda Enemy_Y_HighPos,x ; check high byte of vertical position
|
||||||
cmp #$02 ; if not yet past the bottom of the screen, branch
|
cmp #$02 ; if not yet past the bottom of the screen, branch
|
||||||
bne ExEGHandler
|
bne ExEGHandler
|
||||||
jsr EraseEnemyObject ; what it says
|
jmp EraseEnemyObject ; what it says
|
||||||
|
|
||||||
ExEGHandler:
|
ExEGHandler:
|
||||||
rts
|
rts
|
||||||
|
@ -16287,8 +16280,7 @@ ContinueGrowItems:
|
||||||
lda #$9d ; load contents of other reg directly
|
lda #$9d ; load contents of other reg directly
|
||||||
sta SND_SQUARE2_REG
|
sta SND_SQUARE2_REG
|
||||||
lda PUp_VGrow_FreqData,y ; use secondary counter / 2 as offset for frequency regs
|
lda PUp_VGrow_FreqData,y ; use secondary counter / 2 as offset for frequency regs
|
||||||
jsr SetFreq_Squ2
|
jmp SetFreq_Squ2
|
||||||
rts
|
|
||||||
|
|
||||||
StopGrowItems:
|
StopGrowItems:
|
||||||
jmp EmptySfx2Buffer ; branch to stop playing sounds
|
jmp EmptySfx2Buffer ; branch to stop playing sounds
|
||||||
|
|
Loading…
Reference in New Issue