![]() |
Routines |
| Prev: A9BF | Up: Map | Next: AA62 |
|
Used by the routine at CreateTownObjects.
Called every frame in town. Cacti stand in eight fixed cells of the town (see CactusPositions). When the sheriff comes within two cells of one, and the seventh object slot is free, the routine puts a cactus (an object of type 13) in the slot.
|
||||
|
Return if the seventh slot is in use.
|
||||
| CreateCactus | A9ED | LD A,($A2DD) | Fetch the type of the object in the seventh slot. | |
| A9F0 | AND A | Return if the slot is in use. | ||
| A9F1 | RET NZ | |||
|
Find a cactus that is within two cells of the sheriff.
|
||||
| A9F2 | LD A,($A27F) | Fetch the horizontal cell of the sheriff and keep it in E. | ||
| A9F5 | LD E,A | |||
| A9F6 | LD A,($A281) | Fetch the vertical cell of the sheriff. | ||
| A9F9 | RLCA | Shift it into the high nibble. | ||
| A9FA | RLCA | |||
| A9FB | RLCA | |||
| A9FC | RLCA | |||
| A9FD | AND %11110000 | Keep the high nibble. | ||
| A9FF | LD D,A | Keep the vertical cell in the high nibble of D. | ||
| AA00 | LD HL,$AA76 | Point HL at CactusPositions. | ||
| AA03 | LD B,(HL) | Fetch the number of cacti. | ||
| CreateCactus_Next | AA04 | INC HL | Move on to the next cactus. | |
| CreateCactus_Loop | AA05 | LD A,(HL) | Fetch the position of the cactus. | |
| AA06 | AND %00001111 | Keep the horizontal cell. | ||
| AA08 | SUB E | Subtract the horizontal cell of the sheriff. | ||
| AA09 | JR NC,CreateCactus_CompareHorizontal | Jump to CreateCactus_CompareHorizontal unless the difference is negative. | ||
| AA0B | NEG | Make the difference positive. | ||
| CreateCactus_CompareHorizontal | AA0D | CP $02 | Jump to CreateCactusSkip if the cactus is two or more cells away horizontally. | |
| AA0F | JR NC,CreateCactusSkip | |||
| AA11 | LD A,(HL) | Fetch the position of the cactus again. | ||
| AA12 | AND %11110000 | Keep the vertical cell. | ||
| AA14 | SUB D | Subtract the vertical cell of the sheriff. | ||
| AA15 | JR NC,CreateCactus_CompareVertical | Jump to CreateCactus_CompareVertical unless the difference is negative. | ||
| AA17 | NEG | Make the difference positive. | ||
| CreateCactus_CompareVertical | AA19 | CP $20 | Jump to CreateCactusSkip if the cactus is two or more cells away vertically. | |
| AA1B | JR NC,CreateCactusSkip | |||
|
The sheriff is close to this cactus, so make it.
|
||||
| CreateCactusFound | AA1D | LD A,(HL) | Fetch the position of the cactus. | |
| AA1E | PUSH AF | Stash it on the stack. | ||
| AA1F | LD DE,$A2DD | Point DE at ObjectSlot_07. | ||
| AA22 | PUSH DE | Copy DE to IY (using the stack). | ||
| AA23 | POP IY | |||
| AA25 | LD HL,$AA62 | Point HL at CactusTemplate. | ||
| AA28 | LD BC,$0010 | Set the size of an object slot in BC. | ||
| AA2B | LDIR | Copy the template into the slot. | ||
| AA2D | POP AF | Retrieve the position of the cactus. | ||
| AA2E | LD C,A | Keep the cactus position in C. | ||
| AA2F | AND %00001111 | Keep the horizontal cell. | ||
| AA31 | LD (IY+$02),A | Set the horizontal cell of the cactus. | ||
| AA34 | LD A,C | Fetch the position again. | ||
| AA35 | RRCA | Shift the vertical cell into the bottom of the byte. | ||
| AA36 | RRCA | |||
| AA37 | RRCA | |||
| AA38 | RRCA | |||
| AA39 | AND %00001111 | Keep the vertical cell. | ||
| AA3B | LD (IY+$04),A | Set the vertical cell of the cactus. | ||
| AA3E | LD A,C | Fetch the position again. | ||
| AA3F | RLCA | Swap the two halves of the position. | ||
| AA40 | RLCA | |||
| AA41 | RLCA | |||
| AA42 | RLCA | |||
| AA43 | AND %01110000 | Keep three bits which came from the horizontal cell. | ||
| AA45 | ADD A,$40 | Add 40 to give the horizontal position within the cell. | ||
| AA47 | LD (IY+$01),A | Set the horizontal position of the cactus within its cell. | ||
| AA4A | LD A,C | Fetch the position again. | ||
| AA4B | CPL | Invert it. | ||
| AA4C | AND %01110000 | Keep three bits which came from the vertical cell. | ||
| AA4E | ADD A,$40 | Add 40 to give the vertical position within the cell. | ||
| AA50 | LD (IY+$03),A | Set the vertical position of the cactus within its cell. | ||
| AA53 | XOR (IY+$01) | Combine it with the horizontal position. | ||
| AA56 | RLCA | Rotate bit 4 up into bit 6. | ||
| AA57 | RLCA | |||
| AA58 | AND %01000000 | Keep bit 6, which chooses whether the sprite is flipped. | ||
| AA5A | LD (IY+$07),A | Set the flags of the cactus. | ||
| AA5D | RET | Return. | ||
| CreateCactusSkip | AA5E | INC HL | Move on to the next cactus. | |
| AA5F | DJNZ CreateCactus_Loop | Loop back until every cactus has been checked. | ||
| AA61 | RET | Return. | ||
| Prev: A9BF | Up: Map | Next: AA62 |