![]() |
Forum Index : Microcontroller and PC projects : How to...?
Author | Message | ||||
kiiid Guru ![]() Joined: 11/05/2013 Location: United KingdomPosts: 671 |
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 http://rittle.org -------------- |
||||
Dylan Regular Member ![]() Joined: 17/06/2013 Location: NetherlandsPosts: 81 |
#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: AustraliaPosts: 3287 |
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 KingdomPosts: 671 |
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 KingdomPosts: 676 |
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 KingdomPosts: 671 |
Thanks Peter. I don't use MMedit (using Notepad++ only), but will give it a try. http://rittle.org -------------- |
||||
G8JCF![]() Guru ![]() Joined: 15/05/2014 Location: United KingdomPosts: 676 |
@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 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |