Skip to content

Commit

Permalink
Merge branch 'GP-0_ryanmkurtz_PR-6421_haarlaj_mz-header-short-to-uint'
Browse files Browse the repository at this point in the history
(Closes #6421)
  • Loading branch information
ryanmkurtz committed Apr 30, 2024
2 parents 586fc9e + bc6bc67 commit 1d658ea
Showing 1 changed file with 8 additions and 6 deletions.
Expand Up @@ -139,7 +139,7 @@ private void markupHeaders(Program program, FileBytes fileBytes, MzExecutable mz
MessageLog log, TaskMonitor monitor) {
monitor.setMessage("Marking up headers...");
OldDOSHeader header = mz.getHeader();
int blockSize = paragraphsToBytes(header.e_cparhdr());
int blockSize = paragraphsToBytes(Short.toUnsignedInt(header.e_cparhdr()));
try {
Address headerSpaceAddr = AddressSpace.OTHER_SPACE.getAddress(0);
MemoryBlock headerBlock = MemoryBlockUtils.createInitializedBlock(program, true,
Expand All @@ -156,7 +156,7 @@ private void markupHeaders(Program program, FileBytes fileBytes, MzExecutable mz
if (!relocations.isEmpty()) {
DataType relocationType = relocations.get(0).toDataType();
int len = relocationType.getLength();
addr = addr.add(header.e_lfarlc());
addr = addr.add(Short.toUnsignedInt(header.e_lfarlc()));
for (int i = 0; i < relocations.size(); i++) {
monitor.checkCancelled();
DataUtilities.createData(program, addr.add(i * len), relocationType, -1,
Expand Down Expand Up @@ -187,7 +187,8 @@ private void processMemoryBlocks(Program program, FileBytes fileBytes,
knownSegments.add(space.getAddress((INITIAL_SEGMENT_VAL + header.e_cs()) & 0xffff, 0));
}
// Allocate an initialized memory block for each segment we know about
int endOffset = pagesToBytes(header.e_cp() - 1) + header.e_cblp();
int endOffset = pagesToBytes(Short.toUnsignedInt(header.e_cp()) - 1) +
Short.toUnsignedInt(header.e_cblp());
if (endOffset > reader.length()) {
log.appendMsg(
"File is 0x%x bytes but header reports 0x%x".formatted(reader.length(), endOffset));
Expand Down Expand Up @@ -253,7 +254,7 @@ private void processMemoryBlocks(Program program, FileBytes fileBytes,

// Allocate an uninitialized memory block for extra minimum required data space
if (lastBlock != null) {
int extraAllocSize = paragraphsToBytes(header.e_minalloc());
int extraAllocSize = paragraphsToBytes(Short.toUnsignedInt(header.e_minalloc()));
if (extraAllocSize > 0) {
MemoryBlockUtils.createUninitializedBlock(program, false, "DATA",
lastBlock.getEnd().add(1), extraAllocSize, "", "mz", true, true, false, log);
Expand Down Expand Up @@ -475,7 +476,8 @@ private Set<RelocationFixup> getRelocationFixups(SegmentedAddressSpace space,
* @return The segmented addresses converted to a file offset
*/
private int addressToFileOffset(int segment, int offset, OldDOSHeader header) {
return (short) segment * 16 + offset + paragraphsToBytes(header.e_cparhdr());
return (short) segment * 16 + offset +
paragraphsToBytes(Short.toUnsignedInt(header.e_cparhdr()));
}

/**
Expand All @@ -489,7 +491,7 @@ private int paragraphsToBytes(int paragraphs) {
}

/**
* Converts pages to bytes. There are 512 bytes in a paragraph.
* Converts pages to bytes. There are 512 bytes in a page.
*
* @param pages The number of pages
* @return The number of bytes in the given number of pages
Expand Down

0 comments on commit 1d658ea

Please sign in to comment.