Skip to navigation

Elite on the BBC Micro and NES

Moving: MVEIT (Part 2 of 9)

[NES version, Bank 0]

Name: MVEIT (Part 2 of 9) [Show more] Type: Subroutine Category: Moving Summary: Move current ship: Call tactics routine, remove ship from scanner Deep dive: Scheduling tasks with the main loop counter
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MVEIT (Part 1 of 9) calls via MV30 * TITLE calls via MV30

This routine has multiple stages. This stage does the following: * Apply tactics to ships with AI enabled (by calling the TACTICS routine) * Remove the ship from the scanner, so we can move it
Other entry points: MV30 Move the ship in space but without tidying the orientation vectors or applying tactics
.MV3 LDX TYPE ; If the type of the ship we are moving is positive, BPL P%+5 ; i.e. it is not a planet (types 128 and 130) or sun ; (type 129), then skip the following instruction JMP MV40 ; This item is the planet or sun, so jump to MV40 to ; move it, which ends by jumping back into this routine ; at MV45 (after all the rotation, tactics and scanner ; code, which we don't need to apply to planets or suns) LDA INWK+32 ; Fetch the ship's byte #32 (AI flag) into A BPL MV30 ; If bit 7 of the AI flag is clear, then if this is a ; ship or missile it is dumb and has no AI, and if this ; is the space station it is not hostile, so in both ; cases skip the following as it has no tactics CPX #MSL ; If the ship is a missile, skip straight to MV26 to BEQ MV26 ; call the TACTICS routine, as we do this every ; iteration of the main loop for missiles only LDA MCNT ; Fetch the main loop counter EOR XSAV ; Fetch the slot number of the ship we are moving, EOR AND #7 ; with the loop counter and apply mod 8 to the result. BNE MV30 ; The result will be zero when "counter mod 8" matches ; the slot number mod 8, so this makes sure we call ; TACTICS 12 times every 8 main loop iterations, like ; this: ; ; Iteration 0, apply tactics to slots 0 and 8 ; Iteration 1, apply tactics to slots 1 and 9 ; Iteration 2, apply tactics to slots 2 and 10 ; Iteration 3, apply tactics to slots 3 and 11 ; Iteration 4, apply tactics to slot 4 ; Iteration 5, apply tactics to slot 5 ; Iteration 6, apply tactics to slot 6 ; Iteration 7, apply tactics to slot 7 ; Iteration 8, apply tactics to slots 0 and 8 ; ... ; ; and so on .MV26 SETUP_PPU_FOR_ICON_BAR ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 JSR TACTICS ; Call TACTICS to apply AI tactics to this ship .MV30