Skip to content

Commit

Permalink
Don't fail if segments have not been found yet
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Aug 14, 2023
1 parent 2ffa76c commit 4b8e914
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/mapfile_parser/mapfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,6 @@ def __init__(self):
self.debugging: bool = False

def readMapFile(self, mapPath: Path):
tempSegmentsList: list[Segment] = list()
tempFilesListList: list[list[File]] = list()

with mapPath.open("r") as f:
mapData = f.read()

Expand All @@ -410,6 +407,9 @@ def readMapFile(self, mapPath: Path):
mapData = mapData[startIndex:]
# print(len(mapData))

tempSegmentsList: list[Segment] = [Segment("$$dummysegment$$", 0, 0, 0)]
tempFilesListList: list[list[File]] = [[]]

inFile = False

prevLine = ""
Expand All @@ -436,7 +436,7 @@ def readMapFile(self, mapPath: Path):
if not inFile:
fillMatch = regex_fill.search(line)
entryMatch = regex_fileDataEntry.search(line)
loadAddressMatch = regex_segmentEntry.search(line)
segmentEntryMatch = regex_segmentEntry.search(line)

if fillMatch is not None:
# Add *fill* size to last file
Expand All @@ -452,13 +452,14 @@ def readMapFile(self, mapPath: Path):
if size > 0:
inFile = True
tempFile = File(filepath, vram, size, sectionType)
assert len(tempFilesListList) > 0, line
tempFilesListList[-1].append(tempFile)

elif loadAddressMatch is not None:
name = loadAddressMatch["name"]
vram = int(loadAddressMatch["vram"], 0)
size = int(loadAddressMatch["size"], 0)
vrom = int(loadAddressMatch["vrom"], 0)
elif segmentEntryMatch is not None:
name = segmentEntryMatch["name"]
vram = int(segmentEntryMatch["vram"], 0)
size = int(segmentEntryMatch["size"], 0)
vrom = int(segmentEntryMatch["vrom"], 0)

if name == "":
# If the segment name is too long then this line gets break in two lines
Expand All @@ -470,7 +471,8 @@ def readMapFile(self, mapPath: Path):

prevLine = line

for i, segment in enumerate(tempSegmentsList):
# Skip dummy segment
for i, segment in enumerate(tempSegmentsList[1:]):
filesList = tempFilesListList[i]

vromOffset = segment.vrom
Expand Down

0 comments on commit 4b8e914

Please sign in to comment.