RE: C structs & bad aftershave...
- Posted by Steve <bleak_outlook at hotmail.com> Feb 25, 2006
- 460 views
Hi Bernie, Thanks for the response. I just wanted to see if this example is up the right tree or not: atom videoInfo videoInfo = SDL_GetVideoInfo() if and_bits(videoInfo, #8000) then -- hw available else -- hw unavailable end if Does that look correct? Thanks for the help! Steve Bernie Ryan wrote: > > > posted by: Bernie Ryan <xotron at bluefrog.com> > > > Steve wrote: > > > > > > Anyone have any idea about this? > > > > Do you need more information? Is it not possible? > > > > Hello? :) > > > > Steve > > > > > > Steve wrote: > > > > > > > > > Ok no Old Spice... I just wanted some attention! :) > > > > > > Background: Lest I get ahead of myself. > > > I am using M Akita's SDL for Eu wrapper. SDL is compiled into a DLL. > > > I want to access a member of a C structure. > > > > > > typedef struct{ > > > Uint32 hw_available:1; > > > Uint32 wm_available:1; > > > Uint32 blit_hw:1; > > > Uint32 blit_hw_CC:1; > > > Uint32 blit_hw_A:1; > > > Uint32 blit_sw:1; > > > Uint32 blit_sw_CC:1; > > > Uint32 blit_sw_A:1; > > > Uint32 blit_fill; > > > Uint32 video_mem; > > > SDL_PixelFormat *vfmt; > > > } SDL_VideoInfo; > > > > > > I can access its value by doing this: > > > > > > atom videoInfo > > > > > > videoInfo = SDL_GetVideoInfo() > > > > > > How do I, using Euphoria, best go about reading the above bit flags? > > > I have tried this: > > > > > > <EuCode) > > > sequence mbits > > > atom lflg > > > > > > mbits = int_to_bits(videoInfo) > > > > > > sprintf("flags: %d %d %d ...<snip>", {mbits[1], mbits[2], ...<snip>}) > > > > > <font color="#330033">> <EuCode></font> > > <font color="#330033">> </font> > > <font color="#330033">> Which gives me some really odd results. When I > > </font><font color="#FF00FF">peek </font><font color="#330033">36 bytes > > into this </font> > > <font color="#330033">> structure, </font><font color="#0000FF">and > > </font><font color="#330033">grab 4 bytes, I </font><font > > color="#0000FF">do </font><font color="#330033">get the correct amount > > of video memory </font> > > <font color="#330033">> </font> > > <font color="#330033">> </font><font color="#0000FF">for </font><font > > color="#330033">my graphics card. There ends my success though.</font> > > <font color="#330033">> </font> > > <font color="#330033">> Could someone explain </font><font > > color="#0000FF">to </font><font color="#330033">me how </font><font > > color="#0000FF">to </font><font color="#330033">access the bit flags of > > that struct?</font> > > <font color="#330033">> I seem </font><font color="#0000FF">to > > </font><font color="#330033">be doing this all wrong despite my best > > intentions. :)</font> > > <font color="#330033">> </font> > > <font color="#330033">> For more info, here is the SDL API page.</font> > > <font color="#330033">> > > http://www.libsdl.org/cgi/docwiki.cgi/SDL_20API</font> > > <font color="#330033">> </font> > > <font color="#330033">> Thanks again. As always, you guys rule.</font> > > <font color="#330033">> </font> > > <font color="#330033"></font> > > <font color="#330033"></font> > > Steve: > > The part of the structure Uint32 is a 32bit unsigned integer > > In order to look at bitfield hw_available for example, you have to AND > the binary number 1000 0000 0000 0000 or #8000 hex with > Uint32 portion of the structure > > Therefore: and_bits(Uint32,#8000) would give you hw_available > > -- binary 0010 0000 0000 0000 > and_bits(Uint32,#2000) would give you blit_hw > etc. > > Bernie > > My files in archive: > WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API > > Can be downloaded here: > > http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan >