Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:02 01 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 : CMM2: Basic Extensions and Other Thoughts.

Author Message
johnd
Newbie

Joined: 22/10/2020
Location: United States
Posts: 30
Posted: 11:06am 21 Nov 2020
Copy link to clipboard 
Print this post

So, I'm working on StarTrek kind of clone game, modeled after the old text versions.  And as I sit here and program this, I'm thinking about a wish list:

1) Data structures, like the C 'struct' type.
2) List, Map, and Set data types, similar to what you see in Java, C#, etc.
3) The ternery operator:  x = (y > 1) ? 0 : -1

The game would be so much easier to program and read with these elements.  However, that would probably move the language to something other than BASIC (though I believe there are some flavors of basics that handle data structures).  Also, it's kind of fun to have to rethink how to work around these missing items, and I certainly did this type of stuff 40+ years ago, so I should be able to do it today.

I'm not really expecting to ever see these items on the CMM2, and I am truly enjoying the fun and nostalgia of old school programming.  So thanks to those who have brought the CMM2 into existence and for making it what it is today and in the future.

On a second note: just did my first firmware update, and my initial attempt failed the upload -- I run a Linux computer at home and was following the instructions for using the dfu-util program.  I did the UPDATE FIRMWARE command, then plugged in the cable, saw the device on the PC, and did an update, but the progress bar never moved forward.  When I reset the machine, I just had a blank screen.  Hmm, I was a little worried about having a new $100 door stop, but I continued and tried again.

Since I couldn't issue the firmware command this time (having only a black screen), I used the firmware update button (held it down while turning the machine back on), and this time was able to do the update.  It booted up with version v5.06.b02 I think.  Cool, now I have access to the CALL command, variable PAGE sizes, and improved graphics.  From now on, I'll just use the update button instead of the software command.

Cheers, JohnD
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 11:24am 21 Nov 2020
Copy link to clipboard 
Print this post

Hi John,

If performance isn't a bottleneck then you will find code for manipulating Lists, Sets, Stacks and Maps of Strings here: https://github.com/thwill1000/sptools/tree/develop-r1b3/src/common

Make sure you are looking at the "develop-r1b3" branch, not the "master" as I've substantially improved the API since the last "published" version.

To get an idea of how to use them look at the unit-tests in the "tests/" directory.

For structures you'll have to wait a while longer, I have some ideas, but there are other dragons to slay first.

I agree that a built-in ternary operator would be useful, probably in basic it would look something like:
result = TERNARY(condition, ontrue, onfalse)


@matherp I don't suppose that recent magic has made any room for this ... I suspect not since the magic you described to me would only free up COMMAND slots, not FUNCTION slots.

@johnd Of course if performance isn't an issue you can always write your own FUNCTIONs to achieve that.

Best wishes,

Tom
Edited 2020-11-21 21:26 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 11:32am 21 Nov 2020
Copy link to clipboard 
Print this post

Addendum:

Again depending on your performance concerns and how many fields you require in your structures one possible alternative is to use Strings of comma-separated values and the FIELD$() function. Being Strings these can then be stored in the list/map/set implementations linked to above.

Tom
Edited 2020-11-21 21:32 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 11:35am 21 Nov 2020
Copy link to clipboard 
Print this post

  johnd said  3) The ternery operator:  x = (y > 1) ? 0 : -1


function TernaryIf(condition, iftrue, iffalse) ' add data types to your liking
if condition then
TernaryIf = iftrue
else
TernaryIf = iffalse
endif
end function

(untested)

  johnd said  firmware update, and my initial attempt failed the upload -- I run a Linux computer

It should just work.  Apart from finger trouble, bad cables / power are the most likely.

John
Edited 2020-11-21 21:37 by JohnS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 11:39am 21 Nov 2020
Copy link to clipboard 
Print this post

  JohnS said  
  johnd said  3) The ternery operator:  x = (y > 1) ? 0 : -1


function TernaryIf(condition, iftrue, iffalse) ...


