Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 08:35 30 Apr 2024 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 : MMEdit - #REPLACE Pi-cromite ESPBasic

     Page 1 of 2    
Author Message
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 12:51am 13 Apr 2018
Copy link to clipboard 
Print this post

I use MMEdit for all my programing and would not be without it. I have written a utility that adds a few things others might find useful.

I initially wanted a #REPLACE directive so I could use long meaningful variable and routine names in the initial code but have short name replace these at load time. e.g.
#REPLACE longname shortname
This can result in saving in flash used to store the code and faster execution.

@TassieJim allows MMEdit to call an external program at Load and Run so I have written a utility program in PureBasic called MMReplace.exe which implements the #REPLACE directive before MMEdit loads the code.

Using a number or #REPLACE directives in some code I an developing on an MM I have gone from 4K 6% free to 15K 25% free flash.e.g.

  Quote  ' Directives to map variables, sub and function to short versions at load
#REPLACE HardwareV1V2 HC0
#REPLACE HardwareV3V4 HC1
#REPLACE HardwareX10 HC2
#REPLACE HardwareVREF HC3

#REPLACE selected sd
#REPLACE c1mvperdivisionlast c1mvl
#REPLACE c2mvperdivisionlast c2mvl
#REPLACE c1mvperdivision c1mv
#REPLACE c2mvperdivision c2mv
#REPLACE c1mvperdivisionNOW c1mvN
#REPLACE c2mvperdivisionNOW c2mvN
#REPLACE c1mvperdivisionlastADC c1mvlA
#REPLACE c2mvperdivisionlastADC c2mvlA
#REPLACE c1mvperdivisionADC c1mvA
#REPLACE c2mvperdivisionADC c2mvA
#REPLACE microsecondstep mst
#REPLACE microsecondsteps msts
#REPLACE microsecondsperdivision mspv
#REPLACE millivoltsteps mvsts
#REPLACE millivoltstep1 mvst1
#REPLACE millivoltstep2 mvst2
#REPLACE millivoltsperdivision mvpd
#REPLACE indexcalibrationx1probe ic1p
#REPLACE indexcalibrationx10probe ic10p
#REPLACE indexgainx1probe ig1p
#REPLACE indexgainx10probe ig10p
#REPLACE adcgainx1probe ag1p
#REPLACE adcgainx10probe ag10p
#REPLACE millivoltdisplay1 mvd1
#REPLACE millivoltdisplay2 mvd2
#REPLACE mvtopstep1 mt1
#REPLACE mvbottomstep1 mb1
#REPLACE mvtopstep2 mt2
#REPLACE mvbottomstep2 mb2
#REPLACE mvtopstepx1 mtx1
#REPLACE mvbottomstepx1 mbx1
#REPLACE mvtopstepx10 mtx10
#REPLACE mvbottomstepx10 mbx10
#REPLACE probe1switch ps1
#REPLACE probe2switch ps2
#REPLACE DrawMenuRequired DMR
#REPLACE DrawBoundary DBY
#REPLACE DrawButton DB
#REPLACE DrawToggleButton DTB
#REPLACE DrawOptionButton DOB
#REPLACE DisplayValue DV
#REPLACE ClearLeftRequired CLR
#REPLACE ClearRequired CR
#REPLACE CheckButtonRelease CBR
#REPLACE ClearButton CB
#REPLACE CheckButtonPRESS CBP
#REPLACE ClearButton CB
#REPLACE cButton C1
#REPLACE cSpecial C2
#REPLACE fStandard F1
#REPLACE fGraphics F2
#REPLACE scopemode sm
#REPLACE fscale fs
#REPLACE key_coord k_c
#REPLACE key_caption k_cap
#REPLACE key_font k_f
#REPLACE backcolour b_c
#REPLACE forecolour f_c
#REPLACE tab_backcolour tb_c
#REPLACE tab_forecolour tf_c
#REPLACE PenDown PD
#REPLACE TouchPending TP
#REPLACE ActiveArea AA
#REPLACE ActiveAreaLast AAL



