Shop OBEX P1 Docs P2 Docs Learn Events
file "filename" — Parallax Forums

file "filename"

BasilBasil Posts: 380
edited 2008-09-11 20:41 in Propeller 1
Hi All,

I seem to be bombarding this board with questions recently...

Anywho, In my application I used to have a bunch of previously recorded samples stored in the data section in the following format

byte 202,201,202,202,202,202,202,202 etc etc

When compiled, the program had 2972 longs free.

When I take all that data out ond put it into a txt file, then use the 'file' instruction in the dat section, I only get 618longs free when complied.

Am I formating my txt file incorrectly? I have removed all the spaces, new lines and comma's so its just a huge line of numbers.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

My our page

Comments

  • hippyhippy Posts: 1,981
    edited 2008-09-11 04:10
    If you're storing the data in the file as text then that's where your bloat and reduction of free RAM is coming from.

    The compiler converts "byte 202" into just one byte. In text that's three bytes "2", "0" and "2". You'll need to find a means to convert your text into a set of bytes, one byte per number.
  • BasilBasil Posts: 380
    edited 2008-09-11 04:13
    Oooo nasty.

    What if I were to store it as binary? Or would that be a string of binary? Ie "1""0""0""1""1" etc?

    How do I store it as hex or binary directly in a file?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-11 04:22
    It's not easy. You have to find a program for your PC that will let you edit the file as individual bytes, as numbers from 0-255.

    You can also write your own program that will read a sequence of numbers ranging from 0 to 255 and write each number out as a byte
    to a file.

    The easiest thing to do is to let the Propeller Tool do it and just use the BYTE statement the way you started out.
  • BasilBasil Posts: 380
    edited 2008-09-11 04:24
    Ok lol, thats alot of scrolling.

    Is there I way I can do something like

    In the main program object section...

    OBJ
    Data : "Data.spin"

    and in Data.spin, only have:

    DAT

    byte 123,234,23,45,56,45 etc

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • jazzedjazzed Posts: 11,803
    edited 2008-09-11 04:40
    Maybe you can use the old DOS debug command from the command line window? If you need it bad enough, I could quickly create a DOS program for you to display ascii-hex or whateverfrom a binary file; You must be very clear about your input/output needs though. (sorry I deleted the other post as I thought it might have been irrelevant).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • AribaAriba Posts: 2,687
    edited 2008-09-11 09:30
    Basil

    You can use PropTool to generate a Binary from your text-datas! Write a spin source like this:
    PUB dummy
    DAT
      byte 201,202,202,203
      'and so on
    
    


    You can compile such an "object" with F8 and then save as binary. You get the data as a binary with a little overhead at begin.
    Now you can include this binary with the FILE command in an other object. Your data start at the 24th byte in the produced binary, so you have to take that into account.
    PUB Main  | i,d
      repeat i from 0 to 9    'read first 10 bytes of table
        d := table[noparse][[/noparse]i+24]
    
    DAT
    table   file "yourbinary.binary"
    
    



    Andy
  • hippyhippy Posts: 1,981
    edited 2008-09-11 13:49
    Basil said...
    Ok lol, thats alot of scrolling.

    Is there I way I can do something like

    In the main program object section...

    OBJ
    Data : "Data.spin"

    and in Data.spin, only have:

    DAT

    byte 123,234,23,45,56,45 etc

    Yes, but you'll need a "PUB" at the top to get it to compile and you'll need a PUB anyway so you can return the address of where the data starts to your higher-up program ...

    PUB GetAddressOfData
      return @MyData
    DAT
    MyData byte 202,201,203 ...
    
    
    



    To access the data from the higher program ( untested ) ...

    PUB ShowFirstTenItemsOfData | ptr
      ptr := dataObject.GetAddressOfData
      repeat 10
        tv.Dec( byte[noparse][[/noparse] ptr ] )
        tv.Out( $0D )
        ptr++
    
    
    
  • BasilBasil Posts: 380
    edited 2008-09-11 20:41
    Hmmmm. Thanks for those suggestions. That would probably do for the time being. This is just a temporary fix to test my flight algorithms. Once its all tested I wont be using any data files at all [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
Sign In or Register to comment.