#include "p_apps.h"

//
// handle speed dial
//
USHORT _SpeedDialIndex2Pos(UCHAR iIndex)
{
	DSHORT iPos;

	iPos = iIndex;
	iPos <<= 4;		// iPos *= PHONE_NUMBER_LEN;
	iPos += SPEED_DIAL_BEGIN;
	return iPos;
}

PXCHAR ReadSpeedDial(UCHAR iIndex)
{
	DCHAR iOffset;
	DSHORT iPos;

	iPos = _SpeedDialIndex2Pos(iIndex);
	iOffset = (UCHAR)iPos;
	SdramRead(OPTIONS_SDRAM_HI, P_HIBYTE(iPos), SRAM_DMA_HALF_DWORD);
	X_VAL(Sdram_pDataCache, iOffset+PHONE_NUMBER_LEN) = 0;
	return (PXCHAR)(Sdram_pDataCache+iOffset);
}

void WriteSpeedDial(PXCHAR pBuf, UCHAR iIndex)
{
	DSHORT iPos;
	DCHAR iSdramLo, iOffset;

	iPos = _SpeedDialIndex2Pos(iIndex);
	iSdramLo = P_HIBYTE(iPos);
	iOffset = (UCHAR)iPos;
	SdramRead(OPTIONS_SDRAM_HI, iSdramLo, SRAM_DMA_HALF_DWORD);
	p_memcpy_x2x((PXCHAR)(Sdram_pDataCache+iOffset), pBuf, PHONE_NUMBER_LEN);
	SdramWrite(OPTIONS_SDRAM_HI, iSdramLo, SRAM_DMA_HALF_DWORD);
}

