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

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

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

Post by Richard Russell » Tue Oct 15, 2019 5:24 pm

dhg2 wrote:
Tue Oct 15, 2019 5:10 pm
I notice that if you try to draw text at the location of the graphics cursor (with VDU 5 and then PRINT), and if the current graphics colour is black, no text is drawn.
How very strange. Here's what BBC BASIC for SDL 2.0 produces:

blacktextwhitesurround.png

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Tue Oct 15, 2019 5:39 pm

dhg2 wrote:
Tue Oct 15, 2019 5:10 pm
Hello,
I notice that if you try to draw text at the location of the graphics cursor (with VDU 5 and then PRINT), and if the current graphics colour is black, no text is drawn.
Good spot. Yup, need to fix that.

Edit: The reason this is happening is, that it's building the character cell, blitting transparently, using 0 as transparent. If I try to use the top bit, the blit strips out the entire top byte, which breaks VDU19. I think I need to forego the character cell and pixel-twiddle directly on the screen memory.

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Wed Oct 16, 2019 10:33 am

dhg2 wrote:
Tue Oct 15, 2019 5:10 pm
Hello,
I notice that if you try to draw text at the location of the graphics cursor (with VDU 5 and then PRINT), and if the current graphics colour is black, no text is drawn.

Tested with this program:

Code: Select all

MODE 1
PROCtextdraw(100,100,"Matrix Brandy BBC BASIC")
END
DEF PROCtextdraw(x%,y%,s$)
LOCAL xx%,yy%
GCOL 0,3
VDU 5
FOR xx%=-1 TO 1
  MOVE x%+xx%*4,y%
  PRINT ;s$;
NEXT
FOR yy%=-1 TO 1
  MOVE x%,y%+yy%*4
  PRINT ;s$;
NEXT
GCOL 0,0
MOVE x%,y%
PRINT ;s$;
VDU 4
ENDPROC
This is now fixed - as I had surmised, I had to go to painting directly on the screen display, rather than using a transparent character cell and blitting it. This correctly preserves the top byte (ignored by SDL, but used as a disambiguator for VDU19 by holding the logical colour number).

User avatar
dhg2
Posts: 148
Joined: Tue Oct 25, 2016 8:37 pm
Contact:

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

Post by dhg2 » Wed Oct 16, 2019 1:17 pm

Thanks for looking into it.
Sorry to spam you, but, I notice now that there seems to be some trouble with stuff getting drawn outside of the graphics window.
Tested with this code:

Code: Select all

MODE 13
PROCgcol(0,0,0):RECTANGLE FILL 0,0,1280,1024
VDU 24, 100;100;400;400;
PROCgcol(0,0,128):RECTANGLE FILL 0,0,1280,1024
FOR I%=0 TO 64
  PROCgcol( RND(256)-1,RND(256)-1,RND(256)-1 )
  MOVE RND(1280),RND(1024):DRAW RND(1280),RND(1024)
  PROCtextdraw(RND(1280),RND(1024),"Wednesday")
NEXT
END
DEF PROCtextdraw(x%,y%,s$)
LOCAL xx%,yy%
VDU 5
FOR xx%=-1 TO 1
  MOVE x%+xx%*4,y%
  PRINT ;s$;
NEXT
FOR yy%=-1 TO 1
  MOVE x%,y%+yy%*4
  PRINT ;s$;
NEXT
PROCgcol( 0,0,0 )
MOVE x%,y%
PRINT ;s$;
VDU 4
ENDPROC

DEFPROCgcol(R%,G%,B%)
IF 0 THEN
  COLOUR 2, R%,G%,B%: GCOL 2
ELSE
  GCOL R%,G%,B%
ENDIF
ENDPROC
Results with BBCSDL, RPCemu, and Matrix Brandy:
2019-10-16-130719_960x768_scrot.png
2019-10-16-130813_640x512_scrot.png
2019-10-16-130924_640x512_scrot.png
Regards,
- Patrick

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Wed Oct 16, 2019 1:32 pm

dhg2 wrote:
Wed Oct 16, 2019 1:17 pm
Thanks for looking into it.
Sorry to spam you, but, I notice now that there seems to be some trouble with stuff getting drawn outside of the graphics window.
Tested with this code:

Code: Select all

