-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcommand_mlt_req.asm
259 lines (208 loc) · 4.57 KB
/
command_mlt_req.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
RESULTS_START EQU $c000
RESULTS_N_ROWS EQU 3
include "base.inc"
; This test verifies how SGB command MLT_REQ works
SgbPacket: MACRO
push hl
ld hl, \1
call SendSgbPacket
pop hl
ENDM
CorrectResults:
db $FF, $FE, $FF, $FF, $FF, $FF, $FE, $FD
db $FC, $FE, $FF, $FE, $FF, $FF, $FD, $FD
db $FD, $FF, $FF, $FD, $FD, $FD, $FD, $FF
RunTest:
ld de, $c000
; Initial value always reads out as controller 1
SgbPacket MLT_REQ_1
ldh a, [rP1]
call StoreResult
; Check that incrementing works as expected
call Increment
ldh a, [rP1]
call StoreResult
; Test to see if the controller value is reset by going back to 1 player
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_1
ldh a, [rP1]
call StoreResult
; Test to see the controller value in unsupported MLT_REQ 2
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_2
ldh a, [rP1]
call StoreResult
call Increment
ldh a, [rP1]
call StoreResult
; Test to see the controller order in MLT_REQ 3
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
ldh a, [rP1]
call StoreResult
call Increment
ldh a, [rP1]
call StoreResult
call Increment
ldh a, [rP1]
call StoreResult
call Increment
ldh a, [rP1]
call StoreResult
; Test if switching from 3 to 1 retains any state
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
SgbPacket MLT_REQ_1 ; Each of these increments the player 5 times before it gets ANDed
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
SgbPacket MLT_REQ_1
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
call Increment
SgbPacket MLT_REQ_1
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
call Increment
call Increment
SgbPacket MLT_REQ_1
ldh a, [rP1]
call StoreResult
; Test how many times sending a packet increments
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_3 ; This should increment the player 6 times before it gets ANDed
ldh a, [rP1]
call StoreResult
; Test if invalid mode 2 has a glitched player 3
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
SgbPacket MLT_REQ_2 ; This should increment the player 5 times
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
SgbPacket MLT_REQ_2
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
call Increment
SgbPacket MLT_REQ_2
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
call Increment
call Increment
SgbPacket MLT_REQ_2
ldh a, [rP1]
call StoreResult
; Test if incrementing within the glitched mode works
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
SgbPacket MLT_REQ_2
call Increment
ldh a, [rP1]
call StoreResult
call Increment
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
SgbPacket MLT_REQ_2
call Increment
ldh a, [rP1]
call StoreResult
call Increment
ldh a, [rP1]
call StoreResult
SgbPacket MLT_REQ_0
SgbPacket MLT_REQ_3
call Increment
call Increment
SgbPacket MLT_REQ_2
call Increment
ldh a, [rP1]
call StoreResult
ret
SendSgbPacket:
push bc
push de
ld d, 16
; Reset packet buffer
xor a
ldh [rP1], a
ld a, $30
ldh [rP1], a
.sgbByte:
ld a, [hl+] ; Load next byte
ld c, 8
ld b, a
.sgbByteLoop:
ld a, $10
bit 0, b
jr nz, .sgbBit
sla a
.sgbBit:
ldh [rP1], a
ld a, $30
ldh [rP1], a
srl b
dec c
jr nz, .sgbByteLoop
dec d
jr nz, .sgbByte
; Terminate packet
ld a, $20
ldh [rP1], a
ld a, $30
ldh [rP1], a
pop de
pop bc
SgbWait:
push de
ld de, 7000
.waitloop:
nop
nop
nop
dec de
ld a, e
or d
jr nz, .waitloop
pop de
ret
Increment:
ld a, $10
ldh [rP1], a
ld a, $30
ldh [rP1], a
ret
StoreResult::
ld [de], a
inc de
ret
MLT_REQ_0:
db $89, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
MLT_REQ_1:
db $89, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
MLT_REQ_2:
db $89, $02, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
MLT_REQ_3:
db $89, $03, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
SGB_MODE