📄 lowlvl.c
字号:
if (OriginalWord == SaveTest) return (Size);
}
}
}
#endif
/****************************************************************************
* _FlashDevStatus
*
* FUNCTION:
* Single entry point for all status routines. Control is steered over
* to the status routine stored in the FlashStatus global.
*
* INPUTS:
* CardAddress is point on card to check status for.
*
* GLOBALS:
* FlashStatus
*
* FORMAT:
* int _FlashDevStatus(DWORD CardAddress)
*
* RETURNS:
* See specific erase routines for return values.
****************************************************************************/
#if ERASE_BACKGROUND
WORD FlashDevStatus(DWORD CardAddress)
{
if (CardAddress > Info.media_size)
return (ERR_PARAM);
return FlashStatus(CardAddress);
}
#endif
/****************************************************************************
* _FlashDevEraseBlock
*
* FUNCTION:
* Single entry point for all erase routines. Control is steered over
* to the erase routine stored in the FlashErase global.
*
* INPUTS:
* Address to erase block at
*
* GLOBALS:
* FlashErase
*
* FORMAT:
* int _FlashDevErase(DWORD CardAddress)
*
* RETURNS:
* See specific erase routines for return values.
****************************************************************************/
WORD FlashDevEraseBlock(DWORD CardAddress)
{
if (CardAddress > Info.media_size)
return (ERR_PARAM);
return FlashErase(CardAddress);
}
/****************************************************************************
* _FlashDevRead
*
* FUNCTION:
* Single entry point for all read routines. Control is steered over
* to the read routine stored in the FlashRead global pointer.
*
* INPUTS:
* See specific read routines for input packet structure.
*
* GLOBALS:
* FlashRead
*
* FORMAT:
* int _FlashDevRead(ReadParms...)
*
* RETURNS:
* See specific read routines for return values.
****************************************************************************/
WORD FlashDevRead(DWORD CardAddress,DWORD Length,BYTE_PTR Pointer)
{
if (Length == 0)
return ERR_NONE;
if (CardAddress > Info.media_size)
return (ERR_PARAM);
return FlashRead(CardAddress, Length, Pointer);
}
/****************************************************************************
* _FlashDevWrite
*
* FUNCTION:
* Single entry point for all write routines. Control is steered over
* to the write routine stored in the FlashWrite global.
*
* INPUTS:
*
*
* GLOBALS:
* FlashWrite
*
* FORMAT:
* int _FlashDevWrite(WriteParms...)
*
* RETURNS:
* See specific write routines for return values.
****************************************************************************/
WORD FlashDevWrite(DWORD CardAddress,DWORD Length,BYTE_PTR Pointer)
{
if (Length == 0)
return ERR_NONE;
if (CardAddress > Info.media_size)
return (ERR_PARAM);
return (FlashWrite)(CardAddress, Length, Pointer);
}
/****************************************************************************
* _FlashDevSuspend Ver69
*
* FUNCTION:
* Single entry point for all suspend routines. Control is steered over
* to the suspend routine stored in the FlashSuspend global.
*
* INPUTS:
* None. Flash is suspended AT CURRENT MEMORY WINDOW POSITION.
*
* GLOBALS:
* FlashSuspend
*
* FORMAT:
* int _FlashDevSuspend(void)
*
* RETURNS:
* See specific suspend routines for return values.
****************************************************************************/
#if ERASE_BACKGROUND
void FlashDevSuspend(void)
{
FlashSuspend();
}
/****************************************************************************
* _FlashDevResume Ver69
*
* FUNCTION:
* Single entry point for all resume routines. Control is steered over
* to the resume routine stored in the FlashResume global.
*
* INPUTS:
* None. Flash is suspended AT CURRENT MEMORY WINDOW POSITION.
*
* GLOBALS:
* FlashResume
*
* FORMAT:
* int _FlashDevResume(void)
*
* RETURNS:
* See specific resume routines for return values.
****************************************************************************/
void FlashDevResume(void)
{
FlashResume();
}
#endif
/****************************************************************************
* _Search
*
* FUNCTION:
* Search for requested value within card memory
*
* FORMAT:
* int _Search(StartAddress, SearchAreaSize, TargetValue, TargetSize,
* Skip, Flags)
*
* INPUTS:
* dword StartAddress - card address to begin search
* dword TargetValue - value to search for (4 bytes or less) Ver66
* word SearchAreaSize - maximum number of bytes to search
* word TargetSize - size of TargetValue (1, 2, or 4 bytes)
* word Skip - number of bytes to skip between searches
* word Flags - 0001 = special 12-bit search
* - 0002 = number of occurrences in range
*
* GLOBALS:
* None
*
* CALLS:
* _SlideMemoryWindow(dword CardAddress)
*
* RETURNS:
* Offset of located data
* ERR_NOT_FOUND (FFFFh)
****************************************************************************/
WORD Search(DWORD StartAddress,DWORD register TargetValue, WORD SearchAreaSize,WORD TargetSize,WORD Skip, WORD Flags)
{
FULL_WORD_PTR volatile pointer;
WORD hits=0;
WORD register count=0;
BYTE match_flag=0;
PositionPtr(pointer, (StartAddress & 0xfffffffe));
#if ERASE_BACKGROUND
FlashSuspend();
#endif
if (SearchAreaSize == 0) return (ERR_NOT_FOUND); /* if 0 its pointless */
*(FULL_WORD_PTR)pointer = FlashCommandRead*0x101; /* Set flash into read */
PositionPtr(pointer, StartAddress);
while(count < SearchAreaSize)
{
if (Flags & 0x1) /* If 12-bit flag is on */
{
if ((((WORD)(*((FULL_BYTE_PTR)pointer+2) << 4)) + ((WORD)((*((FULL_BYTE_PTR)pointer+1) & 0xF0)) >> 4)) == (WORD)TargetValue)
{
if (!(Flags & 0x02))
{
#if ERASE_BACKGROUND
FlashResume();
#endif
return (count);
}
else
(hits++);
}
if ((((WORD)(*(FULL_BYTE_PTR)pointer)) + ((WORD)((*((FULL_BYTE_PTR)pointer+1)) & 0xF) << 8))== (WORD)TargetValue)
{
if (!(Flags & 0x02))
{
#if ERASE_BACKGROUND
FlashResume();
#endif
return (count);
}
else
(hits++);
}
}
match_flag=0;
switch(TargetSize) /* Depending on how large we need to search */
{
/* Note - Since it is a VOID pointer, we must cast it always,
but, this allows for variable search sizes */
case 0x01: if ((BYTE)TargetValue == *(FULL_BYTE_PTR)pointer)
match_flag=1;
break;
case 0x02:
#if SWAP
if ((WORD)TargetValue == BSWAP(*(FULL_WORD_PTR)pointer))
#else
if ((WORD)TargetValue == *(FULL_WORD_PTR)pointer)
#endif
match_flag=1;
break;
case 0x04:
#if SWAP
if ((DWORD)TargetValue == LSWAP(*(FULL_DWORD_PTR)pointer))
#else
if ((DWORD)TargetValue == *(FULL_DWORD_PTR)pointer)
#endif
match_flag=1;
break;
}
if (match_flag)
{
if (!(Flags & 0x02))
{
#if ERASE_BACKGROUND
FlashResume();
#endif
return (count);
}
else
(hits++);
}
/* Advance everything as much as Skip value says to */
count += Skip;
IncreasePtr(pointer, Skip);
}
#if ERASE_BACKGROUND
FlashResume();
#endif
if (Flags & 0x02) return (hits); /* If they want a count only */
else return (ERR_NOT_FOUND);
}
/****************************************************************************
* WriteProtect
*
* FUNCTION:
* Just returns error in case someone tries to write ROM.
*
* FORMAT:
* int WriteProtect(CardAddress, Length, BufferAddress)
*
* INPUTS:
* dword CardAddress - address on card to begin write
* int Length - number of bytes to write
* dword BufferAddress - address in system RAM from which to write
*
* GLOBALS:
* None
*
* CALLS:
* None
*
* RETURNS:
* ERR_WRITE_PROTECT
****************************************************************************/
WORD WriteProtectWrite(DWORD CardAddress,DWORD Length,BYTE_PTR Pointer)
{
return(ERR_WRITE_PROTECT);
}
WORD WriteProtectErase(DWORD CardAddress)
{
return(ERR_WRITE_PROTECT);
}
WORD WriteProtectSusRes(void)
{
return(ERR_WRITE_PROTECT);
}
#if SRAM_MEDIA
/****************************************************************************
* SRAMErase
*
* FUNCTION:
* Just returns error in case someone tries to erase SRAM.
*
* FORMAT:
* int SRAMErase(CardAddress)
*
* INPUTS:
* dword CardAddress - address to begin erase
*
* GLOBALS:
* None
*
* CALLS:
* None
*
* RETURNS:
* ERR_ERASE
****************************************************************************/
WORD SRAMErase(DWORD CardAddress)
{
/* Makes no sense to erase SRAM */
CardAddress &= 0;
return(ERR_ERASE);
}
/****************************************************************************
* SRAMWrite
*
* FUNCTION:
* Write bytes to SRAM.
*
* FORMAT:
* int SRAMWrite(CardAddress, Length, BufferAddress)
*
* INPUTS:
* dword CardAddress - address on card to begin write
* int Length - number of bytes to write
* dword BufferAddress - address in system RAM from which to write
*
* GLOBALS:
* None
*
* CALLS:
* _SlideMemoryWindow(dword CardAddress)
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -