![]() |
Forum Index : Microcontroller and PC projects : CMM2: Is there a way to call the TEXT command from a CSUB?
Author | Message | ||||
epsilon![]() Senior Member ![]() Joined: 30/07/2020 Location: BelgiumPosts: 255 |
Hi all, Is there a way to invoke the TEXT command from a CSUB? I don't see any candidates in ARMCFunctions.h (FW ver 5.05.05). TEXT X, Y, STRING, ALIGNMENT, FONT, SCALE, C, BC Thanks for any help, Epsilon/Ruben. Epsilon CMM2 projects |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
If you download and install RC17 again there is now support for a call to RunBasicSub This allows you to create a C string which contains any Basic command and then execute it from a C Function. This idea was created for the PICs by Geoff and I personally have never used it and it is completely untested on the CMM2 IMPORTANT the C string must be terminated by two zero characters and not just one Edited 2020-11-13 02:33 by matherp |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Can you explain this more fully or link to an explanation? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
epsilon![]() Senior Member ![]() Joined: 30/07/2020 Location: BelgiumPosts: 255 |
Thank you for the quick response Peter. Do you know if RunBasicSub has access to the environment from which the calling CSUB was invoked, i.e. can I reference MMBasic locals and globals in that C string, or should I stick to immediates only? Epsilon CMM2 projects |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Why not try it and see. Start simple and see what, if anything, works |
||||
epsilon![]() Senior Member ![]() Joined: 30/07/2020 Location: BelgiumPosts: 255 |
I finally gave this a try and am happy to report that it's working well. I'm making a call-out from a CSUB to an MMBasic SUB and pass along one parameter. The MMBasic code looks like this: DIM wm_draw_callout_arg% SUB WM_DRAW_OBJ_DRAW_CALLOUT Object_draw(wm_draw_callout_arg%, 1) END SUB CSUB wm_draw_csub INTEGER, INTEGER, STRING, INTEGER 00000000 4FF0E92D F44F4C96 68097A48 0B00F04F 68066824 68E06825 FA06FB0A 07C1EB05 00C6EB00 8B02ED2D 921 ... END CSUB wm_draw_csub updates_lid%, wm_view%, "WM_DRAW_OBJ_DRAW_CALLOUT"+CHR$(0), wm_draw_callout_arg% The call-out in the C code looks like this: #include "ARMCFunctions.h" ... void wm_draw_csub(long long *updates_lidp, long long *wm_viewp, char *callout_sub, long long *callout_arg) { ... *callout_arg = current_object; RunBasicSub(callout_sub+1); } A few details to keep in mind: - The string referencing the Basic sub has to be all capitals. - You have to append an additional 0 to that string. That was mentioned before. - In the C code, add one to the string pointer. MMBasic strings have the string length in the first byte, C strings don't, so you have to move the point past that first byte. - You can't just do this: RunBasicSub("WM_DRAW_OBJ_DRAW_CALLOUT\0"); The C compiler would put the string literal in the data segment and that doesn't get included in CSUBs. There might be a way around this. I vaguely remember the original CSUB/CFunction thread talked about it. I prefer passing in the string. Epsilon CMM2 projects |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
For example if necessary can we do this: char foo[] = "foo"; and then use variable foo instead of literal "foo". As my understanding is that this should cause the generated binary to store "foo" on the stack and not in a read-only data section. Best wishes, Tom Edited 2021-03-04 05:48 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
See my second post here |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Thanks Peter. Looks "odd" ![]() Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |