Writing GBA games with D!
Raimondo Mancino
rmancino at gmail.com
Wed May 19 15:59:33 UTC 2021
On Wednesday, 19 May 2021 at 13:52:58 UTC, Raimondo Mancino wrote:
> ## 4. Notice
> At the moment, the binary is built correctly, but it does not
> seem to link correctly when using D.
>
> Using GCC (for the C example above) instead of GDC with same
> options works so my guess is that the linker script needs to be
> updated.
>
> I think I need help for this; do you have any suggestions?
> Thank you in advance.
# Edit: It works!
To make it work correctly, you need to use volatile reference to
VRAM.
So the correct hello world program is:
```d
import core.volatile;
@nogc:
enum VRAM = cast(ushort*) 0x6000000;
enum SCREEN_WIDTH = 240;
enum SCREEN_HEIGHT = 160;
enum FRAME_SEL_BIT = 0x10;
enum BG2_ENABLE = 0x400;
enum REG_DISP_CTL = cast(ushort*) 0x4000000;
extern(C) int main() {
int i;
volatileStore(REG_DISP_CTL, 3 | BG2_ENABLE);
volatileStore(REG_DISP_CTL, volatileLoad(REG_DISP_CTL) &
~FRAME_SEL_BIT);
for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) {
VRAM[i] = 31;
}
for(;;) { }
return 0;
}
```
Since we used -fno-druntime, core/volatile.d needs to be included
in our project.
More information about the Digitalmars-d
mailing list