-
Notifications
You must be signed in to change notification settings - Fork 0
/
snes_userport.asm
194 lines (149 loc) · 3.09 KB
/
snes_userport.asm
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
; 64tass -D TARGET_C64:=1 snes_userport.asm -o snes-c64.prg
; 64tass -D TARGET_C128:=1 snes_userport.asm -o snes-c128.prg
; 64tass -D TARGET_VIC20:=1 snes_userport.asm -o snes-vic20.prg
; 64tass -D TARGET_PET:=1 snes_userport.asm -o snes-pet.prg
; 64tass -D TARGET_PLUS4:=1 snes_userport.asm -o snes-plus4.prg
TARGET_C64 :?= 0
TARGET_C128 :?= 0
TARGET_VIC20 :?= 0
TARGET_PET :?= 0
TARGET_PLUS4 :?= 0
.if TARGET_C64 || TARGET_C128
; C64 CIA#2 PB
snes_data = $dd01
snes_ddr = $dd03
bit_latch = $20 ; PB5 (user port pin J)
bit_data = $40 ; PB6 (user port pin K)
bit_clock = $08 ; PB3 (user port pin F)
.if TARGET_C64
basic_start = $0801
.endif
.if TARGET_C128
basic_start = $1c01
.endif
snes_state = $fb
counter = $fd
CHROUT = $ffd2
.endif
.if TARGET_VIC20
; VIC-20 VIA#1 PB
snes_data = $9110
snes_ddr = $9112
bit_latch = $20 ; PB5 (user port pin J)
bit_data = $40 ; PB6 (user port pin K)
bit_clock = $08 ; PB3 (user port pin F)
basic_start = $1001 ; (Unexpanded)
; basic_start = $0401 ; (3K Expanded)
; basic_start = $1201 ; (8K and more Expansion)
snes_state = $fb
counter = $fd
CHROUT = $ffd2
.endif
.if TARGET_PET
; PET VIA PA
snes_data = $e841
snes_ddr = $e843
bit_latch = $20 ; PA5 (user port pin J)
bit_data = $40 ; PA6 (user port pin K)
bit_clock = $08 ; PA3 (user port pin F)
basic_start = $0401
snes_state = $5e
counter = $60
CHROUT = $ffd2
.endif
.if TARGET_PLUS4
; PLUS/4 PIO 6529B #1
snes_data = $fd10
snes_ddr = 0
bit_latch = $40 ; P6 (user port pin J)
bit_data = $02 ; P1 (user port pin K)
bit_clock = $80 ; P7 (user port pin F)
basic_start = $1001
snes_state = $61
counter = $63
CHROUT = $ffd2
.endif
* = basic_start
.word (+), 1 ; pointer, line number
.null $9e, format("%4d", start) ; sys xxx
+ .word 0 ; basic line end
start
lda #<labels
ldy #>labels
jsr print
; initialize
.if snes_ddr
lda #$ff - bit_data ; bit_latch|bit_clock
sta snes_ddr
.endif
lda #0
sta snes_data
; main loop
main_loop
jsr read_snes
lda #8
sta counter
ldy #1
ldx #0
- lda #'0'
rol snes_state,x
bcs +
lda #'1'
+ sta state,y
iny
iny
dec counter
bne -
lda #4
sta counter
inx
cpx #2
bne -
lda #<state
ldy #>state
jsr print
jmp main_loop
; A - low byte of address
; Y - high byte of address
print
sta snes_state
sty snes_state + 1
ldy #0
- lda (snes_state),y
beq +
jsr CHROUT
iny
jmp -
+ rts
read_snes
; pulse latch
lda #bit_latch|bit_data
sta snes_data
lda #bit_data
sta snes_data
ldx #0
- ldy #8
; read one bit
- lda snes_data
.if TARGET_PET
and #bit_data
.endif
cmp #bit_data
rol snes_state,x
; pulse clock
lda #bit_clock|bit_data
sta snes_data
lda #bit_data
sta snes_data
; loop for 8 bits
dey
bne -
; loop for 2 bytes
inx
cpx #2
bne --
rts
labels
.null $93,"0 B BUTTON",$0d,"0 Y BUTTON",$0d,"0 SELECT",$0d,"0 START",$0d,"0 DPAD UP",$0d,"0 DPAD DOWN",$0d,"0 DPAD LEFT",$0d,"0 DPAD RIGHT",$0d,"0 A BUTTON",$0d,"0 X BUTTON",$0d,"0 LEFT SHOULDER",$0d,"0 RIGHT SHOULDER",$0d
state
.null $13,"A",$0d,"B",$0d,"C",$0d,"D",$0d,"E",$0d,"F",$0d,"G",$0d,"H",$0d,"I",$0d,"J",$0d,"K",$0d,"L",$0d