From d199ca14602d3fe9bceb74dcabcdbfaa16726f99 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 4 Sep 2018 23:08:38 +0200 Subject: [PATCH] Atari, Atari5200: disable "attract mode" on mouse or joystick input Fixes #736. --- libsrc/atari/joy/atrmj8.s | 13 +++++++- libsrc/atari/joy/atrstd.s | 15 ++++++++-- libsrc/atari/mou/atrjoy.s | 20 +++++++++++-- libsrc/atari/mou/atrst.s | 38 +++++++++++++++-------- libsrc/atari/mou/atrtt.s | 50 ++++++++++++++++++------------- libsrc/atari5200/joy/atr5200std.s | 16 ++++++++-- 6 files changed, 111 insertions(+), 41 deletions(-) diff --git a/libsrc/atari/joy/atrmj8.s b/libsrc/atari/joy/atrmj8.s index 9b02485d6..3a26c381d 100644 --- a/libsrc/atari/joy/atrmj8.s +++ b/libsrc/atari/joy/atrmj8.s @@ -95,6 +95,8 @@ COUNT: ; READJOY: + and #JOY_COUNT-1 ; fix joystick number + tax ; Joystick number into X asl a asl a asl a @@ -110,5 +112,14 @@ READJOY: asl a ora PORTA ; add position information eor #$1F - ldx #0 ; fix X + cmp oldval,x + beq :+ + sta oldval,x + ldx #0 + stx ATRACT ; we have interaction, disable "attract mode" +: ldx #0 ; fix X rts + + .bss + +oldval: .res JOY_COUNT diff --git a/libsrc/atari/joy/atrstd.s b/libsrc/atari/joy/atrstd.s index 0c49499f8..fd1d99d31 100644 --- a/libsrc/atari/joy/atrstd.s +++ b/libsrc/atari/joy/atrstd.s @@ -93,8 +93,8 @@ _400800: ; READJOY: - and #3 ; fix joystick number - tax ; Joystick number (0-3) into X + and #JOY_COUNT-1 ; fix joystick number + tax ; Joystick number into X ; Read joystick @@ -105,5 +105,14 @@ READJOY: asl a ora STICK0,x ; add position information eor #$1F - ldx #0 ; fix X + cmp oldval,x + beq :+ + sta oldval,x + ldx #0 + stx ATRACT ; we have interaction, disable "attract mode" +: ldx #0 ; fix X rts + + .bss + +oldval: .res JOY_COUNT diff --git a/libsrc/atari/mou/atrjoy.s b/libsrc/atari/mou/atrjoy.s index 7f1085fb8..3ea428576 100644 --- a/libsrc/atari/mou/atrjoy.s +++ b/libsrc/atari/mou/atrjoy.s @@ -89,6 +89,8 @@ YMin: .res 2 ; Y1 value of bounding box XMax: .res 2 ; X2 value of bounding box YMax: .res 2 ; Y2 value of bounding box Buttons: .res 1 ; Button mask +OldDir: .res 1 ; previous direction bits +OldButton: .res 1 ; previous buttons Temp: .res 1 ; Temporary value used in the int handler @@ -336,9 +338,24 @@ IRQ: jsr CPREP +; Check if user activity occurred, and if yes, disable "attract mode" + + lda Buttons + cmp OldButton + beq @ChkDir + sta OldButton + lda #0 + sta ATRACT ; disable "attract mode" +@ChkDir:lda Temp + cmp OldDir + beq @ChkCnt + sta OldDir + lda #0 + sta ATRACT + ; Check left/right - lda Temp ; Read joystick #0 +@ChkCnt:lda Temp ; Read joystick #0 and #(JOY::LEFT | JOY::RIGHT) beq @SkipX ; @@ -437,4 +454,3 @@ IRQ: @SkipY: jsr CDRAW clc ; Interrupt not "handled" rts - diff --git a/libsrc/atari/mou/atrst.s b/libsrc/atari/mou/atrst.s index 17d2affb5..f8ba24551 100644 --- a/libsrc/atari/mou/atrst.s +++ b/libsrc/atari/mou/atrst.s @@ -126,6 +126,7 @@ YMin: .res 2 ; Y1 value of bounding box XMax: .res 2 ; X2 value of bounding box YMax: .res 2 ; Y2 value of bounding box Buttons: .res 1 ; Button mask +OldButton: .res 1 ; previous buttons XPosWrk: .res 2 YPosWrk: .res 2 @@ -496,6 +497,8 @@ IRQ: lda PORTA ; mouse port contents cmp old_porta_vbi beq @L3 ; no motion + lda #0 + sta ATRACT ; disable "attract mode" ; Turn mouse polling IRQ back on @@ -544,25 +547,34 @@ IRQ: lda PORTA ; mouse port contents jsr CPREP +; Disable "attract mode" if button status has changed + + lda Buttons + cmp OldButton + beq @L5 + sta OldButton + lda #0 + sta ATRACT + ; Limit the X coordinate to the bounding box - lda XPosWrk+1 +@L5: lda XPosWrk+1 ldy XPosWrk tax cpy XMin sbc XMin+1 - bpl @L5 + bpl @L6 ldy XMin ldx XMin+1 - jmp @L6 + jmp @L7 -@L5: txa +@L6: txa cpy XMax sbc XMax+1 - bmi @L6 + bmi @L7 ldy XMax ldx XMax+1 -@L6: sty XPos +@L7: sty XPos stx XPos+1 tya jsr CMOVEX @@ -574,18 +586,18 @@ IRQ: lda PORTA ; mouse port contents tax cpy YMin sbc YMin+1 - bpl @L7 + bpl @L8 ldy YMin ldx YMin+1 - jmp @L8 + jmp @L9 -@L7: txa +@L8: txa cpy YMax sbc YMax+1 - bmi @L8 + bmi @L9 ldy YMax ldx YMax+1 -@L8: sty YPos +@L9: sty YPos stx YPos+1 tya jsr CMOVEY @@ -595,10 +607,10 @@ IRQ: lda PORTA ; mouse port contents .ifdef DEBUG ; print on upper right corner 'E' or 'D', indicating the IRQ is enabled or disabled ldy irq_enabled - beq @L9 + beq @L10 lda #37 ; screen code for 'E' .byte $2c ; bit opcode, eats next 2 bytes -@L9: lda #36 ; screen code for 'D' +@L10: lda #36 ; screen code for 'D' ldy #39 sta (SAVMSC),y .endif diff --git a/libsrc/atari/mou/atrtt.s b/libsrc/atari/mou/atrtt.s index f1f2cde63..61963aa61 100644 --- a/libsrc/atari/mou/atrtt.s +++ b/libsrc/atari/mou/atrtt.s @@ -88,6 +88,7 @@ YMin: .res 2 ; Y1 value of bounding box XMax: .res 2 ; X2 value of bounding box YMax: .res 2 ; Y2 value of bounding box Buttons: .res 1 ; Button mask +OldButton: .res 1 ; previous buttons ; Default values for above variables @@ -337,10 +338,19 @@ IRQ: ora Buttons sta Buttons +; Check if button status changed, and disable "attract mode" if yes + +@L02: lda Buttons + cmp OldButton + beq @L03 + sta OldButton + lda #0 + sta ATRACT + ; If we read 228 for X or Y positions, we assume the user has lifted the pen ; and don't change the cursor position. -@L02: lda PADDL0 +@L03: lda PADDL0 cmp #228 beq @Cont ; CF set if equal lda PADDL1 @@ -350,12 +360,13 @@ IRQ: jsr CPREP plp ; restore CF - bcc @L03 + bcc @L04 jmp @Show -@L03: ldx #0 +@L04: ldx #0 stx XPos+1 stx YPos+1 + stx ATRACT ; disable "attract mode" ; Get cursor position ; ------------------- @@ -382,9 +393,9 @@ IRQ: clc adc XPos sta XPos - bcc @L04 + bcc @L05 inc XPos+1 -@L04: txa +@L05: txa lsr a ; port value / 4 lsr a ; port value / 8 tax @@ -393,18 +404,18 @@ IRQ: stx XPos sbc XPos sta XPos - bcs @L05 + bcs @L06 dec XPos+1 -@L05: txa +@L06: txa lsr a ; port value / 16 lsr a ; port value / 32 clc adc XPos sta XPos - bcc @L06 + bcc @L07 inc XPos+1 -@L06: tay +@L07: tay lda XPos+1 tax @@ -412,18 +423,18 @@ IRQ: cpy XMin sbc XMin+1 - bpl @L07 + bpl @L08 ldy XMin ldx XMin+1 - jmp @L08 -@L07: txa + jmp @L09 +@L08: txa cpy XMax sbc XMax+1 - bmi @L08 + bmi @L09 ldy XMax ldx XMax+1 -@L08: sty XPos +@L09: sty XPos stx XPos+1 ; Move the mouse pointer to the new X pos @@ -456,18 +467,18 @@ IRQ: cpy YMin sbc YMin+1 - bpl @L09 + bpl @L10 ldy YMin ldx YMin+1 - jmp @L10 -@L09: txa + jmp @L11 +@L10: txa cpy YMax sbc YMax+1 - bmi @L10 + bmi @L11 ldy YMax ldx YMax+1 -@L10: sty YPos +@L11: sty YPos stx YPos+1 ; Move the mouse pointer to the new X pos @@ -479,4 +490,3 @@ IRQ: clc ; Interrupt not "handled" rts - diff --git a/libsrc/atari5200/joy/atr5200std.s b/libsrc/atari5200/joy/atr5200std.s index 002ffdaaf..989bc5ee0 100644 --- a/libsrc/atari5200/joy/atr5200std.s +++ b/libsrc/atari5200/joy/atr5200std.s @@ -82,6 +82,7 @@ SENSIVITY = 16 READJOY: and #3 ; put joystick number in range, just in case + sta jsnum ; remember joystick number tay asl a tax ; Joystick number * 2 (0-6) into X, index into ZP shadow registers @@ -89,7 +90,7 @@ READJOY: lda #0 ; Initialize return value cmp TRIG0,y bne @notrg - lda #$10 ; JOY_BTN + ora #$10 ; JOY_BTN ; Read joystick @@ -119,4 +120,15 @@ READJOY: ora #2 ; JOY_DOWN -@done: rts +@done: ldx #0 + ldy jsnum + cmp oldval,y + beq @ret + sta oldval,y + stx ATRACT +@ret: rts + +.bss + +oldval:.res 4 +jsnum: .res 1 -- 2.39.5