Menu
JAQForum Ver 26.09

Forum Index : Microcontroller and PC projects : PicoMite - integrated compact C-compiler / C-runtime

   Page 5 of 6    
Posted: 11:44pm
13 Nov 2026
Copy link to clipboard
MikeV73
Regular Member

  toml_12953 said  
  MikeV73 said  + RC5 (based on PicoMite V7.00.00RC9): https://github.com/DnCraptor/pico-mm/releases/tag/PicoMite-V7.0.00b9-tcc-elf-RC5


Thank you! There shouldn't be too many revisions left before the final.


I guess, finally it will be included into main repo ))
https://github.com/UKTailwind/PicoMite/pull/152 - PR to original repo. Not sure, UKTailwind plans about it.
Also, it may be just rejected ¯\_(ツ)_/¯
Edited 2026-11-14 09:44 by MikeV73
 
Posted: 10:04am
14 Nov 2026
Copy link to clipboard
Frank N. Furter
Guru

Thank you so much for the great update!
I went ahead and updated my PicoCalc right away.

Frank
 
Posted: 08:35pm
14 Nov 2026
Copy link to clipboard
ville56
Guru

Great work MikeV73, runs flawlessly. Plese continue support for new versions from Peter. Many thanks,

Gerald
 
Posted: 05:29pm
15 Nov 2026
Copy link to clipboard
bfwolf
Senior Member

Do you think it might be possible to integrate SQLite into your PicoMite version via a CSUB — much like Peter has managed to do for the CMM2 — perhaps by using a precompiled .elf file?

I think it would be fantastic if Peter accepted your PR and the C extension made it into the mainline!
 
Posted: 06:33pm
15 Nov 2026
Copy link to clipboard
matherp
Guru

Thanks to everyone who has asked about the C compiler in Mike's pico-mm fork, and thanks to Mike (DnCraptor on GitHub) for doing it. Getting TinyCC to compile and run C on the PicoMite itself, with C CSUBs built from source, a loader for ELF objects and a large API into the firmware, is an impressive piece of work, and a lot of it went in very quickly.

I've had a proper look, and I've decided not to bring it into the standard MMBasic/PicoMite firmware. That isn't a judgement on Mike's work. It's about what the standard firmware is for, and who pays for what.

Everyone would pay for it
• It adds about 285KB of flash to every RP2350 build and about 73KB to every RP2040 build. The RP2040 gets the loader and the API but no compiler.
• To make room, the flash layout has to move on every build. Updating would reset everyone's options, and on the RP2040 the A: drive and the library would be wiped and come back about 96KB smaller.
• On the WebMite and Bluetooth RP2350 builds, boards without PSRAM would lose some of the flash that OPTION COMPILE ON uses, so the largest programs could no longer be compiled.
Those figures come from the fork's own build notes, compared with the RC9 builds.

Few could use it
In practice the compiler needs PSRAM, and the fork's own documentation says so. Most boards would carry the cost of a feature they can't really use.

MMBasic is a BASIC
Part of MMBasic's appeal is that a mistake in a program gives you an error message, not a crashed machine. C running natively inside the firmware doesn't work that way. CSUBs already allow it, but they're a deliberate route for people who know what they're doing, not something you get by typing RUN "x.c". Where I've done C myself, on the PC3 under Fuzix and on the CMM2, the compiler is a separate program rather than part of the firmware, and I think that's the right shape for it.

Looking after it
Besides the compiler, the fork reworks a good deal of the interpreter's own code and adds an API that's already at version 35. Anything in the standard firmware is something I have to keep working, document and answer questions about in every release, and I can't take on something this size alongside MMBasic itself.

So, use the fork
None of this stops anyone using it; that's what forks are for. If you want C on the board, try pico-mm and report back to Mike. I'd really encourage Mike to keep it merged with each of my releases so it stays current: it's based on the source from 3 November, and quite a lot has changed since.

Thanks again, Mike. It's an interesting project and I hope it keeps going.
 
