![]() |
Forum Index : Microcontroller and PC projects : MMB4L: MMBasic for Linux alpha release
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
Quazee137![]() Guru ![]() Joined: 07/08/2016 Location: United StatesPosts: 586 |
I made a folder MMB4L unpacked the download into it made mmbasic executable opened minicom from folder typed ./mmbasic and its up and running. Now playing with it. THANKS for doing this. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
You're welcome. That's odd, it looks like it is already flagged as an executable file in the .tgz archives. Which version did you download ? What are you doing with "minicom" ? that's a serial comms program "useful" for connecting to a CMM2 or a PicoMite from a Linux box. MMB4L should just run natively in a Linux terminal. Please let me know how you get on. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Hi folks, I'm still futzing about with error codes and exit codes, possibly in a way that only matters to a true Linux geek, but I'd still like input if anyone has any. ERROR CODES In MMB4L the user can now specify an optional (default 1) error code to the ERROR command: ERROR "my error", 128 And then that value is retrievable using the existing MM.ERRNO variable/function. Other MMBasic implementations don't seem to provide the mechanism for the user to specify an error code and (seemingly by historical accident) use the value 16 for any ERROR except those from the file-system which are implementation dependent. The CMM2 for example will return a 16 both for a general error and also specifically for the "The operation is rejected according to the file sharing policy" error ![]() For MMB4L I'm being a bit more rigorous and currently working along the lines of: 0 : no error. 1 : unclassified MMBasic error, also reported if a C library call reports the error EPERM (Operation not permitted). Note this differs from other versions of MMBasic which use the value of 16 for general errors, which would correspond to the EBUSY (Device or resource busy) error from a C library call. 2..150 : standard error numbers (errno) for C library calls. 151..200 : reserved for future classification of MMBasic errors. 201..255 : suggested range for program specific error codes. Error codes from the SYSTEM command will be an exception to this and instead equal to the exit code of the executed command. Note there is no particular reason to restrict error codes to single byte values and MMBasic currently supports any signed 32-bit value. EXIT CODES The micro-controller versions of MMBasic don't really have an equivalent to this, but when a C program (such as MMB4L) exits it "returns" a 32-bit signed exit code to the operating-system or script that launched it so that it can act on the result if it wants. POSIX only standardises two values for this, 0 for success and 1 for general failure. The bash shell takes this further (https://tldp.org/LDP/abs/html/exitcodes.html) and it also modulos the exit code 256 so only single byte values of that "32-bit signed exit code" are valid. For MMB4L the QUIT and END commands will have an optional (default 0) integer argument to allow an exit code to be specified: END 1 QUIT 128 1. When running interactively END will end the current program and the exit code of the last program can be read via MM.INFO(EXITCODE) - though TBH I'm not sure this has much utility except for testing that the optional argument works. 2. QUIT (and when not running interactively END) exit the MMB4L (mmbasic) process with the given exit code. 3. When not running interactively an ERROR will also exit the MMB4L (mmbasic) process but I'm unsure what to use as the exit code, see below. My questions to anyone still reading 1. Should the argument values to END and QUIT be restricted to a single byte even though the underlying C allows any signed 32-bit result ? 2. What should the exit code for an ERROR be, should it just be the catch-all 1, or should it be equal to the error's code or something else ? ... despite its appeal I'm currently thinking not the error code because error and exit codes aren't generally considered interchangeable with Linux/C. Best wishes, Tom Edited 2021-10-11 21:42 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7503 |
1. Yes, purely for 8-bit psychological reasons. :) (I'm not sure that it's important, is it?) 2. It would be nice to know if it's a program error or a data error (unable to find a file, no write access to a file or something like that). Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
I'm not sure about importance. If you are running MMB4L from the bash shell then the easily accessible exit code will be automatically modulo 256 ... it's tricky, but not impossible to get the longer exit code. I guess either I have to expect the user to trap the errors and call END with an appropriate exit code or I need to create a fixed mapping between errno.h (of which multiple versions exist) and sysexits.h Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
So it turns out (unexpectedly to me) you can do this using MMB4L ... EDIT: USING THE IN-PROGRESS alpha2, sorry File "print_hello.bas": #!/home/thwill/github/mmb4l-src/build/mmbasic Print "Hello World" Make that file executable and then just run it: ./print_hello.bas And lo and behold: thwill@pseuk1140-ubuntu20-vm:~$ ./print.bas Hello World That's neat ... wonder how I retrieve any command line arguments ? EDIT: turns out it just works with the other changes I'm making for alpha2. Best wishes, Tom Edited 2021-10-11 22:57 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Rado Regular Member ![]() Joined: 27/11/2020 Location: CroatiaPosts: 59 |
For first, I'd argue that 8-bit value should be enough. For second, I think it is much more handy to use error code as the exit code, as this would make catching the error from the program wrapped in some shell easier. Of course, it is up to the user to know what is coming out of the program and how to handle that. Those error codes do not need to conform to Linux codes neccessarily - in fact, that might hinder portability to other platforms, if some other versions decide to implement that functionality. Remember, we're still thinking about MMB as an encapsulated environment with its own tiny set of rules and customs. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
I'm thinking that too. I don't think that is going to cut it due to conflicts such as the value 130 which bash interprets as "Script terminated by Control-C" but C (and thus MMB4L) uses for "the per-user limit on new process would be exceeded by an attempted fork." - not a great example, at least until MMB4L has FORK implemented, but indicitive of potential conflicts. I'm not thinking that ![]() Best wishes, Tom Edited 2021-10-11 23:31 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2399 |
imho, basic errors (such as 'next without for') should just be printed as plain text, as they currently are with mmbasic. exit codes should be reserved for user use, with the exceptions: 0 = no exit code specified, 255 = a basic error (as above) has occurred. exit codes 1..254 are passed out: EXIT n and/or STOP n, where n is any value from 1..254 this enables mmbasic to be used within shell scripts to control flow, present fancy menus, etc. cheers, rob :-) |
||||
Quazee137![]() Guru ![]() Joined: 07/08/2016 Location: United StatesPosts: 586 |
thwill yea about minicom I have a bash that I use with the mites and added MMB4L to it and cut n past of things left the minicom title. LOL Thanks Again. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Alpha 2 is now available for x86_64, i686 and armv6l (Raspberry Pi): https://github.com/thwill1000/mmb4l Even if it doesn't have a specific feature you need yet can I ask a favour of anyone who has a Linux installation and thinks MMB4L might be something they can use in the future? Please download, install and give it a brief smoke-test, that will help me flush out some of the more obvious bugs and perhaps identify some low hanging fruit to be implemented in the next alpha. ChangeLog Version 2021.01.00-a2 - 6-Nov-2021: - Added ability to specify at the Linux shell a BASIC program that MMB4L should RUN when it starts, e.g. ./mmbasic myprogram.bas arg1 arg2 arg3 see README for details. - Added optional integer argument (default 0) to END and QUIT that can be used to return an exit code to the Linux shell, see README for details. - Added SETTICK command from the CMM2: - SETTICK FAST is not supported. - Be aware that Since Linux is not a Real Time Operating System all timing commands such as PAUSE and SETTICK are subject to more error and variation than on the microcontroller MMBasic implementations. - Added JSON$() function from the CMM2: - MMB4L adds an optional 3rd parameter which is a 2 bit argument controlling how explicit nulls and missing values are handled in the JSON: - &b00 : return empty strings for both. - &b01 : return "<null>" for explicit null. - &b10 : return "<missing>" for missing value. - &b11 : return both "<null>" and "<missing>". - Added DAY$(), DATETIME$() and EPOCH() functions from the CMM2: - note that unlike DATE$ and TIME$ the DATETIME$(NOW) function will return the date & time in UTC, not in the local timezone. - Added missing MEMORY, PEEK and POKE sub-commands. Now implements the same as the CMM2 (5.07.01) with the exception of the undocumented/legacy: PEEK(hiaddr, loaddr) POKE hiaddr, loaddr, byte And with the addition of: MEMORY COPY BYTE src, dst, number_of_bytes - which is equivalent to MEMORY COPY src, dst, number_of_bytes MEMORY COPY SHORT src, dst, number_of_shorts MEMORY COPY WORD src, dst, number_of_words - Added optional integer array parameter to SYSTEM command to allow any standard output generated to be captured in a LONGSTRING, e.g. DIM out%(100) SYSTEM "ls", out%() LONGSTRING PRINT out%() - Added support for prefixing paths with '~' which is expanded to the users home directory (the value of the HOME environment variable). - Added optional integer argument (default 1) to ERROR command allowing an error code to be specified, this can be retrieved using MM.ERRNO, e.g. ERROR "error message", 220 For MMB4L the values of MM.ERRNO are: - 0 : no error. - 1 : unclassified MMBasic error, also reported if a C library call reports the error EPERM (Operation not permitted). Note this differs from other versions of MMBasic which use the value of 16 for general errors, this would correspond to the EBUSY (Device or resource busy) error from a C library call. - 2..150 : standard error numbers (errno) for C library calls. - 151..200 : reserved for future classification of MMBasic errors. - 201..255 : suggested range for program specific error codes. - error codes from the SYSTEM command are an exception to this rule, see the next entry. - Changed SYSTEM command to set MM.ERRNO equal to the executed program's exit code. Also changed error message to include this value. - Changed CONSOLE SETCURSOR command to allow a maximum x, y of 1023 (previously 255) and updated "examples/mandelbrot.bas" to support this. - Changed "mmbasic.nanorc" to make behaviour more like the CMM2 editor: - added 'set constantshow' so the cursor position display is always visible. - added 'set zap' so that [Delete] and [Backspace] erase all the selected text instead of just a single character. - either of these can be commented out with # if you prefer. - Fixed issues with "mmbasic.syntax.nanorc": - command keywords always highlighted, not just when they are the first token on a line. - hexadecimal and binary constants highlighted as numbers (green). - comments correctly highlighted following string constants containing apostrophes. - highlighting of additional keywords. - Fixed timeout bugs with CONSOLE GETCURSOR: - increase the timeout to 10s. - correct the signed 64-bit arithmetic used in timing code. - Fixed bug where navigating the command prompt history with up/down arrow keys would show display artifacts when using PuTTY; though not sure why the issue was not generally visible. - Many other fixes and tweaks for minor issues encountered along the way. MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1111 |
Hi Tom, Running on Mint 20.2 just fine. Converted one of cdeagles astromite programs (seasons) to run in console mode and it runs successfully. Will convert the others in his suite and report. Found a frustration on my system in that the Del key generated a backspace (deleted the character to the left of cursor) the same as the actual backspace key. I modified this in ~/.mmbasic/mmbasic.nanorc such that ^H now generates a delete operation (ie. delete character under the cursor) with the additional entry set ^H delete main This meant I had to loose the ^H replace option and I changed this to Alt H to retain this capability with set M-H replace main I also commented out some of the deprecated options (these may still be needed fro pre 4.8) I have zipped a copy of the modified mmbasic.nanorc for anyone interested. You have done a terrific job on this - very well done and thanks. Doug. Modified mmbasic.nanorc - works for me but use at your own risk. mmbasic.nanorc.zip ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1111 |
It appears the variable name ls is not allowed?? The following program demonstrates:- a = 5 b = 8 ls = a * b print ls As ls is a normal terminal mode command to list files, has this slipped into mmb4l somehow ![]() I found this in cdeagles moon_phases.bas program which works perfectly once you globally change ls to something else (I changed it to ls1) Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1111 |
cdeagles lunar_eclipse.bas also works in console mode. Note that all these programs from cdeagle are particularly complex and I imaging they really stress the number crunching capabilities so your work on mmb4l that allows them to run correctly is outstanding, thanks. Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7503 |
Flippin' 'eck Tom! Change log? Until I looked more closely I thowt it were the flippin' source code! ;) Back when I were a lad that'd have taken up half a teletype roll... Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Thanks Doug. It works as expected on my Ubuntu 20 system (and I haven't noticed an issue elsewhere), I suspect it is nothing specifically to do with MMB4L or Nano, but instead a property of the terminal you are using. In "GNOME Terminal (3.36.2)" this is configurable on the "Compatibility" page of its preferences, I have the (Ubuntu?) defaults of Backspace generating "ASCII DEL" and Delete generating "Escape sequence". That's funny I'm running 4.8 and haven't noticed any deprecated options being reported, I do see a couple with Nano 5.7 (built from source on github). There are both advantages and disadvantages to using Nano to implement EDIT, I may consider providing multiple rc files for the common Nano versions. Most of the time I actually edit in a separate window using VSCode or geany. If you save a file from an external editor then MMBasic will automatically pick up any changes the next time you RUN or LIST the file. MMB4L deliberately tries to adheer to the behaviour of the CMM2. On that system "LS" is a command the same as "FILES" on the other 'mites. Whereas on the CMM2 "FILES" launches a TUI file-manager (which I haven't ported) which to be honest I think was a mistake by Peter, should have been "FM" (or something similar) instead. Bottom line in MMB4L "FILES", "LS" and "LIST FILES" are all supposed to do the same thing - though I've just discovered "LIST FILES" isn't implemented, I'll fix that for alpha 3. If it really bothers you I don't mind adding an OPTION controlling whether "LS" is a command or not. I'd love to take credit for that, but that is part of the core MMBasic and is all Geoff's work. It's written in portable C and thus requires no effort to port to another platform. When porting MMBasic its the memory management and I/O (including console/serial, file system and graphics) that take the work. It is a month and a half since alpha 1, in that time Peter has had a dozen alphas/betas - we have different styles - and he has a more rabid ![]() I miss printouts on green and white striped continuous paper. Such printers were on their way out when I did my degree but they still had a band printer in the Chem. Eng. department (I was an approximation to a real engineer once). Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7503 |
You *have* been busy... :) I've just been sorting some stuff out and found about 1.25" thickness of plain burstable tractor feed paper. :) No teletype rolls though, although I have a holder for them to fit my Microline 80 printer (which needs a new eyelet-ended typewriter ribbon and a Centronics lead to somewhere to make it work again). I don't think it'll see any more service now. :) Hmmm... ls is a command both on the CMM2 and in linux, the platform that MMB4L is on. TBH I think that should be the default option given the circumstances. In fact, I wish more OSs would use ls. DIR and FILES are so clunky! Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
FWIW, pin I/O works as before with MMB4L V2 on a Raspberry Pi Zero W, using the deprecated sysfs method with SYSTEM calls. Progress is being made with incorporating the "user space" libgpiod Version 2 method (enabling SETPIN, ?PIN(n), and PIN(n)=0/1). pinpi.bas for MMB4L V2 (same as for V1): pi@skypi:~ $ mmbasic Linux armv6l MMBasic Ver 2021.01.00-a2 Copyright 2011-2021 Geoff Graham Copyright 2021 Thomas Hugo Williams > load "pinpi.bas" > list ' pinpi.bas performs digital I/O with MMB4L ' dim integer i,j,k,p(4)=(0,12,16,20,21) dim integer pState(16) dim integer q(4)=(0,25,8,7,1), dout=1, din=0 for i=1 to 4 setpin p(i),dout cmd$="echo '1' > /sys/class/gpio/gpio"+str$(p(i))+"/value" system(cmd$) pause 500 next for i=1 to 4 setpin q(i),din cmd$="echo '0' > /sys/class/gpio/gpio"+str$(p(i))+"/value" system(cmd$) pause 500 next do for i=1 to 4 open "/sys/class/gpio/gpio"+str$(q(i))+"/value" for input as #1 a$=input$(1,#1): close #1 ' 0 or 1 cmd$="echo '"+a$+"' > /sys/class/gpio/gpio"+str$(p(i))+"/value" ' print cmd$ system(cmd$) next i pause 2000 loop sub setpin(pinno as integer, pinmode as integer) local string dirname$, cmd$ dirname$="/sys/class/gpio/gpio"+str$(pinno) if not MM.INFO(EXISTS DIR dirname$) then cmd$="echo '"+str$(pinno)+"' > /sys/class/gpio/export 2>/dev/null" ' print cmd$ system(cmd$) pause 200 endif dirname$=dirname$+"/direction" if pinmode then cmd$="echo 'out' > "+dirname$ else cmd$="echo 'in' > "+dirname$ system(cmd$) pause 200 cmd$="gpio -g mode "+str$(pinno)+" up" ' set weak pullup endif ?pinno,cmd$ system(cmd$) pause 200 end sub > ~ Edited 2021-11-07 23:33 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1111 |
Tom, No problems on either the del key or ls issues - I just thought I would raise them for your info. No action required on my behalf - thanks again. Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Calli Regular Member ![]() Joined: 20/10/2021 Location: GermanyPosts: 74 |
Can I ask for a Raspi Bare Metal version? :) SCNR. I will give it a try some time later (work...) Thanks! Carsten |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |