Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:58 02 Aug 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 : uM2(+): CFunctions

     Page 2 of 2    
Author Message
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 08:29pm 09 Sep 2015
Copy link to clipboard 
Print this post

Hey Jim,

Showing my ignorance here... but as an idea do you think you might be able to modify MMEdit to effectively put "inline C" into a MMBasic program?

I dont talk C (yet.... I am going to have another go at learning it --- any one suggest a good book for dummies like me?) so I cant really say if that idea is even feasible of practical.

Regards,

Mick


Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:45pm 09 Sep 2015
Copy link to clipboard 
Print this post

  bigmik said   Hey Jim,

Showing my ignorance here... but as an idea do you think you might be able to modify MMEdit to effectively put "inline C" into a MMBasic program?

Regards,

Mick


Short answer is no.

CFUNCTIONS or any other C code for the uM really needs a compiler such as MPlab and all the support libraries.

A good place to start is with Pelles C.
Free and plenty of documentation.

http://www.pellesc.de/
or
http://www.smorgasbordet.com/pellesc/index.htm
Just don't ask me to explain any of it...

Jim
Edited by TassyJim 2015-09-11
VK7JH
MMedit
 
matherp
Guru

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

  Quote  Added date as comment.
You can now rerun with the same file names as often as desired using 'Join' and 'Merge'
'New' lets you re-select the files.

As well as outputting to a file, the output is copied to the clipboard ready for pasting into a program.

Is there any call for the ability to read a commandline?


Jim

All looks good and the output checks out perfectly on all my tests - great work.

I can't see any reason for a command line input given the GUI

Would you post the code? I'd really like this version to be completely open source even though most people won't have access to Purebasic

Peter
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:14pm 09 Sep 2015
Copy link to clipboard 
Print this post

  TassyJim said  
  bigmik said   Hey Jim,

Showing my ignorance here... but as an idea do you think you might be able to modify MMEdit to effectively put "inline C" into a MMBasic program?

Regards,

Mick


Short answer is no.

CFUNCTIONS or any other C code for the uM really needs a compiler such as MPlab and all the support libraries.

A good place to start is with Pelles C.
Free and plenty of documentation.

http://www.pellesc.de/
or
http://www.smorgasbordet.com/pellesc/index.htm
Just don't ask me to explain any of it...

Jim

If you want to do something like that you would need something like a 'Project File'.
You could then include the C files in a 'Project Explorer' and edit them from MMEdit.
A Project file could be simple, just a list of files.
I think the compiler can be run from the command prompt, just needs the right make file/batch file. An option to 'Compile' would then just be running that batch file.
If the batchfile can control where the output of the files go, then that could be a parameter. Maybe someone with more knowledge asbout running a compile from the command prompt can help with that.
I am not sure if it is that useful as most CFunctions are library functions better made in their own programming environments. It would be nice though to link the source code (maybe readonly) of those CFunctions in a project. Just to keep everything in one place.

Microblocks. Build with logic.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:49pm 09 Sep 2015
Copy link to clipboard 
Print this post

  matherp said  

Would you post the code? I'd really like this version to be completely open source even though most people won't have access to Purebasic

Peter


Yes.

I need to clean up some of the 'types' and put some more comments.
Also change some globals to locals etc.

I need a day or two - need another rainy day.

You will find that I haven't changed to main code much from your MMBasic version.

You can get a free demo copy of Purebasic to play with. I forget what the restrictions are.


Jim
VK7JH
MMedit
 
Chris Roper
Senior Member

Joined: 19/05/2015
Location: South Africa
Posts: 280
Posted: 11:39pm 09 Sep 2015
Copy link to clipboard 
Print this post

  bigmik said   I dont talk C (yet.... I am going to have another go at learning it --- any one suggest a good book for dummies like me?)


I can't suggest a book as such but I can suggest you try the ChipKIT platform.

It is PIC32MX based so you already know the architecture and probably have a board capable of running it. If not you can quickly build up my breadboard ChipKIT
http://caroper.blogspot.co.za/2013/06/this-will-be-home-for-my-pic32mx.html

It is Arduino Style, but can be plain C if you ignore the Arduino Libraries.
Access to the Libraries helps get you started, and there is lots of Example code to study.

Cheers
Chris



http://caroper.blogspot.com/
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:03pm 10 Sep 2015
Copy link to clipboard 
Print this post

This should be the final version of cfgen.exe although I will change the icon eventually.

No changes to functions but code tidied up.
The ZIP also includes the source code for anyone interested.
2015-09-10_220228_cfgen.zip
I will be adding the program to the MMEdit setup file in the next update.

Jim

VK7JH
MMedit
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 11:25pm 10 Sep 2015
Copy link to clipboard 
Print this post

Jim

Many many thanks - much less "clunky" than my version

Peter
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 01:08am 11 Sep 2015
Copy link to clipboard 
Print this post

Hi Jim, All,

  TassyJim said  
Short answer is no.

CFUNCTIONS or any other C code for the uM really needs a compiler such as MPlab and all the support libraries.


I told you I was showing my ignorance..

OK I understand, you would have to recreate all of the compiler functionality into MMEdit... Yep ! Understand (sort of) now

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1003
Posted: 01:43am 23 Feb 2016
Copy link to clipboard 
Print this post

CFGEN update to switch between CFUNCTION and CSUB

Not sure if CFGEN.EXE has changed since this thread, but attached is an update with source that allows the selection of CFUNCTION or CSUB as the output.


2016-02-23_113328_CFGEN120.zip

My first dabble with PureBasic after many years of VB3 and VB6. I never really tackled VB.NET, seemed too convoluted, but PB seems like a good thing. Thanks Jim for the introduction. The demo version can handle this source OK.

Regards
Gerry
Latest F4 Latest H7 FotS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 01:53am 23 Feb 2016
Copy link to clipboard 
Print this post

Gerry

Jim is just finishing a significant update to CFGEN to incorporate new functionality in the interpretation of the .ELF file so your changes would need folding into that.

Can I suggest you liaise with him direct by PM

Thanks

Peter
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 11:33am 23 Feb 2016
Copy link to clipboard 
Print this post

I was going to ask about CSUB/CFUNCTION differences.
I have added the option to choose either.
I have assumed that the only difference as far as cfgen is concerned is the sub/function labels.

This update to cfgen also includes the changes that Peter referred to above.
Usage is the same as previous versions. I will leave the changes in creating the ELF files to Peter to explain.

The ZIP includes the exe file and the PureBasic source.
AS usual, the code is a conversion from Peters BAS file.

2016-02-23_213203_cfgen.zip

Jim
VK7JH
MMedit
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 01:16pm 23 Feb 2016
Copy link to clipboard 
Print this post

  TassyJim said   The ZIP includes the exe file and the PureBasic source.
AS usual, the code is a conversion from Peters BAS file.
QUOTE]

@Jim.

very appreciated! Thanks!

Michael
causality ≠ correlation ≠ coincidence
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 07:38am 25 Apr 2020
Copy link to clipboard 
Print this post

  Quote  I was going to ask about CSUB/CFUNCTION differences.
...
I have assumed that the only difference as far as cfgen is concerned is the sub/function labels.


Sorry for rehashing an old thread, but there isn't much talk about what the differences actually are. Is the only difference down to whether basic will treat it as a 'command' (on the left side eg: ClearDisplay(colour) ) or a 'function' (on the right side eg: x=Temperature)

Unfortunately P.Mathers most excellent tutorial on CFunctions does not mention CSubs at all, or how to go about creating one, and I can't find any examples (with the C source included - only pre-compiled hex).


Cheers,
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 09:26am 25 Apr 2020
Copy link to clipboard 
Print this post

The only difference between a CSUB and a CFUNCTION is whether the C code returns a value. In CFGEN you then select whether you want a CSUB or a CFUNCTION and it puts the appropriate header on the code. Lots of older code will appear as CFUNCTIONS even though they don't return anything because they pre-date the inclusion of the CSUB in the MM firmware.

e.g. CFUNCTION shellsort
long long shellsort(long long a[], long long *nn) {
   long h, l, j, n=*nn;
   long long k;
   for (h = n; h /= 2;) {
       for (l = h; l < n; l++) {
           k = a[l];
           for (j = l; j >= h && k < a[j - h]; j -= h) {
               a[j] = a[j - h];
           }
           a[j] = k;
       }
   }
   return 0;
}


should be CSUB:
void shellsort(long long a[], long long *nn) {
   long h, l, j, n=*nn;
   long long k;
   for (h = n; h /= 2;) {
       for (l = h; l < n; l++) {
           k = a[l];
           for (j = l; j >= h && k < a[j - h]; j -= h) {
               a[j] = a[j - h];
           }
           a[j] = k;
       }
   }
}




You can use CSUB on a routine that returns a value in which case the return is just ignored.

NB: re PM the scroll demo is very old and pre-loadable drivers. The source is long gone - sorry.
Edited 2020-04-25 20:36 by matherp
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 08:45pm 25 Apr 2020
Copy link to clipboard 
Print this post

Thanks for the clarification Peter, and no worries about the scroll demo C source.

Cheers!
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025