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: 2465
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: 942
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: 942
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: 2465
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: 942
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: 2465
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: 942
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: 942
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: 4351
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: 942
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)
Post Reply

Return to “modern implementations of classic programming languages”