Results 1 to 6 of 6

Thread: A "monster" c struct to convert

  1. #1

    A "monster" c struct to convert

    Ok, so... As usual, every new libnds release I get some problems converting it to pascal. This time a sprite related struct is changed and, when I saw the c source, my face looked like this one: :shock:
    Ladies and Gentlemen, the scary "monster":
    Code:
    typedef union {
    	struct {
    		struct {
    			u16 posY: 8;
    			union {
    				struct {
    					u8: 1;
    					bool isHidden: 1;
    					u8: 6;
    				};
    				struct {
    					bool isRotoscale: 1;
    					bool rsDouble: 1;
    					tObjMode objMode: 2;
    					bool isMosaic: 1;
    					tObjColMode colMode: 1;
    					tObjShape objShape: 2;
    				};
    			};
    		};
     
    		union {
    			struct {
    				u16 posX: 9;
    				u8: 7;
    			};
    			struct {
    				u8: 8;
    				union {
    					struct {
    						u8: 4;
    						bool hFlip: 1;
    						bool vFlip: 1;
    						u8: 2;
    					};
    					struct {
    						u8: 1;
    						u8 rsMatrixIdx: 5; 
    						tObjSize objSize: 2;
    					};
    				};
    			};
    		};
     
    		struct {
    			u16 tileIdx: 10;
    			tObjPriority objPriority: 2;
    			u8 objPal: 4;
    		};
    
    		u16 attribute3;
    	};
     
    	struct {
    		uint16 attribute[3];
    		uint16 filler;
    	};
     
    } SpriteEntry, * pSpriteEntry;
    The main thing that drives me nuts is the fact that neither structs nor unions have a name, as some bit fields too. I could try to break this big nested struct in something smaller (and more readable), but I don't know how this change will be internally "digested" by the library.
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  2. #2

    A "monster" c struct to convert

    they are anonymous unions, but no idea how to convert them to pascal :?
    From brazil (:

    Pascal pownz!

  3. #3

    A "monster" c struct to convert

    dump the data to a file, look with a hex editor and figure out what is what, then write a pascal one.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  4. #4

    A "monster" c struct to convert

    Indeed, it's a very difficult structure to convert, yet I tried to do it. I'm very unsure about the speed and correctness of this code, but I thought you should take a look.
    [pascal]
    type
    //: Only for tests!
    U16 = Integer;
    U8 = Integer;
    tObjMode = Boolean;
    tObjColMode = Boolean;
    tObjColShape = Double;
    tObjShape = Boolean;
    tObjSize = Single;
    tObjPriority = Byte;
    uint16 = LongInt;

    { .: StructA :. }
    StructA = record
    case Integer of
    0: (A: u8);
    1: (isHidden: Boolean);
    2: (B: u8);
    end;

    { .: StructB :. }
    StructB = record
    case Integer of
    0: (isRotoscale: Boolean);
    1: (rsDouble: Boolean);
    2: (objMode: tObjMode);
    3: (isMosaic: Boolean);
    4: (colMode: tObjColMode);
    5: (objShape: tObjColShape);
    end;

    { .: StructC :. }
    StructC = record
    posX: u16;
    A: u8;
    end;

    { .: StructD :. }
    StructD = record
    A: u8;
    hFlip: Boolean;
    vFlip: Boolean;
    B: u8;
    end;

    { .: StructE :. }
    StructE = record
    A: u8;
    rsMatrixIdx: u8;
    objSize: tObjSize;
    end;

    { .: StructF :. }
    StructF = record
    tileIdx: u16;
    objPriority: tObjPriority;
    objPal: u8;
    end;

    { .: StructG :. }
    StructG = record
    attribute: array[0..2] of uint16;
    filler: uint16;
    end;

    { .: UnionA :. }
    UnionA = record
    posY: u16;
    case Integer of
    0: (A: StructA);
    1: (B: StructB);
    end;

    { .: UnionB :. }
    UnionB = record
    A: u8;
    case Integer of
    0: (B: StructD);
    1: (C: StructE);
    end;

    { .: UnionC :. }
    UnionC = record
    A: StructC;
    B: UnionB;
    end;

    { .: SpriteEntry :. }
    pSpriteEntry = ^SpriteEntry;
    SpriteEntry = record
    attribute3: u16;
    U1: UnionA;
    U2: UnionB;
    A: StructF;
    B: StructG;
    end;
    [/pascal]

    Hope that helps.

  5. #5

    A "monster" c struct to convert

    You can' convert it without placing labels on the unions. Using bitpacking you can get a quite good match
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6

    A "monster" c struct to convert

    Post the result, i will like see how the struct is on pascal
    From brazil (:

    Pascal pownz!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •