SPIN/PASM Objects and Propeller GCC C code?
6581
Posts: 132
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?
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
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 If you change that to: 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.
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
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