Shop OBEX P1 Docs P2 Docs Learn Events
Spin2Cpp easiest way to embed files? — Parallax Forums

Spin2Cpp easiest way to embed files?

RaymanRayman Posts: 14,665
edited 2013-05-14 16:10 in Propeller 1
One thing that I often do in Spin is embed files into the code.
This is pretty easy with the "file" command.

Don't see anything like this in PropGcc and there's no resource editor like in Visual Studio.

One thing I think can be done easily though is to create a Spin file with the files embedded in it
and then do Spin2Cpp and then compile that file too.

Is this a good approach?
Is there a better way?

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-05-10 15:59
    Can't you just #include the file? Or I might be missing the point. What is your use case?
  • jazzedjazzed Posts: 11,803
    edited 2013-05-10 16:05
    You need a variable reference for the data as if it was a byte array?
  • RaymanRayman Posts: 14,665
    edited 2013-05-10 16:23
    "Resources" in Visual Studio are things like strings, bitmap images, icons, music data, etc. Basically any kind of data you want outside the code
  • jazzedjazzed Posts: 11,803
    edited 2013-05-10 16:45
    Rayman wrote: »
    "Resources" in Visual Studio are things like strings, bitmap images, icons, music data, etc. Basically any kind of data you want outside the code

    Ray I've never used "resources" in visual studio. Do you reference them as variables?
  • RaymanRayman Posts: 14,665
    edited 2013-05-10 16:51
    Here's a look at how you add a resource:

    resources.png
    297 x 361 - 19K
  • jazzedjazzed Posts: 11,803
    edited 2013-05-10 16:58
    It's a nice picture. How do you use those items in your program?
  • RaymanRayman Posts: 14,665
    edited 2013-05-10 17:07
    Anytime you create a dialog, it shows up as a resource.
    Maybe this all only applies to MFC programming, but that's all I do, usually...
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2013-05-10 17:34
    A resource ultimately is just a chunk of data with an address. The code would have a pointer variable that it would access the resource with.
  • dgatelydgately Posts: 1,630
    edited 2013-05-10 18:09
    Rayman wrote: »
    One thing I think can be done easily though is to create a Spin file with the files embedded in it
    and then do Spin2Cpp and then compile that file too.

    Note for Jazzed...

    Resources on Windows and Mac OS are data accessible by running apps and the OS. They get bundled into the application's "package". Newer versions of the OS's have made most resources less-visible outside of the IDE, but they do exist. Icon files, plists, config files, etc. can all be included in the app package. On Mac OS X, they are visible by Control-clicking on an App's icon and selecting "Show Package COntents". I'm not sure how you get to them on Windows.

    Even SimpleIDE has resources (at least on Mac OS X):

    Resources.png


    Ray, so your idea of pulling them into a Spin file should work. The files will be turned into 8-bit dat arrays (I think)...



    dgately
    567 x 130 - 21K
  • dgatelydgately Posts: 1,630
    edited 2013-05-10 18:26
    Had to test my theory...


    spin2cpp created the following example of including a file in a DAT section of a .spin file...

    DATFile.png



    Of course, a large file will create an expansive byte array, which you could move to a separate source file, right?


    dgately
    852 x 249 - 92K
  • RaymanRayman Posts: 14,665
    edited 2013-05-10 18:34
    yes, resources are often used/exploited to do things like change the text of a program to a different language...

    I was thinking of a spin file with an indexed list of embedded files.
    There would also be one function that would return the address to a file, given it's index.

    That's as much as I've thought about it...
  • jazzedjazzed Posts: 11,803
    edited 2013-05-10 18:43
    Hopefully no one will ask me to add a resource feature to SimpleIDE any time soon.
    Gotta finish up my current todo list, and get that other thing started....
  • Heater.Heater. Posts: 21,230
    edited 2013-05-11 03:22
    What you can do is convert your file into a linkable object with propeller-elf-objdump.
    That will wrap your file up in elf format and provide a label for your code to access it with.

    Here is a nice atricle explaining how to do it:
    http://balau82.wordpress.com/2012/02/19/linking-a-binary-blob-with-gcc/

    Not sure if you can use this technique with spin2cpp but it's worth knowing.
  • RaymanRayman Posts: 14,665
    edited 2013-05-14 16:10
    I just saw somebody doing this:
    const qc_table[17] = {
    # include "qc_table.dat"
    };
    

    to include an external data file. Data file was in text format though.
    Still, could do Spin2cpp on a binary file and then include it this way...
Sign In or Register to comment.