Prev: 7B54 Up: Map Next: 7BE8
7B55: Make ERIC catch a mouse or frog (if present)
The address of this routine is placed into 7FD7 by the routine at E125 after 'C' has been pressed. Adds the mouse or frog to ERIC's inventory if he has managed to catch it. If the captive animal is a mouse, another one is set free for ERIC to catch.
Input
H 0xD2 (ERIC)
7B55 LD L,$00 Point HL at byte 0x00 of ERIC's buffer
7B57 LD A,(HL) A=ERIC's animatory state
7B58 RLCA Set A to -1 if ERIC is facing left, or 1 if he's facing right
7B59 SBC A,A
7B5A ADD A,A
7B5B CPL
7B5C INC L L=1
7B5D ADD A,(HL) Now A=x-coordinate of the spot in front of ERIC
7B5E INC L L=2
7B5F LD DE,($D401) Pick up the coordinates of the animal using buffer 0xD4 (mouse or frog)
7B63 CP E Is there a mouse or frog at this x-coordinate?
7B64 RET NZ Return if not
7B65 LD A,(HL) A=ERIC's y-coordinate
7B66 CP D Is the mouse/frog on this floor?
7B67 RET NZ Return if not
7B68 LD A,($D400) Pick up the mouse/frog's animatory state in A
7B6B AND $7F Discard all but the 'direction' bit (bit 7)
7B6D CP $2F 0x2F: Is it a mouse?
7B6F JP NZ,$7BF5 Jump if not (it's the frog)
ERIC has managed to catch the mouse.
7B72 LD H,$D4 H=0xD4 (the mouse's buffer)
7B74 CALL $61B4 Update the SRB for the mouse's current animatory state and location
Determine where to release another mouse.
7B77 LD HL,$7FFF 7FFF holds the column of the play area at the far left of the screen
7B7A CALL $6291 A=R, a random number from 0 to 7; we'll use this to determine where the new free mouse will be placed
7B7D AND $07
7B7F LD D,A Copy this random number to D
7B80 CP $02 Jump if R>=2
7B82 JR NC,$7B8C
R=0 or 1. The next section of code is intended to set the x-coordinate for the the new free mouse to 170 provided that X<128, or try again with a new random number (R) if X>=128. However, at this point HL may have been set to 7F0A (byte 0x0A of the screen refresh buffer) or 7F58 (byte 4 of the buffer for the Blue Room blackboard) by the LD L,$0A or LD L,$58 instruction below, and so the contents of 7F0A or 7F58 (instead of X at 7FFF) may be compared with 128. Thus it is possible for the new free mouse to appear at x-coordinate 170 even when X>=128, which means it could appear on-screen. This is a bug.
7B84 LD A,(HL) A=X (column of the play area at the far left of the screen), or the contents of 7F0A or 7F58
7B85 RLCA
7B86 JR C,$7B7A Jump if A>=128 to get another random number
7B88 LD L,$AA This will be the x-coordinate for the new free mouse
7B8A JR $7BA3 Go and figure out the y-coordinate
7B8C CP $05
7B8E LD A,(HL) A=X (column of the play area at the far left of the screen), or the contents of 7F0A or 7F58
7B8F JR NC,$7B9D Jump if R>=5
R=2, 3 or 4. The next section of code is intended to set the x-coordinate for the new free mouse to 88 provided that X<56 or X>=104, or try again with a new random number (R) if 56<=X<104. However, as noted above, HL may now hold 7F0A or 7F58 instead of 7FFF, and so the contents of 7F0A or 7F58 (instead of X) may be compared with 56 and 104. Thus it is possible for the new free mouse to appear at x-coordinate 88 even when 56<=X<104, which means it could appear on-screen. This is a bug.
7B91 CP $38
7B93 LD L,$58 This is a possible x-coordinate for the new free mouse
7B95 JR C,$7BA3 Jump if A<56 to figure out the y-coordinate
7B97 CP $68 Jump if 56<=A<104 to get another random number
7B99 JR C,$7B7A
7B9B JR $7BA3 Go and figure out the y-coordinate for the mouse
R=5, 6 or 7. The next section of code is intended to set the x-coordinate for the new free mouse to 10 provided that X>=56, or try again with a new random number (R) if X<56. However, as noted above, HL may now hold 7F0A or 7F58 instead of 7FFF, and so the contents of 7F0A or 7F58 (instead of X) may be compared with 56. Thus it is possible for the new free mouse to appear at x-coordinate 10 even when X<56, which means it could appear on-screen. This is a bug.
7B9D LD L,$0A This is a possible x-coordinate for the new free mouse
7B9F CP $38 Jump if A<56 to get another random number
7BA1 JR C,$7B7A
The x-coordinate for the new free mouse (10, 88 or 170) has been determined. Now to determine the mouse's y-coordinate.
7BA3 LD A,D A=R (the random number from 0 to 7)
7BA4 SUB $03 Convert this to a random number from 0 to 2 by taking the remainder when divided by 3
7BA6 JR NC,$7BA4
7BA8 ADD A,$03
7BAA LD H,$11 This is a possible y-coordinate for the new free mouse (bottom floor)
7BAC JR Z,$7BB5 Jump if the random number is 0
7BAE DEC A
7BAF LD H,$0A This is a possible y-coordinate for the new free mouse (middle floor)
7BB1 JR Z,$7BB5 Jump if the random number was 1
7BB3 LD H,$03 This is the y-coordinate for the new free mouse (top floor)
7BB5 LD ($D401),HL Fill in the location of the new free mouse
7BB8 LD A,$0A Add 100 to the score, print it and make a sound effect
7BBA CALL $7118
7BBD LD HL,$7FE1 7FE1 holds the number of mice ERIC has caught
7BC0 INC (HL) Increase this by 1
7BC1 LD A,(HL)
Now it's time to update the on-screen mouse inventory. This entry point is used by the routine at 7AE6.
7BC2 LD A,($7FE1) A=number of mice in ERIC's pocket
7BC5 LD C,A C will count the number of mice remaining to be printed in the inventory
7BC6 LD L,$A8 0xA8=LSB of the display file address for the spot in the inventory for the first captive mouse
7BC8 LD A,C A=number of mice left to print
7BC9 AND A Set the zero flag if there are none left
7BCA LD B,$08 There are 8 bytes in the mouse UDG/inventory slot
7BCC LD H,$50 Set HL to the appropriate display file address
7BCE JR NZ,$7BD6 Jump if we need to draw a mouse here
7BD0 LD (HL),A Otherwise blank out this spot in the mouse inventory
7BD1 INC H
7BD2 DJNZ $7BD0
7BD4 JR $7BE0 Move to the next spot in the mouse inventory
7BD6 LD DE,$9FE0 The captured mouse UDG is at 9FE0
7BD9 DEC C Decrease the captured mouse counter
7BDA LD A,(DE) Display a captured mouse in the inventory
7BDB LD (HL),A
7BDC INC H
7BDD INC E
7BDE DJNZ $7BDA
7BE0 INC L Point to the next spot in the mouse inventory
7BE1 BIT 4,L Have we drawn all 8 spots yet (L=0xB0)?
7BE3 JR Z,$7BC8 Jump back to draw the next one if not
7BE5 LD H,$D2 0xD2=ERIC
7BE7 RET
Prev: 7B54 Up: Map Next: 7BE8