Skip to navigation

Elite on the BBC Micro

Drawing planets: PLANET [Electron version]

Name: PLANET [Show more] Type: Subroutine Category: Drawing planets Summary: Draw the planet
Context: See this subroutine in context in the source code Variations: See code variations for this subroutine in the different versions References: This subroutine is called as follows: * LL9 (Part 1 of 12) calls PLANET

Arguments: INWK The planet's ship data block
.PLANET LDA TYPE \ If bit 0 of the ship type is set, then this is 129, LSR A \ which is the placeholder used to denote there is no BCS PL2-1 \ space station, so return from the subroutine (as PL2-1 \ contains an RTS) LDA INWK+8 \ Set A = z_sign (the highest byte in the planet's \ coordinates) BMI PL2 \ If A is negative then the planet is behind us, so \ jump to PL2 to remove it from the screen, returning \ from the subroutine using a tail call CMP #48 \ If A >= 48 then the planet is too far away to be BCS PL2 \ seen, so jump to PL2 to remove it from the screen, \ returning from the subroutine using a tail call ORA INWK+7 \ Set A to z_sign OR z_hi to get the maximum of the two BEQ PL2 \ If the maximum is 0, then the planet is too close \ to be shown, so jump to PL2 to remove it from the \ screen, returning from the subroutine using a tail \ call JSR PROJ \ Project the planet onto the screen, returning the \ centre's coordinates in K3(1 0) and K4(1 0) BCS PL2 \ If the C flag is set by PROJ then the planet is \ not visible on-screen, so jump to PL2 to remove it \ from the screen, returning from the subroutine using \ a tail call LDA #96 \ Set (A P+1 P) = (0 96 0) = 24576 STA P+1 \ LDA #0 \ This represents the planet's radius at a distance STA P \ of z = 1 JSR DVID3B2 \ Call DVID3B2 to calculate: \ \ K(3 2 1 0) = (A P+1 P) / (z_sign z_hi z_lo) \ = (0 96 0) / z \ = 24576 / z \ \ so K now contains the planet's radius, reduced by \ the actual distance to the planet. We know that \ K+3 and K+2 will be 0, as the number we are dividing, \ (0 96 0), fits into the two bottom bytes, so the \ result is actually in K(1 0) LDA K+1 \ If the high byte of the reduced radius is zero, jump BEQ PL82 \ to PL82, as K contains the radius on its own LDA #248 \ Otherwise set K = 248, to use as our one-byte radius STA K .PL82 JSR WPLS2 \ Call WPLS2 to remove the planet from the screen JMP CIRCLE \ Jump to CIRCLE to draw the planet (which is just a \ simple circle) and return from the subroutine using \ a tail call