Fixes #736.
;
READJOY:
+ and #JOY_COUNT-1 ; fix joystick number
+ tax ; Joystick number into X
asl a
asl a
asl a
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
;
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
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
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
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 ;
@SkipY: jsr CDRAW
clc ; Interrupt not "handled"
rts
-
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
cmp old_porta_vbi
beq @L3 ; no motion
+ lda #0
+ sta ATRACT ; disable "attract mode"
; Turn mouse polling IRQ back on
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
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
.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
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
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
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
; -------------------
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
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
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
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
clc ; Interrupt not "handled"
rts
-
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
lda #0 ; Initialize return value
cmp TRIG0,y
bne @notrg
- lda #$10 ; JOY_BTN
+ ora #$10 ; JOY_BTN
; Read joystick
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