Local Sidereal Time


This code from block 1170 is loaded into node 512. It computes sidereal time for 120o west longitude (Reno).

More importantly, it is my first use of interpreted code (see init below).

*.16

Multiply by a 16-bit fraction. It's similar to (actually uses) *.17 but allows fractions greater than 1.

d/mod

Basic divide code with a 36-bit positive dividend; 18-bit negative divisor, 18-bit positive quotient and remainder. (This is a classic example of trying to describe a word in its name. The ROM name is --u/mod, which is merely cryptic.)

/mod

*.

Fraction multiply discarding buried multiplicand.

nip

Discard 2nd number on stack. Used twice.

*

Multiply 18-bit positive numbers for a 36-bit product.

leap

Correct days for leap year. Works from 1901 to 2099 since 2000 is a leap year. This is a good example of how conditional returns can simplify logic.

days

yymmdd on stack. Computes days since 000101 (2000/01/01):

lst

Takes minute and yymmdd on the stack and returns LST in minutes:

init

This code is still compiled by native colorForth on the PC, which can access the CMOS clock and defines minute of the day and yymmdd.

These numbers are compiled by lit into the code specified by init to be executed. It jumps to lst with them on the stack and returns with LST on the stack. Node 512 does this and then awaits further instructions, since the return from lst is to the 4-port execute from reset.

That's the end of this block of code. It leaves a number on the stack. Another block of code will be loaded into this node. It will find LST on the stack, since loading code disturbs only the bottom-of-stack.

This procedure is effectively the Forth interpreter. Code is executed at compile time. Unlimited code can be executed by a node, provided only that it's factored into 64-word chunks.

Options

If lst is commented out, over will retrieve PDT. If 420 is added, it becomes UTC. This is useful for debugging, but a civil clock doesn't need this code at all.

Replacing minute lit and yymmdd lit with numbers will compute LST for a particular time. Useful for debugging.