I agree, but it's quite a lot of overhead.

Note for the specific example given by the OP I believe this would suffice:
x = (y > 1) - 1


Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
johnd
Newbie

Joined: 22/10/2020
Location: United States
Posts: 30
Posted: 12:06pm 21 Nov 2020
Copy link to clipboard 
Print this post

I like the Ternery() function solution.  It's simple and works.  My game is not a high performance one, so I don't think I need to worry about utilizing lots of subroutines and functions.  Thanks!

Also, I'll look at the list/map/set code to see if it will work for me.  I think these items work best with data structures, but I might have use for them.  Without data structures, I'm having to use String/integer.float arrays and some singleton variables just for the state of objects, so I'd have to keep separate Lists/Maps/etc for each of these.  For example, a Ship object may have a String name, Integer x,y coordinates, and a float array of ship system values (for % energy, shields, etc), and another array for damage for each ship system.  So a list or map for each of these is probably a bit much for my game at the moment.  But something like:

 struct SHIP
   String name
   String owner
   Integer sx, sy
   Integer qx, qy
   Float systems[NUM_SHIP_SYSTEMS]
   Float damage[NUM_SHIP_SYSTEMS]
end struct

would be nice , then you could

 DIM SHIP ships(MAX_NUM_SHIPS)

But, it's working out right now, and I think I will implement that Ternery function.  That just comes in handy in so many places.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 01:08pm 21 Nov 2020
Copy link to clipboard 
Print this post

  thwill said  
  JohnS said  
  johnd said  3) The ternery operator:  x = (y > 1) ? 0 : -1


function TernaryIf(condition, iftrue, iffalse) ...


I agree, but it's quite a lot of overhead.

Note for the specific example given by the OP I believe this would suffice:
x = (y > 1) - 1


Tom

Whereas that is unreadable :(

In almost all cases no-one needs it faster than a function.

I'd rather have readable than fast except when absolutely necessary...

John
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 01:10pm 21 Nov 2020
Copy link to clipboard 
Print this post

  johnd said  But something like:

 struct SHIP
   String name
   String owner
   Integer sx, sy
   Integer qx, qy
   Float systems[NUM_SHIP_SYSTEMS]
   Float damage[NUM_SHIP_SYSTEMS]
end struct

would be nice

It would but Peter (at least) has explained why it's such a mammoth change that it won't happen.

Have a read of the C source and find out why.

You could, of course, use something like what you posted either by dropping to C or some sort of code converter (transpiler anyone?).

John
Edited 2020-11-21 23:11 by JohnS
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 203
Posted: 04:06pm 21 Nov 2020
Copy link to clipboard 
Print this post

My 2 cents:

When implementing structs, please allow for entries for functions (is that "pointers to functions"?  I don't know...).  So, Johnd's example might then be:
struct SHIP
  String   name
  String   owner
  Integer  sx, sy
  Integer  qx, qy
  Float    systems[NUM_SHIP_SYSTEMS]
  Float    damage[NUM_SHIP_SYSTEMS]
  Sub      FirePhasers[INTENSITY]
  Sub      FirePhotonTorpedoes[NUMBER]
  Function Heading
end struct


I'll have to take a look at Tom's lists / sets / map implementation.  Long after learning C, I picked up functional programming with Haskell, and really appreciated the metaphor.  Those features, combined with "functions as first-class data types" would enable some extremely powerful functionality on our wonderful little machines.

Again, my intense appreciation for this fabulous ecosystem and its inhabitants.
Live in the Future. It's Just Starting Now!
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 504
Posted: 04:55pm 21 Nov 2020
Copy link to clipboard 
Print this post

For some cases I'm using a unidimensional array to store the obj data, something like this:


' X,Y,Z position, X,Y,Z angles, 5*X,Y,Z vertices, etc
dim obj1(3+3+5*3)


and I can access each value using its position.


' X,Y,Z position, X,Y,Z angles, 5*X,Y,Z vertices, etc
obj1(0) ' Position X
obj1(1) ' Position Y
obj1(2) ' Position Z


A command to copy data from one array to another it will be very useful to manipulate this type of data structure, maybe can be called MATH COPY.


' X,Y,Z position, X,Y,Z angles, 5*X,Y,Z vertices
dim obj1(3+3+5*3)
dim obj2(3+3+5*3)
...
dim objver(5*3)
....
MATH COPY obj1(), 6, objver()
....

Edited 2020-11-22 02:56 by LeoNicolas
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 06:44pm 21 Nov 2020
Copy link to clipboard 
Print this post

  johnd said  So, I'm working on StarTrek kind of clone game, modeled after the old text versions.  And as I sit here and program this, I'm thinking about a wish list:

1) Data structures, like the C 'struct' type.
2) List, Map, and Set data types, similar to what you see in Java, C#, etc.
3) The ternery operator:  x = (y > 1) ? 0 : -1

The game would be so much easier to program and read with these elements.  However, that would probably move the language to something other than BASIC (though I believe there are some flavors of basics that handle data structures).  Also, it's kind of fun to have to rethink how to work around these missing items, and I certainly did this type of stuff 40+ years ago, so I should be able to do it today.

I'm not really expecting to ever see these items on the CMM2, and I am truly enjoying the fun and nostalgia of old school programming.  So thanks to those who have brought the CMM2 into existence and for making it what it is today and in the future.

On a second note: just did my first firmware update, and my initial attempt failed the upload -- I run a Linux computer at home and was following the instructions for using the dfu-util program.  I did the UPDATE FIRMWARE command, then plugged in the cable, saw the device on the PC, and did an update, but the progress bar never moved forward.  When I reset the machine, I just had a blank screen.  Hmm, I was a little worried about having a new $100 door stop, but I continued and tried again.

Since I couldn't issue the firmware command this time (having only a black screen), I used the firmware update button (held it down while turning the machine back on), and this time was able to do the update.  It booted up with version v5.06.b02 I think.  Cool, now I have access to the CALL command, variable PAGE sizes, and improved graphics.  From now on, I'll just use the update button instead of the software command.

Cheers, JohnD


"Modern" versions of basic are more structured then what you would be used to from the 80s(if you used it back then). MMBASIC supports the proposed then withdrawn standard for basic which has a lot of the types of things you want. if you google around you can find the standard online its pretty interesting reading.
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 06:48pm 21 Nov 2020
Copy link to clipboard 
Print this post

if you really want to go down the rabbit hole https://www.truebasic.com/. getting this to run on the cmm2 is impossible as this is not a open source language but it shows you were basic was and is heading if it had not died.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 07:15pm 21 Nov 2020
Copy link to clipboard 
Print this post

@LeoNicolas if I understand you correctly then the command you are looking for is MEMORY COPY and already exists, though I'm not sure it's in the documentation, see https://www.thebackshed.com/forum/ViewTopic.php?TID=12998&PID=158397#158397

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 09:07pm 21 Nov 2020
Copy link to clipboard 
Print this post

@LeoNicolas
MATH ADD sourcearray(),0,destinationarray()
or
MATH SCALE sourcearray(),1,destinationarray()

Visit Vegipete's *Mite Library for cool programs.
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 504
Posted: 10:30pm 21 Nov 2020
Copy link to clipboard 
Print this post

  thwill said  @LeoNicolas if I understand you correctly then the command you are looking for is MEMORY COPY and already exists, though I'm not sure it's in the documentation, see https://www.thebackshed.com/forum/ViewTopic.php?TID=12998&PID=158397#158397

Best wishes,

Tom


Yes Tom, these commands probably will work. I'll perform some tests.

@Vegipete

MATH ADD and MATH SCALE only work for the entire array, not to copy a specific part of it. The idea is to do something like the SUBSTRING is doing to string.

The MEMORY COPY is exactly what I was thinking, but maybe an alias like MATH COPY will be more clear and it will not be necessary to worry about the array address.
 
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