Matrix Brandy BASIC VI for Linux with SDL: V1.22.3 released

discuss PC<>Acorn file transfer issues & the use of FDC, XFER, Omniflop/disk etc.
Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Soruk » Mon Jul 08, 2019 9:42 am

Actually (and admittedly counter-intuitively), you MUST NOT (unless you're running the latest git commit as of 11:11 UK time) put quotes around the file name even if there are spaces, as the entirety of the rest of the line is treated as the file name. If you provide quotes they will be treated as part of the file name!

(Though, yes, that is a bit daft - I've just added a commit to git that will strip quotes if the first and last characters of the filename are quote marks. They remain optional even if a space appears in the name.)

Code: Select all

OSCLI "ScreenSave "+filename$
will do exactly what you want. Just remember it will save a BMP file regardless of the extension provided.

Unlike RISC OS, MODE 7 screens can be saved, and any Teletext FLASH item is saved in the visible phase (not hidden).

Edited: pushed a git commit to deal with quote marks in the file name
Last edited by Soruk on Mon Jul 08, 2019 10:14 am, edited 4 times in total.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Soruk » Mon Jul 08, 2019 11:42 am

Hi,

I've just put together version 1.21.20. A number of updates and bug fixes have been wrapped up in this, including:
- Centisecond timer polling hived off to its own thread, as polling it every command iteration for ESCAPE checking was expensive.
- Program execution now much faster than before, and slightly faster again when ESCAPE is disabled via *FX200.
- Renamed some #DEFINEs as they were colliding on a new gcc on Cygwin.
- ESCAPE on VDU14 paged mode now works.
- INKEY no longer swallows a non-matching keypress.
- Some more OS SWIs implemented (the Snow demo from RISC OS Pico for RasPi now runs unmodified).
- Optionally allow an unselectable MODE to be substituted with another one instead of reporting "Screen moe is not available".
- Some more Raspberry Pi GPIO stuff, including recognising most RISC OS GPIO module SWI names, and implementing a few.
- Unsupported colour depths are mapped to 24-bit (previously was 8-bit), so a program asking for a 15-bit mode will be able to draw colours as largely intended.
- Extended OSBYTE 42 to allow an immediate refresh - SYS6,42,16 may be faster than parsing "*REFRESH" for anything time-critical (and obvious functionality that was missing from the interface)
- Quotes are stripped if appropriate from *ScreenSave and *ScreenLoad. They remain optional for filenames which include spaces.

Release is in all the usual places and in git.

scruss
Posts: 155
Joined: Sun Jul 01, 2018 3:12 pm
Location: Toronto
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.12 released

Post by scruss » Mon Jul 08, 2019 2:22 pm

Richard Russell wrote:
Mon Jul 08, 2019 8:12 am
OSCLI is the way to pass variables to 'star' commands::

Code: Select all

      OSCLI "ScreenSave " + bmpfile$
Indeed it is! Thank you. I now have all the screenshots I want, instead of just one last file called bmpfile$

Oh, and huge thanks to Soruk for maintaining and extending this. It's a stable, fast, cross-platform interpreter.
Last edited by scruss on Mon Jul 08, 2019 2:25 pm, edited 1 time in total.

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Richard Russell » Mon Jul 08, 2019 3:02 pm

Soruk wrote:
Mon Jul 08, 2019 9:42 am
Actually (and admittedly counter-intuitively), you MUST NOT (unless you're running the latest git commit as of 11:11 UK time) put quotes around the file name even if there are spaces, as the entirety of the rest of the line is treated as the file name.
Presumably when the command takes (possibly optional) parameters after the filename quotes are required. Otherwise it's ambiguous as to whether what follows are parameters or part of the filename. That is the case for *SCREENSAVE in BB4W and BBCSDL (which can take the position and size of the graphics region to save) and for commands like *LOAD and *SAVE (which take the address and length of transferred memory). Or does Matrix Brandy by chance have no such commands?

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Soruk » Mon Jul 08, 2019 4:29 pm

Richard Russell wrote:
Mon Jul 08, 2019 3:02 pm
Soruk wrote:
Mon Jul 08, 2019 9:42 am
Actually (and admittedly counter-intuitively), you MUST NOT (unless you're running the latest git commit as of 11:11 UK time) put quotes around the file name even if there are spaces, as the entirety of the rest of the line is treated as the file name.
Presumably when the command takes (possibly optional) parameters after the filename quotes are required. Otherwise it's ambiguous as to whether what follows are parameters or part of the filename. That is the case for *SCREENSAVE in BB4W and BBCSDL (which can take the position and size of the graphics region to save) and for commands like *LOAD and *SAVE (which take the address and length of transferred memory). Or does Matrix Brandy by chance have no such commands?
No such options, it's strictly *Screensave <filename> - SDL 1.2 just saves the entire surface area as a BMP - https://www.libsdl.org/release/SDL-1.2. ... vebmp.html
It might be possible in future to do that, by creating a new surface, copying the area to be saved then dumping that.

*LOAD and *SAVE are not supported, at this point in time.
Last edited by Soruk on Mon Jul 08, 2019 4:30 pm, edited 2 times in total.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.12 released

Post by Soruk » Mon Jul 08, 2019 4:41 pm

scruss wrote:
Mon Jul 08, 2019 2:22 pm
Richard Russell wrote:
Mon Jul 08, 2019 8:12 am
OSCLI is the way to pass variables to 'star' commands::

Code: Select all

      OSCLI "ScreenSave " + bmpfile$
Indeed it is! Thank you. I now have all the screenshots I want, instead of just one last file called bmpfile$

Oh, and huge thanks to Soruk for maintaining and extending this. It's a stable, fast, cross-platform interpreter.
I'm glad you're enjoying using it. For me, it has been, and continues to be, a rather nice itch to scratch :D

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Richard Russell » Mon Jul 08, 2019 4:46 pm

Soruk wrote:
Mon Jul 08, 2019 4:29 pm
*LOAD and *SAVE are not supported, at this point in time.
Well, OK, but surely the point remains valid. In principle there could be, and probably at some stage will be, 'star' commands that take a filename followed by parameters; this is a common pattern on most other BBC BASIC platforms. Similarly commands that take two filenames, like *COPY and *RENAME (or whatever the Brandy equivalents are); a similar ambiguity arises in that case if the first path/filename contains spaces. I would have expected that quotes would always be allowed, even when not essential, just as they are at the Linux and Windows command prompts.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Soruk » Mon Jul 08, 2019 11:47 pm

Richard Russell wrote:
Mon Jul 08, 2019 4:46 pm
Soruk wrote:
Mon Jul 08, 2019 4:29 pm
*LOAD and *SAVE are not supported, at this point in time.
Well, OK, but surely the point remains valid. In principle there could be, and probably at some stage will be, 'star' commands that take a filename followed by parameters; this is a common pattern on most other BBC BASIC platforms. Similarly commands that take two filenames, like *COPY and *RENAME (or whatever the Brandy equivalents are); a similar ambiguity arises in that case if the first path/filename contains spaces. I would have expected that quotes would always be allowed, even when not essential, just as they are at the Linux and Windows command prompts.
As of this morning's commit, quotes are allowed. The filename extraction is specific to *screensave and *screenload, which reminds me, I need to check *exec.

For any built-in *-commands that would require parameters after the filename (of which at the moment there are none) of course filename handling would need to be more exacting.

*Copy doesn't exist as such, under Windows it would, in Linux you'd use *cp as unrecognised *-commands are passed to the host OS shell.

User avatar
jgharston
Posts: 3742
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by jgharston » Mon Jul 08, 2019 11:53 pm

It's something I put in my notes to write a proper command parser. Last time I was working on the code (when I was in Japan last November!) the dispatcher was loads of if (strcmp(.... I rewrote the GSRead parser to get KEY and SHOW working properly because I was working on the keyboard handler which needed setting and reading soft keys working correctly.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Soruk » Tue Jul 09, 2019 10:37 am

Soruk wrote:
Mon Jul 08, 2019 11:47 pm
As of this morning's commit, quotes are allowed. The filename extraction is specific to *screensave and *screenload, which reminds me, I need to check *exec.
Yep, *exec needed fixing too. Updated in git.

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Richard Russell » Tue Jul 09, 2019 10:51 am

Soruk wrote:
Tue Jul 09, 2019 10:37 am
Yep, *exec needed fixing too. Updated in git.
*SPOOL, *SPOOLON ?

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Soruk » Tue Jul 09, 2019 12:58 pm

Richard Russell wrote:
Tue Jul 09, 2019 10:51 am
Soruk wrote:
Tue Jul 09, 2019 10:37 am
Yep, *exec needed fixing too. Updated in git.
*SPOOL, *SPOOLON ?
Not (yet) implemented.*EXEC didn't exist in Matrix Brandy until a few months ago!

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Richard Russell » Tue Jul 09, 2019 2:22 pm

Soruk wrote:
Tue Jul 09, 2019 12:58 pm
Not (yet) implemented.*EXEC didn't exist in Matrix Brandy until a few months ago!
Oh. I've always considered *SPOOL and *EXEC to be a related pair (it's not uncommon to *EXEC a file you previously created using *SPOOL) so I hadn't anticipated that one would be implemented without the other.

scruss
Posts: 155
Joined: Sun Jul 01, 2018 3:12 pm
Location: Toronto
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by scruss » Tue Jul 09, 2019 3:27 pm

Then again, with Brandy already loading text files rather than tokenized files via LOAD, *EXEC wouldn't really be a priority

User avatar
dhg2
Posts: 145
Joined: Tue Oct 25, 2016 7:37 pm
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by dhg2 » Tue Jul 09, 2019 6:22 pm

Maybe so, but don't forget that *EXEC is useful for stuff like pre-filling the INPUT buffer.
Regards,
- Patrick

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Soruk » Tue Jul 09, 2019 7:51 pm

scruss wrote:
Tue Jul 09, 2019 3:27 pm
Then again, with Brandy already loading text files rather than tokenized files via LOAD, *EXEC wouldn't really be a priority
Brandy can load both tokenised (Acorn and BB4W/BBCSDL) files, but only saves as plain-text.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.20 released

Post by Soruk » Wed Jul 10, 2019 5:19 am

Richard Russell wrote:
Tue Jul 09, 2019 2:22 pm
Soruk wrote:
Tue Jul 09, 2019 12:58 pm
Not (yet) implemented.*EXEC didn't exist in Matrix Brandy until a few months ago!
Oh. I've always considered *SPOOL and *EXEC to be a related pair (it's not uncommon to *EXEC a file you previously created using *SPOOL) so I hadn't anticipated that one would be implemented without the other.
Operative word above being "yet" - we now have them. I've also forced a rebuild of the nightly.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Soruk » Tue Jul 16, 2019 4:53 pm

Bug fix posted: INT was accepting out-of-range values. It now reports an out-of-range error (as per BBC Micro and RISC OS).

Edit (19th July 2019): I've added a run-time switch (SYS "Brandy_INTusesFloat",<0|1>) that enables INT to handle out-of-range values - and unlike previously, the values aren't mangled into a 32-bit int.
Last edited by Soruk on Fri Jul 19, 2019 1:04 pm, edited 1 time in total.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Soruk » Thu Jul 18, 2019 12:56 pm

Not directly related to the above fix, I spotted this:

Code: Select all

>PRINT 2*1024*1024*1024

Number is out of range
>PRINT 2147483647+2147483647
        -2
>_
Obviously, that isn't right. And, I get the same results in Brandy 1.20.1 so it's not due to my modifications!
So, for simple additions, subtractions and multiplications, I'm promoting the LHS value to a float prior to performing any operations on them, so now we get the right answer.
I don't know how 6502 or ARM BBC BASIC, nor BBCSDL does it under the lid, however the above examples really shouldn't happen. I get the correct answers in RISC OS 3.71 (RPCEmu) and BBC BASIC 4 (BBC Master under emulation).
Edit: To clarify, I do NOT get these problems on any of the Acorn BASICs I've tested it on.
Edit 2: Richard Russell pointed out that Acorn's 8-bit BASICs, and I confirmed also RISC OS with the exception of BASIC VI, does this:

Code: Select all

>PRINT -2147483647 - 2147483647
         2
>_
which is arguably very wrong.
Matrix Brandy and ARM BBC BASIC VI give the result as -4294967294.
Last edited by Soruk on Sat Jul 20, 2019 9:47 am, edited 2 times in total.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Soruk » Fri Jul 19, 2019 7:29 pm

BASIC V or BASIC VI?

Having recently been taking a much closer look at the number handling, it's long been established that Brandy (and thus Matrix Brandy) use 64-bit floating-point maths, whereas RISC OS BASIC V (and all BBC Micro BASICs) use 40-bit floating-point maths. BASIC VI, which shipped with RISC OS 3 initially, introduced 64-bit floating-point mathematics. From what I can gather, this is the only difference between BASIC V and BASIC VI.

So. Should I leave Matrix Brandy tagged as BASIC V, or re-tag it to BASIC VI as it's actually much closer to BASIC VI in mathematical functionality? Personally, I'm inclined to re-tag it. With the above INT handling fixes, the behaviour now also more closely matches BASIC VI than BASIC V.

I'm very much open to opinions on this.
Last edited by Soruk on Sat Jul 20, 2019 9:41 am, edited 2 times in total.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Soruk » Mon Jul 22, 2019 9:28 am

dhg2 wrote:
Thu Aug 30, 2018 8:30 pm
Text mode Brandy is fantastic, I love it. From now on, whenever I need to write some simple shell scripts, I'll probably use Brandy.

I'd like to request a feature: the AUTO statement/editing feature. I often used AUTO to write simple programs at the prompt on my BBC Micro, and also in RISC OS, and miss the feature when I'm using Brandy.
It's not essential of course, but I find that it's nice to have.
It's been a long time coming, but I've just checked in a commit that implements AUTO.

Edit: And another checkin that gives HELP on commands.
Last edited by Soruk on Mon Jul 22, 2019 6:08 pm, edited 1 time in total.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Tue Jul 23, 2019 11:38 am

Hi,

I've just released Matrix Brandy BASIC VI version 1.22.0.
Changes from 1.21.21 include:
- Change identifier to BASIC VI (which is BASIC V with 64-bit FP maths, this is what Brandy has always done)
- *SPOOL and *SPOOLON implemented.
- Fix integer overflows when converting from floats.
- Fix intermittent crash when execution hits a DEF statement.
- Added a run-time switchable setting for INT() whether it can process numbers out of range of a 32-bit int data type. Default is off.
- Implement the AUTO command.
- Implemented HELP for BASIC keywords.

This release is available in the usual places, from the Matrix Brandy website and Github.

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Richard Russell » Tue Jul 23, 2019 7:26 pm

Soruk wrote:
Fri Jul 19, 2019 7:29 pm
Should I leave Matrix Brandy tagged as BASIC V, or re-tag it to BASIC VI as it's actually much closer to BASIC VI in mathematical functionality?
I have mixed feelings about this. Over the years I've come across a number of BBC BASIC programs which rely on the 'integer wrapping' behaviour of all of Acorn's versions up to ARM BASIC V, in other words when adding or subtracting integers you won't get a 'Number too big' error but instead the result will wrap around, modulo 32-bits. If I have understood you correctly, with your recent change such programs will no longer work in Matrix Brandy and therefore a longstanding compatibility between Brandy and BASIC V has been sacrificed. I'm surprised that you seem so relaxed about that.

On the other hand my versions of BBC BASIC have never worked that way, so your change has not only made Matrix Brandy more like ARM BASIC VI (BASIC64) but more like my BASICs too! The 'wrapping' behaviour has always worried me because it can happen 'silently' part way through evaluating a complicated expression, and give rise to an entirely 'incorrect' result without receiving any warning. That Acorn modified it in BASIC VI may suggest they felt the same.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Soruk » Tue Jul 23, 2019 8:13 pm

Richard Russell wrote:
Tue Jul 23, 2019 7:26 pm
Soruk wrote:
Fri Jul 19, 2019 7:29 pm
Should I leave Matrix Brandy tagged as BASIC V, or re-tag it to BASIC VI as it's actually much closer to BASIC VI in mathematical functionality?
I have mixed feelings about this. Over the years I've come across a number of BBC BASIC programs which rely on the 'integer wrapping' behaviour of all of Acorn's versions up to ARM BASIC V, in other words when adding or subtracting integers you won't get a 'Number too big' error but instead the result will wrap around, modulo 32-bits. If I have understood you correctly, with your recent change such programs will no longer work in Matrix Brandy and therefore a longstanding compatibility between Brandy and BASIC V has been sacrificed. I'm surprised that you seem so relaxed about that.

On the other hand my versions of BBC BASIC have never worked that way, so your change has not only made Matrix Brandy more like ARM BASIC VI (BASIC64) but more like my BASICs too! The 'wrapping' behaviour has always worried me because it can happen 'silently' part way through evaluating a complicated expression, and give rise to an entirely 'incorrect' result without receiving any warning. That Acorn modified it in BASIC VI may suggest they felt the same.
That's a very good point, and one I really hadn't thought about, though I personally haven't seen that "feature" exploited. I could make it switchable leaving the BASIC VI behaviour the default. I'll switch it separately to the INTusesFloat switch as BASIC64 still complains trying to INT() outside the range of a 32-bit integer.

Edit: Just checked in a commit which implements

Code: Select all

SYS "Brandy_LegacyIntMaths",<0|1>
which allows old behaviour for anything that needs it.

Assuming I haven't mucked something up for Cygwin, it'll be in tonight's automated nightly build for Windows.
Last edited by Soruk on Tue Jul 23, 2019 9:12 pm, edited 2 times in total.

Phlamethrower
Posts: 112
Joined: Fri Nov 24, 2017 1:35 pm
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Phlamethrower » Tue Jul 23, 2019 9:29 pm

Richard Russell wrote:
Tue Jul 23, 2019 7:26 pm
That Acorn modified it in BASIC VI may suggest they felt the same.
I don't think it was a conscious choice to modify the behaviour. It's all down to whether the expression parser decides to classify the number as being integer or floating point (and thus whether the subtraction is integer or floating point). BASIC V & VI have different number parsing code, and they behave differently when given certain inputs.

Code: Select all

>A%=-2147483647
>B%=2147483647
>PRINT A%-B%
         2
>A=-2147483647
>B=2147483647
>PRINT A-B
-4.29496729E9
Same result for RISC OS BASIC V & VI.

A brief look at the number parsing code suggests that BASIC V will prefer to parse a number as an integer whenever possible (although I think decimal points or exponents will force it to float), whereas BASIC VI will initially try parsing as an integer, and then fall back to floating point if the number looks like it's in danger of becoming too large (+/-&CC00000 is the magic threshold), or if it sees a decimal point or exponent.

Hex and binary numbers are always parsed as integer types.
Last edited by Phlamethrower on Tue Jul 23, 2019 9:34 pm, edited 1 time in total.

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC V for Linux with SDL: V1.21.21 released

Post by Richard Russell » Tue Jul 23, 2019 9:52 pm

Phlamethrower wrote:
Tue Jul 23, 2019 9:29 pm
I don't think it was a conscious choice to modify the behaviour... BASIC V & VI have different number parsing code, and they behave differently
I'm a little puzzled as to how you think the difference came about if it wasn't a "conscious choice". Wouldn't the minimum-effort solution have been to leave the parsing code substantially unchanged when updating from 40-bit to 64-bit floats, or was that impossible for some reason'? If such a significant and incompatible change happened 'by accident' I would be rather concerned!

Phlamethrower
Posts: 112
Joined: Fri Nov 24, 2017 1:35 pm
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Phlamethrower » Wed Jul 24, 2019 12:02 am

OK, let me rephrase: It was a conscious choice to change the code, but it wasn't intended for it to change the arithmetic behaviour.
Richard Russell wrote:
Tue Jul 23, 2019 9:52 pm
Wouldn't the minimum-effort solution have been to leave the parsing code substantially unchanged when updating from 40-bit to 64-bit floats, or was that impossible for some reason'?
The overall structure of the parsers was the same. But the code itself was almost completely different, because the BASIC V version used 40-byte float registers & arithmetic routines, while the BASIC VI version used FPU registers & FPU arithmetic instructions. So at some point during the code conversion process the &CC00000 threshold was added, and the logic for coercing the number into an integer was removed.

("was", past-tense, since a couple of years ago I did rewrite the BASIC VI number parsing in order to make something that works better for the VFP version of the module. But the suspicious &CC00000 threshold from the original code is still there.)
If such a significant and incompatible change happened 'by accident' I would be rather concerned!
I get the impression that BASIC VI didn't receive much testing. There were significant differences in how numbers were formatted when being displayed, and I'm fairly certain that rotated ellipses were broken on initial release (and only fixed 25 years later!)
Last edited by Phlamethrower on Wed Jul 24, 2019 12:05 am, edited 1 time in total.

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Wed Jul 24, 2019 10:13 am

Phlamethrower wrote:
Wed Jul 24, 2019 12:02 am
So at some point during the code conversion process the &CC00000 threshold was added, and the logic for coercing the number into an integer was removed.
Can you explain how this threshold works? I don't know about Brandy but there's nothing similar in my BASICs: I allow an integer overflow to occur (trivially detected using the CPU's overflow flag, in assembly language) and deal with it afterwards, so there's no need to 'predict' it.

Soruk
Posts: 468
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Wed Jul 24, 2019 11:12 am

More playing around with integers, I found this one in the legacy code:

Code: Select all

>SYS "Brandy_LegacyIntMaths",1
>PRINT 1073741824 * 2

Number is out of range
>_
This is reproducible in the upstream Brandy 1.20.1 - but is not reproducible in Acorn's BASICs 2 or 4 on 8-bit (I don't have BASIC 1), nor BASIC V or VI on RISC OS. Thus, I consider this a Brandy bug. Thus, the new code I added for integer multiplication to switch to floats is now used in all cases, and now NOT affected by the LegacyIntMaths switch (as legacy mode is for Acorn BASICs other than VI).

User avatar
Richard Russell
Posts: 953
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Wed Jul 24, 2019 12:01 pm

Soruk wrote:
Wed Jul 24, 2019 11:12 am
Thus, the new code I added for integer multiplication to switch to floats is now used in all cases
You may prefer not to use GCC builtins in Matrix Brandy, although they are widely supported, but for the record there's __builtin_smul_overflow which will multiply two signed 32-bit numbers together and tell you whether there was an overflow. The compiler will "attempt to use hardware instructions to implement" where possible, like conditional jump on overflow etc.

Post Reply