New: in-browser BBC BASIC for SDL 2.0

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

New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Sun Aug 30, 2020 6:50 pm

I've built an experimental in-browser (WebAssembly) edition of BBC BASIC for SDL 2.0 which will currently run in Microsoft Edge and Google Chrome (but not Firefox). It can be run directly from this link.

There are a number of demo programs included which can be found in the examples/games, examples/general, examples/graphics and examples/sounds directories. For example:

Code: Select all

*cd examples/graphics
CHAIN "bounce"
There are some significant limitations, the most serious of which is probably that the GCOL 'logical plotting' modes (AND, OR, EOR) don't work; this is because webgl does not support these operations. Another limitation is that the SYS statement is not supported. It's also quite slow!

Currently there is no way to load in your own program(s), that needs to be thought about. Also, the local filesystem provided by Emscripten is volatile and anything saved there will be lost when you close the browser.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Mon Aug 31, 2020 10:08 am

Richard Russell wrote:
Sun Aug 30, 2020 6:50 pm
There are some significant limitations, the most serious of which is probably that the GCOL 'logical plotting' modes (AND, OR, EOR) don't work
To address this, in part, I have arranged that rather than the logical plotting modes being completely non-functional they activate the nearest supported webgl blend mode. So for example GCOL 1 sets 'add' and GCOL 2 sets 'multiply'; whilst these obviously have significantly different effects from the genuine logical modes (OR and AND), they are equivalent in the special case when the RGB values of the source and destination are all 0.0 (&00) or 1.0 (&FF).

The updated version can be run, as before, from this link; it will only work in Microsoft Edge or Google Chrome. You may have to clear your browser cache to guarantee picking up the new version.

To demonstrate the newly-implemented GCOL modes I have added polydots.bbc in the examples/graphics directory, which didn't work previously because it relies on a GCOL 3,15.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by BigEd » Mon Aug 31, 2020 11:00 am

Great!

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Thu Sep 03, 2020 2:06 pm

After a bit of a struggle, the in-browser BBCSDL now accepts a ?chain= URL parameter to run the specified program automatically (it must be in tokenised .bbc format). You can try this example to see it in action ('desktop' Edge or Chrome).

Interestingly, the processing of the ?chain= parameter and the loading and running of the specified program are handled entirely in BBC BASIC code! No Javascript, no C, but rather the kind of code that I understand. :D

Currently there is no provision for loading resource files or sub-modules in addition to the main BASIC program, but that can be added fairly easily.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Thu Sep 03, 2020 9:58 pm

In the latest update I've implemented ?run= in addition to ?chain=. This allows you to run one of the supplied example programs directly, for example this one.

I've also added a couple more libraries: aagfxlib.bbc (anti-aliased graphics) and imglib.bbc (hardware-accelerated sprites) plus aagfxdem.bbc and aliens.bbc to demonstrate them.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by BigEd » Thu Sep 03, 2020 10:01 pm

Very handy URL parameter additions - thanks!

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Fri Sep 04, 2020 2:45 pm

Another update. The following URL parameters are now accepted:

Code: Select all

?run=<path/program>  Run the specified supplied example program
?dir=<path>          Use the specified directory for subsequent files
?load=<url>          Load the specified file (sub-module or resource file)
?chain=<url>         Load and run the specified program (must be .bbc)
This allows you to run a program that needs resource files. For example this which loads three bitmap images as well as the program itself.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Sat Sep 05, 2020 6:18 am

Richard Russell wrote:
Fri Sep 04, 2020 2:45 pm
This allows you to run a program that needs resource files.
Note that you don't need to repeat the full URL for each file, if just a filename is specified &load= and &chain= will assume the rest of the URL is the same as before.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Mon Sep 07, 2020 11:55 am

I have updated the in-browser edition of BBC BASIC for SDL 2.0 to version 1.14y. The differences in this version are:
  • Fixed a performance issue caused by yielding to the browser too often, which throttled graphics output.

  • Added the sortlib and eventlib libraries, compatible with those supplied with the other editions.

  • Added sorttest.bbc, in the examples/general/ directory, to test the sortlib library.

  • Added multitouch.bbc, in the examples/general/ directory, to demonstrate the eventlib library (needs a touchscreen).

  • Restored aliens.bbc to animate 80 sprites, to demonstrate the improved graphics performance (I get about 30 fps on my Core i7 laptop and 48 fps on my fastest desktop, both in Microsoft Edge).
Users of 32-bit Windows please note that a few of the supplied programs do not work properly, seemingly because of a bug in the 32-bit WebGL.

User avatar
SimonSideburns
Posts: 564
Joined: Mon Aug 26, 2013 9:09 pm
Location: Purbrook, Hampshire
Contact:

Re: New: in-browser BBC BASIC for SDL 2.0

Post by SimonSideburns » Tue Sep 08, 2020 10:36 am

Would it be possible to load a local file? E.g. appending ?chain=file://blablabla.bbc to the URL. I tried it but nothing seemed to happen.

