Skip to content

Commit 1d640ef

Browse files
committed
COMMON: Implementation of TICKS(n)
1 parent 4f9f2d1 commit 1d640ef

9 files changed

Lines changed: 55 additions & 14 deletions

File tree

AUTHORS

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
Chris Warren-Smith cwarrensmith@gmail.com chrisws
2-
Nicholas Christopoulos wired_gr@yahoo.com ndc
3-
Gary A. Clark clarkg@fireserve.net gac
4-
Bob Riess riessb@usa.net bob
5-
Earle F. Philhower III earle@ziplabel.com efp
6-
Laurent Poujoulat lpoujoulat@wanadoo.fr lap
7-
Mehul Sanghvi mehul.sanghvi@gmail.com mnsanghvi
8-
9-
1+
Chris Warren-Smith cwarrensmith@gmail.com chrisws
2+
Nicholas Christopoulos wired_gr@yahoo.com ndc
3+
Gary A. Clark clarkg@fireserve.net gac
4+
Bob Riess riessb@usa.net bob
5+
Earle F. Philhower III earle@ziplabel.com efp
6+
Laurent Poujoulat lpoujoulat@wanadoo.fr lap
7+
Mehul Sanghvi mehul.sanghvi@gmail.com mnsanghvi
8+
Joerg Siebenmorgen siebenmorgen@mailbox.org j7m
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
print "step | ticks"
2+
print "--------------|----------"
3+
4+
print "initial ticks | "; ticks()
5+
delay(100)
6+
print "delay(100) | "; ticks()
7+
8+
ticks(0)
9+
print "ticks(0) | "; ticks()
10+
delay(100)
11+
print "delay(100) | "; ticks()
12+
13+
ticks(1000)
14+
print "ticks(1000) | "; ticks()
15+
delay(100)
16+
print "delay(100) | "; ticks()

samples/distro-examples/tests/all.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ print "CHDIR:" ':CHDIR dir
2929
print "CHMOD:" ':CHMOD file, mode
3030
print "CIRCLE:" ':CIRCLE [STEP] x,y,r [,aspect [, color]] [COLOR color] [FILLED]
3131
print "CLOSE:" ':CLOSE #fileN
32-
print "CLS:" :CLS
32+
print "CLS:"' :CLS
3333
print "COLOR:" :COLOR 1,2
3434
print "COPY:" ':COPY "file", "newfile"
3535
print "DATEDMY:";: DATEDMY(2459590,jd,jm,jy): print jd;jm;jy
@@ -230,7 +230,7 @@ print "TAN:" + TAN (x)
230230
print "TANH:" + TANH (x)
231231
print "TEXTHEIGHT:" + TEXTHEIGHT (s)
232232
print "TEXTWIDTH:" + TEXTWIDTH (s)
233-
print "TICKS:"' + TICKS
233+
print "TICKS:": TICKS(0): if(TICKS()) then throw "Ticks failed"
234234
print "TIME:"' + TIME
235235
print "TIMER:"' + TIMER
236236
print "TIMESTAMP:" '+ TIMESTAMP filename

src/common/blib.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#define STR_INIT_SIZE 256
1717
#define PKG_INIT_SIZE 5
1818

19+
// ticks(n)
20+
extern var_int_t tickOffset;
21+
1922
/**
2023
* LET v[(x)] = any
2124
* CONST v[(x)] = any
@@ -2374,6 +2377,20 @@ void cmd_environ() {
23742377
v_free(&str);
23752378
}
23762379

2380+
/**
2381+
* TICKS int
2382+
*/
2383+
void cmd_ticks(void) {
2384+
var_int_t offset;
2385+
2386+
offset = par_getint();
2387+
if (prog_error) {
2388+
return;
2389+
}
2390+
2391+
tickOffset = dev_get_millisecond_count() - offset;
2392+
}
2393+
23772394
/**
23782395
* DATEDMY string|julian, m, d, y
23792396
*/

src/common/blib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void cmd_datedmy(void);
8989
void cmd_timehms(void);
9090
void cmd_deriv(void);
9191
void cmd_diffeq(void);
92+
void cmd_ticks(void);
9293

9394
// not basic, but speed is needed
9495
void graph_reset(void);

src/common/blib_func.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ static char *date_wdN_table[] = TABLE_WEEKDAYS_FULL;
3030
static char *date_m3_table[] = TABLE_MONTH_3C;
3131
static char *date_mN_table[] = TABLE_MONTH_FULL;
3232

33+
// ticks()
34+
var_int_t tickOffset = 0;
35+
3336
#define BUF_LEN 64
3437
#define BIN_LEN 32 // Number of max bits (digits) kwBIN creates
3538

@@ -752,7 +755,7 @@ var_int_t cmd_imath0(long funcCode) {
752755
//
753756
// int <- TICKS // clock()
754757
//
755-
r = dev_get_millisecond_count();
758+
r = dev_get_millisecond_count() - tickOffset;
756759
break;
757760
case kwPROGLINE:
758761
//

src/common/brun.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ static inline void bc_loop_call_proc() {
495495
case kwAT:
496496
cmd_at();
497497
break;
498+
case kwTICKSP:
499+
cmd_ticks();
500+
break;
498501
case kwPEN:
499502
cmd_pen();
500503
break;

src/common/kw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ enum proc_keywords {
246246
kwDEFINEKEY,
247247
kwSHOWPAGE,
248248
kwTHROW,
249-
kwNULLPROC
249+
kwNULLPROC,
250+
kwTICKSP
250251
};
251252

252253
/**

src/languages/keywords.en.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ struct proc_keyword_s proc_table[] = {
413413
{ "CALL", kwCALLCP },
414414
{ "DEFINEKEY", kwDEFINEKEY },
415415
{ "SHOWPAGE", kwSHOWPAGE },
416-
{ "TIMER", kwTIMER },
416+
{ "TIMER", kwTIMER },
417+
{ "TICKS", kwTICKSP },
417418

418419
#if !defined(OS_LIMITED)
419420
{ "STKDUMP", kwSTKDUMP },

0 commit comments

Comments
 (0)