var File=MSDOS;

includeScript("result");

/**
 * Get the “base” offset, after the header.
 * @param {Int} [nOffset=0] - The offset from the base offset.
 * @returns {Int}
 */
MSDOS.getBaseOffset = function(nOffset)
{
    if(arguments.length==0)
    {
        nOffset=0;
    }
    return (MSDOS.readWord(8)<<4)+nOffset;
}

/**
 * Translate segment/offset address pair to file offset.
 * @param {UShort} nSegment - Segment address.
 * @param {UShort} [nOffset=0] - Offset address.
 * @returns {Int}
 */
MSDOS.AddressToOffset = function(nSegment,nOffset)
{
    if(arguments.length==1)
    {
        nOffset=0;
    }
    nOffset+=nSegment<<4;
    return MSDOS.getBaseOffset(nOffset&0xFFFFF);
}

/**
 * Get the entry point file offset.
 * @param {Int} [nOffset=0] - The offset from the entry point.
 * @returns {Int}
 */
MSDOS.getEntryPointOffset = function(nOffset)
{
    if(arguments.length==0)
    {
        nOffset=0;
    }
    return MSDOS.AddressToOffset(MSDOS.readWord(0x16),MSDOS.readWord(0x14))+nOffset;
}

/**
 * Get the NewExe (or LE/LX) file offset (assuming it's valid).
 * @param {Int} [nOffset=0] - The offset from the NewExe offset.
 * @returns {Int}
 */
MSDOS.getNEOffset = function(nOffset)
{
    if(arguments.length==0)
    {
        nOffset=0;
    }
    return MSDOS.readDword(0x3C)+nOffset;
}
