Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

for discussion of bbc basic for windows/sdl, brandy and more
User avatar
Richard Russell
Posts: 2500
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Richard Russell »

Soruk wrote:
Sat Jul 24, 2021 2:24 pm
that was a slightly different issue of an array seemingly losing its LOCAL-ness after being dimensioned in a sub-procedure (an issue that doesn't arise in Matrix Brandy, instead I get an error that array has already been dimensioned the second time PROCsetup is called
Architecturally Brandy must be very different from either my BASICs or ARM BASIC in the way it implements LOCAL arrays. In my BASICs, and I think in ARM BASIC too from the way it behaves, LOCAL arrays are stored on the stack - the same stack that is used to store the control information for a FOR...NEXT loop. That means it is impossible to DIMension a LOCAL array inside a FOR...NEXT loop, because when the NEXT statement is reached it will find the array on the stack, not the information it expects!

Admittedly my BASICs behave differently from ARM BASIC in respect of what happens if you try it. In mine, the NEXT statement will invariably fail with a 'Not in a FOR loop' error but in ARM BASIC this will only happen if an explicit variable is specified after NEXT, e.g. NEXT i%. If NEXT is used without a variable it will apparently succeed, but the array will be silently discarded. :shock:

In Brandy, however, it seems that the NEXT statement actually succeeds, and the LOCAL array survives, despite it having been dimensioned inside the loop! I have no idea how that is even possible: are LOCAL arrays not stored on the stack, or are there different stacks for LOCAL arrays and FOR loops, or what? :?
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Sat Jul 24, 2021 3:07 pm
Soruk wrote:
Sat Jul 24, 2021 2:24 pm
unpack in your hostfs directory, then inside RPCEmu, do *RMRUN BASIC to replace the ROM BASIC and start it up - but not while BASIC itself is running!).
I only have Red Squirrel, not RPCEmu. Do those instructions apply to Red Squirrel as well?
I see there's a DISK370 directory under HostFS, and that's the one used for a RISC PC emulation. Unzip the files into there, then inside Red Squirrel you should see the BASIC and BASIC64 files.
rs.png
Edit: If you want these to be loaded when you start RS, create a !Boot file containing:

Code: Select all

RMLoad HostFS::HardDisk.$.BASIC
RMLoad HostFS::HardDisk.$.BASIC64
, and give it the right filetype with:

Code: Select all

*SetType !Boot Obey
ALso, I recall a while back I suggested you did *Configure NoBoot to avoid the not found error on start-up. You'll need to switch that back on, with *Configure Boot
Last edited by Soruk on Sat Jul 24, 2021 4:22 pm, edited 3 times in total.
Matrix Brandy BASIC VI (work in progress)
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Sat Jul 24, 2021 3:30 pm
In Brandy, however, it seems that the NEXT statement actually succeeds, and the LOCAL array survives, despite it having been dimensioned inside the loop! I have no idea how that is even possible: are LOCAL arrays not stored on the stack, or are there different stacks for LOCAL arrays and FOR loops, or what? :?
I think Brandy maintains a separate stack for FOR loops, likely outside of the general BASIC workspace. I'll take a closer look at the code in a bit.

Edit: Yep, it is a separate stack, in normal C workspace.
Matrix Brandy BASIC VI (work in progress)
User avatar
Richard Russell
Posts: 2500
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Richard Russell »

Soruk wrote:
Sat Jul 24, 2021 4:01 pm
I think Brandy maintains a separate stack for FOR loops, likely outside of the general BASIC workspace.
That's fascinating, in a way it harks back to the way 6502 BASIC worked, with separate stacks for FOR...NEXT and REPEAT...UNTIL (of course that limited the maximum nesting depth, which presumably it doesn't in Brandy). I wonder why that method was preferred over the more straightforward single-stack approach of ARM BASIC and all of mine, right back to the Z80 version.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Sat Jul 24, 2021 5:17 pm
Soruk wrote:
Sat Jul 24, 2021 4:01 pm
I think Brandy maintains a separate stack for FOR loops, likely outside of the general BASIC workspace.
That's fascinating, in a way it harks back to the way 6502 BASIC worked, with separate stacks for FOR...NEXT and REPEAT...UNTIL (of course that limited the maximum nesting depth, which presumably it doesn't in Brandy). I wonder why that method was preferred over the more straightforward single-stack approach of ARM BASIC and all of mine, right back to the Z80 version.
With the available memory on modern systems, and having the facilities of a high-level language, it is actually more straightforward to have a separate stack for FOR loops, maintained as a (list of) C structures, and managed in the "normal" C fashion outside of the BASIC workspace.
Matrix Brandy BASIC VI (work in progress)
User avatar
Richard Russell
Posts: 2500
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Richard Russell »

