From e680de05ead31ea33e0a696d0bde9789e0a6504c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 15 Apr 2021 22:56:52 +0200 Subject: [PATCH] workaround for the joystick_get() irq problem --- compiler/res/prog8lib/cx16/syslib.p8 | 12 ++++++++++- examples/test.p8 | 30 +++++++--------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index 97090bbc8..06ea357f6 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -227,7 +227,6 @@ romsub $ff6b = mouse_get(ubyte zpdataptr @X) clobbers(A) romsub $ff71 = mouse_scan() clobbers(A, X, Y) romsub $ff53 = joystick_scan() clobbers(A, X, Y) romsub $ff56 = joystick_get(ubyte joynr @A) -> ubyte @A, ubyte @X, ubyte @Y -romsub $ff56 = joystick_get2(ubyte joynr @A) clobbers(Y) -> uword @AX ; convenience definition to get the joystick state without requiring inline assembly romsub $ff4d = clock_set_date_time(uword yearmonth @R0, uword dayhours @R1, uword minsecs @R2, ubyte jiffies @R3) clobbers(A, X, Y) romsub $ff50 = clock_get_date_time() clobbers(A, X, Y) -> uword @R0, uword @R1, uword @R2, ubyte @R3 ; result registers see clock_set_date_time() @@ -462,6 +461,17 @@ asmsub vload(str name @R0, ubyte device @Y, ubyte bank @A, uword address @R1) -> }} } +inline asmsub joystick_get2(ubyte joynr @A) clobbers(Y) -> uword @AX { + ; convenience routine to get the joystick state without requiring inline assembly that deals with the multiple return values. + ; Also disables interrupts to avoid the IRQ race condition mentioned here: https://github.com/commanderx16/x16-rom/issues/203 + ; TODO once that issue is resolved, this routine can be redefined as: romsub $ff56 = joystick_get2(ubyte joynr @A) clobbers(Y) -> uword @AX + %asm {{ + sei + jsr cx16.joystick_get + cli + }} +} + sub FB_set_pixels_from_buf(uword buffer, uword count) { %asm {{ diff --git a/examples/test.p8 b/examples/test.p8 index 43b4517f6..1baa78128 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,33 +1,17 @@ %import textio +%import gfx2 %zeropage basicsafe main { sub start() { - ubyte xx=9 - ubyte yy=9 - - ; ubyte c_xx = xx+1 - - if xx+1 >= 10 { - txt.print("yes") - } else { - txt.print("error!") - } - if yy+1 >= 10 { - txt.print("yes2") - } else { - txt.print("error2!") + repeat { + sys.waitvsync() + ubyte joy = lsb(cx16.joystick_get2(0)) + txt.print_ubbin(joy,1) + txt.nl() } - if xx+1 >= xx-2 { - txt.print("yes") - } else { - txt.print("error!") - } - if yy+1 >= yy-2 { - txt.print("yes2") - } else { - txt.print("error2!") + repeat { } } }