-
Notifications
You must be signed in to change notification settings - Fork 4
/
JoeyJoebags3_18.py
1948 lines (1690 loc) · 68.4 KB
/
JoeyJoebags3_18.py
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
from tkinter import *
from tkinter.filedialog import askopenfilename, asksaveasfilename
import tkinter.messagebox as messagebox
import usb.core
import usb.util
#import sys
#import itertools
import atexit
import re
ROMsize=0
RAMsize=0
ROMbuffer=""
RAMbuffer=""
USBbuffer=""
FlashBlockSize=0
for usbfill in range(64):
USBbuffer=USBbuffer+"\x00"
Command_Get_Version = [0x00]
Command_Get_ROM = [0x10]
Command_Set_Bank = [0x08]
Command_Flash_ROM = [0x20]
class Window(Frame):
def __init__ (self, master=None):
Frame.__init__ (self,master)
self.master = master
self.init_window()
def init_window(self):
self.master.title("Joey Joebags by BennVenn - V3.17")
self.pack(fill=BOTH, expand=1)
self.lowerLeftLabel = StringVar()
cartSelectionLabel = Label(root, textvariable = self.lowerLeftLabel)
cartSelectionLabel.place(x=0,y=280)
self.lowerRightLabel = StringVar()
hardwareStatusLabel = Label(root, textvariable = self.lowerRightLabel)
hardwareStatusLabel.place(x=270,y=280)
self.ROMtitleLabel = StringVar()
ROMtitleLabel = Label(root, textvariable = self.ROMtitleLabel)
ROMtitleLabel.place(x=0,y=0)
self.ROMsizeLabel = StringVar()
ROMsizeLabel = Label(root, textvariable = self.ROMsizeLabel)
ROMsizeLabel.place(x=0,y=20)
self.RAMsizeLabel = StringVar()
RAMsizeLabel = Label(root, textvariable = self.RAMsizeLabel)
RAMsizeLabel.place(x=0,y=40)
self.MAPPERtypeLabel = StringVar()
MAPPERtypeLabel = Label(root, textvariable = self.MAPPERtypeLabel)
MAPPERtypeLabel.place(x=0,y=60)
menu=Menu(root)
root.config(menu=menu)
filemenu=Menu(menu)
menu.add_cascade(label="File",menu=filemenu)
filemenu.add_command(label="Exit",command=main_Exit)
cartTypeMenu = Menu(menu)
menu.add_cascade(label="Cart Type", menu=cartTypeMenu)
#MBC Generic Cart Menu
MBCmenu = Menu(menu)
cartTypeMenu.add_cascade(label="GB(C) Generic",menu=MBCmenu)
MBCmenu.add_command(label='Get Save RAM',command=main_MBC_Dump_RAM)
MBCmenu.add_command(label='Write Save RAM',command=main_MBC_Burn_RAM)
MBCmenu.add_command(label='Dump ROM',command=main_MBC_Dump_ROM)
#MBC2 Menu
MBC2menu = Menu(menu)
cartTypeMenu.add_cascade(label="GB MBC2",menu=MBC2menu)
MBC2menu.add_command(label='Get Save RAM',command=main_MBC2_Dump_RAM)
MBC2menu.add_command(label='Write Save RAM',command=main_MBC2_Burn_RAM)
MBC2menu.add_command(label='Dump ROM',command=main_MBC_Dump_ROM)
#GB Cam Cart Menu
GBCammenu = Menu(menu)
cartTypeMenu.add_cascade(label="GB Camera",menu=GBCammenu)
GBCammenu.add_command(label='Get Save RAM',command=main_Cam_Dump_RAM)
GBCammenu.add_command(label='Write Save RAM',command=main_Cam_Burn_RAM)
#32k cart menu
CatMenu = Menu(menu)
cartTypeMenu.add_cascade(label="Catskull 32k",menu=CatMenu)
CatMenu.add_command(label='Erase',command=main_Catskull_erase)
CatMenu.add_command(label='Flash',command=main_Catskull_write)
#EMS32 Cart Menu
EMS32menu = Menu(menu)
cartTypeMenu.add_cascade(label="EMS32",menu=EMS32menu)
EMS32menu.add_command(label='Get Save RAM')
EMS32menu.add_command(label='Write Save RAM')
EMS32menu.add_command(label='Dump ROM')
EMS32menu.add_command(label='Flash ROM')
#EMS64 Cart Menu
EMS64menu = Menu(menu)
cartTypeMenu.add_cascade(label="EMS64",menu=EMS64menu)
EMS64menu.add_command(label='Get Save RAM',command=main_MBC_Dump_256RAM)
EMS64menu.add_command(label='Write Save RAM',command=main_MBC_Burn_RAM)
EMS64menu.add_command(label='Dump ROM',command=main_MBC_Dump_ROM)
EMS64menu.add_command(label='Flash ROM',command=main_EMS64_Burn_ROM)
EMS64menu.add_command(label='Set page 2',command=main_EMS64_PageSwap)
#BV64 Cart Menu
BV64menu = Menu(menu)
BV64GSR = Menu(menu)
BV64WSR = Menu(menu)
cartTypeMenu.add_cascade(label="BennVenn 64M",menu=BV64menu)
BV64menu.add_cascade(label='Get Save RAM',menu=BV64GSR)
BV64GSR.add_command(label='128K',command=main_BV64_Dump_128K0)
BV64GSR.add_command(label='32K (1)',command=main_BV64_Dump_32K1)
BV64GSR.add_command(label='32K (2)',command=main_BV64_Dump_32K2)
BV64GSR.add_command(label='32K (3)',command=main_BV64_Dump_32K3)
BV64GSR.add_command(label='32K (4)',command=main_BV64_Dump_32K4)
BV64menu.add_cascade(label='Write Save RAM',menu=BV64WSR)
BV64WSR.add_command(label='128K',command=main_BV_Burn_128k0)
BV64WSR.add_command(label='32K (1)',command=main_BV_Burn_32K0)
BV64WSR.add_command(label='32K (2)',command=main_BV_Burn_32K1)
BV64WSR.add_command(label='32K (3)',command=main_BV_Burn_32K2)
BV64WSR.add_command(label='32K (4)',command=main_BV_Burn_32K3)
BV64menu.add_command(label='Dump ROM',command=main_BV64_Dump_ROM0)
BV64menu.add_command(label='Flash ROM',command=main_BV64_Flash_ROM0)
#BV256 Cart Menu
BV256menu = Menu(menu)
BV256B1 = Menu(menu)
BV256B2 = Menu(menu)
BV256B3 = Menu(menu)
BV256B4 = Menu(menu)
BV1256GSR = Menu(menu)
BV1256WSR = Menu(menu)
BV2256GSR = Menu(menu)
BV2256WSR = Menu(menu)
BV3256GSR = Menu(menu)
BV3256WSR = Menu(menu)
BV4256GSR = Menu(menu)
BV4256WSR = Menu(menu)
cartTypeMenu.add_cascade(label="BennVenn 256M",menu=BV256menu)
BV256menu.add_cascade(label="Block1",menu=BV256B1)
BV256menu.add_cascade(label="Block2",menu=BV256B2)
BV256menu.add_cascade(label="Block3",menu=BV256B3)
BV256menu.add_cascade(label="Block4",menu=BV256B4)
#Block1
BV256B1.add_cascade(label='Get Save RAM',menu=BV1256GSR)
BV1256GSR.add_command(label='128K',command=main_BV64_Dump_128K0)
BV1256GSR.add_command(label='32K (1)',command=main_BV64_Dump_32K1)
BV1256GSR.add_command(label='32K (2)',command=main_BV64_Dump_32K1)
BV1256GSR.add_command(label='32K (3)',command=main_BV64_Dump_32K1)
BV1256GSR.add_command(label='32K (4)',command=main_BV64_Dump_32K1)
BV256B1.add_cascade(label='Write Save RAM',menu=BV1256WSR)
BV1256WSR.add_command(label='128K',command=main_BV_Burn_128k0)
BV1256WSR.add_command(label='32K (1)',command=main_BV_Burn_32K0)
BV1256WSR.add_command(label='32K (2)',command=main_BV_Burn_32K1)
BV1256WSR.add_command(label='32K (3)',command=main_BV_Burn_32K2)
BV1256WSR.add_command(label='32K (4)',command=main_BV_Burn_32K3)
BV256B1.add_command(label='Dump ROM',command=main_BV64_Dump_ROM0)
BV256B1.add_command(label='Flash ROM',command=main_BV64_Flash_ROM0)
#Block2
BV256B2.add_cascade(label='Get Save RAM',menu=BV2256GSR)
BV2256GSR.add_command(label='128K',command=main_BV64_Dump_128K1)
BV2256GSR.add_command(label='32K (1)',command=main_BV64_Dump_32K21)
BV2256GSR.add_command(label='32K (2)',command=main_BV64_Dump_32K21)
BV2256GSR.add_command(label='32K (3)',command=main_BV64_Dump_32K21)
BV2256GSR.add_command(label='32K (4)',command=main_BV64_Dump_32K21)
BV256B2.add_cascade(label='Write Save RAM',menu=BV2256WSR)
BV2256WSR.add_command(label='128K',command=main_BV_Burn_128k1)
BV2256WSR.add_command(label='32K (1)',command=main_BV_Burn_32K10)
BV2256WSR.add_command(label='32K (2)',command=main_BV_Burn_32K11)
BV2256WSR.add_command(label='32K (3)',command=main_BV_Burn_32K12)
BV2256WSR.add_command(label='32K (4)',command=main_BV_Burn_32K13)
BV256B2.add_command(label='Dump ROM',command=main_BV64_Dump_ROM1)
BV256B2.add_command(label='Flash ROM',command=main_BV64_Flash_ROM1)
#Block3
BV256B3.add_cascade(label='Get Save RAM',menu=BV3256GSR)
BV3256GSR.add_command(label='128K',command=main_BV64_Dump_128K2)
BV3256GSR.add_command(label='32K (1)',command=main_BV64_Dump_32K31)
BV3256GSR.add_command(label='32K (2)',command=main_BV64_Dump_32K31)
BV3256GSR.add_command(label='32K (3)',command=main_BV64_Dump_32K31)
BV3256GSR.add_command(label='32K (4)',command=main_BV64_Dump_32K31)
BV256B3.add_cascade(label='Write Save RAM',menu=BV3256WSR)
BV3256WSR.add_command(label='128K',command=main_BV_Burn_128k2)
BV3256WSR.add_command(label='32K (1)',command=main_BV_Burn_32K20)
BV3256WSR.add_command(label='32K (2)',command=main_BV_Burn_32K21)
BV3256WSR.add_command(label='32K (3)',command=main_BV_Burn_32K22)
BV3256WSR.add_command(label='32K (4)',command=main_BV_Burn_32K23)
BV256B3.add_command(label='Dump ROM',command=main_BV64_Dump_ROM2)
BV256B3.add_command(label='Flash ROM',command=main_BV64_Flash_ROM2)
#Block4
BV256B4.add_cascade(label='Get Save RAM',menu=BV4256GSR)
BV4256GSR.add_command(label='128K',command=main_BV64_Dump_128K3)
BV4256GSR.add_command(label='32K (1)',command=main_BV64_Dump_32K41)
BV4256GSR.add_command(label='32K (2)',command=main_BV64_Dump_32K41)
BV4256GSR.add_command(label='32K (3)',command=main_BV64_Dump_32K41)
BV4256GSR.add_command(label='32K (4)',command=main_BV64_Dump_32K41)
BV256B4.add_cascade(label='Write Save RAM',menu=BV4256WSR)
BV4256WSR.add_command(label='128K',command=main_BV_Burn_128k3)
BV4256WSR.add_command(label='32K (1)',command=main_BV_Burn_32K30)
BV4256WSR.add_command(label='32K (2)',command=main_BV_Burn_32K31)
BV4256WSR.add_command(label='32K (3)',command=main_BV_Burn_32K32)
BV4256WSR.add_command(label='32K (4)',command=main_BV_Burn_32K33)
BV256B4.add_command(label='Dump ROM',command=main_BV64_Dump_ROM3)
BV256B4.add_command(label='Flash ROM',command=main_BV64_Flash_ROM3)
#Bung32 Cart Menu
Bung32menu = Menu(menu)
cartTypeMenu.add_cascade(label="Bung 32M",menu=Bung32menu,state=DISABLED)
Bung32menu.add_command(label='Get Save RAM')
Bung32menu.add_command(label='Write Save RAM')
Bung32menu.add_command(label='Dump ROM')
Bung32menu.add_command(label='Flash ROM')
#Bung64 Cart Menu
Bung64menu = Menu(menu)
cartTypeMenu.add_cascade(label="Bung 64M",menu=Bung64menu,state=DISABLED)
Bung64menu.add_command(label='Get Save RAM')
Bung64menu.add_command(label='Write Save RAM')
Bung64menu.add_command(label='Dump ROM')
Bung64menu.add_command(label='Flash ROM')
#DMG-MMSA-JPN Cart Menu
JPNmenu = Menu(menu)
cartTypeMenu.add_cascade(label="DMG-MMSA-JPN",menu=JPNmenu)
JPNmenu.add_command(label='Get Save RAM',command=main_MBC_Dump_RAM)
JPNmenu.add_command(label='Write Save RAM',command=main_MBC_Burn_RAM)
JPNmenu.add_command(label='Dump ROM',command=main_MBC_Dump_ROM)
JPNmenu.add_command(label='Flash ROM',command=main_JPN_Burn_ROM)
JPNmenu.add_command(label='Unlock Sector 0',command=main_JPN_Unlock_ROM)
#Shark MX Cart Menu
MXmenu = Menu(menu)
cartTypeMenu.add_cascade(label="Shark MX",menu=MXmenu)
MXmenu.add_command(label='Get Save RAM',command=main_MBC_Dump_RAM)
MXmenu.add_command(label='Write Save RAM',command=main_MBC_Burn_RAM)
MXmenu.add_command(label='Dump ROM',command=main_MX_Dump_ROM)
MXmenu.add_command(label='Flash ROM',command=main_MX_Burn_ROM,)
#El Cheapo Cart Menu
ELmenu = Menu(menu)
cartTypeMenu.add_cascade(label="El-Cheapo",menu=ELmenu)
ELmenu.add_command(label='Erase',command=main_ELCheapo_Erase)
ELmenu.add_command(label='Flash ROM',command=main_ELCheapo_Write)
cartTypeMenu.add_separator()
#El Cheapo SD Cart Menu
ELmenuSD = Menu(menu)
cartTypeMenu.add_cascade(label="El-Cheapo SD",menu=ELmenuSD)
ELmenuSD.add_command(label='Erase',command=main_ELCheapoSD_Erase)
ELmenuSD.add_command(label='Flash ROM',command=main_ELCheapoSD_Write)
cartTypeMenu.add_separator()
#BV5 Cheapo Cart Menu
BV5menu = Menu(menu)
cartTypeMenu.add_cascade(label="Chinese BV5 Clone Cart",menu=BV5menu)
BV5menu.add_command(label='Erase',command=main_BV5_Erase)
BV5menu.add_command(label='Flash ROM',command=main_BV5_Write)
cartTypeMenu.add_separator()
#GBA stuff
GBA_GenericMenu=Menu(menu)
GBA_ROM_Size=Menu(menu)
GBA_ROM_Burn=Menu(menu)
cartTypeMenu.add_cascade(label="GBA Generic",menu=GBA_GenericMenu)
GBA_GenericMenu.add_command(label='Read Header',command=main_GBA_ReadHeader)
GBA_GenericMenu.add_separator()
GBA_GenericMenu.add_command(label='Dump 4kbit EEPROM',command=main_GBA_EEPROM_4k)
GBA_GenericMenu.add_command(label='Dump 64kbit EEPROM',command=main_GBA_EEPROM_64k)
GBA_GenericMenu.add_command(label='Write 4kbit EEPROM',command=main_GBA_Write4kEEPROM)
GBA_GenericMenu.add_command(label='Write 64kbit EEPROM',command=main_GBA_Write64kEEPROM)
GBA_GenericMenu.add_separator()
GBA_GenericMenu.add_command(label='Dump 64kbytes SRAM',command=main_GBA_Dump64kSRAM)
GBA_GenericMenu.add_command(label='Write 64k to SRAM',command=main_GBA_Write64kSRAM)
GBA_GenericMenu.add_separator()
GBA_GenericMenu.add_command(label='Dump 64kbytes FLASH',command=main_GBA_Dump64kFLASH)
GBA_GenericMenu.add_command(label='Dump 128kbytes FLASH',command=main_GBA_Dump128kFLASH)
GBA_GenericMenu.add_command(label='Write 64k to FLASH',command=main_GBA_Write64kFLASHRAM)
GBA_GenericMenu.add_command(label='Write 128k to FLASH',command=main_GBA_Write128kFLASHRAM)
GBA_GenericMenu.add_separator()
GBA_GenericMenu.add_cascade(label='Dump ROM',menu=GBA_ROM_Size)
GBA_ROM_Size.add_command(label='8mbit',command=main_GBA_Dump_8)
GBA_ROM_Size.add_command(label='16mbit',command=main_GBA_Dump_16)
GBA_ROM_Size.add_command(label='32mbit',command=main_GBA_Dump_32)
GBA_ROM_Size.add_command(label='64mbit',command=main_GBA_Dump_64)
GBA_ROM_Size.add_command(label='128mbit',command=main_GBA_Dump_128)
GBA_BV=Menu(menu)
cartTypeMenu.add_cascade(label="GBA BennVenn128M",menu=GBA_BV)
GBA_BV.add_command(label='Flash ROM',command=main_GBA_Flash_ROM)
#GBA_BV.add_command(label='Testcode',command=main_GBA_Testcode)
functionMenu = Menu(menu)
menu.add_cascade(label="Function", menu=functionMenu)
functionMenu.add_command(label="Read Cart Header",command=main_readCartHeader)
functionMenu.add_separator()
joeyMenu = Menu(menu)
menu.add_cascade(label="Joey", menu=joeyMenu)
joeyMenu.add_command(label="Update Firmware",command=main_updateFirmware)
joeyMenu.add_separator()
self.lowerRightLabel.set('Hardware Not Detected')
self.ROMtitleLabel.set("ROM Title: Unknown")
self.ROMsizeLabel.set("ROM Size: Unknown")
self.RAMsizeLabel.set("RAM Size: Unknown")
self.MAPPERtypeLabel.set("Mapper: Unknown")
def main_Header():
global ROMsize
global RAMsize
Header=""
dev.write(0x01,[0x10,0x00,0x00,0x01,0x00])#start of logo
dat = dev.read(0x81,64)
Header=dat
msg = [0x10,0x00,0x00,0x01,0x40] #
dev.write(0x01,msg)
dat = dev.read(0x81,64)
Header+=dat
msg = [0x10,0x00,0x00,0x01,0x80] #
dev.write(0x01,msg)
dat = dev.read(0x81,64)
Header+=dat #Header contains 0xC0 bytes of header data
print("ROM Title: "+str(Header[0x34:0x43]))
def main_readCartHeader():
main_BV_SetBank(0,0)
main_ROMBankSwitch(1)
RAMtypes = [0,2048,8192,32768,(32768*4),(32768*2)]
global ROMsize
global RAMsize
Header=""
dev.write(0x01,[0x10,0x00,0x00,0x01,0x00])#start of logo
dat = dev.read(0x81,64)
Header=dat
msg = [0x10,0x00,0x00,0x01,0x40] #
dev.write(0x01,msg)
dat = dev.read(0x81,64)
Header+=dat
msg = [0x10,0x00,0x00,0x01,0x80] #
dev.write(0x01,msg)
dat = dev.read(0x81,64)
Header+=dat #Header contains 0xC0 bytes of header data
ROMsize=(32768*( 2**(Header[0x48])))
romName = str(Header[0x34:0x43],'utf-8',"ignore")
romName = re.sub(r'\W+', '', romName)
app.ROMtitleLabel.set("ROM Name: " + romName )
app.ROMsizeLabel.set("ROM Size: "+str (32768*( 2**(Header[0x48]))))
RAMsize=RAMtypes[Header[0x49]]
app.RAMsizeLabel.set("RAM Size:"+str(RAMsize))
root.update()
# app.ROMregionLabel.set("Mapper: ?????????")
def main_Exit():
exit()
def dispose_USB(dev):
usb.util.dispose_resources(dev)
def main_LoadROM():
global ROMsize
global ROMbuffer
root.update()
ROMfileName=askopenfilename(filetypes=(("GB ROM File","*.GB"),("GBC ROM File","*.GBC"),("GBA ROM File","*.GBA"),("All Files","*.*")))
if ROMfileName:
ROMfile=open(ROMfileName,'rb')
ROMbuffer=ROMfile.read()
ROMsize=len(ROMbuffer)
ROMfile.close()
return(1)
return(0)
def main_SaveROM():
global ROMsize
global ROMbuffer
root.update()
ROMfileName=asksaveasfilename(defaultextension=".GB",filetypes=(("GB ROM File","*.GB"),("GBC ROM File","*.GBC"),("GBA ROM File","*.GBA"),("All Files","*.*")))
if ROMfileName:
ROMfile=open(ROMfileName,'wb')
ROMfile.write(ROMbuffer)
ROMfile.close()
def main_LoadRAM():
global RAMsize
global RAMbuffer
root.update()
RAMfileName=askopenfilename(filetypes=(("GB/C/A SRAM File","*.SAV"),("All Files","*.*")))
if RAMfileName:
RAMfile=open(RAMfileName,'rb')
RAMbuffer=RAMfile.read()
RAMsize=len(RAMbuffer)
RAMfile.close()
return(1)
return(0)
def main_SaveRAM():
global RAMsize
global RAMbuffer
root.update()
print (len(RAMbuffer))
RAMfileName=asksaveasfilename(defaultextension=".SAV",filetypes=(("GB/C/A SRAM File","*.SAV"),("All Files","*.*")))
if RAMfileName:
RAMfile=open(RAMfileName,'wb')
RAMfile.write(RAMbuffer)
RAMfile.close()
def main_updateFirmware():
root.update()
FWfileName=askopenfilename(filetypes=(("BennVenn Firmware File","*.BEN"),("All Files","*.*")))
if FWfileName:
FWfile=open(FWfileName,'rb')
FWbuffer=FWfile.read()
FWsize=len(FWbuffer)
if FWsize==33280:
dev.write(0x01,[0x03])
USBbuffer = dev.read(0x81,64)
app.lowerRightLabel.set(("File Size Correct"))
for FWpos in range (512,33279,64):
dev.write(0x01,FWbuffer[FWpos:FWpos+64])
else:
app.lowerRightLabel.set(("File Invalid"))
FWfile.close()
exit()
def main_CheckVersion():
dev.write(0x01,Command_Get_Version)
dat = dev.read(0x81,64)
sdat=""
for x in range(5):
sdat=sdat+chr(dat[x])
app.lowerRightLabel.set(("Firmware "+sdat))
#MBC Generic Specific Code Goes here:
def main_MBC_Dump_ROM():
global BankSize
BankSize=16384 #bytes per bank
main_readCartHeader()
main_dumpROM()
def main_MX_Dump_ROM():
global BankSize
BankSize=16384 #bytes per bank
main_readCartHeader()
main_dumpMXROM()
def main_MBC_Dump_RAM():
global BankSize
BankSize=16384 #bytes per bank
main_readCartHeader()
main_dumpRAM()
main_SaveRAM()
def main_MBC_Dump_256RAM():
global BankSize
global RAMsize
BankSize=16384 #bytes per bank
main_readCartHeader()
RAMsize=32768*4
main_dumpRAM()
main_SaveRAM()
def main_MBC2_Dump_RAM():
global BankSize
global RAMsize
RAMsize=512
BankSize=512 #bytes per bank
main_dumpRAM2()
main_SaveRAM()
def main_MBC_Burn_RAM():
global BankSize
BankSize=16384 #bytes per bank
main_readCartHeader()
if main_LoadRAM() == 1:
main_BurnRAM()
def main_MBC2_Burn_RAM():
global BankSize
global RAMsize
RAMsize=512
BankSize=512 #bytes per bank
if main_LoadRAM() == 1:
main_BurnRAM2()
#BV64 Specific Code Goes here:
def main_BV64_Dump_ROM(ROMBlk):
global BankSize
global ROMsize
BankSize=16384 #bytes per bank
ROMsize=8388608
main_BV_SetBank(ROMBlk,0)
main_dumpROM()
def main_BV64_Flash_ROM():
global BankSize
global FlashBlockSize
FlashBlockSize=131072 #bytes per bank
BankSize=16384 #bytes per bank
if main_LoadROM() == 1:
main_BV_lockBank(1)
main_BV_FlashROM()
def main_BV64_Flash_ROM0():
main_BV_Flash_ROM(0)
def main_BV64_Flash_ROM1():
main_BV_Flash_ROM(1)
def main_BV64_Flash_ROM2():
main_BV_Flash_ROM(2)
def main_BV64_Flash_ROM3():
main_BV_Flash_ROM(3)
def main_BV64_Dump_ROM0():
main_BV64_Dump_ROM(0)
def main_BV64_Dump_ROM1():
main_BV64_Dump_ROM(1)
def main_BV64_Dump_ROM2():
main_BV64_Dump_ROM(2)
def main_BV64_Dump_ROM3():
main_BV64_Dump_ROM(3)
def main_BV64_Dump_32K1():
main_BV64_Dump_32K(0,0)
def main_BV64_Dump_32K2():
main_BV64_Dump_32K(0,1)
def main_BV64_Dump_32K3():
main_BV64_Dump_32K(0,2)
def main_BV64_Dump_32K4():
main_BV64_Dump_32K(0,3)
def main_BV64_Dump_32K21():
main_BV64_Dump_32K(1,0)
def main_BV64_Dump_32K22():
main_BV64_Dump_32K(1,1)
def main_BV64_Dump_32K23():
main_BV64_Dump_32K(1,2)
def main_BV64_Dump_32K24():
main_BV64_Dump_32K(1,3)
def main_BV64_Dump_32K31():
main_BV64_Dump_32K(2,0)
def main_BV64_Dump_32K32():
main_BV64_Dump_32K(2,1)
def main_BV64_Dump_32K33():
main_BV64_Dump_32K(2,2)
def main_BV64_Dump_32K34():
main_BV64_Dump_32K(2,3)
def main_BV64_Dump_32K41():
main_BV64_Dump_32K(3,0)
def main_BV64_Dump_32K42():
main_BV64_Dump_32K(3,1)
def main_BV64_Dump_32K43():
main_BV64_Dump_32K(3,2)
def main_BV64_Dump_32K44():
main_BV64_Dump_32K(3,3)
def main_BV64_Dump_128K0():
main_BV64_Dump_128K(0)
def main_BV64_Dump_128K1():
main_BV64_Dump_128K(1)
def main_BV64_Dump_128K2():
main_BV64_Dump_128K(2)
def main_BV64_Dump_128K3():
main_BV64_Dump_128K(3)
def main_Cam_Dump_RAM():
global BankSize
global RAMsize
global RAMbuffer
BankSize=16384 #bytes per bank
RAMsize=32768*4
main_dumpRAM()
main_SaveRAM()
def main_Cam_Burn_RAM():
global RAMbuffer
global RAMsize
if main_LoadRAM() == 1:
RAMsize=32768*4
main_BurnRAM()
def main_BV_Burn_32K0():
main_BV_SetBank(0,0)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K1():
main_BV_SetBank(0,1)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K2():
main_BV_SetBank(0,2)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K3():
main_BV_SetBank(0,3)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K10():
main_BV_SetBank(1,0)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K11():
main_BV_SetBank(1,1)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K12():
main_BV_SetBank(1,2)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K13():
main_BV_SetBank(1,3)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K20():
main_BV_SetBank(2,0)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K21():
main_BV_SetBank(2,1)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K22():
main_BV_SetBank(2,2)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K23():
main_BV_SetBank(2,3)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K30():
main_BV_SetBank(3,0)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K31():
main_BV_SetBank(3,1)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K32():
main_BV_SetBank(3,2)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_32K33():
main_BV_SetBank(3,3)
if main_LoadRAM() == 1:
main_BurnRAM()
def main_BV_Burn_128k0():
main_BV_Burn_128k(0)
def main_BV_Burn_128k1():
main_BV_Burn_128k(1)
def main_BV_Burn_128k2():
main_BV_Burn_128k(2)
def main_BV_Burn_128k3():
main_BV_Burn_128k(3)
def main_BV_Burn_128k(bnum):
global RAMbuffer
global RAMsize
if main_LoadRAM() == 1:
RAMsize=32768
tempRAMbuffer=RAMbuffer
RAMbuffer=tempRAMbuffer[0:32768]
main_BV_SetBank(bnum,0)
main_BurnRAM()
RAMbuffer=tempRAMbuffer[32768:65536]
main_BV_SetBank(bnum,1)
main_BurnRAM()
RAMbuffer=tempRAMbuffer[65536:98304]
main_BV_SetBank(bnum,2)
main_BurnRAM()
RAMbuffer=tempRAMbuffer[98304:131072]
main_BV_SetBank(bnum,3)
main_BurnRAM()
def main_BV64_Dump_128K(blk):
global BankSize
global RAMsize
global RAMbuffer
TempRAMbuffer = b''
BankSize=16384 #bytes per bank
RAMsize=32768
main_BV_SetBank(blk,0)
main_dumpRAM()
TempRAMbuffer=RAMbuffer
main_BV_SetBank(blk,1)
main_dumpRAM()
TempRAMbuffer=TempRAMbuffer +RAMbuffer
main_BV_SetBank(blk,2)
main_dumpRAM()
TempRAMbuffer=TempRAMbuffer +RAMbuffer
main_BV_SetBank(blk,3)
main_dumpRAM()
RAMbuffer=TempRAMbuffer +RAMbuffer
RAMsize=32768*4
main_SaveRAM()
def main_BV64_Dump_32K(blk,sublk):
global BankSize
global RAMsize
BankSize=16384 #bytes per bank
RAMsize=32768
main_BV_SetBank(blk,sublk)
main_dumpRAM()
main_SaveRAM()
def main_BV_lockBank(bnum):
#Lock cart before writing
bnum=bnum+0x90
print ('Flash locked to ',hex(bnum))
dev.write(0x01,[0x0A,0x00,0x03,0x70,0x00,0x00,0x70,0x01,0x00,0x70,0x02,bnum]) #Lock flash block
USBbuffer = dev.read(0x81,64)
def main_BV_SetBank(blk,sublk):#1-4:1-4
#Lock cart before writing
sublk = sublk * 64
print (hex(blk),hex(sublk))
dev.write(0x01,[0x0A,0x00,0x03,0x70,0x00,sublk,0x70,0x01,0xE0,0x70,0x02,blk]) #Lock flash block
USBbuffer = dev.read(0x81,64)
def main_BV_Flash_ROM(block):
FFtest=""
FFtest=b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'
main_LoadROM()
FlashBlockSize=131072
messagebox.showinfo('Block Change Required','Please remove and insert Flash cart, then click OK')
main_BV_lockBank(block)
print ('from flashrom() ',ROMsize,FlashBlockSize)
NumOfBlks=int(ROMsize/FlashBlockSize)
if NumOfBlks==0:
NumOfBlks=1
print ('erasing ',NumOfBlks)
print('Erasing ROM Area required for flash')
for blknum in range (0,NumOfBlks):
main_BV_EraseFlashBlock(blknum)
print('Writing ROM Data')
ROMpos=0
waitcount=0
for BankNumber in range (0,int((ROMsize/16384))):
main_ROMBankSwitch(BankNumber) #Set the bank
print ( BankNumber*16384, ' of ' ,ROMsize)
for ROMAddress in range (0x4000,0x8000,32):
if BankNumber==0:
ROMAddress=ROMAddress-0x4000
AddHi=ROMAddress>>8
AddLo=ROMAddress&0xFF
Data32Bytes=ROMbuffer[ROMpos:ROMpos+32]
if Data32Bytes == FFtest:
pass
else:
AddHi=AddHi.to_bytes(1,'little')
AddLo=AddLo.to_bytes(1,'little')
FlashWriteCommand=b'\x20\x00\x04\x2A\x0A\xAA\xA9\x05\x55\x56'+AddHi+AddLo+b'\x26'+AddHi+AddLo+b'\x1F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
USBoutputPacket = FlashWriteCommand+Data32Bytes
dev.write(0x01,USBoutputPacket)
while main_IsFlashBusy()==1:
pass
waitcount+=1
if waitcount==10:
print ('Error: ',USBoutputPacket,BankNumber,AddHi,AddLo,ROMpos)
waitcount=0
ROMpos+=32
app.lowerLeftLabel.set(str(ROMsize)+' Bytes Written' )
messagebox.showinfo('Block Unlock Required','Writing Complete. Please remove and insert Flash cart, then click OK')
def main_MX_Burn_ROM():
#erase Flash
print ("Erasing Flash")
mx1()
while main_JPN_Read(0)!=255:
pass
print ("Chip erase complete")
main_LoadROM()
addold=0
print('Writing ROM Data')
for address in range (0,ROMsize,32):
AddHi=(address>>16)&0xFF
AddMe=(address>>8)&0xFF
AddLo=address&0xFF
Data32Bytes=ROMbuffer[address:address+32]
AddHi=AddHi.to_bytes(1,'little')
AddMe=AddMe.to_bytes(1,'little')
AddLo=AddLo.to_bytes(1,'little')
FlashWriteCommand=b'\x23'+AddHi+AddMe+AddLo
Data32Bytes=ROMbuffer[address:address+32]
USBoutputPacket = FlashWriteCommand+Data32Bytes
dev.write(0x01,USBoutputPacket)
USBbuffer = dev.read(0x81,64)
print ("writing",address,ROMsize)
app.lowerLeftLabel.set(str(ROMsize)+' Bytes Written' )
messagebox.showinfo('Operation Complete','Writing Complete.')
def mx1():
dev.write(0x01,[0x0A,0x00,0x07, 0x3f,0x00,0x41, 0x55,0x55,0xAA, 0x2A,0xAA,0x55, 0x55,0x55,0x80, 0x55,0x55,0xAA, 0x2A,0xAA,0x55, 0x55,0x55,0x10])
print ("Erasing Flash")
while main_JPN_Read(0)!=255:
pass
print ("Chip erase complete")
def mx2():
dev.write(0x01,[0x23,0x00,0x00,0x20,0x01,0x02,0x03,0x04,0x05,0x06,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55])
USBbuffer = dev.read(0x81,64)
def mx3(address):
AddHi=(address>>16)&0xFF
AddMe=(address>>8)&0xFF
AddLo=address&0xFF
Data32Bytes=b'\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55'
AddHi=AddHi.to_bytes(1,'little')
AddMe=AddMe.to_bytes(1,'little')
AddLo=AddLo.to_bytes(1,'little')
FlashWriteCommand=b'\x23'+AddHi+AddMe+AddLo
USBoutputPacket = FlashWriteCommand+Data32Bytes
dev.write(0x01,USBoutputPacket)
USBbuffer = dev.read(0x81,64)
def main_EMS64_PageSwap():
dev.write(0x01,[0x13])
USBbuffer = dev.read(0x81,64)
def main_EMS64_Burn_ROM():
main_EMS64_Flash_ROM()
pass
def main_EMS64_Flash_ROM():
FFtest=""
for usbfill in range(32):
FFtest=FFtest+"\xFF"
main_LoadROM()
FlashBlockSize=131072
NumOfBlks=int(ROMsize/FlashBlockSize)
if NumOfBlks==0:
NumOfBlks=1
print ('erasing ',NumOfBlks)
print('Erasing ROM Area required for flash')
for blknum in range (0,NumOfBlks):
main_EMS64_EraseFlashBlock(blknum)
print('Writing ROM Data')
ROMpos=0
waitcount=0
for BankNumber in range (0,int((ROMsize/16384))):
main_ROMBankSwitch(BankNumber) #Set the bank
print ( BankNumber*16384, ' of ' ,ROMsize)
for ROMAddress in range (0x4000,0x8000,32):
if BankNumber==0:
ROMAddress=ROMAddress-0x4000
AddHi=ROMAddress>>8
AddLo=ROMAddress&0xFF
Data32Bytes=ROMbuffer[ROMpos:ROMpos+32]
AddHi=AddHi.to_bytes(1,'little')
AddLo=AddLo.to_bytes(1,'little')
#0x21 for flash algo for EMS
FlashWriteCommand=b'\x21\x01\x02\xD0'+AddHi+AddLo+b'\xE8'+AddHi+AddLo+b'\x1F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
USBoutputPacket = FlashWriteCommand+Data32Bytes
dev.write(0x01,USBoutputPacket)
while main_IsFlashBusyEMS()==1:
pass
waitcount+=1
if waitcount==10:
print ('Error: ',USBoutputPacket,BankNumber,AddHi,AddLo,ROMpos)
waitcount=0
ROMpos+=32
app.lowerLeftLabel.set(str(ROMsize)+' Bytes Written' )
messagebox.showinfo('Operation Complete','Writing Complete.')
#return to read mode - datasheet says write 0xFF to any address
main_ROMBankSwitch(0)
dev.write(0x01,[0x0A,0x01,0x01,0x00,0x00,0xFF])
USBbuffer = dev.read(0x81,64)
def main_EMS64_EraseFlashBlock(BlockNum): #1 block = 128kbytes of ROM ()
main_ROMBankSwitch(BlockNum*8)
print ('Erasing Block '+str(BlockNum))
dev.write(0x01,[0x0A,0x01,0x02,0x40,0x00,0x20,0x40,0x00,0xD0])
USBbuffer = dev.read(0x81,64)
waitcount=0
while main_IsFlashBusyEMS()==1:
waitcount+=1
#print (waitcount)
if waitcount==100000:
print ('Error: ',BlockNum)
exit()
#return to read mode - datasheet says write 0xFF to any address
dev.write(0x01,[0x0A,0x01,0x01,0x40,0x00,0xFF])
USBbuffer = dev.read(0x81,64)
print ('Done')
def main_Catskull_erase():
print ("Erasing...")
dev.write(0x01,[0x0A,0x01,0x06,0x55,0x55,0xAA,0x2A,0xAA,0x55,0x55,0x55,0x80,0x55,0x55,0xAA,0x2A,0xAA,0x55,0x55,0x55,0x10])
RAMbuffer= dev.read(0x81,64)
while main_ELCheapo_Read(0)[0]!=0xFF:
pass
print ("Erased")
def main_Catskull_write():
if main_LoadROM() == 1:
main_Catskull_erase()
print('Writing ROM Data')
ROMpos=0
for ROMAddress in range (0x0000,0x8000,1):
AddHi=ROMAddress>>8
AddLo=ROMAddress&0xFF
Data1Byte=ROMbuffer[ROMpos:ROMpos+1]
dev.write(0x01,[0x0A,0x01,0x04,0x55,0x55,0xAA,0x2A,0xAA,0x55,0x55,0x55,0xA0,AddHi,AddLo,Data1Byte[0]])
ROMpos+=1
messagebox.showinfo('Operation Complete','Writing Complete.')
return
#Universal routines
def main_dumpROM():
global ROMbuffer
global USBbuffer
ROMfileName=asksaveasfilename(defaultextension=".GB",filetypes=(("GB ROM File","*.GB"),("GBC ROM File","*.GBC"),("GBA ROM File","*.GBA"),("All Files","*.*")))
if ROMfileName:
ROMfile=open(ROMfileName,'wb')
for bankNumber in range(0,(int(ROMsize/BankSize))):
print ('Dumping ROM:',int(bankNumber*BankSize),' of ',ROMsize)
if bankNumber == 0:
ROMaddress=0 #get bank 0 from address 0, not setbank(0) and get from high bank...
else:
ROMaddress=BankSize
main_ROMBankSwitch(bankNumber) #switch to new bank.
for packetNumber in range(0,(int(BankSize/64))):
AddHi=ROMaddress>>8
AddLo=ROMaddress&0xFF
dev.write(0x01,[0x10,0x00,0x00,AddHi,AddLo])
ROMbuffer= dev.read(0x81,64)
ROMfile.write(ROMbuffer)
ROMaddress += 64
ROMfile.close()
print ('Done!')
def main_dumpMXROM():
global ROMbuffer
global USBbuffer
ROMfileName=asksaveasfilename(filetypes=(("GB ROM File","*.GB"),("GBC ROM File","*.GBC"),("GBA ROM File","*.GBA"),("All Files","*.*")))
if ROMfileName:
ROMfile=open(ROMfileName,'wb')
for bankNumber in range(0,(int(ROMsize/BankSize))):
print ('Dumping ROM:',int(bankNumber*BankSize),' of ',ROMsize)
if bankNumber == 0:
ROMaddress=0 #get bank 0 from address 0, not setbank(0) and get from high bank...
else:
ROMaddress=BankSize
main_MXROMBankSwitch(bankNumber) #switch to new bank.
for packetNumber in range(0,(int(BankSize/64))):
AddHi=ROMaddress>>8
AddLo=ROMaddress&0xFF
dev.write(0x01,[0x10,0x00,0x00,AddHi,AddLo])
ROMbuffer= dev.read(0x81,64)
ROMfile.write(ROMbuffer)
ROMaddress += 64
ROMfile.close()
print ('Done!')
def main_dumpRAM():
global RAMsize
global RAMbuffer
global USBbuffer
global BankSize
RAMbuffer=b''
for bankNumber in range(0,(int(RAMsize/8192))):