Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:53 21 Jul 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 : How to...?

Author Message
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 12:29am 31 Jul 2015
Copy link to clipboard 
Print this post

I decided to do something a bit more complex these days with MM, and since my background for years has been mainly C, immediately hit a few problems/questions. They may have been solved already, but I could not find them in the documentation.

First, is there anything equivalent to the #define in C? I mean, the CONSTANT statement is good, but what if I wanted to express something like PORT(....) as constant?

The other thing is the lack of equivalent to the C's memset() function. How about a command like SET(var, value)?

Thanks for the help
Edited by kiiid 2015-08-01
http://rittle.org

--------------
 
Dylan
Regular Member

Joined: 17/06/2013
Location: Netherlands
Posts: 81
Posted: 05:12am 31 Jul 2015
Copy link to clipboard 
Print this post

#define is not part of C as such, but rather of the preprocessor.

So you could write/port hybrid code on PC, run it through the preprocessor there, and take the resulting .bas to interpret MM. However, the main reason to use PP in the first place is efficiency.

POKE and PEEK write and read in basic (http://www.thebackshed.com/forum/forum_posts.asp?TID=3628), but only a word at a time.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3287
Posted: 06:35am 31 Jul 2015
Copy link to clipboard 
Print this post

Yes, sorry, this is BASIC,

#define would be very useful but I have not yet figured out how to implement it within an interpreter. To fill an area of memory you will need to write a loop. This illustrates that you are coming from a C background as you rarely need to fill memory in BASIC.

Geoff
Geoff Graham - http://geoffg.net
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 07:08am 31 Jul 2015
Copy link to clipboard 
Print this post

  Geoffg said   Yes, sorry, this is BASIC,

#define would be very useful but I have not yet figured out how to implement it within an interpreter. To fill an area of memory you will need to write a loop. This illustrates that you are coming from a C background as you rarely need to fill memory in BASIC.

Geoff


Thanks Geoff :)
I actually think that clearing (or filling) any array could be much faster and easier if there was a command to do that instead of looping through all the elements separately.

For the #define problem, I agree that it is a bit harder to do with an interpreter, but would have been nice to have. In case I come up with an idea, I will let you know, for now will find some workaround for it.

http://rittle.org

--------------
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 08:00am 31 Jul 2015
Copy link to clipboard 
Print this post

Re #define

If U use MMEdit to edit your MMBasic source then you can use MCPP to provide #define (as well as #include and all the other 'C' preprocessor thingies).

Download the CFunction Tutorials from http://www.cfuncgen.dyndns.org/ and refer to Tutorial 4, and also http://www.g8jcf.dyndns.org/mmbasic/ for MCPP and detailed instructions.

Peter


The only Konstant is Change
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 09:13am 31 Jul 2015
Copy link to clipboard 
Print this post

  G8JCF said   Re #define

If U use MMEdit to edit your MMBasic source then you can use MCPP to provide #define (as well as #include and all the other 'C' preprocessor thingies).

Download the CFunction Tutorials from http://www.cfuncgen.dyndns.org/ and refer to Tutorial 4, and also http://www.g8jcf.dyndns.org/mmbasic/ for MCPP and detailed instructions.

Peter



Thanks Peter. I don't use MMedit (using Notepad++ only), but will give it a try.
Edited by kiiid 2015-08-01
http://rittle.org

--------------
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 09:41am 31 Jul 2015
Copy link to clipboard 
Print this post

@kiid

U don't have to use MMEdit to use MCPP, just that using MMEdit makes it pretty seamless/painless. U can of course invoke MCPP from the command line to process your .BAS file and generate an output - take a look inside PP.BAT

echo off
chdir /D %~dp0
Rem Batch File to interface MCPP.EXE to MMEdit.exe V3.18 or later
MCPP.exe -k -P -C -@oldprep %1 -o MCPPout.pp
copy MCPPout.pp %1
Del MCPPout.pp

Rem Uncomment the following line if U want see what the batch is doing
REM pause
exit


I use MCPP to change long symbols into single/double letter symbols to save space, and instead of CONSTs and literals using #define's, and #includes to bring in library/CFunction code at MMBasic program download time to the chip. If one uses MMEdit, then at MMBasic program download time, MMEdit can be set to do a Crunch, which coupled with MCPP, leads to very efficient tight MMBasic code - but of course when the Interpreter hits a runtime error, it can sometimes be a bit tricky relating the line it prints out to the line in the original source !!

Peter
The only Konstant is Change
 
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