Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:11 02 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 : Quick library question...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 06:31pm 04 Jan 2016
Copy link to clipboard 
Print this post

In another thread, Geoff writes:

  Geoffg said  The Subroutine MM.STARTUP is run when the Micromite first powers up. So it is useful for things like printing a message or loading TFT LCD drivers as PeterM does. It is NOT good for general setup of MMBasic (like dimensioning arrays, the LCD INIT command, etc).


In my library, I do DIM a couple of things needed by the library.

One is a wave-table for matherp's sound Cfunction, and the other is a variable to ID the version of the library currently installed:





As this would seem to be perhaps a no-no, is there any better way to do it?

As you can see, SW% is needed as this is the wave-table for matherp's Cfunction, and LibVer is a string that can be called and shown on the LCD to show the version of the library in use.

This is all working just fine, but I am concerned with Geoff's comment from the other thread, so any suggestions would be good to have now, rather then later if this kind of thing is likely to cause obscure bugs later on.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 04:53am 05 Jan 2016
Copy link to clipboard 
Print this post

I believe that the post that you referred to explained it fully. Don't define your variables in MM.STARTUP but instead as normal code in the library.

I bet that you also have autorun turned on. That does not reset everything like RUN does because it assumes that the processor started in a clean state. So this explains why your program works OK. BUT, if you did start your program with the RUN command it would fall over.

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

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 02:39pm 05 Jan 2016
Copy link to clipboard 
Print this post

Yes, your post did suggest that rather well, didn't it?!(rhetorical)

I can move the wave-table to the main code no problems.

The library ID needs to be saved as part of the library, and NOT in the main code, so that it can be referred to from the main code. If I put it in the main code, the library could be updated later, and the main code would keep saying the library was version 1, if you see what I am getting at.

Is there a way to do something like that in the library that does comply with library specs?
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:23pm 05 Jan 2016
Copy link to clipboard 
Print this post

In the library before the sub,
DIM as STRING LibVer

In the sub
LibVer = "Version 9"


As long as it's DIMed outside the sub, the main code will see it.

Jim
VK7JH
MMedit
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 03:59pm 05 Jan 2016
Copy link to clipboard 
Print this post

  Grogster said  The library ID [...] If I put it in the main code, the library could be updated later, and the main code would keep saying the library was version 1


if i am not mistaken, is it not impossible to update the library without first erasing the main code?

from the start i've always seen the library as having quite limited usefulness as:
1. a means of extending the code space beyond the available ram,
2. a place to put custom functions in a 'condensed' form,
3. somewhere to hide away power-on initialization that needs to be kept safe/hidden if the user drops to the command prompt (LCD and keyboard drivers that are part of the console functionality being the main examples),
4. a way to add language extenstions for classroom situations that survive 'NEW', though are still erased with 'LIBRARY DELETE' or 'LIBRARY SAVE'.

whereas, folks do seem to be using the library as a means of partitioing their code simply for the sake of it with no real added utility. if you are writing an embedded application, unless you are running out of space, moving code into the library really doesn't seem to be worthwhile, and in fact just serves to introduce unnecessary complication and opportunity for bugs.

just my opinion!

cheers,
rob :-)Edited by robert.rozee 2016-01-07
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 05:54pm 05 Jan 2016
Copy link to clipboard 
Print this post

@ Jim - thanks - will try that.

@ Rob - You are correct. To save a new library, you have to erase the main code. In my case, I am using the library to hold several Cfunctions rather then having them take up considerably more memory if listed in the main code. The version number variable is the only exception, really.

It's for precisely that reason, that I need to know what is in the library - my 'Version number' string. If you do a new main code, and it does not need any new Cfunctions in the library, no problems. If you do a new code that DOES need another Cfunction, I guess you could just plop it in the main code, but compressing it in the library is a much better idea.

I too think that putting general commands etc in the library is of little use.

I guess at the end of the day, I don't even need the library version number, as LIBRARY LIST shows all the Cfunctions or Csub's stored within, so - meh........

Perhaps a whole lotta nuthin', my wanting a library version variable.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 10:46pm 05 Jan 2016
Copy link to clipboard 
Print this post

One problem is that your program is in an image which I cannot edit to illustrate how it should be done. So, the below is an abbreviated version as I am a slow two finger typist.

If you had this in the library:
DIM AS STRING LibVer = "... etc ..."

SUB MM.PROMPT
etc
END SUB

CFUNCTION etc
etc
etc

The variable LibVar would be visible to your running program. I believe that the issue is that you tried PRINT LibVer at the command prompt and saw nothing. The reason is that the library code is only run before the main program but not at the prompt.

One way out of that would be to define LivVer in both the library code and in MM.PROMPT. For example:
SetVer
etc

SUB MM.PROMPT
SetVer
etc
END SUB

SUB SetVer
DIM AS STRING LibVer = "... etc ..."
END SUB

CFUNCTION etc
etc
etc

BTW, I do agree with Rob that the library is best used for just compressing CFunctions, etc. It is good for some other things but you can get caught up in subtle issues that are normally hidden by MMBasic.

Geoff

Geoff Graham - http://geoffg.net
 
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