Deploying programs in a browser

RichardRussell

Deploying programs in a browser

Post by RichardRussell »

There isn't a section of the forum dedicated to the in-browser (Emscripten / Web Assembly) edition of BBCSDL [admin: How about creating one?] so I'm posting here instead. The compatibility of the in-browser edition with the others is very good, indeed considerably better than I initially expected. Many programs can be expected to run without any modification but there are a few things to bear in mind:
  • The in-browser edition is relatively slow compared with the others; after all the BBC BASIC program is being interpreted to Web Assembly code, which is in turn having to be interpreted (or JITted) to native machine code. Reading data from a file seems to be particularly slow. Don't use *DISPLAY multiple times to plot images, load them into memory once and use *MDISPLAY.

  • The total amount of memory available (i.e. the maximum value to which one can raise HIMEM) is about 16 megabytes compared with the 256 megabytes typically available in the desktop and mobile editions (although that depends on the degree of memory fragmentation).

  • To keep the size of the initial download manageable (it must of course be loaded every time a program is run, so this is important) I only bundle the DejaVuSans and DejaVuSansMono fonts in the library directory. If you want to use a different font (e.g. FreeSans) you will need to supply it alongside your program.

  • The range of API functions available to be called using SYS is very limited: there are only about 80 in all compared with more than 650 in the other editions! If an API function that you want to call is missing let me know, I may be able to add it. If you use SYS "SDL_SetWindowTitle" you must add @memhdc% as the last parameter, otherwise it will crash.

  • Similarly the range of OpenGL/GLES functions available is also very limited (about 50), and their addresses must be obtained by calling SYS "SDL_GL_GetProcAddress" (or use the FN_gpa function in webgllib.bbc).
The danger of publishing a list such as this is that people may just skim over it and conclude that porting programs to the in-browser edition is difficult. Generally it isn't, and these considerations are only likely to affect a tiny proportion of programs.

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Deploying programs in a browser

Post by DDRM »

Hi Richard,

I can take a hint! Forum created and topic moved. Let me know if the name doesn't suit...

D

RichardRussell

Re: Deploying programs in a browser

Post by RichardRussell »

DDRM wrote:
Thu 15 Oct 2020, 08:03
Let me know if the name doesn't suit...
It's fine, but if I was in a pedantic mood I might question why it doesn't start with a capital letter..... :roll:

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Deploying programs in a browser

Post by DDRM »

I don't know what you mean! :D

Hated Moron
Posts: 131
Joined: Thu 07 Apr 2022, 10:10

Re: Deploying programs in a browser

Post by Hated Moron »

Cross-posted from The Distillery forum

This information can be found elsewhere, including in the main BBCSDL documentation, but for the record this is the easiest way of deploying a BBC BASIC program for running in a browser:
  1. Having written your BBC BASIC program, first test that it runs correctly in a browser. To do that open the Compile dialogue in SDLIDE (click on the 'cogs' button in the toolbar, or select 'Utilities... Compile' from the menus).

  2. In the Compile dialogue that is displayed, select the 'Deploy as a web application' checkbox and click the Test button. That will run your program in your default browser; if it runs OK you are good to go, otherwise you will need to fix any problems identified.

  3. Once your program is running in your own browser as you want it to, click on the Create Application button (again, with the 'Deploy as a web application' checkbox selected). This will create a 'web bundle' file, with a .bbb extension, in the location specified in the 'App bundle' field.

  4. Upload that .bbb file to your website (or to Dropbox) and publish the following URL for people to be able to run it:

    Code: Select all

     https://wasm.bbcbasic.co.uk/bbcsdl.html?app=URL_of_web_bundle_file
    
    substituting URL_of_web_bundle_file with the URL of where you have uploaded your .bbb file.
If you are unhappy with any aspect of this post, please report it to the forum administrator (click on the exclamation mark icon in the top-right corner) rather than complaining on the open forum or by private email.