Prev: 34436 Up: Map Next: 35140
34574: Main loop
The routine at 34436 continues here.
The first thing to do is check whether there are any remaining lives to draw at the bottom of the screen.
34574 LD A,(33879) Pick up the number of lives remaining from 33879
34577 LD HL,20640 Set HL to the display file address at which to draw the first Willy sprite
34580 OR A Are there any lives remaining?
34581 JR Z,34608 Jump if not
34583 LD B,A Initialise B to the number of lives remaining
The following loop draws the remaining lives at the bottom of the screen.
34584 LD C,0 C=0; this tells the sprite-drawing routine at 36852 to overwrite any existing graphics
34586 PUSH HL Save HL and BC briefly
34587 PUSH BC
34588 LD A,(33883) Pick up the in-game music note index from 33883; this will determine the animation frame for the Willy sprites
34591 RLCA Now A=0 (frame 0), 32 (frame 1), 64 (frame 2) or 96 (frame 3)
34592 RLCA
34593 RLCA
34594 AND 96
34596 LD E,A Point DE at the corresponding Willy sprite (at 33280+A)
34597 LD D,130
34599 CALL 36852 Draw the Willy sprite on the screen
34602 POP BC Restore HL and BC
34603 POP HL
34604 INC HL Move HL along to the location at which to draw the next Willy sprite
34605 INC HL
34606 DJNZ 34584 Jump back to draw any remaining sprites
Now draw a boot if cheat mode has been activated.
34608 LD A,(33885) Pick up the 6031769 key counter from 33885
34611 CP 7 Has 6031769 been keyed in yet?
34613 JR NZ,34623 Jump if not
34615 LD DE,47840 Point DE at the graphic data for the boot (at 47840)
34618 LD C,0 C=0 (overwrite mode)
34620 CALL 36852 Draw the boot at the bottom of the screen next to the remaining lives
Next, prepare the screen and attribute buffers for drawing to the screen.
34623 LD HL,24064 Copy the contents of the attribute buffer at 24064 (the attributes for the empty cavern) into the attribute buffer at 23552
34626 LD DE,23552
34629 LD BC,512
34632 LDIR
34634 LD HL,28672 Copy the contents of the screen buffer at 28672 (the tiles for the empty cavern) into the screen buffer at 24576
34637 LD DE,24576
34640 LD BC,4096
34643 LDIR
34645 CALL 36111 Move the horizontal guardians in the current cavern
34648 LD A,(33882) Pick up the game mode indicator from 33882
34651 OR A Are we in demo mode?
34652 CALL Z,35515 If not, move Willy
34655 LD A,(33882) Pick up the game mode indicator from 33882
34658 OR A Are we in demo mode?
34659 CALL Z,37434 If not, check and set the attribute bytes for Willy's sprite in the buffer at 23552, and draw Willy to the screen buffer at 24576
34662 CALL 36266 Draw the horizontal guardians in the current cavern
34665 CALL 37125 Move the conveyor in the current cavern
34668 CALL 36707 Draw the items in the current cavern and collect any that Willy is touching
34671 LD A,(33799) Pick up the number of the current cavern from 33799
34674 CP 4 Are we in Eugene's Lair?
34676 CALL Z,36344 If so, move and draw Eugene
34679 LD A,(33799) Pick up the number of the current cavern from 33799
34682 CP 13 Are we in Skylab Landing Bay?
34684 JP Z,36469 If so, move and draw the Skylabs
34687 LD A,(33799) Pick up the number of the current cavern from 33799
34690 CP 8 Are we in Wacky Amoebatrons or beyond?
34692 CALL NC,36593 If so, move and draw the vertical guardians
34695 LD A,(33799) Pick up the number of the current cavern from 33799
34698 CP 7 Are we in Miner Willy meets the Kong Beast?
34700 CALL Z,37173 If so, move and draw the Kong Beast
34703 LD A,(33799) Pick up the number of the current cavern from 33799
34706 CP 11 Are we in Return of the Alien Kong Beast?
34708 CALL Z,37173 If so, move and draw the Kong Beast
34711 LD A,(33799) Pick up the number of the current cavern from 33799
34714 CP 18 Are we in Solar Power Generator?
34716 CALL Z,36211 If so, move and draw the light beam
This entry point is used by the routine at 36469.
34719 CALL 36805 Draw the portal, or move to the next cavern if Willy has entered it
This entry point is used by the routine at 36101.
34722 LD HL,24576 Copy the contents of the screen buffer at 24576 to the display file
34725 LD DE,16384
34728 LD BC,4096
34731 LDIR
34733 LD A,(33880) Pick up the screen flash counter from 33880
34736 OR A Is it zero?
34737 JR Z,34760 Jump if so
34739 DEC A Decrement the screen flash counter at 33880
34740 LD (33880),A
34743 RLCA Move bits 0-2 into bits 3-5 and clear all the other bits
34744 RLCA
34745 RLCA
34746 AND 56
34748 LD HL,23552 Set every attribute byte in the buffer at 23552 to this value
34751 LD DE,23553
34754 LD BC,511
34757 LD (HL),A
34758 LDIR
34760 LD HL,23552 Copy the contents of the attribute buffer at 23552 to the attribute file
34763 LD DE,22528
34766 LD BC,512
34769 LDIR
34771 LD IX,33833 Print the score (see 33833) at (19,26)
34775 LD DE,20602
34778 LD C,6
34780 CALL 37562
34783 LD IX,33823 Print the high score (see 33823) at (19,11)
34787 LD DE,20587
34790 LD C,6
34792 CALL 37562
34795 CALL 35388 Decrease the air remaining in the current cavern
34798 JP Z,35071 Jump if there's no air left
Now check whether SHIFT and SPACE are being pressed.
34801 LD BC,65278 Read keys SHIFT-Z-X-C-V
34804 IN A,(C)
34806 LD E,A Save the result in E
34807 LD B,127 Read keys B-N-M-SS-SPACE
34809 IN A,(C)
34811 OR E Combine the results
34812 AND 1 Are SHIFT and SPACE being pressed?
34814 JP Z,34252 If so, quit the game
Now read the keys A, S, D, F and G (which pause the game).
34817 LD B,253 Read keys A-S-D-F-G
34819 IN A,(C)
34821 AND 31 Are any of these keys being pressed?
34823 CP 31
34825 JR Z,34837 Jump if not
34827 LD B,2 Read every half-row of keys except A-S-D-F-G
34829 IN A,(C)
34831 AND 31 Are any of these keys being pressed?
34833 CP 31
34835 JR Z,34827 Jump back if not (the game is still paused)
Here we check whether Willy has had a fatal accident.
34837 LD A,(32875) Pick up the airborne status indicator from 32875
34840 CP 255 Has Willy landed after falling from too great a height, or collided with a nasty or a guardian?
34842 JP Z,35071 Jump if so
Now read the keys H, J, K, L and ENTER (which toggle the in-game music).
34845 LD B,191 Prepare B for reading keys H-J-K-L-ENTER
34847 LD HL,33884 Point HL at the music flags at 33884
34850 IN A,(C) Read keys H-J-K-L-ENTER
34852 AND 31 Are any of these keys being pressed?
34854 CP 31
34856 JR Z,34868 Jump if not
34858 BIT 0,(HL) Were any of these keys being pressed the last time we checked?
34860 JR NZ,34870 Jump if so
34862 LD A,(HL) Set bit 0 (the keypress flag) and flip bit 1 (the in-game music flag) at 33884
34863 XOR 3
34865 LD (HL),A
34866 JR 34870
34868 RES 0,(HL) Reset bit 0 (the keypress flag) at 33884
34870 BIT 1,(HL) Has the in-game music been switched off?
34872 JR NZ,34911 Jump if so
The next section of code plays a note of the in-game music.
34874 LD A,(33883) Increment the in-game music note index at 33883
34877 INC A
34878 LD (33883),A
34881 AND 126 Point HL at the appropriate entry in the tune data table at 34188
34883 RRCA
34884 LD E,A
34885 LD D,0
34887 LD HL,34188
34890 ADD HL,DE
34891 LD A,(32883) Pick up the border colour for the current cavern from 32883
34894 LD E,(HL) Initialise the pitch delay counter in E
34895 LD BC,3 Initialise the duration delay counters in B (0) and C (3)
34898 OUT (254),A Produce a note of the in-game music
34900 DEC E
34901 JR NZ,34906
34903 LD E,(HL)
34904 XOR 24
34906 DJNZ 34898
34908 DEC C
34909 JR NZ,34898
If we're in demo mode, check the keyboard and joystick and return to the title screen if there's any input.
34911 LD A,(33882) Pick up the game mode indicator from 33882
34914 OR A Are we in demo mode?
34915 JR Z,34948 Jump if not
34917 DEC A We're in demo mode; is it time to show the next cavern?
34918 JP Z,35071 Jump if so
34921 LD (33882),A Update the game mode indicator at 33882
34924 LD BC,254 Read every row of keys on the keyboard
34927 IN A,(C)
34929 AND 31 Are any keys being pressed?
34931 CP 31
34933 JP NZ,34252 If so, return to the title screen
34936 LD A,(33881) Pick up the Kempston joystick indicator from 33881
34939 OR A Is there a joystick connected?
34940 JR Z,34948 Jump if not
34942 IN A,(31) Collect input from the joystick
34944 OR A Is the joystick being moved or the fire button being pressed?
34945 JP NZ,34252 If so, return to the title screen
Here we check the teleport keys.
34948 LD BC,61438 Read keys 6-7-8-9-0
34951 IN A,(C)
34953 BIT 4,A Is '6' (the activator key) being pressed?
34955 JP NZ,34984 Jump if not
34958 LD A,(33885) Pick up the 6031769 key counter from 33885
34961 CP 7 Has 6031769 been keyed in yet?
34963 JP NZ,34984 Jump if not
34966 LD B,247 Read keys 1-2-3-4-5
34968 IN A,(C)
34970 CPL Keep only bits 0-4 and flip them
34971 AND 31
34973 CP 20 Is the result 20 or greater?
34975 JP NC,34984 Jump if so (this is not a cavern number)
34978 LD (33799),A Store the cavern number at 33799
34981 JP 34449 Teleport into the cavern
Now check the 6031769 keys.
34984 LD A,(33885) Pick up the 6031769 key counter from 33885
34987 CP 7 Has 6031769 been keyed in yet?
34989 JP Z,34574 If so, jump back to the start of the main loop
34992 RLCA Point IX at the corresponding entry in the 6031769 table at 33888
34993 LD E,A
34994 LD D,0
34996 LD IX,33888
35000 ADD IX,DE
35002 LD BC,63486 Read keys 1-2-3-4-5
35005 IN A,(C)
35007 AND 31 Keep only bits 0-4
35009 CP (IX+0) Does this match the first byte of the entry in the 6031769 table?
35012 JR Z,35032 Jump if so
35014 CP 31 Are any of the keys 1-2-3-4-5 being pressed?
35016 JP Z,34574 If not, jump back to the start of the main loop
35019 CP (IX-2) Does the keyboard reading match the first byte of the previous entry in the 6031769 table?
35022 JP Z,34574 If so, jump back to the start of the main loop
35025 XOR A Reset the 6031769 key counter at 33885 to 0 (an incorrect key is being pressed)
35026 LD (33885),A
35029 JP 34574 Jump back to the start of the main loop
35032 LD B,239 Read keys 6-7-8-9-0
35034 IN A,(C)
35036 AND 31 Keep only bits 0-4
35038 CP (IX+1) Does this match the second byte of the entry in the 6031769 table?
35041 JR Z,35061 If so, jump to increment the 6031769 key counter
35043 CP 31 Are any of the keys 6-7-8-9-0 being pressed?
35045 JP Z,34574 If not, jump back to the start of the main loop
35048 CP (IX-1) Does the keyboard reading match the second byte of the previous entry in the 6031769 table?
35051 JP Z,34574 If so, jump back to the start of the main loop
35054 XOR A Reset the 6031769 key counter at 33885 to 0 (an incorrect key is being pressed)
35055 LD (33885),A
35058 JP 34574 Jump back to the start of the main loop
35061 LD A,(33885) Increment the 6031769 key counter at 33885 (the next key in the sequence is being pressed)
35064 INC A
35065 LD (33885),A
35068 JP 34574 Jump back to the start of the main loop
The air in the cavern has run out, or Willy has had a fatal accident, or it's demo mode and it's time to show the next cavern.
35071 LD A,(33882) Pick up the game mode indicator from 33882
35074 OR A Is it demo mode?
35075 JP NZ,36904 If so, move to the next cavern
35078 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.
35080 LD HL,22528 Fill the top two thirds of the attribute file with the value in A
35083 LD DE,22529
35086 LD BC,511
35089 LD (HL),A
35090 LDIR
35092 LD E,A Save the attribute byte (64-71) in E for later retrieval
35093 CPL D=63-8*(E AND 7); this value determines the pitch of the short note that will be played
35094 AND 7
35096 RLCA
35097 RLCA
35098 RLCA
35099 OR 7
35101 LD D,A
35102 LD C,E C=8+32*(E AND 7); this value determines the duration of the short note that will be played
35103 RRC C
35105 RRC C
35107 RRC C
35109 OR 16 Set bit 4 of A (for no apparent reason)
35111 XOR A Set A=0 (this will make the border black)
35112 OUT (254),A Produce a short note whose pitch is determined by D and whose duration is determined by C
35114 XOR 24
35116 LD B,D
35117 DJNZ 35117
35119 DEC C
35120 JR NZ,35112
35122 LD A,E Restore the attribute byte (originally 71) to A
35123 DEC A Decrement it (effectively decrementing the INK colour)
35124 CP 63 Have we used attribute value 64 (INK 0) yet?
35126 JR NZ,35080 If not, jump back to update the INK colour in the top two thirds of the screen and make another sound effect
Finally, check whether any lives remain.
35128 LD HL,33879 Pick up the number of lives remaining from 33879
35131 LD A,(HL)
35132 OR A Are there any lives remaining?
35133 JP Z,35140 If not, display the game over sequence
35136 DEC (HL) Decrease the number of lives remaining by one
35137 JP 34449 Jump back to reinitialise the current cavern
Prev: 34436 Up: Map Next: 35140