www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - D code running on the Nintendo 3DS

reply TheGag96 <thegag96 gmail.com> writes:
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!
Oct 19 2019
next sibling parent reply Johan Engelen <j j.nl> writes:
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
Oct 20 2019
parent reply TheGag96 <thegag96 gmail.com> writes:
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 ?
Oct 20 2019
parent reply Johan <j j.nl> writes:
On Sunday, 20 October 2019 at 18:25:42 UTC, TheGag96 wrote:
 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
-mtriple=armv6k-unknown-eabi I am not sure about the "eabi".
 -mtune=mpcore
This is not strictly needed. (It's an optimization parameter) Maybe "-mcpu=mpcore" sets the optimizer to optimize for that cpu.
 -mfloat-abi=hard
-float-abi=hard
 -mtp=soft
Don't know if we expose this option, but LDC by default seem to do the same as GCC's -mtp=soft: https://d.godbolt.org/z/bmcRdI
 -mword-relocations
Don't know!
 -fomit-frame-pointer
This is more of a non-debug option, so not strictly needed. LDC's option is -frame-pointer=none (for newer LDC), or --disable-fp-elim=false (older and newer LDC).
 -ffunction-sections
-function-sections LDC is a cross compiler by nature, but you'll have to build the runtime libraries yourself. But LDC contains an easy tool for just that! Read: https://wiki.dlang.org/Building_LDC_runtime_libraries cheers, Johan
Oct 20 2019
parent reply TheGag96 <thegag96 gmail.com> writes:
On Sunday, 20 October 2019 at 20:31:04 UTC, Johan wrote:
 (snip)
Awesome, I just might try to get LDC working with this... On a different note, I'd really like a critique on a decision I made. Creating the bindings for libctru and citro3d was really tedious, partly because I made the decision to change every named enum from stuff like... enum GPU_TEXTURE_WRAP_PARAM { GPU_CLAMP_TO_EDGE = 0x0, ///< Clamps to edge. GPU_CLAMP_TO_BORDER = 0x1, ///< Clamps to border. GPU_REPEAT = 0x2, ///< Repeats texture. GPU_MIRRORED_REPEAT = 0x3, ///< Repeats with mirrored texture. } ...to... enum GPUTextureWrapParam { clamp_to_edge = 0x0, ///< Clamps to edge. clamp_to_border = 0x1, ///< Clamps to border. repeat = 0x2, ///< Repeats texture. mirrored_repeat = 0x3 ///< Repeats with mirrored texture. } ...in order to fit the D naming style, since the semantics for the enum was changing anyway. But of course, every struct must keep its old name... Is this alright? Should I add aliases for every struct for a better naming style, or maybe go back on my decision before, or...?
Oct 20 2019
parent Daniel Kozak <kozzi11 gmail.com> writes:
On Sun, Oct 20, 2019 at 11:40 PM TheGag96 via Digitalmars-d-announce
<digitalmars-d-announce puremagic.com> wrote:
 On Sunday, 20 October 2019 at 20:31:04 UTC, Johan wrote:
 (snip)
Awesome, I just might try to get LDC working with this... ... ...in order to fit the D naming style, since the semantics for the enum was changing anyway. But of course, every struct must keep its old name... Is this alright? Should I add aliases for every struct for a better naming style, or maybe go back on my decision before, or...?
If it is binding you should probably let it same as original code. I always try to make bindings as same as possible. It is much easier port existing code in original language. If I want to change interface or anything I made a new wrapper around that binding
Oct 21 2019
prev sibling next sibling parent Pander <freschiandrea86 gmail.com> writes:
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.
Oct 20 2019
prev sibling next sibling parent reply Iain Buclaw <ibuclaw gdcproject.org> writes:
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
Oct 20 2019
parent reply TheGag96 <thegag96 gmail.com> writes:
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.
Oct 20 2019
next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
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
Oct 20 2019
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On Sun, 20 Oct 2019 at 20:40, TheGag96 via Digitalmars-d-announce
<digitalmars-d-announce puremagic.com> wrote:
 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.
Saying that, if you can distil that into a test case with no dependencies (no imports) and gdc emits something that neither ldc or dmd does, then I should probably be notified about that in a bug report, as a newer version of the D language frontend won't necessarily fix it. -- Iain
Oct 20 2019
prev sibling parent reply Iain Buclaw <ibuclaw gdcproject.org> writes:
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.
You can compile that with gdc-9 just fine. $ cat test.d 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; x.x = 1; x.y = 42; x.z = 4; x.flag = true; return; } $ gdc -v 2>&1 | grep version gcc version 9.2.0 (GCC) $ gdc -fno-druntime test.d $ nm a.out 0000000000004028 B __bss_start 0000000000004028 b completed.7380 w __cxa_finalize GLIBC_2.2.5 0000000000001142 T _D4test5Stuff1xMFNaNbNdNiNfkZv 0000000000001125 T _D4test5Stuff1xMxFNaNbNdNiNfZk 0000000000001194 T _D4test5Stuff1yMFNaNbNdNiNfiZv 000000000000116a T _D4test5Stuff1yMxFNaNbNdNiNfZi 00000000000011df T _D4test5Stuff1zMFNaNbNdNiNfkZv 00000000000011bf T _D4test5Stuff1zMxFNaNbNdNiNfZk 000000000000121e T _D4test5Stuff4flagMFNaNbNdNiNfbZv 000000000000120a T _D4test5Stuff4flagMxFNaNbNdNiNfZb 0000000000002004 R _D4test5Stuff6__initZ 0000000000004018 D __data_start 0000000000004018 W data_start 0000000000001070 t deregister_tm_clones 00000000000010e0 t __do_global_dtors_aux 0000000000003e00 t __do_global_dtors_aux_fini_array_entry 0000000000004020 D __dso_handle 0000000000003e08 d _DYNAMIC 0000000000004028 D _edata 0000000000004030 B _end 0000000000001314 T _fini 0000000000001120 t frame_dummy 0000000000003df8 t __frame_dummy_init_array_entry 000000000000228c r __FRAME_END__ 0000000000004000 d _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 0000000000002008 r __GNU_EH_FRAME_HDR 0000000000001000 t _init 0000000000003e00 t __init_array_end 0000000000003df8 t __init_array_start 0000000000002000 R _IO_stdin_used w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable 0000000000001310 T __libc_csu_fini 00000000000012b0 T __libc_csu_init U __libc_start_main GLIBC_2.2.5 0000000000001259 T main 00000000000010a0 t register_tm_clones 0000000000001040 T _start 0000000000004028 D __TMC_END__ -- Iain
Oct 21 2019
parent TheGag96 <thegag96 gmail.com> writes:
On Monday, 21 October 2019 at 19:03:00 UTC, Iain Buclaw wrote:
 (snip)
Yeah, I just learned you could do this not long after I posted - when I tried, I had a gdc from around the time of 9.0.1 instead of 9.2, so I just had to rebuild. I'm currently attempting to get a devkitARM based off of 9.2 going since I thought it'd be simple - that may go a long way to making no-runtime/betterC work better!
Oct 21 2019
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
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
Oct 20 2019
prev sibling parent reply Meta <jared771 gmail.com> writes:
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.
Oct 20 2019
parent TheGag96 <thegag96 gmail.com> writes:
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.
Oct 20 2019