DevkitARM,模拟器上的白屏如果我在代码中使用 for 循环?

DevkitARM, white screen on emulator If I use a for loop in the code?

此代码运行良好并按预期输出像素:

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;
}

但是每当我尝试添加 for 循环并从中更改 vram 值时,我在模拟器上出现白屏,它编译时没有错误甚至警告,但我在模拟器上出现白屏。

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;
}

我运行遇到了同样的问题并找到了解决方案:您的显示控制指针需要volatile。如果您不将其标记为 volatile,编译时会发生一些不需要的优化,使您出现意外行为。

*(volatile unsigned int *)0x04000000 = 0x0403;