Routines
 Prev: 7854 Up: Map Next: 7964
78BA: 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 0xD4 (frog)
78BA LD DE,(\$D201) Pick up ERIC's coordinates in DE
78BE LD L,\$02 Point HL at byte 0x02 of the frog's buffer
78C0 LD A,(HL) A=frog's y-coordinate
78C1 CP D Does it match ERIC's y-coordinate?
78C2 JR NZ,\$78D6 Jump if not
78C4 DEC L L=0x01
78C5 LD A,(HL) A=frog's x-coordinate
78C6 SUB E Is ERIC to the left of the frog?
78C7 JR NC,\$78CB Jump if so
78C9 NEG
78CB CP \$04 Now A=horizontal distance between the frog and ERIC
78CD JR NC,\$78D6 Jump if this is greater than 3
78CF CALL \$6291 A=random number >= 0xC0
78D2 OR \$C0
78D4 JR \$78DC
78D6 CALL \$6291 A=random number
78D9 CP \$C0 Return 3 times out of 4 (without moving the frog) when ERIC is not nearby
78DB 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).
78DC CP \$F0 A>=0xC0 at this point
78DE JR C,\$78F0 Jump if 0xC0<=A<0xF0 (75% of the time) to make a short or long hop
78E0 CALL \$61B4 Update the SRB for the frog's current animatory state and location
78E3 INC A A=0x1D/0x9D: frog airborne (phase one)
78E4 CALL \$7746 Update the frog's animatory state and then resume control at entry point 78E7 (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).
78E7 CALL \$61B4 Update the SRB for the frog's current animatory state
78EA DEC A A=0x1C/0x9C: frog sitting
78EB XOR \$80 Turn the frog round
78ED JP \$78B7 Update the frog's animatory state and then resume control at the main entry point (78BA)
The frog is planning a hop. Decide between a short hop (one space forward) and a long hop (three spaces forward).
78F0 LD L,\$00 Point HL at byte 0x00 of the frog's buffer
78F2 CP \$D8 Set the carry flag if 0xC0<=A<0xD8
78F4 BIT 7,(HL) Set the zero flag if the frog is facing left
78F6 LD L,\$01 Pick up the frog's x-coordinate in E and y-coordinate in D
78F8 LD E,(HL)
78F9 LD L,\$02
78FB LD D,(HL)
78FC JR C,\$7928 Jump if A<0xD8 (50% of the time) to consider a long hop
78FE JR NZ,\$7902 Jump if the frog is facing right
7900 DEC E
7901 DEC E
7902 INC E E=x-coordinate of the spot directly in front of the frog
7903 LD HL,\$7FF4 7FF4 holds the door/window status flags
7906 LD A,(HL) Pick these up in A
7907 LD B,A Save a copy of them in B briefly
7908 AND \$3F Reset bits 6 and 7 of the door/window status flags (i.e. pretend that the windows are closed)
790A LD (HL),A
790B CALL \$7654 Check for closed doors and walls in the frog's path
790E LD (HL),B Restore the original door/window status flags
790F LD H,\$D4 0xD4=frog
7911 JR C,\$78E0 Turn the frog round if there's a wall or closed door in its path
7913 CALL \$61B4 Update the SRB for the frog's current animatory state and location
7916 INC A A=0x1D/0x9D: frog airborne (phase one)
7917 RLCA
7918 RRCA
7919 JR C,\$791D Jump if the frog is facing right
791B DEC E
791C DEC E
791D INC E Now E=x-coordinate of the spot directly in front of the frog
791E CALL \$7746 Update the frog's animatory state and then resume control at entry point 7921 (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.
7921 CALL \$61B4 Update the SRB for the frog's current animatory state and location
7924 DEC A A=0x1C/0x9C: frog sitting
7925 JP \$78B7 Update the frog's animatory state and then resume control at the main entry point (78BA)
The frog is planning a long hop. Check whether the coast is clear up to three spaces ahead.
7928 LD C,\$00
792A JR NZ,\$792E Jump if the frog is facing right
792C DEC C
792D DEC C
792E INC C C=0x01 if the frog's facing right, 0xFF if facing left
792F LD HL,\$7FF4 7FF4 holds the door/window status flags
7932 LD A,(HL) Pick these up in A
7933 LD B,A Save a copy of them in B briefly
7934 AND \$3F Reset bits 6 and 7 of the door/window status flags (i.e. pretend that the windows are closed)
7936 LD (HL),A
7937 PUSH BC
7938 LD B,\$03 We will test up to 3 spaces in front of the frog
793A LD A,E Set E to the x-coordinate of the spot 1, 2 or 3 spaces in front of the frog
793C LD E,A
793D PUSH DE
793E CALL \$7654 Check for walls and closed doors in the frog's path
7941 POP DE
7942 JR C,\$7946 Jump if there is one
7944 DJNZ \$793A Jump back until we've checked up to 3 spaces in front of the frog
7946 POP BC
7947 LD (HL),B Restore the original door/window status flags to 7FF4
7948 LD H,\$D4 0xD4=frog
794A JP C,\$78E0 Turn the frog round if there's a wall or closed door less than four spaces ahead
794D CALL \$7913 Otherwise move the frog one space forward and adjust its animatory state to 0x1D/0x9D (airborne, phase one)
7950 LD L,\$11 Change the address in bytes 0x11 and 0x12 of the frog's buffer to 7955 (below) so that we resume there
7952 LD (HL),\$55
7954 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 7A16 to introduce the frog into the game with an initial animatory state of 0x1D (facing left, airborne, phase 1) and location (59,10).
7955 CALL \$7913 Move the frog one space forward and adjust its animatory state to 0x1E/0x9E (airborne, phase 2)
7958 LD L,\$11 Change the address in bytes 0x11 and 0x12 of the frog's buffer to 795D (below) so that we resume there
795A LD (HL),\$5D
795C RET
This entry point is used when the frog is at the highest point of a long hop.
795D CALL \$61B4 Update the SRB for the frog's current animatory state and location
7960 DEC A A=0x1D/0x9D: frog airborne (phase one)
7961 JP \$7917 Move the frog one space forward
 Prev: 7854 Up: Map Next: 7964