Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:32 01 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 : CMM2: Is there a way to call the TEXT command from a CSUB?

Author Message
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 03:46pm 12 Nov 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10310
Posted: 04:28pm 12 Nov 2020
Copy link to clipboard 
Print this post

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 States
Posts: 3378
Posted: 05:51pm 12 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  RC17 ... 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

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: Belgium
Posts: 255
Posted: 05:58pm 12 Nov 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10310
Posted: 06:56pm 12 Nov 2020
Copy link to clipboard 
Print this post

  Quote  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?


Why not try it and see. Start simple and see what, if anything, works
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 11:08am 03 Mar 2021
Copy link to clipboard 
Print this post

  matherp said  
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


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 Kingdom
Posts: 4311
Posted: 07:20pm 03 Mar 2021
Copy link to clipboard 
Print this post

  Quote  Please tell me that this is a problem with a known solution ... and point me at that solution.


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 Kingdom
Posts: 10310
Posted: 07:45pm 03 Mar 2021
Copy link to clipboard 
Print this post

  Quote  Please tell me that this is a problem with a known solution ... and point me at that solution.


See my second post here
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 11:46pm 03 Mar 2021
Copy link to clipboard 
Print this post

  matherp said  
  Quote  Please tell me that this is a problem with a known solution ... and point me at that solution.


See my second post here


Thanks Peter. Looks "odd" , but if it works then who am I to complain.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
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