Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #======================================================================
- # PICO decompressor
- # Tested on Ojamajo/Magical Doremi #
- # (MasterVisualList at $70000,
- # the compressed graphics, palettes and tilemaps are located here)
- #
- # Usage:
- # this_script.py PICO_ROM.bin offset
- #======================================================================
- import sys
- import os.path
- #======================================================================
- # -------------------------------------------------
- # Main
- # -------------------------------------------------
- if len(sys.argv) == 1:
- print("Usage: input_file offset")
- exit()
- if os.path.exists(sys.argv[1]) == False:
- print("Input file not found")
- exit()
- MASTERNAME = sys.argv[1][:-4]
- offset = int("0x"+sys.argv[2],16)
- input_file = open(sys.argv[1],"rb")
- output_file = open(MASTERNAME+"_"+str(hex(offset)[2:].upper())+".bin","wb+")
- # -------------------------------------------------
- Looping = True
- input_file.seek(offset)
- while Looping:
- d0 = 0
- d0 = ord(input_file.read(1)) & 0xFF
- if (d0 & 0x80) == 0x80:
- d0 -= 0x7E
- d2 = 0
- d2 = ord(input_file.read(1)) & 0xFF
- d2 += 1
- a4 = output_file.tell()
- a6 = output_file.tell()
- a4 -= d2
- for i in range(0,d0+1):
- #print(hex(a4),hex(a6),hex(d0))
- output_file.seek(a4)
- gotbyt = ord(output_file.read(1)) & 0xFF
- output_file.seek(a6)
- output_file.write(bytes([gotbyt]))
- a4 += 1
- a6 += 1
- output_file.seek(a6) # return output
- elif d0 != 0:
- for i in range(0,d0):
- gotbyt = ord(input_file.read(1)) & 0xFF
- output_file.write(bytes([gotbyt]))
- else:
- #print("End of Data")
- Looping = False
- #ROM:00001DD6 PicoDecomp: ; CODE XREF: PicoVdp_PkDataComp+1Ap
- #ROM:00001DD6 movem.l d0-d7/a3-a4,-(sp)
- #ROM:00001DDA
- #ROM:00001DDA loc_0_1DDA: ; CODE XREF: PicoDecomp+18j
- #ROM:00001DDA ; PicoDecomp+30j
- #ROM:00001DDA moveq #0,d0
- #ROM:00001DDC move.b (a5)+,d0
- #ROM:00001DDE bmi.w loc_0_1DF0
- #ROM:00001DE2 beq.w PicoDcmp_End
- #ROM:00001DE6 subq.l #1,d0
- #ROM:00001DE8
- #ROM:00001DE8 loc_0_1DE8: ; CODE XREF: PicoDecomp+14j
- #ROM:00001DE8 move.b (a5)+,(a6)+
- #ROM:00001DEA dbf d0,loc_0_1DE8
- #ROM:00001DEE bra.s loc_0_1DDA
- #ROM:00001DF0 ; ---------------------------------------------------------------------------
- #ROM:00001DF0
- #ROM:00001DF0 loc_0_1DF0: ; CODE XREF: PicoDecomp+8j
- #ROM:00001DF0 subi.l #$7E,d0 ; '~'
- #ROM:00001DF6 moveq #0,d2
- #ROM:00001DF8 move.b (a5)+,d2
- #ROM:00001DFA addq.l #1,d2
- #ROM:00001DFC movea.l a6,a4
- #ROM:00001DFE suba.l d2,a4
- #ROM:00001E00
- #ROM:00001E00 loc_0_1E00: ; CODE XREF: PicoDecomp+2Cj
- #ROM:00001E00 move.b (a4)+,(a6)+
- #ROM:00001E02 dbf d0,loc_0_1E00
- #ROM:00001E06 bra.s loc_0_1DDA
- #ROM:00001E08 ; ---------------------------------------------------------------------------
- #ROM:00001E08
- #ROM:00001E08 PicoDcmp_End: ; CODE XREF: PicoDecomp+Cj
- #ROM:00001E08 movem.l (sp)+,d0-d7/a3-a4
- #ROM:00001E0C rts
- # ======================================================================
- # ----------------------------
- # End
- # ----------------------------
- print("Done.")
- input_file.close()
- output_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement