-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathftsGetMemoryBlockSizeAndOffsetIdAndDescriptionForAddress.py
29 lines (27 loc) · 1.45 KB
/
ftsGetMemoryBlockSizeAndOffsetIdAndDescriptionForAddress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from .fsGetNumberDescription import fsGetNumberDescription;
from .fsNumberOfBytes import fsNumberOfBytes;
def ftsGetMemoryBlockSizeAndOffsetIdAndDescriptionForAddress(uBlockStartAddress, uBlockSize, sBlockType, uAddress):
sSizeId = "[%s]" % fsGetNumberDescription(uBlockSize);
sSizeDescription = "a %s %s block at 0x%X" % (fsNumberOfBytes(uBlockSize), sBlockType, uBlockStartAddress);
iOffsetFromStartOfBlock = uAddress - uBlockStartAddress;
if iOffsetFromStartOfBlock < 0:
# "-X" means at X bytes before the block
sOffsetId = "-%s" % fsGetNumberDescription(-iOffsetFromStartOfBlock, "-");
sOffsetDescription = "%s before" % fsNumberOfBytes(-iOffsetFromStartOfBlock);
else:
iOffsetFromEndOfBlock = iOffsetFromStartOfBlock - uBlockSize;
if iOffsetFromEndOfBlock < 0:
# "@X" means at X bytes within the block
sOffsetId = "@%s" % fsGetNumberDescription(iOffsetFromStartOfBlock);
if iOffsetFromStartOfBlock == 0:
sOffsetDescription = "at the start of";
else:
sOffsetDescription = "%s into" % fsNumberOfBytes(iOffsetFromStartOfBlock);
else:
# "+X" means X bytes beyond the block
sOffsetId = "+%s" % fsGetNumberDescription(iOffsetFromEndOfBlock);
if iOffsetFromEndOfBlock == 0:
sOffsetDescription = "at the end of";
else:
sOffsetDescription = "%s beyond" % fsNumberOfBytes(iOffsetFromEndOfBlock);
return (sSizeId, sOffsetId, sOffsetDescription, sSizeDescription);