-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathneoyume_input.spin2
143 lines (123 loc) · 4.12 KB
/
neoyume_input.spin2
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
CON ' Header
''
'' ### ### ######### ###### ##### ### #### ### ### ### #########
'' ### # ## # ## ## ## # ## # ### ### ## #
'' # ## # ## # ## ## # ## # ## # # ## # ## ## #
'' # ## # ##### ### ### ### ## # ## # # ## # ## #####
'' # ## # ## # ## ## # ## ## # # ## # ## ## #
'' # ### ## # ## ## ## ## # # ### ## ## #
'' ### ### ######### ###### #### #### ### # #### #########
''
'' MAX 256 MEGA
'' PROP-GEAR SPEC
''
#include "config.spin2"
OBJ
#ifdef INPUT_USE_USB
'' We try to positionally match the NeoGeo mini controller (NESW is CDBA)
'' Therefore, A = BT3, B = BT2, C = BT0 or BT6, D = BT1 or BT7
usb: "usbnew" | ACTIVITY_LED = -1, ERROR_LED = -1, USB_BASE_PIN = USB0_BASEPIN, USB_ENABLE_OFFSET = ENABLE_PIN, USB_DMINUS_OFFSET = DM_PIN, ...
OVERLAP_MEMORY = true, ...
EMUPAD_MAX_PLAYER = 2, EMUPAD_BUILTIN_RULES = true, ...
EMUPAD_UP_BIT = 0,EMUPAD_DOWN_BIT = 1,EMUPAD_LEFT_BIT = 2,EMUPAD_RIGHT_BIT = 3, ...
EMUPAD_BT0_BIT = 6, EMUPAD_BT1_BIT = 7, EMUPAD_BT2_BIT = 5, EMUPAD_BT3_BIT = 4, ...
EMUPAD_BT4_BIT = -1, EMUPAD_BT5_BIT = -1, EMUPAD_BT6_BIT = 6, EMUPAD_BT7_BIT = 7, ...
EMUPAD_BT8_BIT = 9, EMUPAD_BT9_BIT = 8, ...
EMUPAD_KB_BT0 = $06, EMUPAD_KB_BT1 = $19, EMUPAD_KB_BT2 = $1B, EMUPAD_KB_BT3 = $1D, ...
EMUPAD_KB_BT4 = 0, EMUPAD_KB_BT5 = 0, EMUPAD_KB_BT6 = 0, EMUPAD_KB_BT7 = 0, ...
EMUPAD_KB_BT8 = $2A, EMUPAD_KB_BT9 = $28
#endif
PUB main() | i,p,data,tmp
#ifdef INPUT_USE_USB
long[$6C] := usb.EMUPAD_MAX_RULES
long[$68] := usb.get_emupad_rule_buffer()
repeat while long[$68]
usb.set_emupad_ptr($60)
usb.start()
cogstop(cogid)
#endif
#ifdef INPUT_USE_PINS
repeat i from 0 to 31
if (p:=pin_table[i]) +< 64
wrpin(p,PINPUT_PINMODE)
pinh(p)
repeat
data := 0
repeat i from 0 to 31
if (p:=pin_table[i]) +< 64
data.[i] := pinr(p)
'pinw(p-4,data.[i])
long[$60] := data.word[0]
long[$64] := data.word[1]
#endif
#ifdef INPUT_USE_SNES
pinl(SNES_LATCH)
pinh(SNES_CLK)
waitus(5)
repeat
tmp := 0
pinh(SNES_LATCH)
waitus(5)
pinl(SNES_LATCH)
waitus(5)
repeat 16
tmp := tmp<<1 | pinr(SNES_PLAYER1)<<16 | pinr(SNES_PLAYER2)
pinl(SNES_CLK)
waitus(5)
pinh(SNES_CLK)
waitus(5)
tmp := !tmp rev 31
data.word[0] := snes_buttonmap(tmp.word[0])
data.word[1] := snes_buttonmap(tmp.word[1])
long[$60] := data.word[0]
long[$64] := data.word[1]
waitms(1) ' idle time
#endif
DAT
#ifdef INPUT_USE_PINS
pin_table byte
byte PINPUT_P1_UP,PINPUT_P1_DOWN,PINPUT_P1_LEFT,PINPUT_P1_RIGHT
byte PINPUT_P1_A,PINPUT_P1_B,PINPUT_P1_C,PINPUT_P1_D
byte PINPUT_P1_START,PINPUT_P1_SELECT
byte -1[6]
byte PINPUT_P2_UP,PINPUT_P2_DOWN,PINPUT_P2_LEFT,PINPUT_P2_RIGHT
byte PINPUT_P2_A,PINPUT_P2_B,PINPUT_P2_C,PINPUT_P2_D
byte PINPUT_P2_START,PINPUT_P2_SELECT
byte -1[6]
#endif
PRI snes_buttonmap(in) : out
out := 0
out.[0..3] := in.[4..7] ' directions
out.[8] := in.[3] ' Start
out.[9] := in.[2] ' Select
#ifdef SNES_LAYOUT_MINI_POSITIONAL
' NeoGeo Mini positional equivalent
out.[4] := in.[1] ' Y -> A
out.[5] := in.[0] ' B -> B
out.[6] := in.[9] ' X -> C
out.[7] := in.[8] ' A -> D
#elseifdef SNES_LAYOUT_ARCADE_POSITIONAL
' SNES Arcade style layout
' B C D
' A x x
out.[4] := in.[ 1] ' Y -> A
out.[5] := in.[10] ' L -> B
out.[6] := in.[ 9] ' X -> C
out.[7] := in.[11] ' R -> D
#elseifdef SNES_LAYOUT_LETTERS
' Letter matched layout
out.[4] := in.[8] ' A -> A
out.[5] := in.[0] ' B -> B
out.[6] := in.[9] ' X -> C
out.[7] := in.[1] ' Y -> D
#elseifdef SNES_LAYOUT_COLORS
' Color matched layout
out.[4] := in.[0] ' B -> A
out.[5] := in.[8] ' A -> B
out.[6] := in.[1] ' Y -> C
out.[7] := in.[9] ' X -> D
#else
#ifdef INPUT_USE_SNES
#error "No SNES layout map selected"
#endif
#endif