Prev: A1AA Up: Map Next: A1C8
A1B4: Build Flag Mask
Used by the routines at TestFlag, SetFlag, ClearFlag and Handler_RoomExits.
Turns a bit index into the flag address and the bit mask used by TestFlag, SetFlag and ClearFlag.
Input
A Bit index
HL Flag base address
Output
HL Address of the flag byte
A Bit mask
BuildFlagMask A1B4 PUSH DE Stash DE and BC on the stack.
A1B5 PUSH BC
A1B6 EX DE,HL Switch the flag table base into DE so HL can hold the bit index.
A1B7 LD L,A Put the bit index into HL.
A1B8 LD H,$00
A1BA CALL CalculateBitAddress Call CalculateBitAddress to split the bit index into a byte offset (HL) and a bit number (C).
A1BD ADD HL,DE Point HL at the flag byte holding this bit.
A1BE LD B,C Use the bit number as the rotate count.
A1BF INC B Count one extra rotate so the mask lands on this bit.
A1C0 XOR A Start the mask with no bits set.
A1C1 SCF Seed a single set bit for the mask.
BuildFlagMask_0 A1C2 RLA Build the mask for this flag bit.
A1C3 DJNZ BuildFlagMask_0 Keep rotating until the set bit reaches this flag's position.
A1C5 POP BC Restore BC and DE from the stack.
A1C6 POP DE
A1C7 RET Return.
Prev: A1AA Up: Map Next: A1C8