Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 15:52 20 Apr 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 : CMM2 - New to BASIC, I need some help with Syntax

     Page 1 of 2    
Author Message
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 08:21am 04 Jul 2020
Copy link to clipboard 
Print this post

Hi everyone. I'm new to this forum and new to BASIC and so far, what i've learned has been fun. I'm still waiting on my CMM2 to be delivered, but in the meantime, i've been writing a program in MMEdit, and running it in QBASIC in DOSBOX.
I'm a Java programmer, and so the conveniences of that have been interesting to work around in basic.

I've started working on a project which i'm going to keep secret for now ;) (i'll announce it if it becomes a thing! haha)

But I need some assistance with certain syntax and datatype stuff. I've ordered a book on QBASIC which might provide some assistance (only £2!).

So, basically, I need to work with hexadecimals (I mean, maybe I dont?) and binary, doing bitshifting and bitmasking on the values that will be traveling around my program.

For example, it might be a case where binary 11001101 comes in and I might want to get the 11001101 and flip it, or return just those 4 bits.

I will need to prevent numbers going negative in certain situations, so that if it rolls down to -1, it rolls over to 255 or something like that.

For a CASE switch, how would I do a "BREAK"? END SELECT? Re-reading the Manual gave me the answer to this. The case should only run the statements within the case it enters and exit the select case on its own.

One other thing is arrays. I need to create an array thats rather large. can I read from any point of the array whenever I want?

I've read through the CMM2 manual and programming PDF's. I will keep re-reading til it sticks, but any examples of things would be a massive help. Thanks for your time!
Edited 2020-07-04 18:37 by Atomizer_Zero
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5885
Posted: 08:35am 04 Jul 2020
Copy link to clipboard 
Print this post

Welcome to the forum.

There are a lot of differences between QBASIC and MMBasic.
It would be best for you to use MMBasic for DOS for your playing.

MMEdit is an IDE for MMBasic and the syntax differences will make life interesting if you try and use it for QBasic.

MMBasic for DOS is very close to the MMBasic on the CMM2.

Jim
VK7JH
MMedit   MMBasic Help
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 08:41am 04 Jul 2020
Copy link to clipboard 
Print this post

Oh I had no idea MMBasic even had a version for DOS! interesting. Would code ran in DOS run faster than on the CMM2?
 
IanT
Regular Member

Joined: 29/11/2016
Location: United Kingdom
Posts: 84
Posted: 08:58am 04 Jul 2020
Copy link to clipboard 
Print this post

I'll let others here better qualified answer most of your questions AZ.

However, I use (DOS) MMBasic on my PC as well as on my Micromites. In fact the whole Maximite/Micromite/Picromite family use the same 'foundation' MMBasic (and syntax). I think this is a real strength of MMBasic (that it's scalable across a range of different platforms these days) that is probably underestimated by many just looking at a single MMB version (most recently CMM2).

I haven't ordered a CMM2 yet but I'm fairly certain I will do so. I managed to get MMBasic running on a Picromite but (for me) it comes with too much other baggage. The CMM2 will be a better solution to my workbench needs. I didn't know whether to be annoyed or amused with various folk commenting on YT recently about "why not use a RPi -it's better/faster/cheaper" etc. This completely misses the point that to some like myself, RPi is certainly not simpler/easier/quicker.

Sorry a simple suggestion to use MMBasic on PC is turning into mini-rant. I don't know anything about QBasic vs MMB compatibility but I thought it was worth mentioning.

Regards,

IanT -  here in same time zone :-)
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 09:08am 04 Jul 2020
Copy link to clipboard 
Print this post

Hi IanT.

I'm not entirely sure what pulled me in to this. I guess the videos shown by Mauro Xavier were one good reason lol.

I didn't know anything about the previous iterations of the Maximite or others before seeing the CMM2. Feel like i've missed the first train..

I loaded up my code in MMbasic, and theres issues from line 1! lol Time to rewrite..
 
IanT
Regular Member

Joined: 29/11/2016
Location: United Kingdom
Posts: 84
Posted: 09:14am 04 Jul 2020
Copy link to clipboard 
Print this post

Jim got there first AZ - I do type quite slowly!  

The DOS version just allows 'straight' basic programming (no graphics per-se) and only serial i/o - but it's pretty quick (enough for my needs) and convenient.

Regards,   IanT
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 09:42am 04 Jul 2020
Copy link to clipboard 
Print this post

Download the DOS version from here:  http://geoffg.net/Downloads/Micromite/DOS_MMBasic.zip

Geoff
Geoff Graham - http://geoffg.net
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 840
Posted: 10:13am 04 Jul 2020
Copy link to clipboard 
Print this post

Hi AZ,
Welcome.
Geoffg and TassyJim are both icons of the MMBasic world so heed what they say!
I am just an old B who learnt BASIC about 50 years ago, then QBASIC ~40 years ago and then QB45 (a "modern" version of QBASIC) about 10 years ago.
I'd not get too involved with QBASIC or QB45 at this time as there are substantial differences in the language (mainly syntax). MMBASIC is cleaner and, to my thinking, easier - thanks to Geoff et al.
I'd download MMBASIC for DOS as Geoff suggests but recognise that it is not a patch on what you can do with the CMM2 (or even the less sophisticated MM170s or MM+).
It lacks a lot of the graphics but the syntax of its commands are the same as you will use in the CMM2 - but it does not support some of the more sophisticated CMM2 commands.
But it will let you get started on the journey until your CMM2 arrives.

The other point of this rambling is that the people on this forum are some of the most helpful people I have come across - don't hesitate to ask a question - it will be answered with understanding and accuracy.

Cheers,

Andrew
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 01:51pm 04 Jul 2020
Copy link to clipboard 
Print this post

Atomizer_Zero -- welcome to the forum.

Many platforms for MMBasic, depending on your needs:

Various pre-CMM2 MaxiMites
Original Micromite 28-pinner MM2/170 & PIC variants
MMBasic DOS
Pi-cromite
Armmite, including my cost/power per i/o pin fav, Armmite-F4 (search STM32F407VET6):
 Armmite-F4
CMM2 -- super graphics

So much to choose from, and the best forum.

~
Edited 2020-07-04 23:55 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 03:17pm 04 Jul 2020
Copy link to clipboard 
Print this post

Thanks for the warm welcome everyone.

I didn't get much time this morning to dive into mmbasic for dos but I at least got some expected results from the functions I made, which is nice.

Is there a way to force an integer to be 4bytes or 8bytes,etc.? I need to be able to keep the values within a range without having to do heavy calculations.
In java I would do "value &0x1f" or "value &0xfffe" for example.
Edited 2020-07-05 01:19 by Atomizer_Zero
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 04:02pm 04 Jul 2020
Copy link to clipboard 
Print this post

Yes, you can do the same sort of thing.
The mmbasic equivalent for "value & 0xfffe" is "value and &hfffe"
"and" does bitwise "and",
hex numbers start with "&h"

There's also "&b" for binary
Edited 2020-07-05 02:03 by capsikin
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 04:45pm 04 Jul 2020
Copy link to clipboard 
Print this post

AZ, welcome and buckle up for the ride of your life  

It is important to remember where MMBasic came from - a Microcontroller with (compared to PCs) small program and working memory areas. With modern PCs etc, memory is scarcely a consideration but with MMs, you are closer to the metal and with no underlying OS to do things like memory management and filesystem, you have to cater for it yourself. Personally this is what draws me to them. Your comment about using a Pi is spot on the money. Yes there is MMBasic for the Pi, but it isn't "instant on" like the micromite/maximite and you take a big risk simply dropping the power on a Pi without shutting down nicely - all overheads I don't want  (and you don't get with the CMM, MM etc.... If you are ok with the overhead of the underlying OS, the Picromite is pretty quick and plenty of people here do use it, but it won't have the amazing grphics stuff of the CMM2. Again, personally, I want to be as close to the metal as I can but ARM assembler and the PIC32/STM setup is a headache. With MMBasic you literally switch on and start running.

In MMBasic, the datatypes are fairly simple - you have a choice of 3 (with some tweaks for String Arrays)

Integer: Takes up eight bytes, huge numeric range and perfect whole number accuracy from 2^63 to -2^63 (+/- 9 Million,Million,Million)
Float: takes just four bytes but does allow "real" numbers. In the Micromite they are the equivalent of QB's single precision, but I think with the CMM2 they are double precision using the hardware FPU on the processor. There is no specific double precision datatype so in QB you will see the # after a variable name. MMBasic will handle this for you but heads-up the precision of Float datatypes changes depending what platform you are on - beware the accuracy issues of all floating point systems.
Strings: all simple strings occupy 256 bytes, 255 for the data and one byte for the length. When using strings in arrays, it is clear they can become shockingly huge very quickly and if you don't need 255 bytes per element then you can limit the array total size by using the Length operative. e.g. if you need an array of 200 five byte strings, you can specifically dimension the array to have precisely that - and the memory footprint drops like a stone with it. You might have to do a bit of work to find out what suits you here.

Variable and built-in function names ending in a $ return a string ($ means string in basic), those that don't, generally return either floats or integers. There are exceptions for variables and your own functions depending on how you declare them but that is fairly advanced if you are new - stick to the defaults to avoid any confusion for now.

On the subject of defaults, Variable names can contain the datatype, so Fred$ is a String, Sheila% is an Integer and Trevor! is a Float. Although Fred$ and Fred! are technically separate variables, MMBasic doesn't permit the names to be shared so in that example it will complain

Decimal numbers are just as you would write them, Hex numbers start with a qualifier of &H e.g. &HBB5A, binary starts with &B e.g. &B01101010 and Octal numbers (does anyone use them?) begin with &O e.g. &O7224

Bitwise actions are sort of munged in with logical operators in Basic.
?&hff And &h1f
31

The default radix is 10, so answers come back in base 10. (Note ? is shorthand for Print - broadly speaking equivalent of Java's System.out.println). If you want things as hex or binary you have to convert it to a string using the HEX$(), BIN$() or OCT$() functions - there's that $ again which tells you the result will be a string, not a number type.
? Hex$(&hff And &h1f)
1F


Much of the above is also true of QB so you weren't far off. The manual is a good primer for MMBasic and it does adhere fairly well to the microsoft basics so any of those up to and including VB6/VBS/VBA (all pretty much the same engine) will give you a head start in MMBasic - I have taken a lot of VB6 functions etc and dropped them into MMBasic with hardly any alterations and it works. You are well advised though to ditch the idea of using QB to train yourself. Use MMbasic for DOS - it won't have all the stuff for LCDPanels etc. but you get all the syntax and building blocks of the language ("primitives").

have fun and don't be afraid to ask here for anything you get stuck on and can't get your head around.

enjoy
Edited 2020-07-05 03:16 by CaptainBoing
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 09:40pm 04 Jul 2020
Copy link to clipboard 
Print this post

  capsikin said  Yes, you can do the same sort of thing.
The mmbasic equivalent for "value & 0xfffe" is "value and &hfffe"
"and" does bitwise "and",
hex numbers start with "&h"

There's also "&b" for binary


Good to know! Thats exactly what I was looking for. Thanks!.


  CaptainBoing said  


Thanks for all that information. Certainly helps me out alot!

I actually have one more question.
Lets say I have my main program. In there, I want to call a function thats in another file. Can I "include" that file into the main program?

For example in the main program file (PROGRAM.BAS), I do FOO = BAR(10). BAR(num) is in a file called PROGRAM2.BAS. is this possible?

Thanks!
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 10:04pm 04 Jul 2020
Copy link to clipboard 
Print this post

  Atomizer_Zero said  Oh I had no idea MMBasic even had a version for DOS! interesting. Would code ran in DOS run faster than on the CMM2?

Hi Jamie, welcome. That depends on how fast the Windows machine is, but generally yes, way faster.

MMBasic.exe is a Windows executable so it isn't really running under DOS but under a Windows command environment. It would run string processing benchmarks way faster than the earlier PIC implementations.

Back in July of 2018 I started this forum thread Is this thing fast enough? which caused a bunch of forum members to run a benchmark program I included in the thread. The thread meandered on until April of 2019 and drifted off topic, but it did produce some timing results.

The benchmark program, TA.BAS, runs five loops as follows:
1. 1,000,000 repetitions of an empty loop
2. 10,000 repetitions of a loop which reads 100 lines from TAIN.TXT
3. writes a new TAJUNK.TXT file containing 1,000,000 lines of text
4. 900,000 repetitions of a loop which extracts a MID$() from a string
5. 1,000,000 repetitions of a loop which takes a VAL() from a string

I ran it on my desktop, an i5 at 5GHz. A forum member, Grogster, ran it on his desktop, a celeron at 2 GHz, an MM+ and an MMX. This table lists the observed running times in milliseconds.

The ratio of the processing time for the MM+ versus the i5 desktop for the five loops is shown in the last column of this table.

               i5 celeron      MMX      MMX      MM+      MM+       RATIO
             5GHz    2GHz   252MHz   200MHz   120MHz   100MHz      MM+/i5
1 empty loop   266     844     5109     6477    13532    16257         61
2  read file  7047   19219   170491   202206   491706   565035         80
3 write file  2891    8203   189127   189466   325843   365102        126
4   mid$(x$)  1906    6125    51147    64282   119408   143456         75
5    val(x$)  1391    4157    26971    33824    70604   84823          20


In answer to your question, I have no idea how fast the CMM2 with the ARM processor will be, but it will probably be faster than the MMX at 252 MHz.

I would appreciate it if any forum member with an operating CMM2 would take the time care to go back to the original thread, copy the TA.BAS program code, run it on the CMM2, and post the results here.

Paul in NY
Edited 2020-07-05 08:11 by Paul_L
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3010
Posted: 01:16am 05 Jul 2020
Copy link to clipboard 
Print this post

For the CMM2 (slower than Celeron, faster than MMX/252):

Running on computer 'CMM2' on 04-07-2020 at 21:14:55
Starting 1,000,000 iterations of empty loop ...
Finished 1,000,000 iterations of empty loop in 1176.8ms or 0.0012 ms per iteration.

Starting reading 100 line file 10,000 times ...
Finished reading 100 line file 10,000 times in 109740.469ms or 0.1097 ms per iteration.

Starting writing 1,000,000 line file ...
Finished writing 1,000,000 line file in 126305.172ms or 0.1263 ms per iteration.

Starting parse 9 strings from 100,000 strings ...
Finished parse 9 strings from 100,000 strings in 24451.567ms or 0.0272 ms per iteration.

Starting extracting the value from a string 1,000,000 times ...
Finished extracting the value from a string 1,000,000 times in 11555.081ms or 0.0116 ms per iteration.

Finished 4,900,000 iterations on computer 'CMM2' in 273240.461ms or 0.0558 ms per iteration.
===============================================

And for the slower/cheaper/different Armmite_F4 (slower than MMX, faster than MM+):

Running on computer 'F4' on 04-01-2020 at 22:17:20
Starting 1,000,000 iterations of empty loop ...
Finished 1,000,000 iterations of empty loop in 7083ms or 0.0071 ms per iteration.

Starting reading 100 line file 10,000 times ...
Finished reading 100 line file 10,000 times in 190500ms or 0.1905 ms per iteration.

Starting writing 1,000,000 line file ...
Finished writing 1,000,000 line file in 221530ms or 0.2215 ms per iteration.

Starting parse 9 strings from 100,000 strings ...
Finished parse 9 strings from 100,000 strings in 108169ms or 0.1202 ms per iteration.

Starting extracting the value from a string 1,000,000 times ...
Finished extracting the value from a string 1,000,000 times in 51852ms or 0.0519 ms per iteration.

Finished 4,900,000 iterations on computer 'F4' in 579148ms or 0.1182 ms per iteration.
===============================================

~
Edited 2020-07-05 11:24 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 03:03am 05 Jul 2020
Copy link to clipboard 
Print this post

Thank you Lance.

Here's the updated table of relative speeds.

                i5 celeron     CMM2      MMX      MMX  ARMMITE      MM+      MM+
              5GHz    2GHz            252MHz   200MHz       F4   120MHz   100MHz
1 empty loop    266     844     1176     5109     6477     7083    13532    16257
2  read file   7047   19219   109740   170491   202206   190500   491706   565035
3 write file   2891    8203   126305   189127   189466   221530   325843   365102
4   mid$(x$)   1906    6125    24451    51147    64282   108169   119408   143456
5    val(x$)   1391    4157    11555    26971    33824    51852    70604    84823

That's getting to be quite an assortment of platforms!!!

I can only reiterate what I said two years ago. I'm amazed at the speed Geoff has wrung out of MMBasic. The DOS implementation beats the speed produced by the defunct Visual Studio FoxPro which was a P code compiler. It almost matches the speed produced by fully compiled Clipper, which is also defunct.

Thank you Geoff! I hope MMBasic winds up being more long lasting.

Paul in NY
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 04:24am 05 Jul 2020
Copy link to clipboard 
Print this post

  Atomizer_Zero said  
Thanks for all that information. Certainly helps me out alot!

I actually have one more question.
Lets say I have my main program. In there, I want to call a function thats in another file. Can I "include" that file into the main program?

For example in the main program file (PROGRAM.BAS), I do FOO = BAR(10). BAR(num) is in a file called PROGRAM2.BAS. is this possible?

Thanks!


You're welcome.

For the CMM2, I've seen "#INCLUDE" in the manual, but I don't know of a way in the DOS/Windows version, or the Pi-cromite which I'm using. Mind you I've only just started using MMBASIC myself.

  CaptainBoing said  If you are ok with the overhead of the underlying OS, the Picromite is pretty quick and plenty of people here do use it, but it won't have the amazing grphics stuff of the CMM2.


It doesn't have all of the graphics stuff, but the sprites and full smooth colour are pretty nice.

The main things I'm missing for simple games are the sound/play commands and "keydown" keyboard reading from the CMM2.

(and of course the simplicity of not being based on the Pi)

-- Caspian
 
Bizzie
Senior Member

Joined: 06/07/2014
Location: Australia
Posts: 185
Posted: 05:50am 05 Jul 2020
Copy link to clipboard 
Print this post

While this is not using an include file the library facility does allow you to "include" more subs/functions see Special Functions and Library in the Micromite manual.
Rob White
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 07:25am 05 Jul 2020
Copy link to clipboard 
Print this post

  Bizzie said  While this is not using an include file the library facility does allow you to "include" more subs/functions see Special Functions and Library in the Micromite manual.


Ah I see. I'll have to wait until I get my CMM2 before I can use that feature then, as it doesn't appear to be supported on the dos version. Thanks for the info.
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1345
Posted: 08:10am 05 Jul 2020
Copy link to clipboard 
Print this post

  Atomizer_Zero said  
  Bizzie said  While this is not using an include file the library facility does allow you to "include" more subs/functions see Special Functions and Library in the Micromite manual.


Ah I see. I'll have to wait until I get my CMM2 before I can use that feature then, as it doesn't appear to be supported on the dos version. Thanks for the info.


Don't think you will find Library in the CMM2 command set, the #INCUDE command for SD include files is the closest replacement as the CMM2 Editor is SD file biased.
It's all too hard.
Mike.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024