Created
February 8, 2019 18:08
-
-
Save endrift/2a7e52cf953078a8a59f911274534275 to your computer and use it in GitHub Desktop.
GBA link cable logic analyzer decoder
This file contains hidden or 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
import csv | |
input_file = 'rme4bcg.csv' | |
output_file = 'rme4bcg-decoded.csv' | |
with open(input_file) as c: | |
with open(output_file, 'w') as c2: | |
c.readline() | |
log = csv.reader(c) | |
out = csv.writer(c2) | |
out.writerow(['timestamp', 'player', 'current_word']) | |
active = False | |
start = 0 | |
bit = True | |
current_word_bits = 0 | |
current_word = 0 | |
old_bit = True | |
player = 0 | |
for line in log: | |
new_active = not int(line[1]) | |
new_time = float(line[0]) | |
bit = bool(int(line[2])) | |
if new_active and not active: | |
current_word = 0 | |
current_word_bits = -2 | |
new_active = bit | |
player = 0 | |
if active: | |
assert current_word_bits <= 16 | |
if current_word_bits == -2: | |
if not bit: | |
current_word_bits = -1 | |
elif current_word_bits < 16: | |
bits = int((new_time - start) * 118000) | |
if current_word_bits + bits >= 16: | |
bits = 16 - current_word_bits | |
if old_bit and current_word_bits + bits > 0: | |
current_word |= ((1 << bits) - 1) << max(current_word_bits, 0) | |
current_word_bits += bits | |
if current_word_bits == 16: | |
if not bit or not new_active: | |
#print(player, '0x%04X (%.6f)' % (current_word, new_time)) | |
out.writerow([new_time, player, '0x%04X' % current_word]) | |
if not bit: | |
current_word = 0 | |
current_word_bits = -1 | |
player += 1 | |
start = new_time | |
active = new_active | |
old_bit = bit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment