Skip to content

Commit

Permalink
Merge pull request #126 from chrisws/12_22
Browse files Browse the repository at this point in the history
12 22
  • Loading branch information
chrisws authored Aug 29, 2021
2 parents 602f875 + 4b09a3f commit 15f753f
Show file tree
Hide file tree
Showing 67 changed files with 967 additions and 633 deletions.
51 changes: 51 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
2021-08-22 (12.23)
SDL: Validate window dimensions on loading to prevent hidden window

2021-08-16 (12.23)
COMMON: Fix array append regression #122
UI: added window hideKeypad #125

2021-08-16 (12.23)
ANDROID: Hide keypad on run. Show keypad for INPUT, then re-hide on completion.

2021-07-28 (12.22)
UI: Allow RGB to be used with image array passed to IMAGE

2021-07-27 (12.22)
FLTK: Fix PSET display of extra pixel

2021-07-04 (12.22)
SDL: Fix Live edit when start path contains unicode characters

2021-07-02 (12.22)
UI: Fix to make image save and load compatible

2021-06-25 (12.22)
ANDROID: Unified file listing includes bas files from sub-folders

2021-06-23 (12.22)
FLTK: Implemented image opacity handling
UI: Implemented image.clip(left,top,right,bottom)

2021-06-12 (12.22)
UI: Fix potential memory leak using IMAGE
UI: Fix RGB handling with IMAGE
ANDROID: restore home directory when resuming from run
ANDROID: removed samsung keypad warning

2021-06-06 (12.22)
UI: implemented image.draw(), fix image.save in andoid #115

2021-06-05 (12.22)
COMMON: Fixes 'Socket Client doesn't receive byte with value 13' #112
COMMON: Fixes TSAVE of arrays includes extra null character. #119

2021-05-03 (12.22)
COMMON: Fix array access regression

2021-05-03 (12.22)
ANDROID: Removes path navigation to show unified view of available folder

2021-04-02 (12.22)
SDL: Update editor to handle unit errors

2021-04-02 (12.21)
ANDROID: Added range checking for the web services port

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
dnl Download the GNU Public License (GPL) from www.gnu.org
dnl

AC_INIT([smallbasic], [12.21])
AC_INIT([smallbasic], [12.22])
AC_CONFIG_SRCDIR([configure.ac])

AC_CANONICAL_TARGET
Expand Down
2 changes: 1 addition & 1 deletion documentation/sbasic_ref.csv
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Graphics,command,PSET,621,"PSET [STEP] x,y [, color| COLOR color]","Draw a pixel
Graphics,command,RECT,622,"RECT [STEP] x,y [,|STEP x2,y2] [, color| COLOR color] [FILLED]","Draws a rectangular parallelogram."
Graphics,command,SHOWPAGE,1429,"SHOWPAGE","This command is used to display pending graphics operations allowing for smooth animations."
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."
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"
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"
Graphics,constant,XMAX,1526,"XMAX","Holds the screen width in pixels"
Graphics,constant,YMAX,1527,"YMAX","Holds the screen height in pixels."
Graphics,function,PEN,627,"PEN (0..14)","Returns the PEN/MOUSE data."
Expand Down
2 changes: 1 addition & 1 deletion samples/distro-examples/tests/all.bas
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ print "RIGHT:" + RIGHT (s,2)
print "RIGHTOF:" + RIGHTOF (s1, s2)
print "RIGHTOFLAST:" + RIGHTOFLAST (s1, s2)
print "RINSTR:" + RINSTR (2, s1, s2)
print "RND:" + RND
print "RND:" + iff(RND>=0 && RND<=1.0,1,0)
print "ROUND:" + ROUND (x,22)
print "RTRIM:" + RTRIM (s)
print "RUN:" '+ RUN cmdstr
Expand Down
9 changes: 9 additions & 0 deletions samples/distro-examples/tests/array.bas
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,12 @@ sub xfunc(argx)
end
z=anims[0].framePoses[0, 0].translation
xfunc(anims[0].framePoses[0, 0].translation)

dim a()
append a, [1,2],[3,4],[5,6]
a << [7,8,9]
if (a[0] != [1,2]) then throw "err1"
if (a[1] != [3,4]) then throw "err2"
if (a[2] != [5,6]) then throw "err3"
if (a[3] != [7,8,9]) then throw "err4"

2 changes: 1 addition & 1 deletion samples/distro-examples/tests/output/all.out
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ RIGHT:gs
RIGHTOF:
RIGHTOFLAST:
RINSTR:0
RND:0.75898406142369
RND:1
ROUND:12.3
RTRIM:catsanddogs
RUN:
Expand Down
1 change: 1 addition & 0 deletions src/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ libsb_common_a_SOURCES = \
device.c device.h \
screen.c \
system.c \
random.c \
eval.c \
extlib.c extlib.h \
file.c \
Expand Down
37 changes: 6 additions & 31 deletions src/common/blib.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ void cmd_append() {

// for each argument to append
do {
// get the value to append
var_t arg_p;
v_init(&arg_p);
eval(&arg_p);

// find the array element
var_t *elem_p;
if (var_p->type != V_ARRAY) {
Expand All @@ -274,7 +269,8 @@ void cmd_append() {
}

// set the value onto the element
v_move(elem_p, &arg_p);
v_init(elem_p);
eval(elem_p);

// next parameter
if (code_peek() != kwTYPE_SEP) {
Expand All @@ -288,27 +284,6 @@ void cmd_append() {
} while (1);
}

void cmd_append_opt() {
var_t *v_left = code_getvarptr();

// skip kwTYPE_SEP + ","
code_skipsep();

// skip kwTYPE_VAR
code_skipnext();

var_t *elem_p;
if (v_left->type != V_ARRAY) {
v_toarray1(v_left, 1);
elem_p = v_elem(v_left, 0);
} else {
v_resize_array(v_left, v_asize(v_left) + 1);
elem_p = v_elem(v_left, v_asize(v_left) - 1);
}

v_set(elem_p, tvar[code_getaddr()]);
}

/**
* INSERT A, index, v1 [, vN]
*/
Expand Down Expand Up @@ -530,7 +505,7 @@ void cmd_print(int output) {
if (code_peek() == kwTYPE_EOC || code_peek() == kwTYPE_LINE) {
// There are no parameters
if (dev_fstatus(handle)) {
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, sizeof(OS_LINESEPARATOR));
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, OS_LINESEPARATOR_LEN);
} else {
err_fopen();
}
Expand Down Expand Up @@ -2051,18 +2026,18 @@ void cmd_restore() {
* RANDOMIZE [num]
*/
void cmd_randomize() {
long seed;
var_int_t seed;

byte code = code_peek();
switch (code) {
case kwTYPE_LINE:
case kwTYPE_EOC:
srand(clock());
pcg32_srand(clock());
break;
default:
seed = par_getint();
if (!prog_error) {
srand(seed);
pcg32_srand(seed);
}
};
}
Expand Down
1 change: 0 additions & 1 deletion src/common/blib.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void cmd_packed_let();
void cmd_dim(int);
void cmd_redim(void);
void cmd_append(void);
void cmd_append_opt(void);
void cmd_lins(void);
void cmd_ldel(void);
void cmd_erase(void);
Expand Down
2 changes: 1 addition & 1 deletion src/common/blib_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ void cmd_fsaveln() {
for (int i = 0; i < v_asize(array_p); i++) {
var_p = v_elem(array_p, i);
fprint_var(handle, var_p);
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, sizeof(OS_LINESEPARATOR));
dev_fwrite(handle, (byte *)OS_LINESEPARATOR, OS_LINESEPARATOR_LEN);
}
} else {
// parameter is an string
Expand Down
2 changes: 1 addition & 1 deletion src/common/blib_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ var_num_t cmd_math0(long funcCode) {
}
break;
case kwRND:
r = ((var_num_t) rand()) / (RAND_MAX + 1.0);
r = pcg32_rand();
break;
default:
rt_raise("Unsupported built-in function call %ld", funcCode);
Expand Down
3 changes: 0 additions & 3 deletions src/common/brun.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,6 @@ void bc_loop(int isf) {
case kwAPPEND:
cmd_append();
break;
case kwAPPEND_OPT:
cmd_append_opt();
break;
case kwINSERT:
cmd_lins();
break;
Expand Down
9 changes: 8 additions & 1 deletion src/common/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -1070,12 +1070,19 @@ void panic(const char *fmt, ...);
void lwrite(const char *buf);

/**
* @ingroup dev_f
* @ingroup dev
*
* resize the window coordinate system
*/
void dev_resize(int width, int height);

/**
* @ingroup dev
*
* adjust the point to the window coordinate system
*/
void dev_map_point(int *x, int *y);

#if defined(__cplusplus)
}
#endif
Expand Down
12 changes: 10 additions & 2 deletions src/common/fs_socket_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,16 @@ int sockcl_write(dev_file_t *f, byte *data, uint32_t size) {
* read from a socket
*/
int sockcl_read(dev_file_t *f, byte *data, uint32_t size) {
f->drv_dw[0] = (uint32_t) net_input((socket_t) (long) f->handle, (char *)data, size, NULL);
return (((long) f->drv_dw[0]) <= 0) ? 0 : (long) f->drv_dw[0];
int result;
if (f->handle != -1) {
f->drv_dw[0] = (uint32_t) net_input((socket_t) (long) f->handle, (char *)data, size, NULL);
result = (((long) f->drv_dw[0]) <= 0) ? 0 : (long) f->drv_dw[0];
} else {
err_network();
data[0] = 0;
result = 0;
}
return result;
}

/*
Expand Down
6 changes: 2 additions & 4 deletions src/common/inet2.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ int net_input(socket_t s, char *buf, int size, const char *delim) {
return count; // delimiter found
}
}
if (ch != '\015') { // ignore it
buf[count] = ch;
count += bytes; // actually ++
}
buf[count] = ch;
count += bytes;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/common/kw.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ enum keyword {
kwFORSEP,
kwOUTPUTSEP,
kwAPPEND,
kwAPPEND_OPT,
kwINSERT,
kwDELETE,
kwAPPENDSEP,
Expand Down
38 changes: 38 additions & 0 deletions src/common/random.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file is part of SmallBASIC
//
// random number generator, see:
// https://en.wikipedia.org/wiki/Permuted_congruential_generator
// https://www.pcg-random.org/download.html
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2021 Chris Warren-Smith

#include "config.h"

#include "common/sys.h"
#include <stdint.h>
#include <limits.h>

static uint64_t state = 0x4d595df4d0f33173;
static uint64_t multiplier = 6364136223846793005u;
static uint64_t increment = 1442695040888963407u;

static uint32_t rotr32(uint32_t x, unsigned r) {
return x >> r | x << (-r & 31);
}

var_num_t pcg32_rand() {
uint64_t x = state;
unsigned count = (unsigned)(x >> 59);
state = x * multiplier + increment;
x ^= x >> 18;
int32_t r = rotr32((uint32_t)(x >> 27), count);
return ((var_num_t)abs(r)) / (INT_MAX + 1.0);
}

void pcg32_srand(var_int_t seed) {
state = seed + increment;
pcg32_rand();
}
4 changes: 4 additions & 0 deletions src/common/sberr.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ void err_memory() {
rt_raise(ERR_MEMORY);
}

void err_network() {
rt_raise(ERR_NETWORK);
}

/**
* the DONE message
*/
Expand Down
1 change: 1 addition & 0 deletions src/common/sberr.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void err_ref_circ_var();
void err_array();
void err_form_input();
void err_memory();
void err_network();
void err_throw(const char *fmt, ...);
int err_handle_error(const char *err, var_p_t var);
void inf_done(void);
Expand Down
Loading

0 comments on commit 15f753f

Please sign in to comment.