Routines
 Prev: 8AEB Up: Map Next: 8C01
8B07: Main loop (2)
Used by the routine at 89AD. The main entry point is used when resuming the game after it has been paused.
Input
Output
8B07 LD HL,\$9A00 Copy the attribute bytes from 9A00 to the bottom third of the screen
8B0A LD DE,\$5A00
8B0D LD BC,\$0100
8B10 LDIR
8B12 LD A,(\$80DE) Pick up the border colour for the current room from 80DE
8B15 OUT (\$FE),A Restore the border colour
This entry point is used by the routine at 89AD.
8B17 LD A,(\$85D1) Pick up the airborne status indicator from 85D1
8B1A CP \$FF Has Willy landed after falling from too great a height, or collided with a nasty, an arrow, a guardian, or Maria?
8B1C JP Z,\$8C01 If so, lose a life
Now read the keys H, J, K, L and ENTER (which toggle the in-game music).
8B1F LD B,\$BF Prepare B for reading keys H-J-K-L-ENTER
8B21 LD HL,\$85E2 Point HL at the music flags at 85E2
8B24 IN A,(C) Read keys H-J-K-L-ENTER; note that if the game has just resumed after being paused, C holds 0x00 instead of 0xFE, which is a bug
8B26 AND \$1F Are any of these keys being pressed?
8B28 CP \$1F
8B2A JR Z,\$8B36 Jump if not
8B2C BIT 0,(HL) Were any of these keys being pressed the last time we checked?
8B2E JR NZ,\$8B38 Jump if so
8B30 LD A,(HL) Set bit 0 (the keypress flag) and flip bit 1 (the in-game music flag) at 85E2
8B31 XOR \$03
8B33 LD (HL),A
8B34 JR \$8B38
8B36 RES 0,(HL) Reset bit 0 (the keypress flag) at 85E2
8B38 BIT 1,(HL) Has the in-game music been switched off?
8B3A JR NZ,\$8B70 Jump if so
The next section of code plays a note of the in-game music.
8B3C XOR A Reset the inactivity timer at 85E0 (the game does not automatically pause after a period of inactivity if the in-game music is playing)
8B3D LD (\$85E0),A
8B40 LD A,(\$85E1) Increment the in-game music note index at 85E1
8B43 INC A
8B44 LD (\$85E1),A
8B47 AND \$7E Point HL at the appropriate entry in the tune data table at 865F
8B49 RRCA
8B4A LD E,A
8B4B LD D,\$00
8B4D LD HL,\$865F
8B50 ADD HL,DE
8B51 LD A,(\$85CC) Pick up the number of lives remaining (0-7) from 85CC
8B54 RLCA A=28-4A; this value adjusts the pitch of the note that is played depending on how many lives are remaining (the more lives remaining, the higher the pitch)
8B55 RLCA
8B56 SUB \$1C
8B58 NEG
8B5A ADD A,(HL) Add the entry from the tune data table for the current note
8B5B LD D,A Copy this value to D (which determines the pitch of the note)
8B5C LD A,(\$80DE) Pick up the border colour for the current room from 80DE
8B5F LD E,D Initialise the pitch delay counter in E
8B60 LD BC,\$0003 Initialise the duration delay counters in B (0) and C (3)
8B63 OUT (\$FE),A Produce a note of the in-game music
8B65 DEC E
8B66 JR NZ,\$8B6B
8B68 LD E,D
8B69 XOR \$18
8B6B DJNZ \$8B63
8B6D DEC C
8B6E JR NZ,\$8B63
Here we check the teleport keys.
8B70 LD BC,\$EFFE Read keys 6-7-8-9-0
8B73 IN A,(C)
8B75 BIT 1,A Is '9' (the activator key) being pressed?
8B77 JP NZ,\$8B97 Jump if not
8B7A AND \$10 Keep only bit 4 (corresponding to the '6' key), flip it, and move it into bit 5
8B7C XOR \$10
8B7E RLCA
8B7F LD D,A Now bit 5 of D is set if '6' is being pressed
8B80 LD A,(\$85E3) Pick up the WRITETYPER key counter from 85E3
8B83 CP \$0A Has WRITETYPER been keyed in yet?
8B85 JP NZ,\$8B97 Jump if not
8B88 LD BC,\$F7FE Read keys 1-2-3-4-5
8B8B IN A,(C)
8B8D CPL Keep only bits 0-4 and flip them
8B8E AND \$1F
8B90 OR D Copy bit 5 of D into A; now A holds the number of the room to teleport to
8B91 LD (\$8420),A Store the room number at 8420
8B94 JP \$8912 Teleport into the room
Finally, check the WRITETYPER keys.
8B97 LD A,(\$85E3) Pick up the WRITETYPER key counter from 85E3
8B9A CP \$0A Has WRITETYPER been keyed in yet?
8B9C JP Z,\$89AD If so, jump back to the start of the main loop
8B9F LD A,(\$8420) Pick up the current room number from 8420
8BA2 CP \$1C Are we in First Landing?
8BA4 JP NZ,\$89AD If not, jump back to the start of the main loop
8BA7 LD A,(\$85CF) Pick up Willy's pixel y-coordinate from 85CF
8BAA CP \$D0 Is Willy on the floor at the bottom of the staircase?
8BAC JP NZ,\$89AD If not, jump back to the start of the main loop
8BAF LD A,(\$85E3) Pick up the WRITETYPER key counter (0-9) from 85E3
8BB2 RLCA Point IX at the corresponding entry in the WRITETYPER table at 85E7
8BB3 LD E,A
8BB4 LD D,\$00
8BB6 LD IX,\$85E7
8BBA ADD IX,DE
8BBC LD BC,\$FBFE Read keys Q-W-E-R-T
8BBF IN A,(C)
8BC1 AND \$1F Keep only bits 0-4
8BC3 CP (IX+\$00) Does this match the first byte of the entry in the WRITETYPER table?
8BC6 JR Z,\$8BDA Jump if so
8BC8 CP \$1F Are any of the keys Q-W-E-R-T being pressed?
8BCA JP Z,\$89AD If not, jump back to the start of the main loop
8BCD CP (IX-\$02) Does the keyboard reading match the first byte of the previous entry in the WRITETYPER table?
8BD0 JP Z,\$89AD If so, jump back to the start of the main loop
8BD3 XOR A Reset the WRITETYPER key counter at 85E3 to 0 (an incorrect key was pressed)
8BD4 LD (\$85E3),A
8BD7 JP \$89AD Jump back to the start of the main loop
8BDA LD B,\$DF Read keys Y-U-I-O-P
8BDC IN A,(C)
8BDE AND \$1F Keep only bits 0-4
8BE0 CP (IX+\$01) Does this match the second byte of the entry in the WRITETYPER table?
8BE3 JR Z,\$8BF7 If so, jump to increment the WRITETYPER key counter
8BE5 CP \$1F Are any of the keys Y-U-I-O-P being pressed?
8BE7 JP Z,\$89AD If not, jump back to the start of the main loop
8BEA CP (IX-\$01) Does the keyboard reading match the second byte of the previous entry in the WRITETYPER table?
8BED JP Z,\$89AD If so, jump back to the start of the main loop
8BF0 XOR A Reset the WRITETYPER key counter at 85E3 to 0 (an incorrect key was pressed)
8BF1 LD (\$85E3),A
8BF4 JP \$89AD Jump back to the start of the main loop
8BF7 LD A,(\$85E3) Increment the WRITETYPER key counter at 85E3
8BFA INC A
8BFB LD (\$85E3),A
8BFE JP \$89AD Jump back to the start of the main loop
 Prev: 8AEB Up: Map Next: 8C01