I've encountered the problem that my game starts to lag even tough, as far as I can see it, the game logic is pretty short.
I created a very small sample program to demonstrate my problem. It's in the attachments.
When the game logic hits, this is basically the only thing that is done:
In the sample program, the PpuUpdate array isn't actually used for anything.
But in the actual game, this is the array that gets written into the PPU: I fill two status bars and, if applicable, a vertical column for the background update during scrolling.
And then I write it into the PPU during vblank to put the graphics on screen.
But the above program already takes two frames to finish the ProcessNextFrame function.
If you remove one of the PreparePpuUpdate lines, it runs at full speed.
But the problem is: In the moment, the function doesn't do anything else but filling the array. And this already exceeds the time per frame. So, how am I ever supposed to include actual game logic? Character behavior, enemy behavior etc. How will this be possible if the above code already lags?
Or maybe I'm also doing something wrong in the "Main.s" file.
Does anybody have an idea?
I created a very small sample program to demonstrate my problem. It's in the attachments.
When the game logic hits, this is basically the only thing that is done:
Code:
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0]))
extern unsigned char ScrollingPosition;
#pragma zpsym("ScrollingPosition")
static unsigned char PpuUpdate[255];
static unsigned char PpuUpdateIndex;
static unsigned char b;
static const unsigned char StatusBar[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
void PreparePpuUpdate(const unsigned char *data, unsigned char dataLength)
{
for (b = 0; b < dataLength; ++b)
PpuUpdate[PpuUpdateIndex++] = data[b];
}
void ProcessNextFrame(void)
{
ScrollingPosition += 1;
PpuUpdateIndex = 0;
PreparePpuUpdate(StatusBar, ARRAY_LENGTH(StatusBar));
PreparePpuUpdate(StatusBar, ARRAY_LENGTH(StatusBar));
PreparePpuUpdate(StatusBar, ARRAY_LENGTH(StatusBar));
}
extern unsigned char ScrollingPosition;
#pragma zpsym("ScrollingPosition")
static unsigned char PpuUpdate[255];
static unsigned char PpuUpdateIndex;
static unsigned char b;
static const unsigned char StatusBar[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
void PreparePpuUpdate(const unsigned char *data, unsigned char dataLength)
{
for (b = 0; b < dataLength; ++b)
PpuUpdate[PpuUpdateIndex++] = data[b];
}
void ProcessNextFrame(void)
{
ScrollingPosition += 1;
PpuUpdateIndex = 0;
PreparePpuUpdate(StatusBar, ARRAY_LENGTH(StatusBar));
PreparePpuUpdate(StatusBar, ARRAY_LENGTH(StatusBar));
PreparePpuUpdate(StatusBar, ARRAY_LENGTH(StatusBar));
}
In the sample program, the PpuUpdate array isn't actually used for anything.
But in the actual game, this is the array that gets written into the PPU: I fill two status bars and, if applicable, a vertical column for the background update during scrolling.
And then I write it into the PPU during vblank to put the graphics on screen.
But the above program already takes two frames to finish the ProcessNextFrame function.
If you remove one of the PreparePpuUpdate lines, it runs at full speed.
But the problem is: In the moment, the function doesn't do anything else but filling the array. And this already exceeds the time per frame. So, how am I ever supposed to include actual game logic? Character behavior, enemy behavior etc. How will this be possible if the above code already lags?
Or maybe I'm also doing something wrong in the "Main.s" file.
Does anybody have an idea?