Skip to navigation

Elite on the BBC Micro

Version analysis of PLANET

This code appears in the following versions (click to see it in the source code):

Code variations between these versions are shown below.

Name: PLANET Type: Subroutine Category: Drawing planets

Code variation 1 of 8A variation in the comments only

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

Summary: Draw the planet or sun
Summary: Draw the planet

Arguments:

Code variation 2 of 8A variation in the comments only

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

INWK The planet or sun's ship data block
INWK The planet's ship data block
.PLANET

Code variation 3 of 8Related to the Electron version

In the Electron version, the PLANET routine only draws planets and will terminate if asked to draw a sun.

This variation is blank in the Cassette, Disc (flight), 6502 Second Processor and Master versions.

Electron

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)

Code variation 4 of 8Related to the screen mode

This variation is blank in the Cassette, Disc (flight) and Electron versions.

Tap on a version to expand it, and tap it again to show to all variations.

Master

6502SP

LDA #GREEN \ Switch to stripe 3-1-3-1, which is cyan/yellow in the STA COL \ space view
LDA #GREEN \ Send a #SETCOL GREEN command to the I/O processor to JSR DOCOL \ switch to stripe 3-1-3-1, which is cyan/yellow in the \ space view

Code variation 5 of 8A variation in the comments only

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

LDA INWK+8 \ Set A = z_sign (the highest byte in the planet/sun's \ coordinates)
LDA INWK+8 \ Set A = z_sign (the highest byte in the planet's \ coordinates)

Code variation 6 of 8Other (e.g. bug fix, optimisation)

In the cassette version, in part 14 of the main flight loop, we didn't remove the planet/sun if it was behind us, so we do it here instead.

This variation is blank in the Master version.

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight

6502SP

Electron

BMI PL2 \ If A is negative then the planet/sun is behind us, so \ jump to PL2 to remove it from the screen, returning \ from the subroutine using a tail call
\BMI PL2 \ This instruction is commented out in the original \ source. It would remove the planet from the screen \ when it's behind us
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

Code variation 7 of 8A variation in the comments only

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

CMP #48 \ If A >= 48 then the planet/sun 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/sun 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/sun 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/sun 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/sun'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/sun's radius, reduced by \ the actual distance to the planet/sun. 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)
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

Code variation 8 of 8Related to the Electron version

Planets in the Electron version are simple circles, so the code to draw meridians and craters is omitted, and the simple CIRCLE routine is used instead.

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

LDA TYPE \ If the planet/sun's type has bit 0 clear, then it's LSR A \ either 128 or 130, which is a planet (the sun has type BCC PL9 \ 129, which has bit 0 set). So jump to PL9 to draw the \ planet with radius K, returning from the subroutine \ using a tail call JMP SUN \ Otherwise jump to SUN to draw the sun with radius K, \ returning from the subroutine using a tail call
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
RSS Feed