Skip to navigation

Lander on the Acorn Archimedes

Particles: SetParticleColourToFade

Name: SetParticleColourToFade [Show more] Type: Subroutine Category: Particles Summary: Set the flags for a particle whose colour fades from white to red over time, to give a white-hot explosion particle that cools down Deep dive: Particles and particle clouds Screen memory in the Archimedes
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MoveAndDrawParticles (Part 1 of 4) calls SetParticleColourToFade

Arguments: R6 Particle lifespan counter (i.e. how many iterations around the main loop before the particle expires)
Returns: R7 Particle flags for a fading colour particle * Bits 0-7 = particle colour * 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
.SetParticleColourToFade STMFD R13!, {R0-R2, R6} \ Store R0, R1, R2 and R6 on the stack so \ they don't get corrupted by the following \ We start by setting up a three-channel \ colour, with the red channel in R0, the \ green channel in R1 and the blue channel \ in R2 MOV R0, #15 \ Set the red channel to 15 CMP R6, #8 \ If R6 >= 8, set: MOVHS R1, #15 \ MOVLO R1, R6, LSL #1 \ Green channel in R1 = 15 SUBHS R2, R6, #8 \ Blue channel in R2 = (R6 - 8) * 2 MOVHS R2, R2, LSL #1 \ MOVLO R2, #0 \ otherwise set: \ \ Green channel in R1 = R6 * 2 \ Blue channel in R2 = 0 \ \ So particles start out white (R6 > 8) \ with a fading level of blue, until the \ blue disappears entirely (R6 = 8) and \ then the green fades away (R6 < 8) to \ leave a pure red particle (R6 = 0) \ \ So this is a fading particle from white \ to red, so this looks like a burning \ particle from an explosion that cools \ over time \ We now build a VIDC colour number in R7 \ by combining the three channels into one \ byte, which we then replicate four times \ to get a 32-bit colour number \ \ The byte is of the form: \ \ * Bit 7 = blue bit 3 \ * Bit 6 = green bit 3 \ * Bit 5 = green bit 2 \ * Bit 4 = red bit 3 \ * Bit 3 = blue bit 2 \ * Bit 2 = red bit 2 \ * Bit 1 = sum of red/green/blue bit 1 \ * Bit 0 = sum of red/green/blue bit 0 \ \ We now build this colour number in R7 from \ the red, green and blue values in R0, R1 \ and R2 ORR R7, R1, R2 \ Set R7 to the bottom three bits of: AND R7, R7, #%00000011 \ ORR R7, R7, R0 \ (the bottom two bits of R1 OR R2) OR R0 AND R7, R7, #7 \ \ So this sets bits 0, 1 and 2 of R7 as \ required TST R0, #%00001000 \ If bit 3 of the red channel in R0 is set, ORRNE R7, R7, #%00010000 \ set bit 4 of R7 AND R1, R1, #%00001100 \ Clear all bits of the green channel in R1 \ except bits 2-3 ORR R7, R7, R1, LSL #3 \ And stick them into bits 5-6 of R7 TST R2, #%00000100 \ If bit 2 of the blue channel in R2 is set, ORRNE R7, R7, #%00001000 \ set bit 3 of R7 TST R2, #%00001000 \ If bit 3 of the blue channel in R2 is set, ORRNE R7, R7, #%10000000 \ set bit 7 of R7 ORR R7, 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 LDMFD R13!, {R0-R2, R6} \ Retrieve the registers that we stored on \ the stack above MOV PC, R14 \ Return from the subroutine