Joined: 05/10/2019 Location: United KingdomPosts: 6834
Posted: 04:58pm 03 Mar 2022
Not sure about the comments... Doesn't RESTORE n restore to the nth line of data, ignoring comment lines? I must admit, I've not tried it and I haven't got anything set up to do so at the moment.
Not all 'mites support INC anyway, it's true. You either run self-contained or fit a SDcard (where you can) and use files. Actually, BINARY would make a lot of sense. Even if it's the same token as CSUB it's more obvious to the reader that it's not executable.
thwill
Guru
Joined: 16/09/2019 Location: United KingdomPosts: 4048
Posted: 05:09pm 03 Mar 2022
My reading of the manual is that it restores to line N of the file, not the N'th line of data. Having just tried it out then if MMB4W is indicative it also requires the file to use line numbers in the first place - about the only thing it adds to earlier BASICs is that the line number can be specified using a variable, nothing for me here.
Best wishes,
Tom Edited 2022-03-04 03:18 by thwill
Mixtel90
Guru
Joined: 05/10/2019 Location: United KingdomPosts: 6834
Posted: 06:19pm 03 Mar 2022
I've just finished my pizza, set up a PicoMite and had a play. I see what you mean. It's of limited use, but much better than having to read the data into an array before you can access it easily. It does let you use multiple pointers to the data though, and you can put comments anywhere as it's looking for the line numbers, not the data itself. It certainly works when you need embedded data, though, using almost standard syntax.
' Random book title generator ' Pointless demo of DATA RESTORE READ
Noun1: 1 Data "Mill" 2 Data "Apricot" 3 Data "Mouse" 'we can put 'comments anywhere 'please feel free to add your own! 4 Data "Shoe" 5 Data "Typewriter"
Noun2: 6 Data "Sideboard" 'this is a comment 'on two lines 7 Data "Table" 'and another comment 'yet another comment 8 Data "Floss" 9 Data "Telly" 10 Data "River"
Do 'honestly, this is just silly... a=Int(Rnd*5) Restore a+1 Read b$ Randomize Timer a=Int(Rnd*5) Restore a+6 Read c$ Print "The "b$" on the "c$"" Pause 2000 Loop
Edited 2022-03-04 07:02 by Mixtel90
phil99
Guru
Joined: 11/02/2018 Location: AustraliaPosts: 2149
Posted: 12:01am 04 Mar 2022
It is decades since I last used DATA statements for internal data. Pre-filled arrays are more flexible. For external data bitmap images are very convenient, for Basics that support images.
On any MM with a screen the lazy way is to create the BMP by writing pixels to the screen then SAVE BMP "...". In the program needing the data load the BMP then read back the pixels from the screen. As most screens are RGB(565) it is possible to get 16 bits per pixel, but as I am lazy it is easier with 3 bits per pixel. Edited 2022-03-04 16:27 by phil99
TassyJim
Guru
Joined: 07/08/2011 Location: AustraliaPosts: 6108
Posted: 06:21am 04 Mar 2022
RESTORE restores the data pointer to a line number if you are using line numbers (something to avoid) or a label whether you are using line numbers or not.
Provided you use labels to mark different DATA sections, you should have no trouble finding the data you are looking for, no matter what a rouge include does to the data pointer.
Jim
JohnS Guru
Joined: 18/11/2011 Location: United KingdomPosts: 3820
Posted: 07:39am 04 Mar 2022
Not quite. If you call a function (or sub) and it moves the pointer you can easily end up in a mess.
I think Tom (thwill) wants full encapsulation (so the above can't happen). Makes sense.
John
Mixtel90
Guru
Joined: 05/10/2019 Location: United KingdomPosts: 6834
Posted: 07:43am 04 Mar 2022
Pre-filled arrays would be nice, but are rarely available in BASIC. Also, you require an array for each data type as a minimum. DATA statements can contain any mix of data types providing you read them correctly. Last time I used screen RAM to store data was probably on a Speccy. lol The Nascom was better as it had several hidden characters per line which could store the data without it being seen.
The point of my silly demo, Jim, was to illustrate that the DATA can be handled like a read-only array. I would always avoid line numbers normally, but in this particular case there isn't really a substitute unless you create the label with something like
dataline1: DATA dataline2: DATA dataline3: DATA 'etc
n=11 'this is the data line pointer mylabel$ = "dataline"+str$(n) restore mylabel$
which is rather neat but slower. It does give the ability to split the DATA block into individual segments though.
The point is, as Tom has pointed out, there isn't a way to store built-in data on MMBasic platforms unless it's a kludge. You can use CSUBs as data stores where they are allowed but that's about it. You can only use files, arrays or "magic data" strings if you have a storage device otherwise you have to load them from DATA statements in your program - very inefficient. . Edited 2022-03-04 17:55 by Mixtel90
PeterB Guru
Joined: 05/02/2015 Location: AustraliaPosts: 651
Posted: 08:29am 04 Mar 2022
G'Day All
I now understand that my WIN7 PC can talk to an 8 bit micro over USB that isn't USB. So I located the latest .zip file and installed it, almost. I got the expected, for me, "that didn't work" message. So I went back to Peter's first version and it worked. So then to a more recent version and it worked but the latest version still refuses to cooperate. Is it possible that Peter has made some stupid mistake or could it be that I am making some minor error?
Please help !!!!!!!!
Peter (the stupid one)
Michal Senior Member
Joined: 02/02/2022 Location: PolandPosts: 123
Posted: 08:55am 04 Mar 2022
Hi,
That is why I suggested adding(include) SQLite to MMBASIC with which you can efficiently load (and save) DATA.
Michal Edited 2022-03-04 18:56 by Michal
Mixtel90
Guru
Joined: 05/10/2019 Location: United KingdomPosts: 6834
Posted: 09:37am 04 Mar 2022
Ah, but you can't load data to a device with no storage medium, say a Micromite or a PicoMite (when used without a SDcard). The data has to be inline within the program - like a CSUB or an embedded font - or use DATA statements. SQLite would be of no use unless you used it on embedded data, neither would include. VAR SAVE / VAR RESTORE are ok for keeping data between runs, but store data on the local device, not as part of the program.
As Tom has pointed out previously, the CSUB mechanism works. The CSUB is part of the program and it can be PEEKed and POKEd like using a pre-loaded array. It means that CSUBs have to be supported on that platform though.
@PeterB Can you show us a bit of test code to illustrate the problem? . Edited 2022-03-04 19:41 by Mixtel90
thwill
Guru
Joined: 16/09/2019 Location: United KingdomPosts: 4048
Posted: 09:49am 04 Mar 2022
Fat fingers accidentally started a reply, but I've decided I'm waiting to hear from Peter now. I've got ideas about embedded BASE2, BASE16, BASE64 and TEXT resources in .bas files and might include some of them as extensions in MMB4L, but my main concern is what might be implemented as "standard" MMBasic in the recent generation of devices (CMM2, PicoMite, MMB4W, MMB4L).
Best wishes,
Tom Edited 2022-03-04 20:03 by thwill
PeterB Guru
Joined: 05/02/2015 Location: AustraliaPosts: 651
Posted: 10:00am 04 Mar 2022
Take two.
I click on MMBasic.zip then UNZIP and then nothing of any interest. But it worked for earlier versions. WHY ME?
Peter
Mixtel90
Guru
Joined: 05/10/2019 Location: United KingdomPosts: 6834
Posted: 10:16am 04 Mar 2022
Right click on MMBasic.zip and use Properties to find the file size. If it's zero you have a failed download. It happens sometimes - not just to you. :) Delete it and try again.
If it unzips ok then it should be runnable....
PeterB Guru
Joined: 05/02/2015 Location: AustraliaPosts: 651
Posted: 10:41am 04 Mar 2022
Mick
The zipped file is 798KB - 381KB It gets as far as a small black screen and the message "MMBasic.exe has stopped working and Microsoft is going to solve the worlds problems.
Peter
Mixtel90
Guru
Joined: 05/10/2019 Location: United KingdomPosts: 6834
Posted: 11:05am 04 Mar 2022
Ah.... It appears that you have a problem that Clippy or even Doctor Watson can't figure out. I'm not sure I can help further either. Try another download anyway.
JohnS Guru
Joined: 18/11/2011 Location: United KingdomPosts: 3820
Posted: 11:22am 04 Mar 2022
Not much use as it needs lots of memory etc, so only for quite big platforms.
Some tweaks to DATA etc would be a fix for everywhere.
John
Michal Senior Member
Joined: 02/02/2022 Location: PolandPosts: 123
Posted: 11:30am 04 Mar 2022
Since you can load from *.inc and other files, you can also load from *.db3 files. You can load a comma-separated field with a string of words, and then break it apart like normal DATE.
In Pascal it looks like this:
I.AsString:='5'; ZQuery1.SQL.Text:='SELECT companyname FROM suppliers where supplierid='+I; ZQuery1.Open; Data1.AsString:=ZQuery1.Fields[0].Value;
in Data1- Ala,Ola,Ula,Ewa
by changing supplierid = 2 or 5 or 200 you decide which date you get.
Michal Edited 2022-03-04 21:38 by Michal
thwill
Guru
Joined: 16/09/2019 Location: United KingdomPosts: 4048
Posted: 11:41am 04 Mar 2022
Except Micromite and PicoMite don't have .inc files, and as @Mixtel90 pointed out may or may not have an SD card or other storage media allowing them to load ANY files.
I don't think anybody is arguing that SQLite support would be a bad thing (though I certainly could if pressed) just that it isn't a suitable solution to the problem at hand.
The problem at hand is how we can encode modest amounts of data within a .bas file and encapsulate that data in such a fashion that access to multiple data sections can be intermingled without tramping on each other and without requiring too many contortions by the programmer.
EDIT: Peter provided an approach that would allow access to 2 data sections to be intermingled (using READ SAVE and READ RESTORE), whereas I am an advocate of an approach allowing access to N data sections, and if you balk at my original PEEK/POKE syntax then it could be "READ DATAPOS data_pos%" and "RESTORE DATAPOS data_pos%".
Best wishes,
Tom Edited 2022-03-04 21:53 by thwill
al18 Senior Member
Joined: 06/07/2019 Location: United StatesPosts: 205
Posted: 11:56am 04 Mar 2022
It seems Data Restore would be useful if you have a game were redefined characters are used to create a playfield. Since most Fonts have only 96 characters at a time, and you typically only wanted to define a few characters per level, the Data Restore would be useful.
thwill
Guru
Joined: 16/09/2019 Location: United KingdomPosts: 4048
Posted: 12:10pm 04 Mar 2022
Hi @al18,
MMBasic has a RESTORE command which is more powerful than that in most street BASICs and can do what I believe you are talking about.
The problem being wrangled with is that like most (all?) BASICs there is a single global "pointer" to DATA that the READ command reads from and there is no mechanism for the programmer to read that pointer and then having read it use that value to return the pointer to that state. Specifically the use of a single global pointer has limitations when for example you are partially through reading some DATA and then want to call a subroutine that needs to read some different DATA (or the same DATA from a different point).
This is crazy code, but does illustrate the point that whenever exiting mad() we want the data pointer to be the same as it was when we entered mad():
Option Base 0 Option Default None Option Explicit On
Restore my_data mad(5) End
Sub mad(depth%) If depth% = 0 Then Exit Sub Local data_pos% = Peek(DataPos) ' Cache the data pointer. Local s$ Restore my_data my_label: ' There seems to be an issue with using recursion and DO/FOR loops ? ' Might be MMB4L specific. Read s$ If s$ = "" Then Print Poke DataPos data_pos% ' Restore the data pointer. Exit Sub EndIf Print Space$(5 - depth%) Str$(depth%) s$ " "; If depth% > 1 Then Print mad(depth% - 1) Goto my_label End Sub
my_data: Data "A", "B", "C", "D", "E", ""
Note that PEEK(DATAPOS) and POKE DATAPOS don't currently exist, they are my proposed solution to the problem.