Jet Set Willy: Routine at 35841

| Routines

35841: Lose a life

Used by the routine at 35591.
35841 | LD A,71 | A=71 (INK 7: PAPER 0: BRIGHT 1)
The following loop fills the top two thirds of the attribute file with a single value (71, 70, 69, 68, 67, 66, 65 or 64) and makes a sound effect. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
35843 | LD HL,22528 | Fill the top two thirds of the attribute file with the value in A
35846 | LD DE,22529
35849 | LD BC,511
35852 | LD (HL),A
35853 | LDIR
35855 | LD E,A | Save the attribute byte (64-71) in E for later retrieval
35856 | CPL | D=63-8*(E AND 7); this value determines the pitch of the short note that will be played
35857 | AND 7
35859 | RLCA
35860 | RLCA
35861 | RLCA
35862 | OR 7
35864 | LD D,A
35865 | LD C,E | C=8+32*(E AND 7); this value determines the duration of the short note that will be played
35866 | RRC C
35868 | RRC C
35870 | RRC C
35872 | OR 16 | Set bit 4 of A (for no apparent reason)
35874 | XOR A | Set A=0 (this will make the border black)
35875 | OUT (254),A | Produce a short note whose pitch is determined by D and whose duration is determined by C
35877 | XOR 24
35879 | LD B,D
35880 | DJNZ 35880
35882 | DEC C
35883 | JR NZ,35875
35885 | LD A,E | Restore the attribute byte (originally 71) to A
35886 | DEC A | Decrement it (effectively decrementing the INK colour)
35887 | CP 63 | Have we used attribute value 64 (INK 0) yet?
35889 | JR NZ,35843 | If not, jump back to update the INK colour in the top two thirds of the screen and make another sound effect
Now check whether any lives remain.
35891 | LD HL,34252 | Pick up the number of lives remaining from 34252
35894 | LD A,(HL)
35895 | OR A | Are there any lives remaining?
35896 | JP Z,35914 | If not, display the game over sequence
35899 | DEC (HL) | Decrease the number of lives remaining by one
35900 | LD HL,34263 | Restore Willy's state upon entry to the room by copying the seven bytes at 34263 back into 34255-34261
35903 | LD DE,34255
35906 | LD BC,7
35909 | LDIR
35911 | JP 35090 | Reinitialise the room and resume the game