Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:39 29 Nov 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 : PicoMite experimental for test. Library command (thanks to disco4now)

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 11:32am 28 Mar 2023
Copy link to clipboard 
Print this post

Please try the attached and report any issues. This is a significant enhancement to the PicoMite that has been developed by Gerry (disco4now).
Assuming no issues I will incorporate in all the versions ready for the next release.
Gerry has also provided comprehensive notes on the operation of the commands which are attached below.
Thanks are definitely due

PicoMite.zip

Library Implementation for Picomites.
The LIBRARY commands, LIBRARY SAVE, LIBRARY DELETE and LIBRARY LIST are implemented with the same functionality as the Micromites.
The Library commands can only be run at the command prompt.
In the Micromites the Library inserts itself before the end of the main program area,reducing the available normal program area, but using what it takes more efficiently so resulting in better utilisation of the program area and also the library features.

In the Picomite implementation the Library uses the flash of the last Flash Slot (currently 4) so adds the library without reducing the program area. The use of the Library and the last Flash Slot are mutually exclusive. The first LIBRARY SAVE command will claim the Flash Slot if it is not in use. The FLASH command can claim slot 4 if it has not yet been used by the library.


> flash list
Slot 1 available
Slot 2 available
Slot 3 available
Slot 4 in use: Library
>


When a program is run from the main program area any normal code in the library is run before the main program.The main program is then run and has access to any routines in the library.

Running a program stored in flash with FLASH RUN [1-3] will run any normal code stored in the Library before its main program, and the program will have access to any SUBs, FUNCTIONs,FONTs or CSUBs in the Library. The value returned by MM.Info(FLASH) will identify which slot the program is running from and can be used in the library to conditionally include or exclude Library code/routines.

Chaining a program stored in flash with FLASH CHAIN [1-3] will NOT run any normal code stored in the Library before its main program, however the program will have access to any SUBs, FUNCTIONs, FONTs or CSUBs in the Library. The value returned by MM.Info(FLASH) will identify which slot the program is chained from and can be used in the library to conditionally include or exclude Library code/routines.

FLASH LOAD [1-3] will load the program into the main program memory and will have access to any existing Library code.

FLASH [SAVE|ERASE|ERASE ALL|OVERWRITE|CHAIN|RUN] all respect the library if it has already claimed Flash Slot 4.

LIBRARY DELETE  will delete the library and return Flash Slot 4 for normal use.It also clears the program area.

OPTION RESET returns all Options to default, so will also delete the library and return Flash Slot 4 for normal use.

LIBRARY LIST will list the contents of the Library. The Library does not store comments or the HEX code for FONTs or CSUBs. A copy of the Library source should be kept externally or in one of the Flash Slots if you need to modify or recovered it.
e.g. Write your library code in the main program area. Back it up to a flash slot, FLASH SAVE 3. Your Library source is stored in Slot 3. Then do LIBRARY SAVE, the code in the normal program memory is now moved into the library (comments removed, HEX for Fonts and CSUBs removed) and the main program area cleared.
To modify the library, LIBRARY DELETE, FLASH LOAD 3 to get the source back, EDIT command to modify. FLASH OVERWRITE 3 to back it up, LIBRARY SAVE to put it into the Library or just keep it all in MMEdit.

LIBRARY SAVE is cumulative. i.e. Subsequent LIBRARY SAVEs will append whatever is currently in the main program area to the Library.

Recap on uses for the Library.
The LIBRARY feature makes it possible to create BASIC functions, subroutines ,embedded fonts and CSubs and add them to MMBasic to make them permanent and part of the language.  For example, you might have written a series of subroutines and functions that perform sophisticated bit manipulation; these could be stored as a library and become part of MMBasic and perform the same as other built in functions that are already part of the language.  An embedded font can also be added the same way and used just like a normal font.
To install components into the library you need to write and test the routines as you would with any normal BASIC routines.  When you are satisfied that they are working correctly you can use the LIBRARY SAVE command.  This will transfer the routines (as many as you like) to a non visible part of flash memory where they will be available to any BASIC program but will not show when the LIST command is used and will not be deleted when a new program is loaded or NEW is used.  However, the saved subroutines and functions can be called from within the main program and can even be run at the command prompt (just like a built in command or function).
Some points to note:
• Library routines act exactly like normal BASIC code and can consist of any number of subroutines, functions, embedded C routines and fonts.  The only difference is that they do not show when a program is listed and are not deleted when a new program is loaded.
• Library routines can create and access global variables and are subject to the same rules as the main program – for example, respecting OPTION EXPLICIT if it is set.
• When the routines are transferred to the library MMBasic will compress them by removing comments, extra spaces, blank lines and the hex codes in embedded C routines and fonts.  This makes the library space efficient, especially when loading large fonts.  Following the save the program area is cleared.
• During development of a large program you may want to put already proven code into the library so that reloading of the code you are working on from MMEdit or another external editor is smaller and thus quicker.
• You can use the LIBRARY SAVE command multiple times.  With each save the new contents of the program space are appended to the already existing code in the library.
• You can use line numbers in the library but you cannot use a line number on an otherwise empty line as the target for a GOTO, etc.  
• You can use READ commands in the library but they will default to reading DATA statements in the main program memory.  If you want to read from DATA statements in the library you must use the RESTORE command before the first READ command to set the pointer to the library space.

To delete the routines in the library space you use the LIBRARY DELETE command.  This will clear the space and return the flash memory used by the library back to its original use.
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 899
Posted: 12:12pm 28 Mar 2023
Copy link to clipboard 
Print this post

It works for me and passes all the test I have previously done.
MEMORY command will show Library usage.
F5 key at command line will clear the VT100 screen if you have not defined it for anything else.



Just to see if @thwill will fall off his chair!

tst_library.bas
 Verify CallTable still at 0x10000308:              PASS (1/1)
 Verify Main finds CSUBs in Library 1,2 and main:   PASS (3/3)
 Verify Lib. finds CSUBs in Library 1,2 and main:   PASS (3/3)
 Verify Main finds label in Library 1,2 and main:   PASS (4/4)
 Verify Lib. finds label in Library 1,2 and main:   PASS (4/4)
 Verify Main finds Line in Library 1,2 and main:    PASS (5/5)
 Verify Lib. finds Line in Library 1,2 and main:    PASS (5/5)
 Verify On Error IGNORE  in Library :               PASS (2/2)
 Verify Defined Fonts OK in Library 1,2 and main:   PASS (3/3)
 Verify Displays have not changed:                  PASS (35/35)
 Verify IReturn is functional:                      PASS (1/1)
 Execution time: 1.233916 s
 PASS (11/11)
Single test complete - tst_library.bas



Latest F4 Latest H7
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4047
Posted: 12:27pm 28 Mar 2023
Copy link to clipboard 
Print this post

  disco4now said  Just to see if @thwill will fall off his chair!




OMG, is that my unit-testing code.

I guess if it is then you either "statically" included it, or put it into the LIBRARY ?



Let me know if you have any feedback on the code.

Best wishes,

Tom
Edited 2023-03-28 22:28 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6814
Posted: 01:39pm 28 Mar 2023
Copy link to clipboard 
Print this post

This is very nice indeed. I like the fact that it's up to you whether you have the library or flash slot 4. The flash slots are relatively big so this should be plenty of space for library routines. Many thanks to you both. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 396
Posted: 01:44pm 28 Mar 2023
Copy link to clipboard 
Print this post

Unbelivable, especially because I was afraid to ask if we can have some library functionallity since it would be a GREAT enhancement to bring more structure in often used / and / or complex code.

I can make good use of it driving my samsung vacuum fluorecence display, which has a lot of features and therefore require some space in the code.

Just wonderful!

Greetings
Daniel
Edited 2023-03-28 23:45 by Amnesie
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3152
Posted: 02:05pm 28 Mar 2023
Copy link to clipboard 
Print this post

This is an outstanding addition. Kudos to disco4now and Peter.

MMBasic--the gift that keeps giving.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3152
Posted: 02:29pm 28 Mar 2023
Copy link to clipboard 
Print this post

Of course, the follow-up question for disco4now is: "Do you have a sample Library which you could share with us?".
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6814
Posted: 03:34pm 28 Mar 2023
Copy link to clipboard 
Print this post

Yes - the ANSI display SUB(s) that I did were originally designed to run in the Micromite library. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4256
Posted: 03:49pm 28 Mar 2023
Copy link to clipboard 
Print this post

  lizby said  Of course, the follow-up question for disco4now is: "Do you have a sample Library which you could share with us?".


That is for each of us to determine, but honestly, much of what I would put in a library is already added to MMBasic, such as modbus crc.

Maybe that is a nice topic for the next programming challeng... write a max 5k library routine that you think is usefull. Together we can builg a community library...

I can also think of a perpheral library, containing less common chip drivers. I.e. i2c and spi devices..

Volhout
Edited 2023-03-29 01:52 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 03:51pm 28 Mar 2023
Copy link to clipboard 
Print this post

One major use is for fonts - gets them out of the way and little constraint on size
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 11:11pm 28 Mar 2023
Copy link to clipboard 
Print this post

Nice!  

This will help Mark who was wanting something similar.

Bill
Keep safe. Live long and prosper.
 
mozzie
Regular Member

Joined: 15/06/2020
Location: Australia
Posts: 68
Posted: 01:43am 29 Mar 2023
Copy link to clipboard 
Print this post

A huge thanks to Gerry and Peter for this  
As Peter suggests, the ability to embed extended or graphic fonts in the library rather than save as part of the program is greatly appreciated, makes uploads etc much quicker.

I guess those of us who started with Micromite and Micromite+ probably noticed it more as we lost the library when moving to the Picomite  

Regards,
Lyle.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6102
Posted: 06:22am 29 Mar 2023
Copy link to clipboard 
Print this post

At first look it seems to be a usefull addition.
I am more likely to use the ability to 'run' subs from the command line.

A couple of observations.
When the code is saved to the library, comments are removed as expected but it ends up with blank lines. It does make LISTing the library less easy to read. Can we have lines that only contain comments fully removed?

When there is a duplicate name, the error message list the error line as line one in the main code.
  Quote  RUN
[1] 'this is a test of library feature.
Error : Duplicate name
>

It would be more helpful if it gave the offending sub name.

One for me to fix
MMEdit's file-manager uses 'FLASH LIST' to list flash slots. This gives an error with the library.
FLASH LIST 4
ERROR : Library is using Slot 4
>

Should be easy enough for me to fix.

Jim
VK7JH
MMedit   MMBasic Help
 
karlelch

Senior Member

Joined: 30/10/2014
Location: Germany
Posts: 172
Posted: 12:48pm 29 Mar 2023
Copy link to clipboard 
Print this post

This is great! I wondered about this for some time now but was afraid to ask  
Will try later today.

Thanks @disco4now and @matherp!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 09:01am 30 Mar 2023
Copy link to clipboard 
Print this post

Updated by Gerry to address Jim's comments - untested


PicoMite.zip
 
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 245
Posted: 10:02am 30 Mar 2023
Copy link to clipboard 
Print this post

This a most welcome addition.  I use LIBRARY a lot with the MicroMites and I very much miss it with the Pico.  I had been thinking about posting an enquiry - 'Whatever happened to LIBRARY?' but here it is!  Thank you very much indeed.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024