comp.lang.ada
 help / color / mirror / Atom feed
* Re: C struct import
       [not found] <vhi3drkqqo7.fsf@grotte.ifi.uio.no>
  2000-01-27  0:00 ` C struct import David C. Hoos, Sr.
@ 2000-01-27  0:00 ` tmoran
  1 sibling, 0 replies; 3+ messages in thread
From: tmoran @ 2000-01-27  0:00 UTC (permalink / raw)


Assuming the unused things are really unused, the 1 bit flags
are Booleans, and Uint32 and SDL_PixelFormat types are elsewhere
defined, you might say:

type Access_SDL_Pixel_Format is access all SDL_PixelFormat;

type SDL_VideoInfo is record
  hw_available,         -- Can you create hardware surfaces?
  wm_available,         -- Can you talk to a window manager?
  blit_hw,              -- Accelerated blits HW --> HW
  blit_hw_CC,           -- Accelerated blits with Colorkey
  blit_hw_A,            -- Accelerated blits with Alpha
  blit_sw,              -- Accelerated blits SW --> HW
  blit_sw_CC,           -- Accelerated blits with Colorkey
  blit_sw_A,            -- Accelerated blits with Alpha
  blit_fill : Boolean;  -- Accelerated color fill
  video_mem : Uint32;   -- The total amount of video memory (in K)
  vfmt : Access_SDL_Pixel_Format; -- Value: The format of the video surface
end record;

If you not only need a record with these things, but you need the bits
to occur at specific places in the bytes (if you're interfacing to
hardware or an OS, say), then you'll have to find out just where
your C compiler puts things (since that's implementation dependent)
and then include a record representation clause to ensure the Ada
compiler puts things in the same places.  My Microsoft VC++ says
that it allocates bit fields from the right.  My Windows targetted
Ada compilers label bit locations Low_Order_First.  So to make sure
the Ada structure, using such an Ada compiler, matches the C ordering,
using the Microsoft compiler, you would include:

for SDL_VideoInfo use record
  hw_available at 0 range 0 .. 0;
  wm_available at 0 range 1 .. 1;
  blit_hw      at 1 range 1 .. 1;
  blit_hw_CC   at 1 range 2 .. 2;
  blit_hw_A    at 1 range 3 .. 3;
  blit_sw      at 1 range 4 .. 4;
  blit_sw_CC   at 1 range 5 .. 5;
  blit_sw_A    at 1 range 6 .. 6;
  blit_fill    at 1 range 7 .. 7;
  video_mem    at 4 range 0 .. 31;
  vfmt         at 8 range 0 .. 31; -- Assuming Access types are 32 bits.
end record;




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C struct import
       [not found] <vhi3drkqqo7.fsf@grotte.ifi.uio.no>
@ 2000-01-27  0:00 ` David C. Hoos, Sr.
       [not found]   ` <vhi1z73r5cc.fsf@grotte.ifi.uio.no>
  2000-01-27  0:00 ` tmoran
  1 sibling, 1 reply; 3+ messages in thread
From: David C. Hoos, Sr. @ 2000-01-27  0:00 UTC (permalink / raw)


What is the declaration of SDL_PixelFormat?
Also, anything else in that definition that is not a standard
C type is needed.

Jan Kroken <jankr@nntp.ifi.uio.no> wrote in message
news:vhi3drkqqo7.fsf@grotte.ifi.uio.no...
>
> I have the following C struct. How can I use this from Ada?
>
> typedef struct {
>         Uint32 hw_available :1; /* Flag: Can you create hardware surfaces?
*/
>         Uint32 wm_available :1; /* Flag: Can you talk to a window manager?
*/
>         Uint32 UnusedBits1  :6;
>         Uint32 UnusedBits2  :1;
>         Uint32 blit_hw      :1; /* Flag: Accelerated blits HW --> HW */
>         Uint32 blit_hw_CC   :1; /* Flag: Accelerated blits with Colorkey
*/
>         Uint32 blit_hw_A    :1; /* Flag: Accelerated blits with Alpha */
>         Uint32 blit_sw      :1; /* Flag: Accelerated blits SW --> HW */
>         Uint32 blit_sw_CC   :1; /* Flag: Accelerated blits with Colorkey
*/
>         Uint32 blit_sw_A    :1; /* Flag: Accelerated blits with Alpha */
>         Uint32 blit_fill    :1; /* Flag: Accelerated color fill */
>         Uint32 UnusedBits3  :16;
>         Uint32 video_mem;       /* The total amount of video memory (in K)
*/
>         SDL_PixelFormat *vfmt;  /* Value: The format of the video surface
*/
> } SDL_VideoInfo;
>
>
> --
>                                                      -jk





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C struct import
       [not found]   ` <vhi1z73r5cc.fsf@grotte.ifi.uio.no>
@ 2000-01-30  0:00     ` Mario Klebsch
  0 siblings, 0 replies; 3+ messages in thread
From: Mario Klebsch @ 2000-01-30  0:00 UTC (permalink / raw)


Jan Kroken <jankr@nntp.ifi.uio.no> writes:

>"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:

>> What is the declaration of SDL_PixelFormat?
> I
>It's a struct (which I have imported successfully). 

>> Also, anything else in that definition that is not a standard
>> C type is needed.

>Uint32 is (surprise) a 32 bit unsigned integer type. Corresponds
>to unsigned long on x86 systems, which is the only type of systems
>currently supported by SDL anyway...

David probably was talking about the bitfields. Their implementation
is implementation defined.

73, Mario
-- 
Mario Klebsch						mario@klebsch.de




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-01-30  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <vhi3drkqqo7.fsf@grotte.ifi.uio.no>
2000-01-27  0:00 ` C struct import David C. Hoos, Sr.
     [not found]   ` <vhi1z73r5cc.fsf@grotte.ifi.uio.no>
2000-01-30  0:00     ` Mario Klebsch
2000-01-27  0:00 ` tmoran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox