|
Forum Index : Microcontroller and PC projects : CFunctions - learning by example (4)
| Author | Message | ||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
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 Geoff Geoff Graham - http://geoffg.net |
||||
| twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1671 |
Hi Geoff, Thanks a lot for your quick response! 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? 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 Michael causality ≠ correlation ≠ coincidence |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10565 |
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: GermanyPosts: 1671 |
Thanks Peter! Sometimes the things can be so simple! Michael causality ≠ correlation ≠ coincidence |
||||
| crez Senior Member Joined: 24/10/2012 Location: AustraliaPosts: 152 |
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! David |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4126 |
Maybe here John |
||||
| crez Senior Member Joined: 24/10/2012 Location: AustraliaPosts: 152 |
Thanks John, I'm back on track (for the moment ) |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |