Clock

(Use authentic machine speed)

Virtual basic Applesoft basic
rem * control D char
d${Cmd}= chr$(4)
pi= 3.14159:ci{circumference in radians}= (2 * pi)

rem * width max, height max for screen (279, 191, 159)
ml%{widthMax}= 279:mw%{widthMax}= ml%:mh%{HeightMax}= 191
if peek(33){mode 80 cols} = 80 then mh%{HeightMax}= 159 

rem * true random number
def fn alea{true random number}(x) = int(rnd(peek(78)+peek(79)*256) * x + 1)

rem * beep and buzz by default
bz%{NbreBuzz}= 3:be%{NbreBeep}= 1


section intro
text:home
gosub @splash
gosub @help
closesection

section global vars
def fn hdigi(x)= int( ( ml%{widthmax} - (x * 7.75) ) / 2 )
def fn ten(x)= int(x / 10) * 10
de%{delay}= 10
sn%{sound}= 0
ry%{radius}= 50:di%{digiEdge}= 10
# size of digit numbers
dg%{digitspace}= int( (di%{digiEdge} * 2) + (di%{digiEdge} / 2) + (di%{digiEdge} / 4) )
xo%{OrigX}= 140:yo%{OrigY}= 80
hh%{hours}= 0:mm%{mins}= 0:ss%{secs}= 0
closesection

section main program
£begin
{*** beginning of the main loop ***}
bp%{mainloop}= bp%{mainloop} + 1
# reset to defaut the values
xo%{OrigX}= 140:yo%{OrigY}= 80
hh%{hours}= 0:mm%{mins}= 0:ss%{secs}= 0
hcolor= 3 # white

# every day redraw all
# switch to graphic mode
gosub @hgrscreen
hcolor= 3 # white
# draw the clock
gosub @clockdecoration
gosub @clockcircle

{one day}
# - - - - - - - - - - - - - - - hours
for b1=0 to 23
	gosub @showhour
# - - - - - - - - - - - - - - - minutes
	for b2=0 to 59
		gosub @showminute
		# when minutes erase hour
		if b1 * 5 = mm% - 1 or (b1 - 12) * 5 = mm% - 1 then gosub @showhour
# - - - - - - - - - - - - - - - - seconds	
		for b3=0 to 59
			gosub @showseconde
			if sn%{sound} = 1 then gosub @beep
			
			ki%{keyboardInput}= peek(49152)
			if ki%{keyboardInput}= 209{"Q"} then goto @endprogram
			if ki%{keyboardInput}= 212{"T"} then gosub @setclock
			if ki%{keyboardInput}= 214{"V"} then gosub @setspeed
			if ki%{keyboardInput}= 200{"H"} then gosub @helpbis
			# toggle sound
			if sn%{sound}= 1 and ki%{keyboardInput}= 211{s} then sn%{sound}= 0:goto @soundend
			if ki%{keyboardInput}= 211{"S"} then sn%{sound}= 1
			£soundend
			gosub @keyboardcapture
			# rem * delay
			for b4= 0 to de%{delay}
next : next : next : next

# can run one month
if (bp%{mainloop} < 32) then goto @begin

£endprogram
	text:home:poke 49168,0
	gosub @credits
	end
closesection

section subscripts
{*** subscripts ***}

section diginumbers
# digit schema
# a---b
# |   |
# c---d
# |   |
# e---f
# coordinates postions
# x1%, y1% are a (origin) coordinates
# di%{digiEdge} equal to width of a -> b
£a 
x2%= x1%:y2%= y1%:return
£b 
x2%= x1% + di%{digiEdge}:y2%= y1%:return
£c 
x2%= x1%:y2%= y1% + di%{digiEdge}:return
£d 
x2%= x1% + di%{digiEdge}:y2%= y1% + di%{digiEdge}:return
£e 
x2%= x1%:y2%= y1% + (2 * di%{digiEdge}):return
£f 
x2%= x1% + di%{digiEdge}:y2%= y1% + (2 * di%{digiEdge}):return

# digit numbers
£zero
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @a:hplot x2%,y2%
	gosub @b:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
	gosub @e:hplot to x2%,y2%
	gosub @a:hplot to x2%,y2%
return

£one
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @b:hplot x2%,y2%
	gosub @f:hplot to x2%,y2%
