Manic Miner: Routine at 9135

| Routines

9135: Move and draw the Kong Beast in the current cavern

Used by the routine at 870E.
9135 | LD HL,$5C06 | Flip the left-hand switch at (0,6) if Willy is touching it
9138 | CALL $921B
913B | LD A,($80DB) | Pick up the Kong Beast's status from 80DB
913E | CP $02 | Is the Kong Beast already dead?
9140 | RET Z | Return if so
9141 | LD A,($7506) | Pick up the sixth pixel row of the left-hand switch from the screen buffer at 7000
9144 | CP $10 | Has the switch been flipped?
9146 | JP Z,$91F9 | Jump if not
The left-hand switch has been flipped. Deal with opening up the wall if that is still in progress.
9149 | LD A,($5F71) | Pick up the attribute byte of the tile at (11,17) in the buffer at 5E00
914C | OR A | Has the wall there been removed yet?
914D | JR Z,$9176 | Jump if so
914F | LD HL,$7F71 | Point HL at the bottom row of pixels of the wall tile at (11,17) in the screen buffer at 7000
9152 | LD A,(HL) | Pick up a pixel row
9153 | OR A | Is it blank yet?
9154 | JR NZ,$916C | Jump if not
9156 | DEC H | Point HL at the next pixel row up
9157 | LD A,H | Have we checked all 8 pixel rows yet?
9158 | CP $77
915A | JR NZ,$9152 | If not, jump back to check the next one
915C | LD A,($8020) | Pick up the attribute byte of the background tile for the current cavern from 8020
915F | LD ($5F71),A | Change the attributes at (11,17) and (12,17) in the buffer at 5E00 to match the background tile (the wall there is now gone)
9162 | LD ($5F91),A
9165 | LD A,$72 | Update the seventh byte of the guardian definition at 80C5 so that the guardian moves through the opening in the wall
9167 | LD ($80CB),A
916A | JR $9176 |
916C | LD (HL),$00 | Clear a pixel row of the wall tile at (11,17) in the screen buffer at 7000
916E | LD L,$91 | Point HL at the opposite pixel row of the wall tile one cell down at (12,17)
9170 | LD A,H
9171 | XOR $07
9173 | LD H,A
9174 | LD (HL),$00 | Clear that pixel row as well
Now check the right-hand switch.
9176 | LD HL,$5C12 | Flip the right-hand switch at (0,18) if Willy is touching it (and it hasn't already been flipped)
9179 | CALL $921B
917C | JR NZ,$919D | Jump if the switch was not flipped
917E | XOR A | Initialise the Kong Beast's pixel y-coordinate at 80DC to 0
917F | LD ($80DC),A
9182 | INC A | Update the Kong Beast's status at 80DB to 1: he is falling
9183 | LD ($80DB),A
9186 | LD A,($8020) | Pick up the attribute byte of the background tile for the current cavern from 8020
9189 | LD ($5E4F),A | Change the attributes of the floor beneath the Kong Beast in the buffer at 5E00 to match that of the background tile
918C | LD ($5E50),A
918F | LD HL,$704F | Point HL at (2,15) in the screen buffer at 7000
9192 | LD B,$08 | Clear the cells at (2,15) and (2,16), removing the floor beneath the Kong Beast
9194 | LD (HL),$00
9196 | INC L
9197 | LD (HL),$00
9199 | DEC L
919A | INC H
919B | DJNZ $9194
919D | LD A,($80DB) | Pick up the Kong Beast's status from 80DB
91A0 | OR A | Is the Kong Beast still on the ledge?
91A1 | JR Z,$91F9 | Jump if so
The Kong Beast is falling.
91A3 | LD A,($80DC) | Pick up the Kong Beast's pixel y-coordinate from 80DC
91A6 | CP $64 | Has he fallen into the portal yet?
91A8 | JR Z,$91F3 | Jump if so
91AA | ADD A,$04 | Add 4 to the Kong Beast's pixel y-coordinate at 80DC (moving him downwards)
91AC | LD ($80DC),A
91AF | LD C,A | Copy the pixel y-coordinate to C; this value determines the pitch of the sound effect
91B0 | LD D,$10 | This value determines the duration of the sound effect
91B2 | LD A,($8073) | Pick up the border colour for the current cavern from 8073
91B5 | OUT ($FE),A | Make a falling sound effect
91B7 | XOR $18
91B9 | LD B,C
91BA | DJNZ $91BA
91BC | DEC D
91BD | JR NZ,$91B5
91BF | LD A,C | Copy the Kong Beast's pixel y-coordinate back into A
91C0 | RLCA | Point DE at the entry in the screen buffer address lookup table at 8300 that corresponds to the Kong Beast's pixel y-coordinate
91C1 | LD E,A
91C2 | LD D,$83
91C4 | LD A,(DE) | Point HL at the address of the Kong Beast's location in the screen buffer at 6000
91C5 | OR $0F
91C7 | LD L,A
91C8 | INC DE
91C9 | LD A,(DE)
91CA | LD H,A
91CB | LD D,$81 | Use bit 5 of the value of the game clock at 80BD (which is toggled once every eight passes through the main loop) to point DE at the graphic data for the appropriate Kong Beast sprite
91CD | LD A,($80BD)
91D0 | AND $20
91D2 | OR $40
91D4 | LD E,A
91D5 | LD C,$00 | Draw the Kong Beast to the screen buffer at 6000
91D7 | CALL $8FF4
91DA | LD HL,$842C | Add 100 to the score
91DD | CALL $90FE
91E0 | LD A,($80DC) | Pick up the Kong Beast's pixel y-coordinate from 80DC
91E3 | AND $78 | Point HL at the address of the Kong Beast's location in the attribute buffer at 5C00
91E5 | LD L,A
91E6 | LD H,$17
91E8 | ADD HL,HL
91E9 | ADD HL,HL
91EA | LD A,L
91EB | OR $0F
91ED | LD L,A
91EE | LD A,$06 | The Kong Beast is drawn with yellow INK
91F0 | JP $8E5F | Set the attribute bytes for the Kong Beast
The Kong Beast has fallen into the portal.
91F3 | LD A,$02 | Set the Kong Beast's status at 80DB to 2: he is dead
91F5 | LD ($80DB),A
91F8 | RET |
The Kong Beast is still on the ledge.
91F9 | LD A,($80BD) | Pick up the value of the game clock at 80BD
91FC | AND $20 | Use bit 5 of this value (which is toggled once every eight passes through the main loop) to point DE at the graphic data for the appropriate Kong Beast sprite
91FE | LD E,A
91FF | LD D,$81
9201 | LD HL,$600F | Draw the Kong Beast at (0,15) in the screen buffer at 6000
9204 | LD C,$01
9206 | CALL $8FF4
9209 | JP NZ,$8D06 | Kill Willy if he collided with the Kong Beast
920C | LD A,$44 | A=0x44 (INK 4: PAPER 0: BRIGHT 1)
920E | LD ($5C2F),A | Set the attribute bytes for the Kong Beast in the buffer at 5C00
9211 | LD ($5C30),A
9214 | LD ($5C0F),A
9217 | LD ($5C10),A
921A | RET |