These two ... I'm not a 6502 expert, but disappointingly I can't see a way these CMP -> EOR changes could actually make a difference to anything.
This code is one way the player can die from contact with a monster. I think there is one check for the player moving into a monster (which is what this code seems to be), and a separate check for a monster moving into the player.
Here is my attempt at analysis of this; please tell me if I'm wrong.
The differences between EOR and CMP seem to be:
1. EOR (obviously) sets the accumulator, whereas CMP does not;
2. CMP sets both carry and zero flags; EOR only sets zero (on equality).
Is that right?
Let's look at (1) first -- the fact that EOR scribbles the accumulator:
Code: Select all
068c monster_check lda player_x ; V2: CMP here replaced with this EOR 068e eor t_monsters_x,x 0690 bne L069a 0692 lda player_y ; V2: CMP here replaced with this EOR 0694 eor t_monsters_y,x 0696 bne L069a ; player charges into monster 0698 inc v_death_flag 069a L069a ldy t_monsters_y,x 069c lda t_monsters_x,x 069e tax 069f tya 06a0 jsr tr_get_level_cell
a) if the branch is taken, the LDY at &69A is executed, but the contents of the accumulator are ignored by this instruction. The next instruction is an LDA; the accumulator is updated here anyway, so the EOR's change to A has no effect.
b) if the branch is not taken, the LDA at &692 updates the accumulator immediately, so again the EOR's change to A has no effect.
Assuming (b) happens, the second EOR is then executed at &694, clobbering the accumulator again:
i) if the branch at &696 is taken, again, the LDY at &69A is executed, and the same logic as in (a) above applies to the LDY/LDA sequence, so A doesn't matter.
ii) if the &696 branch isn't taken, an INC happens at &698 to set the variable which kills the player, but INC is unaffected by A; and then we fall into the &69A LDY/LDA pair as in (a) and (i).
So the change to A doesn't make a difference.
What about the other effect -- the fact that carry isn't set by EOR?
BNE, LDA, EOR and INC don't care about C, so we eventually end up at &69A again. LDY, LDA, TAX, and TYA don't care about C either.
Finally, JSR tr_get_level_cell bounces off a JMP to get_level_cell at &1BD3:
Code: Select all
get_level_cell cmp #$18
Have I missed something?