gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Why is this a blank screen?

#8960 - yaustar - Fri Jul 25, 2003 12:49 am

I was working on this code today and just get a blank screen.
I dont think the sprites are being loaded in properly but I cant see anything wrong...

Code:

// Project:  Lights-out clone
// Author:   yaustar
// Start:    23/07/2003
// Modified: 25/07/2003

// Standard GBA headers
#include "gba.h"
#include "dispcnt.h"
#include "modes.h"
#include "sprites.h"

// Graphic files
#include "g_lights_16.h"

// OAM variable
u16* OAM = (u16*)0x7000000;

OAMEntry SPRITES[128];

// Defines for lights
#define ON 0
#define OFF 1

// Structure for sprite data
typedef struct
{
    // X and Y is the position of sprite on screen
    u16 x, y;
    u16 OAMSpriteNum;
    u16 spriteFrame[2];
    bool activeFrame;
}Sprite;

// 2D array of lights of size 5x5 (25 sprites)
Sprite allLights[5][5];

/*
typedef struct
{
    // X and Y is current position on the light array
    int X, Y;
    u16 x, y, OAMSpriteNum, spriteFrame;   
}noAniSprite;

// Sprite used for selecting lights
noAniSprite selector;
*/

// Copy sprite array into OAM
void CopyOAM(void)
{
    u16 loop;
    u16* temp;
    temp = (u16*) SPRITES;
   
    for(loop = 0; loop < 128*4; loop++)
    {
        OAM[loop] = temp[loop];
    }
}

// Set sprites off screen
void initialiseSprites(void)
{
    u16 loop;
   
    for(loop = 0; loop < 128; loop++)
    {
        SPRITES[loop].attribute0 = 160; // the y value
        SPRITES[loop].attribute1 = 240; // the x value
    }
}

// Wait for the screen to stop drawing
void WaitForVSync(void)
{
    while((volatile u16)REG_VCOUNT != 160)
    {/*do nothing*/}
}
   
/*============================================================================*/

// Start main code
int main(void)
{
    u16 loop;
    int temp = 0;
   
    // Put the lights in the right position on screen
    for(int x=0; x<5; x++)
    {
        for(int y=0; y<5; y++)
        {
                allLights[x][y].y = y*32;
                allLights[x][y].x = x*32;
                allLights[x][y].activeFrame = OFF;
                allLights[x][y].spriteFrame[0] = 0;
                // 32x32 sprite uses 16 8x8 tiles
                allLights[x][y].spriteFrame[1] = 16;
                allLights[x][y].OAMSpriteNum = temp;
                temp++;
        }
    }
   
/*    // Have the selector sprite by default on the top left of the
    // light array
    selector.X = 0;
    selector.Y = 0;
    selector.OAMSpriteNum = 25;
    selector.spriteFrame = 32;
*/   
    // Set screen mode to MODE 0, enable sprites using 1D mapping
    SetMode(MODE_0 | OBJ_ENABLE | OBJ_MAP_1D);
   
    **EDIT**
    // Loading the palette into memory
    for(loop = 0; loop = 16; loop++)
    {
        OBJPaletteMem[loop] = palette[loop];
    }
    **END EDIT**   

    initialiseSprites();
   
    // Load Sprite data into memory
   
    // The OFF state of light
    for(loop = 0; loop < 256; loop++)
    {
        OAMData[loop] = g_OFF[loop];
    }
    // The ON state of light
    for(loop = 256; loop < 512; loop++)
    {
        OAMData[loop] = g_ON[loop - 256];
    }
/*    // The SELECTOR sprite
    for(loop = 512; loop < 768; loop++)
    {
        OAMData[loop] = g_SELECT[loop - 512];
    }
*/   
    // Attribute stuff
    for(int x = 0; x < 5; x++)
    {
        for(int y = 0; y < 5; y++)
        {
            SPRITES[allLights[x][y].OAMSpriteNum].attribute0 =
              COLOR_16 | SQUARE | allLights[x][y].y;
                 
            SPRITES[allLights[x][y].OAMSpriteNum].attribute1 =
              SIZE_32 | allLights[x][y].x;
                   
            SPRITES[allLights[x][y].OAMSpriteNum].attribute2 =
              allLights[x][y].spriteFrame[allLights[x][y].activeFrame];
        }
    }
                                                                                                                                                   
    while(1)
    {
        WaitForVSync();
        CopyOAM();
    }
}


Thanks for any help

edit: Still a blank screen but in a colour that should be there
_________________
[Blog] [Portfolio]

#8968 - yaustar - Fri Jul 25, 2003 2:51 am

Sorry, my bad. A goddamn typo was the problem.

Code:

**EDIT**
    // Loading the palette into memory
    for(loop = 0; loop = 16; loop++)
    {
        OBJPaletteMem[loop] = palette[loop];
    }
**END EDIT**


to

Code:

**EDIT**
    // Loading the palette into memory
    for(loop = 0; loop < 16; loop++)
    {
        OBJPaletteMem[loop] = palette[loop];
    }
**END EDIT**

_________________
[Blog] [Portfolio]