summaryrefslogtreecommitdiff
path: root/tools/pokemontools/lz.py
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-06-14 18:08:43 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2020-06-14 18:08:43 -0400
commit94a70b63cf7f1a9dbfc14fcee8e390791fc17a1b (patch)
treed1b2bb44621d8c2ebae4a613669eb75e37e507ad /tools/pokemontools/lz.py
parent7f6bc3d3826fe7727bdc8714aa0295a712a548c3 (diff)
Sync tools with pokecrystal (fixes warnings when building lzcomp)
palette.c and png_dimensions.c will be synced when they are used.
Diffstat (limited to 'tools/pokemontools/lz.py')
-rw-r--r--tools/pokemontools/lz.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/tools/pokemontools/lz.py b/tools/pokemontools/lz.py
index f48be45c..aef5c641 100644
--- a/tools/pokemontools/lz.py
+++ b/tools/pokemontools/lz.py
@@ -44,8 +44,8 @@ lz_end = 0xff
bit_flipped = [
- sum(((byte >> i) & 1) << (7 - i) for i in range(8))
- for byte in range(0x100)
+ sum(((byte >> i) & 1) << (7 - i) for i in xrange(8))
+ for byte in xrange(0x100)
]
@@ -189,7 +189,7 @@ class Compressed:
)
for method in self.lookback_methods:
min_score = self.min_scores[method]
- for address in range(self.address+1, self.address+best_score):
+ for address in xrange(self.address+1, self.address+best_score):
length, index = self.find_lookback(method, address)
if length > max(min_score, best_score):
# BUG: lookbacks can reduce themselves. This appears to be a bug in the target also.
@@ -211,7 +211,7 @@ class Compressed:
def find_lookback(self, method, address=None):
"""Temporarily stubbed, because the real function doesn't run in polynomial time."""
- return 0, None
+ return 0, None
def broken_find_lookback(self, method, address=None):
if address is None:
@@ -315,15 +315,15 @@ class Compressed:
def do_winner(self):
winners = filter(
- lambda method_score:
- method_score[1]
- > self.min_scores[method_score[0]] + int(method_score[1] > lowmax),
+ lambda (method, score):
+ score
+ > self.min_scores[method] + int(score > lowmax),
self.scores.iteritems()
)
winners.sort(
- key = lambda method_score: (
- -(method_score[1] - self.min_scores[method_score[0]] - int(method_score[1] > lowmax)),
- self.preference.index(method_score[0])
+ key = lambda (method, score): (
+ -(score - self.min_scores[method] - int(score > lowmax)),
+ self.preference.index(method)
)
)
winner, score = winners[0]
@@ -368,11 +368,11 @@ class Compressed:
output += [offset / 0x100, offset % 0x100] # big endian
if self.debug:
- print(' '.join(map(str, [
+ print ' '.join(map(str, [
cmd, length, '\t',
' '.join(map('{:02x}'.format, output)),
self.data[start_address:start_address+length] if cmd in self.lookback_methods else '',
- ])))
+ ]))
self.output += output
@@ -414,7 +414,7 @@ class Decompressed:
if self.lz is not None:
self.decompress()
- if self.debug: print(self.command_list())
+ if self.debug: print self.command_list()
def command_list(self):
@@ -543,7 +543,7 @@ class Decompressed:
Write alternating bytes.
"""
alts = [self.next(), self.next()]
- self.output += [ alts[x & 1] for x in range(self.length) ]
+ self.output += [ alts[x & 1] for x in xrange(self.length) ]
def blank(self):
"""
@@ -575,6 +575,6 @@ class Decompressed:
self.get_offset()
self.direction = direction
# Note: appends must be one at a time (this way, repeats can draw from themselves if required)
- for i in range(self.length):
+ for i in xrange(self.length):
byte = self.output[ self.offset + i * direction ]
self.output.append( table[byte] if table else byte )