![]() |
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 KingdomPosts: 676 |
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 KingdomPosts: 10281 |
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 KingdomPosts: 676 |
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: AustraliaPosts: 935 |
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 KingdomPosts: 671 |
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 StatesPosts: 328 |
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 KingdomPosts: 676 |
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: FrancePosts: 134 |
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... |
||||
G8JCF![]() Guru ![]() Joined: 15/05/2014 Location: United KingdomPosts: 676 |
@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 > Peter The only Konstant is Change |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9603 |
![]() ![]() ![]() 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 KingdomPosts: 10281 |
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: FrancePosts: 134 |
|
||||
piclover Senior Member ![]() Joined: 14/06/2015 Location: FrancePosts: 134 |
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 KingdomPosts: 10281 |
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: FrancePosts: 134 |
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. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9603 |
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: FrancePosts: 134 |
See #3 in my reply above. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10281 |
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: FrancePosts: 134 |
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 KingdomPosts: 4039 |
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 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |