diff --git a/README.md b/README.md index bb016b7..3c398da 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,28 @@ # nim-libnx -Libnx ported to the Nim programming language. You will need a nim compiler with Nintendo switch support which can be found [here](https://github.com/jyapayne/Nim/tree/nintendo_switch_support) until the PR is accepted. +Libnx ported to the Nim programming language. You will need a Nim compiler with Nintendo switch support which can be found in the latest devel branch of the Nim compiler. -You also must have DevkitPro and switch (libnx) libraries for [Mac and Linux](https://github.com/devkitPro/pacman/releases) or [Windows](https://github.com/devkitPro/installer/releases) installed. The DEVKITPRO environment variable must also exist and point to a directory with the following structure: +You also must have DevkitPro and switch (libnx) libraries for [Mac and Linux](https://github.com/devkitPro/pacman/releases) or [Windows](https://github.com/devkitPro/installer/releases) installed. + +From dkp-pacman, the switch libraries can be installed with: + +``` +dkp-pacman -Syu +dkp-pacman -S switch-dev +## When it asks for installation options, choose the default which will install everything +``` + +The DEVKITPRO environment variable must also exist and point to a directory with the following structure: - `DEVKITPRO/libnx/lib` - `DEVKITPRO/libnx/include` +OR you must specify a valid libnx path and/or devkitpro path to the `switch_build` utility: + +```bash +switch_build --libnxPath:"C:\devkitPro\libnx" --author:"Joey" --version:"1.0.0" .\examples\accounts\account_ex.nim +# OR +switch_build --devkitProPath:"C:\devkitPro" --author:"Joey" --version:"1.0.0" .\examples\accounts\account_ex.nim +``` ## Install diff --git a/libnx.nimble b/libnx.nimble index b8e3758..6724840 100644 --- a/libnx.nimble +++ b/libnx.nimble @@ -1,6 +1,6 @@ # Package -version = "0.2.1" +version = "0.2.2" author = "Joey Payne" description = "Nintendo Switch library libnx for Nim." license = "The Unlicense" diff --git a/libnxGen.cfg b/libnxGen.cfg index f13d50d..4404075 100644 --- a/libnxGen.cfg +++ b/libnxGen.cfg @@ -8,13 +8,14 @@ filter=lock "${output}/nx/include" "${output}/nx/include/switch" "${output}/nx/include/switch/arm" -"${output}/nx/include/switch/kernel" -"${output}/nx/include/switch/services" "${output}/nx/include/switch/audio" -"${output}/nx/include/switch/gfx" +"${output}/nx/include/switch/display" +"${output}/nx/include/switch/kernel" +"${output}/nx/include/switch/nvidia" "${output}/nx/include/switch/runtime" "${output}/nx/include/switch/runtime/util" "${output}/nx/include/switch/runtime/devices" +"${output}/nx/include/switch/services" "${DEVKITPRO}/devkitA64/aarch64-none-elf/include/" [n.exclude] @@ -33,6 +34,9 @@ defines=true [result.h] defines = true +[thread_context.h] +preprocess = false + [hid.h] defines = true search.static_assert = "static_assert" @@ -165,6 +169,26 @@ import libnx/ext/integer128 template BIT*(n): auto = (1.uint shl n) """ +[thread_context.nim] +search.timport = "../types" +replace.timport = "libnx/wrapper/types" + +prepend.o = """ +import libnx/ext/integer128 +""" + +search.cpuall = "RegisterGroup_CpuAll =" +comment.cpuall = 1 + +search.fpugprs = "RegisterGroup_FpuGprs =" +prepend.fpugprs = "RegisterGroup_CpuAll = BIT(0) or BIT(1), ## /< All CPU registers." + +search.fpuall = "RegisterGroup_FpuGprs or RegisterGroup_FpuSprs" +replace.fpuall = "BIT(2) or BIT(3)" + +search.groupall = "RegisterGroup_CpuAll or RegisterGroup_FpuAll" +replace.groupall = "BIT(0) or BIT(1) or BIT(2) or BIT(3)" + [svc.nim] search.timport = "../types" replace.timport = "libnx/wrapper/types" @@ -309,6 +333,11 @@ prepend.o = """ import libnx/ext/integer128 """ +[fence.nim] +prepend.o = """ +import libnx/wrapper/types +""" + [cons.nim] search.o = "type\n" prepend.o = """ @@ -345,11 +374,16 @@ replace.threedmoo = "debugDevice_3DMOO*" search.timport = "../types" replace.timport = "libnx/wrapper/types" +search.fimport = "../nvidia/fence" +replace.fimport = "libnx/wrapper/fence" + [romfs_dev.nim] search.timport = "../types" replace.timport = "libnx/wrapper/types" search.servimport = "../services/" replace.servimport = "libnx/wrapper/" +search.o = "../libnx" +replace.o = "libnx" [n.sourcefile] "${output}/*.nim" diff --git a/src/libnx/graphics.nim b/src/libnx/graphics.nim index 668ab0f..eedc9a2 100644 --- a/src/libnx/graphics.nim +++ b/src/libnx/graphics.nim @@ -2,10 +2,12 @@ import strutils import libnx/wrapper/types, libnx/wrapper/gfx, + libnx/results, libnx/utils type GraphicsError* = object of Exception + GraphicsInitError* = object of GraphicsError InitResolutionError* = object of GraphicsError CropBoundsError* = object of GraphicsError @@ -53,7 +55,12 @@ var enabled = false ## proc initDefault*() = if not enabled: - gfxInitDefault() + let code = gfxInitDefault().newResult + if code.failed: + raiseEx( + GraphicsInitError, + "Error, graphics could not be initialized", code + ) enabled = true ## * @@ -184,10 +191,6 @@ proc getFramebuffer*(): Framebuffer = ## / Sets the \ref GfxMode. proc setMode*(mode: GfxMode) = gfxSetMode(gfx.GfxMode(mode)) -## / Controls whether a vertical-flip is done when determining the pixel-offset within -## the actual framebuffer. By default this is enabled. -proc setDrawFlip*(enabled: bool) = gfxSetDrawFlip(enabled) - ## / Configures transform. See the NATIVE_WINDOW_TRANSFORM_* enums in buffer_producer.h. ## The default is NATIVE_WINDOW_TRANSFORM_FLIP_V. proc configureTransform*(transform: BufferTransform) =