Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Axenation

MSVC inline assembly and structs problem

This topic is 5231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im fairly new to assembly and im having trouble accessing some data from an SDL_Surface struct (it''s definition is below my function). i''ve tried doing a couple of different things like MOV EDX, surface IMUL someReg, [EDX+16] // surface->pitch ??? this is the code im writing :
static void putpixel24(SDL_Surface *surface, int x, int y, uint32 color)
{
    //

    //  How do i access surface->pitch in assembly?

    //

    uint32 pitch = surface->pitch;

    //  EDX = SDL_Surface *surface

    __asm mov   edx, surface

    //  move address of surface->pixels into EBX

    __asm mov   ebx, [edx+20]

    //  EAX = y * surface->pitch

    __asm mov   eax, y
    __asm imul  eax, pitch         //<---------- ?

    __asm add   ebx, eax

    //  x * 3 (using adds instead of imuls)

    __asm add   ebx, x 
    __asm add   ebx, x
    __asm add   ebx, x

    //  [ebx] is now the address of the pixel we wish to change

    
    __asm mov   eax, color
    __asm mov   [ebx], al
    __asm shr   eax, 8
    __asm mov   [ebx+1], ax
}
this is the definition of an SDL_Surface:
typedef struct SDL_Surface {
	Uint32 flags;				/* Read-only */
	SDL_PixelFormat *format;		/* Read-only */
	int w, h;				/* Read-only */
	Uint16 pitch;				/* Read-only */
	void *pixels;				/* Read-write */
	int offset;				/* Private */

	/* Hardware-specific surface info */
	struct private_hwdata *hwdata;

	/* clipping information */
	SDL_Rect clip_rect;			/* Read-only */
	Uint32 unused1;				/* for binary compatibility */

	/* Allow recursive locks */
	Uint32 locked;				/* Private */

	/* info for fast blit mapping to other surfaces */
	struct SDL_BlitMap *map;		/* Private */

	/* format version, bumped at every change to invalidate blit maps */
	unsigned int format_version;		/* Private */

	/* Reference count -- used when freeing surface */
	int refcount;				/* Read-mostly */
} SDL_Surface;
PS...i know this function would probably be faster written in C++, im just trying to learn new things.

Share this post


Link to post
Share on other sites
Advertisement
figured it out...i needed to type "word ptr" like this.


mov esi, surface
xor edx, edx
mov dx, word ptr [esi+10h] //surface->pitch

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!