-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathread_joy.inc
49 lines (40 loc) · 1.12 KB
/
read_joy.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
; Reads controller
; Out: A=buttons pressed, where bit 0 is A button
read_joy:
;; Strobe controller
lda #1
sta $4016
lda #0
sta $4016
;; Read all 8 buttons
ldx #8
loop:
pha
;; Read next button state and mask off low 2 bits.
;; Compare with $01, which will set carry flag if
;; either or both bits are set.
lda $4016
and #$03
cmp #$01 ; should be 3 for HVC-053?
;; Now, rotate the carry flag into the top of A,
;; land shift all the other buttons to the right
pla
ror a
dex
bne loop
rts
; temp is a zero-page variable
; Reads controller. Reliable when DMC is playing.
; Out: A=buttons held, A button in bit 0
read_joy_safe:
;; Get first reading
jsr read_joy
mismatch:
;; Save previous reading
sta joytmp1
;; Read again and compare. If they differ,
;; read again.
jsr read_joy
cmp joytmp1
bne mismatch
rts