Skip to content

Commit 15f753f

Browse files
authored
Merge pull request #126 from chrisws/12_22
12 22
2 parents 602f875 + 4b09a3f commit 15f753f

Some content is hidden

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

67 files changed

+967
-633
lines changed

ChangeLog

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
1+
2021-08-22 (12.23)
2+
SDL: Validate window dimensions on loading to prevent hidden window
3+
4+
2021-08-16 (12.23)
5+
COMMON: Fix array append regression #122
6+
UI: added window hideKeypad #125
7+
8+
2021-08-16 (12.23)
9+
ANDROID: Hide keypad on run. Show keypad for INPUT, then re-hide on completion.
10+
11+
2021-07-28 (12.22)
12+
UI: Allow RGB to be used with image array passed to IMAGE
13+
14+
2021-07-27 (12.22)
15+
FLTK: Fix PSET display of extra pixel
16+
17+
2021-07-04 (12.22)
18+
SDL: Fix Live edit when start path contains unicode characters
19+
20+
2021-07-02 (12.22)
21+
UI: Fix to make image save and load compatible
22+
23+
2021-06-25 (12.22)
24+
ANDROID: Unified file listing includes bas files from sub-folders
25+
26+
2021-06-23 (12.22)
27+
FLTK: Implemented image opacity handling
28+
UI: Implemented image.clip(left,top,right,bottom)
29+
30+
2021-06-12 (12.22)
31+
UI: Fix potential memory leak using IMAGE
32+
UI: Fix RGB handling with IMAGE
33+
ANDROID: restore home directory when resuming from run
34+
ANDROID: removed samsung keypad warning
35+
36+
2021-06-06 (12.22)
37+
UI: implemented image.draw(), fix image.save in andoid #115
38+
39+
2021-06-05 (12.22)
40+
COMMON: Fixes 'Socket Client doesn't receive byte with value 13' #112
41+
COMMON: Fixes TSAVE of arrays includes extra null character. #119
42+
43+
2021-05-03 (12.22)
44+
COMMON: Fix array access regression
45+
46+
2021-05-03 (12.22)
47+
ANDROID: Removes path navigation to show unified view of available folder
48+
49+
2021-04-02 (12.22)
50+
SDL: Update editor to handle unit errors
51+
152
2021-04-02 (12.21)
253
ANDROID: Added range checking for the web services port
354

configure.ac

Lines changed: 1 addition & 1 deletion
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.21])
10+
AC_INIT([smallbasic], [12.22])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

documentation/sbasic_ref.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Graphics,command,PSET,621,"PSET [STEP] x,y [, color| COLOR color]","Draw a pixel
9595
Graphics,command,RECT,622,"RECT [STEP] x,y [,|STEP x2,y2] [, color| COLOR color] [FILLED]","Draws a rectangular parallelogram."
9696
Graphics,command,SHOWPAGE,1429,"SHOWPAGE","This command is used to display pending graphics operations allowing for smooth animations."
9797
Graphics,command,VIEW,623,"VIEW [x1,y1,x2,y2 [,color [,border-color]]]","Defines a viewport. The viewport defined by VIEW is disabled by a VIEW command with no parameters."
98-
Graphics,command,WINDOW,624,"WINDOW [x1,y1,x2,y2]","The WINDOW command allows you to redefine the corners of the display screen as a pair of ""world"" coordinates. WINDOW is also overloaded as a function, returning a system object providing access to the following sub-commands: graphicsScreen1, graphicsScreen2, textScreen, alert, ask, menu, message, showKeypad, insetTextScreen"
98+
Graphics,command,WINDOW,624,"WINDOW [x1,y2,x2,y1]","The WINDOW command allows you to redefine the corners of the display screen as a pair of ""world"" coordinates. WINDOW is also overloaded as a function, returning a system object providing access to the following sub-commands: graphicsScreen1, graphicsScreen2, textScreen, alert, ask, menu, message, showKeypad, insetTextScreen"
9999
Graphics,constant,XMAX,1526,"XMAX","Holds the screen width in pixels"
100100
Graphics,constant,YMAX,1527,"YMAX","Holds the screen height in pixels."
101101
Graphics,function,PEN,627,"PEN (0..14)","Returns the PEN/MOUSE data."

samples/distro-examples/tests/all.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ print "RIGHT:" + RIGHT (s,2)
198198
print "RIGHTOF:" + RIGHTOF (s1, s2)
199199
print "RIGHTOFLAST:" + RIGHTOFLAST (s1, s2)
200200
print "RINSTR:" + RINSTR (2, s1, s2)
201-
print "RND:" + RND
201+
print "RND:" + iff(RND>=0 && RND<=1.0,1,0)
202202
print "ROUND:" + ROUND (x,22)
203203
print "RTRIM:" + RTRIM (s)
204204
print "RUN:" '+ RUN cmdstr

