Advertisement
GenesisFan64

PicoDecomp

Jul 15th, 2020
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.61 KB | None | 0 0
  1. #======================================================================
  2. # PICO decompressor
  3. # Tested on Ojamajo/Magical Doremi #
  4. # (MasterVisualList at $70000,
  5. # the compressed graphics, palettes and tilemaps are located here)
  6. #
  7. # Usage:
  8. # this_script.py PICO_ROM.bin offset
  9. #======================================================================
  10.  
  11. import sys
  12. import os.path
  13.  
  14. #======================================================================
  15. # -------------------------------------------------
  16. # Main
  17. # -------------------------------------------------
  18.  
  19. if len(sys.argv) == 1:
  20.     print("Usage: input_file offset")
  21.     exit()
  22.    
  23. if os.path.exists(sys.argv[1]) == False:
  24.     print("Input file not found")
  25.     exit()
  26.  
  27. MASTERNAME  = sys.argv[1][:-4]
  28. offset      = int("0x"+sys.argv[2],16)
  29. input_file  = open(sys.argv[1],"rb")
  30. output_file = open(MASTERNAME+"_"+str(hex(offset)[2:].upper())+".bin","wb+")
  31.  
  32. # -------------------------------------------------
  33.  
  34. Looping = True
  35. input_file.seek(offset)
  36. while Looping:
  37.     d0 = 0
  38.     d0 = ord(input_file.read(1)) & 0xFF
  39.     if (d0 & 0x80) == 0x80:
  40.         d0 -= 0x7E
  41.         d2 = 0
  42.         d2 = ord(input_file.read(1)) & 0xFF
  43.         d2 += 1
  44.         a4 = output_file.tell()
  45.         a6 = output_file.tell()
  46.         a4 -= d2
  47.         for i in range(0,d0+1):
  48.             #print(hex(a4),hex(a6),hex(d0))
  49.             output_file.seek(a4)
  50.             gotbyt = ord(output_file.read(1)) & 0xFF
  51.             output_file.seek(a6)
  52.             output_file.write(bytes([gotbyt]))
  53.             a4 += 1
  54.             a6 += 1
  55.         output_file.seek(a6)    # return output
  56.     elif d0 != 0:
  57.         for i in range(0,d0):
  58.             gotbyt = ord(input_file.read(1)) & 0xFF
  59.             output_file.write(bytes([gotbyt]))
  60.     else:
  61.         #print("End of Data")
  62.         Looping = False
  63.    
  64. #ROM:00001DD6 PicoDecomp:                             ; CODE XREF: PicoVdp_PkDataComp+1Ap
  65. #ROM:00001DD6                 movem.l d0-d7/a3-a4,-(sp)
  66. #ROM:00001DDA
  67. #ROM:00001DDA loc_0_1DDA:                             ; CODE XREF: PicoDecomp+18j
  68. #ROM:00001DDA                                         ; PicoDecomp+30j
  69. #ROM:00001DDA                 moveq   #0,d0
  70. #ROM:00001DDC                 move.b  (a5)+,d0
  71. #ROM:00001DDE                 bmi.w   loc_0_1DF0
  72. #ROM:00001DE2                 beq.w   PicoDcmp_End
  73. #ROM:00001DE6                 subq.l  #1,d0
  74. #ROM:00001DE8
  75. #ROM:00001DE8 loc_0_1DE8:                             ; CODE XREF: PicoDecomp+14j
  76. #ROM:00001DE8                 move.b  (a5)+,(a6)+
  77. #ROM:00001DEA                 dbf     d0,loc_0_1DE8
  78. #ROM:00001DEE                 bra.s   loc_0_1DDA
  79. #ROM:00001DF0 ; ---------------------------------------------------------------------------
  80. #ROM:00001DF0
  81. #ROM:00001DF0 loc_0_1DF0:                             ; CODE XREF: PicoDecomp+8j
  82. #ROM:00001DF0                 subi.l  #$7E,d0 ; '~'
  83. #ROM:00001DF6                 moveq   #0,d2
  84. #ROM:00001DF8                 move.b  (a5)+,d2
  85. #ROM:00001DFA                 addq.l  #1,d2
  86. #ROM:00001DFC                 movea.l a6,a4
  87. #ROM:00001DFE                 suba.l  d2,a4
  88. #ROM:00001E00
  89. #ROM:00001E00 loc_0_1E00:                             ; CODE XREF: PicoDecomp+2Cj
  90. #ROM:00001E00                 move.b  (a4)+,(a6)+
  91. #ROM:00001E02                 dbf     d0,loc_0_1E00
  92. #ROM:00001E06                 bra.s   loc_0_1DDA
  93. #ROM:00001E08 ; ---------------------------------------------------------------------------
  94. #ROM:00001E08
  95. #ROM:00001E08 PicoDcmp_End:                           ; CODE XREF: PicoDecomp+Cj
  96. #ROM:00001E08                 movem.l (sp)+,d0-d7/a3-a4
  97. #ROM:00001E0C                 rts
  98.  
  99. # ======================================================================
  100.  
  101. # ----------------------------
  102. # End
  103. # ----------------------------
  104.  
  105. print("Done.")
  106. input_file.close()
  107. output_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement