Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:02 21 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : The MMBasic API : www.mmbasic.org

     Page 1 of 2    
Author Message
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 11:53am 03 Aug 2015
Copy link to clipboard 
Print this post

MMBasic Version 4.7 now exposes many of its internal functions via an Application Programmers Interface, "API", for use from CFunctions - http://www.mmbasic.org

Using the MMBasic API, CFunctions can for example

o Manipulate the I/O pins in EXACTLY the same way as an MMBasic program by
calling the exact same internal MMBasic Interpreter functions as used for
MMBasic code
o Use functions such as MALLOC/FREE
o Perform floating point operations including
roots, powers, trig. & log. functions
o Perform precise micro second accurate delays

It cannot be stressed enough just how significant and important the provision of the MMBasic API is to the future of MMBasic+CFunctions. The User Loadable Display Drivers, and User Loadable Fonts are just the first 2 examples of how the API enables deep integration of user written CFunctions with the core of the MMBasic Interpreter to extend MMBasic's capabilities.

To accompany the release of the MMBasic API, comprehensive online documentation and example code for each MMBasic API call may be found at http://www.mmbasic.org

The CFunction Tutorials document will be updated to include a chapter(s) covering the MMBasic API, but the online documentation and examples are very extensive and should provide a good starting point.

The MMBasic API is common across both MM and MM+ platforms.

Please remember, MMBasic 4.7 is still in the beta phase, so things can and probably will change before the final production release.

Peter
The only Konstant is Change
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10281
Posted: 08:01am 04 Aug 2015
Copy link to clipboard 
Print this post

BUMP!!

Peter has put a huge amount of work into the whole CFunction concept and it increases the possibilities for the Micromite to an extraordinary extent.

Please take the time to visit his site and read the superb document he has written as an introduction to writing CFunctions.

Please don't be put off by "C". I had never programmed in "C" before working on the Micromite and my "C" is still largely syntax converted Basic - but it works!.

My way in was the early versions of Peter's document, the current version is even more accessible.

If you can program in Basic then with a bit of effort and reference to Peter's documentation you can write CFunctions to interact with the Micromite hardware and software and where necessary overcome the limitations of the interpreted language whilst benefiting from its advantages.

Give it a go and experience the satisfaction from learning something new and doing something you couldn't do before
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 08:28am 04 Aug 2015
Copy link to clipboard 
Print this post

Thank You PeterM.

For a "C novice" you put us all to shame. Without your pioneering work with the Displays and CFunctions, the Micromite would be a very much diminished environment. The difference between 4.6 and 4.7 is like night and day, and a great deal of that is down to your tireless efforts (which I find quite exhausting just to follow !)

If nothing else, could I please ask that people at least download http://www.mmbasic.org/tutorials/pic32/MMBasicCFunctions_PIC32.pdf and take a look at the chapter "C For MMBasic Programmers" which attempts to help MMBasic programmers translate/transfer their MMBasic skills and knowledge over to C. As PeterM says, there is nothing wrong with "largely syntax converted Basic - but it works!", and once you get going, you'll wonder what all the fuss and bother was all about !

PeterC

The only Konstant is Change
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 08:52am 04 Aug 2015
Copy link to clipboard 
Print this post

  G8JCF said   If nothing else, could I please ask that people at least download http://www.mmbasic.org/tutorials/pic32/MMBasicCFunctions_PIC32.pdf and take a look at the chapter "C For MMBasic Programmers" which attempts to help MMBasic programmers translate/transfer their MMBasic skills and knowledge over to C. As PeterM says, there is nothing wrong with "largely syntax converted Basic - but it works!", and once you get going, you'll wonder what all the fuss and bother was all about !

PeterC

You talked me into it. I'm now at page 12 and reading. I like your writing style. So far, I haven't seen any grammatical or spelling clangers. This is rare in business and technical writing and correspondence these days.

Thanks for your efforts Peter.
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 08:58am 04 Aug 2015
Copy link to clipboard 
Print this post

Excellent! Finally the future past is now
I can see this working in a really usable system
http://rittle.org

--------------
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 328
Posted: 09:17am 04 Aug 2015
Copy link to clipboard 
Print this post

I downloaded the files yesterday. C and I have never been able to work together, but I'm willing to take another shot.

--Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 12:12pm 04 Aug 2015
Copy link to clipboard 
Print this post

Thanks Guys

Bob, Hopefully the style and pace, makes the subject matter more approachable and less daunting. I try to write as though I was in the readers shoes and try to see things from the readers perspective. As for spelling, and grammatical errors hopefully you'll ignore the way I write eg, ie - Spelling checkers and I have a long running battle on these !

Curtis, Writing a whole C program is a lot tougher than writing a CFunction. All the I/O is done via MMBasic, with the CFunction just doing the crunching. All that stuff about main(), #includes, #defines, linkers and so on, are really background things with CFunctions. Of course once you start writing complex CFunctions, referred to as "Merge CFunctions" in CFunction terminology, then you will start to become more aware of some of those "C ish" things.

kiid, you're a C person so U should be right at home now, but bear in mind that you can't declare variables outside functions - but see MALLOC for how to allocate and use memory which persists between calls.

Happy Reading, and hopefully a CFunction or two in the not too distant future

Peter
The only Konstant is Change
 
piclover
Senior Member

Joined: 14/06/2015
Location: France
Posts: 134
Posted: 01:56pm 04 Aug 2015
Copy link to clipboard 
Print this post

I was wondering if it would be possible to add long long int division to the API, because currently, when attempting a long long int divide operation within a CFunction, the compiler generates a (rather large) divide function which fails to run (generating an exception) after conversion by CFuncGen (probably a position dependent code issue)...

Oh, also, would it be possible to get a Linux version of CFuncGen4PIC32, sometime ?... It works under Wine, but if at all possible, a native Linux (or Mono) version would be so much better. :-)
Addendum/Edit: I also tried CFuncGenV2, but it generates an exception on startup, which may be ignored when ran under Windows, but not under Mono...Edited by piclover 2015-08-06
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 03:24pm 04 Aug 2015
Copy link to clipboard 
Print this post

@piclover

Well blow me down with a feather ! It doesn't work !

CPU exception #13 (possible divide by zero) at address 0x9D000FB8
Processor restarted


I'll have to investigate why not, this is all pure integer arithmetic so there shouldn't be anything clever going on.

Thanks for the report.

Re Linux/Mono/CFuncGen, CFuncGen is written in VB.NET, and afaik mono on LINUX doesn't support VB.NET programs - I get startup error to do with can't find entry point if I recall from last time I tried - perhaps one of the LINUX gurus can assist here and explain if/how to get VB.NET assemblies working under MONO.

Edit : As a workaround I have found that casting the arguments to int does work but of course that's only good enough for 32 bit numbers, eg
long long longlongdivide(long long *a, long long *b){

int c;

c = (int) *a / (int) *b;

return (long long)c;

}


and

a%=123456789
b%=23

Result%=LongLongDivide(a%,b%)

PRINT Result%



'******************************************************************************
'
'----------> PIC32 <----------
'
'C:\MyMicromiteProjects\PicLoverDivideTest.X\dist\default\production\longlongdivide.bas
'
'longlongdivide
'Created : 2015-08-05 01:29:05 UTC
'Author : Peter Carnegie
'Generator : CFuncGen Ver 2.1.5.0
'
CFUNCTION longlongdivide
00000000
8c820000 8ca30000 0043001a 006001f4 00001012 03e00008 00021fc3
END CFUNCTION 'MIPS32 M4K
'
'******************************************************************************

> Run
5367686
>



PeterEdited by G8JCF 2015-08-06
The only Konstant is Change
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9603
Posted: 03:36pm 04 Aug 2015
Copy link to clipboard 
Print this post

  kiiid said   Excellent! Finally the future past is now.




I love that.

I will download and have a read of the document, as "C" has always scared me off for years. I know well it's raw speed advantages over interpreted, but I still prefer the more user-friendly BASIC enviroment!

Perhaps I will have a dabble in Cfunctions to see if I can make something work.
Smoke makes things work. When the smoke gets out, it stops!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10281
Posted: 09:16pm 04 Aug 2015
Copy link to clipboard 
Print this post

  Quote  Well blow me down with a feather ! It doesn't work !


Also << doesn't work

HOWEVER:

As a matter of practice I convert all long long to int before using them. This dramatically reduces code size and speeds execution


long long myCfunction(long long *a, long long *b){
int aa=*a,bb=*b,c;
//do something to create c
return (long long)c;
}
 
piclover
Senior Member

Joined: 14/06/2015
Location: France
Posts: 134
Posted: 11:21pm 04 Aug 2015
Copy link to clipboard 
Print this post

  G8JCF said   @piclover

Well blow me down with a feather ! It doesn't work !

CPU exception #13 (possible divide by zero) at address 0x9D000FB8
Processor restarted


I'll have to investigate why not, this is all pure integer arithmetic so there shouldn't be anything clever going on.

Thanks for the report.[/quote]
Welcome :-)

[quote]Re Linux/Mono/CFuncGen, CFuncGen is written in VB.NET, and afaik mono on LINUX doesn't support VB.NET programs - I get startup error to do with can't find entry point if I recall from last time I tried[/quote]
Mono is alas the only solution (beside a VBox/VMware virtual machine) to run a .NET v4 program under Linux, because Wine only supports .NET v2...

[quote]perhaps one of the LINUX gurus can assist here and explain if/how to get VB.NET assemblies working under MONO.[/quote]I suppose that adding the DLL corresponding to the missing entry point to the application folder would work... VB runtime DLL, perhaps ?...

Note that in the case of CFuncGenV2, I *also* get an exception under Windows when starting it (a dialog appears and allows me to ignore that exception however), so I assumed that was the reason why I couldn't run it with Mono under Linux...

Here is the exception text:
System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
à CFuncGen.frmMain.frmMain_Load(Object sender, EventArgs e)
à System.EventHandler.Invoke(Object sender, EventArgs e)
à System.Windows.Forms.Form.OnLoad(EventArgs e)
à System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
à System.Windows.Forms.Control.CreateControl()
à System.Windows.Forms.Control.WmShowWindow(Message& m)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.Form.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Assemblys chargés **************
mscorlib
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
CFuncGen
Version de l'assembly : 2.1.5.0
Version Win32 : 2.1.5.0
CodeBase : file:///C:/Program%20Files%20(x86)/CFuncGen/CFuncGen.exe
----------------------------------------
Microsoft.VisualBasic
Version de l'assembly : 10.0.0.0
Version Win32 : 12.0.51209.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.Visua lBasic.dll
----------------------------------------
System
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34238 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34251 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Fo rms.dll
----------------------------------------
System.Drawing
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34245 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime .Remoting.dll
----------------------------------------
System.Configuration
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configurat ion.dll
----------------------------------------
System.Xml
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34234 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Accessibility
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Windows.Forms.resources
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/Syste m.Windows.Forms.resources.dll
----------------------------------------
Microsoft.VisualBasic.resources
Version de l'assembly : 10.0.0.0
Version Win32 : 12.0.51209.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic.resources/v4.0_10.0.0.0_fr_b03f5f7f11d50a3a/Mic rosoft.VisualBasic.resources.dll
----------------------------------------
mscorlib.resources
Version de l'assembly : 4.0.0.0
Version Win32 : 4.0.30319.34209 built by: FX452RTMGDR
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/mscorlib.resource s.dll
----------------------------------------


[quote]Edit : As a workaround I have found that casting the arguments to int does work but of course that's only good enough for 32 bit numbers,[/quote]
LOL, yes, thanks, but I know how to optimize a program, when at all possible... If I used long long ints, it's because I did need them... So no, it's not a solution in this case.Edited by piclover 2015-08-06
 
piclover
Senior Member

Joined: 14/06/2015
Location: France
Posts: 134
Posted: 11:41pm 04 Aug 2015
Copy link to clipboard 
Print this post

  matherp said  As a matter of practice I convert all long long to int before using them. This dramatically reduces code size and speeds execution


Thank you, but just to give you a little idea about my programming skills, I wrote my very first program (on a 6800, directly in machine code) 38 years ago... I never stopped programming since that time, on numerous processors, systems, in numerous languages...
Such trivial remarks about obvious optimizations are therefore totally superfluous.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10281
Posted: 11:57pm 04 Aug 2015
Copy link to clipboard 
Print this post

  Quote  Such trivial remarks about obvious optimizations are therefore totally superfluous


This thread is aimed at all MM users many of whom have not got your experience. If my comments aren't useful to you then it would be courteous to ignore them rather than posting a rude response
 
piclover
Senior Member

Joined: 14/06/2015
Location: France
Posts: 134
Posted: 12:05am 05 Aug 2015
Copy link to clipboard 
Print this post

  matherp said  This thread is aimed at all MM users many of whom have not got your experience. If my comments aren't useful to you then it would be courteous to ignore them rather than posting a rude response


1.- You were replying to me. How could I not take it for myself ?

2.- My reply is not rude. I even added a smiley to avoid making it so.

3.- If you are *that* susceptible, then you should perhaps think twice before assuming people posting in this forum are total noobs, because then you might hurt them with your remarks... Don't do to others what you don't want them to do to you... THAT's, also, courtesy.Edited by piclover 2015-08-06
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9603
Posted: 12:07am 05 Aug 2015
Copy link to clipboard 
Print this post

Agreed. A little over the top on the smug-o-meter there, piclover. How the hell was matherp supposed to know about your experience beforehand?
Smoke makes things work. When the smoke gets out, it stops!
 
piclover
Senior Member

Joined: 14/06/2015
Location: France
Posts: 134
Posted: 12:11am 05 Aug 2015
Copy link to clipboard 
Print this post

  Grogster said   Agreed. A little over the top on the smug-o-meter there, piclover. How the hell was matherp supposed to know about your experience beforehand?
See #3 in my reply above.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10281
Posted: 12:25am 05 Aug 2015
Copy link to clipboard 
Print this post

  Quote  You were replying to me. How could I not take it for myself ?


If you read my post carefully you will see I was replying to a quote from G8JCF, not you, and pointing out another issue with long longs. I then added a general comment to all on the board about the use of long longs.You may think the world revolves around you but please consider that this thread was specifically intended to get more Basic programmers to have a go at Cfunctions. Many thanks for highjacking the thread and undermining G8JCF's efforts.

 
piclover
Senior Member

Joined: 14/06/2015
Location: France
Posts: 134
Posted: 12:45am 05 Aug 2015
Copy link to clipboard 
Print this post

  matherp said  Many thanks for highjacking the thread and undermining G8JCF's efforts.

I find it amazing how some people can put the responsibility of their own fault onto others...
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4039
Posted: 01:54am 05 Aug 2015
Copy link to clipboard 
Print this post

piclover - you just have to get used to it here. Bad assumptions will be made and no apology given. It's how it is here sometimes.

John
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025