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 : Modular basic
Page 1 of 2 | |||||
Author | Message | ||||
Olimex Senior Member Joined: 02/10/2011 Location: BulgariaPosts: 226 |
Hi my name is Tsvetan from Olimex we work with Don, Mick and Ken for some time to release the new boards for Maximite. MODULES in MM Basic I'm thinking about this concept for quite some time now, the great thing of MaxiMite Basic is it's simplicity, but if we have to address different hardware peripherial devices or shields like they call it in Arduino it would be great if all these hardware shields come with some kind of pre-built and debugged libraries or modules. MM Basic now is not modular and do not allow use of functions nor local variables which definitely will cause mess if someone decide to make dedicated subroutines for specific hardware drivers, so what do you think about this idea/concept: To modify MM Basic in such way that it allow the use of modules like the DLLs in windows, from the SD-card with command like: USE "FILENAME.MOD" - with this command you call Module from the SD-Card, it's loaded in memory at the end of the program code CLEARM - clear the module which is loaded from the program memory when the interpreter receive USE command the Filename.mod is loaded to the end of code, then you can call it with command like: GOSUBM VAR1, VAR2..., VARn each module will have RETURNM all labels in the module will be made relative so not mess with the Basic code all variables in the module are with some kind of preffix and are allocating at the time of module load and released when the module is removed with CLEARM for simplicity let's think there will be allowed just one module to be used at time. Geoff do you think this could be implemented relatively easily? This will open lot of possibilities all hardware for MaxiMite to be accomplished with ready made modules/libraries ready for use. For instance we have MOD-ENC28J60 Ethernet conetoller which will allow easy plug to our UEXT connector of the MaxiMite derivate board we are releasing, We could prepare TCP-IP module which comes with pre-defined commands for support of WEB, FTP, E-MAIL etc services and so on. so you can send e-mail as simple as this: 10 USE "TCP-IP.MOD" 20 EMAIL$ = "#TO: geoff@geoff.net #SUBJECT: Hello #BODY: Hi, How are you?" 30 GOSUBM 1, EMAIL$ 40 CLEARM best regards Tsvetan |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
Hi, I think it is possible to use MERGE file$. The libraries in Jal language are normal Jal files included anywhere in JAL source with "include" directive. Some of libraries require some const and variable definitions before including the desired library as in the snippet bellow: [code]-- I2C io definition alias i2c_scl is pin_b4 alias i2c_scl_direction is pin_b4_direction -- b3 is pin-compatible with 16f648a board file, b1 is on hardware pins alias i2c_sda is pin_b1 alias i2c_sda_direction is pin_b1_direction -- i2c setup const word _i2c_bus_speed = 4 ; 400kHz const bit _i2c_level = true ; i2c levels (not SMB) include i2c_software i2c_initialize()[/code] The line which starts with "--" sequence, is a comment. Vasi Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
The problem is at line numbering... it needs a "standard" definition. E.g., - from number x to number y, allocated to TCP/IP library; - from number l to number m, ........ Also, it must be known the exact location (number label) of subroutines included in libraries. To me is clear that it needs an IDE, with Dialogs for configuring the hardware and peripherals, and the inclusion of required libraries... GW-Basic is very restrictive... OR, as already made here on forum, the possibility to write a numberless code, then IDE translate it into a numbered list. Still a specialized IDE required. Vasi Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
Library code [code] 100 REM Jumping at the end of library for assuring a continuous program flow 101 GOTO 200 110 REM subroutine X1 .................. 130 RETURN 140 REM subroutine X2 ......................... 160 RETURN 200 REM Library exit point [/code] Main code [code] 10 REM define eventual consts and vars for the library (user action) ............... 20 MERGE TCP.BAS 210 REM The rest of program [/code] It needs a team for developing libraries as standard (see Jallib team as example). Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
It would be nice if MERGE had a starting line number and would renumber the program that it loads. You could have modules x.bas, and y.bas on the SD card. They all start at 100 but would be renumbered as they are loaded. They are utility function programs that you might include in your own code. Your main program could be: 100 REM 110 REM 120 REM etc. You could type MERGE "x.bas", 1000 and MERGE "y.bas", 2000 to include the functions of x.bas and y.bas. Even though x.bas starts at 100 on the SD card, when merged in the lines are renumbered to start at 1000, and y.bas to start at 2000. All utility programs could start at 100 (or wherever) and anyone using them in their code decides where (what line number) to start for their program. Micromites and Maximites! - Beginning Maximite |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
Having libraries developed this way, we don't need an IDE. Including a chain of libraries can be done without headaches (as every library have a jumping command to the end of library, allowing inclusion without unwanted execution of the subroutines inside). [code] 10 REM const and var initializations -- library requirements are detailed on help file 50 MERGE "libs\tcpip.bas" -- you must know the ending label number but this is documented on library "book" 200 MERGE "libs\sensorX.bas" 300 MERGE "libs\other_peripheral.bas" -- and so on... 1000 REM we know from where to continue with the numbering as per library documentation. ----------------- [/code] Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
MERGE "libs\sensorX.bas" No sub-dir support. Unless that has recently changed. Micromites and Maximites! - Beginning Maximite |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
Olimex have access to a large set of devices and peripherals. and have a general image about all the libraries needed. Maybe can make a list and propose some standardization. This include also the label numbers allocated to each library. And for each library an usage example is needed. The label numbers can be allocated for library groups and not for each library. By library groups I mean peripherals from the same category. We can have as many libraries for (by example) I2C temperature sensors, but each starting from the same number because you use only one type of i2c temperature sensors on your project. Vasi Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
Well, would be nice to have...but not mandatory. Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Hi All, To my mind these are excellent ideas. I like the concept of loadable modules and using a modified MERGE/RENUMBER may be the way to go. This will take some thought... Thanks, Geoff Geoff Graham - http://geoffg.net |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
It may be possible that RENUMBER will rise problems as the user must know the number label of each subroutine within library (conform to the library documentation). An IDE which work with numberless program and subroutines being called by name and not numbers, and at the end, the IDE generating the numbers... is on forum something like that (too tired now to search that topic). The IDE PC application is a tool addition and does not change the fact that the Maximite can be used without PC. Otherwise, a team is definitely required to write (in classic mode) and maintain the libraries, maybe in a SVN environment. It requires some work but the result is useful. Again, Olimex have a (complete?) general image about the peripherals and can help immensely. Vasi Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
Dinosaur Guru Joined: 12/08/2011 Location: AustraliaPosts: 311 |
Hi All Considering that we have a limited amount of memory, one option would be to limit the number of "Use Mod's". Also because of the limited memory, the other option may be to utilise a different load statement. IE:10 USE "TCP-IP.MOD" @ 5000 This would nominate that this ".mod" has to start at 5000, and the programmer knows that the Gosub will be 5000 or a line number after that to call different functions of that ".Mod". This would mean that the ".Mod" would be written starting at line number 10 and the 5000 would be added to it. This would be less complex then renumbering. It then allows the programmer to decide where to put it, and the developer of the ".Mod" to specify that ie:Send Email is at base + 500, and Receive Email is at base + 1000. REgards Regards Hervey Bay Qld. |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
The command MERGE "x.bas", 1000 would encounter the first statement in x.bas and use that line number to create an offset that would be used to modify all of the line numbers in the included file (one line at a time as it is loaded.) In this case the offset would be 900. The entry points for subroutines for the modules would be at the start of x.bas. The first numbered lines might be a group of GOTO statements that lead to the remainder of the included code. Micromites and Maximites! - Beginning Maximite |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
I think this approach is the least amount of work for Geoff to implement (MERGE modified with renumbering) than creating line-numberless basic, or other solutions. And no new file name extension. It is all still .bas files. Micromites and Maximites! - Beginning Maximite |
||||
Olimex Senior Member Joined: 02/10/2011 Location: BulgariaPosts: 226 |
I like the MERGE, INITIAL_ADDRESS idea too if we accept convention that the entry point for all functions in the module is the initial address and there inside the module is conditional GOSUB to the parts of the code depend on some variable value |
||||
jebz Regular Member Joined: 13/06/2011 Location: AustraliaPosts: 79 |
I like this method and think the Basic code should be confined to the users program or shared utility code that calls the precompiled modules. I think this could be especially useful in your example with the MOD-ENC28J60 supporting TCPIP services like http and email. . |
||||
vasi Guru Joined: 23/03/2007 Location: RomaniaPosts: 1697 |
I also like the @Dinosaur idea but the offset will also depend on the step in numbering: - at which line-distance is the gosub gosub_name from the beginning of library? - what is the step used in numbering the lines? - we have already the starting number of the library The answer will be the exact "address" of gosub_name . BUT, we still need to know the maximum length (in lines count) of a library to start another inclusion or to continue with the main program. And this mean numbering "by hand" unless is stated in the library documentation. Anyway, you still need to do some calculations... is a little harder for a new beginner. As for an IDE PC software, it will not impose any kind of MMBasic modifications. It is simply a tool for others wanting to work in another way. It can provide a better library management (you don't have to worry about numbering anymore, the IDE will do that at the end for you) and can help the programmer to concentrate in other directions. And it was already done by @crackerjack here (I didn't saw it's advantage at first but now is the best solution in my opinion for the library concept). Thanks @crakerjack ! [quote="crackerjack (from his documentation)"]Rationale --------- The ability to write MMBasic without line numbers was highlighted as being useful by a number of Maximite users for a variety of reasons; mainly to allow for re-use of library code as well as to avoid situations where the use of absolute line numbers in jump statements such as +GOTO+ & +GOSUB+ and interrupt configuration statements such as +SETPIN+ & +SETTICK+ would result in significant rework and risk of program failure after manually renumbering sections of code. [/quote] Vasi P.S. If is about an open project, you can provide both numberless and numbered sources with no effort. It will be easy for those working directly on Maximite. Hobbit name: Togo Toadfoot of Frogmorton Elvish name: Mablung Miriel Beyound Arduino Lang |
||||
wizard Newbie Joined: 29/07/2011 Location: United StatesPosts: 38 |
Hi, Loading modules, VERY good idea. Can test stuff without recompiling core! Fast compile Fast reload, patching, etc. With a little prior thought, you can load and test modules without recompiling the core! Simple way to begin, absolute assembly language call from MMBasic. Eventually add symbols, etc. One day load and link a real ELF file. Lots of fun. Wiz |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
Example library for character-based LCD interface, LCD.bas: 100 REM LCD Interface library 101 GOTO 200 102 GOTO 300 103 GOTO 400 104 GOTO 500 105 GOTO 600 106 GOTO 700 200 REM Send Command Routine 205 ... (routine here each with RETURN) 300 REM Send Data Routine 305 ... (routine here) 400 REM Clear LCD Screen Routine 405 ... (routine here) 500 REM Home Position Routine 505 ... (routine here) 600 REM Send String Routine 605 ... (routine here) 700 REM Cursor On Routine 705 ... (routine here) After a MERGE "LCD.bas", 5000 5000 REM LCD Interface library 5001 GOTO 5100 5002 GOTO 5200 5003 GOTO 5300 5004 GOTO 5400 5005 GOTO 5500 5006 GOTO 5600 5100 REM Send Command Routine 5105 ... (routine here) 5200 REM Send Data Routine 5205 ... (routine here) 5300 REM Clear LCD Screen Routine 5305 ... (routine here) 5400 REM Home Position Routine 5405 ... (routine here) 5500 REM Send String Routine 5505 ... (routine here) 5600 REM Cursor On Routine 5605 ... (routine here) Routine 1 is always entered (GOSUB) at the merge address + 1. Routine 2 is always entered (GOSUB) at merge address + 2. Documentation for the library would list the routines in order: LCD Library routines Routine 1 - Send Command Routine 2 - Send Data Routine 3 - Clear LCD Screen Routine 4 - Home Position Routine 5 - Send String Routine 6 - Cursor On Micromites and Maximites! - Beginning Maximite |
||||
Dinosaur Guru Joined: 12/08/2011 Location: AustraliaPosts: 311 |
Hi All Something is not clear from the discussion. Are we talking about adding "pre-compiled" modules or ".bas" modules. If we are talking about pre-compiled, AND the suggestion is "No Line Numbers" then I would think the amount of work is enormous. If the modules are in .bas format , then each modules is simply written starting at line 1 to whatever, at any increment the programmer likes. Then the "Use" command would simply add the nominated amount to each line number, and insert the block into the existing code. If the application finishes at at line 500, then "Use tcp.bas @ 510 " would append the module at the end. If adding a second module, then look and see where the first finishes and "Use Eth.bas @ 2350" or whatever. I dont think that is to difficult even for a beginner. Regards Regards Hervey Bay Qld. |
||||
Page 1 of 2 |
Print this page |