Sprite rendering failure in GBA

0

I tried the code from TONC example for GBA development, specifically the obj_demo example. It loads the sprite located in the array at the metr.h, based on this image. These are codes in metr.h and metr.c:

metr.h

//======================================================================
//
//  metr, 64x64@4, 
//  + palette 32 entries, not compressed
//  + 64 tiles not compressed
//  Total size: 64 + 2048 = 2112
//
//  Time-stamp: 2005-12-24, 17:36:57
//  Exported by Cearn's Usenti v1.7.1
//  (comments, kudos, flames to "daytshen@hotmail.com")
//
//======================================================================

#ifndef __METR__
#define __METR__

#define metrPalLen 64
extern const unsigned int metrPal[16];

#define metrTilesLen 2048
extern const unsigned int metrTiles[512];

#endif // __METR__

//======================================================================
//
//  metr_box, 64x64@4, 
//  + 64 tiles not compressed
//  Total size: 2048 = 2048
//
//  Time-stamp: 2005-12-24, 17:37:08
//  Exported by Cearn's Usenti v1.7.1
//  (comments, kudos, flames to "daytshen@hotmail.com")
//
//======================================================================

#ifndef __METR_BOX__
#define __METR_BOX__

#define metr_boxTilesLen 2048
extern const unsigned int metr_boxTiles[512];

#endif // __METR_BOX__

metr.c

const unsigned int metrPal[16]=
{
    0x001F4210,0x008C0000,0x04B629DA,0x0000004D,0x031C0218,0x00005F5D,0x01800100,0x00000240,
    0x46314210,0x4E734A52,0x56B55294,0x5EF75AD6,0x67396318,0x6F7B6B5A,0x77BD739C,0x7FFF7BDE,
};

const unsigned int metrTiles[512]=
{
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,

    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0xCCC00000,0xDDCC0000,0xEEDDC000,0x00ECDC00,0x006EEDC0,0x66000EDC,
    0xCCCCC000,0xDDDDDCCC,0xEEEEEDDD,0x45600EEE,0x45600000,0x56000000,0x60000000,0x00000005,
    0x000CCCCC,0xCCCDDDDD,0xDDDEEEEE,0xEEE54000,0x00066400,0x00000644,0x00000065,0x00000006,
    0x00000000,0x00000000,0x000000CC,0x0000CCDD,0x000CDDEE,0x00CDCE00,0x0CDEE000,0xCDE00000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,

    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0xC0000000,0xDC000000,0xCDC00000,0xEDDC0000,0x0ECC0000,0x0ECDC000,0x60EDC000,0x00ECDC00,
    0x000000ED,0x0000000E,0x0000000E,0x00000000,0x00000000,0x00000000,0x66000006,0x00650560,
    0x00006006,0x00060660,0x00650056,0x05000006,0x50500006,0x00000056,0x00000060,0x00000060,
    0x00000060,0x00000600,0x00000600,0x00005600,0x00006000,0x00006000,0x00006500,0x00000600,
    0xDE000000,0xE0000000,0xE0000000,0x00000000,0x60000000,0x56000000,0x45600000,0x00060000,
    0x0000000C,0x000000CD,0x00000CDC,0x0000CDDE,0x0000CDE0,0x000CDCE5,0x000CDE54,0x00CDCE44,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,

    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x000EDC00,0x066EDC00,0x6500EDC0,0x0000EDC0,0x0000EDC0,0x0000EDC0,0x60000EDC,0x66000EDC,
    0x00066600,0x00000000,0x00000050,0x00000006,0x00000065,0x00000060,0x00000506,0x66600600,
    0x60000600,0x56606000,0x45560000,0x34456000,0x44445600,0x34345600,0x43445600,0x34445666,
    0x00006666,0x00665555,0x06554344,0x65444434,0x54444343,0x54343444,0x53434443,0x54443434,
    0x66066000,0x00600600,0x00000600,0x00006000,0x00006006,0x00006006,0x00060006,0x00006606,
    0x00CDE556,0x00CDE660,0x0CDE6000,0x0CDE0000,0x0CDE0000,0x0CDE0000,0xCDE00000,0xCDE00000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,

    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x06000EDC,0x06000EDC,0x06600EDC,0x06560EDC,0x65560EDC,0x65460EDC,0x64560EDC,0x66600EDC,
    0x55566600,0x44455600,0x34445600,0x43344560,0x33444460,0x44433460,0x34344560,0x34445600,
    0x43456655,0x44565553,0x55565444,0x66654344,0x64654434,0x64654343,0x66655444,0x46665544,
    0x66666544,0x55555665,0x43435556,0x43444455,0x34343445,0x43434344,0x44344445,0x44434556,
    0x00000666,0x00006655,0x06065534,0x60655444,0x00654343,0x00654434,0x00655443,0x06065554,
    0xCDE60000,0xCDE56000,0xCDE45600,0xCDE56060,0xCDE60006,0xCDE00000,0xCDE00000,0xCDE00000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,

    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x06000EDC,0x06000EDC,0x6000EDC0,0x5000ED00,0x00EEDC60,0xEEDDC600,0xDCC66000,0x66550880,
    0x43555600,0x55566650,0x66600060,0x0EEE0056,0xEDDDEE00,0xDC6CDDEE,0x66556CCD,0x58885556,
    0x64665554,0x06066655,0x00000666,0x00000000,0x0000000D,0x00000DDE,0xDDDDDEEC,0xEEEEDDC6,
    0x55555660,0x66666000,0x00000650,0x00000060,0xD0060606,0xEDD05005,0xCEEDDDDD,0x6CDDEEEE,
    0x60006655,0x60000066,0x66000000,0x0600EEE0,0x55EEDDDE,0xEEDD66CD,0xDCC65566,0x65558885,
    0xCDE00000,0xCDE00000,0x0CDE0006,0x00DE0065,0x06CDEE54,0x006CDDEE,0x00066CCD,0x08805566,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,

    0x00000000,0x80000000,0x80000000,0x88000000,0x98000000,0x98000000,0x98000000,0x80000000,
    0x55088988,0x80999A98,0x0888AAA9,0x000889A9,0x000088AA,0x0000089A,0x0000089A,0x00000089,
    0x00000885,0x80000000,0x98000000,0x99800000,0x89800000,0xA8000000,0x80000000,0x00000000,
    0x55CC6655,0x66555008,0x50000889,0x00000000,0x00000000,0x00000000,0x0000000A,0x00000000,
    0x5566CC55,0x80055566,0x98800005,0x00000000,0x00000000,0x00000000,0xA0000000,0x00000000,
    0x58800000,0x00000008,0x00000089,0x00000899,0x00000898,0x0000008A,0x00000008,0x00000000,
    0x88988055,0x89A99908,0x9AAA8880,0x9A988000,0xAA880000,0xA9800000,0xA9800000,0x98000000,
    0x00000000,0x00000008,0x00000008,0x00000088,0x00000089,0x00000089,0x00000089,0x00000008,

    0x80000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000089,0x000000A8,0x00000A80,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x98000000,0x8A000000,0x08A00000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000008,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
};

//======================================================================
//
//  metr_box, 64x64@4, 
//  + 64 tiles not compressed
//  Total size: 2048 = 2048
//
//  Time-stamp: 2005-12-24, 17:37:08
//  Exported by Cearn's Usenti v1.7.1
//  (comments, kudos, flames to "daytshen@hotmail.com")
//
//======================================================================

