Shop OBEX P1 Docs P2 Docs Learn Events
Some questions about SPIN - C interaction — Parallax Forums

Some questions about SPIN - C interaction

Hi all,

there are still some issues left I did not understand with that topic:

1. Is the compiled SPIN code (via btsc -c ...), which will be add to the binary via objcopy, bytecode or native?
2. How exactly are parameters passed from C to the start routine in the SPIN code? (I did not get it from some examples...)

I just wanted to interface some VGA spin driver from C ...

Thank you in advance!

Patrick

Comments

  • ElectrodudeElectrodude Posts: 1,621
    edited 2016-06-06 18:09
    When you do "bstc -c", you aren't compiling the Spin parts of the .spin file, only the PASM parts in DAT sections. PASM, being assembly, gets compiled to native machine code. The Spin part, if you were to compile it (by not passing "-c" to bstc), would get compiled to bytecode that would get interpreted by the Spin interpreter in ROM.

    Passing the parameters is usually done through the second argument of coginit (or whatever they call it in C). It's also sometimes done by poking values into the PASM image. Read the Spin code to see how your object does it, and port that Spin code to C.
  • You can always convert the Spin (+ PASM) code to C using spin2cpp; then you can add the generated C (or C++) files to your project just like any other C code. There's even a GUI for spin2cpp now. See https://github.com/totalspectrum/spin2cpp/releases for the downloads.
  • Thanks for the helping answers!

    I think I now understood; currently I am using a header section with unfilled longs in PASM head and pass the content of a filled C structure via memcopy to this absolute address. This worked for me quite good. :D
Sign In or Register to comment.