Add helloworld example
This commit is contained in:
parent
e0e70d16f3
commit
e36b1f812e
3 changed files with 90 additions and 0 deletions
30
examples/helloworld/helloworld.nim
Normal file
30
examples/helloworld/helloworld.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import libnx/gfx
|
||||
import libnx/console
|
||||
import libnx/hid
|
||||
import libnx/applet
|
||||
|
||||
proc printf(formatstr: cstring) {.importc: "printf", varargs,
|
||||
header: "<stdio.h>".}
|
||||
|
||||
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()
|
||||
3
examples/helloworld/helloworld.nim.cfg
Normal file
3
examples/helloworld/helloworld.nim.cfg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
--path="../../src"
|
||||
--path="../../ext"
|
||||
--os="nintendoswitch"
|
||||
57
examples/helloworld/helloworld.nims
Normal file
57
examples/helloworld/helloworld.nims
Normal file
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue