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

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

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

Post by Soruk » Fri Jan 04, 2019 11:04 am

I've not abandoned this!

I've got a handful of fixes and enhancements checked into github, including a lot of keyboard fixes (complete with a new keyboard driver, choose old or new one at compile time) from JGHarston - there has been a bit of activity over on the github ticket facility.

When building from a git tree, *HELP BASIC and HELP both give the git commit reference from where the build was made from, and BRANDY_BUILD_FLAGS environment variable can be defined and contain additional flags to pass to the compiler - for example -DNEWKBD for JGH's new keyboard code, and -DNODISPLAYOS to hide the host OS information from the banner and HELP output.
Last edited by Soruk on Fri Jan 04, 2019 1:47 pm, edited 1 time in total.

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

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

Post by dhg2 » Fri Jan 04, 2019 7:44 pm

Has there been any progress towards sound support? I think jgharston said he was looking into it, or maybe I'm remembering wrongly.
Regards,
- Patrick

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

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

Post by Soruk » Fri Jan 04, 2019 11:12 pm

dhg2 wrote:
Fri Jan 04, 2019 7:44 pm
Has there been any progress towards sound support? I think jgharston said he was looking into it, or maybe I'm remembering wrongly.
I think he was thinking of it after sorting out the mess that is the keyboard support.