Soruk wrote:
Sat Jul 24, 2021 6:57 pm
it is actually more straightforward to have a separate stack for FOR loops, maintained as a (list of) C structures, and managed in the "normal" C fashion outside of the BASIC workspace.
Hmm, experimentally that's not how Brandy is behaving:

Code: Select all

   10 HIMEM = PAGE + 1000000
   20 FOR I% = 1 TO 10
   30   nest% += 1
   40   GOTO 20
This fails with 'Arithmetic stack overflowed' after about 20,000 iterations, whereas:

Code: Select all

   10 HIMEM = PAGE + 10000000
   20 FOR I% = 1 TO 10
   30   nest% += 1
   40   GOTO 20
fails after about 200,000 iterations. So the number of iterations is seemingly related to the value of HIMEM, which is not what I would expect from your description of the FOR stack being "outside of the BASIC workspace". What's more, you can actually monitor the increasing use of stack:

Code: Select all

   10 HIMEM = PAGE + 10000000
   20 FOR I% = 1 TO 10
   25   PROC1
   30   nest% += 1
   40   GOTO 20
   50 DEF PROC1
   60 DIM S% LOCAL -1
   70 PRINT S%
   80 ENDPROC
I'm not too sure what to make of this.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Sat Jul 24, 2021 7:59 pm
What's more, you can actually monitor the increasing use of stack:

Code: Select all

   10 HIMEM = PAGE + 10000000
   20 FOR I% = 1 TO 10
   25   PROC1
   30   nest% += 1
   40   GOTO 20
   50 DEF PROC1
   60 DIM S% LOCAL -1
   70 PRINT S%
   80 ENDPROC
I'm not too sure what to make of this.
Me neither 🤷🏻‍♂️ I am still learning about the intricacies of the code that Dave Daniels wrote. There is certainly some clever stuff going on, and certainly a cursory glance of the C code in exec_for() seemed to indicate that it was just a normal C list. I am definitely missing something there...
Matrix Brandy BASIC VI (work in progress)
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

As a result of a chat with Cameron last night on the Stardot zoom call, he has very kindly put together the makefile and a few changes needed to build Matrix Brandy for RISC OS via the gccsdk cross-compiler (so a build now takes seconds instead of about 15 minutes!). Several advantages to this, the resulting binary is MUCH smaller, it links against SharedCLibrary (rather than SharedUnixLibrary) and the binary runs on any RISC OS 3+ machine (min 4MB RAM), all the way from the Archimedes range up to and including the Raspberry Pi.

DO NOT compile with -Os, it looks like a compiler bug causing an undefined instruction crash when you use DIM.
Last edited by Soruk on Fri Sep 17, 2021 9:37 pm, edited 1 time in total.
Matrix Brandy BASIC VI (work in progress)
User avatar
BigEd
Posts: 4405
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by BigEd »

Excellent result!
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

As I play a bit more with this RISC OS build, one issue has come to light - networking isn't working (it doesn't compile if -DNONET isn't specified), and a SharedUnixLibrary build isn't 26/32-bit neutral, even when built with this cross compiler. The proper fix is to add TCP/IP networking code in SharedCLibrary style instead of Unix-style, but so far I can't find any documentation on this.
Matrix Brandy BASIC VI (work in progress)
ccawley2011
Posts: 9
Joined: Wed Oct 28, 2020 6:06 pm
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by ccawley2011 »

I've taken a quick look at Brandy's network code, and as far as I can tell, the call to fcntl can be replaced with a call to ioctl, like the Windows version. For inet_addr meanwhile, the function does seem to be available in both TCPIPLibs (as used by Norcroft) and UnixLib, but not GCC's Shared C Library implementation. It might be worth emailing the GCCSDK mailing list about it, since it might be possible for it to be added.
User avatar
Richard Russell
Posts: 2500
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Richard Russell »

ccawley2011 wrote:
Sun Sep 19, 2021 11:18 pm
It might be worth emailing the GCCSDK mailing list about it, since it might be possible for it to be added.
inet_addr is deprecated, not least because "255.255.255.255" returns -1 which is also the value returned on an error; I don't think there's any chance of it being added. inet_aton is preferred, so I'd suggest checking whether that is available on all the platforms.

Failing that, parsing the dot-notation string yourself is hardly rocket science.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Sun Sep 19, 2021 11:36 pm
ccawley2011 wrote:
Sun Sep 19, 2021 11:18 pm
It might be worth emailing the GCCSDK mailing list about it, since it might be possible for it to be added.
inet_addr is deprecated, not least because "255.255.255.255" returns -1 which is also the value returned on an error; I don't think there's any chance of it being added. inet_aton is preferred, so I'd suggest checking whether that is available on all the platforms.

Failing that, parsing the dot-notation string yourself is hardly rocket science.
I've adjusted the code to use inet_aton() and this works for a UnixLib build, but the function also doesn't appear to be present in the SharedCLibrary build. (In the meantime, I've been through the build warnings, and it now builds cleanly for a UnixLib build with the cross-compiler.)

I'm beginning to wonder if, for a RISC OS target, I should instead be using the SWI calls (if I can find the docs to work with them) instead of UNIX-style calls.

Another thing I found is, for a SharedCLibrary build, all memory allocations fit in the WimpSlot of the application, whereas for a UnixLib build, if I malloc() a sizeable block of memory it is allocated as a dynamic area, which allows me to allocate a block bigger than about 28M (including DIM HIMEM to allocate an array outside of the WimpSlot space) - which could be useful on RPi targets where there is typically 512M-1G memory available.

I'm starting to think perhaps I should either continue with two builds, the 26-bit clean version that has no networking, but works on older Archimedes hardware, and an all-bells-and-whistles version that works on RiscPC and later, or just discontinue any builds for the 26-bit kit.
Matrix Brandy BASIC VI (work in progress)
User avatar
Richard Russell
Posts: 2500
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Richard Russell »

I've just noticed that Matrix Brandy shares a 'bug' that BBC BASIC for Windows also has: it accepts a space between RND and the opening parenthesis of a parameter. So this prints one number when it should print two:

Code: Select all

      PRINT RND (6)
I don't feel able to fix this in BB4W because of the risk that existing programs could stop working, but you might feel differently about Matrix Brandy. Neither 6502 nor ARM BBC BASIC accepts a space, and the RISC OS documentation explicitly states: "Note that there should be no space before the opening bracket".
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
User avatar
SKS1
Posts: 40
Joined: Sat Sep 19, 2020 12:04 am
Location: Highland Perthshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by SKS1 »

Soruk wrote:
Mon Sep 20, 2021 11:49 am
Another thing I found is, for a SharedCLibrary build, all memory allocations fit in the WimpSlot of the application, whereas for a UnixLib build, if I malloc() a sizeable block of memory it is allocated as a dynamic area, which allows me to allocate a block bigger than about 28M (including DIM HIMEM to allocate an array outside of the WimpSlot space) - which could be useful on RPi targets where there is typically 512M-1G memory available.
Note that the WimpSlot of applications will happily keep extending beyond 28MB on RISC OS 5 systems (up to about 512MB in current builds, up to 1.75GB if you spin a custom ROM: https://riscosopen.org/forum/forums/11/ ... sts-123661)
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

SKS1 wrote:
Thu Oct 07, 2021 11:37 pm
Soruk wrote:
Mon Sep 20, 2021 11:49 am
Another thing I found is, for a SharedCLibrary build, all memory allocations fit in the WimpSlot of the application, whereas for a UnixLib build, if I malloc() a sizeable block of memory it is allocated as a dynamic area, which allows me to allocate a block bigger than about 28M (including DIM HIMEM to allocate an array outside of the WimpSlot space) - which could be useful on RPi targets where there is typically 512M-1G memory available.
Note that the WimpSlot of applications will happily keep extending beyond 28MB on RISC OS 5 systems (up to about 512MB in current builds, up to 1.75GB if you spin a custom ROM: https://riscosopen.org/forum/forums/11/ ... sts-123661)
Thank you for this - I see testing on RISC OS 5 in RPCEmu this does indeed work, but in RISC OS 3.71 I got the above result. However, freeing it doesn't shrink the WimpSlot back down. There remains the other hiccup that the networking calls fail to compile for a CLib build. CLib has the advantage of far smaller binaries, but the UnixLib build has the advantages of working networking and the availability of Dynamic Areas, allowing large allocations even on RISC OS 3.71 thus allowing large (numeric) arrays or memory blocks that are impossible in ARM BBC BASIC on this platform even with the latest builds from RISC OS Open's !System updates.
Matrix Brandy BASIC VI (work in progress)
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Thu Oct 07, 2021 10:50 pm
I've just noticed that Matrix Brandy shares a 'bug' that BBC BASIC for Windows also has: it accepts a space between RND and the opening parenthesis of a parameter. So this prints one number when it should print two:

Code: Select all

      PRINT RND (6)
I don't feel able to fix this in BB4W because of the risk that existing programs could stop working, but you might feel differently about Matrix Brandy. Neither 6502 nor ARM BBC BASIC accepts a space, and the RISC OS documentation explicitly states: "Note that there should be no space before the opening bracket".
In fn_rnd() there is no code for skipping over spaces, indeed it checks if the next character is a '(' so I suspect the space, if supplied, is being removed by the tokeniser.
Matrix Brandy BASIC VI (work in progress)
User avatar
Richard Russell
Posts: 2500
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Richard Russell »

Soruk wrote:
Fri Oct 08, 2021 9:25 am
In fn_rnd() there is no code for skipping over spaces, indeed it checks if the next character is a '(' so I suspect the space, if supplied, is being removed by the tokeniser.
I wouldn't know about the internal mechanism, only that the end result is that it accepts a space when it shouldn't! It doesn't worry me unduly, since BB4W does the same, but I thought you should be aware.

It's only in a PRINT statement that adding a space results in a legal program in both Sophie's BASICs and yours, but which behave differently. Otherwise adding a space results in an error in 6502 and ARM BASICs.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Fri Oct 08, 2021 9:38 am
Soruk wrote:
Fri Oct 08, 2021 9:25 am
In fn_rnd() there is no code for skipping over spaces, indeed it checks if the next character is a '(' so I suspect the space, if supplied, is being removed by the tokeniser.
I wouldn't know about the internal mechanism, only that the end result is that it accepts a space when it shouldn't! It doesn't worry me unduly, since BB4W does the same, but I thought you should be aware.

It's only in a PRINT statement that adding a space results in a legal program in both Sophie's BASICs and yours, but which behave differently. Otherwise adding a space results in an error in 6502 and ARM BASICs.
OKay. This has been fixed, by pulling the same trick I used to implement SYS() by creating a new token for RND( and putting it in front of RND so it'll try to match that first. There is no compatibility issue with this, as Matrix Brandy always saves files in plain text, and tokens are only used internally.
Matrix Brandy BASIC VI (work in progress)
User avatar
Richard Russell
Posts: 2500
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Richard Russell »

Not sure if I'm missing something obvious here, but Matrix Brandy doesn't seem to be respecting the VDU 23,16... cursor movement direction when printing in VDU 5 mode:

Code: Select all

   10 MODE 0
   20 VDU 23,16,2|
   30 VDU 5,30
   40 PRINT "Hello world!";
I expected this to print "!dlrow olleH" in the top-right corner of the window, and it does in ARM BASIC V, BB4W and BBCSDL. But in Matrix Brandy (latest Windows nightly) it appears to be behaving as if the VDU 23,16,2| wasn't there at all!
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.
Soruk
Posts: 947
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for console and SDL1.2: V1.22.11 released

Post by Soruk »

Richard Russell wrote:
Wed Oct 13, 2021 6:06 pm
Not sure if I'm missing something obvious here, but Matrix Brandy doesn't seem to be respecting the VDU 23,16... cursor movement direction when printing in VDU 5 mode:

Code: Select all

   10 MODE 0
   20 VDU 23,16,2|
   30 VDU 5,30
   40 PRINT "Hello world!";
I expected this to print "!dlrow olleH" in the top-right corner of the window, and it does in ARM BASIC V, BB4W and BBCSDL. But in Matrix Brandy (latest Windows nightly) it appears to be behaving as if the VDU 23,16,2| wasn't there at all!
Good spot, thank you. When I implemented it way back when, I was only working (and testing) in VDU4 mode. Testing locally, confirmed that my implementation is somewhat deficient, so yep, something else to implement....

Edit: Done.
Not implemented (nor for VDU4 mode), where X moves in the Y direction and Y moves in the X direction (bit 3 is ignored).
Matrix Brandy BASIC VI (work in progress)
Post Reply

Return to “modern implementations of classic programming languages”