MODE 13
PROCgcol(0,0,0):RECTANGLE FILL 0,0,1280,1024
VDU 24, 100;100;400;400;
PROCgcol(0,0,128):RECTANGLE FILL 0,0,1280,1024
FOR I%=0 TO 64
  PROCgcol( RND(256)-1,RND(256)-1,RND(256)-1 )
  MOVE RND(1280),RND(1024):DRAW RND(1280),RND(1024)
  PROCtextdraw(RND(1280),RND(1024),"Wednesday")
NEXT
END
DEF PROCtextdraw(x%,y%,s$)
LOCAL xx%,yy%
VDU 5
FOR xx%=-1 TO 1
  MOVE x%+xx%*4,y%
  PRINT ;s$;
NEXT
FOR yy%=-1 TO 1
  MOVE x%,y%+yy%*4
  PRINT ;s$;
NEXT
PROCgcol( 0,0,0 )
MOVE x%,y%
PRINT ;s$;
VDU 4
ENDPROC

DEFPROCgcol(R%,G%,B%)
IF 0 THEN
  COLOUR 2, R%,G%,B%: GCOL 2
ELSE
  GCOL R%,G%,B%
ENDIF
ENDPROC
Results with BBCSDL, RPCemu, and Matrix Brandy:
2019-10-16-130719_960x768_scrot.png
2019-10-16-130813_640x512_scrot.png
2019-10-16-130924_640x512_scrot.png
Argh.

The blitting honoured the graphics window. But now that I'm writing directly to the screen memory, that is no longer happening.

Edit: That should be sorted. Rather than poking the video memory, it's now using the plot_pixel graphics primitive to do this, which honours graphics clipping - and another omission from the previous code, it also honours GCOL action codes.

Edit 2: Filled rectangle now honours graphics window.
Last edited by Soruk on Wed Oct 16, 2019 2:23 pm, edited 1 time in total.

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

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

Post by Richard Russell » Wed Oct 16, 2019 1:52 pm

dhg2 wrote:
Wed Oct 16, 2019 1:17 pm
Tested with this code:
If you want to make the choice of GCOL style automatic, Jonathan Harston's recommended test for 'my' BASICs is this:

Code: Select all

DEFPROCgcol(R%,G%,B%)
IF (INKEY-256 AND &D0)=&50 THEN
  COLOUR 2, R%,G%,B%: GCOL 2
ELSE
  GCOL R%,G%,B%
ENDIF
ENDPROC

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Wed Oct 16, 2019 7:40 pm

dhg2 wrote:
Wed Oct 16, 2019 1:17 pm
Sorry to spam you
Nope, not spamming me. Real bug reports like these, especially with a test harness, are most welcome.

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Tue Nov 12, 2019 11:47 am

Over on the BBC BASIC forum (here), I inadvertently uncovered a bug in GOTO parameter handling in Brandy (this code is untouched from the upstream source).

Initially, from quick testing (GOTO x% and getting Syntax error) I came to the erroneous conclusion that Brandy didn't support variables as a parameter to GOTO (and GOSUB) unlike the BBC Micro or RISC OS. Looking at the source, it had been programmed to insist any non-literal had to be enclosed in parentheses to function correctly, else it would bomb out with Syntax error.

I've adjusted the code to remove that catch-all, and instead if a literal wasn't identified, to handle it as an expression. Quite nicely, it still errors when you do something like GOTO 30-10 - exactly the same on Acorn BBC BASICs, yet it handles GOTO x% correctly now. Parentheses round an expression are still accepted (so this change won't break old code), but are still required for an expression involving more than a simple variable (looking into this one as the Acorn BASICs don't require parentheses unless the expression starts with a number) - FIXED.

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Mon Nov 18, 2019 5:06 pm

Just for the sheer hell of it, I've implemented some basic graphics in the text-mode tbrandy client.

This is not enabled by default, and requires tbrandy to be run in an xterm window.
To enable, use: SYS "Brandy_TekEnabled",1
This SYS call is ignored with no error on other builds.

User avatar
dhg2
Posts: 148
Joined: Tue Oct 25, 2016 8:37 pm
Contact:

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

Post by dhg2 » Tue Nov 19, 2019 1:53 am

Interesting feature. Could you post some screenshots and code snippets demonstrating it?
Regards,
- Patrick

scruss
Posts: 213
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

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

Post by scruss » Tue Nov 19, 2019 3:55 am

Neat!

I made this by running tbrandy in an xterm, and entering:

Code: Select all

LOAD "examples/tekspiral"
SYS "Brandy_TekEnabled", 1
RUN
Screenshot from 2019-11-18 22-28-23.png
tekspiral from the Matrix Brandy examples folder
I also ran it through rricharz/Tek4010 for moar Tek goodness : https://www.youtube.com/watch?v=3Ew3O4xFp0Y

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Tue Nov 19, 2019 9:08 am

dhg2 wrote:
Tue Nov 19, 2019 1:53 am
Interesting feature. Could you post some screenshots and code snippets demonstrating it?
examples/graphdemo runs in both the SDL build and tbrandy (within an xterm).

The tekdemo1, tekdemo2 and tekspiral demos do not require this feature, as they use teklib which itself generates the Tektronics codes (and will thus work in all builds when called from an xterm). This new feature is built-in Tek graphics in the tbrandy text-mode client, requiring no outside libraries and supports the built-in BASIC graphics commands.

Edit: I've just checked in a couple of new demos, sine and spiral, which will use the normal graphics in the SDL build, and Tektronix graphics in tbrandy.
There's no path switching in the code, it just switches on TekEnabled then goes ahead with regular BASIC graphics commands.

The "teklib" demos pre-date Matrix Brandy, however my work on various parts broke the upstream teklib, so after implementing OSBYTE 43 (local to Brandy) that emits the byte to stdout in the calling terminal, I reworked teklib to use this interface so making it work once more. (This was done back in August last year.) I also added tekinit (in tbrandy as VDU5) and tekexit (VDU4) to programmatically switch between the VT and Tek windows, where previously the examples required you to manually select the Tek window from the xterm menu.

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

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

Post by Richard Russell » Wed Nov 20, 2019 2:33 pm

I've mentioned in other threads the invaluable (in my opinion) extension to BB4W and BBCSDL: RESTORE LOCAL; would you consider incorporating it in Matrix Brandy? In my BASICs it was almost trivial to implement, because it activates a mechanism that must already exist: restoring formal parameters and LOCAL variables etc. on exiting a procedure with ENDPROC or a function with =. I couldn't live without it now.

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Wed Nov 20, 2019 4:53 pm

Richard Russell wrote:
Wed Nov 20, 2019 2:33 pm
I've mentioned in other threads the invaluable (in my opinion) extension to BB4W and BBCSDL: RESTORE LOCAL; would you consider incorporating it in Matrix Brandy? In my BASICs it was almost trivial to implement, because it activates a mechanism that must already exist: restoring formal parameters and LOCAL variables etc. on exiting a procedure with ENDPROC or a function with =. I couldn't live without it now.
That's now implemented on git, it'll be in tonight's nightly build for Windows.

As you suggested, it was quite trivial to implement!

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

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

Post by Richard Russell » Wed Nov 20, 2019 5:05 pm

Soruk wrote:
Wed Nov 20, 2019 4:53 pm
That's now implemented on git, it'll be in tonight's nightly build for Windows.
Wow, you have surpassed yourself!
As you suggested, it was quite trivial to implement!
Which raises the question of why it wasn't provided from the start in Acorn BASICs, given its usefulness. I expect Sophie simply didn't think of it (and to be fair, neither did I back then).

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Thu Nov 21, 2019 12:23 pm

Richard Russell wrote:
Wed Nov 20, 2019 5:05 pm
Soruk wrote:
Wed Nov 20, 2019 4:53 pm
That's now implemented on git, it'll be in tonight's nightly build for Windows.
Wow, you have surpassed yourself!
Well, it wasn't exactly right, as it turned out the ON ERROR handler was only correctly stacked if you used LOCAL ERROR then ON ERROR, but not ON ERROR LOCAL. While I'm not 100% certain if they are supposed to be different, I've now got the code correctly stacking the handler with ON ERROR LOCAL and carefully unwinding it at the end of the FN/PROC or RESTORE LOCAL. RESTORE ERROR did correctly restore from stack, but only if it it was pushed to the stack in the first place!

I've re-triggered the nightly build so today's build includes the latest fixes.

From reading your example here, I am led to believe that RESTORE LOCAL also does a RESTORE ERROR, and at least in Matrix Brandy and BBCSDL, your example from that thread also works if RESTORE ERROR is used in place of RESTORE LOCAL.
Richard Russell wrote:
Wed Nov 20, 2019 5:05 pm
As you suggested, it was quite trivial to implement!
Which raises the question of why it wasn't provided from the start in Acorn BASICs, given its usefulness. I expect Sophie simply didn't think of it (and to be fair, neither did I back then).
Now you mention it, it does make me wonder. Though, it being missing from Acorn BASICs it's not a feature I had encountered before.

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

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

Post by Richard Russell » Thu Nov 21, 2019 1:02 pm

Soruk wrote:
Thu Nov 21, 2019 12:23 pm
Well, it wasn't exactly right, as it turned out the ON ERROR handler was only correctly stacked if you used LOCAL ERROR then ON ERROR, but not ON ERROR LOCAL.
It's a longstanding difference between Acorn's BASICs and mine. Theirs separate the actions of storing the current error-trapping status on the stack (LOCAL ERROR) and establishing a new error handler in a local context (ON ERROR LOCAL) but mine require just ON ERROR LOCAL to do both (LOCAL ERROR is accepted for compatibility, but ignored). Evidently they felt that there might be circumstances when one would want to do one without the other, but this has always puzzled me.
I am led to believe that RESTORE LOCAL also does a RESTORE ERROR, and at least in Matrix Brandy and BBCSDL, your example from
that thread also works if RESTORE ERROR is used in place of RESTORE LOCAL.
RESTORE LOCAL restores everything that would normally be restored on ENDPROC. So that includes stacked parameters and LOCAL variables (and PRIVATE variables in my BASICs) as well as doing a RESTORE DATA and/or RESTORE ERROR just as ENDPROC does. If you're calling the same code as ENDPROC and = uses you should be good.

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Thu Nov 21, 2019 1:07 pm

Richard Russell wrote:
Thu Nov 21, 2019 1:02 pm
RESTORE LOCAL restores everything that would normally be restored on ENDPROC. So that includes stacked parameters and LOCAL variables (and PRIVATE variables in my BASICs) as well as doing a RESTORE DATA and/or RESTORE ERROR just as ENDPROC does. If you're calling the same code as ENDPROC and = uses you should be good.
That's exactly what I'm doing - though, as I mentioned about the stacking not being right I had to amend those bits too to properly unwind the stack. Prior to that, the PROC2 error handler worked, but then it stopped as if no error handler were in place. And calling PROC1 from the command line resulted in a segfault! It's all good now.

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

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

Post by Richard Russell » Thu Nov 21, 2019 1:42 pm

Soruk wrote:
Thu Nov 21, 2019 1:07 pm
Prior to that, the PROC2 error handler worked, but then it stopped as if no error handler were in place. And calling PROC1 from the command line resulted in a segfault! It's all good now.
Obviously I would not want you to make any changes to Matrix Brandy that unnecessarily impair its compatibility with Acorn's ARM BASIC V and VI. When listing the example of how RESTORE LOCAL can be used I probably should have been more careful to include the LOCAL ERROR statements that Acorn's BASICs require but mine don't. I've also added code to distinguish between using RESTORE LOCAL (it will print B = 3.14159265) and RESTORE ERROR (it will print B = 2.71828183):

Code: Select all

   10 B = PI
   20 ON ERROR PRINT "Error: " REPORT$ ", B = "; B : END
   30 PROC1
   40 END
   50
   60 DEF PROC1
   70 LOCAL ERROR
   80 ON ERROR LOCAL RESTORE LOCAL : PRINT "Error handled in PROC1" : ERROR ERR,REPORT$
   90 PROC2
  100 ENDPROC
  110
  120 DEF PROC2
  130 LOCAL A, B
  140 LOCAL ERROR
  150 ON ERROR LOCAL RESTORE LOCAL : PRINT "Error handled in PROC2" : ERROR ERR,REPORT$
  160 B = EXP(1)
  170 A = 1/0
  180 ENDPROC

scruss
Posts: 213
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

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

Post by scruss » Thu Nov 21, 2019 2:01 pm

Soruk wrote:
Tue Nov 19, 2019 9:08 am
Edit: I've just checked in a couple of new demos, sine and spiral, which will use the normal graphics in the SDL build, and Tektronix graphics in tbrandy.
There's no path switching in the code, it just switches on TekEnabled then goes ahead with regular BASIC graphics commands.
Ooh, nicer still! Sorry I misunderstood: I guess teklib things could nearly always have run under tbrandy.

