In my NES program, I have an array for palette values and a "boolean" variable:
Whenever _PalettesDataIsFilled is set to 1, the NMI will update the palette by reading _PalettesData and copying it into the PPU and then it will set _PalettesDataIsFilled back to 0.
This works totally fine.
My problem is: When I try to copy another array to _PalettesDataIsFilled, it works only when I access the data directly, but not when I use a function for it.
So, let's say I have this constant:
Now, when I do this:
then everything is alright. _PalettesData gets properly filled and I can see the colors in the game because the NMI reads from _PalettesData.
But now my problem: If I try to use a copy function, it doesn't work:
The NMI will just fill the palette with a bunch of zeroes, i.e. the values that _PalettesData has when it is declared.
So, why doesn't the copy function work?
When I use memcpy from the <string.h>, it works again:
What am I doing wrong with my CopyData function? I debugged it in Visual Studio and the copy process worked fine there.
Besides, in case you wonder why I don't just use memcpy: I'm planning to do more custom copy stuff like "read everything until the value 0xFF appears" etc. The above function is just the most basic one to explain my problem.
Code:
.segment "ZEROPAGE"
_PalettesDataIsFilled: .res 1
.exportzp _PalettesDataIsFilled
.segment "BSS"
_PalettesData: .res 32
.export _PalettesData
_PalettesDataIsFilled: .res 1
.exportzp _PalettesDataIsFilled
.segment "BSS"
_PalettesData: .res 32
.export _PalettesData
Whenever _PalettesDataIsFilled is set to 1, the NMI will update the palette by reading _PalettesData and copying it into the PPU and then it will set _PalettesDataIsFilled back to 0.
This works totally fine.
My problem is: When I try to copy another array to _PalettesDataIsFilled, it works only when I access the data directly, but not when I use a function for it.
So, let's say I have this constant:
Code:
const unsigned char TitleScreenPalettesData[] =
{
0x0F, 0x16, 0x16, 0x16, 0x0F, 0x1A, 0x1A, 0x1A, 0x0F, 0x12, 0x12, 0x12, 0x0F, 0x28, 0x28, 0x28,
0x0F, 0x30, 0x30, 0x30, 0x0F, 0x30, 0x30, 0x30, 0x0F, 0x30, 0x30, 0x30, 0x0F, 0x30, 0x30, 0x30,
};
{
0x0F, 0x16, 0x16, 0x16, 0x0F, 0x1A, 0x1A, 0x1A, 0x0F, 0x12, 0x12, 0x12, 0x0F, 0x28, 0x28, 0x28,
0x0F, 0x30, 0x30, 0x30, 0x0F, 0x30, 0x30, 0x30, 0x0F, 0x30, 0x30, 0x30, 0x0F, 0x30, 0x30, 0x30,
};
Now, when I do this:
Code:
extern byte PalettesData[];
extern byte PalettesDataIsFilled;
#pragma zpsym("PalettesDataIsFilled")
static unsigned char Index;
void InitializeTitleScreen(void)
{
for (Index = 0; Index < 32; ++Index)
PalettesData[Index] = TitleScreenPalettesData[Index];
PalettesDataIsFilled = 1;
}
extern byte PalettesDataIsFilled;
#pragma zpsym("PalettesDataIsFilled")
static unsigned char Index;
void InitializeTitleScreen(void)
{
for (Index = 0; Index < 32; ++Index)
PalettesData[Index] = TitleScreenPalettesData[Index];
PalettesDataIsFilled = 1;
}
then everything is alright. _PalettesData gets properly filled and I can see the colors in the game because the NMI reads from _PalettesData.
But now my problem: If I try to use a copy function, it doesn't work:
Code:
extern byte PalettesData[];
extern byte PalettesDataIsFilled;
#pragma zpsym("PalettesDataIsFilled")
static unsigned char Index;
void CopyPalettesData(unsigned char *destinationData, const unsigned char *sourceData)
{
for (Index = 0; Index < 32; ++Index)
destinationData[Index] = sourceData[Index];
}
void InitializeTitleScreen(void)
{
CopyPalettesData(PalettesData, TitleScreenPalettesData);
PalettesDataIsFilled = 1;
}
extern byte PalettesDataIsFilled;
#pragma zpsym("PalettesDataIsFilled")
static unsigned char Index;
void CopyPalettesData(unsigned char *destinationData, const unsigned char *sourceData)
{
for (Index = 0; Index < 32; ++Index)
destinationData[Index] = sourceData[Index];
}
void InitializeTitleScreen(void)
{
CopyPalettesData(PalettesData, TitleScreenPalettesData);
PalettesDataIsFilled = 1;
}
The NMI will just fill the palette with a bunch of zeroes, i.e. the values that _PalettesData has when it is declared.
So, why doesn't the copy function work?
When I use memcpy from the <string.h>, it works again:
Code:
void InitializeTitleScreen(void)
{
memcpy(PalettesData, TitleScreenPalettesData, 32);
PalettesDataIsFilled = 1;
}
{
memcpy(PalettesData, TitleScreenPalettesData, 32);
PalettesDataIsFilled = 1;
}
What am I doing wrong with my CopyData function? I debugged it in Visual Studio and the copy process worked fine there.
Besides, in case you wonder why I don't just use memcpy: I'm planning to do more custom copy stuff like "read everything until the value 0xFF appears" etc. The above function is just the most basic one to explain my problem.