This Code works great and outputs the pixels as expected:
int main()
{
*(unsigned int *)0x04000000 = 0x0403;
unsigned short *Screen = (unsigned short *)0x06000000;
Screen[120 + 80 * 240] = 0x001F;
Screen[136 + 80 * 240] = 0x03E0;
Screen[120 + 96 * 240] = 0x7C00;
Screen[100] = 0x7C00;
while (1);
return 0;
}
but whenever I try to add the for loop and change the vram values from within that, I get white screen on the emulator, it compiles with no errors and even warnings, but I get white screen on the emulator.
int main()
{
*(unsigned int *)0x04000000 = 0x0403;
unsigned short *Screen = (unsigned short *)0x06000000;
Screen[120 + 80 * 240] = 0x001F;
Screen[136 + 80 * 240] = 0x03E0;
Screen[120 + 96 * 240] = 0x7C00;
Screen[100] = 0x7C00;
int i;
for (i = 100; i < 110; i++)
{
Screen[i] = 0x7C00;
}
while (1);
return 0;
}
I ran into the same problem and found the solution: your display control pointer needs to be volatile
. If you don't mark it as volatile
, some unwanted optimizations happen at compile time that leave you with unexpected behavior.
*(volatile unsigned int *)0x04000000 = 0x0403;