📄 store.c
字号:
/******************************************************************************
*******************************************************************************
** **
** Copyright (c) 2002 Videon Central, Inc. **
** All rights reserved. **
** **
** The computer program contained herein contains proprietary information **
** which is the property of Videon Central, Inc. The program may be used **
** and/or copied only with the written permission of Videon Central, Inc. **
** or in accordance with the terms and conditions stipulated in the **
** agreement/contract under which the programs have been supplied. **
** **
*******************************************************************************
******************************************************************************/
/**
* @file store.c
*
* Function to read data from disc and store into given memory address.
*
* $Id: store.c,v 1.15 2006/09/28 15:24:00 mspinnenweber Exp $
*/
#include "vdvd_types.h"
#include "osapi.h"
#include "loader_app.h"
#include "utility.h"
#include "dbgprint.h"
#include "store.h"
#include "dvd_vmgi.h"
#include "nav_task.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/* MACROS AND DEFINES */
#define NON_CACHED_SBUF ((UBYTE *)KSEG1(sbuf))
/* EXTERNS */
extern LOADER_HANDLE tLoader;
extern UBYTE *sbuf;
extern ULONG lbuf[LBUFSIZE];
extern cur_bufd_struct cBfd;
/**
* Name: store
*
* Description: Stores data from sbuf into structures.
*
* Arguments:
* address - Pointer to address location to store data
* RBN - Relative byten number into the sbuf array
* Length - Number of bytes to store
* Endian - process the store as STORE_LITTLE_ENDIAN or STORE_BIG_ENDIAN
*
* Returns: None
*
* Structures: sbuf contains the raw DVD data from the file
*
* Pseudocode:
*
*/
ULONG store(UBYTE * address, ULONG beg_index, ULONG length, UBYTE Endian)
{
UBYTE *temp_address;
ULONG index;
ULONG end_index;
UBYTE ret,adjust_flag;
ULONG sbuf_offset; /* added for non-contiguous tables which is against the DVD standard */
ULONG sbuf_offset_sect; /* sector offset beyond lbuf */
/* validate input */
if (NULL == address)
{
DbgPrint(("store: NULL POINTER\n"));
return (-1);
}
if (0 == length)
{
DbgPrint(("store: Invalid length value\n"));
return (-1);
}
#if VDVD_PLATFORM_ENDIANESS == VDVD_BIG_ENDIAN
/* if the host processor is big endian no byte swap required so process as big endian */
Endian = STORE_BIG_ENDIAN;
#endif
/* set up target starting address */
if (STORE_BIG_ENDIAN == Endian)
{
temp_address = address;
}
else if (STORE_LITTLE_ENDIAN == Endian)
{
temp_address = (UBYTE *)( address + (length - 1) );
}
else
{
DbgPrint(("store: Invalid Endian value\n"));
return (-1);
}
end_index = beg_index + length;
adjust_flag = 0;
/* If source data end address exceeds source data buffer end address */
while ( (ULONG)&sbuf[end_index] > (ULONG)&lbuf[LBSIZE] )
{
/* If source data beginning address exceeds source data buffer end address */
if ( (ULONG)&sbuf[beg_index] >= (ULONG)&lbuf[LBSIZE] )
{
/* The number of bytes past end of lbuf */
sbuf_offset = (ULONG)&sbuf[beg_index] - (ULONG)&lbuf[LBSIZE];
sbuf_offset_sect = sbuf_offset >> 11;
end_index -= beg_index;
beg_index = 0;
cBfd.ulCOff += BUFSIZE + sbuf_offset_sect; /* the only time we'll want data past the end
is when we've gone through BUFSIZE sectors */
/* We read starting at destination sector so we reset sbuf */
sbuf = (UBYTE *)lbuf;
ret = (UBYTE)(LoaderSectorRead(tLoader, cBfd.ulSSec + cBfd.ulCOff, sbuf, MIN(cBfd.ulESec - cBfd.ulCOff, BUFSIZE)));
if (ret != LOADER_SUCCESS)
{
DbgPrint(("store: LoaderSectorRead FAILED\n"));
abort_startup();
return (ret);
}
}
else
{
for (index = beg_index; (ULONG)&sbuf[index] < (ULONG)&lbuf[LBSIZE]; index++)
{
*temp_address = NON_CACHED_SBUF[index];
if (STORE_BIG_ENDIAN == Endian)
{
temp_address++;
}
else
{
temp_address--;
}
}
end_index = (ULONG)&sbuf[end_index] - (ULONG)&lbuf[LBSIZE];
beg_index = 0;
adjust_flag = 1;
cBfd.ulCOff += BUFSIZE; /* the only time we'll want data past the end
is when we've gone through BUFSIZE sectors */
sbuf = (UBYTE *)lbuf;
ret = (UBYTE)(LoaderSectorRead(tLoader, cBfd.ulSSec + cBfd.ulCOff, sbuf, MIN(cBfd.ulESec - cBfd.ulCOff, BUFSIZE)));
if (ret != LOADER_SUCCESS)
{
DbgPrint(("store: LoaderSectorRead FAILED\n"));
abort_startup();
return (ret);
}
}
}
for (index = beg_index; index < end_index; index++)
{
*temp_address = NON_CACHED_SBUF[index];
if (STORE_BIG_ENDIAN == Endian)
{
temp_address++;
}
else
{
temp_address--;
}
}
if (adjust_flag)
{
beg_index -= (length - end_index); /* get a negative number */
}
return (beg_index);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -