Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2021-08-23 09:23:11

popcalent
Member
Registered: 2021-08-18
Posts: 12

Problems with passing a 16x16 sprite struct as a pointer (solved)

Hi,

I'm sure this has to do with my underdeveloped programming skills in C rather than GBDK, but this problem has driven me crazy since yesterday, and I'm unable to figure it out. I defined a struct type and declared a struct to store where the four 8x8 sprites of a 16x16 sprite are located, like so:

struct sprite16x16
        {
        UBYTE spriteid_0;
        UBYTE spriteid_1;
        UBYTE spriteid_2;
        UBYTE spriteid_3;
        };

struct sprite16x16 sprite2;

If I initialize each member of the struct directly (ie. sprite2.spriteid_0=2, etc.) it works without issue. However, I want to use one function to initialize every sprite16x16 object, so I pass the address of a given sprite and the values of each memeber like this: setup(&sprite2, 2, 3, 4, 5); and then inside the function I initialize each member like this: generic_sprite->spriteid_0=2, etc. But this doesn't work: the members of the struct are initialized with whatever...

I wrote to simple programs isolating the problem. The first one uses the direct method (sprite2.spriteid_0=2) and works, the second one uses the indirect method (sprite2->spriteid_0=2) and doesn't work. Both compile, but the second one shows garbage instead of the sprite. The two programs create an 8x8 sprite (sprite1), and a 16x16 sprite using the methods above.

Program 1: https://justpaste.it/9da2q
Program 2: https://justpaste.it/2yi8v

As I said, I'm sure this is something stupid related to the C language. Hopefully someone can help me out. Thanks!


Edit: Never mind. I was using an obsolete version of GBDK. With the latest version, the code does what I want it to do...

Last edited by popcalent (2021-08-23 12:57:24)

Offline

 

#2 2021-08-23 23:30:36

bbbbbr
Member
Registered: 2019-03-04
Posts: 126

Re: Problems with passing a 16x16 sprite struct as a pointer (solved)

You might also look into the GBDK-2020 metasprite features:
https://gbdk-2020.github.io/gbdk-2020/d … f9d1cf392b

Offline

 

#3 2021-08-24 11:32:03

popcalent
Member
Registered: 2021-08-18
Posts: 12

Re: Problems with passing a 16x16 sprite struct as a pointer (solved)

bbbbbr wrote:

You might also look into the GBDK-2020 metasprite features:
https://gbdk-2020.github.io/gbdk-2020/d … f9d1cf392b

Thanks! That IS useful.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson