![]() |
Forum Index : Microcontroller and PC projects : CMM2: Basic Extensions and Other Thoughts.
Author | Message | ||||
johnd Newbie ![]() Joined: 22/10/2020 Location: United StatesPosts: 30 |
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 KingdomPosts: 4311 |
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 KingdomPosts: 4311 |
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 KingdomPosts: 4044 |
function TernaryIf(condition, iftrue, iffalse) ' add data types to your liking if condition then TernaryIf = iftrue else TernaryIf = iffalse endif end function (untested) 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 KingdomPosts: 4311 |
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 StatesPosts: 30 |
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 ![]() 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 KingdomPosts: 4044 |
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 KingdomPosts: 4044 |
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 StatesPosts: 203 |
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: CanadaPosts: 504 |
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 StatesPosts: 76 |
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 StatesPosts: 76 |
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 KingdomPosts: 4311 |
@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: CanadaPosts: 1132 |
@LeoNicolas MATH ADD sourcearray(),0,destinationarray() orMATH SCALE sourcearray(),1,destinationarray() Visit Vegipete's *Mite Library for cool programs. |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 504 |
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. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |