Optimize CMP/CPX/CPY instructions

refactor
Christophe Parent 2024-06-09 00:26:04 -07:00
parent 4b3dcd6d60
commit ca736cc7a6
1 changed files with 9 additions and 15 deletions

View File

@ -2130,10 +2130,10 @@ WriteBlankMT:
rts rts
ReplaceBlockMetatile: ReplaceBlockMetatile:
jmp WriteBlockMetatile ; write metatile to vram buffer to replace block object jmp WriteBlockMetatile ; write metatile to vram buffer to replace block object
DestroyBlockMetatile: DestroyBlockMetatile:
lda #$00 ; force blank metatile if branched/jumped to this point lda #$00 ; force blank metatile if branched/jumped to this point
WriteBlockMetatile: WriteBlockMetatile:
ldy #$03 ; load offset for blank metatile ldy #$03 ; load offset for blank metatile
@ -8118,8 +8118,7 @@ AlterYP:
cmp $02 ; compare to maximum speed cmp $02 ; compare to maximum speed
bmi ChkUpM ; if less than preset value, skip this part bmi ChkUpM ; if less than preset value, skip this part
lda SprObject_Y_MoveForce,x lda SprObject_Y_MoveForce,x
cmp #$80 ; if less positively than preset maximum, skip this part bpl ChkUpM ; if less positively than preset maximum ($80), skip this part (cmp optimization)
bcc ChkUpM
lda $02 lda $02
sta SprObject_Y_Speed,x ; keep vertical speed within maximum value sta SprObject_Y_Speed,x ; keep vertical speed within maximum value
lda #$00 lda #$00
@ -8142,8 +8141,7 @@ ChkUpM:
cmp $07 ; compare vertical speed to two's compliment cmp $07 ; compare vertical speed to two's compliment
bpl ExVMove ; if less negatively than preset maximum, skip this part bpl ExVMove ; if less negatively than preset maximum, skip this part
lda SprObject_Y_MoveForce,x lda SprObject_Y_MoveForce,x
cmp #$80 ; check if fractional part is above certain amount, bmi ExVMove ; check if fractional part is above certain amount ($80), and if so, branch to leave (cmp optimization)
bcs ExVMove ; and if so, branch to leave
lda $07 lda $07
sta SprObject_Y_Speed,x ; keep vertical speed within maximum value sta SprObject_Y_Speed,x ; keep vertical speed within maximum value
lda #$ff lda #$ff
@ -8233,9 +8231,8 @@ FindLoop:
lda Player_Y_Position ; check to see if the player is at the correct position lda Player_Y_Position ; check to see if the player is at the correct position
cmp LoopCmdYPosition,y ; if not, branch to check for world 7 cmp LoopCmdYPosition,y ; if not, branch to check for world 7
bne WrongChk bne WrongChk
lda Player_State ; check to see if the player is lda Player_State ; check to see if the player is on solid ground (i.e. not jumping or falling)
cmp #$00 ; on solid ground (i.e. not jumping or falling) bne WrongChk ; if not, player fails to pass loop, and loopback (cmp optimization)
bne WrongChk ; if not, player fails to pass loop, and loopback
lda WorldNumber ; are we in world 7? (check performed on correct lda WorldNumber ; are we in world 7? (check performed on correct
cmp #World7 ; vertical position and on solid ground) cmp #World7 ; vertical position and on solid ground)
bne InitMLp ; if not, initialize flags used there, otherwise bne InitMLp ; if not, initialize flags used there, otherwise
@ -10732,8 +10729,7 @@ HammerChk:
jsr SpawnHammerObj ; execute sub on every fourth frame to spawn misc object (hammer) jsr SpawnHammerObj ; execute sub on every fourth frame to spawn misc object (hammer)
SetHmrTmr: SetHmrTmr:
lda Enemy_Y_Position,x ; get current vertical position lda Enemy_Y_Position,x ; get current vertical position
cmp #$80 ; if still above a certain point bpl ChkFireB ; if still above a certain point ($80) then skip to world number check for flames (cmp optimization)
bcc ChkFireB ; then skip to world number check for flames
lda PseudoRandomBitReg,x lda PseudoRandomBitReg,x
and #%00000011 ; get pseudorandom offset and #%00000011 ; get pseudorandom offset
tay tay
@ -12643,8 +12639,7 @@ ContSChk:
bne ExCSM ; branch to leave if set bne ExCSM ; branch to leave if set
jmp StopPlayerMove ; otherwise jump to impede player's movement jmp StopPlayerMove ; otherwise jump to impede player's movement
ChkPBtm: ChkPBtm:
ldy Player_State ; get player's state ldy Player_State ; check for player's state set to normal (cpy optimization)
cpy #$00 ; check for player's state set to normal
bne StopPlayerMove ; if not, branch to impede player's movement bne StopPlayerMove ; if not, branch to impede player's movement
ldy PlayerFacingDir ; get player's facing direction ldy PlayerFacingDir ; get player's facing direction
dey dey
@ -15096,8 +15091,7 @@ CntPl:
ldy SwimmingFlag ; if swimming flag set, branch to ldy SwimmingFlag ; if swimming flag set, branch to
beq FindPlayerAction ; different part, do not return beq FindPlayerAction ; different part, do not return
lda Player_State lda Player_State
cmp #$00 ; if player status normal, beq FindPlayerAction ; if player status normal, branch and do not return (cmp optimization)
beq FindPlayerAction ; branch and do not return
jsr FindPlayerAction ; otherwise jump and return jsr FindPlayerAction ; otherwise jump and return
lda FrameCounter lda FrameCounter
and #%00000100 ; check frame counter for d2 set (8 frames every and #%00000100 ; check frame counter for d2 set (8 frames every