Prev: 9FFB Up: Map Next: A064
A00E: Set Entity Attributes
Used by the routines at DrawInventoryItem and MenuIcons.
Colours the attribute cells under an entity. This entry point first saves the position of the entity as if it has not moved; SetEntityAttributes_Moved instead uses the position saved by StoreEntity to work out which way the entity has moved.
The cells under the entity are set to the attribute of the entity, and the cells which the entity has just left behind are put back to the attribute of the room (from CurrentRoom_Attribute). Which way the entity has moved picks one of the routines in the table at AttributeJumpTable, and that routine is jumped to with the registers set up as follows:
Register Contents
B The width of the sprite in cells
C The number of rows of cells
D The attribute of the entity
E The attribute of the room
HL The attribute address of the cell holding the position of the entity (the cell at the bottom left)
Input
IX The entity to colour
Before After
set-attributes-before set-attributes-after
SetEntityAttributes A00E LD A,(IX+$03) Write the entity X position to Previous_X_Position.
A011 LD ($5E16),A
A014 LD A,(IX+$04) Write the entity Y position to Previous_Y_Position.
A017 LD ($5E17),A
This entry point is used by the routines at HandlerWeapon, PopCreature, HandlerKnight, SetItemAttributes and PickUpItem.
Get the entity position, attribute and the room attribute.
SetEntityAttributes_Moved A01A LD L,(IX+$03) L=the entity X position, and H=the entity Y position.
A01D LD H,(IX+$04)
A020 LD D,(IX+$05) Fetch the attribute of the entity.
A023 LD A,($5E1A) E=the room attribute from CurrentRoom_Attribute.
A026 LD E,A
A027 LD A,($5E10) B=the width of the sprite from SpriteWidth.
A02A LD B,A
Work out the number of rows of cells from the height of the sprite in pixels.
A02B LD A,($5E11) A=the height of the sprite from SpriteHeight.
A02E RRCA Divide by 04.
A02F RRCA
A030 INC A Increment A by one.
A031 RRCA Divide by 02.
A032 AND %00011111 Keep only bits 0-4.
A034 INC A Increment A by one.
A035 LD C,A Keep the number of rows of cells in C.
Work out which way the entity has moved. The horizontal movement gives 00 (none), 01 (right) or 02 (left), and the vertical movement adds 00 (none), 04 (down) or 08 (up).
A036 PUSH BC Stash the width and the number of rows on the stack.
A037 LD B,$00 B=00 (the direction so far, which is no movement).
A039 LD A,($5E16) Fetch the previous X position from Previous_X_Position.
A03C CP L Jump to SetEntityAttributes_Vertical if the X position is unchanged.
A03D JR Z,SetEntityAttributes_Vertical
A03F JR C,SetEntityAttributes_Right Jump to SetEntityAttributes_Right if the entity has moved right.
A041 INC B Add 01 to B (the entity has moved left).
SetEntityAttributes_Right A042 INC B Add 01 to B.
SetEntityAttributes_Vertical A043 LD A,($5E17) Fetch the previous Y position from Previous_Y_Position.
A046 CP H Compare the saved Y position against H.
A047 LD A,B Fetch the horizontal direction from B.
A048 JR Z,SetEntityAttributes_Select Jump to SetEntityAttributes_Select if the Y position is unchanged.
A04A JR C,SetEntityAttributes_Down Jump to SetEntityAttributes_Down if the entity has moved down.
A04C ADD A,$04 Add 04 to A (the entity has moved up).
SetEntityAttributes_Down A04E ADD A,$04 Add 04 to A.
SetEntityAttributes_Select A050 LD B,A Stash the direction in B.
A051 CALL AttributeAddress Call AttributeAddress to get the attribute address of the position.
A054 LD A,B Restore the direction into A.
A055 POP BC Restore the width and the number of rows from the stack.
A056 PUSH HL Stash the attribute address on the stack.
A057 LD HL,$A064 Point HL at the attribute jump table at AttributeJumpTable.
A05A SLA A Multiply the direction by 02 as the table contains addresses.
A05C CALL AddAToHL Call AddAToHL to add it to the address of the table.
A05F LD A,(HL) Fetch the routine selected from the table.
A060 INC HL
A061 LD H,(HL)
A062 LD L,A
A063 JP (HL) Jump to the routine.
Prev: 9FFB Up: Map Next: A064