Web Port of MMBasic (PicoCalc Web emulator)

I spent a good amount of time porting MMBasic to WebAsm and then created a nice user interface for it. You can find it here: MMBasic Web

This is essentially a web emulator for the PicoCalc. It can make it a lot easier to develop basic programs for the PicoCalc. You can drag and drop files into its emulated SD card, edit the files live in the browser, and click a single button to run them in the emulator. This drastically shrinks the debugging loop.

Most things should work in the emulator. GPIO, I2S and other hardware specific stuff does not. MP3 support could work, but is currently unimplemented.

This all started out with an attempt to speed up PicoMite, the primary outcome was ‘FRUN’ (Fast run), which is a bytecode compiler for MMBasic. You can try it out with the ‘lightning’ icon in the web editor. For math intensive tight loops it can be 10x faster (try ‘mand.bas’ with RUN and FRUN to compare). FRUN might not work on a given program, if so, let me know and I might fix it.

I also created a new ‘FASTGFX’ graphics primitive that can drive games at about 50fps. In the web emulator they don’t do much, as it’s so much faster than a real pico, but on a real device it uses double buffering and DMA to make screen updates much faster. Try out ‘pico_blocks.bas’, it should perform about the same in the emulator as it does on real hardware, even an RP2040 (note, this requires the PicoCalc has the firmware from my Repo, see below).

If things run too fast in the emulator, edit the config and change the slowdown option until your program performs about the same on device as it does in the emulator.

You can find the source here: GitHub - jvanderberg/PicoMiteAllVersions: This contains files to build MMbasic to run on both RP2040 and RP2350 · GitHub . You can actually build this to create firmware for the PicoCalc with the FASTGFX and bytecode VM - but it’s a bit of a mess right now.

You can get the uf2’s from here if you want to try FASTGFX or the bytecode compiler: Release Latest build · jvanderberg/PicoMiteAllVersions · GitHub

9 Likes

Some other screenshots, the MMBasic internal editor

‘Blocks’ game running at 50fps:

The web editor:

1 Like

This is great! One of the things I found really frustrating with MMBasic on the PicoCalc was how cumbersome it was to write code on the desktop and then transfer files for testing. Your WebAsm port and enhancements make for an excellent development environment, and easier testing.

A few notes:

In the about page you have: “The PicoCalc build used here tracks Craig Madcock’s madcock/PicoMiteAllVersions.” I don’t know where “Craig Madcock” came from, but I’m Michael Adcock, (madcock on github). :slight_smile:

That code in my repo hasn’t been updated in quite a while, and I wasn’t really planning on maintaining it further, especially since the official releases now support PicoCalc builds. So it’s still stuck back at an earlier version of PicoMite MMBasic. At the time I last updated it, the version was newer than the original offering from Clockwork, with their changes and a few other things merged into the (official PicoMite) UKTailwind sources. But it’s well out of date now, and thanks to @ernst’s efforts, the official UKTailwind sources provide PicoCalc builds too. All this is to say that you may want to consider updating your WebAsm version to bring it in line with the official sources instead of my repo. Based on my experience, it seems like PicoMite users have always been keen on having access to the latest version. Trying to keep up with the official updates is often a chore though.

The FASTGFX and bytecode compiler sounds like something that should eventually make their way into the offiical release of PicoMite, assuming Peter and TheBackShed folks are interested and willing (which might be assuming a lot!) I haven’t actually played around with FASTGFX on my PicoCalc yet, but I’m looking forward to it.

I had all but given up on using PicoMite for game development on PicoCalc due to its poor speed, but it sounds like you’ve improved things considerably! Nice.

Sorry about the name. I will fix that. I cloned this repo long ago and made the mistake of not checking before I embarked on extending it. So it looks like I might have a lot of work getting it up to date. I think there was a reason I picked yours, maybe psram support? Not sure. Or maybe you had uf2 builds?

The core performance improvement is FASTGFX. The byte code compiler is important for long running compute intensive loops, which games tend not to have. It helps a ton for stuff like the Mandelbrot viewer. I also tried to backport the fastgfx stuff to the FRAMEBUFFER code but couldn’t get the same result. It’s just doing more.

Unfortunately the original code base is not well structured for the bytecode and webasm work. There are monolithic files where the core interpreter is mixed with the hardware abstraction layer. I tried to break things apart, had a little success with that but then fell back to #ifdef. Ideally MMBasic would have a single repo with different hardware abstraction layers.

I think one of the core improvements here actually goes unmentioned in my post. I got the interpreter and graphics stack running natively on the host, as a precondition for running it in webasm, so there’s a full test suite that runs locally on the developer’s machine. That was a massive help in validating the bytecode compiler.

One ‘fudge’ in the web emulator is that it doesn’t properly implement fastgfx stuff, because it doesn’t need to. The web is super fast. So about all the fastgfx code does there is implements a frame per second blocking call on ‘swap’. A FRAMEBUFFER game would probably be even faster in the web emulator. I’d probably need to throttle graphics throughput if want to properly simulate on device behavior.

considering the presence of a CLAUDE.md file, i can wager a guess

That was my hallucination, fixed.

1 Like