Prev: 25731 Up: Map Next: 25799
25752: Randomise Cup Positions
Used by the routine at NewGame.
Gives every cup on the map a new Y position from 32 to 159 putting back any cups which have been collected. The numbers come from the ROM, read from a random address in the first 16384 bytes (the low byte of the address is whatever is in E).
RandomiseCups 25752 LD BC,31958 Point BC at the end of the map (Sprite_Car_1, one byte past the end of MapPoints).
25755 LD A,R Fetch a random number (from the Z80 refresh register).
Limit the number to 0-63.
25757 AND %00111111 Keep only bits 0-5.
25759 LD D,A Use it as the high byte of a random ROM address, held in D.
25760 LD HL,0 HL=0000.
25763 ADD HL,DE Add DE to HL then swap them over (this leaves DE unchanged).
25764 EX DE,HL
25765 LD HL,30739 HL=30739 (the sprite ID of the first map entry).
Check the sprite ID of each map entry.
RandomiseCups_Loop 25768 LD A,(HL) Fetch the sprite ID of the map entry.
25769 CP 32 If this is a cup (A is 32) then jump to HandlerSpriteCup.
25771 JR Z,HandlerSpriteCup
25773 CP 96 If this is not a collected cup (A is not 96) then jump to RandomiseCups_Next.
25775 JR NZ,RandomiseCups_Next
25777 LD (HL),32 Put the cup back by writing 32 as the sprite ID.
Write a new random Y position.
HandlerSpriteCup 25779 DEC HL Point HL at the Y position of the cup.
25780 LD A,(DE) Fetch a random byte from the ROM.
25781 INC DE Move on to the next ROM address.
25782 AND %01111111 Keep only bits 0-6.
25784 ADD A,32 Add 32 so that the Y position is between 32 and 159.
25786 LD (HL),A Store the new Y position of the cup.
25787 INC HL Point HL back at the sprite ID of the map entry.
Move on to the sprite ID of the next map entry, and check if the end of the map has been reached.
RandomiseCups_Next 25788 INC HL Increment HL by three.
25789 INC HL
25790 INC HL
25791 PUSH HL Stash the map pointer on the stack.
25792 AND A Reset the carry flag.
25793 SBC HL,BC Work out how far the map pointer is from the end of the map.
25795 POP HL Restore the map pointer from the stack.
25796 JR C,RandomiseCups_Loop If the map pointer is before the end of the map then jump to RandomiseCups_Loop.
25798 RET Return.
Prev: 25731 Up: Map Next: 25799