tikevin83

BizHawk mGBA bk2 to GBI Movie Conversion Python Script

Mar 5th, 2020
125
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. import sys
  3. import os
  4. import zipfile
  5.  
  6. GBP_BUTTON_A      = 0x0001
  7. GBP_BUTTON_B      = 0x0002
  8. GBP_BUTTON_SELECT = 0x0004
  9. GBP_BUTTON_START  = 0x0008
  10. GBP_BUTTON_RIGHT  = 0x0010
  11. GBP_BUTTON_LEFT   = 0x0020
  12. GBP_BUTTON_UP     = 0x0040
  13. GBP_BUTTON_DOWN   = 0x0080
  14. GBP_BUTTON_L      = 0x0100
  15. GBP_BUTTON_R      = 0x0200
  16.  
  17. MAPPING = (GBP_BUTTON_UP,
  18.            GBP_BUTTON_DOWN,
  19.            GBP_BUTTON_LEFT,
  20.            GBP_BUTTON_RIGHT,
  21.            GBP_BUTTON_START,
  22.            GBP_BUTTON_SELECT,
  23.            GBP_BUTTON_B,
  24.            GBP_BUTTON_A,
  25.            GBP_BUTTON_L,
  26.            GBP_BUTTON_R)
  27.  
  28. CYCLES_PER_FRAME = 280896
  29.  
  30. bk2_path = sys.argv[1]
  31. if not os.path.isfile(bk2_path):
  32.     print('ERROR: File does not exist!')
  33.     sys.exit(1)
  34. bk2_abs = os.path.abspath(bk2_path)
  35. bk2 = zipfile.ZipFile(bk2_abs)
  36. inputs = bk2.open('Input Log.txt')
  37. lastInput = ""
  38.  
  39. def convert_frame(data):
  40.   out = 0
  41.   for index, button in enumerate(MAPPING):
  42.     if data[index] != ".":
  43.       out ^= button
  44.   return out
  45.  
  46. cycle = 0
  47. with open("GBItimestamps.txt", "w") as f:
  48.   for line in inputs:
  49.     sline = line.decode().rstrip()
  50.     if sline[0] == "|":
  51.       cycle += CYCLES_PER_FRAME
  52.       data = sline.split(",")[4][:-1]
  53.       if data != lastInput:
  54.         f.write(f"{int((cycle-83776)/4096):08X} {convert_frame(data):04X}\n")
  55.       lastInput = data
RAW Paste Data