Shop OBEX P1 Docs P2 Docs Learn Events
DAT Records - Help Please — Parallax Forums

DAT Records - Help Please

DroneDrone Posts: 433
edited 2008-05-26 15:04 in Propeller 1
I'm struggling to do something seeming simple, combine bytes and longs in a single line (record if you will) of DAT data. Please see the simple code attached. I've read the manual pages on DAT, long, byte etc. tried mixed long byte etc. size and alignments in the DAT records - nope. Is there any way to do this? I really want to keep the long and bytes on the same line as that's how a complication spreadsheet generates the data. I feel like I'm missing something here - any suggestions appreciated.

David

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-26 14:46
    You can't combine bytes and longs on the same line. It wouldn't work in your case even if you could since you've got 6 bytes followed by a long and longs are aligned on a 4 byte boundary. You'd have 2 bytes of zero padding added by the compiler.

    The easiest thing to do is to use all longs and change the way the data is formatted. Instead of

    byte $30,$C2,$AD,$A9,$D3,$52,long 1800000

    you'd have

    long $A9_AD_C2_30,$00_00_52_D3,1800000

    Note that the order of the bytes is changed so the 1st 6 bytes still are in memory in the order you want (LSB first),
    then two bytes of padding, then the long value.
  • DroneDrone Posts: 433
    edited 2008-05-26 14:58
    Alas, I was hoping this wasn't the case Mike.

    In the end, using all longs as you suggest may use too much memory. I'll try formatting the data in such a way that the longs and bytes are in different lines or different tables.

    Best Regards,

    David
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-05-26 15:04
    Use just bytes. That way you can store your records anyway you want.
    Just define field offsets and fieldtypes (so you know what is a long).

    Storing a long into byte array at some index
    byte[noparse][[/noparse]index+0] := longvar.byte[noparse][[/noparse]0]
    byte[noparse][[/noparse]index+1] := longvar.byte[noparse][[/noparse]1]
    byte[noparse][[/noparse]index+2] := longvar.byte[noparse][[/noparse]2]
    byte[noparse][[/noparse]index+3] := longvar.byte[noparse][[/noparse]3]

    Retrieving a long
    longvar.byte[noparse][[/noparse]0] := byte[noparse][[/noparse]index+0]
    longvar.byte[noparse][[/noparse]1] := byte[noparse][[/noparse]index+1]
    longvar.byte[noparse][[/noparse]2] := byte[noparse][[/noparse]index+2]
    longvar.byte[noparse][[/noparse]3] := byte[noparse][[/noparse]index+3]

    You can define fieldsize and type in the offset
    offset = (index<<2) + type
    type 0 is byte
    type 1 is word
    type 2 is long

    regards peter
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-26 15:04
    Here's another suggestion using words:

    byte $30,$C2,$AD,$A9,$D3,$52,long 1800000

    could be

    word $C2_30,$A9_AD,$52_D3,1800000>>16,180000&$FFFF

    You could do the same thing with bytes, but the expressions involving the 32 bit value get more complex.

    byte $30,$C2,$AD,$A9,$D3,$52,1800000,1800000>>8,1800000>>16,1800000>>24

    Post Edited (Mike Green) : 5/26/2008 3:10:45 PM GMT
Sign In or Register to comment.