Hi!
While programming with Sinclair BASIC and C (z88dk) I was rather pleasantly surprised that it is rather easy to connect the C code with Sinclair BASIC by exchanging BASIC variables with zx_getstr() and the like. ATM I'm using this to pass information between the BASIC and C portion of my program. Now my question:
Is it possible to read/write array variables like c(1) from a DIM c(10)-array? Same question for strings arrays, something like zx_set/getstr('a(1)') with (f.ex.) DIM a$(10,10).
BTW: Thanks for the z88dk!
Connect to Ainclair BASIC arrays.
-
- Well known member
- Posts: 1635
- Joined: Mon Jul 16, 2007 7:39 pm
I'm sorry, at the moment only numeric types and normal strings are supported.
This type of functions can be created, but to be reasonably effective a whole set of functions should be prepared (picking a single 'cell' from an array, copying the whole matrix in a C storage area, dealing with lists or a bi-dimensional matrix, etc.. and doing it for float values, integers, and strings).
Workarounds are possible but require extensive tests to be sure they are stable enough, e.g. you can try invoking a more complex BASIC portion via zx_line.
I'd try something like this (not tested, watch out !)
Suppose you need to read the array in a$ at a given position, you could use zx_setint to load the position to variables x and y and add an extra line to your BASIC program (colon separated statements are allowed only on the Spectrum or TS2068, the ZX81 is much weaker with this kind of things and could not work at all):
9999 LET r$=a$(x,y)
Using zx_line(9999) in C should execute the single program line and return to caller.
Last step, read r$ with the C function zx_getstr('r').
This type of functions can be created, but to be reasonably effective a whole set of functions should be prepared (picking a single 'cell' from an array, copying the whole matrix in a C storage area, dealing with lists or a bi-dimensional matrix, etc.. and doing it for float values, integers, and strings).
Workarounds are possible but require extensive tests to be sure they are stable enough, e.g. you can try invoking a more complex BASIC portion via zx_line.
I'd try something like this (not tested, watch out !)
Suppose you need to read the array in a$ at a given position, you could use zx_setint to load the position to variables x and y and add an extra line to your BASIC program (colon separated statements are allowed only on the Spectrum or TS2068, the ZX81 is much weaker with this kind of things and could not work at all):
9999 LET r$=a$(x,y)
Using zx_line(9999) in C should execute the single program line and return to caller.
Last step, read r$ with the C function zx_getstr('r').
-
- Member
- Posts: 23
- Joined: Fri Jan 04, 2019 11:06 am
-
- Well known member
- Posts: 1635
- Joined: Mon Jul 16, 2007 7:39 pm