Optimize checks on upper bit

refactor
Christophe Parent 2024-03-02 11:11:12 -08:00
parent 0b81c08d8d
commit 609828b274
1 changed files with 22 additions and 46 deletions

View File

@ -3480,8 +3480,7 @@ ProcADLoop:
bpl RdyDecode ; if buffer not negative, branch, otherwise
iny
jsr AreaDataBankSwitch ; get second byte of area object
asl ; check for page select bit (d7), branch if not set
bcc Chk1Row13
bpl Chk1Row13 ; check for page select bit (d7), branch if not set
lda AreaObjectPageSel ; check page select
bne Chk1Row13
inc AreaObjectPageSel ; if not already set, set it now
@ -6662,8 +6661,7 @@ FireballXSpdData:
FireballObjCore:
stx ObjectOffset ; store offset as current object
lda Fireball_State,x ; check for d7 = 1
asl
bcs FireballExplosion ; if so, branch to get relative coordinates and draw explosion
bmi FireballExplosion ; if so, branch to get relative coordinates and draw explosion
ldy Fireball_State,x ; if fireball inactive, branch to leave
beq NoFBall
dey ; if fireball state set to 1, skip this part and just run it
@ -7394,8 +7392,7 @@ MiscLoop:
stx ObjectOffset ; store misc object offset here
lda Misc_State,x ; check misc object state
beq MiscLoopBack ; branch to check next slot
asl ; otherwise shift d7 into carry
bcc ProcJumpCoin ; if d7 not set, jumping coin, thus skip to rest of code here
bpl ProcJumpCoin ; otherwise, if d7 not set, jumping coin, thus skip to rest of code here
jsr ProcHammerObj ; otherwise go to process hammer,
jmp MiscLoopBack ; then check next slot
@ -7541,8 +7538,7 @@ PowerUpObjHandler:
stx ObjectOffset
lda Enemy_State+5 ; check power-up object's state
beq ExitPUp ; if not set, branch to leave
asl ; shift to check if d7 was set in object state
bcc GrowThePowerUp ; if not set, branch ahead to skip this part
bpl GrowThePowerUp ; if d7 not set in object state, branch ahead to skip this part
lda TimerControl ; if master timer control set,
bne RunPUSubs ; branch ahead to enemy object routines
lda PowerUpType ; check power-up type
@ -8168,10 +8164,7 @@ ExVMove:
EnemiesAndLoopsCore:
lda Enemy_Flag,x ; check data here for MSB set
pha ; save in stack
asl
bcs ChkBowserF ; if MSB set in enemy flag, branch ahead of jumps
pla ; get from stack
bmi ChkBowserF ; if MSB set in enemy flag, branch ahead of jumps
beq ChkAreaTsk ; if data zero, branch
jmp RunEnemyObjectsCore ; otherwise, jump to run enemy subroutines
ChkAreaTsk:
@ -8181,7 +8174,6 @@ ChkAreaTsk:
beq ExitELCore
jmp ProcLoopCommand ; otherwise, jump to process loop command/load enemies
ChkBowserF:
pla ; get data from stack
and #%00001111 ; mask out high nybble
tay
lda Enemy_Flag,y ; use as pointer and load same place with different offset
@ -8325,8 +8317,7 @@ CheckRightBounds:
ldy EnemyDataOffset
iny
jsr EnemyDataBankSwitch ; if MSB of enemy object is clear, branch to check for row $0f
asl
bcc CheckPageCtrlRow
bpl CheckPageCtrlRow
lda EnemyObjectPageSel ; if page select already set, do not set again
bne CheckPageCtrlRow
inc EnemyObjectPageSel ; otherwise, if MSB is set, set page select
@ -9775,9 +9766,7 @@ MoveNormalEnemy:
and #%01000000 ; check enemy state for d6 set, if set skip
bne FallE ; to move enemy vertically, then horizontally if necessary
lda Enemy_State,x
asl ; check enemy state for d7 set
bcs SteadM ; if set, branch to move enemy horizontally
lda Enemy_State,x
bmi SteadM ; if d7 of enemy state set, branch to move enemy horizontally
and #%00100000 ; check enemy state for d5 set
bne MoveDefeatedEnemy ; if set, branch to move defeated enemy object
lda Enemy_State,x
@ -11640,8 +11629,7 @@ ExScrnBd:
FireballEnemyCollision:
lda Fireball_State,x ; check to see if fireball state is set at all
beq ExitFBallEnemy ; branch to leave if not
asl
bcs ExitFBallEnemy ; branch to leave also if d7 in state is set
bmi ExitFBallEnemy ; branch to leave also if d7 in state is set
lda FrameCounter
lsr ; get LSB of frame counter
bcs ExitFBallEnemy ; branch to leave if set (do routine every other frame)
@ -11934,10 +11922,8 @@ HandlePECollisions:
lda AreaType ; branch if water type level
beq InjurePlayer
lda Enemy_State,x ; branch if d7 of enemy state was set
asl
bcs ChkForPlayerInjury
lda Enemy_State,x ; mask out all but 3 LSB of enemy state
and #%00000111
bmi ChkForPlayerInjury
and #%00000111 ; mask out all but 3 LSB of enemy state
cmp #$02 ; branch if enemy is in normal or falling state
bcc ChkForPlayerInjury
lda Enemy_ID,x ; branch to leave if goomba in defeated state
@ -12232,8 +12218,7 @@ ProcEnemyCollisions:
cmp #HammerBro ; if hammer bro found in alt state, branch to leave
beq ExitProcessEColl
lda Enemy_State,y ; check first enemy state for d7 set
asl
bcc ShellCollisions ; branch if d7 is clear
bpl ShellCollisions ; branch if d7 is clear
lda #$06
jsr SetupFloateyNumber ; award 1000 points for killing enemy
jsr ShellOrBlockDefeat ; then kill enemy, then load
@ -13160,14 +13145,12 @@ LandEnemyProperly:
and #%01000000 ; branch if d6 in enemy state is set
bne LandEnemyInitState
lda Enemy_State,x
asl ; branch if d7 in enemy state is not set
bcc ChkLandedEnemyState
bpl ChkLandedEnemyState ; branch if d7 in enemy state is not set
SChkA:
jmp DoEnemySideCheck ; if lower nybble < $0d, d7 set but d6 not set, jump here
ChkLandedEnemyState:
lda Enemy_State,x ; if enemy in normal state, branch back to jump here
beq SChkA
beq SChkA ; if enemy in normal state, branch back to jump here
cmp #$05 ; if in state used by spiny's egg
beq ProcEnemyDirection ; then branch elsewhere
cmp #$03 ; if already in state used by koopas and buzzy beetles
@ -13237,9 +13220,7 @@ ChkForRedKoopa:
Chk2MSBSt:
lda Enemy_State,x ; save enemy state into Y
tay
asl ; check for d7 set
bcc GetSteFromD ; branch if not set
lda Enemy_State,x
bpl GetSteFromD ; branch if d7 not set
ora #%01000000 ; set d6
jmp SetD6Ste ; jump ahead of this part
GetSteFromD:
@ -13279,8 +13260,7 @@ ChkForBump_HammerBroJ:
cpx #$05 ; check if we're on the special use slot
beq NoBump ; and if so, branch ahead and do not play sound
lda Enemy_State,x ; if enemy state d7 not set, branch
asl ; ahead and do not play sound
bcc NoBump
bpl NoBump ; ahead and do not play sound
lda #Sfx_Bump ; otherwise, play bump sound
sta Square1SoundQueue ; sound will never be played if branching from ChkForRedKoopa
NoBump:
@ -14077,14 +14057,12 @@ SChk5:
sta Sprite_Y_Position+16,y
SChk6:
pla ; get bits from stack
asl ; rotate d2 into carry
bcc SLChk ; save to stack
bpl SLChk ; check d2
lda #$f8
sta Sprite_Y_Position+20,y ; if d2 was set, move sixth sprite offscreen
SLChk:
lda Enemy_OffscreenBits ; check d7 of offscreen bits
asl ; and if d7 is not set, skip sub
bcc ExDLPl
bpl ExDLPl ; and if d7 is not set, skip sub
jmp MoveSixSpritesOffscreen ; otherwise branch to move all sprites offscreen
ExDLPl:
rts
@ -14915,8 +14893,7 @@ DChunks:
lda Block_OffscreenBits ; get offscreen bits for block object
jsr ChkLeftCo ; do sub to move left half of sprites offscreen if necessary
lda Block_OffscreenBits ; get offscreen bits again
asl ; shift d7 into carry
bcc ChnkOfs ; if d7 not set, branch to last part
bpl ChnkOfs ; if d7 not set, branch to last part
lda #$f8
jsr DumpTwoSpr ; otherwise move top sprites offscreen
ChnkOfs:
@ -15366,9 +15343,8 @@ ActionSwimming:
lda JumpSwimTimer ; check jump/swim timer
ora PlayerAnimCtrl ; and animation frame control
bne FourFrameExtent ; if any one of these set, branch ahead
lda A_B_Buttons
asl ; check for A button pressed
bcs FourFrameExtent ; branch to same place if A button pressed
lda A_B_Buttons ; check for A button pressed
bmi FourFrameExtent ; branch to same place if A button pressed
GetCurrentAnimOffset:
lda PlayerAnimCtrl ; get animation frame control
@ -17187,8 +17163,8 @@ AreaDataBankSwitch:
pha ; We need to save the byte because A is used for bank switching
ldx #$00
jsr BankSwitch
pla
ldx XStore
pla ; Pulling A last to set up flags as they would be without a bank switch
rts
; Enemy data is located in Bank 1; we switch back to Bank 0 when we are done
@ -17200,8 +17176,8 @@ EnemyDataBankSwitch:
pha ; We need to save the byte because A is used for bank switching
ldx #$00
jsr BankSwitch
pla
ldx XStore
pla ; Pulling A last to set up flags as they would be without a bank switch
rts
; Graphic tiles are located in Bank 2; we switch back to Bank 0 when we are done