Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:59 10 Nov 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 : CFunctions - learning by example (4)

     Page 2 of 2    
Author Message
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 05:18pm 08 Jul 2017
Copy link to clipboard 
Print this post

  twofingers said  Can I call a MMBasic function from within a Cfunction?

Yes, use the RunBasicSub(string) function defined in CFunctions.h

The argument to RunBasicSub is a string specifying the name of the user defined BASIC subroutine to be executed. It MUST be terminated with TWO null chars.

Typical C code:
char s[5];
s[0] ='F'; s[1] ='o'; s[2] ='o'; s[3] = 0; s[4] = 0;
RunBasicSub(s);


Corresponding BASIC function:
SUB Foo
PRINT "Hello World from a CFunction"
END SUB


GeoffEdited by Geoffg 2017-07-10
Geoff Graham - http://geoffg.net
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 03:10am 09 Jul 2017
Copy link to clipboard 
Print this post

Hi Geoff,

Thanks a lot for your quick response!

  Geoffg said  
  twofingers said  Can I call a MMBasic function from within a Cfunction?
Yes, use the RunBasicSub(string) function defined in CFunctions.h

Unfortunately the CFunctions.h is poor documented. (Not a criticism!)

Peters useful documentation "Brief overview of all of the facilities in Cfunctions.h" (released 27. February 2016) is unfortunately somehow outdated.

Undocumented in Cfunctions.h:
#define GetTouchAxisVector (*(unsigned int *)Vector_GetTouchAxis)
#define GetTouchAxis ((int (*)(int)) (*(unsigned int *)GetTouchAxisVector)) (a)

// NOTE: The argument to RunBasicSub is a string specifying the name of the BASIC subroutine to be executed.
// It MUST be terminated with TWO null chars.
#define RunBasicSub(a) ((void (*)(char *)) Vector_ExecuteProgram) (a)

#define SaveProgramToFlash(a,b) ((void (*)(char *, int)) Vector_SaveProgramToFlash) (a,b)
#define error(a) ((void (*)(char *)) Vector_error) (a)
#define ProgFlash ((int *) Vector_ProgFlash)
#define ClearProgram() ((void (*)(void)) Vector_ClearProgram) ()
#define llist(a,b) ((char * (*)(char *, char *)) Vector_llist) (a,b)
#define CFuncInt2 (*(unsigned int *) Vector_CFuncInt2)


Maybe it would be useful to include the (updated) documentation in your MMBasic distribution?



  Geoffg said  The argument to RunBasicSub is a string specifying the name of the user defined BASIC subroutine to be executed. It MUST be terminated with TWO null chars.

Typical C code:
char s[5];
s[0] ='F'; s[1] ='o'; s[2] ='o'; s[3] = 0; s[4] = 0;
RunBasicSub(s);


Corresponding BASIC function:
SUB Foo
PRINT "Hello World from a CFunction"
END SUB


Geoff

Just out of curiosity: Is there also a way to pass arguments?

Regards
MichaelEdited by twofingers 2017-07-10
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 05:14am 09 Jul 2017
Copy link to clipboard 
Print this post

  Quote  Just out of curiosity: Is there also a way to pass arguments?


You don't need to:

Set up a normal Basic variable with Global scope
Pass it to the Cfunction
manipulate it in the CFunction as required
Call the MMBasic function which has by definition got access to the Basic variable
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 05:21am 09 Jul 2017
Copy link to clipboard 
Print this post

Thanks Peter!

Sometimes the things can be so simple!

Michael
causality ≠ correlation ≠ coincidence
 
crez

Senior Member

Joined: 24/10/2012
Location: Australia
Posts: 152
Posted: 07:55pm 26 Oct 2017
Copy link to clipboard 
Print this post

Further back in this thread someone sorted out a problem by switching to xc32 compiler version 1.33. I can not find this for download from microchip, only 1.44. I am getting the same sort of error. Where do I go from here? My entry into C functions has not been smooth so far!

DavidEdited by crez 2017-10-28
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4126
Posted: 08:56pm 26 Oct 2017
Copy link to clipboard 
Print this post

Maybe here

John
 
crez

Senior Member

Joined: 24/10/2012
Location: Australia
Posts: 152
Posted: 01:47am 27 Oct 2017
Copy link to clipboard 
Print this post

Thanks John, I'm back on track (for the moment )
 
     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