I suppose the scale of the Tek screen isn't quite the same as the equivalent BBC BASIC one: graphdemo comes out smaller in a Tek window that in the Matrix Brandy window:
Screenshot from 2019-11-21 08-51-26.png
matrix brandy graph demo
Screenshot from 2019-11-21 08-51-33.png
matrix brandy graph demo, tek window
tek4010 doesn't seem too happy with some of the Tek output, with lots of '38h' labels at every vertex:
Screenshot from 2019-11-21 08-54-26.jpg
tek4010 output

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Thu Nov 21, 2019 2:11 pm

scruss wrote:
Thu Nov 21, 2019 2:01 pm
Soruk wrote:
Tue Nov 19, 2019 9:08 am
Edit: I've just checked in a couple of new demos, sine and spiral, which will use the normal graphics in the SDL build, and Tektronix graphics in tbrandy.
There's no path switching in the code, it just switches on TekEnabled then goes ahead with regular BASIC graphics commands.
Ooh, nicer still! Sorry I misunderstood: I guess teklib things could nearly always have run under tbrandy.

I suppose the scale of the Tek screen isn't quite the same as the equivalent BBC BASIC one: graphdemo comes out smaller in a Tek window that in the Matrix Brandy window:
Screenshot from 2019-11-21 08-51-26.png
Screenshot from 2019-11-21 08-51-33.png

tek4010 doesn't seem too happy with some of the Tek output, with lots of '38h' labels at every vertex:
Screenshot from 2019-11-21 08-54-26.jpg
The Tek window in xterm emulates a 1024x780 display, so in RISC OS units, 2048x1560, so rather bigger than the traditional 1280x1024 RISC OS units of the traditional modes.

The 38h possibly comes from the codes used by xterm to switch the cursor between the VT (text) window and the Tek window. I suspect the tek4010 emulator won't recognise them as there's nothing for it to switch to.

I've just realised there's a bug with the VDU5 implementation, really in VDU5 mode the cursor should stay in the Tek window until a VDU4 is seen. I'll look to fix that then amend the demos to be in VDU5 mode throughout the drawing, then VDU4 afterwards (so at worst there should only be one 38h seen).

Edit: This VDU5 thing done, I've amended the demos to draw in VDU5 mode. There should be no difference in the SDL version, the Tek in xterm should be faster as there are far fewer codes being generated, and from a quick test on my end there's fewer 38h's appearing, but don't forget Brandy will be trying to output codes for the VT window (e.g. Mode change) which will be ANSI, not Tek.
Edit 2: CLG after VDU5 is ensuring no spurious ANSI codes remain displayed before drawing starts.

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Thu Nov 21, 2019 3:51 pm

Richard Russell wrote:
Thu Nov 21, 2019 1:42 pm
Soruk wrote:
Thu Nov 21, 2019 1:07 pm
Prior to that, the PROC2 error handler worked, but then it stopped as if no error handler were in place. And calling PROC1 from the command line resulted in a segfault! It's all good now.
Obviously I would not want you to make any changes to Matrix Brandy that unnecessarily impair its compatibility with Acorn's ARM BASIC V and VI. When listing the example of how RESTORE LOCAL can be used I probably should have been more careful to include the LOCAL ERROR statements that Acorn's BASICs require but mine don't. I've also added code to distinguish between using RESTORE LOCAL (it will print B = 3.14159265) and RESTORE ERROR (it will print B = 2.71828183):

Code: Select all

   10 B = PI
   20 ON ERROR PRINT "Error: " REPORT$ ", B = "; B : END
   30 PROC1
   40 END
   50
   60 DEF PROC1
   70 LOCAL ERROR
   80 ON ERROR LOCAL RESTORE LOCAL : PRINT "Error handled in PROC1" : ERROR ERR,REPORT$
   90 PROC2
  100 ENDPROC
  110
  120 DEF PROC2
  130 LOCAL A, B
  140 LOCAL ERROR
  150 ON ERROR LOCAL RESTORE LOCAL : PRINT "Error handled in PROC2" : ERROR ERR,REPORT$
  160 B = EXP(1)
  170 A = 1/0
  180 ENDPROC
On Matrix Brandy I'm getting 3.14159265 both ways. I did read about this effect, it seems by breaking out of a PROC other than via ENDPROC a variable declared LOCAL has its local value suddenly become global. I need to dig a bit deeper why this is, but Matrix Brandy is restoring the values even when exiting via an error condition. While it's at variance to both Acorn's and your BASICs, I tend towards not considering this a bug.

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

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

Post by Richard Russell » Thu Nov 21, 2019 5:09 pm

Soruk wrote:
Thu Nov 21, 2019 3:51 pm
While it's at variance to both Acorn's and your BASICs, I tend towards not considering this a bug.
I don't understand how it is happening. This code prints 2.71828183, as expected, in Brandy so it's not RESTORE ERROR behaving like RESTORE LOCAL in restoring B to its previous value, so what is? Which statement is responsible?

Code: Select all

   10 B = PI
   20 PROC1
   30 END
   40
   50 DEF PROC1
   60 LOCAL B
   70 LOCAL ERROR
   80 ON ERROR LOCAL REPORT : STOP
   90 B = EXP(1)
  100 RESTORE ERROR
  110 PRINT B
  120 ENDPROC

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

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

Post by Richard Russell » Thu Nov 21, 2019 5:54 pm

Richard Russell wrote:
Thu Nov 21, 2019 5:09 pm
I don't understand how it is happening.
I trust you remembered to change both RESTORE LOCALs to RESTORE ERROR for your test. If you changed only the one in PROC2 it's not in the least surprising that 3.14159265 woud be printed!

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Thu Nov 21, 2019 5:57 pm

Richard Russell wrote:
Thu Nov 21, 2019 5:54 pm
Richard Russell wrote:
Thu Nov 21, 2019 5:09 pm
I don't understand how it is happening.
I trust you remembered to change both RESTORE LOCALs to RESTORE ERROR for your test. If you changed only the one in PROC2 it's not in the least surprising that 3.14159265 woud be printed!
Yes, I did.

Saying that, when trying it in BBCSDL I only changed the second one, and got 2.71.... (on the train right now!)

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

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

Post by Richard Russell » Thu Nov 21, 2019 11:40 pm

Soruk wrote:
Thu Nov 21, 2019 3:51 pm
I need to dig a bit deeper why this is, but Matrix Brandy is restoring the values even when exiting via an error condition.
I will await your analysis with interest, particularly if you are able to ascertain whether it is deliberate or accidental. Given Brandy's excellent compatibility with Acorn's ARM BASIC, in general, I certainly find it surprising. One consequence seems to be that this code produces an unexpected result:

Code: Select all

   10 B = PI
   20 PROC1
   30 END

   50 DEF PROC1
   60 LOCAL A,B
   70 ON ERROR PRINT REPORT$ ", B = ";B : STOP
   80 LOCAL ERROR
   90 ON ERROR LOCAL RESTORE ERROR : ERROR ERR, REPORT$
  100 B = 0
  110 A = 1/B
  120 ENDPROC
It prints 'B = 3.14159265', indicating that B has been restored, but the code never leaves the procedure and from a debugging standpoint it's misleading because it appears that a 'Division by zero' error resulted from dividing by PI. When you're trying to figure out the cause of an error you don't want the error handler to destroy the evidence! :roll:

This code, which I would have expected to do something sensible, reports 'Address exception':

Code: Select all

   10 B = PI
   20 PROC1
   30 END

   50 DEF PROC1
   60 LOCAL A,B
   70 LOCAL ERROR
   80 ON ERROR PRINT REPORT$ ", B = ";B : STOP
  100 B = 0
  110 A = 1/B
  120 ENDPROC

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Fri Nov 22, 2019 9:27 am

Richard Russell wrote:
Thu Nov 21, 2019 11:40 pm
This code, which I would have expected to do something sensible, reports 'Address exception':

Code: Select all

   10 B = PI
   20 PROC1
   30 END

   50 DEF PROC1
   60 LOCAL A,B
   70 LOCAL ERROR
   80 ON ERROR PRINT REPORT$ ", B = ";B : STOP
  100 B = 0
  110 A = 1/B
  120 ENDPROC
