You can get a real-time clock through hardware or software. The hardware option, while usually more reliable (especially with battery backup), costs about $60 with special purpose chips (MSM 5832). Software clocks are cheaper.
Soft Clock creates a software clock from the 3.25 MHz ZX/TS logic clock using the system variable FRAMES at decimal addresses 16436 and 16437. FRAMES tracks the number of pictures sent to your TV (60/second in the US). Soft Clock keeps track of the value of FRAMES.
Soft Clock should be accurate to a few seconds/day. It requires just less than 2K RAM. You can use it as a subroutine in application programs. Just make sure you GOTO 200 at least every five minutes (actually about 8.8). The severe limitations are:
1. You can’t turn off your computer, even for a second.
2. You can’t use FAST anywhere in your program (FAST resets FRAMES to 65536).
3. You can’t use PAUSE.
Line Functions:
Line Purpose
7 F (fudge factor) corrects
for internal clock. Value
between 0 and 2 works best.
8 Initializes the count.
100 Looks at current FRAMES.
211 Checks that FRAMES isn't in
to the middle of a bit manipu-
215 lation. If it is, ignore
the count this time.
220 Resets starting count if
FRAMES rolls over from
32768 to 65556.
230 PINC is change in count.
250 SS is value of seconds.
Same for MM, HH.
340-74, 600 Pretty up output.
392 Print time at 4,20.
920 Lets you start clock at
any time you want.
960 Lets you set time.
1 REM SOFTWARE CLOCK
6 CLEAR
7 LET F=1.605
8 LET OV=32768
9 GOTO 900
100 LET C=PEEK 16436+256*PEEK 16437
105 RETURN
200 GOSUB 100
210 LET NV=C
211 IF OV<NV THEN GOTO 215
212 GOTO 220
213 REM
215 IF OV>NV-256 THEN GOTO 200
220 IF OV<NV THEN LET OV=OV+32768
230 LET PINC=ABS ((OV-NV)+F)
240 LET OV=NV
250 LET SS=SS+PINC/60
260 LET MINC=0
270 IF SS>=60 THEN LET MINC=INT (SS/60)
280 LET SS=SS-MINC*60
290 LET MM=MM+MINC
300 LET HC=0
310 IF MM>=60 THEN LET HC=INT (MM/60)
320 LET MM=MM-HC*60
330 LET HH=HH+HC
340 IF HH>24 THEN LET HH=HH-24
370 IF HH<10 THEN LET H$="0"
372 IF MM<10 THEN LET M$="0"
374 IF SS<10 THEN LET Z$="0"
390 LET SS1=INT SS
391 PRINT AT 2,20;" "
392 PRINT AT 4,20;H$+STR$ HH+":"+M$+STR$ MM+":"+Z$+STR$ SS1
410 GOSUB 600
499 GOTO 200
600 LET H$=""
602 LET M$=""
604 LET Z$=""
607 RETURN
900 PRINT " SOFT CLOCK "
901 LET PINC=0
905 PRINT "",,,,
920 PRINT "SET TIME (S) OR START AT 0 (Z)"
930 INPUT S$
935 CLS
940 IF S$="Z" THEN GOTO 950
942 IF S$="S" THEN GOTO 960
944 GOTO 930
950 LET SS=-4
952 LET MM=0
954 LET HH=0
956 PAUSE 0
958 GOTO 200
960 CLS
961 PRINT "ENTER TIME AS HH:MM:SS"
962 LET PINC=0
963 INPUT T$
965 IF LEN T$<>8 THEN GOTO 963
966 LET MINC=0
967 LET HH=VAL T$(1 TO 2)
968 LET MM=VAL T$(4 TO 5)
969 LET SS=VAL T$(7 TO 8)
971 PRINT "IS THIS RIGHT? ";HH;":";MM;":";SS
973 INPUT S$
974 PAUSE 0
975 CLS
976 IF S$<>"Y" OR S$<>"YES" THEN GOTO 200
978 GOTO 961
SYNTACTIC SUM: 15979, 8K ROM
Media
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.