In the back of my mind I thought of borrowing the code from BBCSDL (adding zlib-licensed code to GPL-licensed code doesn't violate either licence), which would require porting it to the SDL-1.2 interface. But I'm not sure how well that would go down in some circles, as I don't want Brandy to be seen to be "stealing" code from what could be seen as a competitor product.

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

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

Post by dhg2 » Thu Jan 10, 2019 9:54 pm

Hello again,

I've noticed two issues (or maybe three issues, with two of them similar but separate) related to OSCLI.

I found myself in the situation where I wanted to use OSCLI to run an executable in the current directory. So I tried

Code: Select all

OSCLI "./binfile"
But this didn't work because any command string starting with a "." just prints a directory listing. So I tried putting the full path to the executable:

Code: Select all

OSCLI "/path/to/binfile"
But that produces this error: "sh: 1: path/to/binfile: not found".

Another issue I've noticed is that, if you try to run a command in the background by putting a & on the end of the command, brandy still waits for the command to finish executing before proceeding. I would have expected it to continue executing immediately after the OSCLI, behaving the same as "system()" does in C when you use it to run a command with & at the end.
Last edited by dhg2 on Thu Jan 10, 2019 9:55 pm, edited 1 time in total.
Regards,
- Patrick

User avatar
BigEd
Posts: 2270
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

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

Post by BigEd » Thu Jan 10, 2019 10:12 pm

Try an extra leading slash. (*/ is the same as *RUN I think.)

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

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

Post by dhg2 » Thu Jan 10, 2019 10:25 pm

BigEd wrote:
Thu Jan 10, 2019 10:12 pm
Try an extra leading slash. (*/ is the same as *RUN I think.)
Thanks, that worked. I've also just worked out that "$PWD/binfile" works for executing something that's in the current working directory.
Regards,
- Patrick

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

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

Post by Soruk » Fri Jan 11, 2019 11:03 am

dhg2 wrote:
Thu Jan 10, 2019 9:54 pm
Another issue I've noticed is that, if you try to run a command in the background by putting a & on the end of the command, brandy still waits for the command to finish executing before proceeding. I would have expected it to continue executing immediately after the OSCLI, behaving the same as "system()" does in C when you use it to run a command with & at the end.
Under SDL, it uses popen() so output can be captured and returned to the SDL window. Other builds do use system() so the text-mode builds will be able to run background processes but currently the SDL cannot.

Perhaps an option here is to check if the '&' character exists in the command string, and if so, run it through system() - but may need some command parsing to do this correctly.
For example:

Code: Select all

this & that & the_other
will run this and that as background processes, and the_other as a foreground process. system() would be able to handle this, but in SDL it'll block until the_other completes. popen() wouldn't be able to handle this. If we were to split on '&' and fire background processes off with system() we then need to be extremely careful with quote parsing so as not to split in the wrong place.

Rather messy, but you could write a program in BASIC that creates a temporary script file (remember to use BPUT# to write the strings), ose OSCLI to chmod u+x then use OSCLI to run the script. A word of warning: I haven't tested this :)

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

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

Post by Soruk » Tue Jan 15, 2019 10:18 am

Hi,

I've just put together version 1.21.18. This release wraps up a number of updates, most of which were from the Git ticketing system:
- *SHOW implemented (JGHarston)
- Bug fix for DEL in text-only builds (JGHarston)
- Limit *WinTitle to SDL and UNIX builds - it's a no-op otherwise.
- MODE 7 scrolling text fix
- MODE 135 now selects MODE 7.
- Fix VDU20 for text-mode UNIX build
- Top-level makefiles now read BRANDY_BUILD_FLAGS environment variable for additional build flags
- New keyboard handler (JGHarston) - add -DNEWKBD to makefile to CFLAGS or define

Code: Select all

export BRANDY_BUILD_FLAGS=-DNEWKBD
in your shell environment to use.

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

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

Post by jgharston » Tue Jan 15, 2019 11:12 pm

dhg2 wrote:
Thu Jan 10, 2019 9:54 pm
Another issue I've noticed is that, if you try to run a command in the background by putting a & on the end of the command, brandy still waits for the command to finish executing before proceeding. I would have expected it to continue executing immediately after the OSCLI, behaving the same as "system()" does in C when you use it to run a command with & at the end.
Backgrounding is (essentially) a command processor function, the caller (ie, Brandy in this case) needs to chose to make it do that. It's one of the things I've got scribbled down, along with using an actual command lookup table instead of line after line of if strcpm(cmdline, "commandname")...

Code: Select all

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

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

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

Post by Richard Russell » Tue Jan 15, 2019 11:32 pm

jgharston wrote:
Tue Jan 15, 2019 11:12 pm
Backgrounding is (essentially) a command processor function, the caller (ie, Brandy in this case) needs to chose to make it do that.
FWIW the syntax in BB4W and BBCSDL is to add a semicolon (;) to the end of the *RUN command to force it to run in the background. This is loosely based on the use of the semicolon to mean 'suppress forthcoming action' in other BBC BASIC contexts (to suppress the newline in PRINT, to suppress the Line Feed in BPUT#, and after THEN in my 'ELSE IF' extension). However in BBCSDL all that happens is that the semicolon is converted to an ampersand before the command is passed to system()!

User avatar
sweh
Posts: 2004
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

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

Post by sweh » Wed Jan 16, 2019 12:21 am

jgharston wrote:
Tue Jan 15, 2019 11:12 pm
dhg2 wrote:
Thu Jan 10, 2019 9:54 pm
Another issue I've noticed is that, if you try to run a command in the background by putting a & on the end of the command, brandy still waits for the command to finish executing before proceeding. I would have expected it to continue executing immediately after the OSCLI, behaving the same as "system()" does in C when you use it to run a command with & at the end.
Backgrounding is (essentially) a command processor function, the caller (ie, Brandy in this case) needs to chose to make it do that. It's one of the things I've got scribbled down, along with using an actual command lookup table instead of line after line of if strcpm(cmdline, "commandname")...
Well, kinda-maybe-perhaps.

Both system() and popen() invoke the shell to do the work, so it effectively calls something line /bin/sh -c "cmdtorun". Note: this has a lot of security issues, so never ever ever do this on untrusted input!

This means that commands with "&" in them will automatically be backgrounded.

However, if we look at the calling code:

Code: Select all

    strcat(cmdbuf, " 2>&1");
    sout = popen(cmdbuf, "r");
    if (sout == NULL) error(ERR_CMDFAIL);
    echo_off();
    while (fread(&buf, 1, 1, sout) > 0) {
      if (buf == '\n') emulate_vdu('\r');
      emulate_vdu(buf);
    }
    echo_on();
    pclose(sout);
So in this case the MatrixBrandy code is deliberately waiting until the child process closes its stdout (typically, it ends), so that it can do VDU emulation.

In the scenario where we do popen("mycommand &") then stdout is still open; the child needs to close stdout before that loop will terminate.

What might work is popen("mycomamnd > /dev/null &") so now the main loop should(!) just see the EOF and terminate.

So I did a simple test:

Code: Select all

#include <stdio.h>
#include <string.h>

int main()
{
  char cmdbuf[1000];
  char buf[10];
  FILE *sout;

  strcpy(cmdbuf,"sleep 10");
  strcat(cmdbuf, " 2>&1");
  sout = popen(cmdbuf, "r");
  if (sout == NULL) perror("popen");

  while (fread(&buf, 1, 1, sout) > 0) {
    printf("%c",*buf);
  }
  pclose(sout);
}
With strcpy(cmdbuf,"sleep 10"); the code took 10 seconds.

With strcpy(cmdbuf,"sleep 10 &"); the code took 10 seconds. Looking at the "ps" listing we see the shell has zombied, and we're waiting for sleep to finish.

With strcpy(cmdbuf,"sleep 10 > /dev/null &"); the code finished immediately, and looking at the ps listing we see the "sleep" process has been orphaned and re-parented to PID 1.

So this should be a solution; if you're creating a background job then ensure stdout is sent to /dev/null (or some another file).
Rgds
Stephen

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

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

Post by dhg2 » Sat Jan 19, 2019 8:51 pm

Thanks sweh! I've tested this and it works.
Regards,
- Patrick

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

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

Post by Soruk » Mon Jan 21, 2019 10:02 pm

Some graphics updates, not looked at this for a while. Ellipses with shears are now working, at least as far as PLOT &C5 and PLOT &CD are concerned, other variants still need to be tested. Though, the implementation is probably not the nicest (and filled ellipses, while working, are SLOW)...

Next on the list is to implement angled ellipses at the BASIC command (angles other than 0 give an unsupported error at the moment) - helpfully, the RISC OS 5 source code has a comment which describes the algorithm used, and an implementation in BASIC does the right thing.

Edit: ELLIPSE command now done.
Last edited by Soruk on Tue Jan 22, 2019 1:48 pm, edited 2 times in total.

Post Reply