Prev: 30804 Up: Map Next: 31076
30906: Control the frog
This uninterruptible subcommand routine controls the frog's movements. The main entry point is used when the frog is sitting on the floor, deciding whether to stay put or take a hop.
Input
H 212 (frog)
30906 LD DE,(53761) Pick up ERIC's coordinates in DE
30910 LD L,2 Point HL at byte 2 of the frog's buffer
30912 LD A,(HL) A=frog's y-coordinate
30913 CP D Does it match ERIC's y-coordinate?
30914 JR NZ,30934 Jump if not
30916 DEC L L=1
30917 LD A,(HL) A=frog's x-coordinate
30918 SUB E Is ERIC to the left of the frog?
30919 JR NC,30923 Jump if so
30921 NEG
30923 CP 4 Now A=horizontal distance between the frog and ERIC
30925 JR NC,30934 Jump if this is greater than 3
30927 CALL 25233 A=random number >= 192
30930 OR 192
30932 JR 30940
30934 CALL 25233 A=random number
30937 CP 192 Return 3 times out of 4 (without moving the frog) when ERIC is not nearby
30939 RET C
The frog has decided to move. It has three options: turn round, short hop (one space forward), or long hop (three spaces forward).
30940 CP 240 A>=192 at this point
30942 JR C,30960 Jump if 192<=A<240 (75% of the time) to make a short or long hop
30944 CALL 25012 Update the SRB for the frog's current animatory state and location
30947 INC A A=29/157: frog airborne (phase one)
30948 CALL 30534 Update the frog's animatory state and then resume control at entry point 30951 (below)
This entry point is used when the frog has jumped into the air in order to turn round (either by choice, or because a wall or closed door is in the way).
30951 CALL 25012 Update the SRB for the frog's current animatory state
30954 DEC A A=28/156: frog sitting
30955 XOR 128 Turn the frog round
30957 JP 30903 Update the frog's animatory state and then resume control at the main entry point (30906)
The frog is planning a hop. Decide between a short hop (one space forward) and a long hop (three spaces forward).
30960 LD L,0 Point HL at byte 0 of the frog's buffer
30962 CP 216 Set the carry flag if 192<=A<216
30964 BIT 7,(HL) Set the zero flag if the frog is facing left
30966 LD L,1 Pick up the frog's x-coordinate in E and y-coordinate in D
30968 LD E,(HL)
30969 LD L,2
30971 LD D,(HL)
30972 JR C,31016 Jump if A<216 (50% of the time) to consider a long hop
30974 JR NZ,30978 Jump if the frog is facing right
30976 DEC E
30977 DEC E
30978 INC E E=x-coordinate of the spot directly in front of the frog
30979 LD HL,32756 32756 holds the door/window status flags
30982 LD A,(HL) Pick these up in A
30983 LD B,A Save a copy of them in B briefly
30984 AND 63 Reset bits 6 and 7 of the door/window status flags (i.e. pretend that the windows are closed)
30986 LD (HL),A
30987 CALL 30292 Check for closed doors and walls in the frog's path
30990 LD (HL),B Restore the original door/window status flags
30991 LD H,212 212=frog
30993 JR C,30944 Turn the frog round if there's a wall or closed door in its path
30995 CALL 25012 Update the SRB for the frog's current animatory state and location
30998 INC A A=29/157: frog airborne (phase one)
30999 RLCA
31000 RRCA
31001 JR C,31005 Jump if the frog is facing right
31003 DEC E
31004 DEC E
31005 INC E Now E=x-coordinate of the spot directly in front of the frog
31006 CALL 30534 Update the frog's animatory state and then resume control at entry point 31009 (below)
This entry point is used when the frog has just jumped into the air for a short hop, or is just about to finish a long hop. Either way, the frog is going to land now.
31009 CALL 25012 Update the SRB for the frog's current animatory state and location
31012 DEC A A=28/156: frog sitting
31013 JP 30903 Update the frog's animatory state and then resume control at the main entry point (30906)
The frog is planning a long hop. Check whether the coast is clear up to three spaces ahead.
31016 LD C,0
31018 JR NZ,31022 Jump if the frog is facing right
31020 DEC C
31021 DEC C
31022 INC C C=1 if the frog's facing right, 255 if facing left
31023 LD HL,32756 32756 holds the door/window status flags
31026 LD A,(HL) Pick these up in A
31027 LD B,A Save a copy of them in B briefly
31028 AND 63 Reset bits 6 and 7 of the door/window status flags (i.e. pretend that the windows are closed)
31030 LD (HL),A
31031 PUSH BC
31032 LD B,3 We will test up to 3 spaces in front of the frog
31034 LD A,E Set E to the x-coordinate of the spot 1, 2 or 3 spaces in front of the frog
31035 ADD A,C
31036 LD E,A
31037 PUSH DE
31038 CALL 30292 Check for walls and closed doors in the frog's path
31041 POP DE
31042 JR C,31046 Jump if there is one
31044 DJNZ 31034 Jump back until we've checked up to 3 spaces in front of the frog
31046 POP BC
31047 LD (HL),B Restore the original door/window status flags to 32756
31048 LD H,212 212=frog
31050 JP C,30944 Turn the frog round if there's a wall or closed door less than four spaces ahead
31053 CALL 30995 Otherwise move the frog one space forward and adjust its animatory state to 29/157 (airborne, phase one)
31056 LD L,17 Change the address in bytes 17 and 18 of the frog's buffer to 31061 (below) so that we resume there
31058 LD (HL),85
31060 RET
This entry point is used when the frog has just jumped into the air in order to make a long hop (three spaces forward). It is also used by the routine at 31254 to introduce the frog into the game with an initial animatory state of 29 (facing left, airborne, phase 1) and location (59,10).
31061 CALL 30995 Move the frog one space forward and adjust its animatory state to 30/158 (airborne, phase 2)
31064 LD L,17 Change the address in bytes 17 and 18 of the frog's buffer to 31069 (below) so that we resume there
31066 LD (HL),93
31068 RET
This entry point is used when the frog is at the highest point of a long hop.
31069 CALL 25012 Update the SRB for the frog's current animatory state and location
31072 DEC A A=29/157: frog airborne (phase one)
31073 JP 30999 Move the frog one space forward
Prev: 30804 Up: Map Next: 31076