Technical Reference Manual
System timing is controlled by two interrupts:
The clock time is stored in binary in 6 fields from $20C5 to $20CA:
On the LZ there is another time-related system variable:
TMB_24F stores 2 flags:
These flags can be read or written to at any time.
An NMI interrupt is generated from the semi-custom chip every second to provide an accurate real-time clock. When the machine is on, the NMI interrupt updates the time by 1 second, see TM$UPDT.
When NMIs are switched off the processor, (e.g. when the machine is switched off) an internal counter in the semi-custom chip is connected to the NMI line so that NMIs can still be counted, enabling the time to be updated when restoring NMIs to the processor.
The counter has 11 bits, so the maximum time it can store is 2048 secs. When the counter reaches this value, the ACOUT bit of PORT 5 goes high and the machine switches on. Hence the machine can be forced to switch on automatically at any time up to 34mins 8secs after switching off, be pre-counting the counter. This is done when an alarm is due.
Whenever the machine switches on it updates the real-time clock by the amount in the counter (less any pre-counting). If ACOUT is high, and no alarm was due, the machine switches back off immediately after updating the clock. This can be seen as the screen flashes on for an instant, every 34 mins and 8 secs while the machine is off.
To disable NMIs and keep the time, system services BT$NOF and BT$NON should be used.
The following three variables control the auto-switch-off:
The time before the machine switches off (in secs) is stored in TMW_TCNT and is set to $012C on cold start (5 mins). The contents of TMW_TCNT are copied into TMW_TOUT whenever a key is pressed or KB$GETK is called and TMW_TOUT is decremented until zero by the NMI routine every second. If TMW_TOUT is found to be zero in KB$TEST, the machine will switch off.
The contents of TMW_TCNT can be changed at any time to alter the auto-switch-off time, up to a maximum of 65535 seconds (18 hours, 12 mins and 15 secs). If it is set to less than 15, the machine will will still stay on for 15 secs.
To disable the auto-switch-off completely, TMB_SWOF should be set to zero. This will inhibit the NMI from decrementing TMW_TOUT and prevent KB$TEST testing it.
The timer 1 compare interrupt is used to scan the keyboard to allow keyboard buffering and to provide a timing service. The time between interrupts is controlled by the variable KBW_TDEL which is initialised on cold start to be $B3DD. This value makes the KI interrupt occur exactly every 50 milliseconds and is used extensively by the operating system for timing purposes.
TMW_FRAM is incremented by 1 on each keyboard interrupt. When $FFFF is reached, it wraps back to $0000. It can be read at any time and used for accurate timing.
DPW_REDY is decremented by 1 on each keyboard interrupt until zero is reached. It can be used to provide delays (e.g. TM$WAIT stores D in DPW_REDY and waits for it to reach zero - see below).
Note that some services work from any buffer containing a 6 byte time representation exactly like the real-time clock (TMB_YEAR...). These routines should not operate on the real-time clock itself if an NMI is imminent, so NMIs must be checked for or TM$TGET should be used to copy the time to another buffer.
Calculates the day of the week for a given date.
Get a copy of the real-time clock into a buffer. It is not possible to read the clock directly in case it is being updated by an NMI.
Updates a time buffer by a given number of minutes and seconds.
Waits for a number of ticks (1 tick is the interval between keyboard interrupts, controlled by KBW_TDEL and set to 50ms by default). If interrupts are disabled (I flag set) then this routine waits for the given number x 50ms.
TM$NDYS (LZ only)
TM$WEEK (LZ only)
Returns the week number of the supplied date. The first MONDAY of the year
starts WEEK 0. Any dates before this MONDAY are in the last week of the
previous year. Applications (e.g. the DIARY) convert the week number from
0-52 to 1-53.
TM$DNAM (LZ only)
Returns a 3 letter day name for a given day of the week in the currently selected language.
TM$MNAM (LZ only)
Returns a 3 letter month name for a given month in the currently selected language.
TM$TSET (LZ only)
Sets the system time to a given time. The time should not be simply poke'd into the system time variables since an NMI may be updating the time.