Reusing arduino analog clock code from years ago on ESP Basic.
Yeah I know... BASIC right ?, but honestly as a quick way of getting something happening on the ESP it is one of the simplest ways available.
time.setup(+11,0)
tft.setup(16,4,3)
tft.text.color(tft.rgb(55,155,67))
tft.text.font(1)
WHITE=tft.rgb(255,255,255)
gosub [showtime]
timercb 60000 , [showtime]
wait
[showtime]
tft.cls()
tvx = 320/2
tvy = 240/2
tvradius = 240/2 - 2
'clock face
tft.circle(tvx,tvy,tvradius,WHITE)
gosub [ticks]
minute = time("minute")
hour=time("hour")
second=time("second")
'angle = second * 6
'Convert degrees to radians
'angle = (angle/57.29577951)
'x3 = (tvx+(sin(angle)*(tvradius-6)))
'y3 = (tvy-(cos(angle)*(tvradius-6)))
'tft.line(tvx,tvy,x3,y3,WHITE)
angle = minute * 6
angle = (angle/57.29577951) 'Convert degrees to radians
x3 = (tvx+(sin(angle)*(tvradius-11)))
y3 = (tvy-(cos(angle)*(tvradius-11)))
tft.line(tvx,tvy,x3,y3,WHITE)
angle = hour * 30 + int((minute / 12) * 6 )
angle = (angle/57.29577951) 'Convert degrees to radians
x3 = (tvx+(sin(angle)*(tvradius-40)))
y3 = (tvy-(cos(angle)*(tvradius-40)))
tft.line(tvx,tvy,x3,y3,WHITE)
return
[ticks]
'hour ticks
z = 0
n = 12
do
'Begin at 0 and stop at 360
angle = z
angle=(angle/57.29577951) 'Convert degrees to radians
x2=(tvx+(sin(angle)*tvradius))
y2=(tvy-(cos(angle)*tvradius))
x3=(tvx+(sin(angle)*(tvradius-5)))
y3=(tvy-(cos(angle)*(tvradius-5)))
tft.line(x2,y2,x3,y3,WHITE)
tft.text.cursor(x3,y3)
tft.print( str(n) )
if n == 12 then n = 0
n = n + 1
z = z + 30
loop while z < 360
return
Thursday, 1 February 2018
Thursday, 25 January 2018
Tuesday, 23 January 2018
Monday, 22 January 2018
Monday, 8 January 2018
Wednesday, 27 December 2017
Wednesday, 6 December 2017
csirac "emulator"
I am dabbling with a CSIRAC "emulator", very basic so far. There is a Windows 98 program but it is a little
wonky under Wine, so this.
Using Frank Hirst's Principles and Operations... and the programming manual
(also in the emulator zip) as guide. Not sure about the tape mechanism, but
I guess a file to load the programs at least.
/* csirac rustic "emulator" with hello world program
*
* not all src and dest codes decoded yet, and no tape functions
*
*/
#include -stdio.h- //these dashes should be lt and gt but blogger won't show them
//#define DEBUG
int A,B,C,D[15],Src,Dest,S=0,K=0,M , Value ,Reg1=0,Reg2=45 ;
int Store[1024] ={
//0123456789SSSSSDDDDD
0b00000010010000000010, //0 M 13 T H
0b00000000000000000100, //1 A= M 0
0b00000010001100000101, //2 A = A + PE
0b00000000000010000000, //3 M 0 = A
0b00000010000000000110, //4 A - M 8 (stop value)
0b00000000000101011001, //5 SKIP IF 0 src=10 (ZA) dest=25 (CS)
0b00000000001010010111, //6 JMP 0 src=20 (Z) dest = 23 (S)
0b00000010111111111111, //7 HALT
0b00000101010000000010, //8 P20-P11 = 21 (stop value)
0x48, 0x45, 0x4C, 0x4C, 0x4F, 0x20, 0x57, 0x4F, 0x52, 0x4C, 0x44, 0x0d, //9
0b00000000000000000000, //21 spare
0b00000000000000000000, //22 spare
0b00000000000000000000, //23 spare
0b00000000000000000000, //24 spare
};
int main (void) {
while (S < 1024){
Dest=0b11111 & Store[S];
if (Dest > 1024) break ;
Src=0b11111 & ( Store[S] >> 5 );
if (Src > 1024 ) break ;
K=Store[S] >>10;
if (Src==0) Value = Store[K] ;
//if (Src==1) Value = ;
if (Src==2) Value = Reg1 ;
if (Src==3) Value = Reg2 ;
if (Src==4) Value = A;
if (Src==5 ) Value = A >> 20 ;
if (Src==6 ) Value = A /2 ;
if (Src==7 ) Value = A*2;
if (Src==8 ) Value = 0b00001111 & A ;
if (Src==9 ) { Value = A ; A = 0 ; }
if (Src==10 ) { if (A == 0) Value = 0 ; else Value = 1 ; }
if (Src==11 ) Value = B ;
if (Src==12 ) { if ((B >> 20) == 1 ) Value = 99; else Value =0 ; } ;
if (Src==13 ) Value = B >> 1 ;
if (Src==14 ) Value = C ;
if (Src==15 ) Value = C >> 20 ;
if (Src==20) Value =0;
if (Src==23) Value =S;
if (Src==24) Value=0b00000000010000000000;
if (Src==25) Value=0b00000000000000000001;
if (Src==26) Value = K;
if (Dest==0) Store[K]=Value;
if (Dest==2) { printf ("%c", Value);
#ifdef DEBUG
printf("\n");
#endif
}
if (Dest==4) A = Value;
if (Dest==5) A = A + Value;
if (Dest==6) A = A - Value;
if (Dest==7) A = A & Value;
if (Dest==8) A = A | Value;
if (Dest==9) A = A ^ Value;
if (Dest==16) C = C - Value;
if (Dest==23) { S = Value - 1 ; if (S > 1024 ) break;}
if (Dest==25) if (Value==0) S++;
if (Dest==26) K = Value;
if ((Src == 31) && (Dest==31)) { printf("\n\n*Halt*\n\n");break; }
S++;
#ifdef DEBUG
printf("A=%d Src=%d Dest=%d K=%d S=%d Store[%d]=%d\n",A,Src,Dest,K,S,S,Store[S] );
#endif
}
printf ("\n");
#ifdef DEBUG
// display memory store
for (S=0;S <=20 ;S++) { printf("%d = %d\n",S,Store[S]); }
#endif
return 0;
}
Subscribe to:
Posts (Atom)























