/
dualshock.cpp
1133 lines (966 loc) · 33.6 KB
/
dualshock.cpp
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Mednafen - Multi-system Emulator
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../psx.h"
#include "../frontio.h"
#include "dualshock.h"
#include "../../mednafen.h"
#include "../../mednafen-endian.h"
/*
TODO:
If we ever call Update() more than once per video frame(IE 50/60Hz), we'll need to add debounce logic to the analog mode button evaluation code.
*/
/* Notes:
Both DA and DS style rumblings work in both analog and digital modes.
Regarding getting Dual Shock style rumble working, Sony is evil and/or mean. The owl tells me to burn Sony with boiling oil.
To enable Dual Shock-style rumble, the game has to at least enter MAD MUNCHKINS MODE with command 0x43, and send the appropriate data(not the actual rumble type data per-se)
with command 0x4D.
DualAnalog-style rumble support seems to be borked until power loss if MAD MUNCHKINS MODE is even entered once...investigate further.
Command 0x44 in MAD MUNCHKINS MODE can turn on/off analog mode(and the light with it).
Command 0x42 in MAD MUNCHKINS MODE will return the analog mode style gamepad data, even when analog mode is off. In combination with command 0x44, this could hypothetically
be used for using the light in the gamepad as some kind of game mechanic).
Dual Analog-style rumble notes(some of which may apply to DS too):
Rumble appears to stop if you hold DTR active(TODO: for how long? instant?). (TODO: investigate if it's still stopped even if a memory card device number is sent. It may be, since rumble may
cause excessive current draw in combination with memory card access)
Rumble will work even if you interrupt the communication process after you've sent the rumble data(via command 0x42).
Though if you interrupt it when you've only sent partial rumble data, dragons will eat you and I don't know(seems to have timing-dependent or random effects or something;
based on VERY ROUGH testing).
*/
class InputDevice_DualShock : public InputDevice
{
public:
InputDevice_DualShock(const std::string &arg_name);
virtual ~InputDevice_DualShock();
virtual void Power(void);
virtual int StateAction(StateMem* sm, int load, int data_only, const char* section_name);
virtual void Update(const int32_t timestamp);
virtual void ResetTS(void);
virtual void UpdateInput(const void *data);
virtual void SetAMCT(bool enabled);
//
//
//
virtual void SetDTR(bool new_dtr);
virtual bool GetDSR(void);
virtual bool Clock(bool TxD, int32 &dsr_pulse_delay);
private:
void CheckManualAnaModeChange(void);
//
//
bool cur_ana_button_state;
bool prev_ana_button_state;
int64 combo_anatoggle_counter;
//
bool da_rumble_compat;
bool analog_mode;
bool analog_mode_locked;
bool mad_munchkins;
uint8 rumble_magic[6];
uint8 rumble_param[2];
bool dtr;
uint8 buttons[2];
uint8 axes[2][2];
int32 command_phase;
uint32 bitpos;
uint8 receive_buffer;
uint8 command;
uint8 transmit_buffer[8];
uint32 transmit_pos;
uint32 transmit_count;
//
//
//
bool am_prev_info;
bool aml_prev_info;
std::string gp_name;
int32_t lastts;
//
//
bool amct_enabled;
};
InputDevice_DualShock::InputDevice_DualShock(const std::string &name)
{
gp_name = name;
Power();
am_prev_info = analog_mode;
aml_prev_info = analog_mode_locked;
amct_enabled = false;
}
InputDevice_DualShock::~InputDevice_DualShock()
{
}
void InputDevice_DualShock::Update(const int32_t timestamp)
{
lastts = timestamp;
}
void InputDevice_DualShock::ResetTS(void)
{
//printf("%lld\n", combo_anatoggle_counter);
if(combo_anatoggle_counter >= 0)
combo_anatoggle_counter += lastts;
lastts = 0;
}
#ifdef __LIBRETRO__
extern bool setting_apply_analog_default;
#endif
void InputDevice_DualShock::SetAMCT(bool enabled)
{
bool amct_prev_info = amct_enabled;
amct_enabled = enabled;
if(amct_enabled)
analog_mode = setting_apply_analog_default;
else
analog_mode = true;
if (amct_prev_info == analog_mode && amct_prev_info == amct_enabled)
return;
am_prev_info = analog_mode;
MDFN_DispMessage(2, RETRO_LOG_INFO,
RETRO_MESSAGE_TARGET_OSD, RETRO_MESSAGE_TYPE_NOTIFICATION_ALT,
"%s: Analog toggle is %s, sticks are %s",
gp_name.c_str(), amct_enabled ? "ENABLED" : "DISABLED", analog_mode ? "ON" : "OFF");
}
//
// This simulates the behavior of the actual DualShock(analog toggle button evaluation is suspended while DTR is active).
// Call in Update(), and whenever dtr goes inactive in the port access code.
void InputDevice_DualShock::CheckManualAnaModeChange(void)
{
if(!dtr)
{
bool need_mode_toggle = false;
if(amct_enabled)
{
if(buttons[0] == analog_combo[0] && buttons[1] == analog_combo[1])
{
if(combo_anatoggle_counter == -1)
combo_anatoggle_counter = 0;
else if(combo_anatoggle_counter >= (44100 * (768 * HOLD)))
{
need_mode_toggle = true;
combo_anatoggle_counter = -2;
}
}
else
combo_anatoggle_counter = -1;
}
else
{
combo_anatoggle_counter = -1;
if(cur_ana_button_state && (cur_ana_button_state != prev_ana_button_state))
{
need_mode_toggle = true;
}
}
if(need_mode_toggle)
{
if(analog_mode_locked)
MDFN_DispMessage(2, RETRO_LOG_INFO,
RETRO_MESSAGE_TARGET_OSD, RETRO_MESSAGE_TYPE_NOTIFICATION_ALT,
"%s: Analog toggle is DISABLED, sticks are %s",
gp_name.c_str(), analog_mode ? "ON" : "OFF");
else
analog_mode = !analog_mode;
}
prev_ana_button_state = cur_ana_button_state; // Don't move this outside of the if(!dtr) block!
}
}
void InputDevice_DualShock::Power(void)
{
combo_anatoggle_counter = -2;
lastts = 0;
//
//
dtr = 0;
buttons[0] = buttons[1] = 0;
command_phase = 0;
bitpos = 0;
receive_buffer = 0;
command = 0;
memset(transmit_buffer, 0, sizeof(transmit_buffer));
transmit_pos = 0;
transmit_count = 0;
analog_mode = true;
analog_mode_locked = false;
mad_munchkins = false;
memset(rumble_magic, 0xFF, sizeof(rumble_magic));
memset(rumble_param, 0, sizeof(rumble_param));
da_rumble_compat = true;
prev_ana_button_state = false;
}
int InputDevice_DualShock::StateAction(StateMem* sm, int load, int data_only, const char* section_name)
{
SFORMAT StateRegs[] =
{
SFVAR(cur_ana_button_state),
SFVAR(prev_ana_button_state),
SFVAR(combo_anatoggle_counter),
SFVAR(da_rumble_compat),
SFVAR(analog_mode),
SFVAR(analog_mode_locked),
SFVAR(mad_munchkins),
SFARRAY(rumble_magic, sizeof(rumble_magic)),
SFARRAY(rumble_param, sizeof(rumble_param)),
SFVAR(dtr),
SFARRAY(buttons, sizeof(buttons)),
SFARRAY(&axes[0][0], sizeof(axes)),
SFVAR(command_phase),
SFVAR(bitpos),
SFVAR(receive_buffer),
SFVAR(command),
SFARRAY(transmit_buffer, sizeof(transmit_buffer)),
SFVAR(transmit_pos),
SFVAR(transmit_count),
SFEND
};
int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, section_name);
if(load)
{
if(((uint64_t)transmit_pos + transmit_count) > sizeof(transmit_buffer))
{
transmit_pos = 0;
transmit_count = 0;
}
}
return(ret);
}
void InputDevice_DualShock::UpdateInput(const void *data)
{
uint8 *d8 = (uint8 *)data;
uint8* const rumb_dp = &d8[3 + 16];
buttons[0] = d8[0];
buttons[1] = d8[1];
cur_ana_button_state = d8[2] & 0x01;
for(int stick = 0; stick < 2; stick++)
{
for(int axis = 0; axis < 2; axis++)
{
const uint8* aba = &d8[3] + stick * 8 + axis * 4;
int32 tmp;
//revert to 0.9.33, should be fixed on libretro side instead
//tmp = 32767 + MDFN_de16lsb(&aba[0]) - MDFN_de16lsb(&aba[2]);
//tmp = (tmp * 0x100) / 0xFFFF;
tmp = 32768 + MDFN_de32lsb<false>((const uint8 *)data + stick * 16 + axis * 8 + 4) - ((int32)MDFN_de32lsb<false>((const uint8 *)data + stick * 16 + axis * 8 + 8) * 32768 / 32767);
tmp >>= 8;
axes[stick][axis] = tmp;
}
}
//printf("%3d:%3d, %3d:%3d\n", axes[0][0], axes[0][1], axes[1][0], axes[1][1]);
//printf("RUMBLE: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", rumble_magic[0], rumble_magic[1], rumble_magic[2], rumble_magic[3], rumble_magic[4], rumble_magic[5]);
//printf("%d, 0x%02x 0x%02x\n", da_rumble_compat, rumble_param[0], rumble_param[1]);
if(da_rumble_compat == false)
{
uint8 sneaky_weaky = 0;
if(rumble_param[0] == 0x01)
sneaky_weaky = 0xFF;
//revert to 0.9.33, should be fixed on libretro side instead
//MDFN_en16lsb(rumb_dp, (sneaky_weaky << 0) | (rumble_param[1] << 8));
MDFN_en32lsb<false>(&d8[4 + 32 + 0], (sneaky_weaky << 0) | (rumble_param[1] << 8));
}
else
{
uint8 sneaky_weaky = 0;
if(((rumble_param[0] & 0xC0) == 0x40) && ((rumble_param[1] & 0x01) == 0x01))
sneaky_weaky = 0xFF;
//revert to 0.9.33, should be fixed on libretro side instead
//MDFN_en16lsb(rumb_dp, sneaky_weaky << 0);
MDFN_en32lsb<false>(&d8[4 + 32 + 0], sneaky_weaky << 0);
}
//printf("%d %d %d %d\n", axes[0][0], axes[0][1], axes[1][0], axes[1][1]);
//
//
//
CheckManualAnaModeChange();
if(am_prev_info != analog_mode || aml_prev_info != analog_mode_locked)
MDFN_DispMessage(2, RETRO_LOG_INFO,
RETRO_MESSAGE_TARGET_OSD, RETRO_MESSAGE_TYPE_NOTIFICATION_ALT,
"%s: Analog toggle is %s, sticks are %s",
gp_name.c_str(), amct_enabled ? "ENABLED" : "DISABLED", analog_mode ? "ON" : "OFF");
aml_prev_info = analog_mode_locked;
am_prev_info = analog_mode;
}
void InputDevice_DualShock::SetDTR(bool new_dtr)
{
const bool old_dtr = dtr;
dtr = new_dtr; // Set it to new state before we call CheckManualAnaModeChange().
if(!old_dtr && dtr)
{
command_phase = 0;
bitpos = 0;
transmit_pos = 0;
transmit_count = 0;
}
else if(old_dtr && !dtr)
{
CheckManualAnaModeChange();
//if(bitpos || transmit_count)
// printf("[PAD] Abort communication!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
}
}
bool InputDevice_DualShock::GetDSR(void)
{
if(!dtr)
return(0);
if(!bitpos && transmit_count)
return(1);
return(0);
}
bool InputDevice_DualShock::Clock(bool TxD, int32 &dsr_pulse_delay)
{
bool ret = 1;
dsr_pulse_delay = 0;
if(!dtr)
return(1);
if(transmit_count)
ret = (transmit_buffer[transmit_pos] >> bitpos) & 1;
receive_buffer &= ~(1 << bitpos);
receive_buffer |= TxD << bitpos;
bitpos = (bitpos + 1) & 0x7;
if(!bitpos)
{
//if(command == 0x44)
//if(command == 0x4D) //mad_munchkins) // || command == 0x43)
// fprintf(stderr, "[PAD] Receive: %02x -- command=%02x, command_phase=%d, transmit_pos=%d\n", receive_buffer, command, command_phase, transmit_pos);
if(transmit_count)
{
transmit_pos++;
transmit_count--;
}
switch(command_phase)
{
case 0:
if(receive_buffer != 0x01)
command_phase = -1;
else
{
if(mad_munchkins)
{
transmit_buffer[0] = 0xF3;
transmit_pos = 0;
transmit_count = 1;
command_phase = 101;
}
else
{
transmit_buffer[0] = analog_mode ? 0x73 : 0x41;
transmit_pos = 0;
transmit_count = 1;
command_phase++;
}
}
break;
case 1:
command = receive_buffer;
command_phase++;
transmit_buffer[0] = 0x5A;
//fprintf(stderr, "Gamepad command: 0x%02x\n", command);
//if(command != 0x42 && command != 0x43)
// fprintf(stderr, "Gamepad unhandled command: 0x%02x\n", command);
if(command == 0x42)
{
transmit_buffer[0] = 0x5A;
transmit_pos = 0;
transmit_count = 1;
command_phase = (command << 8) | 0x00;
}
else if(command == 0x43)
{
transmit_pos = 0;
if(analog_mode)
{
transmit_buffer[1] = 0xFF ^ buttons[0];
transmit_buffer[2] = 0xFF ^ buttons[1];
transmit_buffer[3] = axes[0][0];
transmit_buffer[4] = axes[0][1];
transmit_buffer[5] = axes[1][0];
transmit_buffer[6] = axes[1][1];
transmit_count = 7;
}
else
{
transmit_buffer[1] = 0xFF ^ buttons[0];
transmit_buffer[2] = 0xFF ^ buttons[1];
transmit_count = 3;
}
}
else
{
command_phase = -1;
transmit_buffer[1] = 0;
transmit_buffer[2] = 0;
transmit_pos = 0;
transmit_count = 0;
}
break;
case 2:
{
if(command == 0x43 && transmit_pos == 2 && (receive_buffer == 0x01))
{
//fprintf(stderr, "Mad Munchkins mode entered!\n");
mad_munchkins = true;
if(da_rumble_compat)
{
rumble_param[0] = 0;
rumble_param[1] = 0;
da_rumble_compat = false;
}
command_phase = -1;
}
}
break;
case 101:
command = receive_buffer;
//fprintf(stderr, "Mad Munchkins DualShock command: 0x%02x\n", command);
if(command >= 0x40 && command <= 0x4F)
{
transmit_buffer[0] = 0x5A;
transmit_pos = 0;
transmit_count = 1;
command_phase = (command << 8) | 0x00;
}
else
{
transmit_count = 0;
command_phase = -1;
}
break;
/************************/
/* MMMode 1, Command 0x40 */
/************************/
case 0x4000:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4001:
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x41 */
/************************/
case 0x4100:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4101:
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/**************************/
/* MMMode 0&1, Command 0x42 */
/**************************/
case 0x4200:
transmit_pos = 0;
if(analog_mode || mad_munchkins)
{
transmit_buffer[0] = 0xFF ^ buttons[0];
transmit_buffer[1] = 0xFF ^ buttons[1];
transmit_buffer[2] = axes[0][0];
transmit_buffer[3] = axes[0][1];
transmit_buffer[4] = axes[1][0];
transmit_buffer[5] = axes[1][1];
transmit_count = 6;
}
else
{
transmit_buffer[0] = 0xFF ^ buttons[0];
transmit_buffer[1] = 0xFF ^ buttons[1];
transmit_count = 2;
if(!(rumble_magic[2] & 0xFE))
{
transmit_buffer[transmit_count++] = 0x00;
transmit_buffer[transmit_count++] = 0x00;
}
}
command_phase++;
break;
case 0x4201: // Weak(in DS mode)
if(da_rumble_compat)
rumble_param[0] = receive_buffer;
// Dualshock weak
else if(rumble_magic[0] == 0x00 && rumble_magic[2] != 0x00 && rumble_magic[3] != 0x00 && rumble_magic[4] != 0x00 && rumble_magic[5] != 0x00)
rumble_param[0] = receive_buffer;
command_phase++;
break;
case 0x4202:
if(da_rumble_compat)
rumble_param[1] = receive_buffer;
else if(rumble_magic[1] == 0x01) // DualShock strong
rumble_param[1] = receive_buffer;
else if(rumble_magic[1] == 0x00 && rumble_magic[2] != 0x00 && rumble_magic[3] != 0x00 && rumble_magic[4] != 0x00 && rumble_magic[5] != 0x00) // DualShock weak
rumble_param[0] = receive_buffer;
command_phase++;
break;
case 0x4203:
if(da_rumble_compat)
{
}
else if(rumble_magic[1] == 0x00 && rumble_magic[2] == 0x01)
rumble_param[1] = receive_buffer; // DualShock strong.
command_phase++; // Nowhere here we come!
break;
/************************/
/* MMMode 1, Command 0x43 */
/************************/
case 0x4300:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4301:
if(receive_buffer == 0x00)
{
//fprintf(stderr, "Mad Munchkins mode left!\n");
mad_munchkins = false;
}
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x44 */
/************************/
case 0x4400:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4401:
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase++;
// Ignores locking state.
switch(receive_buffer)
{
case 0x00:
analog_mode = false;
//fprintf(stderr, "Analog mode disabled\n");
break;
case 0x01:
analog_mode = true;
//fprintf(stderr, "Analog mode enabled\n");
break;
}
break;
case 0x4402:
switch(receive_buffer)
{
case 0x02:
analog_mode_locked = false;
break;
case 0x03:
analog_mode_locked = true;
break;
}
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x45 */
/************************/
case 0x4500:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0x01; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4501:
transmit_buffer[0] = 0x02;
transmit_buffer[1] = analog_mode ? 0x01 : 0x00;
transmit_buffer[2] = 0x02;
transmit_buffer[3] = 0x01;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x46 */
/************************/
case 0x4600:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4601:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x01;
transmit_buffer[2] = 0x02;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x0A;
}
else if(receive_buffer == 0x01)
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x01;
transmit_buffer[2] = 0x01;
transmit_buffer[3] = 0x01;
transmit_buffer[4] = 0x14;
}
else
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
}
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x47 */
/************************/
case 0x4700:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4701:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x02;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x01;
transmit_buffer[4] = 0x00;
}
else
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
}
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x48 */
/************************/
case 0x4800:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4801:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x01;
transmit_buffer[4] = rumble_param[0];
}
else if(receive_buffer == 0x01)
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x01;
transmit_buffer[4] = rumble_param[1];
}
else
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
}
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x49 */
/************************/
case 0x4900:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4901:
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x4A */
/************************/
case 0x4A00:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4A01:
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x4B */
/************************/
case 0x4B00:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4B01:
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/
/* MMMode 1, Command 0x4C */
/************************/
case 0x4C00:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0; /**/ transmit_pos = 0; transmit_count = 1; /**/
command_phase++;
}
else
command_phase = -1;
break;
case 0x4C01:
if(receive_buffer == 0x00)
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x04;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
}
else if(receive_buffer == 0x01)
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x07;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
}
else
{
transmit_buffer[0] = 0x00;
transmit_buffer[1] = 0x00;
transmit_buffer[2] = 0x00;
transmit_buffer[3] = 0x00;
transmit_buffer[4] = 0x00;
}
transmit_pos = 0;
transmit_count = 5;
command_phase = -1;
break;
/************************/