![]() |
Routines |
| Prev: FC39 | Up: Map | Next: FD2B |
|
Used by the routine at RunHandlers.
|
|||||||
| Handler_Train | FCB6 | LD A,($D405) | Return if train spawning is set to be off (*TrainState is equal to FE). | ||||
| FCB9 | CP $FE | ||||||
| FCBB | RET Z | ||||||
| FCBC | CP $FF | Jump to Handler_Train_Movement if a train is already active (*TrainState is equal to FF). | |||||
| FCBE | JR Z,Handler_Train_Movement | ||||||
|
Else the counter is a counter, so count it down.
|
|||||||
| FCC0 | DEC A | Decrease *TrainState by one. | |||||
| FCC1 | LD ($D405),A | ||||||
| FCC4 | RET NZ | Return if *TrainState is still in progress. | |||||
|
Else the countdown is complete so set the counter/ state to indicate that a train has been spawned and then spawn a train!
|
|||||||
| FCC5 | LD A,$FF | Write FF to *TrainState. | |||||
| FCC7 | LD ($D405),A | ||||||
|
Randomly bring the train in from either the left or right hand side of the play area.
|
|||||||
| FCCA | CALL RandomNumber | Get a random number of either zero or one. | |||||
| FCCD | AND %00000001 | ||||||
| FCCF | JR NZ,Handler_SpawnTrainRight | Jump to Handler_SpawnTrainRight if the random number is one. | |||||
|
Train moves from left-to-right.
|
|||||||
| FCD1 | LD A,$13 | Write 13 to *TrainYPosition. | |||||
| FCD3 | LD ($D407),A | ||||||
| FCD6 | LD A,$F0 | Write F0 to *TrainXPosition. | |||||
| FCD8 | LD ($D406),A | ||||||
| FCDB | JR Handler_Train_Movement | Jump to Handler_Train_Movement. | |||||
|
Bit 7 signifies that this train moves from right-to-left.
|
|||||||
| Handler_SpawnTrainRight | FCDD | LD A,$93 | Write 93 (13 + bit 7 set) to *TrainYPosition. | ||||
| FCDF | LD ($D407),A | ||||||
| FCE2 | LD A,$20 | Write 20 to *TrainXPosition. | |||||
| FCE4 | LD ($D406),A | ||||||
| Handler_Train_Movement | FCE7 | LD A,($D407) | A=*TrainYPosition. | ||||
| FCEA | AND %01000000 | Keep only bit 6. | |||||
|
Set the carry flag according to bit 6.
|
|||||||
| FCEC | RLCA | Rotate A left twice, moving bit 6 to bit 0 and setting the carry flag if bit 0 was set. | |||||
| FCED | RLCA | ||||||
| FCEE | LD C,A | C=A. | |||||
|
Which direction should the train be moving in?
|
|||||||
| FCEF | LD A,($D407) | Jump to Handler_MoveTrain_RightToLeft if *TrainYPosition is higher than 80 (bit 7 is set). | |||||
| FCF2 | CP $80 | ||||||
| FCF4 | JR NC,Handler_MoveTrain_RightToLeft | ||||||
|
Handles moving the train from the left-to-right hand side of the play area.
|
|||||||
| FCF6 | AND %00111111 | Strip off the right-to-left flag. | |||||
| FCF8 | LD B,A | B=train Y position. | |||||
| FCF9 | LD A,($D406) | A=*TrainXPosition. | |||||
| FCFC | INC A | Increment A by one. | |||||
| FCFD | ADD A,C | A+=C. | |||||
|
Draw the train.
|
|||||||
| DrawTrain | FCFE | LD ($D406),A | Write A to *TrainXPosition. | ||||
| FD01 | LD C,A | C=train X position. | |||||
| FD02 | LD A,$79 | A=sprite ID 79.
|
|||||
| FD04 | PUSH BC | Stash the train position on the stack. | |||||
| FD05 | CALL PrintSprite | Call PrintSprite. | |||||
| FD08 | POP BC | Restore the train position from the stack. | |||||
|
Draws the centre sprite of the train three times.
|
|||||||
| FD09 | LD A,$03 | A=03 (counter). | |||||
| DrawTrain_Loop | FD0B | PUSH AF | Stash the counter on the stack. | ||||
| FD0C | INC C | Increment the X position by two to draw the next section of the train. | |||||
| FD0D | INC C | ||||||
| FD0E | LD A,$7B | A=sprite ID 7B.
|
|||||
| FD10 | PUSH BC | Stash the train position on the stack. | |||||
| FD11 | CALL PrintSprite | Call PrintSprite. | |||||
| FD14 | POP BC | Restore the train position and counter from the stack. | |||||
| FD15 | POP AF | ||||||
| FD16 | DEC A | Decrease the counter held by A by one. | |||||
| FD17 | JR NZ,DrawTrain_Loop | Jump to DrawTrain_Loop until all centre sprites have been drawn. | |||||
|
Now draw the rear section of the train.
|
|||||||
| FD19 | INC C | Increment the X position by two to draw the next section of the train. | |||||
| FD1A | INC C | ||||||
| FD1B | LD A,$79 | A=sprite ID 79.
|
|||||
| FD1D | CALL PrintSprite_Mirrored | Call PrintSprite_Mirrored. | |||||
| FD20 | RET | Return. | |||||
|
Handles moving the train from the right-to-left hand side of the play area.
|
|||||||
| Handler_MoveTrain_RightToLeft | FD21 | AND %00111111 | Strip off the right-to-left flag. | ||||
| FD23 | LD B,A | B=train Y position. | |||||
| FD24 | LD A,($D406) | A=*TrainXPosition. | |||||
| FD27 | DEC A | Decrease A by one. | |||||
| FD28 | SUB C | A-=C. | |||||
| FD29 | JR DrawTrain | Jump to DrawTrain. | |||||
| Prev: FC39 | Up: Map | Next: FD2B |