![]() |
Routines |
| Prev: 29980 | Up: Map | Next: 30074 |
|
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 1-3) or SpritesTable_Other (for types 4-13). 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.
|
||||||||
| PrepareOldSprite | 30018 | LD A,(24075) | A=the saved X position (from Actor). | |||||
| 30021 | AND %00000110 | Keep only bits 1-2 (the X position within a character cell, in steps of two pixels). | ||||||
| 30023 | LD C,A | Keep the X position bits in C. | ||||||
| 30024 | LD A,(24077) | A=the saved state (from 24077). | ||||||
|
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 | 30027 | BIT 6,A | Jump to ActorGetSpriteAddress_Type if bit 6 of the state is clear. | |||||
| 30029 | JR Z,ActorGetSpriteAddress_Type | |||||||
| 30031 | SET 3,C | Set bit 3 of C to select the second set of sprites. | ||||||
| ActorGetSpriteAddress_Type | 30033 | DEC A | Decrease the state by one (so that type 1 becomes 0). | |||||
| 30034 | CP 3 | Jump to ActorGetSpriteAddress_OtherTypes if the result is 3 or more. | ||||||
| 30036 | JR NC,ActorGetSpriteAddress_OtherTypes | |||||||
|
Types 1-3 have eight sprites each (four X positions for each of the two directions).
|
||||||||
| 30038 | RLCA | Multiply the type by 16 (the length of a type's entries in the table). | ||||||
| 30039 | RLCA | |||||||
| 30040 | RLCA | |||||||
| 30041 | RLCA | |||||||
| 30042 | AND %11110000 | Keep only bits 4-7. | ||||||
| 30044 | OR C | Add in the X position and direction bits from C. | ||||||
| 30045 | LD HL,30234 | HL=SpritesTable. | ||||||
| ActorGetSpriteAddress_Lookup | 30048 | LD C,A | Store the offset in C. | |||||
| 30049 | LD B,0 | B=0. | ||||||
| 30051 | ADD HL,BC | HL=the table address + the offset. | ||||||
| 30052 | LD E,(HL) | Fetch the sprite address into DE. | ||||||
| 30053 | INC HL | |||||||
| 30054 | LD D,(HL) | |||||||
| 30055 | RET | Return. | ||||||
|
Types 4 and above have four sprites each, which only change with bit 2 of the X position and with the direction.
|
||||||||
| ActorGetSpriteAddress_OtherTypes | 30056 | SUB 3 | Subtract 3 from the type (it is already one less than the real type), so that type 4 becomes 0. | |||||
| 30058 | RLCA | Multiply the type by 8 (the length of a type's entries in the table). | ||||||
| 30059 | RLCA | |||||||
| 30060 | RLCA | |||||||
| 30061 | AND %11111000 | Keep only bits 3-7. | ||||||
| 30063 | LD B,A | Store the result in B. | ||||||
| 30064 | LD A,C | A=C. | ||||||
| 30065 | RRCA | Move the X position bits and the direction bit down by one place. | ||||||
| 30066 | AND %00000110 | Keep only bits 1-2. | ||||||
| 30068 | OR B | Add in the type offset. | ||||||
| 30069 | LD HL,30282 | HL=SpritesTable_Other. | ||||||
| 30072 | JR ActorGetSpriteAddress_Lookup | Jump to ActorGetSpriteAddress_Lookup. | ||||||
|
View the equivalent code in;
|
||||||||
| Prev: 29980 | Up: Map | Next: 30074 |