In-browser BBC BASIC for SDL 2.0

New releases of BB4W and BBCSDL, and other updates, will be announced here
RichardRussell

In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

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.
michael
Posts: 43
Joined: Mon 02 Apr 2018, 17:13

Re: In-browser BBC BASIC for SDL 2.0

Post by michael »

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
That is extremely cool. Caught my attention fast when I seen it in my email.... WHOA!!
* I tried to paste some code / text and couldn't figure that out yet.
I am assuming that the only way a person could store a program is if you added it to the list in your directory?
RichardRussell

Re: In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

michael wrote: Sun 30 Aug 2020, 19:40 I am assuming that the only way a person could store a program is if you added it to the list in your directory?
The conventional way would be to add a parameter to the URL: bbcsdl.html?parm=value specifying from where the program can be fetched, but I don't currently know how to implement that. I am making enquiries.
RichardRussell

Re: In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

RichardRussell wrote: Sun 30 Aug 2020, 18:41which will currently run in Microsoft Edge and Google Chrome
Some people seem to be incapable of reading. It will ONLY run in Microsoft Edge or Google Chrome (and it needs a really fast PC). Please do not complain that it doesn't run in some other browser that you happen to prefer.
michael
Posts: 43
Joined: Mon 02 Apr 2018, 17:13

Re: In-browser BBC BASIC for SDL 2.0

Post by michael »

I am making enquiries.
I assume that you can write to a file using this IDE? Lets say I am managing data? Or is all the files I see being fetched also? I gather that it disappears after such a file might be created? If BBC Basic is operating in this medium, could I also maybe use your method within this site you use to store my program and allow others to use my code as your examples are being used? Perhaps a Console web version that automatically executes a program that just uses a link to BBC BASIC.

I hope maybe the above statements might inspire solutions. I hope to see more on this.. I will work on some text programs. I hope that keyboard input in games is available in this cool new tool.
RichardRussell

Re: In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

michael wrote: Mon 31 Aug 2020, 00:31 I assume that you can write to a file using this IDE?
Yes, Emscripten implements a 'virtual' file system in RAM which you can write as well as read, but anything you save will be discarded when you close the browser tab. This is most useful for writing temporary files to @tmp$, because it doesn't matter if they are volatile. I think some of the supplied example programs do that.
Perhaps a Console web version that automatically executes a program that just uses a link to BBC BASIC.
If by "Console web version" you mean an in-browser version that has no support for graphics or sound, I don't have any plans for that. The great thing about Emscripten / WebAssembly is that it runs a fairly complete implementation of SDL 2.0 in your browser (if compatible, and if your PC is fast enough) including full support for graphics and sound. For example the supplied programs in examples/sounds should play correctly!

Although an in-browser 'console' version is technically possible I've already got too many different variants to maintain!
I hope that keyboard input in games is available in this cool new tool.
Again that's down to Emscripten / WebAssembly's implementation of SDL2. I would expect it to be fairly complete; I've just checked whether INKEY with a negative parameter is working and it seems to be (in Chrome anyway, which is what I tried). The only keyboard-related issues that I would expect you to encounter are that some browser keyboard shortcuts may still be active (so for example Ctrl+N may open a new browser tab rather than setting BBC BASIC's 'paged' mode).
RichardRussell

Re: In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

RichardRussell wrote: Sun 30 Aug 2020, 18:41There 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 GCOL 3,15.
RichardRussell

Re: In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

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.
RichardRussell

Re: In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

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.
RichardRussell

Re: In-browser BBC BASIC for SDL 2.0

Post by RichardRussell »

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.