workaround for the joystick_get() irq problem

This commit is contained in:
Irmen de Jong 2021-04-15 22:56:52 +02:00
parent 56fec674c5
commit e680de05ea
2 changed files with 18 additions and 24 deletions

View File

@ -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 {{

View File

@ -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 {
}
}
}