-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a779a3d
commit 3ba60c3
Showing
33 changed files
with
2,016 additions
and
943 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
# UTF-8 | ||
import sys | ||
import sys, traceback | ||
from PySide2.QtCore import QThread, Signal | ||
|
||
class DataTransfer(QThread): | ||
CONFIG = None | ||
RUNNING = False | ||
FINISHED = False | ||
|
||
updateProgress = Signal(object, int, int, float, float, float) | ||
updateProgress = Signal(object) | ||
|
||
def __init__(self, config=None): | ||
QThread.__init__(self) | ||
if config is not None: | ||
self.CONFIG = config | ||
self.FINISHED = False | ||
|
||
def setConfig(self, config): | ||
self.CONFIG = config | ||
|
||
self.FINISHED = False | ||
|
||
def isRunning(self): | ||
return self.RUNNING | ||
return not self.FINISHED | ||
|
||
def run(self): | ||
try: | ||
if self.CONFIG == None: | ||
pass | ||
elif self.CONFIG['mode'] == 1: | ||
self.RUNNING = True | ||
self.CONFIG['port']._TransferData(1, self.updateProgress, [ self.CONFIG['path'], self.CONFIG['mbc'], self.CONFIG['rom_banks'], self.CONFIG['agb_rom_size'] ]) | ||
self.RUNNING = False | ||
elif self.CONFIG['mode'] == 2: | ||
self.RUNNING = True | ||
self.CONFIG['port']._TransferData(2, self.updateProgress, [ self.CONFIG['path'], self.CONFIG['mbc'], self.CONFIG['save_type'] ]) | ||
self.RUNNING = False | ||
elif self.CONFIG['mode'] == 3: | ||
self.RUNNING = True | ||
self.CONFIG['port']._TransferData(3, self.updateProgress, [ self.CONFIG['path'], self.CONFIG['mbc'], self.CONFIG['save_type'], self.CONFIG['erase'] ]) | ||
self.RUNNING = False | ||
elif self.CONFIG['mode'] == 4: | ||
self.RUNNING = True | ||
self.CONFIG['port']._TransferData(4, self.updateProgress, [ self.CONFIG['path'], self.CONFIG['cart_type'], self.CONFIG['trim_rom'], self.CONFIG['override_voltage'] ]) | ||
self.RUNNING = False | ||
|
||
|
||
else: | ||
self.FINISHED = False | ||
self.CONFIG['port']._TransferData(self.CONFIG, self.updateProgress) | ||
self.FINISHED = True | ||
|
||
except Exception as e: | ||
self.updateProgress.emit({"action":"ABORT", "info_type":"msgbox_critical", "info_msg":"An error has occured!\nPlease try to reconnect the hardware and restart the application.\n\n" + str(e), "abortable":False}, 0, 0, 0, 0, 0) | ||
self.RUNNING = False | ||
traceback.print_exc() | ||
self.updateProgress.emit({"action":"ABORT", "info_type":"msgbox_critical", "info_msg":"An error has occured!\nPlease try to reconnect the hardware and restart the application.\n\n{:s}: {:s}".format(type(e).__name__, str(e)), "abortable":False}) | ||
self.FINISHED = True |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
# UTF-8 | ||
import math, time, datetime, copy | ||
|
||
# Utility functions | ||
def bitswap(n, s): | ||
p, q = s | ||
if (((n & (1 << p)) >> p) ^ ((n & (1 << q)) >> q)) == 1: | ||
n ^= (1 << p) | ||
n ^= (1 << q) | ||
return n | ||
|
||
def ParseCFI(buffer): | ||
buffer = copy.copy(buffer) | ||
info = {} | ||
magic = "{:s}{:s}{:s}".format(chr(buffer[0x20]), chr(buffer[0x22]), chr(buffer[0x24])) | ||
if magic != "QRY": # nothing swapped | ||
return False | ||
|
||
try: | ||
info["flash_id"] = buffer[0:8] | ||
info["magic"] = "{:s}{:s}{:s}".format(chr(buffer[0x20]), chr(buffer[0x22]), chr(buffer[0x24])) | ||
|
||
if buffer[0x36] == 0xFF and buffer[0x48] == 0xFF: | ||
print("FAIL: No information about the voltage range found in CFI data.") | ||
try: | ||
with open("./cfi_debug.bin", "wb") as f: f.write(buffer) | ||
except: | ||
pass | ||
return False | ||
|
||
info["vdd_min"] = (buffer[0x36] >> 4) + ((buffer[0x36] & 0x0F) / 10) | ||
info["vdd_max"] = (buffer[0x38] >> 4) + ((buffer[0x38] & 0x0F) / 10) | ||
|
||
if buffer[0x3E] > 0 and buffer[0x3E] < 0xFF: | ||
info["single_write"] = True | ||
info["single_write_time_avg"] = int(math.pow(2, buffer[0x3E])) | ||
info["single_write_time_max"] = int(math.pow(2, buffer[0x46]) * info["single_write_time_avg"]) | ||
else: | ||
info["single_write"] = False | ||
|
||
if buffer[0x40] > 0 and buffer[0x40] < 0xFF: | ||
info["buffer_write"] = True | ||
info["buffer_write_time_avg"] = int(math.pow(2, buffer[0x40])) | ||
info["buffer_write_time_max"] = int(math.pow(2, buffer[0x48]) * info["buffer_write_time_avg"]) | ||
else: | ||
info["buffer_write"] = False | ||
|
||
if buffer[0x42] > 0 and buffer[0x42] < 0xFF: | ||
info["sector_erase"] = True | ||
info["sector_erase_time_avg"] = int(math.pow(2, buffer[0x42])) | ||
info["sector_erase_time_max"] = int(math.pow(2, buffer[0x4A]) * info["sector_erase_time_avg"]) | ||
else: | ||
info["sector_erase"] = False | ||
|
||
if buffer[0x44] > 0 and buffer[0x44] < 0xFF: | ||
info["chip_erase"] = True | ||
info["chip_erase_time_avg"] = int(math.pow(2, buffer[0x44])) | ||
info["chip_erase_time_max"] = int(math.pow(2, buffer[0x4C]) * info["chip_erase_time_avg"]) | ||
else: | ||
info["chip_erase"] = False | ||
|
||
info["tb_boot_sector"] = False | ||
if "{:s}{:s}{:s}".format(chr(buffer[0x80]), chr(buffer[0x82]), chr(buffer[0x84])) == "PRI": | ||
if buffer[0x9E] != 0 and buffer[0x9E] != 0xFF: | ||
temp = { 0x02: 'Bottom Boot Device', 0x03: 'Top Boot Device' } | ||
try: | ||
info["tb_boot_sector"] = "{:s} (0x{:02X})".format(temp[buffer[0x9E]], buffer[0x9E]) | ||
except: | ||
info["tb_boot_sector"] = "0x{:02X}".format(buffer[0x9E]) | ||
elif "{:s}{:s}{:s}".format(chr(buffer[0x214]), chr(buffer[0x216]), chr(buffer[0x218])) == "PRI": | ||
pass # todo | ||
|
||
info["device_size"] = int(math.pow(2, buffer[0x4E])) | ||
info["buffer_size"] = buffer[0x56] << 8 | buffer[0x54] | ||
if info["buffer_size"] > 1: | ||
info["buffer_write"] = True | ||
info["buffer_size"] = int(math.pow(2, info["buffer_size"])) | ||
else: | ||
del(info["buffer_size"]) | ||
info["buffer_write"] = False | ||
info["erase_sector_regions"] = buffer[0x58] | ||
info["erase_sector_blocks"] = [] | ||
total_blocks = 0 | ||
pos = 0 | ||
for i in range(0, min(4, info["erase_sector_regions"])): | ||
b = (buffer[0x5C+(i*8)] << 8 | buffer[0x5A+(i*8)]) + 1 | ||
t = (buffer[0x60+(i*8)] << 8 | buffer[0x5E+(i*8)]) * 256 | ||
total_blocks += b | ||
size = b * t | ||
pos += size | ||
info["erase_sector_blocks"].append([ t, b, size ]) | ||
|
||
except: | ||
print("ERROR: Trying to parse CFI data resulted in an error.") | ||
try: | ||
with open("./cfi_debug.bin", "wb") as f: f.write(buffer) | ||
except: | ||
pass | ||
return False | ||
|
||
return info | ||
|
||
def dprint(*args, **kwargs): | ||
# uncomment for some debug prints | ||
#print(" ".join(map(str, args)), **kwargs) | ||
pass |
Oops, something went wrong.