from spin to C , how to translate this address ?

I'm trying to convert the code for the OLED 128 from spin to C.

the function Fxn takes only 3 parameters:
- nb of arg
- command
- first adress of argument

With that it can be called with higher function with several parameter. see code below with function Drawcircle

How can it be translated correctly to C ?
this line cause me some problem :

pri Fxn(argCount,Command,ArgAddress)|index
   index := 0
   repeat argCount
        SendData(long[ArgAddress][index++])                  ''Main Function to communicate with various methods 
    result := ser.CharIn                                    ''associated with the uOLED display

pub DrawCircle(X,Y,R,Co)                             
draws a circle with center at X,Y with radius R using the specified color
_Ack := Fxn(4,Cmd_gfx_Circle,@X)

pri SendData(Data)                                      ''Send Word variable to the uOLED display 


  • I used the Spin Converter
    which used the 'spin2cpp' executable to produce the following output from your code fragment:
    static int32_t Fxn(int32_t argCount, int32_t Command, int32_t ArgAddress)
      int32_t	index, _idx__0001, _limit__0002;
      int32_t result = 0;
      index = 0;
      for(( (_idx__0001 = 0), (_limit__0002 = argCount) ); _idx__0001 < _limit__0002; _idx__0001++)
        SendData(((int32_t *)ArgAddress)[(index++)]); // Main Function to communicate with various methods                                                                        
        result = index;                               // associated with the uOLED display
      return result;
    void SendData(int32_t Data) // Send Word variable to the uOLED display

    To simplify the above output I removed references to the 'ser' object and the content of the SendData routine in the Spin code before conversion, so you can see more clearly the answer to your specific question regarding the 'SendData' statement.

    The Spin Converter is a great tool to convert Spin code into either PASM or C, even if you just want to see how the resulting code looks for your own understanding/knowledge. Give the converter a try...
  • laurent974laurent974 Posts: 76
    edited 2017-02-18 - 19:01:20
    excellent . that part was what i was looking for:
    SendData(((int32_t *)ArgAddress)[(index++)]);

    i gave a try of this tool, and it's really impressive. there's still left a lot of rework after the first pass. But it helps a lot for pointer conversion.

    [EDIT]: The accurate translation in C is with VA_Arg.
    char Fxn(int argCount, int Command,...) {
      int index;
      va_list ap;
      va_start(ap, Command);
      for (index = 0;index < argCount; index++) {
      return fdserial_rxChar(oled);                       // associated with the uOLED display
Sign In or Register to comment.