const unsigned int metr_boxTiles[512]=
{
    0x11111111,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,
    0x11111111,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x11111111,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x11111111,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x11111111,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x11111111,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x11111111,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x11111111,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,

    0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0xCCC00000,0xDDCC0000,0xEEDDC000,0x00ECDC00,0x006EEDC0,0x66000EDC,
    0xCCCCC000,0xDDDDDCCC,0xEEEEEDDD,0x45600EEE,0x45600000,0x56000000,0x60000000,0x00000005,
    0x000CCCCC,0xCCCDDDDD,0xDDDEEEEE,0xEEE54000,0x00066400,0x00000644,0x00000065,0x00000006,
    0x00000000,0x00000000,0x000000CC,0x0000CCDD,0x000CDDEE,0x00CDCE00,0x0CDEE000,0xCDE00000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,

    0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,
    0xC0000000,0xDC000000,0xCDC00000,0xEDDC0000,0x0ECC0000,0x0ECDC000,0x60EDC000,0x00ECDC00,
    0x000000ED,0x0000000E,0x0000000E,0x00000000,0x00000000,0x00000000,0x66000006,0x00650560,
    0x00006006,0x00060660,0x00650056,0x05000006,0x50500006,0x00000056,0x00000060,0x00000060,
    0x00000060,0x00000600,0x00000600,0x00005600,0x00006000,0x00006000,0x00006500,0x00000600,
    0xDE000000,0xE0000000,0xE0000000,0x00000000,0x60000000,0x56000000,0x45600000,0x00060000,
    0x0000000C,0x000000CD,0x00000CDC,0x0000CDDE,0x0000CDE0,0x000CDCE5,0x000CDE54,0x00CDCE44,
    0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,

    0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,
    0x000EDC00,0x066EDC00,0x6500EDC0,0x0000EDC0,0x0000EDC0,0x0000EDC0,0x60000EDC,0x66000EDC,
    0x00066600,0x00000000,0x00000050,0x00000006,0x00000065,0x00000060,0x00000506,0x66600600,
    0x60000600,0x56606000,0x45560000,0x34456000,0x44445600,0x34345600,0x43445600,0x34445666,
    0x00006666,0x00665555,0x06554344,0x65444434,0x54444343,0x54343444,0x53434443,0x54443434,
    0x66066000,0x00600600,0x00000600,0x00006000,0x00006006,0x00006006,0x00060006,0x00006606,
    0x00CDE556,0x00CDE660,0x0CDE6000,0x0CDE0000,0x0CDE0000,0x0CDE0000,0xCDE00000,0xCDE00000,
    0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,

    0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,
    0x06000EDC,0x06000EDC,0x06600EDC,0x06560EDC,0x65560EDC,0x65460EDC,0x64560EDC,0x66600EDC,
    0x55566600,0x44455600,0x34445600,0x43344560,0x33444460,0x44433460,0x34344560,0x34445600,
    0x43456655,0x44565553,0x55565444,0x66654344,0x64654434,0x64654343,0x66655444,0x46665544,
    0x66666544,0x55555665,0x43435556,0x43444455,0x34343445,0x43434344,0x44344445,0x44434556,
    0x00000666,0x00006655,0x06065534,0x60655444,0x00654343,0x00654434,0x00655443,0x06065554,
    0xCDE60000,0xCDE56000,0xCDE45600,0xCDE56060,0xCDE60006,0xCDE00000,0xCDE00000,0xCDE00000,
    0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,

    0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,
    0x06000EDC,0x06000EDC,0x6000EDC0,0x5000ED00,0x00EEDC60,0xEEDDC600,0xDCC66000,0x66550880,
    0x43555600,0x55566650,0x66600060,0x0EEE0056,0xEDDDEE00,0xDC6CDDEE,0x66556CCD,0x58885556,
    0x64665554,0x06066655,0x00000666,0x00000000,0x0000000D,0x00000DDE,0xDDDDDEEC,0xEEEEDDC6,
    0x55555660,0x66666000,0x00000650,0x00000060,0xD0060606,0xEDD05005,0xCEEDDDDD,0x6CDDEEEE,
    0x60006655,0x60000066,0x66000000,0x0600EEE0,0x55EEDDDE,0xEEDD66CD,0xDCC65566,0x65558885,
    0xCDE00000,0xCDE00000,0x0CDE0006,0x00DE0065,0x06CDEE54,0x006CDDEE,0x00066CCD,0x08805566,
    0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,

    0x00000001,0x80000001,0x80000001,0x88000001,0x98000001,0x98000001,0x98000001,0x80000001,
    0x55088988,0x80999A98,0x0888AAA9,0x000889A9,0x000088AA,0x0000089A,0x0000089A,0x00000089,
    0x00000885,0x80000000,0x98000000,0x99800000,0x89800000,0xA8000000,0x80000000,0x00000000,
    0x55CC6655,0x66555008,0x50000889,0x00000000,0x00000000,0x00000000,0x0000000A,0x00000000,
    0x5566CC55,0x80055566,0x98800005,0x00000000,0x00000000,0x00000000,0xA0000000,0x00000000,
    0x58800000,0x00000008,0x00000089,0x00000899,0x00000898,0x0000008A,0x00000008,0x00000000,
    0x88988055,0x89A99908,0x9AAA8880,0x9A988000,0xAA880000,0xA9800000,0xA9800000,0x98000000,
    0x10000000,0x10000008,0x10000008,0x10000088,0x10000089,0x10000089,0x10000089,0x10000008,

    0x80000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x00000001,0x11111111,
    0x00000089,0x000000A8,0x00000A80,0x00000000,0x00000000,0x00000000,0x00000000,0x11111111,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x11111111,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x11111111,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x11111111,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x11111111,
    0x98000000,0x8A000000,0x08A00000,0x00000000,0x00000000,0x00000000,0x00000000,0x11111111,
    0x10000008,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x11111111,
};

And this is the main code to load the sprite from metr.c.

    #include <tonc.h>
    #include <string.h>
    #include "metr.h"

    OBJ_ATTR    obj_buffer[128];
    OBJ_AFFINE  *obj_aff_buffer = (OBJ_AFFINE*)obj_buffer;


    int main()
    {
        /* copy array of tiles to tile_mem */
       memcpy( &tile_mem[4][0], metrTiles, metrTilesLen );
       /* copy array of pallete to pallet object memory */
       memcpy( pal_obj_mem, metrPal, metrPalLen);

    /* malloc()-ing the obj_buffer according to its length */
    oam_init( obj_buffer, 128 );
    REG_DISPCNT = DCNT_MODE0 | DCNT_OBJ | DCNT_OBJ_1D;

    u16 x       = 96;
    u16 y       = 32;
    u32 tid     = 0;
    u32 palbank = 0;

    OBJ_ATTR    *metr = &obj_buffer[0];
    obj_set_attr( metr,
                  ATTR0_SQUARE,
                  ATTR1_SIZE_64,
                  ATTR2_PALBANK(palbank) | tid );


    obj_set_pos( metr, x, y );

    while(1)
    {
        vid_vsync();
        key_poll();

        oam_copy( oam_mem, obj_buffer, 1 );
    }

    return 0;
}

It works well, so I tried to create my own sprite code based on this image. Here's the resulting sprite array in .h and .c file:

knight.h

/*
 * Exported with nin10kit v1.8
 * Time-stamp: Saturday 06/23/2018, 03:26:15
 * 
 * Image Information
 * -----------------
 * /home/amarcellinus/Public/assets/CH01_Idle.png 32@64
 * /home/amarcellinus/Public/assets/CH01_Idle.png 32@64
 * 
 * All bug reports / feature requests are to be filed here https://github.com/TricksterGuy/nin10kit/issues
 */

#ifndef KNIGHT_H
#define KNIGHT_H

#define KNIGHT_PALETTE_TYPE (1 << 13)
#define KNIGHT_DIMENSION_TYPE (1 << 6)

extern const unsigned short knight_palette[12];
#define KNIGHT_PALETTE_SIZE 24
#define KNIGHT_PALETTE_LENGTH 12

extern const unsigned short knight[1024];
#define KNIGHT_SIZE 2048
#define KNIGHT_LENGTH 1024

#define KNIGHT_PALETTE_ID (0 << 12)
#define KNIGHT_SPRITE_SHAPE (2 << 14)
#define KNIGHT_SPRITE_SIZE (3 << 14)
#define KNIGHT_ID 512

#endif

knight.c

/*
 * Exported with nin10kit v1.8
 * Time-stamp: Saturday 06/23/2018, 03:26:15
 * 
 * Image Information
 * -----------------
 * /home/amarcellinus/Public/assets/CH01_Idle.png 32@64
 * /home/amarcellinus/Public/assets/CH01_Idle.png 32@64
 * 
 * All bug reports / feature requests are to be filed here https://github.com/TricksterGuy/nin10kit/issues
 */

#include "knight.h"

const unsigned short knight_palette[12] =
{
    0x7fff,0x0000,0x1c63,0x146a,0x1cb1,0x6146,0x1d77,0x620f,
    0x7e6e,0x3a9d,0x7b57,0x5b3e
};

const unsigned short knight[1024] =
{
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0201,0x0102,0x0201,
    0x0101,0x0502,0x0105,0x0502,0x0101,0x0505,0x0505,0x0502,
    0x0201,0x0505,0x0505,0x0505,0x0501,0x0808,0x0108,0x0505,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0201,0x0505,0x0505,0x0505,0x0505,0x0808,0x0505,0x0505,
    0x0805,0x0505,0x0808,0x0808,0x0508,0x0808,0x0808,0x0808,
    0x0805,0x080a,0x0808,0x0805,0x0a05,0x080a,0x0508,0x0808,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0801,0x0101,
    0x0102,0x0801,0x0108,0x0101,0x0505,0x0505,0x0105,0x0101,
    0x0508,0x0205,0x0101,0x0101,0x0808,0x0508,0x0105,0x0101,
    0x0808,0x0808,0x0505,0x0101,0x0808,0x0a05,0x050a,0x0102,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0801,0x0808,0x0108,0x0505,0x0801,0x0808,0x0101,0x0505,
    0x0501,0x0a0a,0x0201,0x0505,0x0501,0x0a08,0x0201,0x0505,
    0x0501,0x0808,0x0201,0x0202,0x0501,0x0805,0x0101,0x0201,
    0x0501,0x0505,0x0101,0x0601,0x0201,0x0505,0x0101,0x0901,
    0x0808,0x0a0a,0x0805,0x0a08,0x0808,0x0508,0x0802,0x0a0a,
    0x0808,0x0508,0x0802,0x0508,0x0808,0x0208,0x0505,0x0205,
    0x0805,0x0208,0x0205,0x0602,0x0805,0x0208,0x0101,0x0b09,
    0x0805,0x0208,0x0400,0x0b0b,0x0502,0x0208,0x0400,0x0000,
    0x050a,0x0a08,0x0508,0x0102,0x0805,0x080a,0x0208,0x0101,
    0x0502,0x0808,0x0105,0x0101,0x0206,0x0805,0x0105,0x0101,
    0x0609,0x0502,0x0102,0x0101,0x090b,0x0502,0x0102,0x0101,
    0x0b0b,0x0202,0x0101,0x0101,0x0000,0x0201,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0201,0x0502,0x0101,0x0101,0x0101,0x0102,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0201,
    0x0502,0x0208,0x0109,0x000b,0x0201,0x0205,0x0b09,0x090b,
    0x0101,0x0202,0x0602,0x0906,0x0101,0x0201,0x0303,0x0202,
    0x0101,0x0004,0x0004,0x0400,0x0101,0x0004,0x0004,0x0400,
    0x0201,0x0703,0x0703,0x0407,0x0202,0x0302,0x0703,0x0103,
    0x0900,0x0201,0x0101,0x0101,0x0609,0x0201,0x0101,0x0101,
    0x0102,0x0101,0x0101,0x0101,0x0702,0x0101,0x0101,0x0101,
    0x0202,0x0102,0x0101,0x0101,0x0103,0x0202,0x0101,0x0101,
    0x0101,0x0201,0x0102,0x0101,0x0101,0x0101,0x0202,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0701,0x0101,0x0101,0x0701,0x0007,
    0x0101,0x0101,0x0101,0x0202,0x0101,0x0101,0x0701,0x0207,
    0x0101,0x0101,0x0007,0x0207,0x0101,0x0701,0x0000,0x0202,
    0x0701,0x0007,0x0200,0x0102,0x0007,0x0000,0x0202,0x0601,
    0x0000,0x0200,0x0107,0x0b06,0x0000,0x0702,0x0107,0x0b0b,
    0x0201,0x0302,0x0202,0x0103,0x0102,0x0209,0x0006,0x0202,
    0x0102,0x0603,0x0303,0x0206,0x0301,0x0603,0x0903,0x0200,
    0x0206,0x0602,0x0303,0x0203,0x0b0b,0x0106,0x0606,0x0306,
    0x060b,0x0101,0x0101,0x0301,0x0106,0x0101,0x0101,0x0601,
    0x0101,0x0301,0x0206,0x0101,0x0101,0x0202,0x0602,0x0101,
    0x0701,0x0202,0x0102,0x0101,0x0207,0x0207,0x0102,0x0101,
    0x0702,0x0702,0x0101,0x0101,0x0202,0x0207,0x0101,0x0101,
    0x0203,0x0102,0x0101,0x0101,0x0b0b,0x0103,0x0101,0x0101,
    0x0101,0x0101,0x0007,0x0000,0x0101,0x0707,0x0000,0x0200,
    0x0701,0x0000,0x0000,0x0702,0x0701,0x0000,0x0700,0x0707,
    0x0001,0x0700,0x0707,0x0707,0x0001,0x0707,0x0707,0x0202,
    0x0201,0x0202,0x0202,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0200,0x0707,0x0102,0x0b06,0x0702,0x0207,0x0101,0x0101,
    0x0707,0x0102,0x0101,0x0301,0x0207,0x0101,0x0101,0x0301,
    0x0102,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0001,0x0101,0x0101,0x0101,0x0303,
    0x060b,0x0101,0x0101,0x0101,0x0606,0x0101,0x0101,0x0101,
    0x0303,0x0103,0x0101,0x0101,0x0303,0x0103,0x0101,0x0101,
    0x0303,0x0103,0x0101,0x0101,0x0303,0x0101,0x0101,0x0101,
    0x0300,0x0101,0x0101,0x0101,0x0103,0x0101,0x0101,0x0101,
    0x0b06,0x0106,0x0101,0x0101,0x0b06,0x010b,0x0101,0x0101,
    0x0601,0x0b0b,0x0101,0x0101,0x0601,0x060b,0x0101,0x0101,
    0x0101,0x0303,0x0303,0x0101,0x0101,0x0301,0x0303,0x0101,
    0x0101,0x0301,0x0303,0x0101,0x0101,0x0101,0x0303,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0303,0x0101,0x0101,0x0101,0x0000,0x0101,
    0x0101,0x0101,0x0003,0x0103,0x0101,0x0101,0x0303,0x0103,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
    0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101
};

And I modify the code based on the main code I showed before.

#include <tonc.h>
#include <string.h>
#include "knight.h"

OBJ_ATTR    obj_buffer[128];
OBJ_AFFINE  *obj_aff_buffer = (OBJ_AFFINE*)obj_buffer;


int main()
{
    /* copy array of tiles to tile_mem */
    memcpy( &tile_mem[4][0], knight, KNIGHT_LENGTH );
    /* copy array of pallete to pallet object memory */
    memcpy( pal_obj_mem, knight_palette, KNIGHT_PALETTE_LENGTH);

    /* malloc()-ing the obj_buffer according to its length */
    oam_init( obj_buffer, 128 );
    REG_DISPCNT = DCNT_MODE0 | DCNT_OBJ | DCNT_OBJ_1D;

    u16 x       = 96;
    u16 y       = 32;
    u32 tid     = 0;
    u32 palbank = 0;

    OBJ_ATTR    *metr = &obj_buffer[0];
    obj_set_attr( metr,
                  ATTR0_TALL,
                  ATTR1_SIZE_64,
                  ATTR2_PALBANK( 0 ) | KNIGHT_ID );



    obj_set_pos( metr, x, y );

    while(1)
    {
        vid_vsync();
        key_poll();

        oam_copy( oam_mem, obj_buffer, 1 );
    }

    return 0;
}

When I compiled it, it just only showing the broken pixel, as shown in here. Any idea why the rendering is not working as I expected while I just changed the content of the array?

c
sprite
devkitpro
gba

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0