Skip to content

Commit bd314e9

Browse files
authored
Merge pull request #240 from chrisws/12_28
12 28
2 parents 5d8f044 + 593a645 commit bd314e9

File tree

107 files changed

+3736
-905
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+3736
-905
lines changed

ChangeLog

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2025-02-18 (12.28)
2+
ANDROID: added experimental usb communication support
3+
4+
2025-02-02 (12.28)
5+
TEENSY: added experimental runtime platform for teensy mcu
6+
7+
2025-01-27 (12.28)
8+
ANDROID: Updated app icon, thanks to bplus, j7m, round157, qube, baggey
9+
Final design by j7m
10+
11+
2024-10-09 (12.28)
12+
COMMON: Fix #232: TICKS stops working after 50 days
13+
ANDROID: Fix delay accuracy
14+
ANDROID: Fix location regression
15+
16+
2024-10-06 (12.28)
17+
ANDROID: Fix web UI regression
18+
19+
2024-09-27 (12.28)
20+
ANDROID: Fix issue with playing an audio file on android #231
21+
122
2024-04-14 (12.27)
223
COMMON: Fix bug #149: Problem with big hex numbers in windows
324
COMMON: Add new function TRANSPOSE()

configure.ac

+35-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [12.27])
10+
AC_INIT([smallbasic], [12.28])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET
@@ -53,6 +53,11 @@ AC_ARG_ENABLE(dist,
5353
[ac_build_dist="yes"],
5454
[ac_build_dist="no"])
5555

