Prev: 751C Up: Map Next: 757A
7542: Prepare Old Sprite
Used by the routine at SetUpPreviousSprite.
Finds the graphic for the previous state of an object, using the copy of its X position and state that StoreEntity saved at Actor. The rest of the routine, from ActorGetSpriteAddress, is shared with ActorMoveSprite.
The sprite is looked up in SpritesTable (for types 01-03) or SpritesTable_Other (for types 04-0D). The entry is chosen by the object type (the state with bits 6 and 7 removed), by the X position within a character cell and by bit 6 of the state, which selects the second set of sprites.
Output
DE Address of the sprite
PrepareOldSprite 7542 LD A,($5E0B) A=the saved X position (from Actor).
7545 AND %00000110 Keep only bits 1-2 (the X position within a character cell, in steps of two pixels).
7547 LD C,A Keep the X position bits in C.
7548 LD A,($5E0D) A=the saved state (from 5E0D).
This entry point is used by the routine at ActorMoveSprite.
Find the sprite from the state in A and the X position bits in C.
ActorGetSpriteAddress 754B BIT 6,A Jump to ActorGetSpriteAddress_Type if bit 6 of the state is clear.
754D JR Z,ActorGetSpriteAddress_Type
754F SET 3,C Set bit 3 of C to select the second set of sprites.
ActorGetSpriteAddress_Type 7551 DEC A Decrease the state by one (so that type 01 becomes 00).
7552 CP $03 Jump to ActorGetSpriteAddress_OtherTypes if the result is 03 or more.
7554 JR NC,ActorGetSpriteAddress_OtherTypes
Types 01-03 have eight sprites each (four X positions for each of the two directions).
7556 RLCA Multiply the type by 10 (the length of a type's entries in the table).
7557 RLCA
7558 RLCA
7559 RLCA
755A AND %11110000 Keep only bits 4-7.
755C OR C Add in the X position and direction bits from C.
755D LD HL,$761A HL=SpritesTable.
ActorGetSpriteAddress_Lookup 7560 LD C,A Store the offset in C.
7561 LD B,$00 B=00.
7563 ADD HL,BC HL=the table address + the offset.
7564 LD E,(HL) Fetch the sprite address into DE.
7565 INC HL
7566 LD D,(HL)
7567 RET Return.
Types 04 and above have four sprites each, which only change with bit 2 of the X position and with the direction.
ActorGetSpriteAddress_OtherTypes 7568 SUB $03 Subtract 03 from the type (it is already one less than the real type), so that type 04 becomes 00.
756A RLCA Multiply the type by 08 (the length of a type's entries in the table).
756B RLCA
756C RLCA
756D AND %11111000 Keep only bits 3-7.
756F LD B,A Store the result in B.
7570 LD A,C A=C.
7571 RRCA Move the X position bits and the direction bit down by one place.
7572 AND %00000110 Keep only bits 1-2.
7574 OR B Add in the type offset.
7575 LD HL,$764A HL=SpritesTable_Other.
7578 JR ActorGetSpriteAddress_Lookup Jump to ActorGetSpriteAddress_Lookup.
View the equivalent code in;
Prev: 751C Up: Map Next: 757A