Routines

30804: Deal with frog when knocked out of cup


The address of this routine is placed into the frog's buffer by the routine at 30229 when a catapult pellet has knocked the frog out of the cup in the girls' skool

30804 3AEB7F LD A,(32747)
30807 0F RRCA
30808 384F JR C,30889 Jump if ERIC already has the safe key
30810 2100CC LD HL,52224 Point to byte 0 of MISS TAKE's buffer
30813 7E LD A,(HL) A=MISS TAKE's animatory state
30814 2C INC L
30815 5E LD E,(HL) E=MISS TAKE's x-coordinate
30816 2C INC L
30817 FE76 CP 118 Is MISS TAKE sitting on the floor facing left?
30819 2808 JR Z,30829 Jump if so
30821 FEF6 CP 246 Is she sitting on the floor facing right?
30823 3EFC LD A,252
30825 2005 JR NZ,30832 Jump if not
30827 1D DEC E
30828 1D DEC E
30829 1C INC E Now E=x-coordinate of MISS TAKE's head
30830 3EFD LD A,253
30832 86 ADD A,(HL)
30833 26D4 LD H,212 212=frog
30835 BE CP (HL) (HL)=frog's y-coordinate
30836 2033 JR NZ,30889 Jump if the frog has not reached the level of MISS TAKE's head
30838 2D DEC L
30839 7E LD A,(HL) A=frog's x-coordinate
30840 BB CP E Compare with MISS TAKE's x-coordinate
30841 202E JR NZ,30889 Jump if they don't match

ERIC's pellet has knocked the frog out of the cup and onto MISS TAKE's head. Celebrate!
30843 21EB7F LD HL,32747 Inventory flags
30846 CBC6 SET 0,(HL) Give ERIC the safe key
30848 3EC8 LD A,200 Add 2000 to the score and print it
30850 CDB573 CALL 29621
30853 210003 LD HL,768 Make safe-key-getting celebratory sound effect
30856 1601 LD D,1
30858 7D LD A,L
30859 E63F AND 63
30861 3C INC A
30862 47 LD B,A
30863 4E LD C,(HL)
30864 CBE1 SET 4,C
30866 CD8C74 CALL 29836
30869 2D DEC L
30870 20F0 JR NZ,30856
30872 00 NOP
30873 00 NOP
30874 00 NOP
30875 CD027C CALL 31746 Print the inventory
30878 26D4 LD H,212 212=frog
30880 CDB461 CALL 25012 Update SRB for frog's current animatory state and location
30883 1D DEC E
30884 3C INC A A=29: Frog facing left, airborne (stage 1)
30885 14 INC D Make frog fall one level
30886 C33061 JP 24880 Update SRB for frog's new animatory state and location

We come here if the frog either hasn't hit MISS TAKE yet, or has hit the ground without doing so.
30889 CDB461 CALL 25012 Update SRB for frog's current animatory state and location
30892 CB62 BIT 4,D Is the frog about to hit the floor?
30894 28F5 JR Z,30885 Jump if not
30896 FE1C CP 28 28=frog sitting still, facing left
30898 3E1C LD A,28
30900 20F0 JR NZ,30886 Jump if the frog has one more level to drop before reaching the floor
30902 14 INC D D=17 (ground floor level)
30903 CD4677 CALL 30534 Place address 30906 into bytes 17 and 18 of frog's buffer and update SRB for frog's new animatory state and location

This section of code deals with the frog once it has landed
30906 ED5B01D2 LD DE,(53761) Pick up ERIC's coordinates in DE
30910 2E02 LD L,2
30912 7E LD A,(HL) A=frog's y-coordinate
30913 BA CP D Does it match ERIC's y-coordinate?
30914 2012 JR NZ,30934 Jump if not
30916 2D DEC L
30917 7E LD A,(HL) A=frog's x-coordinate
30918 93 SUB E Is ERIC to the left of the frog?
30919 3002 JR NC,30923 Jump if so
30921 ED44 NEG
30923 FE04 CP 4 Now A=horizontal distance between frog and ERIC
30925 3007 JR NC,30934 Jump if this is greater than 3
30927 CD9162 CALL 25233 Get random number in A
30930 F6C0 OR 192 The frog will move if ERIC's close by
30932 1806 JR 30940
30934 CD9162 CALL 25233 Get random number in A
30937 FEC0 CP 192
30939 D8 RET C Return without moving frog 3 times out of 4
30940 FEF0 CP 240 A≥192 at this point
30942 3810 JR C,30960 Jump if 192≤A<240
30944 CDB461 CALL 25012 Update SRB for frog's current animatory state and location
30947 3C INC A A=next animatory state for frog
30948 CD4677 CALL 30534 Place address 30951 into bytes 17 and 18 of frog's buffer and update SRB for frog's new animatory state and location

