Merge pull request #1 from FexCollects/python3

modern: Update scripts to Python 3
This commit is contained in:
FexCollects 2024-12-29 11:40:30 -07:00 committed by GitHub
commit edd8b1a2b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 63 additions and 74 deletions

View File

@ -9,7 +9,7 @@ SERIES_2_BERRIES = ginema kuo yago touga niniku topo
PROMO_EN_NUMS = B001 B002
PROMO_EN_TRAINERS = astrid nils
P_PROMO_NUMS = P001 P002 P003 P004 P005 P006 P007 P008
P_PROMO_TRAINERS = craig yasuo darlene mattego hidehiko yufu sagami mattegoDEMO
P_PROMO_TRAINERS = craig yasuo darlene mattego hidehiko yufu sagami mattegoDEMO
N_PROMO_NUMS = N001 N002 N003 N004 N005 N006 N007 N008
N_PROMO_TRAINERS = teruko kimiko norton simon hozumi ritsue yuuma taisen
@ -26,127 +26,127 @@ verify:
trainers/%-EN.tx: trainers/%.asm
python ../scripts/regionalize.py $< $@ EN EN
python3 ../scripts/regionalize.py $< $@ EN EN
trainers/%.o: trainers/%.tx
./rgbasm.exe -o $@ $<
trainers/%.gbc: trainers/%.o
./rgblink.exe -o $@ $<
trainers/%.bin: trainers/%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
trainers/%.z80: trainers/%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
trainers/%.mev: trainers/%.bin
python ../scripts/checksum.py $< $@
python3 ../scripts/checksum.py $< $@
berries/%-EN.tx: berries/%.asm
python ../scripts/regionalize.py $< $@ EN EN
python3 ../scripts/regionalize.py $< $@ EN EN
berries/%.o: berries/%.tx
./rgbasm.exe -o $@ $<
berries/%.gbc: berries/%.o
./rgblink.exe -o $@ $<
berries/%.bin: berries/%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
berries/%.z80: berries/%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
berries/%.mev: berries/%.bin
python ../scripts/checksum.py $< $@
python3 ../scripts/checksum.py $< $@
prologue-%.tx: prologue.asm
python ../scripts/regionalize.py $< $@ $* $*
python3 ../scripts/regionalize.py $< $@ $* $*
prologue-%.o: prologue-%.tx
./rgbasm.exe -o $@ $<
prologue-%.gbc: prologue-%.o
./rgblink.exe -o $@ $<
prologue-%.bin: prologue-%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
battletrainer-%.tx: battletrainer.asm prologue-%.bin
python ../scripts/ereadertext.py $< $@ $*
python3 ../scripts/ereadertext.py $< $@ $*
08-A%-EN.tx: 08-A%.asm battletrainer-EN.tx
python ../scripts/ereadertext.py $< $@ EN
python3 ../scripts/ereadertext.py $< $@ EN
08-A%.o: 08-A%.tx
./rgbasm.exe -o $@ $<
08-A%.gbc: 08-A%.o
./rgblink.exe -o $@ $<
08-A%.z80: 08-A%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
08-A%.vpk: 08-A%.z80
./nevpk.exe -c -i $< -o $@
08-A%.raw: 08-A%.vpk
./nedcmake.exe -i $< -o $@ -type 1 -region 1
08-B%-EN.tx: 08-B%.asm battletrainer-EN.tx
python ../scripts/ereadertext.py $< $@ EN
python3 ../scripts/ereadertext.py $< $@ EN
08-B%.o: 08-B%.tx
./rgbasm.exe -o $@ $<
08-B%.gbc: 08-B%.o
./rgblink.exe -o $@ $<
08-B%.z80: 08-B%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
08-B%.vpk: 08-B%.z80
./nevpk.exe -c -i $< -o $@
08-B%.raw: 08-B%.vpk
./nedcmake.exe -i $< -o $@ -type 1 -region 1
./nedcmake.exe -i $< -o $@ -type 1 -region 1
129-B%-EN.tx: 129-B%.asm battletrainer-EN.tx
python ../scripts/ereadertext.py $< $@ EN
python3 ../scripts/ereadertext.py $< $@ EN
129-B%.o: 129-B%.tx
./rgbasm.exe -o $@ $<
129-B%.gbc: 129-B%.o
./rgblink.exe -o $@ $<
129-B%.z80: 129-B%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
129-B%.vpk: 129-B%.z80
./nevpk.exe -c -i $< -o $@
129-B%.raw: 129-B%.vpk
./nedcmake.exe -i $< -o $@ -type 1 -region 1
enigmaberry-%.tx: enigmaberry.asm prologue-%.bin
python ../scripts/ereadertext.py $< $@ $*
python3 ../scripts/ereadertext.py $< $@ $*
08-K%-EN.tx: 08-K%.asm enigmaberry-EN.tx
python ../scripts/ereadertext.py $< $@ EN
python3 ../scripts/ereadertext.py $< $@ EN
08-K%.o: 08-K%.tx
./rgbasm.exe -o $@ $<
08-K%.gbc: 08-K%.o
./rgblink.exe -o $@ $<
08-K%.z80: 08-K%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
08-K%.vpk: 08-K%.z80
./nevpk.exe -c -i $< -o $@
08-K%.raw: 08-K%.vpk
./nedcmake.exe -i $< -o $@ -type 1 -region 1 -raw
./nedcmake.exe -i $< -o $@ -type 1 -region 1 -raw
08-N%-EN.tx: 08-N%.asm battletrainer-EN.tx
python ../scripts/ereadertext.py $< $@ EN
python3 ../scripts/ereadertext.py $< $@ EN
08-N%.o: 08-N%.tx
./rgbasm.exe -o $@ $<
08-N%.gbc: 08-N%.o
./rgblink.exe -o $@ $<
08-N%.z80: 08-N%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
08-N%.vpk: 08-N%.z80
./nevpk.exe -c -i $< -o $@
08-N%.raw: 08-N%.vpk
./nedcmake.exe -i $< -o $@ -type 1 -region 1
./nedcmake.exe -i $< -o $@ -type 1 -region 1
08-P%-EN.tx: 08-P%.asm battletrainer-EN.tx
python ../scripts/ereadertext.py $< $@ EN
python3 ../scripts/ereadertext.py $< $@ EN
08-P%.o: 08-P%.tx
./rgbasm.exe -o $@ $<
08-P%.gbc: 08-P%.o
./rgblink.exe -o $@ $<
08-P%.z80: 08-P%.gbc
python ../scripts/stripgbc.py $< $@
python3 ../scripts/stripgbc.py $< $@
08-P%.vpk: 08-P%.z80
./nevpk.exe -c -i $< -o $@
08-P%.raw: 08-P%.vpk
./nedcmake.exe -i $< -o $@ -type 1 -region 1
./nedcmake.exe -i $< -o $@ -type 1 -region 1
clean:
rm -f *.z80 *.tx *.o *.gbc *.bin *.raw \
trainers/*.tx trainers/*.o trainers/*.gbc trainers/*.bin trainers/*.mev \
berries/*.tx berries/*.o berries/*.gbc berries/*.bin berries/*.mev
berries/*.tx berries/*.o berries/*.gbc berries/*.bin berries/*.mev

View File

@ -25,4 +25,13 @@ def asmQuote(t):
t = t[1:]
if quoted:
result += '"'
return result
return result
def asmQuoteBytes(t):
result = ""
for b in t:
result += '{0}'.format(ord(b)) + ","
result = result[:-1]
return result

View File

@ -11,7 +11,6 @@ wordwise_results = []
crcs = []
crc_results = []
data = ""
with open(sys.argv[1], 'rb') as f:
data = f.read()
f.closed
@ -19,7 +18,7 @@ f.closed
base_address = struct.unpack('<I', data[1:5])[0]
i = 0x11 # first chunk location
while i < len(data):
chunk_type = ord(data[i])
chunk_type = data[i]
if chunk_type == 0x02: # END_OF_CHUNKS
break
elif chunk_type == 0x07: # CUSTOM_BERRY
@ -37,7 +36,7 @@ while i < len(data):
end_address = struct.unpack('<I', data[i+9:i+13])[0] - base_address
crcs.append([i + 1, start_address, end_address])
elif chunk_type < 0x02 or chunk_type > 0x10:
print "Unknown chunk {0:X}".format(chunk_type)
print("Unknown chunk {0:X}".format(chunk_type))
raise TypeError
i += chunk_lengths[chunk_type]
@ -58,7 +57,7 @@ for wordwise in wordwises:
for bytewise in bytewises:
sum = 0
for i in range(bytewise[1], bytewise[2]):
sum = (sum + ord(data[i])) & 0xFFFFFFFF
sum = (sum + data[i]) & 0xFFFFFFFF
bytewise_results.append(sum)
i = 0
for bytewise in bytewises:
@ -70,7 +69,7 @@ for bytewise in bytewises:
for crc in crcs:
sum = 0x1121
for i in range(crc[1], crc[2]):
sum ^= ord(data[i])
sum ^= data[i]
for j in range(8):
if(sum & 1):
sum = (sum >> 1) ^ 0x8408
@ -86,5 +85,5 @@ for crc in crcs:
# write the updated file
out = open(sys.argv[2], 'w')
out.write(data)
out = open(sys.argv[2], 'wb')
out.write(data)

View File

@ -52,7 +52,7 @@ for i in pos:
start_address = struct.unpack('<I', data[i+1:i+5])[0] - base_address
wordwises.append([start_address + 0x13C, start_address, start_address + 0x13C])
elif chunk_type < 0x02 or chunk_type > 0x11:
print "Unknown chunk {0:X}".format(chunk_type)
print("Unknown chunk {0:X}".format(chunk_type))
raise TypeError
i += chunk_lengths[chunk_type]

View File

@ -7,7 +7,7 @@ region = sys.argv[3]
out = open(sys.argv[2], 'w')
with open(sys.argv[1], 'rb') as f:
with open(sys.argv[1], 'r') as f:
for asm in f:
asms = asm.split('"')
command = asms[0].strip()
@ -17,11 +17,11 @@ with open(sys.argv[1], 'rb') as f:
asms[1] = asms[1].replace('\\n', '\n')
asms[1] = asms[1].replace('é', '\x7F')
out.write("db " + asmQuote(asms[1]) + "\n")
out.write("\tdb " + asmQuote(asms[1]) + "\n")
else:
out.write(asm)
if "macros.asm" in asm:
out.write("REGION EQU REGION_{0}\n".format(region))
out.write('REGION_NAME EQUS "{0}"\n'.format(region))
f.closed
f.closed

View File

@ -431,27 +431,8 @@ def utf8ToRSText(t, region = ""):
if region == "DE":
chars[''] = '\xB2'
characters = []
char = ""
while len(t):
if ord(t[0]) >= 0xF0:
char += t[0:4]
t = t[4:]
elif ord(t[0]) >= 0xE0:
char += t[0:3]
t = t[3:]
elif ord(t[0]) >= 0xC0:
char += t[0:2]
t = t[2:]
else:
char += t[0:1]
t = t[1:]
if char != "\\" and char != "\\v" and (char[0:2] != "\\{" or char[-1] == "}"):
characters.append(char)
char = ""
result = ""
for char in characters:
for char in t:
result += chars[char]
return result
@ -479,4 +460,4 @@ def asmQuote(t):
t = t[1:]
if quoted:
result += '"'
return result
return result

View File

@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
import sys
from gen3text import utf8ToRSText
from asmquote import asmQuote
from asmquote import asmQuoteBytes
data_region = sys.argv[3] # determines region code
text_region = sys.argv[4] # determines string translation
out = open(sys.argv[2], 'w')
with open(sys.argv[1], 'rb') as f:
with open(sys.argv[1], 'r') as f:
for asm in f:
asms = asm.split('"')
command = asms[0].strip()
@ -23,11 +23,11 @@ with open(sys.argv[1], 'rb') as f:
asms[1] += "\x00"
except ValueError:
pass
out.write("db " + asmQuote(asms[1]) + "\n")
out.write("\tdb " + asmQuoteBytes(asms[1]) + "\n")
elif len(command) < 5 or command[0:5] != "Text_":
out.write(asm)
if "macros.asm" in asm:
# cant do this until after REGION_EN, etc. are loaded
out.write("REGION EQU REGION_" + data_region + "\n")
# else this is foreign text, delete it
f.closed
f.closed

View File

@ -2,9 +2,9 @@
#!/usr/bin/env python2.7
import sys
out = open(sys.argv[2], 'w')
out = open(sys.argv[2], 'wb')
buffering = False
buf = ""
buf = bytes()
with open(sys.argv[1], 'rb') as f:
f.read(256) # skip to $0100
while True:
@ -23,8 +23,8 @@ with open(sys.argv[1], 'rb') as f:
elif buffering:
out.write(buf)
out.write(byte)
buf = ""
buf = bytes()
buffering = False
else:
out.write(byte)
f.closed
f.closed