return

£two
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @a:hplot x2%,y2%
	gosub @b:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
	gosub @c:hplot to x2%,y2%
	gosub @e:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
return

£three
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @a:hplot x2%,y2%
	gosub @b:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
	gosub @c:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
	gosub @e:hplot to x2%,y2%
return

£four
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @a:hplot x2%,y2%
	gosub @c:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
	gosub @b:hplot to x2%,y2%
return

£five
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @b:hplot x2%,y2%
	gosub @a:hplot to x2%,y2%
	gosub @c:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
	gosub @e:hplot to x2%,y2%
return

£six
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @a:hplot x2%,y2%
	gosub @e:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
	gosub @c:hplot to x2%,y2%
return

£seven
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @a:hplot x2%,y2%
	gosub @b:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
return

£eight
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @a:hplot x2%,y2%
	gosub @e:hplot to x2%,y2%
	gosub @f:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
	gosub @c:hplot to x2%,y2%
	gosub @a:hplot to x2%,y2%
	gosub @b:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
return

£nine
	x1%= xo%{OrigX}:y1%= yo%{OrigY}
	gosub @f:hplot x2%,y2%
	gosub @b:hplot to x2%,y2%
	gosub @a:hplot to x2%,y2%
	gosub @c:hplot to x2%,y2%
	gosub @d:hplot to x2%,y2%
return
closesection

section draw digital clock
£digisecs
	if ss%{secs} < 10 then s1%= 1:s2%= ss%{secs} + 1
	if ss%{secs} >= 10 then s1%= int(ss%{secs} / 10) + 1:s2%= ss%{secs} - fn ten(ss%{secs}) + 1
	on s1% gosub @zero, @one, @two, @three, @four, @five, @six, @seven, @eight, @nine
	xo%{OrigX}= xo%{OrigX} + (di%{digiEdge} + int(di%{digiEdge} / 4))
	on s2% gosub @zero, @one, @two, @three, @four, @five, @six, @seven, @eight, @nine
return

£digimins
	if mm%{mins} < 10 then m1%= 1:m2%= mm%{mins} + 1
	if mm%{mins} >= 10 then m1%= int(mm%{mins} / 10) + 1:m2%= mm%{mins} - fn ten(mm%{mins}) + 1
	on m1% gosub @zero, @one, @two, @three, @four, @five, @six, @seven, @eight, @nine
	xo%{OrigX}= xo%{OrigX} + (di%{digiEdge} + int(di%{digiEdge} / 4))
	on m2% gosub @zero, @one, @two, @three, @four, @five, @six, @seven, @eight, @nine
return

£digihours
	if hh%{hours} < 10 then h1%= 1:h2%= hh%{hours} + 1
	if hh%{hours} >= 10 then h1%= int(hh%{hours} / 10) + 1:h2%= hh%{hours} - fn ten(hh%{hours}) + 1
	on h1% gosub @zero, @one, @two, @three, @four, @five, @six, @seven, @eight, @nine
	xo%{OrigX}= xo%{OrigX} + (di%{digiEdge} + int(di%{digiEdge} / 4))
	on h2% gosub @zero, @one, @two, @three, @four, @five, @six, @seven, @eight, @nine
return
closesection

section draw arrows 
£secondsarrows
	ag= (ss%{secs} + 45) * (ci / 60) 
	x2= xo%{OrigX} + ( ry%{radius} * cos(ag) )
	y2= yo%{OrigY} + ( ry%{radius} * sin(ag) )
	x1= xo%{OrigX} + ( (ry%{radius}-6) * cos(ag) )
	y1= yo%{OrigY} + ( (ry%{radius}-6) * sin(ag) )
	hplot x1{OrigX},y1{OrigY} to x2,y2
return 

£minutesarrows
	ag= (mm%{mins} + 45) * (ci / 60)
	x2= xo%{OrigX} + ( (ry%{radius}-10) * cos(ag) )
	y2= yo%{OrigY} + ( (ry%{radius}-10) * sin(ag) )
	x1= xo%{OrigX} + ( (ry%{radius}-40) * cos(ag) )
	y1= yo%{OrigY} + ( (ry%{radius}-40) * sin(ag) )
	hplot x1{OrigX},y1{OrigY} to x2,y2
return

£hoursarrows
	ag= (hh%{hours} + 9) * (ci / 12) 
	x2= xo%{OrigX} + ( (ry%{radius} - 18) * cos(ag) ) 
	y2= yo%{OrigY} + ( (ry%{radius} - 18) * sin(ag) )
	x1= xo%{OrigX} + ( (ry%{radius}-40) * cos(ag) )
	y1= yo%{OrigY} + ( (ry%{radius}-40) * sin(ag) )
	hplot x1{OrigX},y1{OrigY} to x2,y2
return
closesection

section show the clock time
£showseconde
	# erase old second arrow
	hcolor= 0
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @secondsarrows
	xo%{OrigX}= fn hdigi(di%{digiEdge}) :yo%{OrigY}= 160
	xo% = xo% + ( dg%{digitspace} * 2 )
	gosub @digisecs
	# draw new second arrow
	hcolor= 3
	ss%{secs}= b3 # new second arrow = b3
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @secondsarrows
	xo%{OrigX}= fn hdigi(di%{digiEdge}) :yo%{OrigY}= 160
	xo% = xo% + ( dg%{digitspace} * 2 )
	gosub @digisecs
return

£showminute
	# erase old minute
	hcolor= 0
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @minutesarrows
	mm%{mins} = 88 # digit erase
	xo%{OrigX}= fn hdigi(di%{digiEdge}) :yo%{OrigY}= 160
	xo% = xo% + dg%{digitspace}
	gosub @digimins
	# new time
	hcolor= 3
	mm%{mins}= b2
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @minutesarrows
	xo%{OrigX}= fn hdigi(di%{digiEdge}) :yo%{OrigY}= 160
	xo% = xo% + dg%{digitspace}
	gosub @digimins
return

£showhour
	# erase old hour
	hcolor= 0
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @hoursarrows
	hh%{hours} = 88 # digit erase
	xo%{OrigX}= fn hdigi(di%{digiEdge}) :yo%{OrigY}= 160
	gosub @digihours
	# new time
	hcolor= 3
	hh%{hours}= b1
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @hoursarrows
	xo%{OrigX}= fn hdigi(di%{digiEdge}) :yo%{OrigY}= 160
	gosub @digihours
return
closesection

section clock draw
£clockdecoration
	s5 = ci{radiantcircle} / 14
	for b7= 0 to ci{radiantcircle} + 0.1 step s5
		v1= (ry%{radius} + 20) * cos(b7)
		v2= (ry%{radius} + 20) * sin(b7)
		x2%= int( xo%{OrigX} + v1 )
		y2%= int( yo%{OrigY} + v2 )
		if b7 = 0 then hplot x2%,y2%
		if b7 > 0 then hplot to x2%,y2%
	next
	s5 = ci{radiantcircle} / 14
	for b7= 0 to ci{radiantcircle} + 0.1 step s5
		v1= (ry%{radius} - 46) * cos(b7)
		v2= (ry%{radius} - 46) * sin(b7)
		x2%= int( xo%{OrigX} + v1 )
		y2%= int( yo%{OrigY} + v2 )
		if b7 = 0 then hplot x2%,y2%
		if b7 > 0 then hplot to x2%,y2%
	next
return

£clockcircle
	s4 = ci{radiantcircle} / 12
	for b6= (s4 * 9) to ( ci{radiantcircle} + 0.1 ) + (s4 * 9) step s4
		v1= (ry%{radius} + 5) * cos(b6)
		v2= (ry%{radius} + 5) * sin(b6)
		x2%= int( xo%{OrigX} + v1 )
		y2%= int( yo%{OrigY} + v2 )
		hplot x2%,y2%
	next
return
closesection

section clock settings
£setclock
	poke 49168,0
	text:home
	print
	input "hour 1/23 ? ";b1
	input "minute 1/59 ? ";b2
	input "second 1/59 ? ";b3
	if b1 > 23 then b1= 23
	if b1 < 0 then b1= 0
	if b2 > 59 then b2= 59
	if b2 < 0 then b2= 0
	if b3 > 59 then b3= 59
	if b3 < 0 then b3= 0
	gosub @hgrscreen
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @clockdecoration
	gosub @clockcircle
	gosub @showhour
	gosub @showminute
	gosub @showseconde
return

£setspeed
	poke 49168,0
	text:home
	print "actual speed: ";de%{delay}
	input "speed 1/1000 ?";de%{delay}
	if de%{delay} <= 0 then de%{delay}= 1
	gosub @hgrscreen
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @clockdecoration
	gosub @clockcircle
	gosub @showhour
	gosub @showminute
	gosub @showseconde
return

£help
	poke 49168,0
	text:home
	vtab(peek(37) + 2):
	s$= "     *** clock  ***    ":gosub @centertext
	print s$
	vtab(peek(37) + 2):
	s$= "     *** by loz ***    ":gosub @centertext
	print s$
	vtab(peek(37) + 2):
	s$= "q-> quit               ":gosub @centertext
	print s$
	vtab(peek(37) + 2):
	s$= "h-> this help          ":gosub @centertext
	print s$
	vtab(peek(37) + 2):
	s$= "t-> set time           ":gosub @centertext
	print s$
	vtab(peek(37) + 2):
	s$= "v-> time speed         ":gosub @centertext
	print s$
	vtab(peek(37) + 2):
	s$= "s-> toggle sound on/off":gosub @centertext
	print s$
	vtab(peek(37) + 2):
	s$= "type enter to continue ":gosub @centertext
	print s$
	get s$
return

£helpbis
	gosub @help
	gosub @hgrscreen
	xo%{OrigX}= 140:yo%{OrigY}= 80
	gosub @clockcircle
	gosub @clockdecoration
	gosub @showhour
	gosub @showminute
	gosub @showseconde
return
closesection

closesection

£hgrscreen
	if peek(33) < 41 and mh%{MaxHauteur} > 159 then hg$= "hgr2"
	if peek(33) < 41 and mh%{MaxHauteur} <= 159 then hg$= "hgr"
	rem * mod 80 colonnes
	if peek(33) > 40 then hg$= "hgr"
	if hg$ = "hgr" then hgr
	if hg$ = "hgr2" then hgr2
return

£splash
	text:home
	vtab(3):print
	vtab(peek(37) + 2)
	s${sentence}= "applesoft basic code":gosub @centertext
	print s${sentence}
return

£credits
	text:home
	gosub @beep
	vtab(3):print
	vtab(peek(37) + 2)
	s${sentence}= "by andres aka loz":gosub @centertext
	print s${sentence}
return

£keyboardcapture
	rem * capture last keyboard entered
	ki%{keyboardInput}= peek(49152)
	rem * reset
	poke 49168,0
	rem * actions
	if ki% = 155{Escape} then goto @endprogram
	if chr$(ki%) = "t" then text
return

£centertext
	t9%{leftSpace}= int( (peek(33) - len(s${sentence}) ) / 2 ) 
	rem * is result is null
	if (t9% < 1) then t9%= 0
	htab(t9%{leftSpace}+1)
return

£beep
if (be%{NbreBeep} < 2) then be%{NbreBeep}= 1
	for b9= 1 to be%{NbreBeep}
		print chr$(7);
	next
return
10 REM - CLOCK7.BAS - 14/01/2012 - 08h34 - BY - ANDRES - AKA - LOZ - COPYLEFT
20 D$= CHR$(4)
30 PI= 3.14159:CI= (2 * PI)
40 ML%= 279:MW%= ML%:MH%= 191
50 IF PEEK(33) = 80 THEN MH%= 159 
60 DEF FN ALEA(X) = INT(RND(PEEK(78)+PEEK(79)*256) * X + 1)
70 BZ%= 3:BE%= 1
80 TEXT:HOME
90 GOSUB 3480
100 GOSUB 3020
110 DEF FN HDIGI(X)= INT( ( ML% - (X * 7.75) ) / 2 )
120 DEF FN TEN(X)= INT(X / 10) * 10
130 DE%= 10
140 SN%= 0
150 RY%= 50:DI%= 10
160 DG%= INT( (DI% * 2) + (DI% / 2) + (DI% / 4) )
170 XO%= 140:YO%= 80
180 HH%= 0:MM%= 0:SS%= 0
190 REM->BEGIN
200 BP%= BP% + 1
210 XO%= 140:YO%= 80
220 HH%= 0:MM%= 0:SS%= 0
230 HCOLOR= 3
240 GOSUB 3410
250 HCOLOR= 3
260 GOSUB 2370
270 GOSUB 2570
280 FOR B1=0 TO 23
290 GOSUB 2230
300 FOR B2=0 TO 59
310 GOSUB 2070
320 IF B1 * 5 = MM% - 1 OR (B1 - 12) * 5 = MM% - 1 THEN GOSUB 2230
330 FOR B3=0 TO 59
340 GOSUB 1920
350 IF SN% = 1 THEN GOSUB 3740
360 KI%= PEEK(49152)
370 IF KI%= 209 THEN GOTO 490
380 IF KI%= 212 THEN GOSUB 2670
390 IF KI%= 214 THEN GOSUB 2880
400 IF KI%= 200 THEN GOSUB 3310
410 IF SN%= 1 AND KI%= 211 THEN SN%= 0:GOTO 440
420 IF KI%= 211 THEN SN%= 1
430 REM->SOUNDEND
440 GOSUB 3630
450 FOR B4= 0 TO DE%
460 NEXT : NEXT : NEXT : NEXT
470 IF (BP% < 32) THEN GOTO 200
480 REM->ENDPROGRAM
490 TEXT:HOME:POKE 49168,0
500 GOSUB 3550
510 END
520 REM->A 
530 X2%= X1%:Y2%= Y1%:RETURN
540 REM->B 
550 X2%= X1% + DI%:Y2%= Y1%:RETURN
560 REM->C 
570 X2%= X1%:Y2%= Y1% + DI%:RETURN
580 REM->D 
590 X2%= X1% + DI%:Y2%= Y1% + DI%:RETURN
600 REM->E 
610 X2%= X1%:Y2%= Y1% + (2 * DI%):RETURN
620 REM->F 
630 X2%= X1% + DI%:Y2%= Y1% + (2 * DI%):RETURN
640 REM->ZERO
650 X1%= XO%:Y1%= YO%
660 GOSUB 530:HPLOT X2%,Y2%
670 GOSUB 550:HPLOT TO X2%,Y2%
680 GOSUB 630:HPLOT TO X2%,Y2%
690 GOSUB 610:HPLOT TO X2%,Y2%
700 GOSUB 530:HPLOT TO X2%,Y2%
710 RETURN
720 REM->ONE
730 X1%= XO%:Y1%= YO%
740 GOSUB 550:HPLOT X2%,Y2%
750 GOSUB 630:HPLOT TO X2%,Y2%
760 RETURN
770 REM->TWO
780 X1%= XO%:Y1%= YO%
790 GOSUB 530:HPLOT X2%,Y2%
800 GOSUB 550:HPLOT TO X2%,Y2%
810 GOSUB 590:HPLOT TO X2%,Y2%
820 GOSUB 570:HPLOT TO X2%,Y2%
830 GOSUB 610:HPLOT TO X2%,Y2%
840 GOSUB 630:HPLOT TO X2%,Y2%
850 RETURN
860 REM->THREE
870 X1%= XO%:Y1%= YO%
880 GOSUB 530:HPLOT X2%,Y2%
890 GOSUB 550:HPLOT TO X2%,Y2%
900 GOSUB 590:HPLOT TO X2%,Y2%
910 GOSUB 570:HPLOT TO X2%,Y2%
920 GOSUB 590:HPLOT TO X2%,Y2%
930 GOSUB 630:HPLOT TO X2%,Y2%
940 GOSUB 610:HPLOT TO X2%,Y2%
950 RETURN
960 REM->FOUR
970 X1%= XO%:Y1%= YO%
980 GOSUB 530:HPLOT X2%,Y2%
990 GOSUB 570:HPLOT TO X2%,Y2%
1000 GOSUB 590:HPLOT TO X2%,Y2%
1010 GOSUB 630:HPLOT TO X2%,Y2%
1020 GOSUB 550:HPLOT TO X2%,Y2%
1030 RETURN
1040 REM->FIVE
1050 X1%= XO%:Y1%= YO%
1060 GOSUB 550:HPLOT X2%,Y2%
1070 GOSUB 530:HPLOT TO X2%,Y2%
1080 GOSUB 570:HPLOT TO X2%,Y2%
1090 GOSUB 590:HPLOT TO X2%,Y2%
1100 GOSUB 630:HPLOT TO X2%,Y2%
1110 GOSUB 610:HPLOT TO X2%,Y2%
1120 RETURN
1130 REM->SIX
1140 X1%= XO%:Y1%= YO%
1150 GOSUB 530:HPLOT X2%,Y2%
1160 GOSUB 610:HPLOT TO X2%,Y2%
1170 GOSUB 630:HPLOT TO X2%,Y2%
1180 GOSUB 590:HPLOT TO X2%,Y2%
1190 GOSUB 570:HPLOT TO X2%,Y2%
1200 RETURN
1210 REM->SEVEN
1220 X1%= XO%:Y1%= YO%
1230 GOSUB 530:HPLOT X2%,Y2%
1240 GOSUB 550:HPLOT TO X2%,Y2%
1250 GOSUB 630:HPLOT TO X2%,Y2%
1260 RETURN
1270 REM->EIGHT
1280 X1%= XO%:Y1%= YO%
1290 GOSUB 530:HPLOT X2%,Y2%
1300 GOSUB 610:HPLOT TO X2%,Y2%
1310 GOSUB 630:HPLOT TO X2%,Y2%
1320 GOSUB 590:HPLOT TO X2%,Y2%
1330 GOSUB 570:HPLOT TO X2%,Y2%
1340 GOSUB 530:HPLOT TO X2%,Y2%
1350 GOSUB 550:HPLOT TO X2%,Y2%
1360 GOSUB 590:HPLOT TO X2%,Y2%
1370 RETURN
1380 REM->NINE
1390 X1%= XO%:Y1%= YO%
1400 GOSUB 630:HPLOT X2%,Y2%
1410 GOSUB 550:HPLOT TO X2%,Y2%
1420 GOSUB 530:HPLOT TO X2%,Y2%
1430 GOSUB 570:HPLOT TO X2%,Y2%
1440 GOSUB 590:HPLOT TO X2%,Y2%
1450 RETURN
1460 REM->DIGISECS
1470 IF SS% < 10 THEN S1%= 1:S2%= SS% + 1
1480 IF SS% >= 10 THEN S1%= INT(SS% / 10) + 1:S2%= SS% - FN TEN(SS%) + 1
1490 ON S1% GOSUB 650, 730, 780, 870, 970, 1050, 1140, 1220, 1280, 1390
1500 XO%= XO% + (DI% + INT(DI% / 4))
1510 ON S2% GOSUB 650, 730, 780, 870, 970, 1050, 1140, 1220, 1280, 1390
1520 RETURN
1530 REM->DIGIMINS
1540 IF MM% < 10 THEN M1%= 1:M2%= MM% + 1
1550 IF MM% >= 10 THEN M1%= INT(MM% / 10) + 1:M2%= MM% - FN TEN(MM%) + 1
1560 ON M1% GOSUB 650, 730, 780, 870, 970, 1050, 1140, 1220, 1280, 1390
1570 XO%= XO% + (DI% + INT(DI% / 4))
1580 ON M2% GOSUB 650, 730, 780, 870, 970, 1050, 1140, 1220, 1280, 1390
1590 RETURN
1600 REM->DIGIHOURS
1610 IF HH% < 10 THEN H1%= 1:H2%= HH% + 1
1620 IF HH% >= 10 THEN H1%= INT(HH% / 10) + 1:H2%= HH% - FN TEN(HH%) + 1
1630 ON H1% GOSUB 650, 730, 780, 870, 970, 1050, 1140, 1220, 1280, 1390
1640 XO%= XO% + (DI% + INT(DI% / 4))
1650 ON H2% GOSUB 650, 730, 780, 870, 970, 1050, 1140, 1220, 1280, 1390
1660 RETURN
1670 REM->SECONDSARROWS
1680 AG= (SS% + 45) * (CI / 60) 
1690 X2= XO% + ( RY% * COS(AG) )
1700 Y2= YO% + ( RY% * SIN(AG) )
1710 X1= XO% + ( (RY%-6) * COS(AG) )
1720 Y1= YO% + ( (RY%-6) * SIN(AG) )
1730 HPLOT X1,Y1 TO X2,Y2
1740 RETURN 
1750 REM->MINUTESARROWS
1760 AG= (MM% + 45) * (CI / 60)
1770 X2= XO% + ( (RY%-10) * COS(AG) )
1780 Y2= YO% + ( (RY%-10) * SIN(AG) )
1790 X1= XO% + ( (RY%-40) * COS(AG) )
1800 Y1= YO% + ( (RY%-40) * SIN(AG) )
1810 HPLOT X1,Y1 TO X2,Y2
1820 RETURN
1830 REM->HOURSARROWS
1840 AG= (HH% + 9) * (CI / 12) 
1850 X2= XO% + ( (RY% - 18) * COS(AG) ) 
1860 Y2= YO% + ( (RY% - 18) * SIN(AG) )
1870 X1= XO% + ( (RY%-40) * COS(AG) )
1880 Y1= YO% + ( (RY%-40) * SIN(AG) )
1890 HPLOT X1,Y1 TO X2,Y2
1900 RETURN
1910 REM->SHOWSECONDE
1920 HCOLOR= 0
1930 XO%= 140:YO%= 80
1940 GOSUB 1680
1950 XO%= FN HDIGI(DI%) :YO%= 160
1960 XO% = XO% + ( DG% * 2 )
1970 GOSUB 1470
1980 HCOLOR= 3
1990 SS%= B3
2000 XO%= 140:YO%= 80
2010 GOSUB 1680
2020 XO%= FN HDIGI(DI%) :YO%= 160
2030 XO% = XO% + ( DG% * 2 )
2040 GOSUB 1470
2050 RETURN
2060 REM->SHOWMINUTE
2070 HCOLOR= 0
2080 XO%= 140:YO%= 80
2090 GOSUB 1760
2100 MM% = 88
2110 XO%= FN HDIGI(DI%) :YO%= 160
2120 XO% = XO% + DG%
2130 GOSUB 1540
2140 HCOLOR= 3
2150 MM%= B2
2160 XO%= 140:YO%= 80
2170 GOSUB 1760
2180 XO%= FN HDIGI(DI%) :YO%= 160
2190 XO% = XO% + DG%
2200 GOSUB 1540
2210 RETURN
2220 REM->SHOWHOUR
2230 HCOLOR= 0
2240 XO%= 140:YO%= 80
2250 GOSUB 1840
2260 HH% = 88
2270 XO%= FN HDIGI(DI%) :YO%= 160
2280 GOSUB 1610
2290 HCOLOR= 3
2300 HH%= B1
2310 XO%= 140:YO%= 80
2320 GOSUB 1840
2330 XO%= FN HDIGI(DI%) :YO%= 160
2340 GOSUB 1610
2350 RETURN
2360 REM->CLOCKDECORATION
2370 S5 = CI / 14
2380 FOR B7= 0 TO CI + 0.1 STEP S5
2390 V1= (RY% + 20) * COS(B7)
2400 V2= (RY% + 20) * SIN(B7)
2410 X2%= INT( XO% + V1 )
2420 Y2%= INT( YO% + V2 )
2430 IF B7 = 0 THEN HPLOT X2%,Y2%
2440 IF B7 > 0 THEN HPLOT TO X2%,Y2%
2450 NEXT
2460 S5 = CI / 14
2470 FOR B7= 0 TO CI + 0.1 STEP S5
2480 V1= (RY% - 46) * COS(B7)
2490 V2= (RY% - 46) * SIN(B7)
2500 X2%= INT( XO% + V1 )
2510 Y2%= INT( YO% + V2 )
2520 IF B7 = 0 THEN HPLOT X2%,Y2%
2530 IF B7 > 0 THEN HPLOT TO X2%,Y2%
2540 NEXT
2550 RETURN
2560 REM->CLOCKCIRCLE
2570 S4 = CI / 12
2580 FOR B6= (S4 * 9) TO ( CI + 0.1 ) + (S4 * 9) STEP S4
2590 V1= (RY% + 5) * COS(B6)
2600 V2= (RY% + 5) * SIN(B6)
2610 X2%= INT( XO% + V1 )
2620 Y2%= INT( YO% + V2 )
2630 HPLOT X2%,Y2%
2640 NEXT
2650 RETURN
2660 REM->SETCLOCK
2670 POKE 49168,0
2680 TEXT:HOME
2690 ?
2700 INPUT "HOUR 1/23 ? ";B1
2710 INPUT "MINUTE 1/59 ? ";B2
2720 INPUT "SECOND 1/59 ? ";B3
2730 IF B1 > 23 THEN B1= 23
2740 IF B1 < 0 THEN B1= 0
2750 IF B2 > 59 THEN B2= 59
2760 IF B2 < 0 THEN B2= 0
2770 IF B3 > 59 THEN B3= 59
2780 IF B3 < 0 THEN B3= 0
2790 GOSUB 3410
2800 XO%= 140:YO%= 80
2810 GOSUB 2370
2820 GOSUB 2570
2830 GOSUB 2230
2840 GOSUB 2070
2850 GOSUB 1920
2860 RETURN
2870 REM->SETSPEED
2880 POKE 49168,0
2890 TEXT:HOME
2900 ? "ACTUAL SPEED: ";DE%
2910 INPUT "SPEED 1/1000 ?";DE%
2920 IF DE% <= 0 THEN DE%= 1
2930 GOSUB 3410
2940 XO%= 140:YO%= 80
2950 GOSUB 2370
2960 GOSUB 2570
2970 GOSUB 2230
2980 GOSUB 2070
2990 GOSUB 1920
3000 RETURN
3010 REM->HELP
3020 POKE 49168,0
3030 TEXT:HOME
3040 VTAB(PEEK(37) + 2):
3050 S$= "     *** CLOCK  ***    ":GOSUB 3690
3060 ? S$
3070 VTAB(PEEK(37) + 2):
3080 S$= "     *** BY LOZ ***    ":GOSUB 3690
3090 ? S$
3100 VTAB(PEEK(37) + 2):
3110 S$= "Q-> QUIT               ":GOSUB 3690
3120 ? S$
3130 VTAB(PEEK(37) + 2):
3140 S$= "H-> THIS HELP          ":GOSUB 3690
3150 ? S$
3160 VTAB(PEEK(37) + 2):
3170 S$= "T-> SET TIME           ":GOSUB 3690
3180 ? S$
3190 VTAB(PEEK(37) + 2):
3200 S$= "V-> TIME SPEED         ":GOSUB 3690
3210 ? S$
3220 VTAB(PEEK(37) + 2):
3230 S$= "S-> TOGGLE SOUND ON/OFF":GOSUB 3690
3240 ? S$
3250 VTAB(PEEK(37) + 2):
3260 S$= "TYPE ENTER TO CONTINUE ":GOSUB 3690
3270 ? S$
3280 GET S$
3290 RETURN
3300 REM->HELPBIS
3310 GOSUB 3020
3320 GOSUB 3410
3330 XO%= 140:YO%= 80
3340 GOSUB 2570
3350 GOSUB 2370
3360 GOSUB 2230
3370 GOSUB 2070
3380 GOSUB 1920
3390 RETURN
3400 REM->HGRSCREEN
3410 IF PEEK(33) < 41 AND MH% > 159 THEN HG$= "HGR2"
3420 IF PEEK(33) < 41 AND MH% <= 159 THEN HG$= "HGR"
3430 IF PEEK(33) > 40 THEN HG$= "HGR"
3440 IF HG$ = "HGR" THEN HGR
3450 IF HG$ = "HGR2" THEN HGR2
3460 RETURN
3470 REM->SPLASH
3480 TEXT:HOME
3490 VTAB(3):?
3500 VTAB(PEEK(37) + 2)
3510 S$= "APPLESOFT BASIC CODE":GOSUB 3690
3520 ? S$
3530 RETURN
3540 REM->CREDITS
3550 TEXT:HOME
3560 GOSUB 3740
3570 VTAB(3):?
3580 VTAB(PEEK(37) + 2)
3590 S$= "BY ANDRES AKA LOZ":GOSUB 3690
3600 ? S$
3610 RETURN
3620 REM->KEYBOARDCAPTURE
3630 KI%= PEEK(49152)
3640 POKE 49168,0
3650 IF KI% = 155 THEN GOTO 490
3660 IF CHR$(KI%) = "T" THEN TEXT
3670 RETURN
3680 REM->CENTERTEXT
3690 T9%= INT( (PEEK(33) - LEN(S$) ) / 2 ) 
3700 IF (T9% < 1) THEN T9%= 0
3710 HTAB(T9%+1)
3720 RETURN
3730 REM->BEEP
3740 IF (BE% < 2) THEN BE%= 1
3750 FOR B9= 1 TO BE%
3760 ? CHR$(7);
3770 NEXT
3780 RETURN