| Routines

35591: Main loop (2)

Used by the routine at 35245. The main entry point is used when resuming the game after it has been paused.
35591 | LD HL,39424 | Copy the attribute bytes from 39424 to the bottom third of the screen
35594 | LD DE,23040
35597 | LD BC,256
35600 | LDIR
35602 | LD A,(32990) | Pick up the border colour for the current room from 32990
35605 | OUT (254),A | Restore the border colour
This entry point is used by the routine at 35245.
35607 | LD A,(34257) | Pick up the airborne status indicator from 34257
35610 | CP 255 | Has Willy landed after falling from too great a height, or collided with a nasty, an arrow, a guardian, or Maria?
35612 | JP Z,35841 | If so, lose a life
Now read the keys H, J, K, L and ENTER (which toggle the in-game music).
35615 | LD B,191 | Prepare B for reading keys H-J-K-L-ENTER
35617 | LD HL,34274 | Point HL at the music flags at 34274
35620 | IN A,(C) | Read keys H-J-K-L-ENTER; note that if the game has just resumed after being paused, C holds 0 instead of 254, which is a bug
35622 | AND 31 | Are any of these keys being pressed?
35624 | CP 31
35626 | JR Z,35638 | Jump if not
35628 | BIT 0,(HL) | Were any of these keys being pressed the last time we checked?
35630 | JR NZ,35640 | Jump if so
35632 | LD A,(HL) | Set bit 0 (the keypress flag) and flip bit 1 (the in-game music flag) at 34274
35633 | XOR 3
35635 | LD (HL),A
35636 | JR 35640 |
35638 | RES 0,(HL) | Reset bit 0 (the keypress flag) at 34274
35640 | BIT 1,(HL) | Has the in-game music been switched off?
35642 | JR NZ,35696 | Jump if so
The next section of code plays a note of the in-game music. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
35644 | XOR A | Reset the inactivity timer at 34272 (the game does not automatically pause after a period of inactivity if the in-game music is playing)
35645 | LD (34272),A
35648 | LD A,(34273) | Increment the in-game music note index at 34273
35651 | INC A
35652 | LD (34273),A
35655 | AND 126 | Point HL at the appropriate entry in the tune data table at 34399
35657 | RRCA
35658 | LD E,A
35659 | LD D,0
35661 | LD HL,34399
35664 | ADD HL,DE
35665 | LD A,(34252) | Pick up the number of lives remaining (0-7) from 34252
35668 | 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)
35669 | RLCA
35670 | SUB 28
35672 | NEG
35674 | ADD A,(HL) | Add the entry from the tune data table for the current note
35675 | LD D,A | Copy this value to D (which determines the pitch of the note)
35676 | LD A,(32990) | Pick up the border colour for the current room from 32990
35679 | LD E,D | Initialise the pitch delay counter in E
35680 | LD BC,3 | Initialise the duration delay counters in B (0) and C (3)
35683 | OUT (254),A | Produce a note of the in-game music
35685 | DEC E
35686 | JR NZ,35691
35688 | LD E,D
35689 | XOR 24
35691 | DJNZ 35683
35693 | DEC C
35694 | JR NZ,35683
Here we check the teleport keys.
35696 | LD BC,61438 | Read keys 6-7-8-9-0
35699 | IN A,(C)
35701 | BIT 1,A | Is '9' (the activator key) being pressed?
35703 | JP NZ,35735 | Jump if not
35706 | AND 16 | Keep only bit 4 (corresponding to the '6' key), flip it, and move it into bit 5
35708 | XOR 16
35710 | RLCA
35711 | LD D,A | Now bit 5 of D is set if '6' is being pressed
35712 | LD A,(34275) | Pick up the WRITETYPER key counter from 34275
35715 | CP 10 | Has WRITETYPER been keyed in yet?
35717 | JP NZ,35735 | Jump if not
35720 | LD BC,63486 | Read keys 1-2-3-4-5
35723 | IN A,(C)
35725 | CPL | Keep only bits 0-4 and flip them
35726 | AND 31
35728 | OR D | Copy bit 5 of D into A; now A holds the number of the room to teleport to
35729 | LD (33824),A | Store the room number at 33824
35732 | JP 35090 | Teleport into the room
Finally, check the WRITETYPER keys.
35735 | LD A,(34275) | Pick up the WRITETYPER key counter from 34275
35738 | CP 10 | Has WRITETYPER been keyed in yet?
35740 | JP Z,35245 | If so, jump back to the start of the main loop
35743 | LD A,(33824) | Pick up the current room number from 33824
35746 | CP 28 | Are we in First Landing?
35748 | JP NZ,35245 | If not, jump back to the start of the main loop
35751 | LD A,(34255) | Pick up Willy's y-coordinate from 34255
35754 | CP 208 | Is Willy on the floor at the bottom of the staircase?
35756 | JP NZ,35245 | If not, jump back to the start of the main loop
35759 | LD A,(34275) | Pick up the WRITETYPER key counter (0-9) from 34275
35762 | RLCA | Point IX at the corresponding entry in the WRITETYPER table at 34279
35763 | LD E,A
35764 | LD D,0
35766 | LD IX,34279
35770 | ADD IX,DE
35772 | LD BC,64510 | Read keys Q-W-E-R-T
35775 | IN A,(C)
35777 | AND 31 | Keep only bits 0-4
35779 | CP (IX+0) | Does this match the first byte of the entry in the WRITETYPER table?
35782 | JR Z,35802 | Jump if so
35784 | CP 31 | Are any of the keys Q-W-E-R-T being pressed?
35786 | JP Z,35245 | If not, jump back to the start of the main loop
35789 | CP (IX-2) | Does the keyboard reading match the first byte of the previous entry in the WRITETYPER table?
35792 | JP Z,35245 | If so, jump back to the start of the main loop
35795 | XOR A | Reset the WRITETYPER key counter at 34275 to 0 (an incorrect key was pressed)
35796 | LD (34275),A
35799 | JP 35245 | Jump back to the start of the main loop
35802 | LD B,223 | Read keys Y-U-I-O-P
35804 | IN A,(C)
35806 | AND 31 | Keep only bits 0-4
35808 | CP (IX+1) | Does this match the second byte of the entry in the WRITETYPER table?
35811 | JR Z,35831 | If so, jump to increment the WRITETYPER key counter
35813 | CP 31 | Are any of the keys Y-U-I-O-P being pressed?
35815 | JP Z,35245 | If not, jump back to the start of the main loop
35818 | CP (IX-1) | Does the keyboard reading match the second byte of the previous entry in the WRITETYPER table?
35821 | JP Z,35245 | If so, jump back to the start of the main loop
35824 | XOR A | Reset the WRITETYPER key counter at 34275 to 0 (an incorrect key was pressed)
35825 | LD (34275),A
35828 | JP 35245 | Jump back to the start of the main loop
35831 | LD A,(34275) | Increment the WRITETYPER key counter at 34275
35834 | INC A
35835 | LD (34275),A
35838 | JP 35245 | Jump back to the start of the main loop