News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

[ASM] Questions about the Morph Lock routine.

Started by dewhi100, May 23, 2017, 09:35:17 PM

Previous topic - Next topic

dewhi100

I'm looking at the morph lock patch from this thread and I just don't see why this works:

LDA $09A1 ;LDA equipped items
BMI $04 ;Branch if items are equipped


First of all, equipped items are stored @ $09A2 according to the wiki. By loading from the byte before, aren't we getting the high equipment byte as the low byte in A, and some value of unknown significance in the high byte?

Resolving that may resolve this next issue I have: LDA sets the N flag to equal the high bit of A. BMI then branches if that flag's set.  Branch if minus = branch if N flag is set. LDA sets N = high bit of A. Highest bit of equipped items is... X-ray? "Branch if items are equipped" = "Branch if X-ray is equipped"? That is, if the routine was even loading A from the equipped items bytes.

What is going on here?

Scyzer

This is a short way of checking for Bit 7 of $09A2. The other (and much more easy to understand) method is LDA $09A2 : BIT #$0080 : BNE $04.
By loading $09A1, the low byte of $09A2 becomes the high byte, which makes the relevent bit easier to check as it becomes the negative/positive flag of the address, and can be checked simply with BMI or BPL without the need for BIT or AND.

dewhi100

#2
Ah, I had not considered that the storage is little-endian. In that case, the code *does* seem to be checking for X-ray. Why?

Edit: the answer came to me. The item flags are stored lowest byte first as well. The routine is using an unused item flag, not x-ray.