samples/distro-examples/tests/array.bas

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,12 @@ sub xfunc(argx)
327327
end
328328
z=anims[0].framePoses[0, 0].translation
329329
xfunc(anims[0].framePoses[0, 0].translation)
330+
331+
dim a()
332+
append a, [1,2],[3,4],[5,6]
333+
a << [7,8,9]
334+
if (a[0] != [1,2]) then throw "err1"
335+
if (a[1] != [3,4]) then throw "err2"
336+
if (a[2] != [5,6]) then throw "err3"
337+
if (a[3] != [7,8,9]) then throw "err4"
338+

samples/distro-examples/tests/output/all.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ RIGHT:gs
183183
RIGHTOF:
184184
RIGHTOFLAST:
185185
RINSTR:0
186-
RND:0.75898406142369
186+
RND:1
187187
ROUND:12.3
188188
RTRIM:catsanddogs
189189
RUN:

src/common/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ libsb_common_a_SOURCES = \
5454
device.c device.h \
5555
screen.c \
5656
system.c \
57+
random.c \
5758
eval.c \
5859
extlib.c extlib.h \
5960
file.c \

src/common/blib.c

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,6 @@ void cmd_append() {
258258

259259
// for each argument to append
260260
do {
261-
// get the value to append
262-
var_t arg_p;
263-
v_init(&arg_p);
264-
eval(&arg_p);
265-
266261
// find the array element
267262
var_t *elem_p;
268263
if (var_p->type != V_ARRAY) {
@@ -274,7 +269,8 @@ void cmd_append() {
274269
}
275270

276271
// set the value onto the element
277-
v_move(elem_p, &arg_p);
272+
v_init(elem_p);
273+
eval(elem_p);
278274

279275
// next parameter
280276
if (code_peek() != kwTYPE_SEP) {
@@ -288,27 +284,6 @@ void cmd_append() {
288284
} while (1);
289285
}
290286

291-
void cmd_append_opt() {
292-
var_t *v_left = code_getvarptr();
293-
294-
// skip kwTYPE_SEP + ","
295-
code_skipsep();
296-
297-
// skip kwTYPE_VAR
298-
code_skipnext();
299-
300-
var_t *elem_p;
301-
if (v_left->type != V_ARRAY) {
302-
v_toarray1(v_left, 1);
303-
elem_p = v_elem(v_left, 0);
304-
} else {
305-
v_resize_array(v_left, v_asize(v_left) + 1);
306-
elem_p = v_elem(v_left, v_asize(v_left) - 1);
307-
}
308-
309-
v_set(elem_p, tvar[code_getaddr()]);
310-
}
311-
312287
/**
313288
* INSERT A, index, v1 [, vN]
314289
*/
@@ -530,7 +505,7 @@ void cmd_print(int output) {
530505
if (code_peek() == kwTYPE_EOC || code_peek() == kwTYPE_LINE) {
531506
// There are no parameters
532507
if (dev_fstatus(handle)) {
533-
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, sizeof(OS_LINESEPARATOR));
508+
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, OS_LINESEPARATOR_LEN);
534509
} else {
535510
err_fopen();
536511
}
@@ -2051,18 +2026,18 @@ void cmd_restore() {
20512026
* RANDOMIZE [num]
20522027
*/
20532028
void cmd_randomize() {
2054-
long seed;
2029+
var_int_t seed;
20552030

20562031
byte code = code_peek();
20572032
switch (code) {
20582033
case kwTYPE_LINE:
20592034
case kwTYPE_EOC:
2060-
srand(clock());
2035+
pcg32_srand(clock());
20612036
break;
20622037
default:
20632038
seed = par_getint();
20642039
if (!prog_error) {
2065-
srand(seed);
2040+
pcg32_srand(seed);
20662041
}
20672042
};
20682043
}

src/common/blib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ void cmd_packed_let();
3737
void cmd_dim(int);
3838
void cmd_redim(void);
3939
void cmd_append(void);
40-
void cmd_append_opt(void);
4140
void cmd_lins(void);
4241
void cmd_ldel(void);
4342
void cmd_erase(void);

src/common/blib_db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ void cmd_fsaveln() {
725725
for (int i = 0; i < v_asize(array_p); i++) {
726726
var_p = v_elem(array_p, i);
727727
fprint_var(handle, var_p);
728-
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, sizeof(OS_LINESEPARATOR));
728+
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, OS_LINESEPARATOR_LEN);
729729
}
730730
} else {
731731
// parameter is an string

src/common/blib_func.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ var_num_t cmd_math0(long funcCode) {
480480
}
481481
break;
482482
case kwRND:
483-
r = ((var_num_t) rand()) / (RAND_MAX + 1.0);
483+
r = pcg32_rand();
484484
break;
485485
default:
486486
rt_raise("Unsupported built-in function call %ld", funcCode);

src/common/brun.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,6 @@ void bc_loop(int isf) {
882882
case kwAPPEND:
883883
cmd_append();
884884
break;
885-
case kwAPPEND_OPT:
886-
cmd_append_opt();
887-
break;
888885
case kwINSERT:
889886
cmd_lins();
890887
break;

src/common/device.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,12 +1070,19 @@ void panic(const char *fmt, ...);
10701070
void lwrite(const char *buf);
10711071

10721072
/**
1073-
* @ingroup dev_f
1073+
* @ingroup dev
10741074
*
10751075
* resize the window coordinate system
10761076
*/
10771077
void dev_resize(int width, int height);
10781078

1079+
/**
1080+
* @ingroup dev
1081+
*
1082+
* adjust the point to the window coordinate system
1083+
*/
1084+
void dev_map_point(int *x, int *y);
1085+
10791086
#if defined(__cplusplus)
10801087
}
10811088
#endif

src/common/fs_socket_client.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,16 @@ int sockcl_write(dev_file_t *f, byte *data, uint32_t size) {
202202
* read from a socket
203203
*/
204204
int sockcl_read(dev_file_t *f, byte *data, uint32_t size) {
205-
f->drv_dw[0] = (uint32_t) net_input((socket_t) (long) f->handle, (char *)data, size, NULL);
206-
return (((long) f->drv_dw[0]) <= 0) ? 0 : (long) f->drv_dw[0];
205+
int result;
206+
if (f->handle != -1) {
207+
f->drv_dw[0] = (uint32_t) net_input((socket_t) (long) f->handle, (char *)data, size, NULL);
208+
result = (((long) f->drv_dw[0]) <= 0) ? 0 : (long) f->drv_dw[0];
209+
} else {
210+
err_network();
211+
data[0] = 0;
212+
result = 0;
213+
}
214+
return result;
207215
}
208216

209217
/*

src/common/inet2.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,8 @@ int net_input(socket_t s, char *buf, int size, const char *delim) {
169169
return count; // delimiter found
170170
}
171171
}
172-
if (ch != '\015') { // ignore it
173-
buf[count] = ch;
174-
count += bytes; // actually ++
175-
}
172+
buf[count] = ch;
173+
count += bytes;
176174
}
177175
}
178176

src/common/kw.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ enum keyword {
151151
kwFORSEP,
152152
kwOUTPUTSEP,
153153
kwAPPEND,
154-
kwAPPEND_OPT,
155154
kwINSERT,
156155
kwDELETE,
157156
kwAPPENDSEP,

src/common/random.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This file is part of SmallBASIC
2+
//
3+
// random number generator, see:
4+
// https://en.wikipedia.org/wiki/Permuted_congruential_generator
5+
// https://www.pcg-random.org/download.html
6+
//
7+
// This program is distributed under the terms of the GPL v2.0 or later
8+
// Download the GNU Public License (GPL) from www.gnu.org
9+
//
10+
// Copyright(C) 2021 Chris Warren-Smith
11+
12+
#include "config.h"
13+
14+
#include "common/sys.h"
15+
#include <stdint.h>
16+
#include <limits.h>
17+
18+
static uint64_t state = 0x4d595df4d0f33173;
19+
static uint64_t multiplier = 6364136223846793005u;
20+
static uint64_t increment = 1442695040888963407u;
21+
22+
static uint32_t rotr32(uint32_t x, unsigned r) {
23+
return x >> r | x << (-r & 31);
24+
}
25+
26+
var_num_t pcg32_rand() {
27+
uint64_t x = state;
28+
unsigned count = (unsigned)(x >> 59);
29+
state = x * multiplier + increment;
30+
x ^= x >> 18;
31+
int32_t r = rotr32((uint32_t)(x >> 27), count);
32+
return ((var_num_t)abs(r)) / (INT_MAX + 1.0);
33+
}
34+
35+
void pcg32_srand(var_int_t seed) {
36+
state = seed + increment;
37+
pcg32_rand();
38+
}

src/common/sberr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ void err_memory() {
351351
rt_raise(ERR_MEMORY);
352352
}
353353

354+
void err_network() {
355+
rt_raise(ERR_NETWORK);
356+
}
357+
354358
/**
355359
* the DONE message
356360
*/

src/common/sberr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void err_ref_circ_var();
7878
void err_array();
7979
void err_form_input();
8080
void err_memory();
81+
void err_network();
8182
void err_throw(const char *fmt, ...);
8283
int err_handle_error(const char *err, var_p_t var);
8384
void inf_done(void);

0 commit comments

Comments
 (0)