⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dm_edit.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 4 页
字号:
    if (!GetParameters(arg, MemEditWidth))
    {
        do
        {
            // Ask user for memory width.
            printf("Memory width to 8, 16 or 32 bits: ");
            memoryWidth = GetDecimal(2, 55);
            switch (memoryWidth)
            {
                case 8:    // 8-bits.
                    dumpLength = 32;
                    break;
                case 16:   // 16-bits.
                case 32:   // 32-bits.
                    dumpLength = 64;
                    break;
                default:
                    memoryWidth = 0;    // Try again.
                    break;
            }
        }
        while (memoryWidth == 0);
    }

    printf("New memory width = %d bits\r\n", memoryWidth);
}

/*----------------------------------------------------------------------
 * Search memory - This function is called directly from the menu system.
 */

void DM_SearchMemory(void *menuP, char *arg)
{
    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Check parameters.
    if (!GetParameters(arg, MemEditSearch))
    {
        // Ask user for address.
        printf("Enter search address: 0x");
        searchAddrP = (PUINT32)GetHex(8, 56);
        // Ask user for value.
        printf("Enter search value: 0x");
        searchValue = GetHex(memoryWidth/4, (47 + memoryWidth/4));
    }

    // Search memory.
    searchMemory(TRUE);
}

/*----------------------------------------------------------------------
 * Search higher memory - This function is called directly from the menu system.
 */

void DM_SearchHigherMemory(void *menuP, char *arg)
{
    UINT32 srcAddr = (UINT32)searchAddrP;

    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Determine memory width.
    switch (memoryWidth)
    {
        case 8:    // 8-bits
            // Update starting search location.
            srcAddr += sizeof(UINT8);
            searchAddrP = (PUINT32)srcAddr;
            break;

        case 16:    // 16-bits
            // Update starting search location.
            srcAddr += sizeof(UINT16);
            searchAddrP = (PUINT32)srcAddr;
            break;

        case 32:    // 32-bits
            // Update starting search location.
            srcAddr += sizeof(UINT32);
            searchAddrP = (PUINT32)srcAddr;
            break;
    }

    // Search memory.
    searchMemory(TRUE);
}

/*----------------------------------------------------------------------
 * Search Lower memory - This function is called directly from the menu system.
 */

void DM_SearchLowerMemory(void *menuP, char *arg)
{
    UINT32 srcAddr = (UINT32)searchAddrP;

    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Determine memory width.
    switch (memoryWidth)
    {
        case 8:    // 8-bits
            // Update starting search location.
            if (srcAddr > sizeof(UINT8))
            {
                srcAddr -= sizeof(UINT8);
                searchAddrP = (PUINT32)srcAddr;
            }
            break;

        case 16:    // 16-bits
            // Update starting search location.
            if (srcAddr > sizeof(UINT16))
            {
                srcAddr -= sizeof(UINT16);
                searchAddrP = (PUINT32)srcAddr;
            }
            break;

        case 32:    // 32-bits
            // Update starting search location.
            if (srcAddr > sizeof(UINT32))
            {
                srcAddr -= sizeof(UINT32);
                searchAddrP = (PUINT32)srcAddr;
            }
            break;
    }

    // Search memory.
    searchMemory(FALSE);
}

/*----------------------------------------------------------------------
 * Set Search length - This function is called directly from the menu system.
 */

void DM_SearchLength(void *menuP, char *arg)
{
    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    printf("Search length = 0x%X\r\n", searchLength);

    // Check parameters.
    if (!GetParameters(arg, MemEditSearchLength))
    {
        // Ask user for search length.
        printf("Enter search length: 0x");
        searchLength = GetHex(8, 55);
    }

    printf("New search length = 0x%X\r\n", searchLength);
}

/*
*******************************************************************************
*
* FUNCTION:         GetHex
*
* DESCRIPTION:      Constructs a hex value from the standard input
*
* INPUT PARAMETERS: UINT places - maximum number of digits expected
*                   UCHAR entryPos - position on the screen to display
*                                    characters.
*
* RETURNS:          a 32 bit integer
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      NOne
*
* CALLS:            None
*
* CALLED BY:        DM_LengthMemory, DM_WriteMemory, DM_ViewMemory
*
* PROTOTYPE:        UINT32 GetHex(UINT places, UCHAR entryPos);
*
*******************************************************************************
*/
extern int StatusCurRow;

static UINT32 GetHex(UINT places, UCHAR entryPos)
{
    UINT32 constructedValue = 0;
    INT count, i;
    CHAR buf[2];
    BOOL done = FALSE;

//    DM_ClearKeypad();
//    DM_PaintKeypad(BaseHex);
    buf[1] = 0;

    // Copy the maximum number of digits expected
    count = places;

    do
    {
        do
        {
            // Get key from user.
            buf[0] = DM_GetKey();
            // Check for backspace.
            if (buf[0] == 0x08 && count != places)
            {
                // Send backspace.
                printf("\x08 \x08");
                // Caculate previous value.
                constructedValue >>= 4;
                // Backup the count;
                count++;
                // Clear the character.
//                DM_PrintChar(' ', StatusCurRow-1, entryPos-count, gFgColor, gBgColor);
            }
            // Check for carriage return.
            else if (buf[0] == 0x0d)
            {
                // Exit loop.
                done = TRUE;
                break;
            }

        // Check range of hex value.
        } while (buf[0] < '0' || buf[0] > 'F' || (buf[0] > '9' && buf[0] < 'A'));

        if (!done)
        {
            // Convert ascii to hex.
            i = (buf[0] > '9') ? buf[0]-'A'+10 : buf[0]-'0';
            // Send character to serial port.
            printf(buf);
            // Display character on screen.
//            DM_PrintChar(buf[0], StatusCurRow-1, entryPos-count, gFgColor, gBgColor);
            // Calculate hex value.
            constructedValue = (constructedValue << 4) | i;
        }
        else
        {
            break;
        }

    // Decrement loop count.
    } while (--count);

    printf("\r\n");
//    DM_ClearKeypad();

    return constructedValue;
}

/*
*******************************************************************************
*
* FUNCTION:         GetDecimal
*
* DESCRIPTION:      Constructs a 32 bit hex value from the standard input
*
* INPUT PARAMETERS: UINT places - maximum number of digits expected
*                   UCHAR entryPos - position on the screen to display
*                                    characters.
*
* RETURNS:          a 32 bit integer
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      NOne
*
* CALLS:            None
*
* CALLED BY:        DM_LengthMemory, DM_WriteMemory, DM_ViewMemory
*
* PROTOTYPE:        UINT32 GetDecimal(UINT places, UCHAR entryPos);
*
*******************************************************************************
*/
static UINT32 GetDecimal(UINT places, UCHAR entryPos)
{
    UINT32 constructedValue = 0;
    int count, i;
    char buf[2];
    BOOL done = FALSE;

//    DM_ClearKeypad();
//    DM_PaintKeypad(BaseDecimal);
    buf[1] = 0;

    // Copy the maximum number of digits expected
    count = places;

    do
    {
        do
        {
            // Get key from user.
            buf[0] = DM_GetKey();
            // Check for backspace.
            if (buf[0] == 0x08 && count != places)
            {
                // Send backspace.
                printf("\x08 \x08");
                // Caculate previous value.
                if (constructedValue >= 10)
                {
                    constructedValue = constructedValue / 10;
                }
                else
                {
                    constructedValue = 0;
                }
                // Backup the count;
                count++;
                // Clear the character.
//                DM_PrintChar(' ', StatusCurRow-1, entryPos-count, gFgColor, gBgColor);
            }
            // Check for carriage return.
            else if (buf[0] == 0x0d)
            {
                // Exit loop.
                done = TRUE;
                break;
            }

        // Check range of hex value.
        } while ((buf[0] < '0') || (buf[0] > '9'));

        if (!done)
        {
            // Convert ascii to hex.
            i = buf[0]-'0';
            // Send character to serial port.
            printf(buf);
            // Display character on screen.
//            DM_PrintChar(buf[0], StatusCurRow-1, entryPos-count, gFgColor, gBgColor);
            // Calculate hex value.
            constructedValue = (constructedValue * 10) + i;
        }
        else
        {
            break;
        }

    // Decrement loop count.
    } while (--count);

    printf("\r\n");
//    DM_ClearKeypad();

    return constructedValue;
}

static BOOL findValue(BOOL forward, PUINT32 virtMemP)
{
    UINT32 vaMem = (UINT32)*virtMemP;
    PVOID vaMemP = (PVOID)vaMem;
    UINT32 paMem;
    BOOL found = FALSE;

    // Check search size.
    switch (memoryWidth)
    {
        case 8:    // 8-bits

            // Check if this is a valid address
            if (!VirtualToPhysical(vaMemP, (PUINT32)&paMem))
            {
                // Check for byte.
                if (*((PUINT8)vaMemP) == (UINT8)searchValue)
                {
                    // Set flag.
                    found = TRUE;
                }
                else if (forward)
                {
                    // Get address.
                    PUINT8 vaMem8P = vaMemP;
                    // Point to next byte.
                    vaMem8P++;
                    // Update pointer.
                    vaMemP = vaMem8P;
                }
                else
                {
                    // Get address.
                    PUINT8 vaMem8P = vaMemP;
                    // Point to next byte.
                    vaMem8P--;
                    // Update pointer.
                    vaMemP = vaMem8P;
                }
            }
            break;

        case 16:    // 16-bits

            // Check if this is a valid address
            if (!VirtualToPhysical(vaMemP, (PUINT32)&paMem))
            {
                // Check for word.
                if ((UINT16)*((PUINT16)vaMemP) == (UINT16)searchValue)
                {

⌨️ 快捷键说明

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