30951 CDB461 CALL 25012 Update SRB for frog's current animatory state and location
30954 3D DEC A A=frog's new animatory state
30955 EE80 XOR 128 Turn frog round
30957 C3B778 JP 30903

30960 2E00 LD L,0
30962 FED8 CP 216 Note: 192≤A<240
30964 CB7E BIT 7,(HL)
30966 2E01 LD L,1
30968 5E LD E,(HL) E=frog's x-coordinate
30969 2E02 LD L,2
30971 56 LD D,(HL) D=frog's y-coordinate
30972 382A JR C,31016 Jump if A<216 (50% of the time)
30974 2002 JR NZ,30978 Jump if the frog is facing right
30976 1D DEC E
30977 1D DEC E
30978 1C INC E E=x-coordinate of position directly in front of frog
30979 21F47F LD HL,32756
30982 7E LD A,(HL) Pick up the doors flags
30983 47 LD B,A
30984 E63F AND 63 Lose bits 6 and 7 (windows)
30986 77 LD (HL),A
30987 CD5476 CALL 30292 Check for closed doors and walls
30990 70 LD (HL),B Restore the doors flags
30991 26D4 LD H,212 212=frog
30993 38CD JR C,30944 Jump if there's a wall or closed door in the frog's path
30995 CDB461 CALL 25012 Update SRB for frog's current animatory state and location
30998 3C INC A
30999 07 RLCA
31000 0F RRCA
31001 3802 JR C,31005 Jump if frog is facing right
31003 1D DEC E
31004 1D DEC E
31005 1C INC E Now E=x-coordinate of position directly in front of frog
31006 CD4677 CALL 30534 Place address 31009 into bytes 17 and 18 of the frog's buffer and update SRB for frog's new animatory state and location

31009 CDB461 CALL 25012 Update SRB for frog's current animatory state and location
31012 3D DEC A A=frog's new animatory state
31013 C3B778 JP 30903

31016 0E00 LD C,0
31018 2002 JR NZ,31022 Jump if the frog is facing right
31020 0D DEC C
31021 0D DEC C
31022 0C INC C C=1 if the frog's facing right, 255 if facing left
31023 21F47F LD HL,32756
31026 7E LD A,(HL) Pick up the doors flags
31027 47 LD B,A
31028 E63F AND 63 Lose bits 6 and 7 (windows)
31030 77 LD (HL),A
31031 C5 PUSH BC
31032 0603 LD B,3
31034 7B LD A,E A=frog's current x-coordinate
31035 81 ADD A,C
31036 5F LD E,A Now E=x-coordinate of position in front of frog
31037 D5 PUSH DE
31038 CD5476 CALL 30292 Check for walls and closed doors in the frog's path
31041 D1 POP DE
31042 3802 JR C,31046 Jump if frog has hit one
31044 10F4 DJNZ 31034
31046 C1 POP BC
31047 70 LD (HL),B Restore the doors flags
31048 26D4 LD H,212 212=frog
31050 DAE078 JP C,30944 Jump if frog has hit a wall or closed door
31053 CD1379 CALL 30995 Move frog one space forward
31056 2E11 LD L,17 Change the address in bytes 17 and 18 of the frog's buffer to 31061
31058 3655 LD (HL),85
31060 C9 RET

This entry point is used by the routine at 31254 to bring the frog into the game:
31061 CD1379 CALL 30995 Move frog one space forward
31064 2E11 LD L,17 Change the address in bytes 17 and 18 of the frog's buffer to 31069
31066 365D LD (HL),93
31068 C9 RET

31069 CDB461 CALL 25012 Update SRB for frog's current animatory state and location
31072 3D DEC A A=frog's new animatory state
31073 C31779 JP 30999 Jump to move frog one space forward