source/graphics.c
struct Sprite* sprite_init(int x, int y, enum SpriteSize size,
        int horizontal_flip, int vertical_flip, int tile_index, int priority) {
    /* grab the next index */
    int index = next_sprite_index++;

    /* setup the bits used for each shape/size possible */
    int size_bits, shape_bits;
    switch (size) {
        case SIZE_8_8:   size_bits = 0; shape_bits = 0; break;
        case SIZE_16_16: size_bits = 1; shape_bits = 0; break;
        case SIZE_32_32: size_bits = 2; shape_bits = 0; break;
        case SIZE_64_64: size_bits = 3; shape_bits = 0; break;
        case SIZE_16_8:  size_bits = 0; shape_bits = 1; break;
        case SIZE_32_8:  size_bits = 1; shape_bits = 1; break;
        case SIZE_32_16: size_bits = 2; shape_bits = 1; break;
        case SIZE_64_32: size_bits = 3; shape_bits = 1; break;
        case SIZE_8_16:  size_bits = 0; shape_bits = 2; break;
        case SIZE_8_32:  size_bits = 1; shape_bits = 2; break;
        case SIZE_16_32: size_bits = 2; shape_bits = 2; break;
        case SIZE_32_64: size_bits = 3; shape_bits = 2; break;
    }

    int h = horizontal_flip ? 1 : 0;
    int v = vertical_flip ? 1 : 0;

    /* set up the first attribute */ 
    sprites[index].attribute0 = y |             /* y coordinate */
                            (0 << 8) |          /* rendering mode */
                            (0 << 10) |         /* gfx mode */
                            (0 << 12) |         /* mosaic */
                            (1 << 13) |         /* color mode, 0:16, 1:256 */
                            (shape_bits << 14); /* shape */
                                                                                
    /* set up the second attribute */ 
    sprites[index].attribute1 = x |             /* x coordinate */
                            (0 << 9) |          /* affine flag */
                            (h << 12) |         /* horizontal flip flag */
                            (v << 13) |         /* vertical flip flag */
                            (size_bits << 14);  /* size */
                                                                                
    /* setup the second attribute */ 
    sprites[index].attribute2 = tile_index |   // tile index */
                            (priority << 10) | // priority */
                            (0 << 12);         // palette bank (only 16 color)*/

    /* return pointer to this sprite */
    return &sprites[index];
}
/* function to initialize a sprite with its properties, and return a pointer */
function to initialize a sprite with its properties, and return a pointer
function to initialize a sprite with its properties and return a pointer
struct Sprite* sprite_init(int x, int y, enum SpriteSize size,
        int horizontal_flip, int vertical_flip, int tile_index, int priority) {
    int index = next_sprite_index++;
    int size_bits, shape_bits;
    switch (size) {
        case SIZE_8_8:   size_bits = 0; shape_bits = 0; break;
        case SIZE_16_16: size_bits = 1; shape_bits = 0; break;
        case SIZE_32_32: size_bits = 2; shape_bits = 0; break;
        case SIZE_64_64: size_bits = 3; shape_bits = 0; break;
        case SIZE_16_8:  size_bits = 0; shape_bits = 1; break;
        case SIZE_32_8:  size_bits = 1; shape_bits = 1; break;
        case SIZE_32_16: size_bits = 2; shape_bits = 1; break;
        case SIZE_64_32: size_bits = 3; shape_bits = 1; break;
        case SIZE_8_16:  size_bits = 0; shape_bits = 2; break;
        case SIZE_8_32:  size_bits = 1; shape_bits = 2; break;
        case SIZE_16_32: size_bits = 2; shape_bits = 2; break;
        case SIZE_32_64: size_bits = 3; shape_bits = 2; break;
    }
    int h = horizontal_flip ? 1 : 0;
    int v = vertical_flip ? 1 : 0;
    sprites[index].attribute0 = y |             
                            (0 << 8) |          
                            (0 << 10) |         
                            (0 << 12) |         
                            (1 << 13) |         
                            (shape_bits << 14); 
    sprites[index].attribute1 = x |             
                            (0 << 9) |          
                            (h << 12) |         
                            (v << 13) |         
                            (size_bits << 14);  
    sprites[index].attribute2 = tile_index |   
                            (priority << 10) | 
                            (0 << 12);         
    return &sprites[index];
}
struct Sprite * sprite_init ( int x , int y , enum SpriteSize size , int horizontal_flip , int vertical_flip , int tile_index , int priority ) { int index = next_sprite_index ++ ; int size_bits , shape_bits ; switch ( size ) { case SIZE_8_8 : size_bits = 0 ; shape_bits = 0 ; break ; case SIZE_16_16 : size_bits = 1 ; shape_bits = 0 ; break ; case SIZE_32_32 : size_bits = 2 ; shape_bits = 0 ; break ; case SIZE_64_64 : size_bits = 3 ; shape_bits = 0 ; break ; case SIZE_16_8 : size_bits = 0 ; shape_bits = 1 ; break ; case SIZE_32_8 : size_bits = 1 ; shape_bits = 1 ; break ; case SIZE_32_16 : size_bits = 2 ; shape_bits = 1 ; break ; case SIZE_64_32 : size_bits = 3 ; shape_bits = 1 ; break ; case SIZE_8_16 : size_bits = 0 ; shape_bits = 2 ; break ; case SIZE_8_32 : size_bits = 1 ; shape_bits = 2 ; break ; case SIZE_16_32 : size_bits = 2 ; shape_bits = 2 ; break ; case SIZE_32_64 : size_bits = 3 ; shape_bits = 2 ; break ; } int h = horizontal_flip ? 1 : 0 ; int v = vertical_flip ? 1 : 0 ; sprites [ index ] . attribute0 = y | ( 0 << 8 ) | ( 0 << 10 ) | ( 0 << 12 ) | ( 1 << 13 ) | ( shape_bits << 14 ) ; sprites [ index ] . attribute1 = x | ( 0 << 9 ) | ( h << 12 ) | ( v << 13 ) | ( size_bits << 14 ) ; sprites [ index ] . attribute2 = tile_index | ( priority << 10 ) | ( 0 << 12 ) ; return & sprites [ index ] ; }
function to initialize a sprite with its properties, and return a pointer
function to initialize a sprite with its properties and return a pointer
/* grab the next index */ /* setup the bits used for each shape/size possible */ /* set up the first attribute */ /* y coordinate */ /* rendering mode */ /* gfx mode */ /* mosaic */ /* color mode, 0:16, 1:256 */ /* shape */ /* set up the second attribute */ /* x coordinate */ /* affine flag */ /* horizontal flip flag */ /* vertical flip flag */ /* size */ /* setup the second attribute */ // tile index */ // priority */ // palette bank (only 16 color)*/ /* return pointer to this sprite */