Page 1 of 1

Analog clock in BASIC

Posted: Tue Jan 17, 2017 6:04 pm
by JavaJack
I was reading this discussion:
https://www.reddit.com/r/retrobattlesta ... ary_clock/

and got inspired to make this analog clock:

Code: Select all

5 ?"{clear}"
6 input "hhmmss"; ti$
7 ?"{clear}"
8 poke 36879, 8

10 dim c%(60)
20 for x=0 to 7
30   read y
40   c%(x)    = 7910 - (y*22) + x
50   c%(15-x) = 7910 - (x*22) + y
60   c%(15+x) = 7910 + (x*22) + y
70   c%(30-x) = 7910 + (y*22) + x
80   c%(30+x) = 7910 + (y*22) - x
90   c%(45-x) = 7910 + (x*22) - y
100  c%(45+x) = 7910 - (x*22) - y
110  c%(60-x) = 7910 - (y*22) - x
190 next x

200 for i=0 to 59
210   poke c%(i), 81
220   poke 30720+c%(i), 4
230 next i

240 for i=0 to 55 step 5
250   poke c%(i), 87
260 next i

500 data 10
510 data 10
520 data 10
530 data 10
540 data 10
550 data 9
560 data 9
570 data 8

1000 a$="000000"
1010 oh = 0
1020 om = 0
1030 os = 0

1500 if a$ = ti$ goto 1500

1600 a$ = ti$
1610 hh = val(left$(a$,2))
1620 mm = val(mid$(a$,3,2))
1630 ss = val(right$(a$,2))
1640 if hh > 12 then hh = hh-12

1700 poke 30720+c%(oh*5+int(om/12)), 4
1710 poke 30720+c%(om), 4
1720 poke 30720+c%(os), 4

1800 poke 30720+c%(hh*5+int(mm/12)), 3
1810 poke 30720+c%(mm), 1
1820 poke 30720+c%(ss), 7

1900 oh = hh
1910 om = mm
1920 os = ss

2000 goto 1500 

Re: Analog clock in BASIC

Posted: Wed Jan 18, 2017 1:19 am
by Mike
Oh...! :)

Code: Select all

10 REM ** WALL CLOCK
11 TI$="123456":DIMSX(59),SY(59),BX(59),BY(59):MX=80:MY=96:@ON:@CLR
12 FORT=0TO59:S=SIN({PI}*T/30):C=COS({PI}*T/30)
13 SX(T)=MX+INT(33*S+.5):SY(T)=MY-INT(55*C+.5)
14 BX(T)=MX+INT(48*S+.5):BY(T)=MY-INT(80*C+.5)
15 RX=54:RY=90:IFT=5*INT(T/5)THENRX=51:RY=85
16 @1,MX+INT(RX*S+.5),MY-INT(RY*C+.5)TOMX+INT(57*S+.5),MY-INT(95*C+.5)
17 NEXT:H=0:M=0:S=0:A$=TI$
18 :
19 B$=TI$:IFB$=A$THEN19
20 S=VAL(MID$(B$,5,2)):M=VAL(MID$(B$,3,2))
21 H=VAL(MID$(B$,1,2)):H=INT(0.5+5*H+M/12):H=H-60*INT(H/60)
22 IFG<>HTHEN:@0,MX,MYTOSX(G),SY(G)
23 IFL<>MTHEN:@0,MX,MYTOBX(L),BY(L)
24 @0,MX,MYTOBX(R),BY(R):@1,MX,MYTOBX(S),BY(S)
25 @1,MX,MYTOBX(M),BY(M):@1,MX,MYTOSX(H),SY(H)
26 G=H:L=M:R=S:A$=B$:GOTO19
From here. :mrgreen:

This program runs with a graphic display, and draws hands for seconds, minutes and hours. There's a BASIC extension in use, which is responsible for the commands prefaced with "@".

I've put a slightly enhanced version on a disk image in another thread: MG batch suite. You need at least a +8K RAM expansion. Load MINIGRAFIK first and run it (which returns you to the start-up screen, but with slightly less RAM available), then load and run "WALL CLOCK".

...

So if your interest extends beyond the "Not x86 week" on retrobattlestations@reddit, head over here. Here on Denial is the real deal. 8)


P.S. CBM BASIC processes integers *slower* than floats - that's because there are no dedicated integer routines in the interpreter, and use of integers incurs extra conversions. Neither do simple integer variables use less space than floats (both require 7 bytes per variable - 2 bytes for the name, 5 for the value - and integers fill up 3 bytes of the value with 0s). Only arrays of integers are stored in a compact way, with 2 bytes per value.

Re: Analog clock in BASIC

Posted: Thu Jan 19, 2017 1:45 am
by wimoos
Mike wrote:P.S. CBM BASIC processes integers *slower* than floats - that's because there are no dedicated integer routines in the interpreter, and use of integers incurs extra conversions. Neither do simple integer variables use less space than floats (both require 7 bytes per variable - 2 bytes for the name, 5 for the value - and integers fill up 3 bytes of the value with 0s). Only arrays of integers are stored in a compact way, with 2 bytes per value.
May I suggest to adopt SuperNumbers in MINIGRAFIK ? Cost a couple of dozen bytes of code and 130 bytes of RAM, but gives about 20% speed improvement in processing floats.

Regards,

Wim.

Re: Analog clock in BASIC

Posted: Thu Jan 19, 2017 2:48 am
by Mike
Hi, Wim.

I was mostly referring to the use of integers in the start post of the thread. This could, or could not, be motivated by the hope integers might be processed faster than floats. For the complete program, the memory savings are irrelevant at that program size - even with a float array, that program would run on an unexpanded VIC-20.

I am not going to bolt SuperNumbers or any other (only so perceived missing) feature to the core of MINIGRAFIK. MG in its current state since 2008 features a minimal set of routines for hires graphics, usable from BASIC, where nothing of it could sensibly be left out. A program that uses MINIGRAFIK can count on using nearly its whole code, so there is no baggage of unused parts of MG around when it is loaded. Other features specific for a client application still can be added as SYS-callable libraries in machine language.

Greetings,

Michael

Re: Analog clock in BASIC

Posted: Thu Jan 19, 2017 8:01 pm
by JavaJack
Yellow=seconds
Cyan=hours
White=minutes
analogclock.png
analogclock.png (5.72 KiB) Viewed 1723 times

Re: Analog clock in BASIC

Posted: Fri Jan 20, 2017 1:06 am
by Mike
Image

The wall clock shows 07:57:18. You can easily tell apart the hands of minutes and seconds by their speed. :wink:

Re: Analog clock in BASIC

Posted: Mon Jan 23, 2017 8:31 pm
by eslapion
Any version for the good ole' Super Expander ?