Will FreeBASIC support web?

Emscripten, WASM, and asm.js related questions
song
Posts: 48
Joined: Jan 24, 2006 8:39

Will FreeBASIC support web?

Post by song »

The game made me very surprised. The game was programmed in QB64. However, the game is played on a webpage. The game is not bad and the people left good comments there. QB64 and FreeBASIC are so similar. Will FreeBASIC support web platform in the near future? Was the feature included on the roadmap for FreeBASIC?

https://itch.io/jam/jam-for-all-basic-d ... te/1650199
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Will FreeBASIC support web?

Post by D.J.Peters »

There was a emscripten support for FreeBASIC in the past,
here are Jasc Soccer a Game written in FreeBASIC running in WEB browser.

https://www.freebasic.net/temp/js-JascSoccer/main.html
(use the cursor keys to select the play menu)

viewtopic.php?p=215212

Joshy
caseih
Posts: 2159
Joined: Feb 26, 2007 5:32

Re: Will FreeBASIC support web?

Post by caseih »

The game you linked to was originally developed in QB64, but for web-based play it is actually run in the QBJS interpreter, which is a QB-compatible interpreter written in Javascript that runs in a browser. If someone made an interpreter for the normal FB dialect in Javascript, you could do the same thing with FB and it would be somewhat fast.

As Joshy said, there once was a backend for the FB compiler that would output WebAssembly through the Emscripten C compiler. However as near as I can tell there are no active maintainers for this port of FB. And it's not clear to me if the graphics part of the runtime library was ever implemented in this port, or if the demos I saw for it used OpenGL directly (which Emscripten supports). Emscripten is under active development, and it is probably the "easiest" method for porting a conventional application, such as a binary compiled by FB, to run directly in a browser. Emscripten does seem to have built-in support for SDL2, which may be what the FB demos used.

I remain skeptical of the utility of WebAssembly in general, and I've yet to see anything made with Emscripten that I'd want to use on a regular basis. For one Emscripten apps are quite slow to load and run. WebAssembly itself is plenty fast, but you end up having to load large wasm libraries to support Emscripten applications that ordinarily would expect a wide variety of DLLs including large standard libraries. This is true of other to-javascript transpilers as well, not just FB. They end up emulating a complete environment to really support a language.

It's a bit bizarre that Javascript, itself an interpreted language, has become a low-level common target for a variety of languages, but here we are.

Some people use FB to make CGI binaries that run a web server. FB can work for this purpose without any changes. However that is backend stuff only, not running in a browser.
coderJeff
Site Admin
Posts: 4354
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Will FreeBASIC support web?

Post by coderJeff »

I don't really work with emscripten much. however, v1ctor's work has been merged in to all fbc releases since fbc 1.08.0.

FWIW, Compiling FB with Emscripten, windows only.
song
Posts: 48
Joined: Jan 24, 2006 8:39

Re: Will FreeBASIC support web?

Post by song »

D.J.Peters wrote: Oct 22, 2022 10:25 There was a emscripten support for FreeBASIC in the past,
here are Jasc Soccer a Game written in FreeBASIC running in WEB browser.

https://www.freebasic.net/temp/js-JascSoccer/main.html
(use the cursor keys to select the play menu)

viewtopic.php?p=215212

Joshy
Thanks for telling me! The soccer game is nice. Good job!
:P
song
Posts: 48
Joined: Jan 24, 2006 8:39

Re: Will FreeBASIC support web?

Post by song »

caseih wrote: Oct 22, 2022 14:54
The game you linked to was................
......................................................
......................................................
......................................................
......................................................
Wow! You wrote a long post to explain to me in detail. I have learnt a lot. Thank you very much!!!! :)
song
Posts: 48
Joined: Jan 24, 2006 8:39

Re: Will FreeBASIC support web?

Post by song »

coderJeff wrote: Oct 22, 2022 20:47 however, v1ctor's work has been merged in to all fbc releases since fbc 1.08.0.

FWIW, Compiling FB with Emscripten, windows only.
Okay....thanks!
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: Will FreeBASIC support web?

Post by angros47 »

FreeBasic already supports web, through Emscripten: it can compile in synchronous or asynchronous mode (synchronous is faster, but the program has to be event driven, it must not have never ending cycles: asynchronous mode is a bit slower, but usually allows to compile a program with almost no change)

It supports text and graphic mode, and even WebGl (a subset of OpenGL)

About speed, I found on this forum some examples of code written originally in JavaScript, and ported to FreeBasic. I tried to compile them with Emscripten, and to compare them with the original javascript version, and the FreeBasic version was faster (although it had a longer loading time)

Actually, FreeBasic support for web is better than QB64 support, since QB64 itself, as far as I know, does not support web (perhaps the C++ code it emits could be compiled with Emscripten, but as far as I know, no one has tried): the web games have been made with a different software (likely qbjs, that can be found here: https://qb64.com/qbjs.html ) that aims to be compatible with QB64, but is not qb64

In the past, there was also QLOUD, a solution to run QB64 programs on web, that was completely different, since it worked on server, and not on client. As far as I know, it has been abandoned.
caseih
Posts: 2159
Joined: Feb 26, 2007 5:32

Re: Will FreeBASIC support web?

Post by caseih »

The game referenced in the first post was run in QBJS which is an interpreter that runs in the browser. So it was written in QB64, but executed in QBJS.

Simply being able to compile through Emscripten is not enough to qualify as a "web" language. But Emscripten does provide functions to access the browser DOM and the Javascript environment of a page. It's done via the html5.h header file. Or via executing javascript via a function call. So it is definitely possible, but quite clunky. Neither FB nor C was ever meant for running in a browser and doing web stuff. There are far better tools out there! Unless of course your goal is simply to get an old BASIC game or program running in a browser for fun.
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: Will FreeBASIC support web?

Post by angros47 »

I have a question: should perhaps a sub forum be created, under the "Platforms" section, for Emscripten? At the moment many people seem not to even know that such an option exists, having a dedicated section would perhaps help.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Will FreeBASIC support web?

Post by grindstone »

I would support this, but I doubt that it will happen. The maintainers of this forum seem not to be willing (or able) to change anything.
caseih
Posts: 2159
Joined: Feb 26, 2007 5:32

Re: Will FreeBASIC support web?

Post by caseih »

There are only just a very few volunteers doing development work, releases, and managing the forum. So I suspect it's just a matter of limited time and resources more than will.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Will FreeBASIC support web?

Post by grindstone »

It's not my intention to offense anyone, it's only just an observation.

I'm still looking for an opportunity to use FB on Android devices, and Emscripten seems to be a way it can be done.
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: Will FreeBASIC support web?

Post by angros47 »

Actually, one more sub-forum shouldn't mean much extra work for moderators, because the amount of posts would not increase, they would just go to a different place, I assume.

About using FreeBasic on Android, I agree, Emscripten could be the best solution: an alternate solution would be to use the Android NDK, but Google doesn't recommend that, since the resulting code would have to be distributed in several versions (intel 32 and 64, ARM 32 and 64 and so on).

I read some documentation, and I have the impression that NDK is used mostly to create the equivalent of libraries, on Android, and then the code must still be called by a program written in Java or Kotlin (so, even if part of the app were written in FreeBasic, the developer will still have to use these languages). And FreeBasic code cannot be ported to the virtual machine used for Java, since such a virtual machine doesn't support pointers, and has a different memory management.

On the other hand, Emscripten can work on any platform, and code compiled with it should be slower than code compiled with NDK, but faster than code compiled with Java (they both would run on a virtual machine, and in theory Emscripten should be more optimized). Also, it would work on iPhone, too, so it would be possible to write once, and run on all mobile devices.

The most interesting thing is that recent versions of Android support the Progressive Web Apps (PWA), that are apps written exclusively with web tools: basically, they are web pages with some support workers to make them able to work offline, and with a manifest to instruct the browser to add an icon in the main menu. These apps can be run from web without installing (so one can try them easily), or they can be installed once opened (so, no need to pass through the play store and their registration and approval procedure), or can be also distributed through the play store. (Of course, someone anticipated https://xkcd.com/1367/)

To develop Android apps, PWAs made with Emscripten seem a more viable solution than compiling with NDK. Thoughts?
marcov
Posts: 3465
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Will FreeBASIC support web?

Post by marcov »

(Personally I would only add a forum if there are a few regulars clearly working with it. No use in making a forum with heaps of subforums that only have a few initial messages and then only tumbleweed "is this still alive?" kind of messages. )
Post Reply