Prev: 37972 Up: Map Next: 38243
37977: Finish Object Pass
The return address of every object handler.
It moves IX on to the next object record. If the frame counter has changed since the last time (that is, an interrupt has happened) the priority records are handled first: the two projectile records and, while Sabreman's type is from 9 to 27 Sabreman himself.
When all of the object records have been handled it adds one to the tick counter, counts down the gem timer, checks for the pause key and for a new press of an action key, runs the handlers of the small object records and then starts the main loop again.
Move on to the next object record and see if the frame counter has changed.
Finish_Object_Pass 37977 LD DE,16 Set the size of an object record to 16.
37980 ADD IX,DE Move IX on to the next object record.
37982 PUSH IX Stash the pointer to the next record on the stack.
37984 LD HL,(23672) Fetch the frame counter (the low word of FRAMES) from 23672.
37987 LD DE,(36575) Fetch the last frame counter from LastFrame.
37991 LD (36575),HL Store the new frame counter in LastFrame.
37994 AND A Subtract the last frame counter from the new one.
37995 SBC HL,DE
37997 JP NZ,Finish_Object_Pass_Priority_Records Jump to Finish_Object_Pass_Priority_Records if the frame counter has changed.
If there are more object records, run the handler of the next one.
Finish_Object_Pass_Next_Record 38000 POP HL Restore the pointer to the next record into HL.
38001 LD DE,36906 Point at the end of the object records (Small_Object_Records).
38004 AND A Subtract the end of the records from the pointer.
38005 SBC HL,DE
38007 JP C,Run_Object_Handler Jump to Run_Object_Handler if there are more records to handle.
All of the records have been handled, so count a tick.
38010 LD HL,(36566) Fetch the tick counter from GameTimer.
38013 INC HL Add one to the tick counter.
38014 LD (36566),HL Store the tick counter.
38017 LD A,(36593) Fetch the byte at Type_5C_Active_Flag.
38020 LD (36594),A Store it in Previous_Type_5C_Active_Flag.
38023 XOR A Write 0 to Type_5C_Active_Flag.
38024 LD (36593),A
38027 LD A,(36566) Fetch the low byte of the tick counter.
38030 AND %00000011 Keep only bits 0 and 1.
38032 JR NZ,Finish_Object_Pass_Check_Pause Jump to Finish_Object_Pass_Check_Pause if the tick counter is not a multiple of four.
Every fourth tick the gem timer counts down.
38034 LD A,(36590) Fetch the gem timer from Gem_Timer.
38037 AND A Jump to Finish_Object_Pass_Check_Pause if the gem timer is zero.
38038 JR Z,Finish_Object_Pass_Check_Pause
38040 DEC A Count down the gem timer, keeping it as a BCD value.
38041 DAA
38042 LD (36590),A Store the gem timer.
38045 PUSH AF Stash the timer flags on the stack.
38046 CALL Print_Status_Panel_Gem_Timer Print the gem timer.
38049 POP AF Restore the timer flags.
38050 JR NZ,Finish_Object_Pass_Check_Pause Jump to Finish_Object_Pass_Check_Pause if the gem timer has not run out.
38052 LD A,71 Make Sabreman bright white again.
38054 LD (36639),A
Check for the ENTER key which pauses the game.
Finish_Object_Pass_Check_Pause 38057 LD A,191 Read from the keyboard;
Port Number Bit
0 1 2 3 4
191 ENTER L K J H
38059 OUT (253),A
38061 IN A,(254)
38063 AND %00000001 Keep only the bit for ENTER.
38065 JR NZ,Finish_Object_Pass_Check_Action_Keys Jump to Finish_Object_Pass_Check_Action_Keys if ENTER is not pressed.
38067 DI Disable interrupts.
Wait for ENTER to be released.
Finish_Object_Pass_Wait_For_Release 38068 LD A,191 Read from the keyboard;
Port Number Bit
0 1 2 3 4
191 ENTER L K J H
38070 OUT (253),A
38072 CALL Pause_Briefly
38075 IN A,(254) Read from port 254.
38077 AND %00000001 Keep only the bit for ENTER.
38079 JR Z,Finish_Object_Pass_Wait_For_Release Jump to Finish_Object_Pass_Wait_For_Release if ENTER is still pressed.
The game is paused. Wait for ENTER to be pressed again.
Finish_Object_Pass_Wait_For_Resume 38081 LD A,191 Read from the keyboard;
Port Number Bit
0 1 2 3 4
191 ENTER L K J H
38083 OUT (253),A
38085 CALL Pause_Briefly
38088 IN A,(254) Read from port 254.
38090 AND %00000001 Keep only the bit for ENTER.
38092 JR NZ,Finish_Object_Pass_Wait_For_Resume Jump to Finish_Object_Pass_Wait_For_Resume if ENTER is not pressed.
Wait for ENTER to be released and carry on with the game.
Finish_Object_Pass_Wait_For_Final_Release 38094 LD A,191 Read from the keyboard;
Port Number Bit
0 1 2 3 4
191 ENTER L K J H
38096 OUT (253),A
38098 CALL Pause_Briefly
38101 IN A,(254) Read from port 254.
38103 AND %00000001 Keep only the bit for ENTER.
38105 JR Z,Finish_Object_Pass_Wait_For_Final_Release Jump to Finish_Object_Pass_Wait_For_Final_Release if ENTER is still pressed.
38107 EI Enable interrupts.
Check for the keys that pick up, drop or throw weapons (SPACE, SYMBOL SHIFT, M, N and B). A new press is recorded in New_Action_Key_Press_Flag and a held key in Action_Key_Held_Flag.
Finish_Object_Pass_Check_Action_Keys 38108 LD A,(36592) Fetch the room redrawn flag from Room_Redrawn_Flag.
38111 AND A Jump to Handle_Small_Objects if the room has just been redrawn.
38112 JR NZ,Handle_Small_Objects
38114 LD A,127 Read from the keyboard;
Port Number Bit
0 1 2 3 4
127 SPACE SYMBOL SHIFT M N B
38116 OUT (253),A
38118 IN A,(254)
38120 CPL Flip the bits so that a pressed key gives a set bit.
38121 AND %00011111 Keep only the bits of the five keys.
38123 JR NZ,Finish_Object_Pass_Key_Is_Pressed Jump to Finish_Object_Pass_Key_Is_Pressed if one of the keys is pressed.
Finish_Object_Pass_Store_Key_Flags 38125 LD (36585),A Store the key held flag in Action_Key_Held_Flag.
38128 LD (36586),A Store the new key press flag in New_Action_Key_Press_Flag.
38131 JR Handle_Small_Objects Jump to Handle_Small_Objects.
Finish_Object_Pass_Key_Is_Pressed 38133 LD A,(36585) Fetch the key held flag from Action_Key_Held_Flag.
38136 AND A Jump to Finish_Object_Pass_Key_Is_Held if the key was already pressed.
38137 JR NZ,Finish_Object_Pass_Key_Is_Held
This is a new press, so empty the table of the weapons that Sabreman holds; the handlers of the weapons fill it in again.
38139 XOR A Empty the three slots of the weapons table at Weapon_Slots.
38140 LD H,A
38141 LD L,A
38142 LD (36587),A
38145 LD (36588),HL
38148 LD A,255 Jump to Finish_Object_Pass_Store_Key_Flags with 255 to set the key held and new key press flags.
38150 JR Finish_Object_Pass_Store_Key_Flags
Finish_Object_Pass_Key_Is_Held 38152 XOR A The key is only being held, so clear the new key press flag in New_Action_Key_Press_Flag.
38153 LD (36586),A
Run the handlers of the small object records.
Handle_Small_Objects 38156 LD IX,36906 Point at the first small object record (Small_Object_Records).
Finish_Object_Pass_Small_Object_Loop 38160 LD HL,38220 Point at the return address of the handler (Finish_Object_Pass_Small_Object_Return).
38163 PUSH HL Stash it on the stack.
38164 LD L,(IX+0) Fetch the type of the object.
38167 LD BC,37402 Point at the handler table (Object_Handler_Table).
38170 JP Run_Object_Handler_Look_Up Jump to Run_Object_Handler_Look_Up to run the handler.
The frame counter has changed, so handle the priority records: the first two object records (the projectiles) and, when Sabreman's type is from 9 to 27 Sabreman's record too.
Finish_Object_Pass_Priority_Records 38173 LD IX,36602 Point at the first object record (Object_Records).
Finish_Object_Pass_Priority_Loop 38177 LD HL,38183 Point at the return address of the handler (Finish_Object_Pass_Priority_Return).
38180 JP Run_Object_Handler_Stash_Return Jump to Run_Object_Handler_Stash_Return to run the handler.
Finish_Object_Pass_Priority_Return 38183 LD DE,16 Set the size of an object record to 16.
38186 ADD IX,DE Move IX on to the next object record.
38188 LD DE,36634 Point at the record of Sabreman (Sabreman_Record).
38191 LD A,(36634) Fetch the type of Sabreman.
38194 CP 28 Jump to Finish_Object_Pass_Priority_Limit if the type is greater than or equal to 28.
38196 JR NC,Finish_Object_Pass_Priority_Limit
38198 CP 9 Jump to Finish_Object_Pass_Priority_Limit if the type is less than 9.
38200 JR C,Finish_Object_Pass_Priority_Limit
38202 LD DE,36650 Point at the record after Sabreman's (Rope_Record).
Finish_Object_Pass_Priority_Limit 38205 PUSH IX Copy IX to HL (using the stack).
38207 POP HL
38208 AND A Subtract the limit from the pointer.
38209 SBC HL,DE
38211 JR C,Finish_Object_Pass_Priority_Loop Jump to Finish_Object_Pass_Priority_Loop if there are more priority records to handle.
38213 POP IX Restore IX to the pointer to the next record.
38215 PUSH IX Stash it on the stack again.
38217 JP Finish_Object_Pass_Next_Record Jump to Finish_Object_Pass_Next_Record to carry on with the normal pass.
Return address of the handlers of the small object records.
Finish_Object_Pass_Small_Object_Return 38220 LD DE,8 Set the size of a small object record to 8.
38223 ADD IX,DE Move IX on to the next small object record.
38225 PUSH IX Copy IX to HL (using the stack).
38227 POP HL
38228 LD DE,36946 Point at the end of the small object records (Select_Game_Options).
38231 AND A Subtract the end of the records from the pointer.
38232 SBC HL,DE
38234 JR C,Finish_Object_Pass_Small_Object_Loop Jump to Finish_Object_Pass_Small_Object_Loop if there are more small object records to handle.
38236 XOR A Write 0 to Room_Redrawn_Flag to clear the room redrawn flag.
38237 LD (36592),A
38240 JP Main_Loop Jump back to the main loop.
Prev: 37972 Up: Map Next: 38243