-
Notifications
You must be signed in to change notification settings - Fork 2
/
Class5_burn.cs
1007 lines (936 loc) · 34.1 KB
/
Class5_burn.cs
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
//using PropertiesRes;
using System;
using System.ComponentModel;
using System.IO.Ports;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
internal class Class5_burn
{
private BackgroundWorker backgroundWorker_0;
private BackgroundWorker backgroundWorker_1;
private BackgroundWorker backgroundWorker_2;
private bool bool_0;
private bool bool_1;
private bool bool_2;
private bool bool_3;
private bool bool_4;
private bool bool_SST256;
private byte[] byte_0;
private byte[] byte_1;
private byte[] byte_2;
private byte byte_3;
private Class10_settings class10_settings_0;
private Class17 class17_0;
private Class18 class18_0;
private int int_0;
private long long_0;
private string BMBurnerTitle = "";
private string BMBurnerDesc = "";
private SerialPort serialPort_0;
public frmBurner frmBurner_0;
private int FirmwareNumber = 0;
private bool IsBMBurner = false;
public byte[] byte_ALL = new byte[] { };
private bool SecondPass = false;
public event Delegate8 delegate8_0;
public event Delegate9 delegate9_0;
internal Class5_burn(ref Class18 rm, ref Class10_settings cfg, ref Class17 dt, ref FrmMain frmM)
{
this.class10_settings_0 = cfg;
this.class17_0 = dt;
this.class18_0 = rm;
}
private byte GetByteAt(long Location)
{
byte RByte= 0;
if (byte_ALL.Length >= Location + 1) RByte = byte_ALL[Location];
return RByte;
}
private string GetConnectedTitleString()
{
if (BMBurnerTitle != "")
{
if (this.bool_2) return " Connected";
return " Disconnected";
}
return "Connecting Burner...";
}
private void backgroundWorker_0_DoWork(object sender, DoWorkEventArgs e)
{
this.bool_2 = false;
this.int_0 = 1;
BMBurnerDesc = "Detecting burner";
UpdateTileText();
try
{
if (this.class10_settings_0.burnCommCache != 0)
{
this.int_0 = this.class10_settings_0.burnCommCache;
this.bool_2 = false;
if (this.serialPort_0 != null)
{
if (this.serialPort_0.IsOpen) this.serialPort_0.Close();
this.serialPort_0.Dispose();
this.serialPort_0 = null;
}
if (this.method_5())
{
this.bool_2 = true;
return;
}
}
}
catch
{
}
this.int_0 = 1;
Label_00A0:
try
{
if (this.int_0 == 41)
{
LogThis("Burner NOT found!");
this.bool_2 = false;
if (this.serialPort_0 != null)
{
if (this.serialPort_0.IsOpen) this.serialPort_0.Close();
this.serialPort_0.Dispose();
this.serialPort_0 = null;
}
BMBurnerDesc = "Device not found!";
UpdateTileText();
}
else if (this.method_5())
{
LogThis("Burner found on COM" + this.int_0);
this.class10_settings_0.burnCommCache = this.int_0;
this.bool_2 = true;
BMBurnerDesc = "Device found!";
UpdateTileText();
}
else
{
this.int_0++;
goto Label_00A0;
}
}
catch (Exception)
{
if (this.serialPort_0 != null)
{
this.serialPort_0.Dispose();
this.serialPort_0 = null;
}
this.int_0++;
goto Label_00A0;
}
}
//Burn Write Chip
private void backgroundWorker_1_DoWork(object sender, DoWorkEventArgs e)
{
ChangeAccTime();
DialogResult result = DialogResult.OK;
if (IsBurnerV2())
{
if (this.frmBurner_0.ChipSelectBox.Text == "W27C512 (Fake Winbond SST)" || this.frmBurner_0.ChipSelectBox.Text == "W27E512") result = MessageBox.Show(Form.ActiveForm, "Set the BMBurner on 14v then press OK", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
if (this.frmBurner_0.ChipSelectBox.Text == "27SF512") result = MessageBox.Show(Form.ActiveForm, "Set the BMBurner on 12v then press OK", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (this.frmBurner_0.ChipSelectBox.Text == "W27C512 (Fake Winbond SST)" || this.frmBurner_0.ChipSelectBox.Text == "W27E512")
{
if (IsBMBurner) result = MessageBox.Show(Form.ActiveForm, "This version of BMBurner CANNOT change voltage to 14v" + Environment.NewLine + Environment.NewLine + "It's possible the chip won't erase correctly!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
else result = MessageBox.Show(Form.ActiveForm, "The Burn2 CANNOT change voltage to 14v" + Environment.NewLine + Environment.NewLine + "It's possible the chip won't erase correctly!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
if (result != DialogResult.OK) return;
byte num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
this.byte_1 = new byte[0x106];
if (this.backgroundWorker_1.CancellationPending)
{
goto Label_02F7;
}
long num = 0L;
num3 = 0;
//chip index
if (bool_SST256)
{
num4 = 0x36;
}
else
{
if (!this.bool_4)
{
num4 = 0x35;
}
else
{
num4 = 50;
}
}
Label_0043:
this.serialPort_0.ReadTimeout = 0x7d0;
this.serialPort_0.WriteTimeout = 110;
if (num5 == 3)
{
LogThis("Failed to erase SST after " + this.class10_settings_0.int_21.ToString() + " tries");
MessageBox.Show(Form.ActiveForm, "Failed to erase SST");
return;
}
if (num4 == 53)
{
LogThis("Erasing chip");
BMBurnerDesc = "Erasing chip";
UpdateTileText();
this.byte_1[0] = (byte) num4;
this.byte_1[1] = 0x45;
this.byte_1[2] = this.method_10(this.byte_1, 0, 2);
try
{
this.method_7(this.byte_1, 0, 3);
num2 = this.method_9();
}
catch (Exception)
{
num5++;
goto Label_0043;
}
if (num2 != 0x4f)
{
num5++;
goto Label_0043;
}
}
this.serialPort_0.ReadTimeout = 1000;
this.serialPort_0.WriteTimeout = 500;
if (IsBurnerV2() && this.frmBurner_0.ChipSelectBox.Text == "W27C512 (Fake Winbond SST)" || this.frmBurner_0.ChipSelectBox.Text == "W27E512") result = MessageBox.Show(Form.ActiveForm, "Set the BMBurner on 12v then press OK", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Label_010B:
if ((num3 - 1) == this.class10_settings_0.int_21)
{
LogThis("Uploading failed after " + this.class10_settings_0.int_21.ToString() + " tries");
MessageBox.Show(Form.ActiveForm, "Uploading failed after " + this.class10_settings_0.int_21.ToString() + " on Burner", "Burner Notification", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
if (num < 0x8000L)
{
//LogThis("Writing chip at 0x" + num.ToString("X4"));
if (SecondPass)
{
BMBurnerDesc = "Writing 2nd 2Timer chip";
UpdateTileText();
}
else
{
BMBurnerDesc = "Writing chip";
UpdateTileText();
}
this.backgroundWorker_1.ReportProgress((int) ((((double) num) / 32768.0) * 100.0));
try
{
this.byte_1[0] = (byte) num4;
this.byte_1[1] = 0x57;
this.byte_1[2] = 0;
if (!SecondPass)
{
this.byte_1[3] = this.class18_0.method_148(this.long_0 + num);
this.byte_1[4] = this.class18_0.method_147(this.long_0 + num);
}
else
{
this.byte_1[3] = this.class18_0.method_148(this.long_0 + num + 0x8000L);
this.byte_1[4] = this.class18_0.method_147(this.long_0 + num + 0x8000L);
}
for (int i = 0; i < 0x100; i++)
{
if (!SecondPass) this.byte_1[5 + i] = GetByteAt(num + i);
else this.byte_1[5 + i] = GetByteAt(num + i + 32768);
//this.byte_1[5 + i] = this.class18_0.method_150(num + i);
}
this.byte_1[0x105] = this.method_10(this.byte_1, 0, 0x105);
this.method_7(this.byte_1, 0, 0x106);
if (this.method_9() == 0x4f)
{
num += 0xffL;
num += 1L;
if (frmBurner_0.Is2Timer && num >= 0x8000L)
{
if (!SecondPass)
{
num = 0L;
SecondPass = true;
LogThis("Writing 2nd 2Timer chip");
}
else
{
SecondPass = false;
}
}
}
else
{
num3++;
}
goto Label_010B;
}
catch
{
num3++;
goto Label_010B;
}
}
}
Label_02F7:
if (this.backgroundWorker_1 != null) this.backgroundWorker_1.ReportProgress(100);
num = 0L;
}
private void backgroundWorker_1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (this.delegate8_0 != null)
{
this.delegate8_0(e.ProgressPercentage);
}
}
private void backgroundWorker_1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.backgroundWorker_1.Dispose();
this.backgroundWorker_1 = null;
this.byte_1 = null;
this.byte_2 = null;
this.byte_0 = null;
this.method_18(frmBurner_0, false);
this.serialPort_0.Close();
this.serialPort_0.Dispose();
this.serialPort_0 = null;
this.bool_2 = false;
this.bool_0 = false;
UpdateTileText();
GC.Collect();
}
private void backgroundWorker_2_DoWork(object sender, DoWorkEventArgs e)
{
int num2 = 0;
this.byte_1 = new byte[7];
this.byte_2 = new byte[260];
int num3 = 0;
if (bool_SST256)
{
num3 = 0x36;
}
else
{
if (!this.bool_4)
{
num3 = 0x35;
}
else
{
num3 = 50;
}
}
this.serialPort_0.ReadTimeout = 1000;
this.serialPort_0.WriteTimeout = 500;
if (this.backgroundWorker_2.CancellationPending)
{
goto Label_0238;
}
long num = 0L;
num2 = 0;
Label_005A:
if ((num2 - 1) == 3)
{
this.bool_3 = true;
LogThis("Burner failed to read");
MessageBox.Show(Form.ActiveForm, "Burner failed to read", "Burner Notification", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else if (num < 0x8000L)
{
//LogThis("Reading chip at 0x" + num.ToString("X4"));
if (SecondPass)
{
BMBurnerDesc = "Verifying 2nd 2Timer chip";
UpdateTileText();
}
this.backgroundWorker_2.ReportProgress((int) ((((double) num) / 32768.0) * 100.0));
this.method_12();
this.byte_1[0] = (byte) num3;
this.byte_1[1] = 0x52;
this.byte_1[2] = 0;
if (!SecondPass)
{
this.byte_1[3] = this.class18_0.method_148(this.long_0 + num);
this.byte_1[4] = this.class18_0.method_147(this.long_0 + num);
}
else
{
this.byte_1[3] = this.class18_0.method_148(this.long_0 + num + 0x8000L);
this.byte_1[4] = this.class18_0.method_147(this.long_0 + num + 0x8000L);
}
this.byte_1[5] = this.method_10(this.byte_1, 0, 5);
try
{
this.method_7(this.byte_1, 0, 6);
int Tries = 0;
while (this.serialPort_0.BytesToRead < 0x100 && Tries < 5)
{
Application.DoEvents();
int Tries_Fast = 0;
while (this.serialPort_0.BytesToRead < 0x100 && Tries_Fast < 50)
{
Thread.Sleep(1);
Tries_Fast++;
}
if (this.serialPort_0.BytesToRead < 0x100)
{
if (Tries >= 3) this.method_7(this.byte_1, 0, 6);
Thread.Sleep(50);
Tries++;
}
}
this.serialPort_0.Read(this.byte_2, 0, 0x100);
if (num == 0L)
{
for (int i = 0; i < 0x100; i++)
{
}
}
this.method_14(this.byte_2, 0x100);
byte num5 = this.method_9();
if (this.method_11() != num5)
{
this.serialPort_0.DiscardInBuffer();
this.bool_3 = true;
num2++;
}
else
{
if (!SecondPass) this.method_15(this.byte_2, (int) num, 0x100);
else this.method_15(this.byte_2, (int)num + 32768, 0x100);
num += 0xffL;
num += 1L;
this.bool_3 = false;
if (frmBurner_0.Is2Timer && num >= 0x8000L)
{
if (!SecondPass)
{
num = 0L;
SecondPass = true;
LogThis("Reading 2nd 2Timer chip");
}
else
{
SecondPass = false;
}
}
}
}
catch (Exception)
{
if (this.serialPort_0 != null)
if (this.serialPort_0.IsOpen) this.serialPort_0.DiscardInBuffer();
num2++;
}
goto Label_005A;
}
Label_0238:
this.backgroundWorker_2.ReportProgress(100);
this.byte_1 = null;
this.byte_2 = null;
num2 = 0;
num = 0L;
}
private void backgroundWorker_2_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (this.delegate8_0 != null)
{
this.delegate8_0(e.ProgressPercentage);
}
}
private void backgroundWorker_2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!this.bool_1)
{
if (!this.bool_3)
{
this.class18_0.method_67(this.byte_0, false);
}
this.backgroundWorker_2.Dispose();
this.backgroundWorker_2 = null;
this.bool_2 = false;
this.bool_0 = false;
//this.byte_0 = null;
this.serialPort_0.Close();
this.serialPort_0.Dispose();
this.serialPort_0 = null;
if (!this.bool_3)
{
if (!this.class18_0.method_30_HasFileLoadedInBMTune()) FailRead();
else
{
LogThis("Chip succesfully read");
BMBurnerDesc = "Succesfully read";
UpdateTileText();
}
}
else
{
FailRead();
}
}
this.byte_1 = null;
this.byte_2 = null;
GC.Collect();
}
private void FailRead()
{
LogThis("Chip failed to read");
BMBurnerDesc = "Failed to read";
UpdateTileText();
if (MessageBox.Show(Form.ActiveForm, "Do you want to save a copy of the file?", "BMTune", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
{
this.class18_0.SetAllByte(this.byte_0);
this.class18_0.method_70();
this.class18_0.SetByteNull();
this.byte_0 = null;
}
}
internal bool method_0()
{
return this.bool_4;
}
internal void method_1(bool bool_5)
{
this.bool_4 = bool_5;
}
internal bool method_0_SST256()
{
return this.bool_SST256;
}
internal void method_1_SST256(bool bool_5)
{
this.bool_SST256 = bool_5;
}
private byte method_10(byte[] byte_4, int int_1, int int_2)
{
byte num = 0;
for (int i = 0; i < int_2; i++)
{
num = (byte) (num + byte_4[i]);
}
return num;
}
private byte method_11()
{
return this.byte_3;
}
private void method_12()
{
this.byte_3 = 0;
}
private void method_13(byte byte_4)
{
this.byte_3 = (byte) (this.byte_3 + byte_4);
}
private void method_14(byte[] byte_4, int int_1)
{
for (int i = 0; i < int_1; i++)
{
this.byte_3 = (byte) (this.byte_3 + byte_4[i]);
}
}
private void method_15(byte[] byte_4, int int_1, int int_2)
{
for (int i = 0; i < int_2; i++)
{
this.byte_0[int_1 + i] = byte_4[i];
}
}
public void method_16(frmBurner TFRM)
{
frmBurner_0 = TFRM;
if (!this.method_4())
{
this.bool_0 = false;
}
else
{
LogThis("Writing chip");
this.backgroundWorker_1 = new BackgroundWorker();
this.backgroundWorker_1.WorkerReportsProgress = true;
this.backgroundWorker_1.WorkerSupportsCancellation = true;
this.backgroundWorker_1.DoWork += new DoWorkEventHandler(this.backgroundWorker_1_DoWork);
this.backgroundWorker_1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker_1_RunWorkerCompleted);
this.backgroundWorker_1.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker_1_ProgressChanged);
this.backgroundWorker_1.RunWorkerAsync();
while (this.backgroundWorker_1 != null && this.backgroundWorker_1.IsBusy)
{
Application.DoEvents();
}
if (this.backgroundWorker_1 != null)
{
this.backgroundWorker_1.Dispose();
this.backgroundWorker_1 = null;
}
}
}
public void method_17(frmBurner TFRM)
{
frmBurner_0 = TFRM;
this.class18_0.method_68();
if (!this.method_4())
{
this.bool_0 = false;
}
else
{
this.byte_0 = new byte[0x8000];
if (!this.bool_1)
{
LogThis("Reading chip");
BMBurnerDesc = "Reading chip";
UpdateTileText();
}
this.backgroundWorker_2 = new BackgroundWorker();
this.backgroundWorker_2.WorkerSupportsCancellation = true;
this.backgroundWorker_2.WorkerReportsProgress = true;
this.backgroundWorker_2.DoWork += new DoWorkEventHandler(this.backgroundWorker_2_DoWork);
this.backgroundWorker_2.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker_2_ProgressChanged);
this.backgroundWorker_2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker_2_RunWorkerCompleted);
this.backgroundWorker_2.RunWorkerAsync();
while (this.backgroundWorker_2 != null && this.backgroundWorker_2.IsBusy)
{
Application.DoEvents();
}
if (this.backgroundWorker_2 != null)
{
this.backgroundWorker_2.Dispose();
this.backgroundWorker_2 = null;
}
}
}
public void method_18(frmBurner TFRM, bool bool_5)
{
frmBurner_0 = TFRM;
if (bool_5 && !this.method_4())
{
this.bool_0 = false;
}
else
{
int ThisLenght = 32768;
if (frmBurner_0.Is2Timer) ThisLenght = ThisLenght * 2;
this.byte_0 = new byte[ThisLenght];
this.bool_1 = true;
LogThis("Verifying chip");
BMBurnerDesc = "Chip verifying";
UpdateTileText();
this.backgroundWorker_2 = new BackgroundWorker();
this.backgroundWorker_2.WorkerSupportsCancellation = true;
this.backgroundWorker_2.WorkerReportsProgress = true;
this.backgroundWorker_2.DoWork += new DoWorkEventHandler(this.backgroundWorker_2_DoWork);
this.backgroundWorker_2.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker_2_ProgressChanged);
this.backgroundWorker_2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker_2_RunWorkerCompleted);
this.backgroundWorker_2.RunWorkerAsync();
while (this.backgroundWorker_2 != null && this.backgroundWorker_2.IsBusy)
{
Application.DoEvents();
}
if (this.backgroundWorker_2 != null)
{
this.backgroundWorker_2.Dispose();
this.backgroundWorker_2 = null;
}
for (int i = 0; i < ThisLenght; i++)
{
if (this.byte_0[i] != GetByteAt((long)i))
//if (this.byte_0[i] != this.class18_0.method_150((long) i))
{
LogThis("Chip NOT verified!");
BMBurnerDesc = "Chip NOT verified!";
UpdateTileText();
return;
}
}
LogThis("Chip verified");
BMBurnerDesc = "Chip verified";
UpdateTileText();
this.byte_0 = null;
this.bool_1 = false;
GC.Collect();
}
}
private void UpdateTileText()
{
if (this.delegate9_0 != null)
{
this.delegate9_0(BMBurnerTitle + GetConnectedTitleString() + " - " + BMBurnerDesc);
}
}
private void LogThis(string string_1)
{
this.class17_0.frmMain_0.LogThis("Burner - " + string_1);
}
internal long method_2()
{
return this.long_0;
}
internal void method_3(long long_1)
{
this.long_0 = long_1;
}
internal bool method_4()
{
LogThis("Detecting Burner");
BMBurnerTitle = "";
this.backgroundWorker_0 = new BackgroundWorker();
this.backgroundWorker_0.DoWork += new DoWorkEventHandler(this.backgroundWorker_0_DoWork);
this.backgroundWorker_0.WorkerReportsProgress = false;
this.backgroundWorker_0.WorkerSupportsCancellation = false;
this.backgroundWorker_0.RunWorkerAsync();
while (this.backgroundWorker_0.IsBusy)
{
Application.DoEvents();
}
this.bool_0 = false;
if (!this.bool_2 && this.frmBurner_0 != null) this.frmBurner_0.button1.Enabled = true;
return this.bool_2;
}
private bool method_5()
{
int num = 3;
int num2 = 0;
if ((this.serialPort_0 != null) && this.serialPort_0.IsOpen)
{
this.serialPort_0.Close();
}
if (this.serialPort_0 != null)
{
this.serialPort_0.Dispose();
this.serialPort_0 = null;
}
this.serialPort_0 = new SerialPort("COM" + this.int_0.ToString(), 0x1c200);
this.serialPort_0.ReadTimeout = 1000;
this.serialPort_0.WriteTimeout = 500;
this.serialPort_0.Encoding = Encoding.Default;
this.serialPort_0.Open();
this.LogThis("------------------------------");
this.LogThis("Port open:COM" + this.int_0.ToString() + " (Baud:115200)");
//this.byte_1 = new byte[5];
this.byte_1 = new byte[2];
this.byte_2 = new byte[3];
Label_00B8:
if ((num2 + 1) != num)
{
this.byte_1 = new byte[2];
this.byte_1[0] = 0x56;
this.byte_1[1] = 0x56;
try
{
this.method_7(this.byte_1, 0, 2);
for (int i = 0; i < 3; i++)
{
this.byte_2[i] = this.method_9();
}
if (this.byte_2[0] == 5)
{
TestBMBurner();
if (BMBurnerTitle == "") BMBurnerTitle = "Moates Burn1/2";
return true;
}
}
catch
{
this.serialPort_0.DiscardInBuffer();
try
{
this.byte_1 = new byte[3];
this.byte_1[0] = 0x53;
this.byte_1[1] = 0;
this.byte_1[2] = 0x53;
this.method_7(this.byte_1, 0, 3);
this.serialPort_0.DiscardInBuffer();
this.serialPort_0.Close();
this.serialPort_0 = new SerialPort("COM" + this.int_0.ToString(), 0xe1000);
this.serialPort_0.ReadTimeout = 1000;
this.serialPort_0.WriteTimeout = 500;
this.serialPort_0.Open();
this.LogThis("Port open:COM" + this.int_0.ToString() + " (Baud:921600)");
this.byte_1 = new byte[2];
this.byte_1[0] = 0x56;
this.byte_1[1] = 0x56;
try
{
this.method_7(this.byte_1, 0, 2);
for (int j = 0; j < 3; j++)
{
this.byte_2[j] = this.method_9();
}
if (this.byte_2[0] == 5)
{
TestBMBurner();
if (BMBurnerTitle == "") BMBurnerTitle = "Moates Burn1/2";
return true;
}
this.LogThis("Can't dectect Burner on COM" + this.int_0.ToString());
}
catch
{
this.LogThis("Can't dectect Burner on COM" + this.int_0.ToString());
num2++;
}
}
catch
{
this.LogThis("Can't dectect Burner on COM" + this.int_0.ToString());
num2++;
}
goto Label_00B8;
}
}
this.serialPort_0.Close();
this.serialPort_0.Dispose();
this.serialPort_0 = null;
return false;
}
public void ChangeAccTime()
{
if (IsBurnerV2())
{
this.LogThis("Changing chip Access Time to: " + frmBurner_0.LastAccessTime + "ns");
byte[] Commands = new byte[2];
Commands[0] = Convert.ToByte('A');
Commands[1] = (byte)frmBurner_0.LastAccessTime;
byte num2 = 0;
try
{
this.method_7(Commands, 0, 2);
num2 = this.method_9();
}
catch { }
if (num2 == 0x4f)
{
this.LogThis("Chip Access Time changed succesfully");
}
else
{
this.LogThis("Error when changing chip Access Time");
//MessageBox.Show(Form.ActiveForm, "Error when changing chip Access Time", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
if (IsBMBurner)
{
if ((this.frmBurner_0.LastAccessTime != 70 && this.frmBurner_0.ChipSelectBox.Text != "AT29C256")
|| (this.frmBurner_0.LastAccessTime != 20)) MessageBox.Show(Form.ActiveForm, "This version of BMBurner CANNOT change AccessTime" + Environment.NewLine + Environment.NewLine + "It's possible the chip won't write correctly!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if ((this.frmBurner_0.LastAccessTime != 20 && this.frmBurner_0.ChipSelectBox.Text == "SST27SF512")
|| (this.frmBurner_0.LastAccessTime != 70 && this.frmBurner_0.ChipSelectBox.Text == "SST27SF512 (Fake 70ns)")
|| (this.frmBurner_0.LastAccessTime != 70 && this.frmBurner_0.ChipSelectBox.Text == "AT29C256")) MessageBox.Show(Form.ActiveForm, "The Burn2 CANNOT change AccessTime" + Environment.NewLine + Environment.NewLine + "It's possible the chip won't write correctly!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void TestBMBurner()
{
byte[] BurnerVersion = this.byte_2;
int int_1 = BurnerVersion[0];
int int_2 = BurnerVersion[1];
string string_V = char.ConvertFromUtf32(BurnerVersion[2]);
byte[] BurnerVersionFirmware = new byte[2];
if (this.serialPort_0.IsOpen) this.serialPort_0.DiscardInBuffer();
if (this.serialPort_0.IsOpen) this.serialPort_0.DiscardOutBuffer();
IsBMBurner = false;
//try
//{
this.byte_1 = new byte[2];
this.byte_1[0] = Convert.ToByte('F');
this.byte_1[1] = Convert.ToByte('F');
this.method_7(this.byte_1, 0, 2);
for (int j = 0; j < 2; j++) BurnerVersionFirmware[j] = this.method_9();
if (BurnerVersionFirmware[0] < 50)
{
IsBMBurner = true;
}
//Console.WriteLine("firmware V" + BurnerVersionFirmware[0] + "." + BurnerVersionFirmware[1]);
//}
//catch {
/*try
{
//##########################
//testing old bmburner function
this.byte_1 = new byte[2];
this.byte_1[0] = Convert.ToByte('F');
this.byte_1[1] = Convert.ToByte('F');
this.method_7(this.byte_1, 0, 2);
for (int j = 0; j < 2; j++) BurnerVersionFirmware[j] = this.method_9();
IsBMBurner = true;
//##########################
}
catch
{
}*/
//}
if (IsBMBurner)
{
FirmwareNumber = (BurnerVersionFirmware[0] * 10) + BurnerVersionFirmware[1];
if (FirmwareNumber >= 13)
{
this.LogThis("BMBurner V2.X (firmware V" + BurnerVersionFirmware[0] + "." + BurnerVersionFirmware[1] + ")");
BMBurnerTitle = "BMBurner V2.X";
}
else
{
if (this.serialPort_0.BaudRate == 115200)
{
this.LogThis("BMBurner V1.0 (firmware V" + BurnerVersionFirmware[0] + "." + BurnerVersionFirmware[1] + ")");
BMBurnerTitle = "BMBurner V1.0";
}
else if (this.serialPort_0.BaudRate == 921600)
{
this.LogThis("BMBurner V1.1 (firmware V" + BurnerVersionFirmware[0] + "." + BurnerVersionFirmware[1] + ")");
BMBurnerTitle = "BMBurner V1.1";
}
}
}
else
{
this.LogThis("Moates Burn1/2 (V" + int_1 + "." + int_2 + "." + string_V + ")");
BMBurnerTitle = "Moates Burn1/2";
IsBMBurner = false;
}
}
private bool IsBurnerV2()
{
if (IsBMBurner)
{
if (FirmwareNumber >= 13) return true;
else return false;
}
return false;
}
private void method_6(byte byte_4)
{
this.serialPort_0.Write(((char) byte_4).ToString());
}
private void method_7(byte[] byte_4, int int_1, int int_2)
{
this.serialPort_0.Write(byte_4, int_1, int_2);
}
private void method_8(string string_0)
{
this.serialPort_0.Write(string_0);
}
private byte method_9()
{
return (byte) this.serialPort_0.ReadByte();