For that, I need to point a debugger at it, as Matrix Brandy generates that error for a segmentation fault (this was set up for the switch to actual addressing so indirections out of the Brandy workspace give a sensible error rather than the interpreter collapsing in a heap).

Edit: This is fixed.

Edit 2:
Richard Russell wrote:
Soruk wrote:
Thu Nov 21, 2019 3:51 pm
I need to dig a bit deeper why this is, but Matrix Brandy is restoring the values even when exiting via an error condition.
I will await your analysis with interest, particularly if you are able to ascertain whether it is deliberate or accidental. Given Brandy's excellent compatibility with Acorn's ARM BASIC, in general, I certainly find it surprising. One consequence seems to be that this code produces an unexpected result:

Code: Select all

   10 B = PI
   20 PROC1
   30 END

   50 DEF PROC1
   60 LOCAL A,B
   70 ON ERROR PRINT REPORT$ ", B = ";B : STOP
   80 LOCAL ERROR
   90 ON ERROR LOCAL RESTORE ERROR : ERROR ERR, REPORT$
  100 B = 0
  110 A = 1/B
  120 ENDPROC
It prints 'B = 3.14159265', indicating that B has been restored, but the code never leaves the procedure and from a debugging standpoint it's misleading because it appears that a 'Division by zero' error resulted from dividing by PI. When you're trying to figure out the cause of an error you don't want the error handler to destroy the evidence! :roll:
The error handler unwinds the stack - and in the process of discarding the stack it's restoring the various pointers. I've added a new code path for discarding the stack on error handling, such that on this particular path, stack entries for variables declared LOCAL are discarded without being restored.

Edit 3: The Windows nightly has been rebuilt, *HELP BASIC shows git commit 16ba6a8 on branch master.

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

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

Post by Richard Russell » Fri Nov 22, 2019 12:38 pm

Soruk wrote:
Fri Nov 22, 2019 9:27 am
I've added a new code path for discarding the stack on error handling
That should certainly improve compatibility with other versions, and may perhaps be a little faster too. Had you not also implemented RESTORE LOCAL I can imagine there being some complaints that it is a retrograde step, but now the programmer has the choice of restoring the local variables (RESTORE LOCAL) or not (RESTORE ERROR).

David1664
Posts: 59
Joined: Thu Feb 25, 2010 2:24 am
Contact:

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

Post by David1664 » Fri Nov 22, 2019 2:08 pm

Hi Soruk,

The 'original' Brandy BASIC is listed on this page http://www.bbcbasic.co.uk/bbcbasic.html as being for "RISC OS, NetBSD, OpenBSD, FreeBSD, Linux, Mac OS X, Amiga OS, MS-DOS." Matrix Brandy BASIC is listed for "Linux, Raspberry Pi and Windows."

Can Matrix Brandy BASIC also be compiled and run on the same platforms (NetBSD, Mac OS X, Amiga OS, etc.) as the original Brandy BASIC?


David.
--

http://www.proggies.uk/
http://www.proggies.uk/bbcsdl/index.html

Soruk
Posts: 617
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

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

Post by Soruk » Fri Nov 22, 2019 2:50 pm

David1664 wrote:
Fri Nov 22, 2019 2:08 pm
Hi Soruk,

The 'original' Brandy BASIC is listed on this page http://www.bbcbasic.co.uk/bbcbasic.html as being for "RISC OS, NetBSD, OpenBSD, FreeBSD, Linux, Mac OS X, Amiga OS, MS-DOS." Matrix Brandy BASIC is listed for "Linux, Raspberry Pi and Windows."

Can Matrix Brandy BASIC also be compiled and run on the same platforms (NetBSD, Mac OS X, Amiga OS, etc.) as the original Brandy BASIC?


David.
--

http://www.proggies.uk/
http://www.proggies.uk/bbcsdl/index.html
I've developed and focused on the kit that I have. Certainly I see no reason why it won't build on the BSDs, and at a push, Mac OS X. The GUI might be harder, but if SDL 1.2 is available, then that should also work. I've never used an Amiga (or a Mac). Others have had more success than I have at building it on RISC OS - notably @jgharston has got that working, and I believe he might have had some luck with MS-DOS too.

Note also that the download from the orpheusweb site linked from the above page dates to 2005, there is no graphics capability at all so all in all the code is far simpler than where it is today.

Post Reply

Return to “classic languages (e.g. BASIC) on non-acorn platforms”