Optimize checks on upper bit

develop
Christophe Parent 2024-05-30 16:26:48 -07:00
parent 54d1bc7511
commit fd54208307
1 changed files with 20 additions and 44 deletions

View File

@ -3473,8 +3473,7 @@ ProcADLoop:
bpl RdyDecode ; if buffer not negative, branch, otherwise
iny
lda (AreaData),y ; 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
@ -6648,8 +6647,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
@ -7380,8 +7378,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
@ -7527,8 +7524,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
@ -8152,10 +8148,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:
@ -8165,7 +8158,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
@ -8309,8 +8301,7 @@ CheckRightBounds:
ldy EnemyDataOffset
iny
lda (EnemyData),y ; 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
@ -9759,9 +9750,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
@ -11624,8 +11613,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)
@ -11918,10 +11906,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
@ -12216,8 +12202,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
@ -13144,14 +13129,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
@ -13221,9 +13204,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:
@ -13263,8 +13244,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:
@ -14061,14 +14041,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
@ -14899,8 +14877,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:
@ -15350,9 +15327,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