Posted: 07:28pm
15 Nov 2026
Copy link to clipboard
PhenixRising
Guru

  matherp said   I hope it keeps going.


X 1,000,000  
 
Posted: 08:32pm
15 Nov 2026
Copy link to clipboard
bfwolf
Senior Member

  matherp said  Thanks to everyone who has asked about the C compiler in Mike's pico-mm fork, and thanks to Mike (DnCraptor on GitHub) for doing it. Getting TinyCC to compile and run C on the PicoMite itself, with C CSUBs built from source, a loader for ELF objects and a large API into the firmware, is an impressive piece of work, and a lot of it went in very quickly.

I've had a proper look, and I've decided not to bring it into the standard MMBasic/PicoMite firmware. That isn't a judgement on Mike's work. It's about what the standard firmware is for, and who pays for what.

Everyone would pay for it
• It adds about 285KB of flash to every RP2350 build and about 73KB to every RP2040 build. The RP2040 gets the loader and the API but no compiler.
• To make room, the flash layout has to move on every build. Updating would reset everyone's options, and on the RP2040 the A: drive and the library would be wiped and come back about 96KB smaller.
• On the WebMite and Bluetooth RP2350 builds, boards without PSRAM would lose some of the flash that OPTION COMPILE ON uses, so the largest programs could no longer be compiled.
Those figures come from the fork's own build notes, compared with the RC9 builds.
...


I understand your reasoning and arguments, and I largely agree with them: including a C compiler by default doesn't make much sense, as it would add a significant amount of code to the binary — thereby noticeably shrinking the space available on drive A:, at least on the Pico1 or RP2040 boards, which only have 2MB of flash. Furthermore, a C compiler is "fairly pointless" without PSRAM; while it might be able to compile simple "Hello, World!" programs, any serious application would quickly hit its limits.

Regarding the RP2350, I would be in favor of including an .elf loader, provided the overhead isn't too great. This would allow .elf files to be generated — either on boards equipped with PSRAM (using the version from the fork) or via a cross-compiler running on Linux, Windows, etc.

However, I’m not sure how much additional code an .elf loader and a C runtime would actually require. Is it the 73kB you mentioned for the RP2040? On the RP2350, which has at least 4MB of flash, that would certainly be an acceptable trade-off. On the RP2040, it would simply have to be omitted — as is the case with "minimal" builds anyway.

  matherp said  ...
So, use the fork

None of this stops anyone using it; that's what forks are for. If you want C on the board, try pico-mm and report back to Mike. I'd really encourage Mike to keep it merged with each of my releases so it stays current: it's based on the source from 3 November, and quite a lot has changed since.

Thanks again, Mike. It's an interesting project and I hope it keeps going.


I intend to keep using this fork, and I truly hope that MikeV73 continues working on it! It works perfectly on the Pimoroni Pico+2, and even without PSRAM, you can load and execute .elf files directly! Kudos for the work! And, once again, many thanks for your own contributions as well, Peter!

Regards, bfwolf
 
Posted: 09:17pm
15 Nov 2026
Copy link to clipboard
PhenixRising
Guru

Although I confess to only limited testing, thus far, the RP2350B-DIL without PSRAM works just fine. I simply translate a few small functions where the fastest execution can benefit the overall performance. Many areas, I would only be "waiting faster". Loving this stuff  
 
Posted: 10:05pm
15 Nov 2026
Copy link to clipboard
MikeV73
Regular Member

Actually .elf-loader may be optimized by size. It was not my initial goal... so, the size of impl. was not in the priority.

About API and TCC... I guess, it is possible to provide it as separate .bas-file (with CSUB really implemeting the tcc).
 
Posted: 04:45am
16 Nov 2026
Copy link to clipboard
toml_12953
Guru

How is pm_timer_us supposed to work? In the following program (hat.c) the hat is drawn properly but I am trying to display the run time and I keep getting 0. How should I be doing it?

#include <stdio.h>
#include <math.h>
#include <picomite.h>
int main(void)
{
   unsigned long long m=pm_timer_us();
   pm_cls(PM_BLACK);
   int p=160, q=160, zi;
   double xp=144, xr=1.5*3.1415927;
   int yp=56, yr=1, zp=64;
   double xf=xr/xp, yf=yp/yr, zf=xr/zp;

   for (zi = -q; zi <= q - 1; zi++) {
       double zt,zz;
       int xx,xl,xi;
       if (zi < -zp || zi > zp)
           continue ;
       zt=zi*xp/zp; zz=zi;
       xl=floor(0.5+sqrt(xp*xp-zt*zt));
       for (xi=-xl; xi<=xl; xi++) {
           double xt,yy,x1,y1;
           xt=sqrt(xi*xi+zt*zt)*xf; xx=xi;
           yy=(sin(xt)+0.4*sin(3*xt))*yf;
           x1=xx+zz+p;
           y1=320-(yy-zz+q);
           pm_pixel(x1, y1, PM_WHITE);
           if (y1 != 320)
               pm_line(x1,y1+1,x1,320-1,1,PM_BLACK);
       }
   }
   m=pm_timer_us()-m;
   printf("Time: %5u seconds\n",m);
}


I managed to solve the problem. Here's what I did at the end of the program:

m=pm_timer_us()-m;
double n=m/1000000.0
printf("Time: %f seconds\n",n);

Edited 2026-11-16 15:16 by toml_12953
 
Posted: 01:39pm
16 Nov 2026
Copy link to clipboard
JohnS
Guru

Looks like %u needed one or more l as m is not an unsigned int (it's much "longer").

John
 
Posted: 03:19pm
16 Nov 2026
Copy link to clipboard
MikeV73
Regular Member

Reviewed.

`pm_timer_us()` is working correctly. I've checked the implementation: it returns a 64-bit `unsigned long long` value in microseconds.

As JohnS pointed out, `%u` expects a 32-bit `unsigned int`, so the format specifier is incorrect.

To display microseconds:
printf("Time: %llu us\n", m);


Or seconds:
printf("Time: %.3f seconds\n", (double)m / 1000000.0);


No firmware changes are needed. I'll add an example to the API documentation to avoid confusion.
 
Posted: 05:37pm
16 Nov 2026
Copy link to clipboard
toml_12953
Guru

  MikeV73 said  Reviewed.

`pm_timer_us()` is working correctly. I've checked the implementation: it returns a 64-bit `unsigned long long` value in microseconds.

As JohnS pointed out, `%u` expects a 32-bit `unsigned int`, so the format specifier is incorrect.

To display microseconds:
printf("Time: %llu us\n", m);


Or seconds:
printf("Time: %.3f seconds\n", (double)m / 1000000.0);


No firmware changes are needed. I'll add an example to the API documentation to avoid confusion.


Yeah, I found out how to do it. I listed the correction in a footnote. I'm really disappointed that your wonderful effort won't be included in the mainstream builds. I hope you'll keep making it available on your own, though. It's too valuable to lose!
 
Posted: 05:48pm
18 Nov 2026
Copy link to clipboard
bfwolf
Senior Member

I just took a look at the documentation for your fork in the file "PicoMite-native-C-support.md":

<picomite/memory.h>

void *pm_alloc(size_t size, int where);  /* PM_MEM_ANY, PM_MEM_SRAM, PM_MEM_PSRAM */
void  pm_free(void *p);
int   pm_mem_where(const void *p);       /* PM_MEM_SRAM, PM_MEM_PSRAM or 0 */
int   pm_get_mem_info(pm_mem_info *m);   /* SRAM and PSRAM: total and free */

   pm_alloc takes a zeroed block straight from the MMBasic heap, so the program chooses where it goes. Use PSRAM for big buffers, and SRAM for speed or for anything DMA reads.
   Blocks are whole 256-byte pages, so use it for buffers and malloc() for small objects.
   Like malloc() memory, every block is given back when the program ends.
   NULL means there is no room where asked.
   Not available in a C CSUB.


Why are the "pm_alloc/pm_free" functions from MMBasic not available within CSUBs?

It would be a pity if that were the case — or if it were to remain so. If one had access to "pm_alloc/pm_free" in conjunction with MMBasic, one could define a large structure for "global" or "static" variables and request the necessary memory using "pm_alloc()":

struct globals_s {
 uint32_t counter;
 uint32_t values[100];
 // ...
};

int doSomeThing(void)
{
 struct globals_s *globals = pm_alloc(sizeof(struct globals_s));
 ; // do some things..
 globals->counter = 0;
 globals->values[0] = 1234;
 pm_free(globals );
}


I just noticed that in "PicoCFunctions.h", there is:
#define GetMemory(a) ((void *(*)(int))Vector_GetMemory)(a)

Would this provide the required functionality?
The documentation states that everything in "PicoCFunctions.h" is accessible within CSUBs, right?

Regards, bfwolf.
 
Posted: 06:45pm
18 Nov 2026
Copy link to clipboard
MikeV73
Regular Member

  bfwolf said  ...
Would this provide the required functionality?
The documentation states that everything in "PicoCFunctions.h" is accessible within CSUBs, right?

Regards, bfwolf.


You're right — `GetMemory()` and `FreeMemory()` from `PicoCFunctions.h` are available to CSUBs, and your example is a valid use case.

The restriction applies specifically to `pm_alloc()` / `pm_free()`, which belong to the native C `RUN` runtime. They track allocations and automatically release them when the C program ends. A CSUB has no such runtime allocation scope.

`GetMemory()` and `FreeMemory()` use the MMBasic heap directly, so they can be used from a CSUB to allocate temporary structures.

There are a few differences:
- Memory must be explicitly freed.
- SRAM/PSRAM placement cannot be selected explicitly.
- Allocation failure raises an MMBasic error rather than returning NULL.
- Allocations do not survive a BASIC heap reset.

So for your example, using `GetMemory(sizeof(struct globals_s))` and `FreeMemory(globals)` is perfectly reasonable.

The documentation should clarify this distinction (will do). Thanks for pointing it out!
 
Posted: 01:01am
19 Nov 2026
Copy link to clipboard
MikeV73
Regular Member

 
Posted: 08:57am
19 Nov 2026
Copy link to clipboard
bfwolf
Senior Member

I was wondering yesterday whether there might be a "hook" for callbacks in MMBasic that would be triggered automatically upon the next "RUN" command. This could be used to execute "FreeMemory()" — in case any memory requested within a CSUB needs to be released after the calls are finished. However, I didn't find anything of the sort while reading through "PicoCFunctions.h".

Alternatively, could it be that memory requested via "GetMemory()" is automatically "cleaned up" — i.e., released—the next time the "RUN" command is issued? If so, that would make it possible to create "static objects" within CSUBs.

Does the new "PicoMite-V7.00.00-tcc-elf-RC6" build rely on Peter's "PicoMite-V7.00.00"? If that’s the case, perhaps you’ll be ready to issue a formal release soon, provided no critical bugs surface in the meantime?

Regards, bfwolf.
 
Posted: 11:01am
19 Nov 2026
Copy link to clipboard
MikeV73
Regular Member

  bfwolf said  I was wondering yesterday whether there might be a "hook" for callbacks in MMBasic that would be triggered automatically upon the next "RUN" command. This could be used to execute "FreeMemory()" — in case any memory requested within a CSUB needs to be released after the calls are finished. However, I didn't find anything of the sort while reading through "PicoCFunctions.h".

Alternatively, could it be that memory requested via "GetMemory()" is automatically "cleaned up" — i.e., released—the next time the "RUN" command is issued? If so, that would make it possible to create "static objects" within CSUBs.

Does the new "PicoMite-V7.00.00-tcc-elf-RC6" build rely on Peter's "PicoMite-V7.00.00"? If that’s the case, perhaps you’ll be ready to issue a formal release soon, provided no critical bugs surface in the meantime?

Regards, bfwolf.


Yes, `GetMemory()` allocations are reclaimed automatically on the next BASIC `RUN`.

I checked the actual implementation: `RUN` calls `ClearRuntime(true)`, which calls `InitHeap(true)`. This resets the MMBasic heap allocation bitmap (and the corresponding PSRAM allocation bitmap), making all previously allocated blocks available again.

So there is no need for a special callback just to call `FreeMemory()` before the next `RUN`.

However, the allocated blocks remain in use until explicitly freed or until the heap is reset. Any saved pointers become invalid after that reset.

One additional limitation: ordinary C CSUBs cannot contain writable static/global variables (`.bss`). You can allocate a structure dynamically with `GetMemory()`, but you need to keep its pointer somewhere appropriate, for example in a BASIC variable.

And yes, RC6 is based on Peter's PicoMite V7.00.00, merged with the native C/TCC/ELF extensions. All 24 firmware variants have compiled successfully. A final release is the next logical step once regression testing is satisfactory.

WBR. MikeV73.
 
Posted: 01:48pm
19 Nov 2026
Copy link to clipboard
bfwolf
Senior Member

  MikeV73 said  ...
Yes, `GetMemory()` allocations are reclaimed automatically on the next BASIC `RUN`.

I checked the actual implementation: `RUN` calls `ClearRuntime(true)`, which calls `InitHeap(true)`. This resets the MMBasic heap allocation bitmap (and the corresponding PSRAM allocation bitmap), making all previously allocated blocks available again.

So there is no need for a special callback just to call `FreeMemory()` before the next `RUN`.


That sounds good so far!

  MikeV73 said  
However, the allocated blocks remain in use until explicitly freed or until the heap is reset. Any saved pointers become invalid after that reset.

One additional limitation: ordinary C CSUBs cannot contain writable static/global variables (`.bss`). You can allocate a structure dynamically with `GetMemory()`, but you need to keep its pointer somewhere appropriate, for example in a BASIC variable.


I suppose this is the classic "chicken-and-egg" problem.

The classical way in C
static struct globals_s *globals = GetMemory(sizeof(struct globals_s));

won't work, then.

So, one should first use `pm_var()` to check whether the variable already exists. If it does, use the returned existing pointer; if not, create it using `pm_dim()` and store the result from `GetMemory()` there as a "long long".

  MikeV73 said  And yes, RC6 is based on Peter's PicoMite V7.00.00, merged with the native C/TCC/ELF extensions. All 24 firmware variants have compiled successfully. A final release is the next logical step once regression testing is satisfactory.

WBR. MikeV73.


I look forward to it!
Regards
 
Posted: 01:55pm
19 Nov 2026
Copy link to clipboard
MikeV73
Regular Member

  bfwolf said  ...


Yes, that approach should work, with two small corrections.

First, `pm_var()` raises an MMBasic error if the variable doesn't exist; it doesn't return NULL. So you would need to handle that error (using `pm_try()`) before calling `pm_dim()`, or simply declare the variable in BASIC beforehand.

Second, `static struct globals_s *globals = GetMemory(...)` wouldn't be valid even in ordinary C, since a static initializer must be a constant expression.

But the general idea is correct: store the pointer returned by `GetMemory()` in a BASIC INTEGER variable, then retrieve it on subsequent CSUB calls through `pm_var()`.

The BASIC INTEGER is 64-bit, so it can hold a 32-bit RP2040/RP2350 pointer without loss.

Both the stored pointer and the allocated structure belong to the current BASIC runtime. They become invalid when the heap is reset by the next RUN.

So this effectively provides dynamically allocated state shared between CSUB calls, without needing writable static variables inside the CSUB itself.
 
   Page 5 of 6    
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026