Astronomy Conversions

This file is part of Timex Sinclair Public Domain Library Tape 1002 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Astronomy

This program is a simple astronomical unit-conversion tool that converts between light-years, kilometres, and miles. It presents a text menu using INKEY$ for keypress detection without requiring ENTER, looping back to the menu after each conversion. The conversion constants used are 9.4830912×10¹² km and 5.892792872×10¹² miles per light-year, the latter being slightly low compared to the accepted value of approximately 5.879×10¹² miles, suggesting a minor inaccuracy in the miles constant. The program uses `10**12` (exponentiation) for expressing large astronomical constants inline, and the menu-driven flow relies on string comparison with `C$>”1″` to branch between options 2 and 3 versus option 1.


Program Analysis

Program Structure

The program is divided into several logical blocks, navigated by menu choice stored in C$:

  1. Lines 10–130: Initialisation, menu display, and INKEY$ input loop.
  2. Lines 300–390: Light-years → km and miles conversion (option 1).
  3. Lines 400–460: km → light-years conversion (option 2).
  4. Lines 500–530: Miles → light-years conversion (option 3).
  5. Lines 540–560: Shared output and loop-back to menu.
  6. Lines 600–700: SAVE and RUN utility lines, not part of normal execution flow.

Menu Input and Branching

The program uses a tight INKEY$ polling loop at lines 120130 to detect a keypress without requiring ENTER. Only three choices are valid (1, 2, 3), but the branching logic is coarse: line 140 uses IF C$>"1" to divert anything greater than “1” (i.e., “2”, “3”, or any higher character) to line 400. Within that block, line 410 specifically checks for “3” to divert to the miles input. Any character other than “1”, “2”, or “3” will enter the km conversion path silently, which is a minor robustness issue.

Conversion Constants

The program defines its conversion factors inline using the exponentiation operator **:

ConversionConstant UsedAccepted Value
Light-year → km9.4830912 × 10¹²9.4607 × 10¹² km
Light-year → miles5.892792872 × 10¹²5.8786 × 10¹² miles

Both constants are somewhat inaccurate compared to the modern IAU definition, with the km value about 0.24% too high and the miles value about 0.24% too high as well — consistent with each other but diverging from accepted values, suggesting the author used a slightly off source figure for the light-year.

Key BASIC Idioms

  • INKEY$ polling loop: Lines 120130 form the classic IF INKEY$="" THEN GOTO busy-wait for a single keypress, avoiding the need for INPUT and ENTER.
  • Exponentiation with **: Used at lines 340, 350, 450, and 530 to express 10¹² compactly inline.
  • Shared output path: Lines 540560 handle the final light-year output for all three reverse-conversion branches, reducing code duplication.
  • GOTO 10 loop: Line 560 returns to the menu start rather than a dedicated restart line, re-running variable initialisation (M=0, K=0) each cycle.

Notable Anomalies

  • Line 300 is reached from the menu only when C$="1", but there is no explicit GOTO 300 — execution falls through from line 140 when the condition is false (i.e., when C$ is not greater than “1”). This works correctly but is easy to misread.
  • After completing a light-year → km/miles conversion (option 1), execution falls into line 400 (CLS) and then line 410, which checks C$ again. Since C$ is still “1” at this point, neither branch at 410 triggers, so it falls through to the km input at line 420 — meaning option 1 unexpectedly prompts for a km value after displaying its results. This is a genuine bug.
  • The PRINT L at line 330 and similar echo prints (lines 440, 520) re-display the just-entered value, a common idiom to confirm INPUT on machines without line-editing feedback.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10051 – 10121.

Related Products

Related Articles

Related Content

Image Gallery

Astronomy Conversions

Source Code

   5 REM **ASTRONOMY**
  10 CLEAR 
  20 LET M=0
  30 LET K=0
  40 PRINT "CONVERSIONS"
  50 FOR P=1 TO 11
  60 PRINT "*";
  70 NEXT P
  80 PRINT 
  90 PRINT "1/LTYRS TO MILES"
 100 PRINT "2/KM TO LTYRS"
 110 PRINT "3/MILES TO LTYRS"
 120 LET C$=INKEY$
 130 IF C$="" THEN GOTO 120
 140 IF C$>"1" THEN GOTO 400
 300 CLS 
 310 PRINT "LTYRS: ";
 320 INPUT L
 330 PRINT L
 340 LET K=L*(9.4830912*10**12)
 350 LET M=L*(5.892792872*10**12)
 360 PRINT "KM: ";K
 370 PRINT "MILES: ";M
 400 CLS 
 410 IF C$="3" THEN GOTO 500
 420 PRINT "KM: ";
 430 INPUT K
 440 PRINT K
 450 LET L=K/(9.4830912*(10**12))
 460 GOTO 540
 500 PRINT "MILES: ";
 510 INPUT M
 520 PRINT M
 530 LET L=M/(5.892792872*(10**12))
 540 PRINT "LTYRS: ";L
 550 PRINT 
 560 GOTO 10
 600 SAVE "1006%3"
 700 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top