From e36b1f812e08f1a291f6c8c9c28d73a47e51c300 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Tue, 19 Jun 2018 20:50:47 +0900 Subject: [PATCH] Add helloworld example --- examples/helloworld/helloworld.nim | 30 ++++++++++++++ examples/helloworld/helloworld.nim.cfg | 3 ++ examples/helloworld/helloworld.nims | 57 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 examples/helloworld/helloworld.nim create mode 100644 examples/helloworld/helloworld.nim.cfg create mode 100644 examples/helloworld/helloworld.nims diff --git a/examples/helloworld/helloworld.nim b/examples/helloworld/helloworld.nim new file mode 100644 index 0000000..0ddc66a --- /dev/null +++ b/examples/helloworld/helloworld.nim @@ -0,0 +1,30 @@ +import libnx/gfx +import libnx/console +import libnx/hid +import libnx/applet + +proc printf(formatstr: cstring) {.importc: "printf", varargs, + header: "".} + +proc main() = + gfxInitDefault() + + discard consoleInit(nil) + + printf("\x1b[16;20HHello World From NIM!") + echo "\x1b[17;20HHELLO FROM NIM" + while appletMainLoop(): + hidScanInput() + + let keysDown = hidKeysDown(CONTROLLER_P1_AUTO) + + if (keysDown and KEY_PLUS.uint64) > 0.uint64: + break + + gfxFlushBuffers() + gfxSwapBuffers() + gfxWaitForVsync() + + gfxExit() + +main() diff --git a/examples/helloworld/helloworld.nim.cfg b/examples/helloworld/helloworld.nim.cfg new file mode 100644 index 0000000..ac4ccf2 --- /dev/null +++ b/examples/helloworld/helloworld.nim.cfg @@ -0,0 +1,3 @@ +--path="../../src" +--path="../../ext" +--os="nintendoswitch" diff --git a/examples/helloworld/helloworld.nims b/examples/helloworld/helloworld.nims new file mode 100644 index 0000000..7dba2c2 --- /dev/null +++ b/examples/helloworld/helloworld.nims @@ -0,0 +1,57 @@ +let buildDir = "build" +let dkpPath = getEnv("DEVKITPRO") +let toolsPath = dkpPath & "/tools/bin" +let dkpCompilerPath = dkpPath & "/devkitA64/bin" + +switch("path", toolsPath) +switch("path", dkpCompilerPath) + +task build, "Build hello world": + + let author = "Unspecified Author" + let version = "1.0.0" + + if existsDir buildDir: + rmDir buildDir + + echo "Building..." + + mkDir buildDir + + + exec "nim c --os:nintendoswitch helloworld.nim" + + echo "Making nso..." + exec "elf2nso helloworld.elf " & buildDir & "/helloworld.nso" + + echo "Making pfs0..." + mkdir buildDir & "/exefs" + exec "cp " & buildDir & "/helloworld.nso " & buildDir & "/exefs/main" + exec "build_pfs0 " & buildDir & "/exefs " & buildDir & "/helloworld.pfs0" + + echo "Making lst..." + exec "aarch64-none-elf-gcc-nm helloworld.elf > " & buildDir & "/helloworld.lst" + + echo "Making nacp..." + # Some meta data for the homebrew launcher + exec "nacptool --create helloworld '" & author & "' '" & version & "' " & buildDir & "/helloworld.nacp" + + echo "Making nro..." + # This is the important one. The above are just extras. + exec "elf2nro helloworld.elf helloworld.nro --icon=" & dkpPath & "/libnx/default_icon.jpg --nacp=" & buildDir & "/helloworld.nacp" + + echo "Done! helloworld.nro is now in the current directory." + echo "Other build files are in the build folder." + +task clean, "Cleanup files": + if existsDir buildDir: + rmDir buildDir + + if existsDir "nimcache": + rmDir "nimcache" + + if existsFile "helloworld.elf": + rmFile "helloworld.elf" + + if existsFile "helloworld.nro": + rmFile "helloworld.nro"