Shop OBEX P1 Docs P2 Docs Learn Events
SPIN/PASM Objects and Propeller GCC C code? — Parallax Forums

SPIN/PASM Objects and Propeller GCC C code?

65816581 Posts: 132
edited 2014-10-05 08:08 in Propeller 1
Hi,

I've been thinking about porting some stuff I've been working on to Propeller GCC.
One thing is my SIDcog based synthesizer. Now I'd like to ask what's the best effort embedding
the SIDcog in C? Can you give me an example please?

Comments

  • jazzedjazzed Posts: 11,803
    edited 2012-09-06 16:05
    It could propably be done. Maybe Eric's Spin2Cpp program can handle it.
  • 65816581 Posts: 132
    edited 2012-09-07 04:12
    Unfortunately it doesn't work out of the box with spin2cpp.
    Is there any starting point I can look at for porting SPIN to C/C++?
  • ersmithersmith Posts: 6,053
    edited 2012-09-07 04:53
    6581 wrote: »
    Unfortunately it doesn't work out of the box with spin2cpp.
    Is there any starting point I can look at for porting SPIN to C/C++?

    You've found a bug in spin2cpp -- it doesn't understand the first line of SIDCog.spin, namely
    CON PAL = 985248.0, NTSC = 1022727.0, MAXF = 1031000.0
    
    If you change that to:
    CON
      PAL = 985248.0
      NTSC = 1022727.0
      MAXF = 1031000.0
    
    then the code will at least compile with spin2cpp. I don't have speakers hooked up to my system so I'm not sure if it works or not, but it'll be a starting point.

    I'll fix that bug in the next release of spin2cpp. Thanks for finding it!

    Eric
  • 65816581 Posts: 132
    edited 2012-09-07 04:56
    ersmith wrote: »
    You've found a bug in spin2cpp -- it doesn't understand the first line of SIDCog.spin, namely
    CON PAL = 985248.0, NTSC = 1022727.0, MAXF = 1031000.0
    
    If you change that to:
    CON
      PAL = 985248.0
      NTSC = 1022727.0
      MAXF = 1031000.0
    
    then the code will at least compile with spin2cpp. I don't have speakers hooked up to my system so I'm not sure if it works or not, but it'll be a starting point.

    I'll fix that bug in the next release of spin2cpp. Thanks for finding it!

    Eric

    Yep, sorry, I forgot to say that I've fixed that previously in the SPIN code before compiling.
    Another error is in Line 75: sampleRate := clkfreq/trunc(C64_CLOCK_FREQ/32.0)

    Even after fixing that and initalizing the SIDcog as it was done in the ExamplePlayRoutine from C,
    it still doesn't output any audio. I think I'll hook up the PASM Debugger later and see what happens.
  • ersmithersmith Posts: 6,053
    edited 2012-09-07 09:18
    Ah, I see. It sounds like there are some more bugs in spin2cpp as well. I'll try to track those down.

    In general there are three approaches to porting a Spin+PASM driver:

    (1) use spin2cpp (if it works)

    (2) compile the PASM code from the Spin to a "binary blob" (using bstc -c, spin2cpp --dat, or some similar option to the Spin compiler of your choice) and load that into a Cog with cognew; then port the Spin interface to the PASM to C. This works well if the PASM code is pretty self contained and communicates data only through a block that is pointed to by PAR. It looks like SIDcog works this way, so it should be pretty straightforward. There's a simple example in the toggle/pasm_toggle demo.

    (3) port the PASM code to GAS syntax and add the resulting .s file to your Makefile or project. This is the only option if the Spin code needs access to global variables in the Spin code (other than things passed in via the initial PAR pointer). This generally isn't difficult -- PASM and GAS syntaxes are very similar. The main thing to watch out for is that all addresses in GAS are byte addresses, whereas PASM typically uses long addresses. That is, in GAS the registers in COG memory are addressed at 0, 4, 8, 12, etc. rather than 0, 1, 2, 3.... You can largely work around this by putting a ".cog_ram" directive at the top of your GAS file, which tells GAS to divide all symbols by 4 before using them. Also, GAS doesn't understand the ':' notation for temporary variables.

    There's a demo in toggle/gas_toggle.

    Eric
  • 65816581 Posts: 132
    edited 2012-09-07 15:18
    Hey,

    Thank you very much. I figured it out and now I've got SIDcog up and running.
    Be prepared for a new synthesizer release soon :)
  • threadzthreadz Posts: 56
    edited 2014-10-04 20:44
    Could you please the files on paste bin. I haven't had any luck getting the spin2cpp to produce working code.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2014-10-05 08:08
    6581 wrote: »
    Hey,

    Thank you very much. I figured it out and now I've got SIDcog up and running.
    Be prepared for a new synthesizer release soon :)

    Congrats!

    If want examples of C++ objects, there are lots in both PropWare and libpropeller. And if you have any questions about how to do something, feel free to ask! I'm all for more C++ objects :)
Sign In or Register to comment.