GenesisFan64

SpinballExtract

Jul 26th, 2021 (edited)
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. # SPINBALL text extractor
  2. # notes:
  3. # PEA (label).l | 0x4879 label
  4.  
  5. # User
  6. Rom_File = "Sonic Spinball (U) [!].bin"
  7. Tag_File = "str_list.txt"
  8.  
  9. # Variables
  10. TAG_PEA = 0x4879
  11.  
  12. # subs
  13. def add_tag(got_pos):
  14.  global SRCH_STR
  15.  
  16.  # String found, add to database
  17.  output_file.write(str(got_pos)) # read address
  18.  output_file.write(str("|")) # separator
  19.  output_file.write(str(SRCH_STR)) # string data
  20.  output_file.write(str("|")) # separator
  21.  
  22.  input_file.seek(SRCH_STR) #copy string (needs to check for 0xFF align)
  23.  d = True
  24.  output_file.write(chr(0x22)) # "
  25.  while d:
  26.   a = input_file.read(1).decode("ascii")
  27.   input_file.seek(-1,1)
  28.   b = ord(input_file.read(1))
  29.   if b != 0:
  30.     output_file.write(str(a))
  31.   else:
  32.     SRCH_STR = input_file.tell()
  33.     a = ord(input_file.read(1))
  34.     if a == 0xFF:
  35.      SRCH_STR = input_file.tell()
  36.     d = False
  37.  
  38.  output_file.write(chr(0x22)) # "
  39.  output_file.write("\n")
  40.  
  41. input_file = open(Rom_File,"rb")
  42. output_file = open(Tag_File,"w")
  43.  
  44. # *********************************************
  45. # Start
  46. # *********************************************
  47.  
  48. got_text = 1
  49.  
  50. # *** First pass ***
  51. print("FIRST PASS")
  52. SRCH_STR = 0xBE248
  53. NUMOF_STR = 293
  54. wrk = NUMOF_STR
  55. curr_pos = 0
  56. while wrk:
  57.  # DIRECT SEARCH
  58.  input_file.seek(curr_pos)
  59.  a = (ord(input_file.read(1))&0xFF) << 24
  60.  b = (ord(input_file.read(1))&0xFF) << 16
  61.  c = (ord(input_file.read(1))&0xFF) << 8
  62.  d = ord(input_file.read(1))&0xFF
  63.  e = a|b|c|d
  64.  curr_pos += 2 # <-- word align
  65.  if e == SRCH_STR:
  66.    wrk -= 1
  67.    got_pos = curr_pos-2
  68.    print("Got text",got_text,"of",NUMOF_STR,":",hex(got_pos))
  69.    add_tag(got_pos)
  70.    #print("Next:",hex(SRCH_STR))
  71.    curr_pos = 0
  72.    got_text += 1
  73.  
  74. # *** Second pass ***
  75. print("SECOND PASS")
  76. SRCH_STR = 0xC14B0
  77. NUMOF_STR = 5
  78. wrk = NUMOF_STR
  79. curr_pos = 0
  80. while wrk:
  81.  # DIRECT SEARCH
  82.  input_file.seek(curr_pos)
  83.  a = (ord(input_file.read(1))&0xFF) << 24
  84.  b = (ord(input_file.read(1))&0xFF) << 16
  85.  c = (ord(input_file.read(1))&0xFF) << 8
  86.  d = ord(input_file.read(1))&0xFF
  87.  e = a|b|c|d
  88.  curr_pos += 2 # <-- word align
  89.  if e == SRCH_STR:
  90.    wrk -= 1
  91.    got_pos = curr_pos-2
  92.    print("Got text",got_text,"of",NUMOF_STR,":",hex(got_pos))
  93.    add_tag(got_pos)
  94.    #print("Next:",hex(SRCH_STR))
  95.    curr_pos = 0
  96.    got_text += 1
  97.  
  98.  # PEA SEARCH
  99.  #input_file.seek(curr_pos)
  100.  #b = (ord(input_file.read(1))&0xFF) << 8
  101.  #a = ord(input_file.read(1))&0xFF
  102.  #c = a|b
  103.  #if c == TAG_PEA:
  104.   #a = (ord(input_file.read(1))&0xFF) << 24
  105.   #b = (ord(input_file.read(1))&0xFF) << 16
  106.   #c = (ord(input_file.read(1))&0xFF) << 8
  107.   #d = ord(input_file.read(1))&0xFF
  108.   #e = a|b|c|d
  109.   #if e == SRCH_STR:
  110.     #wrk -= 1
  111.     #got_pos = curr_pos+1
  112.     #print("FOUND AT:",hex(got_pos))
  113.     #add_tag(got_pos)
Add Comment
Please, Sign In to add comment