-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterrupt.s
86 lines (70 loc) · 1.36 KB
/
interrupt.s
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
; ---------------------------------------------------------------------------
; interrupt.s
; ---------------------------------------------------------------------------
;
; Interrupt handler.
.export _irq, _nmi
.import _button1PressEvt
.import _button1
.import _manual_NMI
.segment "CODE"
.PC02 ; Force 65C02 assembly mode
buttons_1 = $00A0
; ---------------------------------------------------------------------------
; Maskable interrupt (IRQ) service routine
_irq:
rti
_nmi:
pha
tya
pha
txa
pha
lda #$00
sta $2005
sta $2005
jsr readjoy
lda buttons_1
ldx $A1
inx
cpx #$0A
bcs @SampleButtonResetCounter
stx $A1
jmp @exitNMI
@SampleButtonResetCounter:
ldx #$00
stx $A1
lda buttons_1
cmp #$00
bne @buttonPressed
jmp @exitNMI
@buttonPressed:
lda #$01
sta _button1PressEvt
lda buttons_1
sta _button1
jmp @exitNMI
@exitNMI:
lda #$01
sta _manual_NMI
pla
tax
pla
tay
pla
rti
; https://www.nesdev.org/wiki/Controller_reading_code
; readjoy:
; returns result to buttons_1:
readjoy:
lda #$01
sta $4016
sta buttons_1
lsr a
sta $4016
@loop:
lda $4016
lsr a
rol buttons_1
bcc @loop
rts