Routines |
Prev: 64569 | Up: Map | Next: 64811 |
Used by the routine at RunHandlers.
|
|||||||
Handler_Train | 64694 | LD A,(54277) | Return if train spawning is set to be off (*TrainState is equal to 254). | ||||
64697 | CP 254 | ||||||
64699 | RET Z | ||||||
64700 | CP 255 | Jump to Handler_Train_Movement if a train is already active (*TrainState is equal to 255). | |||||
64702 | JR Z,Handler_Train_Movement | ||||||
Else the counter is a counter, so count it down.
|
|||||||
64704 | DEC A | Decrease *TrainState by one. | |||||
64705 | LD (54277),A | ||||||
64708 | 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!
|
|||||||
64709 | LD A,255 | Write 255 to *TrainState. | |||||
64711 | LD (54277),A | ||||||
Randomly bring the train in from either the left or right hand side of the play area.
|
|||||||
64714 | CALL RandomNumber | Get a random number of either zero or one. | |||||
64717 | AND %00000001 | ||||||
64719 | JR NZ,Handler_SpawnTrainRight | Jump to Handler_SpawnTrainRight if the random number is one. | |||||
Train moves from left-to-right.
|
|||||||
64721 | LD A,19 | Write 19 to *TrainYPosition. | |||||
64723 | LD (54279),A | ||||||
64726 | LD A,240 | Write 240 to *TrainXPosition. | |||||
64728 | LD (54278),A | ||||||
64731 | JR Handler_Train_Movement | Jump to Handler_Train_Movement. | |||||
Bit 7 signifies that this train moves from right-to-left.
|
|||||||
Handler_SpawnTrainRight | 64733 | LD A,147 | Write 147 (19 + bit 7 set) to *TrainYPosition. | ||||
64735 | LD (54279),A | ||||||
64738 | LD A,32 | Write 32 to *TrainXPosition. | |||||
64740 | LD (54278),A | ||||||
Handler_Train_Movement | 64743 | LD A,(54279) | A=*TrainYPosition. | ||||
64746 | AND %01000000 | Keep only bit 6. | |||||
Set the carry flag according to bit 6.
|
|||||||
64748 | RLCA | Rotate A left twice, moving bit 6 to bit 0 and setting the carry flag if bit 0 was set. | |||||
64749 | RLCA | ||||||
64750 | LD C,A | C=A. | |||||
Which direction should the train be moving in?
|
|||||||
64751 | LD A,(54279) | Jump to Handler_MoveTrain_RightToLeft if *TrainYPosition is higher than 128 (bit 7 is set). | |||||
64754 | CP 128 | ||||||
64756 | JR NC,Handler_MoveTrain_RightToLeft | ||||||
Handles moving the train from the left-to-right hand side of the play area.
|
|||||||
64758 | AND %00111111 | Strip off the right-to-left flag. | |||||
64760 | LD B,A | B=train Y position. | |||||
64761 | LD A,(54278) | A=*TrainXPosition. | |||||
64764 | INC A | Increment A by one. | |||||
64765 | ADD A,C | A+=C. | |||||
Draw the train.
|
|||||||
DrawTrain | 64766 | LD (54278),A | Write A to *TrainXPosition. | ||||
64769 | LD C,A | C=train X position. | |||||
64770 | LD A,121 | A=sprite ID 121.
|
|||||
64772 | PUSH BC | Stash the train position on the stack. | |||||
64773 | CALL PrintSprite | Call PrintSprite. | |||||
64776 | POP BC | Restore the train position from the stack. | |||||
Draws the centre sprite of the train three times.
|
|||||||
64777 | LD A,3 | A=3 (counter). | |||||
DrawTrain_Loop | 64779 | PUSH AF | Stash the counter on the stack. | ||||
64780 | INC C | Increment the X position by two to draw the next section of the train. | |||||
64781 | INC C | ||||||
64782 | LD A,123 | A=sprite ID 123.
|
|||||
64784 | PUSH BC | Stash the train position on the stack. | |||||
64785 | CALL PrintSprite | Call PrintSprite. | |||||
64788 | POP BC | Restore the train position and counter from the stack. | |||||
64789 | POP AF | ||||||
64790 | DEC A | Decrease the counter held by A by one. | |||||
64791 | JR NZ,DrawTrain_Loop | Jump to DrawTrain_Loop until all centre sprites have been drawn. | |||||
Now draw the rear section of the train.
|
|||||||
64793 | INC C | Increment the X position by two to draw the next section of the train. | |||||
64794 | INC C | ||||||
64795 | LD A,121 | A=sprite ID 121.
|
|||||
64797 | CALL PrintSprite_Mirrored | Call PrintSprite_Mirrored. | |||||
64800 | RET | Return. | |||||
Handles moving the train from the right-to-left hand side of the play area.
|
|||||||
Handler_MoveTrain_RightToLeft | 64801 | AND %00111111 | Strip off the right-to-left flag. | ||||
64803 | LD B,A | B=train Y position. | |||||
64804 | LD A,(54278) | A=*TrainXPosition. | |||||
64807 | DEC A | Decrease A by one. | |||||
64808 | SUB C | A-=C. | |||||
64809 | JR DrawTrain | Jump to DrawTrain. |
Prev: 64569 | Up: Map | Next: 64811 |