READ / WRITE to DATA - Need Example
John Kauffman
Posts: 653
1 - Can someone point me to a read/write example for data in RAM using SPIN?
I've searched Prop Help, manual PDF, fora and the Prop Help Tutorial. Maybe I am using the wrong search strings. I see LONG [BaseAddress] 〈[Offset]〉 in the Prop Chip Quick Reference pdf, but am not sure how to use it without an example.
2 - I'm putting the data into the RAM with the FILE command, but am having problems finding the address where FILE loads into RAM. I need that address for my first READ.
Much thanks.
I've searched Prop Help, manual PDF, fora and the Prop Help Tutorial. Maybe I am using the wrong search strings. I see LONG [BaseAddress] 〈[Offset]〉 in the Prop Chip Quick Reference pdf, but am not sure how to use it without an example.
2 - I'm putting the data into the RAM with the FILE command, but am having problems finding the address where FILE loads into RAM. I need that address for my first READ.
Much thanks.
Comments
DAT
sample LONG 0
then you'd refer to this as the variable sample just like any other variable. It would be a LONG. If you use WORD, then it would be like any other word variable. If you use BYTE, then it would be like any other byte variable. In both cases, you'd refer to it by name.
If you want a byte array, you could have
DAT
myArray BYTE "This is a string",0
You'd refer to bytes here with myArray[subscript] where subscript is any expression. Obviously, if you refer to a byte beyond what you've defined, you'd access something higher in memory, not what you might want.
You can use FILE to load data into a DAT section. You'd refer to the data by declaring a variable just before the FILE statement like
DAT
myFile BYTE
FILE filename
myFile is a zero length byte array that can be used to access the contents provided by the FILE statement by writing myFile[subscript]. If your file contains word or long data, you'd use WORD or LONG instead of BYTE and the subscripts would work as expected with the zeroth element being the first word or long.
I am still confused about what is the address of the first byte of data form the file after a command of:
FILE myDataFile
I see the following example in the manual. I assume that the Datafile bytes are stored higher than the string. But what is the start address of the first byte of DataFile's values? (Other than me just counting how many bytes the str variable uses).
DAT
Str byte "This is a data string.", 0
Data file "Datafile.dat"
PUB GetData | Index, Temp
Index := 0
repeat
Temp := byte[Data][Index++]
<do something with Temp>
while Temp > 0
Much thanks, Mike. You have been a consistent and wise help in these fora for years.