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