56+
AC_ARG_ENABLE(teensy,
57+
AS_HELP_STRING([--enable-teensy],[build teensy version(default=no)]),
58+
[ac_build_teensy="yes"],
59+
[ac_build_teensy="no"])
60+
5661
function checkForWindows() {
5762
win32=no
5863
case "${host_os}" in
@@ -126,6 +131,10 @@ function checkPCRE() {
126131
have_pcre="no"
127132
fi
128133

134+
if test x$ac_build_teensy = xyes; then
135+
have_pcre="no"
136+
fi
137+
129138
if test "${have_pcre}" = "yes" ; then
130139
AC_DEFINE(USE_PCRE, 1, [match.c used with libpcre.])
131140
PACKAGE_LIBS="${PACKAGE_LIBS} `pcre-config --libs`"
@@ -144,6 +153,10 @@ function checkTermios() {
144153
have_termios_h="no"
145154
fi
146155

156+
if test x$ac_build_teensy = xyes; then
157+
have_termios_h="no"
158+
fi
159+
147160
if test "${have_termios_h}" = "yes" ; then
148161
AC_DEFINE(USE_TERM_IO, 1, [use the termios library.])
149162
fi
@@ -373,6 +386,24 @@ function buildEmscripten() {
373386
(cd src/platform/android/app/src/main/assets && xxd -i main.bas > ../../../../../../../src/platform/emcc/main_bas.h)
374387
}
375388

389+
function buildTEENSY() {
390+
TARGET="Building teensy version."
391+
BUILD_SUBDIRS="src/platform/teensy"
392+
AC_CHECK_PROG(have_xxd, xxd, [yes], [no])
393+
if test "${have_xxd}" = "no" ; then
394+
AC_MSG_ERROR([xxd command not installed: configure failed.])
395+
fi
396+
AM_CONDITIONAL(WITH_CYGWIN_CONSOLE, false)
397+
AC_DEFINE(_UnixOS, 1, [Building under Unix like systems.])
398+
AC_DEFINE(_MCU, 1, [Micro controller based builds])
399+
AC_DEFINE(_TEENSY, 1, [Teensy Micro controller based build])
400+
AC_DEFINE(USE_TERM_IO, 0, [dont use the termios library.])
401+
AC_DEFINE(IMPL_LOG_WRITE, 1, [Driver implements lwrite()])
402+
AC_DEFINE(IMPL_DEV_READ, 1, [Implement dev_read()])
403+
AC_SUBST(BUILD_SUBDIRS)
404+
(cd src/platform/teensy && xxd -i main.bas > src/main_bas.h)
405+
}
406+
376407
function buildFLTK() {
377408
TARGET="Building FLTK version."
378409

@@ -444,6 +475,8 @@ elif test x$ac_build_fltk = xyes; then
444475
buildFLTK
445476
elif test x$ac_build_emcc = xyes; then
446477
buildEmscripten
478+
elif test x$ac_build_teensy = xyes; then
479+
buildTEENSY
447480
else
448481
buildConsole
449482
fi
@@ -484,6 +517,7 @@ src/platform/emcc/Makefile
484517
src/platform/sdl/Makefile
485518
src/platform/web/Makefile
486519
src/platform/fltk/Makefile
520+
src/platform/teensy/Makefile
487521
])
488522
AC_OUTPUT
489523

images/sb-logo.blend

814 KB
Binary file not shown.

images/sb-logo.png

26.1 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import android
2+
3+
'
4+
' request usage: endpoint [, data, apiKey]
5+
' data, apikey: uses POST to send data, apiKey applied as bearer authorisation
6+
'
7+
const endPoint = "http://ip-api.com/json"
8+
print android.request(endPoint)
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import android
2+
3+
usb = android.openUsbSerial(0x16C0)
4+
5+
while 1
6+
usb.send("hello");
7+
print usb.receive()
8+
delay 1000
9+
wend
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'
2+
' provided by rpnielsen
3+
' https://www.syntaxbomb.com/smallbasic/the-play-string-command-and-the-latest-beta/
4+
'
5+
nrtests=5
6+
tempo=240 '1/4 notes pr min
7+
length=4 'play 1/x notes
8+
9+
expDur=(240000/tempo)/length
10+
11+
play "V10O3T"+tempo+"L"+length
12+
13+
? nrtests;" tests of 10 1/";length;" notes"
14+
? "at tempo = ";tempo;" 1/4 notes pr minute"
15+
? "Expected note duration = ";expDur;" ms."
16+
? "--------------------------"
17+
?
18+
19+
for a=1 to nrtests
20+
delay 50 'because otherwise nothing is printed to screen until after PLAY is done
21+
t=ticks
22+
play "CDEFGGFEDC"
23+
actDur=(ticks-t)/10
24+
dev=actDur-expDur
25+
? "Test ";a
26+
? "Average note duration = ";actDur;" ms."
27+
? "Deviaton = ";dev;" ms = ";((actDur/expDur)-1)*100;" %"
28+
totalDur=totalDur+actDur
29+
totalDev=totalDev+dev
30+
?
31+
next a
32+
33+
? "Overall average:"
34+
? "Duration = ";totalDur/nrtests;" ms"
35+
? "Deviation = ";totalDev/nrtests;" ms = ";(((totalDur/nrtests)/expDur)-1)*100;" %"
36+
37+
end

src/common/blib_func.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ void cmd_intN(long funcCode, var_t *r) {
19221922
if (l >= 0 && l < v_maxdim(var_p)) {
19231923
r->v.i = v_ubound(var_p, l);
19241924
} else {
1925-
rt_raise(ERR_BOUND_DIM, v_maxdim(var_p));
1925+
rt_raise(ERR_BOUND_DIM, l, v_maxdim(var_p));
19261926
}
19271927
}
19281928
} else {

src/common/brun.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void cmd_chain(void) {
351351
if (h != -1) {
352352
struct stat st;
353353
if (fstat(h, &st) == 0) {
354-
int len = st.st_size;
354+
size_t len = st.st_size;
355355
code = (char *)malloc(len + 1);
356356
len = read(h, code, len);
357357
code[len] = '\0';
@@ -1185,18 +1185,16 @@ int brun_create_task(const char *filename, byte *preloaded_bc, int libf) {
11851185
} else {
11861186
find_unit(filename, fname);
11871187
}
1188-
if (access(fname, R_OK)) {
1188+
// open & load
1189+
int h = open(fname, O_RDWR | O_BINARY);
1190+
if (h == -1) {
11891191
panic("File '%s' not found", fname);
11901192
}
11911193
// look if it is already loaded
11921194
if (search_task(fname) != -1) {
1195+
close(h);
11931196
return search_task(fname);
11941197
}
1195-
// open & load
1196-
int h = open(fname, O_RDWR | O_BINARY);
1197-
if (h == -1) {
1198-
panic("File '%s' not found", fname);
1199-
}
12001198
// load it
12011199
if (libf) {
12021200
read(h, &uft, sizeof(unit_file_t));

src/common/device.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ void dev_chdir(const char *dir);
969969
*
970970
* @return the current directory
971971
*/
972-
char *dev_getcwd(void);
972+
const char *dev_getcwd(void);
973973

974974
/**
975975
* @ingroup dev

src/common/eval.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var_num_t *mat_toc(var_t *v, int32_t *rows, int32_t *cols) {
7373
//
7474
// matrix: conv. double[nr][nc] to var_t
7575
//
76-
void mat_tov(var_t *v, var_num_t *m, int rows, int cols, int protect_col1) {
76+
void mat_tov(var_t *v, var_num_t *m, int32_t rows, int32_t cols, int protect_col1) {
7777
if (cols > 1 || protect_col1) {
7878
v_tomatrix(v, rows, cols);
7979
} else {
@@ -93,7 +93,7 @@ void mat_tov(var_t *v, var_num_t *m, int rows, int cols, int protect_col1) {
9393
// matrix: 1op
9494
//
9595
void mat_op1(var_t *l, int op, var_num_t n) {
96-
int lr, lc;
96+
int32_t lr, lc;
9797

9898
var_num_t *m1 = mat_toc(l, &lr, &lc);
9999
if (m1) {
@@ -142,7 +142,7 @@ void mat_mulN(var_t *v, var_num_t N) {
142142
// matrix - add/sub
143143
//
144144
void mat_op2(var_t *l, var_t *r, int op) {
145-
int lr, lc, rr, rc;
145+
int32_t lr, lc, rr, rc;
146146

147147
var_num_t *m1 = mat_toc(l, &lr, &lc);
148148
if (m1) {
@@ -221,7 +221,7 @@ void mat_dot(var_t *l, var_t *r) {
221221
// matrix: multiply
222222
//
223223
void mat_mul(var_t *l, var_t *r) {
224-
int lr, lc, rr, rc;
224+
int32_t lr, lc, rr, rc;
225225

226226
var_num_t *m1 = mat_toc(l, &lr, &lc);
227227
if (m1) {

src/common/file.c

+85-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,90 @@
3030
// FILE TABLE
3131
static dev_file_t file_table[OS_FILEHANDLES];
3232

33+
/*
34+
* returns the last-modified time of the file
35+
*
36+
* on error returns 0L
37+
*/
38+
time_t sys_filetime(const char *file) {
39+
struct stat st;
40+
41+
if (stat(file, &st) == 0) {
42+
return st.st_mtime;
43+
}
44+
return 0L;
45+
}
46+
47+
/*
48+
* search a set of directories for the given file
49+
* directories on path must be separated with symbol ':' (unix) or ';' (dos/win)
50+
*
51+
* @param path the path
52+
* @param file the file
53+
* @param retbuf a buffer to store the full-path-name file (can be NULL)
54+
* @return non-zero if found
55+
*/
56+
int sys_search_path(const char *path, const char *file, char *retbuf) {
57+
char cur_path[OS_PATHNAME_SIZE + 1];
58+
int found = 0;
59+
60+
if (path == NULL || strlen(path) == 0) {
61+
return 0;
62+
}
63+
const char *ps = path;
64+
const char *p;
65+
do {
66+
// next element, build cur_path
67+
p = strchr(ps, ':');
68+
if (!p) {
69+
strlcpy(cur_path, ps, sizeof(cur_path));
70+
} else {
71+
strncpy(cur_path, ps, p - ps);
72+
cur_path[p - ps] = '\0';
73+
ps = p + 1;
74+
}
75+
76+
// fix home directory
77+
if (cur_path[0] == '~') {
78+
char *old_path = malloc(strlen(cur_path) + 1);
79+
strcpy(old_path, cur_path + 1);
80+
if (getenv("HOME")) {
81+
strlcpy(cur_path, getenv("HOME"), sizeof(cur_path));
82+
} else {
83+
strlcpy(cur_path, getenv("HOMEDRIVE"), sizeof(cur_path));
84+
strlcat(cur_path, getenv("HOMEPATH"), sizeof(cur_path));
85+
}
86+
if (old_path[0] != '/') {
87+
strlcat(cur_path, "/", sizeof(cur_path));
88+
}
89+
strlcat(cur_path, old_path, sizeof(cur_path));
90+
free(old_path);
91+
}
92+
93+
DIR *dp = opendir(cur_path);
94+
if (dp != NULL) {
95+
struct dirent *entry;
96+
while (!found && (entry = readdir(dp)) != NULL) {
97+
if (strcasecmp(entry->d_name, file) == 0) {
98+
int end = strlen(cur_path);
99+
strcat(cur_path, "/");
100+
strcat(cur_path, entry->d_name);
101+
if (access(cur_path, R_OK) == 0) {
102+
if (retbuf) {
103+
strcpy(retbuf, cur_path);
104+
}
105+
found = 1;
106+
} else {
107+
cur_path[end] = '\0';
108+
}
109+
}
110+
}
111+
closedir(dp);
112+
}
113+
} while (p && !found);
114+
return found;
115+
}
116+
33117
/**
34118
* Basic wild-cards
35119
*/
@@ -659,7 +743,7 @@ void dev_destroy_file_list(char_p_t *list, int count) {
659743
* returns the current directory
660744
* BUG: no drivers supported
661745
*/
662-
char *dev_getcwd() {
746+
const char *dev_getcwd() {
663747
static char retbuf[OS_PATHNAME_SIZE + 1];
664748
getcwd(retbuf, OS_PATHNAME_SIZE);
665749
int l = strlen(retbuf);

src/common/keymap.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ int dev_kbhit() {
178178
* returns the next key in keyboard buffer (and removes it)
179179
*/
180180
long int dev_getch() {
181-
while ((dev_kbhit() == 0) && (prog_error == 0)) {
181+
while ((dev_kbhit() == 0) && (ctask && prog_error == 0)) {
182182
int evc = dev_events(2);
183-
if (evc < 0 || prog_error) {
183+
if (evc < 0 || (ctask && prog_error)) {
184184
return 0xFFFF;
185185
}
186186
}

0 commit comments

Comments
 (0)