| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Change DATA pointer READ in Basic
I want a value that I can skip by four or one (when x*4), so I can skip data lines.
Example
1000 DATA 1,2,3,4,5,6,...
1001 DATA ....
1002 ....
1004 DATA 6,5,4,3,2,1,...
...
1006 ....
...
1008 ....
(I have data lines in 3 by 3, but I separate them by line of fours, such that the beginning of each section is an even number).
So when I do a READ Q, I want to have changed the data-pointer to either 1000, 1004, 1008 or 1012, etc..
But the only way I found out to jump between these datas are by POKE 65,x and POKE 66,y, before READ Q. But those are not lines, those are addresses, and the addresses change alot because I have 27 values on each line (81 values in total for each section). POKING into 63 and 64 doesn't work here, it seems its read only and writing to these zp address does not work. Is there any way to bypass this or is there a formula to convert line number to read pointer address? Or is there another method to do this?
|
|
| |
TheRyk
Registered: Mar 2009 Posts: 2244 |
the idea seems quite painful
Might be $0F flag interferes. Adresses are definetely not ROM. Maybe $3f and $40 need to be manipulated too?
Did you try if Y=5:RESTORE:FORX=1TOY*4:READZ:NEXT:READA sets A to the desired value? Also not sure if I understood the structure of your DATA ^^ slightly confused by these 3s and 4s
otherwise just check out BASIC and KERNAL ROM listings, but I don't believe that you find any register for "line no. of currently read DATA" |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Thank for the reply TheRyk. The structure of my data is shown on screenshot: I have 3 lines of DATA, and each line consist of 27 values separated by commas.
In my program I want to only read 81 values from data-lines in total. But during the program I would like to read arbitrary data (not all the data, but different sections). I use the term sections for different data here. for example: instead of reading the first section: i.e. line 1000 to 1002 I would like to read 1004 to 1007 instead.
I tried using "Pointer to next DATA item for READ" ($41 and $42) but found it to be a pain, yes. Maybe I can figure a way around it by reading the first line and storing the pointer then do 16-bit arithmetic to change the pointer. Ill try that next. |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
this seemed to work:
I can multiply 180 with section-number;
i will go for this method and see with time if it fails or not. (it may corrupt if peek(65)<2), but so far so good. |
| |
Krill
Registered: Apr 2002 Posts: 2980 |
I sense an XY problem.
With the little means given by BASIC V2, what about reading all data into arrays first (so you have a random-access representation of it), then performing whatever number crunching you want on those arrays instead of the initial data lines? |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
why not just stuff those numbers into memory and then peek(whatever) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
... or store the info as data strings, one string per line, then use mid$ and val to extract the numbers you need, skipping lines should be trivial in that case. |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Thanks. Might try that if this fails. |
| |
Krill
Registered: Apr 2002 Posts: 2980 |
Yeah. Really, DATA lines are intended to be one-time sequentially imported into whatever variable types you deem sensible.
If you need delimiters, run lengths or other meta-data, you can encode them into your data values. And multi-dimensional arrays for storage exist, too. I wouldn't go for direct memory access via PEEK and POKE, though. |