main.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 1,056 行 · 第 1/3 页

C
1,056
字号

            case 's':
                {
                    char   *pszPath;
                    iPpfstool=1;
                    if (argv[iArgIndex][2] != '\0')
                    {
                        pszPath = &argv[iArgIndex][2];
                        if (*pszPath == ':')
                        {
                            pszPath++;
                        }
                    }
                    else if (argc > (i+1) && argv[iArgIndex+1][0] != '-' && argv[iArgIndex+1][0] != '/')
                    {
                        pszPath = argv[iArgIndex+1];
                        i++;
                    }
                    else
                    {
                        pszPath = "*.*";
                    }
                    DisplayDirectory(pszPath);
                }
                break;

                case 'g':
                case 'r':
                case 'u':
                {
                    char    *pszSource;
                    char    *pszDestination;

                    iPpfstool=1;
                    if (argv[iArgIndex][2] != '\0')
                    {
                        pszSource = &argv[iArgIndex][2];
                        if (*pszSource == ':')
                        {
                            pszSource++;
                        }
                    }
                    else if (argc > (iArgIndex+1) && argv[iArgIndex+1][0] != '-' && argv[iArgIndex+1][0] != '/')
                    {
                        pszSource = argv[iArgIndex+1];
                        iArgIndex++;
                    }
                    else
                    {
                        printf("Error source path missing\n");
                        break;
                    }

                    if (argc > (iArgIndex+1) && argv[iArgIndex+1][0] != '-' && argv[iArgIndex+1][0] != '/')
                    {
                        pszDestination = argv[iArgIndex+1];
                        i++;
                    }
                    else
                    {
                        pszDestination = NULL;
                    }

                    GetFile(
                        pszSource, pszDestination,
                        cOption == 'r' ? COPY_FLAG_UPDATE_EXISTING :
                        cOption == 'u' ? COPY_FLAG_UPDATE_OR_ADD :
                        0);
                }
                break;

                default:
                    printf("Unrecognized option - %s\n", argv[iArgIndex]);
                    /* FALL THROUGH */

                case '?':
                case 'h':
                    usage(argv[0]);
                    ret = 1;
                    goto main_error;
            }
        }

        if (iArgIndex == (argc - 1))
        {
            pszFileName = argv[iArgIndex];
        }
    }

    if (iPpfstool) {
        ret = 0;
        goto main_error;
    }

    if (!XmsIsInstalled())
    {
        printf("HIMEM.SYS must be loaded\n");
        ret = 2;
        goto main_error;
    }

    if (bVerbose)
    {
        if ((xmsError = XmsQueryA20(&bEnabled)) != XMS_SUCCESS)
        {
            printf("Error querying A20 status - %s\n", XmsErrorString(xmsError));
            ret = 3;
            goto main_error;
        }

        if (bEnabled)
        {
            printf("Warning A20 line already enabled\n");
        }
    }

    /*
    ** Check if PCI Bios is available, if so find out config mechanism
    */

    BootArgs.ucPCIConfigType = GetPCIConfigMechanism();

    if (!LoadImage(bVerbose, bParallelDownload, pszFileName, &ulEntryPoint))
    {
        ret = 4;
        goto main_error;
    }

    /*
    ** Enable A20 line
    */

    if ((xmsError = XmsLocalEnableA20()) != XMS_SUCCESS)
    {
        printf("Can't enable A20 line, error = 0x%4.4X\n", xmsError);

        ret = 5;
        goto main_error;
    }

    BootArgs.ucVideoMode = SetVideoMode(iDesiredMode);
    if (BootArgs.ucVideoMode == 0)          // if using default mode
    {
        BootArgs.cxDisplayScreen     = 320; // set params for flat framebuffer driver accordingly
        BootArgs.cyDisplayScreen     = 200;
        BootArgs.cxPhysicalScreen    = 320; 
        BootArgs.cyPhysicalScreen    = 200;
        BootArgs.bppScreen           = 8;
        BootArgs.cbScanLineLength    = 320;
        BootArgs.pvFlatFrameBuffer   = 0x800A0000;
    }
    else if (BootArgs.ucVideoMode != 0xFF)  // if not using VESA mode
    {
        BootArgs.cxDisplayScreen     = 0;   // clear these so flat framebuffer driver sees all zeroes and faults
        BootArgs.cyDisplayScreen     = 0;
        BootArgs.cxPhysicalScreen    = 0;   
        BootArgs.cyPhysicalScreen    = 0;
        BootArgs.bppScreen           = 0;
        BootArgs.cbScanLineLength    = 0;
        BootArgs.pvFlatFrameBuffer   = 0;
    }

    if (bSerialDownload)
        BootArgs.ucBaudDivisor|=0x80;

    if (bVerbose)
    {
        printf("Jumping to 0x%8.8lX\n", ulEntryPoint);
    }

    /*
    ** Convert arguments to linear addres
    */

    ulArguments = (((ULONG)(void far *)&BootArgs) >> 16) << 4;
    ulArguments += ((ULONG)(void far *)&BootArgs) & 0xFFFF;

    Launch(ulEntryPoint, ulArguments);

    /*
    ** Launch shouldn't have returned
    */
    return 0;

main_error:
    if (usBlockHandle) {
        XmsUnlockExtendedMemory(usBlockHandle);
        XmsFreeExtendedMemory(usBlockHandle);
    }
    return ret;
}

USHORT DownloadRead(int hImage, UCHAR* ucBuffer, USHORT usReadSize, BOOL bParallelDownload)
{
    USHORT  loop;

    if (bParallelDownload)
    {
        for (loop = 0; loop < usReadSize; loop++ )
        {
            ucBuffer[loop]= (UCHAR)OEMParallelPortGetByte();
            if (NoPPFS)
            {
                return 0;
            }
        }
        return usReadSize;
    }
    else if (bSerialDownload)
    {
        OEMReadDebugBytes(ucBuffer,usReadSize);
        return usReadSize;
    }
    else
    {
        return _read(hImage, ucBuffer, usReadSize);
    }
}

int
LoadImage(BOOL bVerbose, BOOL bParallelDownload, char *pszFileName, PULONG pulEntryPoint)
{
    int             hImage;
    long            lImageSize;

    int             xmsError;

    USHORT          usTotalFree;
    USHORT          usLargestBlock;

    ULONG           ulLinearAddress;

    ULONG           ulSectionAddress;
    ULONG           ulSectionSize;
    ULONG           ulSectionChecksum;

    ULONG           ulSectionOffset;
    ULONG           ulChecksum;

    USHORT          usReadSize;
    USHORT          usAmountRead;
    ULONG           ulReadTotal=0;
    ULONG           ulReadProgress=0;

    USHORT          usIndex;

    static UCHAR    ucBuffer[ CHUNKSIZE ];

    static UCHAR    ucSignature[] = { 'B', '0', '0', '0', 'F', 'F', '\n' };
    int i;
    UCHAR           BootPacket[256];
    UCHAR           *pDestByte;
    UCHAR           *pTemp;
    unsigned int    chksum;
    long int        uiTemp;
    long int        bootType;
    unsigned        len;

    /*
    ** Stop the floppy motor in case it contained the image file
    */

    __asm
    {
        push    dx
        mov     dx, 03F2h   ; Floppy motor and DMA control
        in      al, dx
        and     al, 00Fh    ; Clear motor on bits
        out     dx, al
        pop     dx
    }
    /*
    ** Find the largest Extended Memory block and allocate it
    */

    xmsError = XmsQueryFreeExtendedMemory(&usLargestBlock, &usTotalFree);

    if (xmsError != XMS_SUCCESS)
    {
        printf("Error querying free extended memory - %s\n", XmsErrorString(xmsError));
        if (!bParallelDownload && !bSerialDownload)
            _close(hImage);

        return FALSE;
    }

    if (bVerbose)
    {
        /*
        ** Print info about memory available
        */

        printf(
            "Total free extended memory = %u, largest block = %u\n",
            usTotalFree, usLargestBlock);
    }

    xmsError = XmsAllocateExtendedMemory(usLargestBlock, &usBlockHandle);

    if (xmsError != XMS_SUCCESS)
    {
        printf("Error allocating extended memory - %s\n", XmsErrorString(xmsError));
        if (!bParallelDownload && !bSerialDownload)
            _close(hImage);

        return FALSE;
    }
    //printf("XMS usBlockHandle = 0x%x\n", usBlockHandle);

    /*
    ** Lock the block and obtain its linear address.  Then ensure that the
    ** image fits into it.
    */

    xmsError = XmsLockExtendedMemory(usBlockHandle, &ulLinearAddress);

    if (xmsError != XMS_SUCCESS)
    {
        fprintf(stderr, "\r                          \r");
        printf("Error locking extended memory - %s\n", XmsErrorString(xmsError));

        XmsFreeExtendedMemory(usBlockHandle);
        usBlockHandle = 0;
        if (!bParallelDownload && !bSerialDownload)
            _close(hImage);

        return FALSE;
    }

    if (bVerbose)
    {
        /*
        ** Print info about block allocated
        */

        fprintf(stderr, "\r                          \r");
        printf("Block allocated at 0x%lX\n", ulLinearAddress);
    }

    /*
    ** Zero upper memory in CHUNKSIZE chunks
    */

    memset(ucBuffer, 0, sizeof(ucBuffer));
    ulSectionSize = (ULONG)usLargestBlock * 1024;
#if 1   
    for (ulSectionOffset = 0; ulSectionOffset < ulSectionSize; ulSectionOffset += usReadSize)
    {
        if ((ulSectionSize - ulSectionOffset) < CHUNKSIZE)
        {
            usReadSize = (USHORT)(ulSectionSize - ulSectionOffset);
        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?