Skip to content

Commit

Permalink
Further Python 3 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboddie committed Mar 3, 2024
1 parent 347a74f commit 13ac004
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Fixes/Lunar_Rescue/patch_file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import commands, os, sys
import os, shlex, sys

# Patch out the JMP (&FFFC) reset call EORed with 0x0e in the final file.
# 0x04 is 0xea ^ 0x0e where 0xea is the opcode for NOP.
t = open("temp/Lunar3\xc3", "rb").read()
t = t[:0x261e] + b"\x04\x04\x04" + t[0x2621:]
open("temp/Lunar3\xc3", "wb").write(t)

os.system("UEFtrans.py " + commands.mkarg(sys.argv[1]) + " insert 3 temp/Lunar3\xc3")
os.system("UEFtrans.py " + shlex.quote(sys.argv[1]) + " insert 3 temp/Lunar3\xc3")
23 changes: 8 additions & 15 deletions UEFtrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,19 +541,18 @@ def create_chunks(file_names, gaps = True):

# Find the .inf file and read the details stored within
try:
details = open(name + suffix + 'inf', 'r').readline()
details = open(name + suffix + 'inf', 'rb').readline()
except IOError:

try:
details = open(name + suffix + 'INF', 'r').readline()
details = open(name + suffix + 'INF', 'rb').readline()
except IOError:
print("Couldn't open information file, %s" % name+suffix+'inf')
sys.exit()

# Parse the details
details = [details.rstrip()]

splitters = [' ', '\011']
splitters = [b' ', b'\011']

# Split the details up where certain whitespace characters occur
for s in splitters:
Expand All @@ -562,7 +561,6 @@ def create_chunks(file_names, gaps = True):

# Split up each substring (list entry)
for d in details:

new_details = new_details + d.split(s)

details = new_details
Expand All @@ -584,7 +582,7 @@ def create_chunks(file_names, gaps = True):
in_file.seek(0, 0)

# Examine the name entry and take the load and execution addresses.
dot_at = details[0].find('.')
dot_at = details[0].find(b'.')
if dot_at != -1:
real_name = details[0][dot_at+1:]
load, exe = details[1], details[2]
Expand All @@ -597,7 +595,7 @@ def create_chunks(file_names, gaps = True):

if load == None or exe == None:
print('Problem with %s: information is possibly incorrect.' % \
name+suffix+'inf')
name+suffix+'inf')

sys.exit()

Expand All @@ -609,17 +607,12 @@ def create_chunks(file_names, gaps = True):

# Write block details.
while True:
block, last = write_block(
in_file, real_name.encode("ascii"), load, exe, length, block_number
)
block, last = write_block(in_file, real_name, load, exe, length, block_number)

if gap == 1:

new_chunks.append((0x110, struct.pack("<H", 0x05dc)))
gap = 0

else:

new_chunks.append((0x110, struct.pack("<H", 0x0258)))

# Write the block to the list of new chunks.
Expand Down Expand Up @@ -747,7 +740,7 @@ def export_file(out_path, chunks, name, write_name, load, exe, length):
try:

inf_file = open(
out_path + os.sep + write_name + suffix + 'inf', 'w'
out_path + os.sep + write_name + suffix + 'inf', 'wb'
)

except IOError:
Expand All @@ -757,7 +750,7 @@ def export_file(out_path, chunks, name, write_name, load, exe, length):
if inf_file != None:

# Write information to the .inf file
inf_file.write('$.%s\t%x\t%x\t%x\n' % (name.decode("ascii"), load, exe, length))
inf_file.write(b'$.%s\t%x\t%x\t%x\n' % (name, load, exe, length))

# Read the blocks from the UEF file and write
# them to the file
Expand Down

0 comments on commit 13ac004

Please sign in to comment.