MMEdit V5.4.3


Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6621
Posted: 07:20am 29 Aug 2026      

Gerry,
Gerald would like to " pull SUB and FUNCTION blocks out of a reference library at load time"
To make it more of a challenge, there will be multiple source files and code needs to be extracted from more than 1 each time.

I have been playing a bit.
If the source/library files used tags to indicate the start and end of blocks of interest, code that is not within a SUB can be extracted.
Multiple SUBs can be grouped together and extracted in one go.


 '#MODULE INA3221
 ' all registers are 16 bit so write register number then read 2 bytes
function INA3221_read(reg as integer) as integer
 local registers$
 i2c2 write ina3221addr,0,1,reg
 i2c2 read ina3221addr,0,2,registers$
 INA3221_read = str2bin(int16,registers$,BIG)
end function
 
 ' all registers are 16 bit so write register number then 2 data bytes
sub INA3221_write reg as integer, value as integer
 local integer hibyte, lobyte
 lobyte = value and &hFF
 hibyte = (value >> 8) and &hFF
 i2c2 write ina3221addr,0,3,reg,hibyte,lobyte
end sub
 
sub INA3221_reset
 local integer config
 config = INA3221_read(0)
 config = config or &h8000
 INA3221_write(0,config)
end sub
 '#ENDMODULE INA3221


In the main code
#CODEMODULE filename$ modulename$


I also suggest that all the source files be stored under a common root folder to keep file names short. Subdirectories are OK
I can save the codebase folder name between sessions (in MMReplace.inf withot upsetting anything else) so if that doesn't change it won't need to be specified very often.

I have started butchering MMReplace to see how it works in practice.
I will try and use your existing functions where possible so my hack can be rolled in if desired.

Jim