This example below shows an increase in execution speed

  Quote   '-----------------------------------------------------------------------'
' This code is to demonstrate the affect of using shorter variable and
' function names
' Timer prints 3712 without the #REPLACE Directives
' Timer prints 2214 with the #REPLACE Directives
' The size of the variable and function names does have some affect
' on speed of execution. In this case long names seem to increase
' time to execute by about 50%
'-----------------------------------------------------------------------

#REPLACE LongAndDescriptiveFunctionName F1
#REPLACE firstnumber n1
#REPLACE secondnumber n2
#REPLACE firstinput i1
#REPLACE secondinput i2
#REPLACE theresult r1


timer=0
firstinput=
1
secondinput=
2
theresult=
0
for x=1 to 10000
theresult=LongAndDescriptiveFunctionName(firstinput,secondinput)
next x
?
timer

Function LongAndDescriptiveFunctionName(firstnumber,secondnumber) as integer
LongAndDescriptiveFunctionName = firstnumber+secondnumber
End Function


LIBRARY MANAGEMENT
To fit the code I was working on into an MM I needed to use the library. I resisted as long as I could as I like to see all the code in one file. This was the trigger for the #LIBRARYSTART, #LIBRARYEND and #LIBRARYLOAD directives. These allow the library code to remain in the main file bounded by the two directives but to only load when the #LOADLIBRARY directive is active. This simplifies maintaining the library code and loading/refreshing it when required. This means you can place a big part of your code in the library but still see it while developing. This means the code you load each time is smaller and loads quicker while you are developing. You can adjust what you want in the library when you finish development.

PI-CROMITE
Then came the Pi-cromite. I found you can reliably paste the clipboard into Putty and load code into the Pi-cromite. This lead to the #PI_CLIPBOARD directive which tells MMEdit to put the code into the Clipboard instead of trying to load it when a matching pi-cromite syntax file is selected.

ESPBASIC
ESPBasic can also have code pasted via the browser so the #ESP_CLIPBOARD directive was added along with an ESPBasic syntax file, so MMEdit can be used to edit your ESPBasic code.

ARRAYS Stored in CFUNCTION/CSUB
@Nathan has posted about his simpleArrayFuncGen program which allows static array data to be stored in Cfunction/Csub instead of populating an array using the traditional DATA and READ commands.

simpleArrayFunctGen forum post
http://www.thebackshed.com/forum/forum_posts.asp?TID=10253&PN=7


I have added some directives so that the config file for simpleArrayFuncGen can be included in the main file and simpleArrayFuncGen can automatically be called to generate the Cfunction/Csub during Load and Run.
#ARRAYSTART, #ARRAYEND , #ARRAYINCLUDE and #ARRAYGENERATE directives control this.

DOCUMENTATION and INSTALLATION
The attached pdf explains in more detail and the zip file contains the files required and installation instructions.

2018-04-13_103421_MMReplace.pdf

2018-04-13_103504_MMReplaceDistribution.zip

Thanks Jim for MMEdit,

Regards
Gerry



Latest F4 Latest H7
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5906
Posted: 03:26am 13 Apr 2018
Copy link to clipboard 
Print this post

This looks like a very useful option when you are pushing the 'mite memory to the limit.
I have deliberately avoided a global replace function so far - it can be dangerous.

I have been giving a lot of thought to the syntax files. As the number of devices and versions of MMBasic increase, the existing method of one file for each variant gets difficult to keep up with.
I am planning on having a master syntax file for each version and extract the syntax for the device 'on the fly' when you select the device.

I will make sure that it is backward compatible with the extras such as your ESPBasic syntax file.

It will be a few weeks before I get a chance to play with your offering.

Jim


VK7JH
MMedit   MMBasic Help
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 02:10am 14 Apr 2018
Copy link to clipboard 
Print this post

@TassyJim

Is it possible to actually have a directive(s) within MMEdit so that on a Crunch & load, it will ignore a block of code as it does for Comments? In that way, library files etc could be placed be within the main program for reference & not lose the pretty colours as you do when commented out.

Just thinking
ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5906
Posted: 02:32am 14 Apr 2018
Copy link to clipboard 
Print this post

  Chopperp said   @TassyJim

Is it possible to actually have a directive(s) within MMEdit so that on a Crunch & load, it will ignore a block of code as it does for Comments?

That is one of the things that Gerry's solution does.

Jim
VK7JH
MMedit   MMBasic Help
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 03:21am 14 Apr 2018
Copy link to clipboard 
Print this post

Hi Jim
I did sort of gather that but I found bit hard to follow. Will have another read of his descriptions etc.
Reread & found the #ENDCODE directive, but still hard to follow. I thought that there could be something simpler like putting a "#" in the program & MMEdit ignoring the following code like it does a "'" without his prog.
Will have a play & see if I can get Gerry's prog to work

Thanks

ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 05:39am 14 Apr 2018
Copy link to clipboard 
Print this post

OK, got #ENDCODE working (after I put in the /* & */) on my CMM. Not quite as hard as it looked.
I assume however that the LIBRARY directives will NOT work with the CMM as they are firstly loaded onto the SD card. Is this correct or is there a workaround?

Thanks

EDIT
Probably the comments working rather than the #ENDCODE but still does what I want for this bit.Edited by Chopperp 2018-04-15
ChopperP
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 07:33am 14 Apr 2018
Copy link to clipboard 
Print this post

Check you have the
#ENDCODE starting in column 1.

The library directives also need to start in column 1.
They should just exclude the enclosed code when you Load and Run.
#LIBRARYSTART
code here not loaded.
...
#LIBRARYEND

I haven't played with a CMM so not sure how you load its library.However if you
have a
#LIBRARYLOAD directive before the other Library directives then only the enclosed code is loaded. Would a modified #LOADLIBRARY directive such as
#LOADLIBRARY filename
be of any use if it then exported the library code to a separate file so it can be transferred to the SDCard?

regards
Gerry
Latest F4 Latest H7
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 09:19am 14 Apr 2018
Copy link to clipboard 
Print this post

Hi Disco4now

#ENDCODE now in column 1. Yet to be tried.

Need to figure out what you are on about for the second part of above.
Brain not working too good ATM. Bit of the flu I think. Understand the middle bit.

Thanks
ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 09:33am 14 Apr 2018
Copy link to clipboard 
Print this post



  disco4now said   I haven't played with a CMM so not sure how you load its library.However if you
have a
#LIBRARYLOAD directive before the other Library directives then only the enclosed code is loaded. Would a modified #LOADLIBRARY directive such as
#LOADLIBRARY filename
be of any use if it then exported the library code to a separate file so it can be transferred to the SDCard?


I think I understand. Yes, *.lib file exports would be good.


ChopperP
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 11:44am 14 Apr 2018
Copy link to clipboard 
Print this post

I have now allowed the
#LIBRARYLOAD to take an optional filename parameter.
i.e

#LIBRARYLOAD filename

If this extra parameter is found it will be assumed that a separate library file is to be generated with the code bounded by the #LIBRARYSTART/#LIBRARYEND directives. The .lib extension will be added if not supplied. It will be placed in the same directory as the current .bas file. My understanding is that you would then use MMEdit to xfer it to the SDCARD. As a side affect the code would also be load into the Maximite so you would have to reload again after you comment the '#LOADLIBRARY directive to load the main code back into the Maximite.

I have also relaxed the requirement for directives to start in column 1.
They still must be first thing on the line other than spaces.

The attached zip contains only the update MMReplace.exe file. If this is successful/useful I will update the documentation and re post the whole package.

2018-04-14_213913_MMReplace.zip

Regards
Gerry
Latest F4 Latest H7
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 12:24pm 14 Apr 2018
Copy link to clipboard 
Print this post

That's great Gerry. Much appreciated. Will test tomorrow.
May need to comment the Main prog out as the CMM will try to run the uploaded *.bas file & probably crash (or turn off RUN after load which is not a problem)

ChopperP
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 08:03pm 14 Apr 2018
Copy link to clipboard 
Print this post

Excellent work Gerry.

You have almost implemented a precompiler and library linker for MMBasic! If it can be integrated in MMedit somewhat tighter it could develop into a really good IDE, an honest to goodness Integrated Development Environment. SHADES OF VISUAL STUDIO!!!

Keep this thing going. The improvements in resident code size, operating speed and development speed will be enormous.

Paul in NY
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 12:15am 15 Apr 2018
Copy link to clipboard 
Print this post

Hi Gerry
Sorry to say the prog didn't work at all. Just ignored everything. Noticed that it is only half the size of the first one.
ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 12:25am 15 Apr 2018
Copy link to clipboard 
Print this post

@TassyJim
I noticed that the TEMP.BAS file disappears from the MMEdit working directory after being uploaded to the CMM. I wanted to check what was actually being sent to CMM without stopping it & using MM File. Any chance of a COPY to the CMM, rather than a move pretty please?
ChopperP
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 12:51am 15 Apr 2018
Copy link to clipboard 
Print this post

Sorry wrong one. Try this.

2018-04-15_105045_MMReplace.zip
Latest F4 Latest H7
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 01:28am 15 Apr 2018
Copy link to clipboard 
Print this post

Hi Gerry. Sorry to say it didn't work with the #LIBRARYLOAD filename directive. MMEdit just loads the file as TEMP.BAS into the CMM. No saving to the directory. Code snippet below. I think it is correct

#LIBRARYLOAD Start01.lib
#LIBRARYSTART
Sub Start_01

dim T(10)

end sub

#LIBRARYEND

ChopperP
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 03:05am 15 Apr 2018
Copy link to clipboard 
Print this post

Your code snippet is correct. It created the file for me. Is the Run External Command thing checked. I checked the uploaded file and I have given you the correct file this time.

Also if you put a debug.txt file (or rename debugXXX.txt in directory where mmreplace.exe lives it will pause so you can see the the console output before it closes. You need to hit enter to continue.

Regards
Gerry







Latest F4 Latest H7
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 04:33am 15 Apr 2018
Copy link to clipboard 
Print this post

I get this..Can't see a file though

C:\Program Files (x86)\CCom\MMReplaceDistribution\debug.txt found - verbose mode
Passed Parameter=C:\Users\Owner\Documents\CMM Working\temp.bas
Array Executable=C:\Program Files (x86)\CCom\MMReplaceDistribution\simpleArrayFuncGen.exe
Directive #LIBRARYLOAD found
#LIBRARYLOAD Start01.lib
Directive #LIBRARYSTART found
#LIBRARYSTART
Directive #LIBRARYEND found
#LIBRARYEND
TotalLines= 0
Total #REPLACE = 0
Press return to exit
ChopperP
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 05:10am 15 Apr 2018
Copy link to clipboard 
Print this post

Can you check there is only a single space between #LIBRARYLOAD and Start01.lib in the directive
#LIBRARYLOAD Start01.lib

It currently cant handle more than one space or a TAB here.
Latest F4 Latest H7
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 08:04am 15 Apr 2018
Copy link to clipboard 
Print this post

TBS Connection playing up. Keep losing my posts.
Space OK.
Noted adding your MMReplace file removes the /*...*/ sections from the Basic file. Undo brings it back.
If LIBRARY directives are in place (with or without the filename) & then I click on Advanced, Run External Prog, MMReplace removes everything apart from the Library file. This file can then be saved as a *.LIB file ready to be uploaded to the SD card.
The original file has to be reloaded of course.
This is a good compromise. Happy with that. Maybe, that's what I supposed to be doing anyway.
Now to see if this will post (preview works)
ChopperP
 
     Page 1 of 2    
Print this page
© JAQ Software 2024