Skip to navigation

Lander on the Acorn Archimedes

Player: MoveAndDrawPlayer (Part 4 of 5)

Name: MoveAndDrawPlayer (Part 4 of 5) [Show more] Type: Subroutine Category: Player Summary: Spawn the particles in the exhaust plume if the engine is engaged Deep dive: Flying by mouse
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
LDRB R10, [R11, #fuelBurnRate] \ If both bits 1 and 2 of the fuel burn rate TST R10, #%00000110 \ are clear then the engine is not running, BEQ ship7 \ so jump to ship7 to skip generating an \ exhaust plume ADD R14, R11, #xVelocity \ Set R0 to R2 and R6 to R8 as follows by LDMIA R14, {R0-R2, R6-R8} \ fetching the values we stored in part 2: \ \ R0 = xVelocity \ R1 = yVelocity \ R2 = zVelocity \ \ R6 = xExhaust \ R7 = yExhaust \ R8 = zExhaust \ \ So (R0, R1, R2) is the player's velocity \ and (R6, R7, R8) is the player's thrust \ vector ADD R3, R0, R6, ASR #7 \ Set (R3, R4, R5) as follows: ADD R4, R1, R7, ASR #7 \ ADD R5, R2, R8, ASR #7 \ [ (xVelocity + xExhaust / 128) / 2 ] MOV R3, R3, ASR #1 \ [ (yVelocity + yExhaust / 128) / 2 ] MOV R4, R4, ASR #1 \ [ (zVelocity + zExhaust / 128) / 2 ] MOV R5, R5, ASR #1 \ \ So this sets (R3, R4, R5) to a vector in \ the direction of the player's velocity \ (so the particles move along with the \ ship) and in the direction of the exhaust \ plume (so that's heading away from the \ engine, in the direction that it's \ pointing), and we halve the result so they \ shoot out of the engine but soon get left \ behind as we blast away ADD R0, R11, #xPlayer \ Set R0 to R2 as follows: LDMIA R0, {R0-R2} \ \ R0 = xPlayer \ R1 = yPlayer \ R2 = zPlayer \ \ So (R0, R1, R2) is the player's coordinate SUB R0, R0, R3 \ Set (R0, R1, R2) as follows: SUB R1, R1, R4 \ SUB R2, R2, R5 \ [ xPlayer - R3 + (xExhaust / 128) ] ADD R0, R0, R6, ASR #7 \ [ yPlayer - R4 + (yExhaust / 128) ] ADD R1, R1, R7, ASR #7 \ [ zPlayer - R5 + (zExhaust / 128) ] ADD R2, R2, R8, ASR #7 \ \ So this sets (R0, R1, R2) to the position \ of the player's ship, but a little way in \ the direction of the exhaust plume (so \ that's below the engine in the direction \ that it's pointing), and we also subtract \ the velocity in (R3, R4, R5) because the \ first thing that happens when we process \ the particle in MoveAndDrawParticles is \ to add the velocity, so this cancels that \ out to ensure the particle starts out \ along the line of the exhaust plume \ By this stage we have: \ \ (R0, R1, R2) = particle coordinate \ \ (R3, R4, R5) = particle velocity \ \ We now set the values of R6 to R9 to pass \ to the AddExhaustParticleToBuffer routine MOV R7, #&001D0000 \ Set bits 16, 18, 19 and 20 of the particle \ flags, so that's: \ \ * Bit 16 set = colour fades white to red \ * Bit 18 set = splash on impact with sea \ * Bit 19 set = bounce on ground \ * Bit 20 set = apply gravity to particle MOV R6, #8 \ Set the particle's lifespan counter to 8 \ iterations of the main loop MOV R8, #10 \ Set the random element of the particle's \ velocity to the range +/- 2^(32 - 10), \ i.e. -&400000 to +&400000 MOV R9, #29 \ Set the random element of the particle's \ lifespan to the range 0 to 2^(32 - 29), \ i.e. 0 to 8 STMFD R13!, {R0-R9} \ Store R0 to R9 on the stack so we can \ fetch this set of values before each call \ to AddExhaustParticleToBuffer \ We now call the AddExhaustParticleToBuffer \ routine eight times if full thrust is \ engaged, or twice if hover mode is being \ used (so the exhaust plume is four times \ denser when full thrust is engaged) BL AddExhaustParticleToBuffer \ Call AddExhaustParticleToBuffer with the \ set of parameters in R0 to R9 to add the \ first exhaust plume particle to the \ particle data buffer TST R10, #%00000100 \ If bit 2 of R10 is set then full thrust is LDMNEIA R13, {R0-R9} \ engaged, so fetch the same parameters and BLNE AddExhaustParticleToBuffer \ add the second particle to the particle \ data buffer TST R10, #%00000100 \ If bit 2 of R10 is set then full thrust is LDMNEIA R13, {R0-R9} \ engaged, so fetch the same parameters and BLNE AddExhaustParticleToBuffer \ add the third particle to the particle \ data buffer TST R10, #%00000100 \ If bit 2 of R10 is set then full thrust is LDMNEIA R13, {R0-R9} \ engaged, so fetch the same parameters and BLNE AddExhaustParticleToBuffer \ add the fourth particle to the particle \ data buffer TST R10, #%00000100 \ If bit 2 of R10 is set then full thrust is LDMNEIA R13, {R0-R9} \ engaged, so fetch the same parameters and BLNE AddExhaustParticleToBuffer \ add the fifth particle to the particle \ data buffer TST R10, #%00000100 \ If bit 2 of R10 is set then full thrust is LDMNEIA R13, {R0-R9} \ engaged, so fetch the same parameters and BLNE AddExhaustParticleToBuffer \ add the sixth particle to the particle \ data buffer TST R10, #%00000100 \ If bit 2 of R10 is set then full thrust is LDMNEIA R13, {R0-R9} \ engaged, so fetch the same parameters and BLNE AddExhaustParticleToBuffer \ add the seventh particle to the particle \ data buffer LDMFD R13!, {R0-R9} \ Fetch the same parameters and add the BL AddExhaustParticleToBuffer \ final particle to the particle data buffer