Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:29 27 Nov 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 : MMBasic Restore

Author Message
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 03:32pm 03 Feb 2013
Copy link to clipboard 
Print this post

I keep harping back on a version of Microsoft 8K Bascic-in-ROM. Sorry if it is boring.

This version allowed the RESTORE command to set the pointer for DATA to dirrerent line numbers which obviated the need to count through unwanted DATA to get to the relevant bits. I found it quite useful and sped up DATA READ functions.

Any thoughts on this or would it take up more memory than the benefit justifies?
David M.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1425
Posted: 03:51pm 03 Feb 2013
Copy link to clipboard 
Print this post

Interesting. I have not used this in practice, but I looked it up and indeed there are some BASICs that let you restore to the line number of the data statement.

I suppose restore-to-label would be a way to implement this.

DATA ...
DATA ...
DATA ...
Fred:
DATA ...
DATA ...
DATA ...

RESTORE FredEdited by CircuitGizmos 2013-02-05
Micromites and Maximites! - Beginning Maximite
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 11:56pm 03 Feb 2013
Copy link to clipboard 
Print this post

Hi MOBI,

You could do something like this -


' Restore to index in data statement
'
' how about making a data index variable then
' step into the data and get an entry

function Read.Index(data_index)
restore
for x = 1 to data_index
read a
next x
Read.Index = a
end function

' Test

data 1,2,3,4,5,6,7,8,9,10
? Read.Index(4)


You could embed this in another loop if you want to get multiple elements.

Cheers, Doug.


... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 12:11am 04 Feb 2013
Copy link to clipboard 
Print this post

  CG said  I suppose restore-to-label would be a way to implement this.


That is what I imagined seeing as line numbers are on their antepenultimate breath.

  Doug said   Restore to index in data statement


That looks like it would do though. I was trying to get away from for-next loops and speed the process up using the underlying Basic command "restore" to go to the relevant Data statement.

When executing a READ, does the Basic have to start from the top of the programme and look for the first occurrence of DATA or is the RESTORE point set to the first DATA line? As it is an interpreter, I suspect the former is the case.
David M.
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 12:19am 04 Feb 2013
Copy link to clipboard 
Print this post

According to the doco, RESTORE Resets the line and position counters for DATA and READ statements to the top of the program file.

My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 12:28am 04 Feb 2013
Copy link to clipboard 
Print this post

  James said  According to the doco, RESTORE Resets the line and position counters for DATA and READ statements to the top of the program file.



Yes, I did read that, which makes a "restore to label" more sensible to just restore. There must be a DATA element pointer that points to the next DATA element once a READ has been implemented, so why not use the RESTORE command to find the first occurrence of DATA or DATA Label - hope I'm making sense.
David M.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 01:04am 04 Feb 2013
Copy link to clipboard 
Print this post

MOBI,

Used without line numbers, the RESTORE command just re-sets the data statement index pointers to the first element in the first data statement and then executes the line following the restore statement.


? "Start of program"
? "First data statement"
data 1,2,3

read a,b
? a,b

? "Second data statement"
data 11,12,13

read z,x,y

restore
? "Line following RESTORE"
read a,b,c,z,y,x

? a,b,c,z,y,x



Cheers, Doug.

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 01:06am 04 Feb 2013
Copy link to clipboard 
Print this post

One way to speed up the process, at the expense of memory, is to read the data once into an array. Then you get direct access to each element in the original DATA statement(s).

It is really a question of the priorities in your application. Whether speed is more important or memory.
Hugh
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1425
Posted: 05:35am 04 Feb 2013
Copy link to clipboard 
Print this post

  CircuitGizmos said  
I suppose restore-to-label would be a way to implement this.

DATA ...
DATA ...
DATA ...
Fred:
DATA ...
DATA ...
DATA ...

RESTORE Fred


The convenience of a restore-to-label over a restore function that does a loop read of x data elements to skip is that you don't need to adjust that every time the number of elements in your DATA statements changes.

In other words, if you add more data above Fred, you would have to adjust your program, perhaps in several places. This makes DATA in a program more like randomly accessed records than like serially accessed records.


Micromites and Maximites! - Beginning Maximite
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024