Also, is the 32k memory limit in place (like in the trial version)?
Just remember kids, Beeb spelled backwards is Beeb!

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Tue Sep 08, 2020 12:13 pm

SimonSideburns wrote:
Tue Sep 08, 2020 10:36 am
Would it be possible to load a local file? E.g. appending ?chain=file://blablabla.bbc to the URL.
I don't believe so. The best explanation I have found is here where it says "Modern web browsers are designed with security in mind so they are highly sandboxed. They are never going to allow web pages to write/open a local file in your machine".

You could, in principle, run a WebSockets server on your local machine and communicate with it from BBC BASIC, but it might be a bit tricky to get it working. If there's anything I can do to help let me know.
Also, is the 32k memory limit in place (like in the trial version)?
No, this is BBC BASIC for SDL 2.0 which is free and unrestricted: there is no "trial version"! The default setting of HIMEM is 2 Mbytes above PAGE, just as it is in the other editions of BBCSDL. By experiment, the in-browser edition allows you to raise HIMEM to about 8 Mbytes; any more and it fails with 'No room' (which is not trappable and you have to close the page). The other editions support up to 256 Mbytes.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Thu Sep 10, 2020 4:25 pm

The in-browser edition of BBC BASIC for SDL 2.0 now runs in Firefox as well as Edge and Chrome (desktop versions).

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Soruk » Thu Sep 10, 2020 7:40 pm

Richard Russell wrote:
Thu Sep 10, 2020 4:25 pm
The in-browser edition of BBC BASIC for SDL 2.0 now runs in Firefox as well as Edge and Chrome (desktop versions).
Nice.

Works in Firefox 80.0.1 in Windows (tested on my work machine). Does NOT work on 78.2.0esr (current shipped with CentOS 8.2) on Linux.

The error caught is:

Code: Select all

Uncaught ReferenceError: SharedArrayBuffer is not defined
    <anonymous> https://bbcbasic.co.uk/bbcsdl/wasm/bbcsdl.js:1616
Matrix Brandy BASIC VI (work in progress)

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Thu Sep 10, 2020 7:58 pm

Soruk wrote:
Thu Sep 10, 2020 7:40 pm
Does NOT work on 78.2.0esr (current shipped with CentOS 8.2) on Linux.
According to what it says here it may be possible to enable SharedArrayBuffer in Firefox 78: "From version 57: this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config". It would be interesting to know whether that is indeed the case.

Failing that you will need a newer version. Although Chrome has had the necessary features for some time (a few months) Edge and Firefox have gained them only in recent updates. That's one reason why this has been a good time to release the in-browser edition.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Thu Sep 10, 2020 11:40 pm

Richard Russell wrote:
Thu Sep 10, 2020 7:58 pm
it may be possible to enable SharedArrayBuffer in Firefox 78
Actually according to this SharedArrayBuffer needs Firefox 79, which is inconsistent with the other page I linked to.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Soruk » Fri Sep 11, 2020 8:46 am

Richard Russell wrote:
Thu Sep 10, 2020 11:40 pm
Richard Russell wrote:
Thu Sep 10, 2020 7:58 pm
it may be possible to enable SharedArrayBuffer in Firefox 78
Actually according to this SharedArrayBuffer needs Firefox 79, which is inconsistent with the other page I linked to.
Confirmed, the above toggle is already set to true on 78.2.0esr, and BBC BASIC in browser is not working.
Matrix Brandy BASIC VI (work in progress)

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Fri Sep 11, 2020 9:51 am

Soruk wrote:
Fri Sep 11, 2020 8:46 am
Confirmed, the above toggle is already set to true on 78.2.0esr, and BBC BASIC in browser is not working.
On Ubuntu (18.04 LTS) I have Firefox 80.0.1, and BBC BASIC runs fine:

Screenshot from 2020-09-11 09-48-19.png

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Mon Sep 14, 2020 2:45 pm

I've updated the in-browser BBC BASIC for SDL 2.0 so that the @usr$ folder is now 'persistent', i.e. files stored there will not be discarded when you close the page and should still be there the next time you run BBC BASIC (in the same browser). That directory is typically where custom settings or game state (e.g. high score) are stored; you may save your own programs there too.

It's possible that performance may be adversely affected if there are many and/or large files stored there, but that will need to be ascertained by experience. If you don't have need of persistent storage, save files in @tmp$ instead.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Sat Sep 19, 2020 11:26 pm

To my considerable surprise (because it says here that it shouldn't) the latest version of Opera successfully runs the in-browser BBC BASIC. However the speed seems not to be very good compared with the others, running Tyoob at only about half the frame rate of Firefox here. Still, if you use Opera it's worth knowing.

Here's another little online demo, David Williams's kaleidoscope program.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Tue Sep 22, 2020 12:47 pm

Here's another of David Williams's games which runs nicely in a suitable browser: Rainbow Snake.

Something to note: if you use SYS "SDL_SetWindowTitle" ensure that you include @memhdc% as the last parameter; that's necessary anyway for it to work reliably in MacOS but the in-browser edition crashes if you don't!

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Thu Sep 24, 2020 2:23 pm

The latest program to be ported to the in-browser edition of BBC BASIC is mandel which displays the Mandelbrot Set and allows you to pan and zoom it. This runs best in Firefox, in the other browsers it occasionally crashes with a 'WebGL context lost' error (as it works in Firefox I assume this is not my fault!).

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Thu Sep 24, 2020 11:38 pm

The in-browser edition currently starts up at the immediate-mode prompt if no URL parameter is specified; to run the supplied example programs you must change directory (e.g. *cd examples/graphics) and then CHAIN the program you want. Would it be better for it instead to run the 'touch IDE' at start-up, as do the Android and iOS editions (despite its name it can be used with a keyboard and mouse)?

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by BigEd » Fri Sep 25, 2020 7:43 am

I'm not sure if the 'touch IDE' is the answer (because I don't know what it is) but I do note that *cat applies a wildcard of *.bbc, and as a consequence doesn't show the 'examples' directory at all. Is there a way to make the filesystem more conveniently discoverable? Even a menu.bbc at the root, or in 'examples' and have 'examples' as the current directory?

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Fri Sep 25, 2020 9:34 am

BigEd wrote:
Fri Sep 25, 2020 7:43 am
Is there a way to make the filesystem more conveniently discoverable? Even a menu.bbc at the root, or in 'examples' and have 'examples' as the current directory?
Even if 'examples' was the current directory at startup *. still wouldn't show the subdirectories (games, general, graphics, sounds) so I'm not sure that it would help a great deal; you need to do *.. to show subdirectories (stardotdot!).

If you don't know what the Touch IDE is, can I suggest that you try it? It's the default interface in the Android and iOS editions of BBC BASIC for SDL 2.0, and is available in the desktop editions in the examples/tools/ directory. In terms of making the filesystem "discoverable" I would have thought it was the best solution.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by BigEd » Fri Sep 25, 2020 9:18 pm

Ah, *.. - would never have thought of that!

It does feel like the implicit *.bbc added a bit of an obstacle for me.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Fri Sep 25, 2020 10:08 pm

BigEd wrote:
Fri Sep 25, 2020 9:18 pm
It does feel like the implicit *.bbc added a bit of an obstacle for me.
I make no apology for 'my' BBC BASICs betraying their CP/M, MS-DOS and Windows heritage. :)

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by BigEd » Fri Sep 25, 2020 10:25 pm

Hmm - do those OSes do that kind of thing? Is it a mechanism that's hard-coded, or a setting which the user can change? I am a bit baffled: under what circumstance would DOS' DIR apply an implicit file extension?

(Edit: I should clarify: I'm not bothered by the existence of an apparent three letter extension, but by '*.' applying an extension implicitly)

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Fri Sep 25, 2020 10:45 pm

BigEd wrote:
Fri Sep 25, 2020 10:25 pm
I am a bit baffled: under what circumstance would DOS' DIR apply an implicit file extension?
Whenever the application performing the directory listing has a preferred, default or associated extension! So that's almost always; about the only occasion I can think of when it's not sensible to default to a specific extension or extensions is when the directory listing is being performed outside of an application, for example at the command prompt.

This is pretty much universal in Windows. If I list a directory in Windows File Explorer it shows me all the files, but if I do the same in Notepad it shows me only *.txt files by default, if I do so in Microsoft Excel it shows me only .xls files by default, in Word it shows me only .doc and .docx (and a few others) by default.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by Richard Russell » Fri Sep 25, 2020 11:40 pm

Richard Russell wrote:
Thu Sep 24, 2020 11:38 pm
Would it be better for it instead to run the 'touch IDE' at start-up, as do the Android and iOS editions?
There's been disappointingly little feedback, but what I have received has been positive so I've made the change experimentally. Here is the revised version, let me know what you think (if you're not familiar with the Touch IDE there's a brief description here). I can easily switch it back to how it was if necessary.

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

Re: New: in-browser BBC BASIC for SDL 2.0

Post by BigEd » Sat Sep 26, 2020 5:57 pm

Richard Russell wrote:
Fri Sep 25, 2020 10:45 pm
This is pretty much universal in Windows. If I list a directory in Windows File Explorer it shows me all the files, but if I do the same in Notepad it shows me only *.txt files by default, if I do so in Microsoft Excel it shows me only .xls files by default, in Word it shows me only .doc and .docx (and a few others) by default.
Indeed, but I think the file chooser also shows folders. So you can pick, or navigate and then pick.

This is what the 'interactive' mode looked like when I tried it:
BBC-SDL-browser-CLI.png
I think that's a bit obscure. Maybe that's just an opinion, but I offer it in good faith as feedback.

Post Reply

Return to “modern implementations of classic programming languages”