Jump to page: 1 2
Thread overview
D code running on the Nintendo 3DS
Oct 20, 2019
TheGag96
Oct 20
TheGag96
Oct 20
Johan
Oct 20
TheGag96
Oct 20
Pander
Oct 20
TheGag96
Oct 21
TheGag96
Oct 20
Meta
Oct 20
TheGag96
October 20, 2019
Hi, all. I wanted to get into the world of 3DS homebrew, but I really didn't feel like coding in C or C++. So, through an effort of sheer will, I somehow got a hello world example written in D up and running, along with bindings for most of libctru and citro3d.

https://github.com/TheGag96/3ds-hello-dlang

Included are instructions on how to set this up (although it's pretty hacky). I imagine one could easily start writing Switch homebrew in D by following most of these steps as well. Once GCC 10 comes out with an updated GDC, it might become a pretty attractive alternative to C/++ for such projects if some work is put into bindings and stuff.

Hope someone finds this interesting!
October 20
On Sunday, 20 October 2019 at 06:06:48 UTC, TheGag96 wrote:
> Hi, all. I wanted to get into the world of 3DS homebrew, but I really didn't feel like coding in C or C++. So, through an effort of sheer will, I somehow got a hello world example written in D up and running, along with bindings for most of libctru and citro3d.
>
> https://github.com/TheGag96/3ds-hello-dlang
>
> Included are instructions on how to set this up (although it's pretty hacky). I imagine one could easily start writing Switch homebrew in D by following most of these steps as well. Once GCC 10 comes out with an updated GDC, it might become a pretty attractive alternative to C/++ for such projects if some work is put into bindings and stuff.
>
> Hope someone finds this interesting!

Definitely :-)

Did you try with LDC?
Just a wild guess but perhaps this triple will work: `-mtriple=armv6k-unknown-eabi`.

-Johan


October 20
On Sunday, 20 October 2019 at 06:06:48 UTC, TheGag96 wrote:
> Hi, all. I wanted to get into the world of 3DS homebrew, but I really didn't feel like coding in C or C++. So, through an effort of sheer will, I somehow got a hello world example written in D up and running, along with bindings for most of libctru and citro3d.
>
> https://github.com/TheGag96/3ds-hello-dlang
>
> Included are instructions on how to set this up (although it's pretty hacky). I imagine one could easily start writing Switch homebrew in D by following most of these steps as well. Once GCC 10 comes out with an updated GDC, it might become a pretty attractive alternative to C/++ for such projects if some work is put into bindings and stuff.
>
> Hope someone finds this interesting!

I'm really gonna give it a try. Really nice, nice work.
October 20
On Sun, 20 Oct 2019 at 08:10, TheGag96 via Digitalmars-d-announce <digitalmars-d-announce@puremagic.com> wrote:
>
> Hi, all. I wanted to get into the world of 3DS homebrew, but I really didn't feel like coding in C or C++. So, through an effort of sheer will, I somehow got a hello world example written in D up and running, along with bindings for most of libctru and citro3d.
>
> https://github.com/TheGag96/3ds-hello-dlang
>
> Included are instructions on how to set this up (although it's pretty hacky). I imagine one could easily start writing Switch homebrew in D by following most of these steps as well. Once GCC 10 comes out with an updated GDC, it might become a pretty attractive alternative to C/++ for such projects if some work is put into bindings and stuff.
>
> Hope someone finds this interesting!

Great stuff!  Though I don't think you'll find much improvement in gdc 10 regarding switching off D features.  Backported patches to make gdc on parity with dmd as of April 2019 was done prior to the gdc 9 release.  I'm not aware of much more being done regarding that other than some extern(C) library functions being converted into templates, and the C main function being moved to a common location in D runtime (C main is not "compiled into" gdc unlike previous versions of dmd).

-- 
Iain
October 20
On Sun, 20 Oct 2019 at 17:27, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>
> On Sun, 20 Oct 2019 at 08:10, TheGag96 via Digitalmars-d-announce <digitalmars-d-announce@puremagic.com> wrote:
> >
> > Hi, all. I wanted to get into the world of 3DS homebrew, but I really didn't feel like coding in C or C++. So, through an effort of sheer will, I somehow got a hello world example written in D up and running, along with bindings for most of libctru and citro3d.
> >
> > https://github.com/TheGag96/3ds-hello-dlang
> >
> > Included are instructions on how to set this up (although it's pretty hacky). I imagine one could easily start writing Switch homebrew in D by following most of these steps as well. Once GCC 10 comes out with an updated GDC, it might become a pretty attractive alternative to C/++ for such projects if some work is put into bindings and stuff.
> >
> > Hope someone finds this interesting!
>
> Great stuff!  Though I don't think you'll find much improvement in gdc 10 regarding switching off D features.  Backported patches to make gdc on parity with dmd as of April 2019 was done prior to the gdc 9 release.  I'm not aware of much more being done regarding that other than some extern(C) library functions being converted into templates, and the C main function being moved to a common location in D runtime (C main is not "compiled into" gdc unlike previous versions of dmd).
>

For citation on betterC, this is the dmd-cxx PR: https://github.com/dlang/dmd/pull/9678

And the commit done to gcc trunk: https://github.com/gcc-mirror/gcc/commit/7ad41fff7142a495d030e55aa93ae4959b804494

-- 
Iain
October 20
On Sunday, 20 October 2019 at 06:06:48 UTC, TheGag96 wrote:
> Hi, all. I wanted to get into the world of 3DS homebrew, but I really didn't feel like coding in C or C++. So, through an effort of sheer will, I somehow got a hello world example written in D up and running, along with bindings for most of libctru and citro3d.
>
> https://github.com/TheGag96/3ds-hello-dlang
>
> Included are instructions on how to set this up (although it's pretty hacky). I imagine one could easily start writing Switch homebrew in D by following most of these steps as well. Once GCC 10 comes out with an updated GDC, it might become a pretty attractive alternative to C/++ for such projects if some work is put into bindings and stuff.
>
> Hope someone finds this interesting!

Awesome work. I used to hack around on my original NDS and thought about maybe trying to get D working on it, but didn't have sufficient time or motivation. I'll definitely play around with this.
October 20
On Sunday, 20 October 2019 at 09:36:17 UTC, Johan Engelen wrote:
> Did you try with LDC?
> Just a wild guess but perhaps this triple will work: `-mtriple=armv6k-unknown-eabi`.
>
> -Johan

I haven't yet, but I've been told also by someone else to try! It would certainly be nice to have a true -betterC going with this. Does LDC have equivalent flags for what devkitARM wants passed into GCC, like:

-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
-mword-relocations -fomit-frame-pointer -ffunction-sections

?
October 20
On Sunday, 20 October 2019 at 15:27:35 UTC, Iain Buclaw wrote:
> Great stuff!  Though I don't think you'll find much improvement in gdc 10 regarding switching off D features.  Backported patches to make gdc on parity with dmd as of April 2019 was done prior to the gdc 9 release.  I'm not aware of much more being done regarding that other than some extern(C) library functions being converted into templates, and the C main function being moved to a common location in D runtime (C main is not "compiled into" gdc unlike previous versions of dmd).

Darn... Are there any plans at some point in the future to add a real -betterC sort of flag? It would be really really nice to be able to compile something like...

import std.bitmanip : bitfields;

struct Stuff {
  mixin(bitfields!(
        uint, "x",    2,
        int,  "y",    3,
        uint, "z",    2,
        bool, "flag", 1));
}

extern(C) void main() {
  Stuff x;
}

...just as in DMD or LDC.
October 20
On Sunday, 20 October 2019 at 17:40:04 UTC, Meta wrote:
> Awesome work. I used to hack around on my original NDS and thought about maybe trying to get D working on it, but didn't have sufficient time or motivation. I'll definitely play around with this.

Last year I was able to get some C very simple code running on the DS, hacked into Pokemon Platinum... I imagine it could be done with -betterC, I guess! Following this tutorial might do a good chunk of the work to setting it up. You'd just need to copy similar stuff I did in 3ds_rules and my (horrific) Makefile in nds_rules. You could get by converting an example DS hello world and declaring any functions/structs needed in your main file as a start.
October 20
On Sun, 20 Oct 2019 at 20:40, TheGag96 via Digitalmars-d-announce <digitalmars-d-announce@puremagic.com> wrote:
>
> On Sunday, 20 October 2019 at 15:27:35 UTC, Iain Buclaw wrote:
> > Great stuff!  Though I don't think you'll find much improvement in gdc 10 regarding switching off D features.  Backported patches to make gdc on parity with dmd as of April 2019 was done prior to the gdc 9 release.  I'm not aware of much more being done regarding that other than some extern(C) library functions being converted into templates, and the C main function being moved to a common location in D runtime (C main is not "compiled into" gdc unlike previous versions of dmd).
>
> Darn... Are there any plans at some point in the future to add a real -betterC sort of flag? It would be really really nice to be able to compile something like...
>
> import std.bitmanip : bitfields;
>
> struct Stuff {
>    mixin(bitfields!(
>          uint, "x",    2,
>          int,  "y",    3,
>          uint, "z",    2,
>          bool, "flag", 1));
> }
>
> extern(C) void main() {
>    Stuff x;
> }
>
> ...just as in DMD or LDC.

I called the option switch -fno-druntime, because -betterC was at the time of invention (and still is) a terrible name for a switch. Originally, for a long time, it just meant -fno-mduleinfo, but then -fno-exceptions and -fno-rtti got added which warranted giving it a name that turned off all three (well, four including D asserts, that is not exposed as an option as far as I recall).

If the above works for you in the latest dmd, that's probably because the library has improved, not the compiler. (You need to write code in a way that doesn't depend on D runtime, not just expect the compiler to do everything for you. :-)

-- 
Iain
« First   ‹ Prev
1 2