From 55246d6b4e0b76494fb3c36306a775aa2764b345 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Sat, 28 Dec 2024 19:26:16 +0100 Subject: [PATCH] ADD getRefreshRate --- src/playdate/bindings/display.nim | 11 +++++++---- src/playdate/display.nim | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/playdate/bindings/display.nim b/src/playdate/bindings/display.nim index 26d3527..52a8ade 100644 --- a/src/playdate/bindings/display.nim +++ b/src/playdate/bindings/display.nim @@ -4,11 +4,14 @@ import utils sdktype: type PlaydateDisplay* {.importc: "const struct playdate_display", header: "pd_api.h".} = object + # directly mapped to C api getWidth {.importsdk.}: proc (): cint getHeight {.importsdk.}: proc (): cint - setRefreshRate {.importsdk.}: proc (rate: cfloat) - setInverted {.importc: "setInverted".}: proc (flag: cint) {.cdecl, raises: [].} setScale {.importsdk.}: proc (s: cuint) setMosaic {.importsdk.}: proc (x: cuint; y: cuint) - setFlipped {.importc: "setFlipped".}: proc (x: cint; y: cint) {.cdecl, raises: [].} - setOffset {.importsdk.}: proc (x: cint; y: cint) \ No newline at end of file + setOffset* {.importsdk.}: proc (x: cint; y: cint) + + # Called from Nim (src/playdate/display.nim) + setRefreshRate {.importc: "setRefreshRate".}: proc (rate: cfloat) {.cdecl, raises: [].} + setInverted {.importc: "setInverted".}: proc (flag: cint) {.cdecl, raises: [].} + setFlipped {.importc: "setFlipped".}: proc (x: cint; y: cint) {.cdecl, raises: [].} \ No newline at end of file diff --git a/src/playdate/display.nim b/src/playdate/display.nim index 5733c57..56c6d0a 100644 --- a/src/playdate/display.nim +++ b/src/playdate/display.nim @@ -9,10 +9,24 @@ export display {.hint[DuplicateModuleImport]: off.} import bindings/display {.all.} +var + refreshRate = 30f + ## bookkeeping variable for refresh rate, because API does not provide a getter. + ## Initial value is the rate that is set on device boot + proc setInverted* (this: ptr PlaydateDisplay, inverted: bool) = privateAccess(PlaydateDisplay) this.setInverted(if inverted: 1 else: 0) proc setFlipped* (this: ptr PlaydateDisplay, x: bool, y: bool) = privateAccess(PlaydateDisplay) - this.setFlipped(if x: 1 else: 0, if y: 1 else: 0) \ No newline at end of file + this.setFlipped(if x: 1 else: 0, if y: 1 else: 0) + + +proc getRefreshRate* (this: ptr PlaydateDisplay): float32 = + refreshRate + +proc setRefreshRate* (this: ptr PlaydateDisplay, rate: float32) = + privateAccess(PlaydateDisplay) + refreshRate = rate + this.setRefreshRate(rate) \ No newline at end of file